Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/33026-addressed-automation-every-verb.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@objectstack/runtime': patch
---

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

Clause-②: no
Metadata-protocol: none

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`.

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`.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ import { createDispatcherPlugin } from './dispatcher-plugin.js';
* `405` with the verbs it serves (`automationRouteAllow`, pinned against the
* ledger in `route-ledger.conformance.test.ts`).
*
* An address is served exactly as its bare path (ADR-0150 D5), so the
* addressed shapes of those rows (`/automation/:ns/:name/runs`,
* `/automation/:ns/:name/trigger`, `/automation/trigger/:ns/:name`) are
* declared too, and answer the same as their bare row: an anonymous caller
* `401`, a signed-in one the domain's `405`. `crm` is an installed namespace
* holding `send_digest` (an ObjectQL registry double answering the holder
* table the address reads).
*
* The door is read off the body, as in `actions-every-verb.hono.integration.test.ts`:
* the dispatcher's envelope fills `error.httpStatus` and carries no
* `error.details`; the transport's fills `error.details` and no `httpStatus`.
Expand All @@ -42,8 +50,19 @@ const ROWS = [
['/automation/send_digest/trigger', 'GET', 'POST'],
['/automation/connectors/credential-refs', 'POST', 'GET'],
['/automation/trigger/send_digest', 'GET', 'POST'],
// The addressed shapes: three segments, the namespace `crm` in front of the name.
['/automation/crm/send_digest/runs', 'DELETE', 'GET'],
['/automation/crm/send_digest/runs', 'POST', 'GET'],
['/automation/crm/send_digest/runs', 'PUT', 'GET'],
['/automation/crm/send_digest/trigger', 'GET', 'POST'],
['/automation/trigger/crm/send_digest', 'GET', 'POST'],
] as const;

/** The installed namespace the addressed rows name, and the package holding `send_digest` under it. */
const CRM = 'com.crm.pkg';
const NAMESPACES: Record<string, string> = { [CRM]: 'crm' };
const HOLDERS: Record<string, string[]> = { 'flow:send_digest': [CRM] };

/** Every flow name the automation double was asked to run. */
const executed: string[] = [];

Expand All @@ -67,6 +86,18 @@ function fakeAuthPlugin(): Plugin {
return { success: true, output: {} };
},
});
// The holder table the address reads: `crm` is installed and holds `send_digest`.
const holdersOf = (type: string, name: string) => HOLDERS[`${type}:${name}`] ?? [];
ctx.registerService('objectql', {
registry: {
getNamespaceOwners: (ns: string) => Object.keys(NAMESPACES).filter((id) => NAMESPACES[id] === ns),
packageScopedHoldersOf: holdersOf,
getPackageScopedItem: (type: string, name: string, packageId: string) =>
(holdersOf(type, name).includes(packageId) ? { name, _packageId: packageId } : undefined),
getEnvironmentScopedItem: () => undefined,
getPackage: (id: string) => (NAMESPACES[id] ? { manifest: { id, namespace: NAMESPACES[id] } } : undefined),
},
});
},
};
}
Expand Down Expand Up @@ -190,6 +221,27 @@ describe('every verb on a two-segment /api/v1/automation path reaches the automa
expect(status, JSON.stringify(body)).toBe(200);
expect(executed).toEqual(['send_digest']);
});

// ── control: a first segment that is no installed namespace is no address — declined under every verb ──
for (const method of ['GET', 'DELETE']) {
it(`CONTROL — signed-in ${method} ${prefix}/automation/no_such_ns/send_digest/runs → the dispatcher's no-route 404, never a 405`, async () => {
const { status, allow, body } = await call(method, `${prefix}/automation/no_such_ns/send_digest/runs`, true);

expect([status, allow]).toEqual([404, null]);
expect(body?.error?.code).toBe('ROUTE_NOT_FOUND');
});
}

// ── control: the declarations hand only unserved verbs to the domain; a served verb on an address runs ──
for (const shape of ['/automation/crm/send_digest/trigger', '/automation/trigger/crm/send_digest']) {
it(`CONTROL — signed-in POST ${prefix}${shape} runs the addressed flow`, async () => {
executed.length = 0;
const { status, body } = await call('POST', `${prefix}${shape}`, true);

expect(status, JSON.stringify(body)).toBe(200);
expect(executed).toEqual(['send_digest']);
});
}
}

// ── the claim is narrow: a shape no mount matches stays the transport's 404 ──
Expand Down
9 changes: 9 additions & 0 deletions packages/runtime/src/dispatcher-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2074,6 +2074,15 @@ export function createDispatcherPlugin(config: DispatcherPluginConfig = {}): Plu
domainDecidesEveryVerb('GET', `${base}/automation/:ns/:name`);
domainDecidesEveryVerb('GET', `${base}/automation/:name/runs`);
domainDecidesEveryVerb('GET', `${base}/automation/connectors/credential-refs`);
// An address is served exactly as its bare path (ADR-0150 D5),
// so the addressed shapes of the bare rows above are declared
// too: the addressed `/runs` list, `trigger` and legacy trigger.
// Left undeclared, a verb they are not served under was the
// transport's `405` (its envelope, `Allow: GET, HEAD`, and that
// answer ahead of an anonymous caller's `401`), not the domain's.
domainDecidesEveryVerb('GET', `${base}/automation/:ns/:name/runs`);
domainDecidesEveryVerb('POST', `${base}/automation/:ns/:name/trigger`);
domainDecidesEveryVerb('POST', `${base}/automation/trigger/:ns/:name`);
for (const { verb, pattern, readsBody, encode } of addressedAutomationRoutes) {
server![verb](`${base}${pattern}`, async (req: any, res: any) => {
try {
Expand Down
Loading