Skip to content

Commit 7a55ba4

Browse files
committed
fix(i18n): carry the hooks translation group through its exhaustive copies
The console's translation preview and loader group list, the i18n docs, the walk-parity fixture and the served hook property count move with the new group. Hook refusal pins read the declared code off declaredCode. Claude-Session: https://claude.ai/code/session_01WGufzfyVQuRsL6SRGuKCem Co-authored-by: Claude <noreply@anthropic.com>
1 parent 08af21e commit 7a55ba4

14 files changed

Lines changed: 51 additions & 17 deletions

File tree

‎.changeset/26170-hook-refusal-catalogue.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ feat(spec): a hook declares its refusal catalogue, and its body refuses by code,
1111
Clause-②: yes (widening)
1212
Metadata-protocol: added
1313

14-
A hook can now declare `refusals`: one entry per SCREAMING_SNAKE code, each with the `message` the user reads and an optional 4xx `status` (default `400`). A sandboxed `body` then refuses by code only: it throws an error carrying a declared `code`, and the body runner answers with the entry. The message is translated through `hooks.<hook>.refusals.<CODE>.message` in the caller's locale, the code reaches the caller's error envelope, and the status is the entry's. The body's own error text and `status` are not what the caller reads.
14+
A hook can now declare `refusals`: one entry per SCREAMING_SNAKE code, each with the `message` the user reads and an optional 4xx `status` (default `400`). A sandboxed `body` then refuses by code only: it throws an error carrying a declared `code`, and the body runner answers with the entry. The message is translated through `hooks.<hook>.refusals.<CODE>.message` in the caller's locale, the code reaches the caller's error envelope as `declaredCode` (beside the status's registered `code`), and the status is the entry's. The body's own error text and `status` are not what the caller reads.
1515

1616
- **Spec.** `HookSchema.refusals` (`HookRefusalSchema`: `message`, `status?`). A new `hooks` group on the translation bundle, `hooks.<hook>.refusals.<CODE>.message`, and `hookRefusalMessageKey`. `HookContext.session.locale` declares the caller's locale.
1717
- **Undeclared codes are refused loudly.** A code the body throws literally (`{ code: 'X' }`, or `e.code = 'X'; throw e`) that the catalogue does not declare fails the save at `body.source`. Any other undeclared code, and a throw with no code, is a `500` fault at run time that names the hook and the code. This applies only to a hook that declares `refusals`; a hook without one is answered exactly as before.

‎content/docs/protocol/kernel/i18n-standard.mdx‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,8 @@ Three rules the shape enforces, all of them closed since #4001:
406406

407407
- **The top level is the declared group set and nothing else** — `objects`,
408408
`picklists`, `apps`, `messages`, `globalActions`, `dashboards`, `datasets`,
409-
`reports`, `pages`, `flows`, `positions`, `permissions`, `metadataForms`,
410-
`settingsCommon`. A group invented beside them
409+
`reports`, `pages`, `flows`, `hooks`, `positions`, `permissions`,
410+
`metadataForms`, `settingsCommon`. A group invented beside them
411411
(`"account"`, `"fields"`, `"list"`, `"industries"`) is rejected **by name**
412412
at both authoring doors, with the group to use instead named in the
413413
rejection.
@@ -496,7 +496,7 @@ what the overlay writes back as the node's `title`.
496496
The contract is `t(key, locale, params?)` — the target locale is always passed
497497
explicitly, and the key itself is returned when no translation is found (there
498498
is no `defaultValue` option). The key is a **dot path into `TranslationData`**,
499-
so it starts at one of the fourteen declared groups.
499+
so it starts at one of the fifteen declared groups.
500500

501501
```typescript
502502
const i18n = kernel.getService('i18n');
@@ -1077,6 +1077,8 @@ beneath an action entry are judged the same way under either.
10771077
| `positions.{name}` | a position's `name`, declared, or an audience anchor (`everyone`, `guest`) |
10781078
| `permissions.{name}` | a permission set's `name`, declared |
10791079
| `reports.{name}` | a report's `name`, declared |
1080+
| `hooks.{hook}` | a hook's `name`, declared |
1081+
| `hooks.{hook}.refusals.{code}` | a code that hook's `refusals` declares |
10801082
| `flows.{flow}.screens.{node}` | the `id` of a `type: 'screen'` node in that flow, nodes nested in loop, parallel and try/catch regions included |
10811083
| `flows.{flow}.screens.{node}.fields.{field}` | a `config.fields[].name` on that screen — an object-form screen (`config.objectName`) declares none, and its input labels live under `objects.{objectName}.fields` |
10821084

‎content/docs/ui/translations.mdx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export default defineStack({
8787
| Page component copy, by component id | `pages.<name>.components.<id>.title` / `description` / `label` / `placeholder` / `emptyText` — reached under `regions[].components[]` and `slots.<slot>`, through `properties.children` and a `page:tabs` / `page:accordion` panel's `items[].children` |
8888
| Page tab labels (`page:tabs` items) | `pages.<name>.components.<tabsId>.items.<value>.label` — keyed by the tabs component's `id` and the item's `value`; an item without a `value` has no key (localize it with an inline locale map), and `page:accordion` panels have none |
8989
| Screen-flow wizards (flow label, screen headings and body text, screen field copy) | `flows.<flow>.label` / `flows.<flow>.screens.<node_id>.title` / `.description` / `.fields.<field>.label` / `.placeholder` / `.inlineHelpText` — a screen field's help text is `inlineHelpText`, the key the field itself declares, not `help`; see the boundary note below |
90+
| Hook refusal messages | `hooks.<hook>.refusals.<CODE>.message` — one per entry of the hook's `refusals` catalogue. A sandboxed hook body refuses by code, and the server answers the refusal with this message in the caller's locale, else the declared `message` |
9091
| Position label / description | `positions.<name>.label` / `description` — keyed by the position's `name`; overlaid on every served position, which is the list the console's position picker draws |
9192
| Permission-set label / description | `permissions.<name>.label` / `description` — the group is spelled as the stack spells the collection (`permissions[]`), keyed by the set's `name` |
9293
| Global actions, messages | `globalActions`, `messages` |

‎packages/metadata-protocol/src/protocol.meta-types-degenerate-derivation.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,10 @@ describe('#17501 — /meta/types serves a real schema for `action`, and moves no
341341
// `dashboard` 22 → 20 (`aria`, `performance`), `field` 80 → 79
342342
// (`conditionalRequired`), `flow` 24 → 22 (`template`, `active`), `skill`
343343
// 17 → 16 (`triggerPhrases`). The live sets are unchanged.
344+
// [#26170] `hook` 22 → 23: the declared refusal catalogue, `refusals`.
344345
const CARD_PROPERTY_COUNTS: Record<string, number> = {
345346
agent: 24, app: 22, dashboard: 20, dataset: 16, field: 79, flow: 22,
346-
hook: 22, object: 48, page: 26, position: 13, report: 21, skill: 16, tool: 14,
347+
hook: 23, object: 48, page: 26, position: 13, report: 21, skill: 16, tool: 14,
347348
};
348349

349350
it.each(Object.entries(CARD_PROPERTY_COUNTS))(

‎packages/runtime/src/sandbox/hook-refusal-catalogue.test.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ describe('[#26170] a declared code is answered with the catalogue entry', () =>
7171
expect(err).toBeInstanceOf(SandboxError);
7272
const wire = mapDataError(err, 'order');
7373
expect(wire.status).toBe(DEFAULT_HOOK_REFUSAL_STATUS);
74-
expect(wire.body.code).toBe('CREDIT_LIMIT');
74+
// An author's code is not an ADR-0112 registered one: the wire `code` is
75+
// the status's registered code, and the declared one rides beside it.
76+
expect(wire.body.code).toBe('VALIDATION_ERROR');
77+
expect(wire.body.declaredCode).toBe('CREDIT_LIMIT');
7578
expect(wire.body.userMessage).toBe(REFUSALS.CREDIT_LIMIT.message);
7679
// The body's own sentence is not what the caller reads.
7780
expect(JSON.stringify(wire.body)).not.toContain('internal detail');
@@ -83,7 +86,7 @@ describe('[#26170] a declared code is answered with the catalogue entry', () =>
8386
)(ctx()));
8487
const wire = mapDataError(err, 'order');
8588
expect(wire.status).toBe(409);
86-
expect(wire.body.code).toBe('ACCOUNT_ON_HOLD');
89+
expect(wire.body.declaredCode).toBe('ACCOUNT_ON_HOLD');
8790
expect(wire.body.userMessage).toBe('The account is on hold.');
8891
});
8992

@@ -112,7 +115,7 @@ describe('[#26170] a declared code is answered with the catalogue entry', () =>
112115

113116
it('`e.code = …; throw e` is the same refusal', async () => {
114117
const err = await rejectionOf(boundHook("const e = new Error('x'); e.code = 'CREDIT_LIMIT'; throw e;")(ctx()));
115-
expect(mapDataError(err, 'order').body.code).toBe('CREDIT_LIMIT');
118+
expect(mapDataError(err, 'order').body.declaredCode).toBe('CREDIT_LIMIT');
116119
});
117120
});
118121

@@ -142,7 +145,8 @@ describe('[#26170] what the body did not make passes through untouched', () => {
142145
)(ctx()));
143146
const wire = mapDataError(err, 'order');
144147
expect(wire.status).toBe(422);
145-
expect(wire.body.code).toBe('ANY_CODE');
148+
expect(wire.body.declaredCode).toBe('ANY_CODE');
149+
expect(wire.body.userMessage).toBeUndefined();
146150
});
147151

148152
it('a crash stays a crash', async () => {
@@ -185,7 +189,7 @@ describe('[#26170] what the body did not make passes through untouched', () => {
185189
} as any)!;
186190
const err = await rejectionOf(fn(ctx()));
187191
expect(mapDataError(err, 'order').status).toBe(409);
188-
expect(mapDataError(err, 'order').body.code).toBe('ACCOUNT_ON_HOLD');
192+
expect(mapDataError(err, 'order').body.declaredCode).toBe('ACCOUNT_ON_HOLD');
189193
});
190194
});
191195

‎packages/runtime/src/sandbox/hook-refusal-catalogue.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
* `message` — served as the error's caller-facing sentence (`innerMessage`)
1616
* and marked as the end user's (`userMessage`, the objectui#5210 opt-in);
1717
* - the status is the declared `status`, else 400;
18-
* - the code is the declared code, so the caller can branch on it.
18+
* - the code is the declared code — on the wire, `declaredCode` beside the
19+
* status's registered `code` — so the caller can branch on it.
1920
*
2021
* **Picked here, before the refusal leaves.** A hook refusal reaches the
2122
* caller already rendered — the error envelope every door builds from the

‎packages/spec/src/data/hook-refusal-codes.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525

2626
/**
2727
* The spelling of a declared refusal code: SCREAMING_SNAKE, the one wire
28-
* vocabulary of an error code (ADR-0112). The code a body throws is the
29-
* `code` the caller's envelope carries, so it is spelled as every other code a
30-
* client branches on.
28+
* vocabulary of an error code (ADR-0112). The code a body throws reaches the
29+
* caller's envelope (as `declaredCode`, beside the status's registered `code`),
30+
* so it is spelled as every other code a client branches on.
3131
*/
3232
export const HOOK_REFUSAL_CODE_PATTERN = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/;
3333

‎scripts/fixtures/i18n-walk-parity/every-group.stack.json‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,15 @@
173173
]
174174
}
175175
],
176+
"hooks": [
177+
{
178+
"name": "parity_guard",
179+
"object": "parity_object",
180+
"events": ["beforeInsert"],
181+
"body": { "language": "js", "source": "throw Object.assign(new Error('refused'), { code: 'PARITY_REFUSED' });" },
182+
"refusals": { "PARITY_REFUSED": { "message": "Parity records are refused." } }
183+
}
184+
],
176185
"positions": [
177186
{ "name": "parity_reviewer", "label": "Parity Reviewer", "description": "Reviews parity findings" }
178187
],

‎skills/objectstack-data/references/data-hooks.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,8 +1006,9 @@ defineHook({
10061006
});
10071007
```
10081008

1009-
- **Codes** are SCREAMING_SNAKE (`CREDIT_LIMIT`); the caller's error envelope
1010-
carries the code, so a client can branch on it.
1009+
- **Codes** are SCREAMING_SNAKE (`CREDIT_LIMIT`). The error envelope carries
1010+
it as `declaredCode`, beside the status's registered `code`
1011+
(`VALIDATION_ERROR` for 400), so a client can branch on it.
10111012
- **The message is translated** through
10121013
`hooks.<hook>.refusals.<CODE>.message` in the caller's locale; `os i18n
10131014
extract` scaffolds one key per declared entry and `os i18n check` counts them.

‎ui/packages/app-shell/src/views/metadata-admin/i18n.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,6 +1867,7 @@ const ENGINE_STRINGS_EN: Record<string, string> = {
18671867
'engine.translationPreview.category.reports': 'Reports',
18681868
'engine.translationPreview.category.pages': 'Pages',
18691869
'engine.translationPreview.category.flows': 'Flows',
1870+
'engine.translationPreview.category.hooks': 'Hooks',
18701871
'engine.translationPreview.category.positions': 'Positions',
18711872
'engine.translationPreview.category.permissions': 'Permission Sets',
18721873
'engine.translationPreview.category.metadataForms': 'Metadata Forms',
@@ -5143,6 +5144,7 @@ const ENGINE_STRINGS_ZH: Record<string, string> = {
51435144
'engine.translationPreview.category.reports': '报表',
51445145
'engine.translationPreview.category.pages': '页面',
51455146
'engine.translationPreview.category.flows': '流程',
5147+
'engine.translationPreview.category.hooks': '钩子',
51465148
'engine.translationPreview.category.positions': '岗位',
51475149
'engine.translationPreview.category.permissions': '权限集',
51485150
'engine.translationPreview.category.metadataForms': '元数据表单',

0 commit comments

Comments
 (0)