Skip to content

Commit e1fdaf8

Browse files
claude[bot]claude
andauthored
docs(api): state what projectResolution: 'required' serves for package routes, and pin the ruled mount shape (#17666)
* test(runtime): measure what an unscoped /packages reaches under projectResolution 'required' The escalation condition on this card asks whether the unconditionally mounted unscoped `/packages*` crosses an environment boundary on a `required` host. It does not, and this is the measurement. The unscoped mount supplies neither of `urlEnvironmentId`'s two sources, so the request names no environment of its own and is bound by the host resolver's documented order 2-6; the scoped URL is order 1, the stronger addressing primitive. Both mounts are the same handler behind the same `dispatch()` preamble, so the tenancy gate answers them identically: a non-member is refused `PROJECT_MEMBERSHIP_REQUIRED` before the domain on either, and a member reaches one byte-identical door. The fixture gives the two environments data planes that answer differently (registry-bearing vs registry-less), so the response itself names which environment served it -- and the positive control drives the same door, the same assertions and the same spies for a request the host DOES bind to another environment, so the no-leak legs are readings rather than a probe that could not have seen a crossing. Claude-Session: https://claude.ai/code/session_01TSf4DV7ziu4V5j73e46b7c Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * docs(api): stop claiming `required` scopes package routes, and pin the ruled mount shape `environment-routing.mdx` said `projectResolution: 'required'` registers only environment-scoped routes for data/meta/AI/automation/package handlers. Three of those four families are true of the dispatcher, and the REST `POST /packages/publish` registrar honours it too, but the dispatcher's `/packages*` bridge is mounted unscoped unconditionally and is ruled to stay that way -- the mount site records why, and a doc that over-claims is what set the operator's mental model. So the doc now states what the code does, with the isolation half stated beside it: an unscoped request names no environment, so it is resolved by the same order 2-6 and passes the same membership and capability gates as a scoped URL, and what `required` does not deliver for package routes is the URL guarantee rather than isolation. The mount pin turns the comment's "stays that way" into something a future tidy-up trips over. Reverse-verified: moving the unscoped call into the `required` branch reds exactly the three unscoped package cases (3 failed / 11 passed) while the scoped cases, the dropped-sibling controls and the binding measurement stay green; restore reproduces the HEAD blob byte-for-byte. Claude-Session: https://claude.ai/code/session_01TSf4DV7ziu4V5j73e46b7c Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4ecfd2b commit e1fdaf8

3 files changed

Lines changed: 481 additions & 1 deletion

File tree

content/docs/api/environment-routing.mdx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,26 @@ surface:
8989
|:---|:---|:---|
9090
| `auto` | Registers both unscoped `/api/v1/...` and scoped `/api/v1/environments/:environmentId/...` routes. | Default migration mode. |
9191
| `optional` | Same route surface as `auto`; resolution may come from URL, hostname, header, session, or default. | Multi-environment hosts that still accept unscoped callers. |
92-
| `required` | Registers only environment-scoped routes for data/meta/AI/automation/package handlers. | Hardened clients that always pass an environment id. |
92+
| `required` | Registers only environment-scoped routes for data/meta/AI/automation handlers, and for the REST `POST /packages/publish` route. The dispatcher's own `/packages*` bridge is the exception — it stays mounted unscoped too. | Hardened clients that always pass an environment id. |
93+
94+
<Callout type="warn">
95+
**`required` does not close the unscoped `/packages*` surface.** The dispatcher
96+
plugin mounts the package routes at the unscoped prefix unconditionally and adds
97+
the scoped mount beside it, so `GET`/`POST`/`PATCH`/`DELETE`
98+
`/api/v1/packages...` — the destructive lifecycle verbs included — stay served
99+
on a `required` host. The asymmetry with the automation / action / AI families
100+
is deliberate and recorded at the mount site
101+
(`packages/runtime/src/dispatcher-plugin.ts`): removing a mounted route surface
102+
is a different change, with a different blast radius, from adding a missing
103+
door.
104+
105+
It is not an isolation hole. An unscoped request names no environment, so it is
106+
resolved by steps 2–6 of the order below and is served by whichever environment
107+
that resolves to, behind the same project-membership and capability gates as the
108+
scoped URL — the scoped URL is step 1, the *stronger* way to address an
109+
environment, not a weaker one. What `required` does not give you for package
110+
routes is the guarantee that every caller has named an environment in the URL.
111+
</Callout>
93112

94113
---
95114

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* #17432 — the route surface `projectResolution: 'required'` actually serves.
5+
*
6+
* ## What is pinned, and why a pin rather than a repair
7+
*
8+
* Under `required` the dispatcher plugin drops the UNSCOPED mounts of
9+
* `registerAutomationRoutes` / `registerActionRoutes` / `registerAIRoutes`, and
10+
* keeps `/packages*` mounted unscoped as well as scoped. That asymmetry is
11+
* RULED, not an oversight: the mount site records it in full
12+
* (`dispatcher-plugin.ts`, beside the scoped package mount), because taking a
13+
* mounted route surface away is a different change with a different blast
14+
* radius than adding a missing door — #16781's residue under ruling C' on
15+
* #14503 step 2.
16+
*
17+
* A recorded decision that lives only in a comment is one a future "tidy-up"
18+
* has to NOTICE. This file is that decision expressed as a test: moving
19+
* `registerPackageRoutes(prefix)` into the `required` branch turns the first
20+
* case below red, and the reader is sent to the comment rather than to a
21+
* paragraph nobody read. The isolation half — that the unscoped door reaches no
22+
* other environment's package data, which is what makes keeping it safe — is
23+
* measured in `packages-unscoped-environment-binding.test.ts`.
24+
*
25+
* ## The composition, and the discriminator
26+
*
27+
* `plugin-hono-server` + the dispatcher, scoping on, `required`. No
28+
* `createHonoApp`, no `@objectstack/rest`, no service plugins — so nothing may
29+
* supply a second door and a mount is the only way in, exactly as in
30+
* `dispatcher-plugin.scoped-packages-door.integration.test.ts`, whose
31+
* discriminator this file reuses: a credential-less request that REACHES the
32+
* dispatcher is answered from the anonymous-deny floor (`ANONYMOUS_DENY_STATUS`
33+
* / `ANONYMOUS_DENY_CODE`, imported rather than spelled), a verdict no
34+
* transport-level sink emits, while a path no mount claims is answered by the
35+
* transport's own `notFound`. Both directions are measured below rather than
36+
* assumed, and the dropped sibling mounts are the second direction: they are
37+
* the reason "404 means unmounted" is a reading here.
38+
*
39+
* ⚠️ The `/ai` family is deliberately NOT among the dropped-mount cases. Its
40+
* dynamic routes arrive from `AIServicePlugin` through the `ai:routes` hook,
41+
* which this composition never fires, so an `/ai` 404 here would be silent
42+
* about `projectResolution` — it would be about the absent service plugin.
43+
* `registerAIRoutes`' own mounts sit on the same branch as automation and
44+
* actions; those two carry the case.
45+
*/
46+
47+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
48+
import { ANONYMOUS_DENY_CODE, ANONYMOUS_DENY_STATUS, LiteKernel } from '@objectstack/core';
49+
import { HonoServerPlugin } from '@objectstack/plugin-hono-server';
50+
import type { IHttpServer } from '@objectstack/spec/contracts';
51+
52+
import { createDispatcherPlugin } from './dispatcher-plugin.js';
53+
54+
const PREFIX = '/api/v1';
55+
const ENV_ID = 'env_alpha';
56+
const PKG_ID = 'com.acme.crm';
57+
58+
let kernel: LiteKernel | undefined;
59+
let baseUrl = '';
60+
61+
beforeAll(async () => {
62+
kernel = new LiteKernel();
63+
kernel.use(new HonoServerPlugin({ port: 0, cors: false }));
64+
kernel.use(createDispatcherPlugin({
65+
prefix: PREFIX,
66+
scoping: { enableProjectScoping: true, projectResolution: 'required' },
67+
enforceProjectMembership: false,
68+
securityHeaders: false,
69+
}));
70+
await kernel.bootstrap();
71+
const httpServer = kernel.getService<IHttpServer>('http.server');
72+
baseUrl = `http://127.0.0.1:${httpServer.getPort!()}`;
73+
}, 60_000);
74+
75+
afterAll(async () => {
76+
if (!kernel) return;
77+
await Promise.race([
78+
kernel.shutdown(),
79+
new Promise<void>((resolve) => setTimeout(resolve, 10_000)),
80+
]);
81+
}, 60_000);
82+
83+
async function probe(method: string, path: string): Promise<{ status: number; body: any }> {
84+
const res = await fetch(`${baseUrl}${path}`, { method });
85+
let body: any;
86+
try { body = await res.json(); } catch { body = undefined; }
87+
return { status: res.status, body };
88+
}
89+
90+
/** Did the DISPATCHER answer? Minted inside `dispatch()`, by nothing in the transport. */
91+
function dispatcherAnswered(r: { status: number; body: any }): boolean {
92+
return r.status === ANONYMOUS_DENY_STATUS && r.body?.error?.code === ANONYMOUS_DENY_CODE;
93+
}
94+
95+
/** The shape "no door answered" takes on this transport. */
96+
function transportRefused(r: { status: number; body: any }): boolean {
97+
const code = r.body?.error?.code;
98+
return r.status === 404 && (code === undefined || code === 'ROUTE_NOT_FOUND' || code === 'ENDPOINT_NOT_FOUND');
99+
}
100+
101+
const UNSCOPED = `${PREFIX}/packages`;
102+
const SCOPED = `${PREFIX}/environments/${ENV_ID}/packages`;
103+
104+
/** The package routes the card names, destructive verb included. */
105+
const PACKAGE_ROUTES: Array<[string, string]> = [
106+
['GET', ''],
107+
['GET', `/${PKG_ID}`],
108+
['DELETE', `/${PKG_ID}`],
109+
];
110+
111+
describe("#17432 — under `required`, /packages* stays mounted unscoped (ruled, not an oversight)", () => {
112+
for (const [method, sub] of PACKAGE_ROUTES) {
113+
it(`${method} ${UNSCOPED}${sub} is still served`, async () => {
114+
const r = await probe(method, `${UNSCOPED}${sub}`);
115+
expect(
116+
dispatcherAnswered(r),
117+
`${method} ${UNSCOPED}${sub} -> ${r.status} ${JSON.stringify(r.body)} — `
118+
+ 'the unscoped package mount is ruled to stay under `required`; see the mount-site '
119+
+ 'comment in dispatcher-plugin.ts before changing this',
120+
).toBe(true);
121+
}, 60_000);
122+
}
123+
124+
for (const [method, sub] of PACKAGE_ROUTES) {
125+
it(`${method} ${SCOPED}${sub} is served too — the scoped door is additive`, async () => {
126+
const r = await probe(method, `${SCOPED}${sub}`);
127+
expect(
128+
dispatcherAnswered(r),
129+
`${method} ${SCOPED}${sub} -> ${r.status} ${JSON.stringify(r.body)}`,
130+
).toBe(true);
131+
}, 60_000);
132+
}
133+
});
134+
135+
describe('#17432 — the siblings DO drop their unscoped mounts, which is what makes 404 a reading', () => {
136+
const DROPPED: Array<[string, string, string]> = [
137+
['GET', `${PREFIX}/automation/flows`, 'automation'],
138+
['POST', `${PREFIX}/actions/task/ping`, 'actions'],
139+
];
140+
141+
for (const [method, path, family] of DROPPED) {
142+
it(`${method} ${path} (${family}, unscoped) is NOT mounted under \`required\``, async () => {
143+
const r = await probe(method, path);
144+
expect(dispatcherAnswered(r)).toBe(false);
145+
expect(transportRefused(r), `${method} ${path} -> ${r.status} ${JSON.stringify(r.body)}`).toBe(true);
146+
}, 60_000);
147+
}
148+
149+
it('…while the same families ARE mounted scoped', async () => {
150+
const r = await probe('GET', `${PREFIX}/environments/${ENV_ID}/automation/flows`);
151+
expect(dispatcherAnswered(r), `scoped automation -> ${r.status} ${JSON.stringify(r.body)}`).toBe(true);
152+
}, 60_000);
153+
});

0 commit comments

Comments
 (0)