Skip to content

Commit afba96e

Browse files
fix(runtime): an addressed /automation/:ns/:name/(runs|trigger) under an unserved verb answers the automation domain, as its bare path does (#33926)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Steedos** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbCpddLFmKzR39wJWZpkRMCi)_ Fixes #33026 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:独立服务器上,带命名空间地址的 `/automation/:ns/:name/runs`、`/automation/:ns/:name/trigger`、`/automation/trigger/:ns/:name` 收到不支持的方法时,改由自动化领域回答(与不带地址的同一路由一致),不再由传输层回答。 - 为什么改:同一路由因写法不同返回两种错误信封、两种 `Allow`;匿名调用者在带地址写法上拿到 405(暴露路由形状)而不是 401。 - 风险与回滚:只在调度器里多声明三条「领域决定所有方法」的路由;已服务的方法照旧;回滚即还原该 PR。 - 先看:`packages/runtime/src/dispatcher-plugin.ts` 新增的三行声明;`automation-every-verb.hono.integration.test.ts` 的新行与命名空间假数据。 - 两分钟验证:`pnpm --filter @objectstack/runtime exec vitest run src/automation-every-verb.hono.integration.test.ts`,预期 57/57 通过。 - 需要你做的:无,席位落地。 ## What changes - `registerAutomationRoutes` (`packages/runtime/src/dispatcher-plugin.ts`) declares three more patterns through `domainDecidesEveryVerb` (#24228's mechanism): GET `/automation/:ns/:name/runs`, POST `/automation/:ns/:name/trigger`, POST `/automation/trigger/:ns/:name`. These are the addressed shapes (ADR-0150 D5) of the bare rows that were already declared. A verb the router cannot route on them now reaches `dispatch()`, so the anonymous floor answers `401` and the domain's `automationRouteAllow` answers `405` with `Allow: GET` / `Allow: POST` in the dispatcher's envelope. - Measured before the change, on a real Hono socket at `1e65a389`: `DELETE /api/v1/automation/crm/send_digest/runs` answered `405`, `Allow: GET, HEAD`, with an `error.details` envelope, for a signed-in and an anonymous caller alike. The bare `DELETE /api/v1/automation/send_digest/runs` answered the domain's `405 Allow: GET` (signed in) and `401` (anonymous). The domain itself was never at fault: dispatched directly, the addressed shapes already answer its `405` (`automation-addressed-route.test.ts`). The gap was only the transport declaration. No edit to `runtime/src/domains/automation.ts`. ## Tests `automation-every-verb.hono.integration.test.ts` (both prefixes): - Added rows: DELETE / POST / PUT on `/automation/crm/send_digest/runs`, GET on `/automation/crm/send_digest/trigger` and GET on `/automation/trigger/crm/send_digest`. Each row has an anonymous `401` case and a signed-in domain `405` case. - Added controls: a served POST on both addressed triggers runs the flow; GET and DELETE on `/automation/no_such_ns/send_digest/runs` answer the dispatcher's `404 ROUTE_NOT_FOUND`. - `crm` is installed through an ObjectQL registry double answering the holder table the address reads. <details><summary>Ablation, one per declaration (scripts/ablation-replace.mjs, each restored to the HEAD blob with git diff HEAD empty)</summary> - Without `:ns/:name/runs`: `Tests 14 failed | 43 passed (57)`. The failures are every addressed `/runs` row on both prefixes, plus the no-namespace DELETE control. - Without `:ns/:name/trigger`: `Tests 4 failed | 53 passed (57)`. The failures are the anonymous and signed-in GET on `/automation/crm/send_digest/trigger`, on both prefixes. - Without `trigger/:ns/:name`: `Tests 4 failed | 53 passed (57)`. The failures are the anonymous and signed-in GET on `/automation/trigger/crm/send_digest`, on both prefixes. </details> ## Acceptance notes - Same behaviour on a `createHonoApp` host (catch-all): it already handed every verb to `dispatch()`. No change there. ## Verification Readings at `9bdd492b`, the head before the last `origin/main` merge. That merge brought no change to the three files here. - `pnpm --filter @objectstack/runtime typecheck`: exit 0. - `pnpm --filter @objectstack/runtime test`: `Test Files 603 passed (603) / Tests 10934 passed | 19 skipped`. - Direct dependents exercising the dispatcher on Hono: `@objectstack/http-conformance` test, `Test Files 20 passed / Tests 292 passed`. `@objectstack/client` `package-addressing.test.ts`, `83 passed`. - `automation-every-verb.hono.integration.test.ts`: `57 passed (57)`. - eslint on both touched `.ts` files: exit 0. - `dispatch-gates --commands`: 67 run, reconciled with `--ran` (67 derived, 67 run). 65 exit 0. Two NOT MEASURED on prerequisites: `check:dual-build-cjs-loads` needs a full `pnpm build`; `check:type-check-debt`'s inner build never got the lock. Final head `39826829` (merge of `origin/main`, which carries #33721 and #33844 in `packages/runtime`): the scoped re-check (closure build, runtime typecheck, the every-verb, addressed-route, contract-mounts, clone-mount and route-ledger suites) is NOT MEASURED. The shared verify lock was held by another worktree's run for over 27 minutes. CI's Test Core runs the package on this head. --- _Generated by [Claude Code](https://claude.ai/code/session_01QsR2jUZKdq3PK2Sab53cT3)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent de3538c commit afba96e

3 files changed

Lines changed: 73 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/runtime': patch
3+
---
4+
5+
fix(runtime): an addressed `/automation/:ns/:name/(runs|trigger)` route under a verb it does not serve answers the automation domain, as its bare path does
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
On the standalone server (the dispatcher plugin on an HTTP adapter), an address is served exactly as its bare path (ADR-0150 D5), but a verb the route is not served under was answered differently on the two. `DELETE /api/v1/automation/send_digest/runs` answered the automation domain's `405` with `Allow: GET` in the dispatcher's envelope, and `401 UNAUTHENTICATED` to an anonymous caller. `DELETE /api/v1/automation/crm/send_digest/runs` answered the transport's `405` with `Allow: GET, HEAD` and an `error.details` envelope, to an anonymous caller too. The same held for `POST` / `PUT` on the addressed `/runs`, `GET` on `/automation/NS/NAME/trigger` and `GET` on `/automation/trigger/NS/NAME`.
11+
12+
The dispatcher now declares those three addressed shapes as routes whose domain decides every verb, as it already did for their bare two-segment shapes. Each of them answers an anonymous caller `401`, and a signed-in caller the domain's `405` with the verbs the route serves (`Allow: GET` for `/runs`, `Allow: POST` for both triggers) in the dispatcher's envelope. A served verb on an address (`GET .../runs`, `POST .../trigger`) is unchanged, and so is a three-segment path whose first segment is no installed namespace: under an unserved verb it now answers the dispatcher's `404 ROUTE_NOT_FOUND`, as the same path does under `GET`.

‎packages/runtime/src/automation-every-verb.hono.integration.test.ts‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ import { createDispatcherPlugin } from './dispatcher-plugin.js';
2525
* `405` with the verbs it serves (`automationRouteAllow`, pinned against the
2626
* ledger in `route-ledger.conformance.test.ts`).
2727
*
28+
* An address is served exactly as its bare path (ADR-0150 D5), so the
29+
* addressed shapes of those rows (`/automation/:ns/:name/runs`,
30+
* `/automation/:ns/:name/trigger`, `/automation/trigger/:ns/:name`) are
31+
* declared too, and answer the same as their bare row: an anonymous caller
32+
* `401`, a signed-in one the domain's `405`. `crm` is an installed namespace
33+
* holding `send_digest` (an ObjectQL registry double answering the holder
34+
* table the address reads).
35+
*
2836
* The door is read off the body, as in `actions-every-verb.hono.integration.test.ts`:
2937
* the dispatcher's envelope fills `error.httpStatus` and carries no
3038
* `error.details`; the transport's fills `error.details` and no `httpStatus`.
@@ -42,8 +50,19 @@ const ROWS = [
4250
['/automation/send_digest/trigger', 'GET', 'POST'],
4351
['/automation/connectors/credential-refs', 'POST', 'GET'],
4452
['/automation/trigger/send_digest', 'GET', 'POST'],
53+
// The addressed shapes: three segments, the namespace `crm` in front of the name.
54+
['/automation/crm/send_digest/runs', 'DELETE', 'GET'],
55+
['/automation/crm/send_digest/runs', 'POST', 'GET'],
56+
['/automation/crm/send_digest/runs', 'PUT', 'GET'],
57+
['/automation/crm/send_digest/trigger', 'GET', 'POST'],
58+
['/automation/trigger/crm/send_digest', 'GET', 'POST'],
4559
] as const;
4660

61+
/** The installed namespace the addressed rows name, and the package holding `send_digest` under it. */
62+
const CRM = 'com.crm.pkg';
63+
const NAMESPACES: Record<string, string> = { [CRM]: 'crm' };
64+
const HOLDERS: Record<string, string[]> = { 'flow:send_digest': [CRM] };
65+
4766
/** Every flow name the automation double was asked to run. */
4867
const executed: string[] = [];
4968

@@ -67,6 +86,18 @@ function fakeAuthPlugin(): Plugin {
6786
return { success: true, output: {} };
6887
},
6988
});
89+
// The holder table the address reads: `crm` is installed and holds `send_digest`.
90+
const holdersOf = (type: string, name: string) => HOLDERS[`${type}:${name}`] ?? [];
91+
ctx.registerService('objectql', {
92+
registry: {
93+
getNamespaceOwners: (ns: string) => Object.keys(NAMESPACES).filter((id) => NAMESPACES[id] === ns),
94+
packageScopedHoldersOf: holdersOf,
95+
getPackageScopedItem: (type: string, name: string, packageId: string) =>
96+
(holdersOf(type, name).includes(packageId) ? { name, _packageId: packageId } : undefined),
97+
getEnvironmentScopedItem: () => undefined,
98+
getPackage: (id: string) => (NAMESPACES[id] ? { manifest: { id, namespace: NAMESPACES[id] } } : undefined),
99+
},
100+
});
70101
},
71102
};
72103
}
@@ -190,6 +221,27 @@ describe('every verb on a two-segment /api/v1/automation path reaches the automa
190221
expect(status, JSON.stringify(body)).toBe(200);
191222
expect(executed).toEqual(['send_digest']);
192223
});
224+
225+
// ── control: a first segment that is no installed namespace is no address — declined under every verb ──
226+
for (const method of ['GET', 'DELETE']) {
227+
it(`CONTROL — signed-in ${method} ${prefix}/automation/no_such_ns/send_digest/runs → the dispatcher's no-route 404, never a 405`, async () => {
228+
const { status, allow, body } = await call(method, `${prefix}/automation/no_such_ns/send_digest/runs`, true);
229+
230+
expect([status, allow]).toEqual([404, null]);
231+
expect(body?.error?.code).toBe('ROUTE_NOT_FOUND');
232+
});
233+
}
234+
235+
// ── control: the declarations hand only unserved verbs to the domain; a served verb on an address runs ──
236+
for (const shape of ['/automation/crm/send_digest/trigger', '/automation/trigger/crm/send_digest']) {
237+
it(`CONTROL — signed-in POST ${prefix}${shape} runs the addressed flow`, async () => {
238+
executed.length = 0;
239+
const { status, body } = await call('POST', `${prefix}${shape}`, true);
240+
241+
expect(status, JSON.stringify(body)).toBe(200);
242+
expect(executed).toEqual(['send_digest']);
243+
});
244+
}
193245
}
194246

195247
// ── the claim is narrow: a shape no mount matches stays the transport's 404 ──

‎packages/runtime/src/dispatcher-plugin.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,6 +2074,15 @@ export function createDispatcherPlugin(config: DispatcherPluginConfig = {}): Plu
20742074
domainDecidesEveryVerb('GET', `${base}/automation/:ns/:name`);
20752075
domainDecidesEveryVerb('GET', `${base}/automation/:name/runs`);
20762076
domainDecidesEveryVerb('GET', `${base}/automation/connectors/credential-refs`);
2077+
// An address is served exactly as its bare path (ADR-0150 D5),
2078+
// so the addressed shapes of the bare rows above are declared
2079+
// too: the addressed `/runs` list, `trigger` and legacy trigger.
2080+
// Left undeclared, a verb they are not served under was the
2081+
// transport's `405` (its envelope, `Allow: GET, HEAD`, and that
2082+
// answer ahead of an anonymous caller's `401`), not the domain's.
2083+
domainDecidesEveryVerb('GET', `${base}/automation/:ns/:name/runs`);
2084+
domainDecidesEveryVerb('POST', `${base}/automation/:ns/:name/trigger`);
2085+
domainDecidesEveryVerb('POST', `${base}/automation/trigger/:ns/:name`);
20772086
for (const { verb, pattern, readsBody, encode } of addressedAutomationRoutes) {
20782087
server![verb](`${base}${pattern}`, async (req: any, res: any) => {
20792088
try {

0 commit comments

Comments
 (0)