Skip to content

Commit 2fc3861

Browse files
fix(types): an undeclared hook abort answers HOOK_ABORTED on package publish and the runtime /actions doors (#27898)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} --> _Requested by **Elon** · [project thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DNWHtgDxNLpTCKKRCiYAQZ8)_ Fixes #27672 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:钩子用自由文本中止写入且没声明错误码时,包发布与 runtime `/actions` 两类门现在也答 `HOOK_ABORTED`,与 `/api/v1/data` 一致,不再答 `VALIDATION_ERROR`。 - 为什么改:#27597 只让 `/data` 答 `HOOK_ABORTED`,其它从 `resolveThrownHttpError` 取码的门仍按 400 推导,客户端按码分支时得先知道是哪个门。 - 风险与回滚:只换这一种中止的码(状态、文案不变);声明了码的照旧,崩溃仍是 500。回滚即 revert 本 PR。 - 先看:`packages/types/src/thrown-http-error.ts`(`undeclaredHookAbort` 一段)、`packages/types/src/data-error-classification.ts`(搬出 `sandboxBusinessMessage`)、`packages/runtime/src/domains/actions-undeclared-hook-abort-code.test.ts`。 - 两分钟验证:`pnpm --filter @objectstack/runtime exec vitest run src/domains/actions-undeclared-hook-abort-code.test.ts`,预期 7 个全绿。 - 需要你做的:无,席位落地。 ## What changes - `resolveThrownHttpError` (`@objectstack/types`) now answers `UNDECLARED_HOOK_REFUSAL_CODE` (`HOOK_ABORTED`) for a sandboxed body's refusal that declared no code, at a 4xx status. It is the one constant `/api/v1/data` has read since #27597, now declared beside the resolver; `sandboxRefusalCodeFields` reads the same constant. - So the doors that take their code from the resolver answer the same code as `/data`: `POST /api/v1/packages/publish` (`@objectstack/rest`, `sendThrownError`) and the runtime `/actions` doors (`errorFromThrown`). No route source changes; both already call the resolver. - `sandboxBusinessMessage` (with its private `isScriptFaultMessage`) moved verbatim to `packages/types/src/sandbox-business-message.ts`: `data-error-classification.ts` imports `thrown-http-error.ts`, so the resolver could not read it from there without a cycle. `data-error-classification.ts` re-exports it, so `@objectstack/types` exports the same names as before. The platform-checklist anchor for it follows the move. - Unchanged: a declared code is kept (registered → its own `code`; unregistered → `declaredCode` beside the derived `code`); `declaredCode` stays absent for an undeclared abort; a non-sandbox producer, a crash, and a sandboxed refusal resolved at a 5xx answer as before. ## Tests - New: `packages/types/src/thrown-http-error-undeclared-hook-abort.test.ts` (resolver, §1 the card, §2 controls), `packages/rest/src/package-door-undeclared-hook-abort-code.test.ts` (publish door), `packages/runtime/src/domains/actions-undeclared-hook-abort-code.test.ts` (`/actions`: an action body's throw, a hook abort relayed through an action body, a declared 4xx status; controls). - Flipped on purpose from `VALIDATION_ERROR` to `HOOK_ABORTED`, each with a `[#27672] FLIPPED` note: the publish row of `rest-write-route-hook-refusal-sentence.ledger.test.ts`; the four rows of `actions-hook-refusal-sentence.ledger.test.ts`; `nested-hook-refusal-is-a-rejection.test.ts` ("matches /data", which it does again); the thrown-Error control in `sandbox-plain-object-throw-client-sentence.test.ts`; `throw ''` and `throw Object.create(null)` in `sandbox-unreadable-rejection-door.test.ts`. ## Acceptance notes - Premise measured: the dispatch placed `resolveThrownHttpError` in `packages/rest/src/error-response.ts`; it is defined in `packages/types/src/thrown-http-error.ts` (rest imports it). The fix is there, per the ruling ("`resolveThrownHttpError` answers `HOOK_ABORTED`"); the seat amended the claim's file surface. `logUnexpectedRouteError` (#27508) is untouched. - The wrapper fallback in `classifyDataError` (an abort whose `SandboxError` instance was lost, no `innerMessage`) keeps answering the constant through `sandboxRefusalCodeFields`, because the resolver has no marker to read there. ## Verification <details><summary>Ablation (resolver arm removed, types rebuilt) → restore</summary> - Ablated: types new pin 2 failed / 6 passed; rest (new publish pin + publish ledger row + /data pins) 3 failed / 603 passed, the `/data` pins staying green; runtime (5 touched files) 11 failed / 21 passed. Every control stayed green. - Restored + rebuilt: types 8/8, rest 606/606, runtime 32/32. </details> <details><summary>Suites on the final tree (after merging main)</summary> - `@objectstack/types`: Test Files 32 passed, Tests 817 passed. - `@objectstack/rest`: Test Files 353 passed, Tests 7025 passed | 350 skipped. - `@objectstack/runtime`: Test Files 484 passed, Tests 8784 passed | 19 skipped. - Other readers of the resolver's code, before the merge: `@objectstack/metadata-protocol` 21822 passed | 26 skipped, `@objectstack/service-automation` 2795 passed, `@objectstack/plugin-hono-server` 448 passed, `@objectstack/cloud-connection` 758 passed. No pin moved there. </details> <details><summary>Gates</summary> - `node scripts/pm/dispatch-gates.mjs --ran`: 64 derived families accounted for — 63 run (exit 0), 1 NOT MEASURED: `pnpm check:dual-build-cjs-loads` exit 3 (needs every package's dist; CI builds the whole tree). - `pnpm lint`: exit 0. - `check-governed-merges --test` on the touched paths: NOT governed. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_016WV4d1iG6EQSWf7veWbAar)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_016WV4d1iG6EQSWf7veWbAar Co-authored-by: Claude <noreply@anthropic.com>
1 parent d8de26d commit 2fc3861

13 files changed

Lines changed: 497 additions & 126 deletions
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@objectstack/types': patch
3+
'@objectstack/rest': patch
4+
'@objectstack/runtime': patch
5+
---
6+
7+
fix(types): a hook that aborts with free text answers `HOOK_ABORTED` on package publish and the runtime `/actions` doors too, not `VALIDATION_ERROR`
8+
9+
Clause-②: no
10+
Metadata-protocol: none
11+
12+
- **Before.** Since #27597 a sandboxed body that aborts with free text (`throw new Error('…')`, no `code`) answers `/api/v1/data` with `HOOK_ABORTED`. The doors that take their code from `resolveThrownHttpError` (`@objectstack/types`) instead of from the `/data` classification still answered the same abort with the code its `400` derives, `VALIDATION_ERROR`, so a client branching on the code had to know which door the abort came through.
13+
- **Now.** `resolveThrownHttpError` answers `UNDECLARED_HOOK_REFUSAL_CODE` (`HOOK_ABORTED`) for a sandboxed body's refusal that declared no code, at a 4xx status. It is the one constant `/data` already reads, now declared beside the resolver. The value moves, from `VALIDATION_ERROR` to `HOOK_ABORTED`, on these doors:
14+
- `POST /api/v1/packages/publish` (`@objectstack/rest`);
15+
- the runtime `/actions` doors: `POST /api/v1/actions/:object/:action`, `POST /api/v1/actions/:object/:action/:recordId`, `POST /api/v1/actions/global/:action` and `POST /api/v1/actions//:action`, for an action body's own free-text throw, a hook abort relayed through an action body, and an action body's unreadable rejection (`throw ''`, `throw Object.create(null)`) (`@objectstack/runtime`).
16+
- **Unchanged.** A code the body declared is kept: a registered code is still its own wire `code`, and an unregistered one (a `refusals` catalogue entry) still rides `declaredCode` beside the status-derived `code`. `declaredCode` stays absent for an undeclared abort. A producer that is not a sandboxed body still derives its code from the status, a crashed body is still the sanitised `500 INTERNAL_ERROR`, and a sandboxed refusal resolved at a 5xx keeps the fault's code. `/api/v1/data` answers exactly as before.
17+
- **Moved, not added.** No error code is added; `HOOK_ABORTED` is the one #27597 registered. `sandboxBusinessMessage` moved to its own module so the resolver can read it without an import cycle; `@objectstack/types` exports the same names as before.

‎docs/qa/platform-checklist/areas/api-backend.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3307,7 +3307,7 @@
33073307
"ref": "packages/rest/src/rest-write-route-hook-refusal-sentence.ledger.test.ts + packages/rest/src/rest-hook-script-fault-envelope.test.ts + packages/runtime/src/dispatcher-unique-violation-wire-code.test.ts + packages/services/service-storage/src/storage-routes.server-fault-withheld.test.ts (acceptance[0], unit and engine) + packages/qa/dogfood/test/error-sentences-live.dogfood.test.ts (acceptance[1]–[3] over HTTP on the scratch app packages/qa/dogfood/test/fixtures/error-sentences-fixture.ts: the hook's sentence at 400 with no code on the /data doors, 409 UNIQUE_VIOLATION with details exactly developerMessage + object at the action door, and a storage route's 500 INTERNAL withholding the caught text)"
33083308
},
33093309
"source": [
3310-
"packages/types/src/data-error-classification.ts#sandboxBusinessMessage",
3310+
"packages/types/src/sandbox-business-message.ts#sandboxBusinessMessage",
33113311
"packages/types/src/data-error-classification.ts#isSandboxOwnFault",
33123312
"packages/types/src/response-envelope.ts#sendServerFault",
33133313
"packages/runtime/src/http-dispatcher.ts",
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [#27672] `POST /api/v1/packages/publish` answers a sandboxed hook's
5+
* undeclared abort with `HOOK_ABORTED`, the code `/api/v1/data` has answered
6+
* since #27597, instead of the `VALIDATION_ERROR` its 400 derives.
7+
*
8+
* This door does not answer from the `/data` classification: `sendThrownError`
9+
* (`package-routes.ts`) takes the status from it and the CODE from
10+
* `resolveThrownHttpError` (`@objectstack/types`). The resolver now answers
11+
* `UNDECLARED_HOOK_REFUSAL_CODE` for a sandboxed refusal that declared no code,
12+
* so this door reads the one rule rather than a copy of it. §2 is the control:
13+
* a code the body declared is kept, and a plain 400 with no code still derives
14+
* `VALIDATION_ERROR`.
15+
*/
16+
17+
import { describe, it, expect } from 'vitest';
18+
import { ApiErrorSchema } from '@objectstack/spec/api';
19+
import type { RouteHandler } from '@objectstack/spec/contracts';
20+
import { UNDECLARED_HOOK_REFUSAL_CODE } from '@objectstack/types';
21+
import { registerPackageRoutes } from './package-routes.js';
22+
23+
const PUBLISH = 'POST:/api/v1/packages/publish';
24+
const BODY = { manifest: { id: 'com.acme.crm', version: '1.0.0' }, metadata: {} };
25+
26+
/** The shape `runtime/src/sandbox/quickjs-runner.ts` throws for a body's own `throw`. */
27+
function sandboxRefusal(businessMessage: string, extra: Record<string, unknown> = {}) {
28+
const err: any = new Error(`hook 'guard' threw: Error: ${businessMessage}`);
29+
err.name = 'SandboxError';
30+
err.innerMessage = businessMessage;
31+
return Object.assign(err, extra);
32+
}
33+
34+
async function publishRejectingWith(error: unknown): Promise<{ status: number; body: any }> {
35+
const routes = new Map<string, RouteHandler>();
36+
const server = {
37+
get: () => {},
38+
post: (p: string, h: RouteHandler) => { routes.set(`POST:${p}`, h); },
39+
put: () => {}, delete: () => {}, patch: () => {}, use: () => {},
40+
listen: async () => {}, close: async () => {},
41+
} as any;
42+
const svc = { publish: async () => { throw error; } };
43+
registerPackageRoutes(server, () => svc as any, '/api/v1', {
44+
resolveExecutionContext: async () => ({
45+
userId: 'u_pkg',
46+
systemPermissions: ['manage_metadata', 'studio.access', 'setup.access'],
47+
}),
48+
} as any);
49+
const captured = { status: 0, body: undefined as any };
50+
const res: any = {
51+
json(data: any) { captured.body = data; },
52+
send() {},
53+
status(code: number) { captured.status = code; return res; },
54+
header() { return res; },
55+
};
56+
await routes.get(PUBLISH)!(
57+
{ params: {}, query: {}, headers: {}, method: 'POST', path: '/api/v1/packages/publish', body: BODY } as any,
58+
res,
59+
);
60+
return captured;
61+
}
62+
63+
describe('[#27672] §1 an undeclared hook abort answers HOOK_ABORTED at package publish', () => {
64+
it('400, the hook\'s own sentence, and the code /data answers', async () => {
65+
const { status, body } = await publishRejectingWith(sandboxRefusal('Publishing is frozen.'));
66+
expect(status).toBe(400);
67+
expect(body.error.code).toBe('HOOK_ABORTED');
68+
expect(body.error.code).toBe(UNDECLARED_HOOK_REFUSAL_CODE);
69+
expect(body.error.message).toBe('Publishing is frozen.');
70+
// The body declared no code, so none is reported as declared.
71+
expect(body.error).not.toHaveProperty('declaredCode');
72+
expect(ApiErrorSchema.safeParse(body.error).success).toBe(true);
73+
});
74+
75+
it('a 4xx status the body declared without a code keeps the status', async () => {
76+
const { status, body } = await publishRejectingWith(sandboxRefusal('Frozen.', { status: 422 }));
77+
expect(status).toBe(422);
78+
expect(body.error.code).toBe('HOOK_ABORTED');
79+
});
80+
});
81+
82+
describe('[#27672] §2 CONTROLS — a declared code is kept; nothing is invented elsewhere', () => {
83+
it('a registered code the body declared is its own code', async () => {
84+
const { status, body } = await publishRejectingWith(sandboxRefusal('Locked.', { code: 'RECORD_LOCKED', status: 409 }));
85+
expect(status).toBe(409);
86+
expect(body.error.code).toBe('RECORD_LOCKED');
87+
});
88+
89+
it('an unregistered code the body declared rides declaredCode beside the derived code', async () => {
90+
const { body } = await publishRejectingWith(sandboxRefusal('Over the limit.', { code: 'CREDIT_LIMIT', status: 400 }));
91+
expect(body.error.code).toBe('VALIDATION_ERROR');
92+
expect(body.error.declaredCode).toBe('CREDIT_LIMIT');
93+
});
94+
95+
it('a non-sandbox producer that declared a 400 and no code still derives VALIDATION_ERROR', async () => {
96+
const { status, body } = await publishRejectingWith(Object.assign(new Error('Manifest is invalid.'), { status: 400 }));
97+
expect(status).toBe(400);
98+
expect(body.error.code).toBe('VALIDATION_ERROR');
99+
});
100+
});

‎packages/rest/src/rest-write-route-hook-refusal-sentence.ledger.test.ts‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,6 @@ const IMPORT_BODY = { format: 'json', rows: [{ name: 'x' }] };
277277
const importRow = (res: any) => res.body?.results?.[0]?.error;
278278
const jobRow = async (_res: any, b: Booted) => (await terminalJobPatch(b)).results?.items?.[0]?.error;
279279

280-
/**
281-
* [#22719] An undeclared refusal re-dressed in the nested envelope: the code
282-
* the classification leaves out is the catalog's own floor for `400`.
283-
*/
284-
const REFUSED_400 = { status: 400, code: 'VALIDATION_ERROR' } as const;
285-
286280
/**
287281
* [#27597] The same refusal where the family re-dresses the `/data` door's
288282
* classification whole: a sandboxed hook's undeclared abort answers the
@@ -373,8 +367,11 @@ const ANSWERS_THE_SENTENCE: Record<string, Driver> = {
373367
'POST /api/v1/approvals/requests/:id/comment': { called: 'approvals.comment', body: {}, answers: HOOK_ABORTED_400 },
374368
// Package publish: the classification decides the status the door falls
375369
// back to, the shared read the sentence. Was `500 INTERNAL_ERROR`.
370+
// [#27672] FLIPPED on purpose from `400 VALIDATION_ERROR`: the door's code
371+
// is `resolveThrownHttpError`'s, which now answers an undeclared hook abort
372+
// `HOOK_ABORTED`, the code `/data` answers.
376373
'POST /api/v1/packages/publish': {
377-
called: 'service:package.publish', answers: REFUSED_400,
374+
called: 'service:package.publish', answers: HOOK_ABORTED_400,
378375
body: { manifest: { id: 'p1', version: '1.0.0' }, metadata: {} },
379376
},
380377
// External datasources: the shared read only, so status and code are this

‎packages/runtime/src/domains/actions-hook-refusal-sentence.ledger.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ describe('[#22588] the /actions ledger rows, each driven with a real nested hook
136136
expect(executeAction).toHaveBeenCalled();
137137
expect(res.response.status).toBe(400);
138138
expect(res.response.body.success).toBe(false);
139-
expect(res.response.body.error.code).toBe('VALIDATION_ERROR');
139+
// [#27672] FLIPPED on purpose from `VALIDATION_ERROR`: an undeclared
140+
// abort answers `HOOK_ABORTED` here, the code `/data` answers.
141+
expect(res.response.body.error.code).toBe('HOOK_ABORTED');
140142
// The wording IS the defect here, so the sentence is asserted whole.
141143
expect(res.response.body.error.message).toBe(REFUSAL);
142144
expect(JSON.stringify(res.response.body)).not.toMatch(/threw:|hook '/);
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* [#27672] The runtime `/actions` door answers a sandboxed body's undeclared
5+
* abort with `HOOK_ABORTED`, the code `/api/v1/data` has answered since
6+
* #27597, instead of the `VALIDATION_ERROR` its 400 derives.
7+
*
8+
* The door's catch hands a rejection to `errorFromThrown`
9+
* (`http-dispatcher.ts`), whose code is `resolveThrownHttpError`'s
10+
* (`@objectstack/types`). The resolver now answers
11+
* `UNDECLARED_HOOK_REFUSAL_CODE` for a sandboxed refusal that declared no code,
12+
* so this door reads the one rule rather than a copy of it. §2 is the control:
13+
* a code the body declared is kept, a registered handler's plain rejection
14+
* still derives `VALIDATION_ERROR`, and a crash is still the sanitised 500.
15+
*/
16+
17+
import { describe, it, expect, vi } from 'vitest';
18+
import { UNDECLARED_HOOK_REFUSAL_CODE } from '@objectstack/types';
19+
20+
import { HttpDispatcher } from '../http-dispatcher.js';
21+
import { SandboxError } from '../sandbox/quickjs-runner.js';
22+
23+
const scriptAction = {
24+
name: 'submit_signoff',
25+
objectName: 'crm_invoice',
26+
type: 'script',
27+
body: { language: 'js', source: 'return 1;', capabilities: ['api.write'] },
28+
};
29+
30+
/** A dispatcher whose action handler rejects with `thrown`. */
31+
function makeDispatcher(thrown: unknown) {
32+
const objectDef = { name: 'crm_invoice', actions: [scriptAction] };
33+
const ql: any = {
34+
executeAction: vi.fn(async () => { throw thrown; }),
35+
getSchema: (n: string) => (n === objectDef.name ? objectDef : undefined),
36+
registry: { getObject: (n: string) => (n === objectDef.name ? objectDef : undefined), getItem: () => undefined },
37+
find: vi.fn(async () => [{ id: 'inv_1', status: 'draft' }]),
38+
insert: vi.fn(), update: vi.fn(), delete: vi.fn(),
39+
};
40+
const metadata: any = {
41+
load: vi.fn(async () => null),
42+
listObjects: vi.fn(async () => [objectDef]),
43+
getObject: vi.fn(async () => objectDef),
44+
};
45+
const kernel: any = {
46+
context: {
47+
getService: (n: string) =>
48+
n === 'objectql' || n === 'data' ? ql : n === 'metadata' ? metadata : null,
49+
},
50+
};
51+
return new HttpDispatcher(kernel);
52+
}
53+
54+
async function invoke(thrown: unknown) {
55+
const res: any = await makeDispatcher(thrown).handleActions(
56+
'/crm_invoice/submit_signoff/inv_1',
57+
'POST',
58+
{},
59+
{ request: {}, environmentId: 'platform', executionContext: { userId: 'u1', systemPermissions: [] } } as any,
60+
);
61+
return res.response;
62+
}
63+
64+
describe('[#27672] §1 an undeclared abort answers HOOK_ABORTED at /actions', () => {
65+
it('the action body\'s own free-text throw', async () => {
66+
vi.spyOn(console, 'error').mockImplementation(() => {});
67+
const response = await invoke(
68+
new SandboxError("action 'submit_signoff' threw: Contact has no phone", 'Contact has no phone'),
69+
);
70+
expect(response.status).toBe(400);
71+
expect(response.body.error.code).toBe('HOOK_ABORTED');
72+
expect(response.body.error.code).toBe(UNDECLARED_HOOK_REFUSAL_CODE);
73+
expect(response.body.error.message).toBe('Contact has no phone');
74+
expect(response.body.error).not.toHaveProperty('declaredCode');
75+
});
76+
77+
it('a hook abort relayed through the action body (the nested refusal\'s shape)', async () => {
78+
vi.spyOn(console, 'error').mockImplementation(() => {});
79+
const response = await invoke(new SandboxError(
80+
"action 'submit_signoff' threw: hook 'guard' threw: Error: A finished invoice cannot be signed.",
81+
'A finished invoice cannot be signed.',
82+
));
83+
expect(response.status).toBe(400);
84+
expect(response.body.error.code).toBe('HOOK_ABORTED');
85+
expect(response.body.error.message).toBe('A finished invoice cannot be signed.');
86+
});
87+
88+
it('a 4xx status the body declared without a code keeps the status', async () => {
89+
vi.spyOn(console, 'error').mockImplementation(() => {});
90+
const response = await invoke(new SandboxError("action 'submit_signoff' threw: Closed.", 'Closed.', { status: 422 }));
91+
expect(response.status).toBe(422);
92+
expect(response.body.error.code).toBe('HOOK_ABORTED');
93+
});
94+
});
95+
96+
describe('[#27672] §2 CONTROLS — a declared code is kept; nothing is invented elsewhere', () => {
97+
it('a registered code the body declared is its own code', async () => {
98+
vi.spyOn(console, 'error').mockImplementation(() => {});
99+
const response = await invoke(new SandboxError(
100+
"action 'submit_signoff' threw: Locked.", 'Locked.', { code: 'RECORD_LOCKED', status: 409 },
101+
));
102+
expect(response.status).toBe(409);
103+
expect(response.body.error.code).toBe('RECORD_LOCKED');
104+
});
105+
106+
it('an unregistered code the body declared rides declaredCode beside the derived code', async () => {
107+
vi.spyOn(console, 'error').mockImplementation(() => {});
108+
const response = await invoke(new SandboxError(
109+
"action 'submit_signoff' threw: Over the limit.", 'Over the limit.', { code: 'CREDIT_LIMIT', status: 400 },
110+
));
111+
expect(response.status).toBe(400);
112+
expect(response.body.error.code).toBe('VALIDATION_ERROR');
113+
expect(response.body.error.declaredCode).toBe('CREDIT_LIMIT');
114+
});
115+
116+
it('a registered handler\'s plain rejection (no sandbox) still derives VALIDATION_ERROR', async () => {
117+
const response = await invoke(new Error('Lead is already converted'));
118+
expect(response.status).toBe(400);
119+
expect(response.body.error.code).toBe('VALIDATION_ERROR');
120+
});
121+
122+
it('a body that CRASHED is still the sanitised 500', async () => {
123+
vi.spyOn(console, 'error').mockImplementation(() => {});
124+
const response = await invoke(new SandboxError(
125+
"action 'submit_signoff' threw: TypeError: x is not a function", 'TypeError: x is not a function',
126+
));
127+
expect(response.status).toBe(500);
128+
expect(response.body.error.code).toBe('INTERNAL_ERROR');
129+
});
130+
});

‎packages/runtime/src/sandbox-plain-object-throw-client-sentence.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,10 @@ describe('[#23718] the action door answers a body\'s thrown plain object with it
201201
it('CONTROL — a thrown Error answers as before', async () => {
202202
const response = await postAction('throw_error');
203203
expect(response.status, JSON.stringify(response.body)).toBe(400);
204-
expect(response.body?.error?.code).toBe('VALIDATION_ERROR');
204+
// [#27672] FLIPPED on purpose from `VALIDATION_ERROR`: a thrown Error
205+
// with no code is an undeclared abort, answered `HOOK_ABORTED` as `/data`
206+
// answers it. The sentence is this control's subject and is unchanged.
207+
expect(response.body?.error?.code).toBe('HOOK_ABORTED');
205208
expect(response.body?.error?.message).toBe('x');
206209
});
207210
});

‎packages/runtime/src/sandbox-unreadable-rejection-door.test.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,18 @@ describe('[#23723] the action door answers an unreadable rejection at once, as a
128128
it("throw '': 400, the fixed sentence", async () => {
129129
const response = await postAction('throw_empty_string');
130130
expect(response.status, JSON.stringify(response.body)).toBe(400);
131-
expect(response.body?.error?.code).toBe('VALIDATION_ERROR');
131+
// [#27672] FLIPPED on purpose from `VALIDATION_ERROR`: the body declared
132+
// no code, so this is an undeclared abort, answered `HOOK_ABORTED`.
133+
expect(response.body?.error?.code).toBe('HOOK_ABORTED');
132134
expect(response.body?.error?.message).toBe(UNREADABLE);
133135
});
134136

135137
it('throw Object.create(null): 400, the fixed sentence', async () => {
136138
const response = await postAction('throw_null_proto');
137139
expect(response.status, JSON.stringify(response.body)).toBe(400);
138-
expect(response.body?.error?.code).toBe('VALIDATION_ERROR');
140+
// [#27672] FLIPPED on purpose from `VALIDATION_ERROR`: the body declared
141+
// no code, so this is an undeclared abort, answered `HOOK_ABORTED`.
142+
expect(response.body?.error?.code).toBe('HOOK_ABORTED');
139143
expect(response.body?.error?.message).toBe(UNREADABLE);
140144
});
141145
});

‎packages/runtime/src/sandbox/nested-hook-refusal-is-a-rejection.test.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,17 @@ describe('[#17265] a nested sandboxed hook refusal keeps its business message',
162162
expect(err.innerMessage).not.toContain('SandboxError:');
163163
});
164164

165-
it('the wire answer matches /data: 400 VALIDATION_ERROR with the sentence', async () => {
165+
it('the wire answer matches /data: 400 HOOK_ABORTED with the sentence', async () => {
166166
// /data answers this refusal `400` with `error.innerMessage` verbatim
167167
// (`error-response.ts`'s sandbox unwrap door, `declared ?? 400`). The
168168
// action route must not answer a second thing for one refusal.
169169
const response = await wireAnswer(await escapeOf(nestedHookRefusal));
170170

171171
expect(response.status).toBe(400);
172-
expect(response.body.error.code).toBe('VALIDATION_ERROR');
172+
// [#27672] FLIPPED on purpose from `VALIDATION_ERROR`, which /data
173+
// stopped answering in #27597: the undeclared abort is `HOOK_ABORTED`
174+
// at both doors now, so this pin matches /data again.
175+
expect(response.body.error.code).toBe('HOOK_ABORTED');
173176
// [#22588] `toBe`, not `toContain`: a `toContain` pin stayed green
174177
// while the wire carried the hook's debug wrapper in front of it.
175178
expect(response.body.error.message).toBe(REFUSAL);

0 commit comments

Comments
 (0)