Skip to content

Commit b0505c0

Browse files
feat(mcp): a refusal with several declared reasons names every line to the agent (#37497)
<!-- claude-projects-attribution: {"github_login":"os-bill"} --> _Requested by **Bill** · [project thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wgFiXLbrG7d8JVydkmtSf4Bt)_ Fixes #37416 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:智能体通过 MCP 新建、修改、删除记录或运行动作时,如果一次拒绝带了多条原因,它现在能完整拿到每一条原因和最后的总结句,再转告用户;只有一条原因的拒绝和以前一样。 - 为什么做:接上「一次拒绝可以带多条已翻译原因」那张卡;数据入口把给用户的那句话截在 500 字,原因多时智能体只看到被截断的一段。 - 出错会怎样:只影响带多条原因的拒绝,智能体多看到一段文字;原来的错误内容一个字不变,可以直接撤回。 - 要你做什么:无。 ## What changes - `packages/mcp/src/mcp-http-tools.ts`: a refusal thrown as a declared `reasons` list now gets a second text block, the `flowFailureRelaySentence` pattern (card ruling): `content[0]` stays the door's envelope byte for byte, and `content[1]` is a fixed lead (`REFUSAL_REASONS_RELAY_LEAD`) followed by every listed line, whole and in the order thrown, then the closing line. - Wired into the two renderers that serve a door's `userMessage`: `errorResultFromThrown` (`run_action`, `resume_run`; the `/actions` answer) and `dataDoorErrorResult` (the record data tools; the `/data` answer, whose `userMessage` is cut at 500). - The lines are read through `declaredRefusalLines` (`@objectstack/types`), the one recogniser every door uses for `details.refusals` (imported, not hand-spelled). The closing line is not on the list (the #36877 changeset says so). It is read as the part of the error's own unbounded `userMessage` (`declaredUserMessage`) after the listed lines. If that text does not begin with the lines, no closing line is invented and the block carries the lines alone. - Withheld, so these answers are unchanged: a `PERMISSION_DENIED` answer (the #7450 rule; `run_action` already returned before this point, and the data tools now ask the same question), an answer with no `userMessage`, a fault (5xx), and any throw the shared recogniser does not read (a single-reason refusal among them). - `packages/mcp/src/stdio-data-bridge.ts` is untouched. It only implements the bridge and renders no tool result. The stdio server's tools are rendered by the same `mcp-http-tools.ts` functions, so the relay applies to both transports with no stdio edit. ## Tests `packages/mcp/src/mcp-refusal-reasons.test.ts` (new, named for the card): 14 cases through the real HTTP `/mcp` transport (`MCPServerRuntime.handleHttpRequest`), with a bridge double that throws the shape the runtime's catalogue throws (`SandboxError` with `code`, `status`, `userMessage`, `refusals`). - For each of `run_action`, `resume_run`, `create_record`, `update_record` and `delete_record`: two lines plus the closing line ride as `content[1]`, and `content[0]` equals the answer to the same throw without `refusals`. A single-reason refusal answers one block, as today. - A six-line list on `create_record` whose joined text exceeds 500 characters: the envelope's `userMessage` is cut (at most 500 characters, closing line missing), and the relay names every line whole with the closing line last. - Controls: `PERMISSION_DENIED` carrying a list gets no relay on all five tools; four malformed lists get none; a `userMessage` that does not begin with the lines gets the lines and no invented closing line. <details><summary>Package suite, typecheck, ablations</summary> - `pnpm --filter @objectstack/mcp typecheck && pnpm --filter @objectstack/mcp exec vitest run --maxWorkers=2` on `ef53eb6617`, under the verify lock: `VERDICT command-exit 0`; Test Files 86 passed (86), Tests 1540 passed (1540); `check:test-typecheck: OK` (the new file compiles under `tsconfig.test.json` and has no debt entry). - Ablation 1 (`node scripts/ablation-replace.mjs`): `const text = refusalReasonsRelayText(err);` replaced by an always-undefined value (anchor 1 → 0, blob a311814 → 335b2247). Result: 7 failed / 7 passed, namely the five per-tool relay cases, the 500-cut case and the no-invented-closing case. Restored: blob equals HEAD, `git diff HEAD` empty. - Ablation 2: the `PERMISSION_DENIED` guard removed (blob a311814 → 172d9385). Result: 1 failed / 13 passed, the #7450 control, failing at `create_record` (`run_action` already returns earlier). Restored: blob equals HEAD, `git diff HEAD` empty. - The tests import `src/` through relative paths, so no rebuild was needed for either ablation. </details> ## Acceptance notes - H3 measured: the closing line is not carried in `details`. The #36877 changeset states that `details.refusals` holds only the listed lines and that the closing line exists only as the last line of `userMessage`. MCP holds the thrown value in process, so it reads the unbounded `userMessage` that the `/data` door would later cut. The closing line is that text minus the listed-lines prefix. This relies on the composition the catalogue documents (lines joined by a line break, then the code's own `message`), and the control pins the case where the composition does not match. - On `run_action` / `resume_run`, the `/actions` door does not cut `userMessage`, so the envelope already held every line. The block is added there too so that every tool answers a listed refusal one way. The envelope is unchanged on both doors. `details.refusals` is not added to either envelope: `errorResultFromThrown` serves only a thrown `details`, and the data tools withhold `details` by design (`errorResultWithCode`). - Not covered: `delete_records` groups refused rows by the thrown message (`rowRefusalOf`) and reads neither `userMessage` nor `details`. The record resource and the metadata tools render no `userMessage` relay. None of these is changed here. - The tests are in a new file, as the dispatch order asked. The closest existing file (`mcp-action-refusal-details.test.ts`) builds its own local harness and is not a shared harness file. ## Verification - Derived gate list (`node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack`, change set of 3 paths against merge base `eaa9e5447`): 67 derived, run on `ef53eb6617`. 66 exit 0. One NOT MEASURED: `pnpm check:dual-build-cjs-loads` exit 3 (PREREQUISITE NOT MET: it needs the whole workspace built; CI Build Core runs it). `--ran` reconciliation: 67 accounted, 66 run, 1 NOT-MEASURED. - CI check-runs are the authority for every family. Two-minute check: `pnpm --filter @objectstack/mcp exec vitest run --maxWorkers=2 src/mcp-refusal-reasons.test.ts`. Expect 14 passed. Read first: `packages/mcp/src/mcp-http-tools.ts`, specifically `withRefusalReasonsRelay` and `refusalReasonsRelayText` (the closing-line read) and the `dataDoorErrorResult` hunk. --- _Generated by [Claude Code](https://claude.ai/code/session_01Utp6CZmwqAVSYHM1nQUDTq)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent dd1ffcc commit b0505c0

3 files changed

Lines changed: 306 additions & 3 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/mcp': patch
3+
---
4+
5+
feat(mcp): a refusal with several declared reasons names every line to the agent
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A hook or `script` action that refuses with a declared `reasons` list answers `userMessage` as the listed sentences joined by a line break, the code's own `message` closing them, and the `/api/v1/data` door bounds that `userMessage` at 500 characters. The record data tools (`create_record`, `update_record`, `delete_record`, and the other record tools that render the `/data` answer) serve the door's value, so on a long list an agent read a cut sentence and lost the closing line.
11+
12+
Every MCP tool that renders a door's `userMessage` (`run_action`, `resume_run` and the record data tools) now adds a second text block to such a refusal: every listed line, whole and in the order thrown, then the closing line. The lines are read from the error's `refusals` through `declaredRefusalLines` (`@objectstack/types`), the reader every door uses for `details.refusals`. The closing line is the part of the error's own unbounded `userMessage` after those lines; when that text does not begin with the lines, the block carries the lines alone. The first block, the coded envelope, is unchanged. A refusal with one reason, a `PERMISSION_DENIED` answer, a fault, and an answer with no `userMessage` get no second block.

‎packages/mcp/src/mcp-http-tools.ts‎

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ import { SystemFieldName } from '@objectstack/spec/system';
6666
// [#23701] The one key every door that translates the engine's unique-violation
6767
// envelope asks (the registered code AND the class name, never message text),
6868
// and the one classification whose arm states the wire code for it.
69-
import { actionsDoorAnswerOf, earnedAnswerOf, isEngineDuplicateRecordEnvelope, isSandboxCrash, isServerFault, logServerFault, mapDataError, resolveQueryReadLimits, resolveThrownHttpError, sandboxBusinessMessage, serverFaultProvenance, staleSummaryAnswerLines, structuredCodeAnswer, type SummaryRecomputeRefusal } from '@objectstack/types';
69+
import { actionsDoorAnswerOf, declaredRefusalLines, declaredUserMessage, earnedAnswerOf, isEngineDuplicateRecordEnvelope, isSandboxCrash, isServerFault, logServerFault, mapDataError, resolveQueryReadLimits, resolveThrownHttpError, sandboxBusinessMessage, serverFaultProvenance, staleSummaryAnswerLines, structuredCodeAnswer, type SummaryRecomputeRefusal } from '@objectstack/types';
7070
import {
7171
MCP_OAUTH_SCOPE_DATA_READ,
7272
MCP_OAUTH_SCOPE_DATA_WRITE,
@@ -1384,9 +1384,83 @@ function errorResultFromThrown(err: unknown, request: string, objectName?: strin
13841384
// is the one arm whose `details` are the run's artefacts; `satisfies` keeps
13851385
// the spelling checked against the registered vocabulary.
13861386
const relay = answer.code === ('FLOW_FAILED' satisfies ErrorCode) ? flowFailureRelaySentence(details, answer.userMessage) : undefined;
1387-
return relay === undefined
1387+
const flowed = relay === undefined
13881388
? result
13891389
: { ...result, content: [...result.content, { type: 'text' as const, text: `${FLOW_FAILURE_RELAY_LEAD}${relay}` }] };
1390+
// [#37416] A declared refusal thrown as a `reasons` list names each line.
1391+
return withRefusalReasonsRelay(flowed, err, envelope);
1392+
}
1393+
1394+
/**
1395+
* [#37416] The lead of the plain text a refusal thrown as a declared `reasons`
1396+
* list carries beside its envelope ({@link withRefusalReasonsRelay}). Exported
1397+
* for the pin; not on the package entry.
1398+
*/
1399+
export const REFUSAL_REASONS_RELAY_LEAD =
1400+
'Tell the user every line below, whole and in this order, rather than a userMessage the door may have cut:\n';
1401+
1402+
/**
1403+
* [#37416] A refusal thrown as a declared `reasons` list (#36877, ruling
1404+
* 7178348458 term 3) names every line to the agent, whole, in order, with the
1405+
* refusal's closing line last — as a second text block, the
1406+
* {@link flowFailureRelaySentence} pattern: `content[0]` stays the door's
1407+
* envelope byte for byte, and the lines ride beside it as plain text.
1408+
*
1409+
* ## Why
1410+
*
1411+
* The runtime's refusal catalogue renders each listed reason in the caller's
1412+
* locale and answers them as `userMessage`, the lines joined by a line break
1413+
* with the code's own `message` closing them. The `/data` door bounds that
1414+
* `userMessage` at 500 characters (#5423), and the record data tools serve the
1415+
* door's value, so on a long list an agent read a cut sentence with its
1416+
* closing line lost. The doors carry the lines structured as
1417+
* `details.refusals`, unbounded; the closing line is on no list.
1418+
*
1419+
* ## How it is read
1420+
*
1421+
* - The lines through `declaredRefusalLines` (`@objectstack/types`), the one
1422+
* recogniser every door reads `details.refusals` with: a non-empty list of
1423+
* `{ reason, message }` on an error that also carries a declared
1424+
* `userMessage`. ⛔ Never a second reading of the shape here. A thrown value
1425+
* it does not recognise — a single-reason refusal among them — gets no block,
1426+
* so it reads exactly as before.
1427+
* - The closing line from the thrown value's own declared `userMessage`
1428+
* (`declaredUserMessage`, unbounded: the bound is the `/data` door's, applied
1429+
* when it builds its answer), the part after the listed lines. When that
1430+
* text does not begin with the listed lines, no closing line is invented and
1431+
* the block carries the lines alone.
1432+
*
1433+
* ## When it is withheld
1434+
*
1435+
* - A `PERMISSION_DENIED` answer gets no block, as it gets no `details` (the
1436+
* ruling on #7450, {@link errorResultFromThrown}).
1437+
* - An answer that serves no `userMessage`, or a fault (5xx), gets none: the
1438+
* door decided that the marked sentence does not reach this caller, and the
1439+
* lines are that sentence.
1440+
*/
1441+
function withRefusalReasonsRelay<R extends { content: Array<{ type: 'text'; text: string }> }>(
1442+
result: R,
1443+
err: unknown,
1444+
served: { code?: string; status?: number; userMessage?: string },
1445+
): R {
1446+
if (served.code === StandardErrorCode.enum.PERMISSION_DENIED) return result;
1447+
if (served.userMessage === undefined) return result;
1448+
if (served.status !== undefined && isServerFault(served.status)) return result;
1449+
const text = refusalReasonsRelayText(err);
1450+
return text === undefined
1451+
? result
1452+
: { ...result, content: [...result.content, { type: 'text' as const, text: `${REFUSAL_REASONS_RELAY_LEAD}${text}` }] };
1453+
}
1454+
1455+
/** [#37416] The listed lines, then the closing line when the declared `userMessage` carries it after them. */
1456+
function refusalReasonsRelayText(err: unknown): string | undefined {
1457+
const lines = declaredRefusalLines(err);
1458+
if (lines === undefined) return undefined;
1459+
const listed = lines.map((line) => line.message);
1460+
const joined = listed.join('\n');
1461+
const whole = declaredUserMessage(err);
1462+
const closing = whole !== undefined && whole.startsWith(`${joined}\n`) ? whole.slice(joined.length + 1) : '';
1463+
return [...listed, ...(closing.trim() !== '' ? [closing] : [])].join('\n');
13901464
}
13911465

13921466
/**
@@ -1678,7 +1752,8 @@ function dataDoorErrorResult(
16781752
beside?: NotRecordedMembers,
16791753
) {
16801754
const envelope = dataDoorRefusalEnvelope(err, objectName);
1681-
if (envelope) return codedErrorResult({ ...envelope }, beside);
1755+
// [#37416] The door may cut `userMessage` at 500; a listed refusal's lines ride whole beside it.
1756+
if (envelope) return withRefusalReasonsRelay(codedErrorResult({ ...envelope }, beside), err, envelope);
16821757
const door = dataDoorAnswerOf(err, objectName);
16831758
if (isServerFault(door.status)) {
16841759
logServerFault({
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [#37416] A refusal thrown as a declared `reasons` list names every line to
5+
* the agent, whole and in order, with the refusal's closing line last.
6+
*
7+
* ## The thrown value
8+
*
9+
* What the runtime's refusal catalogue (`hook-refusal-catalogue.ts`,
10+
* `@objectstack/runtime`, #36877) throws for a hook or `script` action body
11+
* that refuses with `{ code, reasons: [{ reason, params? }, …] }`: a
12+
* `SandboxError` whose `userMessage` is the listed lines joined by a line
13+
* break, the code's own `message` closing them, and whose `refusals` carries
14+
* the lines structured (`details.refusals` on every door). This package does
15+
* not depend on `@objectstack/runtime`, so the bridge double throws that
16+
* shape.
17+
*
18+
* ## What is pinned
19+
*
20+
* - Through the real HTTP `/mcp` transport, on every tool whose catch renders
21+
* the door's `userMessage`: `run_action` / `resume_run` (the `/actions`
22+
* answer) and the record write tools (the `/data` answer).
23+
* - `content[0]` is the door's envelope byte for byte: identical to the
24+
* answer to the same throw with no `refusals`.
25+
* - `content[1]` is the relay: every line whole, in order, the closing line
26+
* last.
27+
* - On a list long enough that the `/data` door cuts `userMessage` at 500
28+
* characters, the envelope carries the cut text and the relay still names
29+
* every line whole and the closing line.
30+
* - A single-reason refusal (no `refusals`) answers one block, as before.
31+
* - Controls: a `PERMISSION_DENIED` answer gets no relay (the ruling on
32+
* #7450); a list the shared recogniser does not read gets none; a
33+
* `userMessage` that does not begin with the lines gets no invented closing
34+
* line.
35+
*/
36+
37+
import { describe, it, expect } from 'vitest';
38+
39+
import { MCPServerRuntime } from './mcp-server-runtime.js';
40+
import { REFUSAL_REASONS_RELAY_LEAD, type McpActionBridge, type McpDataBridge } from './mcp-http-tools.js';
41+
42+
type Bridge = McpDataBridge & McpActionBridge;
43+
44+
const OBJECT = 'expense_report';
45+
const RECORD_ID = 'er_1';
46+
47+
/** A refusal code an app declares: unregistered, so each door demotes it beside `declaredCode`. */
48+
const CODE = 'SUBMIT_REFUSED';
49+
const LINE_ON_REPORT = 'pin37416 Taxi 12 is already on another report.';
50+
const LINE_APPROVED = 'pin37416 Hotel 7 was approved and cannot be submitted again.';
51+
const CLOSING = 'pin37416 2 expenses could not be submitted.';
52+
53+
interface Listed {
54+
lines: ReadonlyArray<{ reason: string; message: string }>;
55+
closing: string;
56+
}
57+
58+
const TWO: Listed = {
59+
lines: [
60+
{ reason: 'on_report', message: LINE_ON_REPORT },
61+
{ reason: 'approved', message: LINE_APPROVED },
62+
],
63+
closing: CLOSING,
64+
};
65+
66+
/**
67+
* The catalogue's throw for a listed refusal, in `SandboxError`'s shape:
68+
* the debug wrapper as `.message`, the body's own sentence as `innerMessage`,
69+
* the code and status, `userMessage` (the lines, then the closing line) and
70+
* `refusals`. `withList: false` drops `refusals` only: the same throw as a
71+
* door saw it before #36877 carried a list.
72+
*/
73+
function listedRefusal(
74+
listed: Listed,
75+
opts: { withList?: boolean; code?: string; status?: number; userMessage?: string; refusals?: unknown } = {},
76+
): () => Error {
77+
return () => {
78+
const userMessage = opts.userMessage ?? [...listed.lines.map((line) => line.message), listed.closing].join('\n');
79+
const err = Object.assign(new Error(`hook 'expense_submit_guard' threw: Error: ${CODE}`), {
80+
innerMessage: CODE,
81+
code: opts.code ?? CODE,
82+
status: opts.status ?? 400,
83+
userMessage,
84+
...(opts.withList === false ? {} : { refusals: opts.refusals ?? listed.lines.map((line) => ({ ...line })) }),
85+
});
86+
err.name = 'SandboxError';
87+
return err;
88+
};
89+
}
90+
91+
/** Every member answers benignly but the refusing ones, which throw `thrown`. */
92+
function refusingBridge(thrown: () => Error): Bridge {
93+
return {
94+
async listObjects() { return [{ name: OBJECT, label: 'Expense report', fieldCount: 1 }]; },
95+
async describeObject() { return { name: OBJECT, fields: [{ name: 'status', type: 'text' }] }; },
96+
async query() { return { object: OBJECT, records: [], total: 0 }; },
97+
async get(_object, id) { return { id, status: 'draft' }; },
98+
async create() { throw thrown(); },
99+
async update() { throw thrown(); },
100+
async remove() { throw thrown(); },
101+
async listActions() {
102+
return [{ name: 'submit', objectName: OBJECT, type: 'script', requiresRecord: true, requiresConfirmation: false }];
103+
},
104+
async runAction() { throw thrown(); },
105+
async resumeRun() { throw thrown(); },
106+
};
107+
}
108+
109+
let nextId = 1;
110+
111+
/** One `tools/call` over the real HTTP transport; answers the parsed tool result. */
112+
async function callOverHttp(bridge: Bridge, name: string, args: Record<string, unknown>) {
113+
const body = { jsonrpc: '2.0', id: nextId++, method: 'tools/call', params: { name, arguments: args } };
114+
const runtime = new MCPServerRuntime({ name: 'pin', version: '0.0.0' });
115+
const res = await runtime.handleHttpRequest(
116+
new Request('http://localhost/api/v1/mcp', {
117+
method: 'POST',
118+
headers: { 'content-type': 'application/json', accept: 'application/json, text/event-stream' },
119+
body: JSON.stringify(body),
120+
}),
121+
{ bridge, parsedBody: body },
122+
);
123+
expect(res.status, `${name}: the HTTP transport itself answered ${res.status}`).toBe(200);
124+
const json = JSON.parse(await res.text()) as { result?: any; error?: unknown };
125+
expect(json.error, `${name}: JSON-RPC error ${JSON.stringify(json.error)}`).toBeUndefined();
126+
expect(json.result.isError, `${name}: not a tool error`).toBe(true);
127+
return json.result as { isError: true; content: Array<{ type: string; text: string }> };
128+
}
129+
130+
/** The tools whose catch renders the door's `userMessage`, and which door that is. */
131+
const DOORS = [
132+
{ tool: 'run_action', door: '/actions', args: { actionName: 'submit', objectName: OBJECT, recordId: RECORD_ID } },
133+
{ tool: 'resume_run', door: '/actions', args: { runId: 'run_1', values: {} } },
134+
{ tool: 'create_record', door: '/data', args: { objectName: OBJECT, data: { status: 'submitted' } } },
135+
{ tool: 'update_record', door: '/data', args: { objectName: OBJECT, recordId: RECORD_ID, data: { status: 'submitted' } } },
136+
{ tool: 'delete_record', door: '/data', args: { objectName: OBJECT, recordId: RECORD_ID, confirm: true } },
137+
] as const;
138+
139+
function relayOf(listed: Listed): string {
140+
return `${REFUSAL_REASONS_RELAY_LEAD}${[...listed.lines.map((line) => line.message), listed.closing].join('\n')}`;
141+
}
142+
143+
describe('MCP tools: a refusal with several declared reasons names every line, whole and in order (#37416)', () => {
144+
for (const door of DOORS) {
145+
it(`${door.tool} (${door.door}): every line rides as a second text block, the closing line last; the envelope is unchanged`, async () => {
146+
const listed = await callOverHttp(refusingBridge(listedRefusal(TWO)), door.tool, door.args);
147+
const unlisted = await callOverHttp(refusingBridge(listedRefusal(TWO, { withList: false })), door.tool, door.args);
148+
149+
expect(listed.content).toHaveLength(2);
150+
// The envelope is the door's, byte for byte: the same as for the throw without a list.
151+
expect(unlisted.content).toHaveLength(1);
152+
expect(listed.content[0]).toEqual(unlisted.content[0]);
153+
expect(JSON.parse(listed.content[0].text).error).toMatchObject({ status: 400, declaredCode: CODE });
154+
expect(listed.content[1]).toEqual({ type: 'text', text: relayOf(TWO) });
155+
});
156+
157+
it(`${door.tool} (${door.door}): a single-reason refusal reads as today, one block and no relay`, async () => {
158+
const single: Listed = { lines: [], closing: 'pin37416 Taxi 12 is already on another report.' };
159+
const { content } = await callOverHttp(
160+
refusingBridge(listedRefusal(single, { withList: false, userMessage: single.closing })), door.tool, door.args,
161+
);
162+
expect(content).toHaveLength(1);
163+
expect(JSON.parse(content[0].text).error.userMessage).toBe(single.closing);
164+
});
165+
}
166+
167+
it('create_record: a list long enough that /data cuts userMessage at 500 still names every line whole, and the closing line', async () => {
168+
const lines = Array.from({ length: 6 }, (_, i) => ({
169+
reason: 'on_report',
170+
message: `pin37416 Expense line ${i + 1} (${'x'.repeat(90)}) is already on another report.`,
171+
}));
172+
const long: Listed = { lines, closing: CLOSING };
173+
const whole = [...lines.map((line) => line.message), CLOSING].join('\n');
174+
expect(whole.length).toBeGreaterThan(500);
175+
176+
const { content } = await callOverHttp(refusingBridge(listedRefusal(long)), 'create_record', DOORS[2].args);
177+
178+
expect(content).toHaveLength(2);
179+
const served = JSON.parse(content[0].text).error.userMessage as string;
180+
// The door's bound: the envelope's userMessage is cut and has lost the closing line.
181+
expect(served.length).toBeLessThanOrEqual(500);
182+
expect(served).not.toContain(CLOSING);
183+
expect(served).not.toBe(whole);
184+
// The relay: every line whole, in order, the closing line last.
185+
expect(content[1].text).toBe(relayOf(long));
186+
const relayed = content[1].text.slice(REFUSAL_REASONS_RELAY_LEAD.length).split('\n');
187+
expect(relayed).toEqual([...lines.map((line) => line.message), CLOSING]);
188+
});
189+
190+
it('control: a PERMISSION_DENIED answer carrying a list gets no relay (the #7450 withholding)', async () => {
191+
for (const door of DOORS) {
192+
const { content } = await callOverHttp(
193+
refusingBridge(listedRefusal(TWO, { code: 'PERMISSION_DENIED', status: 403 })), door.tool, door.args,
194+
);
195+
expect(content, door.tool).toHaveLength(1);
196+
expect(JSON.parse(content[0].text).error.code, door.tool).toBe('PERMISSION_DENIED');
197+
}
198+
});
199+
200+
it('control: a list the shared recogniser does not read gets no relay', async () => {
201+
for (const refusals of [[], [{ reason: 'on_report' }], [{ reason: 'on_report', message: 7 }], 'on_report']) {
202+
const { content } = await callOverHttp(
203+
refusingBridge(listedRefusal(TWO, { refusals })), 'update_record', DOORS[3].args,
204+
);
205+
expect(content, JSON.stringify(refusals)).toHaveLength(1);
206+
}
207+
});
208+
209+
it('control: a userMessage that does not begin with the listed lines gets no invented closing line', async () => {
210+
const { content } = await callOverHttp(
211+
refusingBridge(listedRefusal(TWO, { userMessage: 'pin37416 something else entirely' })), 'run_action', DOORS[0].args,
212+
);
213+
expect(content).toHaveLength(2);
214+
expect(content[1].text).toBe(`${REFUSAL_REASONS_RELAY_LEAD}${LINE_ON_REPORT}\n${LINE_APPROVED}`);
215+
});
216+
});

0 commit comments

Comments
 (0)