Skip to content

Commit f72f335

Browse files
fix(runtime): a dispatcher door is served only by the request's own kernel (#37897)
Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:托管多环境主机上,登录、评论、审批链接页、Webhook 重投、入站自动化钩子等入口只由本次请求所在环境自己的服务来处理;该环境没装对应插件时,入口如实回答"尚未提供"。单环境部署用户无感。 - 为什么做:加固多环境部署下这几个入口的服务归属规则。 - 出错会怎样:最坏是某环境里本应可用的入口回答"尚未提供",不会写错数据;改动小,可直接撤回。 - 要你做什么:无 ## What changes A dispatcher door is served only by the request's own kernel. - `packages/runtime/src/domains/own-door-bridge.ts` gains `readDoorSlot`, the reader dispatcher doors read their services through. It reads the slot off the request's own kernel (`getRequestKernelService`, the reader the personal-view, attachment and print bridges already used) and treats a lookup that throws as an empty slot. It carries the same two overloads `getRequestKernelService` has: a slot in `ServiceSlotContracts` reads as its contract, any other name as an untyped value the caller casts. - The auth door (`auth.ts`), the comment doors (`comments.ts`), the approval action page (`approvals.ts`), the webhook redeliver door (`webhooks.ts`) and the inbound automation hook (`automation-hooks.ts`) now read their member through it, and so does the engine that judges a qualified inbound hook's address. A request kernel without the slot answers the door's existing typed not-available answer, `501 NOT_IMPLEMENTED`, in the request's language, exactly as an empty slot already did. - The jsdoc of `getRequestKernelService` (`packages/runtime/src/domain-handler-registry.ts`) points doors at `readDoorSlot`. - On a host with one kernel the request's kernel is that kernel, so nothing changes there. First files to read, by risk: 1. `packages/runtime/src/domains/own-door-bridge.ts` — `readDoorSlot` and its overloads, the only new code path. 2. `packages/runtime/src/domains/automation-hooks.ts` — the two reader swaps in `handleInboundHookRequest` (the member, and the qualified hook's engine). 3. `packages/runtime/src/domains/own-door-bridge.test.ts` — the last top-level `describe`. ## Tests A top-level `describe` in `own-door-bridge.test.ts` (the door bridges' shared harness), "a dispatcher door is served only by the request's own kernel", driven through the real `HttpDispatcher.dispatch()` with a `kernel-resolver` that places each request on its own kernel: - for each of eight doors (auth, comments, approvals, webhooks, automation-hooks, personal-views, attachments, print), twice (a request kernel whose lookup throws, and one that answers nothing): the door answers `501 NOT_IMPLEMENTED` and a member registered elsewhere is never called (16 cases); - for each of the eight: with the slot on the request kernel, the request kernel's member serves the call (8 preservation cases); - a qualified inbound hook: a request kernel without the automation engine never consults another kernel's engine for the address, and with its own engine that engine judges it (2 cases); - the door net: every non-test module under `src/domains/` (any depth) that takes the transport's request whole (`context.request as Request`) or is built on the shared bridge body reads no service through `deps.resolveService`, `deps.resolveServiceOrLoud`, `deps.getService` or a `deps.getObjectQL` given an environment id, and each one that reads a slot itself reads it through `readDoorSlot`; the modules are found by scanning, with a floor of the nine shipped door modules. Not covered, and said so in the pin: a module that hands the request on some other way, and anything outside `src/domains/`. The pin also holds that the reader reads the request kernel's slot and nothing else. Reverse verification (each leg on the committed fix, mutated through `scripts/ablation-replace.mjs`, then restored and proved byte-identical to `HEAD`): - the qualified hook's engine read through its previous reader: 2 red (the engine pin and the door net), 75 green; - the auth door's member read through its previous reader: 1 red (the door net), 76 green; - earlier round: the four bridge member reads reverted, 9 red; `readDoorSlot` itself reading through another reader, 15 red. <details><summary>Readings</summary> Code head `bded79bb60a` (merge base with `origin/main`: `da21c49d9db`'s, unchanged this round): - `pnpm --workspace-concurrency=2 --filter '@objectstack/runtime^...' build && pnpm --filter @objectstack/runtime typecheck && pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2` over 11 files (`own-door-bridge`, `comments`, `approvals-act`, `webhooks-redeliver`, `automation-hooks`, `scoped-service-miss-attribution`, `domain-501-language-37811`, `http-dispatcher`, `auth-forward-fault-sanitization`, `domain-handler-registry`, `auth-claim-segment-boundary`) at `721702a2687`: build and typecheck exit 0, `Tests 538 passed` and 1 failed, the door net finding a refused-reader spelling in the reader's own jsdoc. The next commit (`bded79bb60a`, jsdoc and test-comment wording only) rewords it; `own-door-bridge.test.ts` there: `Tests 77 passed (77)`, lock VERDICT command-exit 0. - Reverse verification at `bded79bb60a`: engine leg `Tests 2 failed | 75 passed (77)`, auth leg `Tests 1 failed | 76 passed (77)`, each restored to the `HEAD` blob with `git diff HEAD` empty. - Derived gate families (`dispatch-gates.mjs --commands`, 67), re-run on a clean tree at `bded79bb60a`: 64 exit 0; three NOT MEASURED locally and left to CI: `check:dual-build-cjs-loads` (exit 3, it needs a full `pnpm build`), `check:query-options-erasure` and `check:type-check-debt` (stopped at a 300 s local cap on a shared box). `--ran` reconciliation: 67 derived, 67 run. - The full `@objectstack/runtime` suite was not run locally; `Test Core` runs it on this PR. </details> ## Acceptance notes - The preservation cases are green before and after the fix by design: they pin that the request kernel's own member keeps serving. - No shared-kernel (scoped-registration) mode is affected: every slot these doors read is registered as a plain singleton by its plugin. - The door net reads source text, so a door module whose comments spell one of the refused reader calls with its opening parenthesis also reds it; the shipped modules spell those names without one. ## Verification Two-minute check: `pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2 src/domains/own-door-bridge.test.ts` — expect `Tests 77 passed (77)`, with every case under "a dispatcher door is served only by the request's own kernel" passing. --- _Generated by [Claude Code](https://claude.ai/code/session_01ASNY8XNef4ywkQio6S9ju4)_ <!-- signed: security#1 · os-mickey · session_01ASNY8XNef4ywkQio6S9ju4 --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 58b513a commit f72f335

9 files changed

Lines changed: 250 additions & 33 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/runtime': patch
3+
---
4+
5+
fix(runtime): a dispatcher door is served only by the request's own kernel
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
Every dispatcher door bridge — the auth door, the comment doors, the approval action page, the webhook redeliver door, the inbound automation hook (including the engine that judges a qualified hook's address), and the personal-view, attachment and print doors — reads the services it serves with off the request's own kernel, and only there. When the request's kernel holds no such member, the door answers its typed not-available `501 NOT_IMPLEMENTED`, the same answer an empty slot already gave. On a host with one kernel nothing changes: the request's kernel is that kernel.

‎packages/runtime/src/domain-handler-registry.ts‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -283,18 +283,24 @@ export interface DomainHandlerDeps {
283283
getObjectQL(context: HttpProtocolContext, environmentId?: string): Promise<IObjectQLEngine | null>;
284284
/**
285285
* Service lookup on the request's RESOLVED (per-environment) kernel —
286-
* NOT the default kernel and NOT the scoped-factory path. Domains whose
287-
* data must live in the same store as their service bindings (e.g.
288-
* share-links: the token row and the shared record sit next to the
289-
* `shareLinks` service's engine) read through this and fall back to
290-
* `resolveService` themselves.
286+
* NOT the default kernel and NOT the scoped-factory path.
287+
*
288+
* ⭐ A dispatcher DOOR reads its member through `readDoorSlot`
289+
* (`./domains/own-door-bridge.ts`), which wraps this and nothing else: a
290+
* door is served only by the request's own kernel, so a door ⛔ never adds
291+
* a `resolveService` fall-back after this lookup.
292+
*
293+
* Elsewhere, a domain whose data must live in the same store as its service
294+
* bindings (share-links: the token row and the shared record sit next to
295+
* the `shareLinks` service's engine) reads its engine through this first and
296+
* falls back to `resolveService` itself.
291297
*
292298
* [#4127 batch 4] The third and last lookup path on this contract, split by
293299
* the same rule as `resolveService`. It resolves the SAME slots off a
294300
* different kernel, so a slot's contract cannot depend on which path
295-
* reached it — and its one caller proves the point: `share-links` tries
296-
* this path and falls back to `resolveService` for the same `'objectql'`
297-
* slot, so before this the two arms of one expression had different types.
301+
* reached it: `share-links` tries this path and falls back to
302+
* `resolveService` for the same `'objectql'` slot, so before the split the
303+
* two arms of one expression had different types.
298304
*/
299305
getRequestKernelService<K extends keyof ServiceSlotContracts>(context: HttpProtocolContext, name: K): Promise<ServiceSlotContract<K> | undefined>;
300306
getRequestKernelService(context: HttpProtocolContext, name: string): Promise<any>;

‎packages/runtime/src/domains/approvals.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ import { INTERNAL_ERROR_MESSAGE } from '@objectstack/types';
6868
import type { IApprovalService } from '@objectstack/spec/contracts';
6969
import type { HttpProtocolContext, HttpDispatcherResult } from '../http-dispatcher.js';
7070
import type { DomainHandlerDeps, DomainRoute } from '../domain-handler-registry.js';
71-
import { catalogNotImplemented } from './own-door-bridge.js';
71+
import { catalogNotImplemented, readDoorSlot } from './own-door-bridge.js';
7272

7373
/**
7474
* The one path this domain claims — exactly, with no sub-paths: the action
@@ -108,7 +108,8 @@ export async function handleApprovalsActRequest(
108108
method: string,
109109
context: HttpProtocolContext,
110110
): Promise<HttpDispatcherResult> {
111-
const service = await deps.resolveService(context, APPROVALS_SLOT, context.environmentId) as
111+
// The request's own kernel serves the door, and only it (`readDoorSlot`).
112+
const service = await readDoorSlot(deps, context, APPROVALS_SLOT) as
112113
Pick<IApprovalService, 'handleActionPage'> | undefined;
113114
// [#37662] The `501` is the operation-message catalog's, in the request's
114115
// top `Accept-Language` tag, as the own-door bridge answers its own.

‎packages/runtime/src/domains/auth.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { INTERNAL_ERROR_MESSAGE } from '@objectstack/types';
1212
import { CoreServiceName } from '@objectstack/spec/system';
1313
import type { HttpProtocolContext, HttpDispatcherResult } from '../http-dispatcher.js';
1414
import type { DomainHandlerDeps, DomainRoute } from '../domain-handler-registry.js';
15-
import { catalogNotImplemented } from './own-door-bridge.js';
15+
import { catalogNotImplemented, readDoorSlot } from './own-door-bridge.js';
1616

1717
/**
1818
* The route this domain claims — `/auth` and its slash-separated sub-paths,
@@ -107,7 +107,8 @@ export async function handleAuthRequest(deps: DomainHandlerDeps, _path: string,
107107
// that reached `handleAuth` directly WITH an auth service registered used to
108108
// get that mock's `mock_<uuid>` session instead of real authentication. It
109109
// now gets the auth service; #4113 removed the mock entirely (see below).
110-
const authService = await deps.getService(context, CoreServiceName.enum.auth);
110+
// The request's own kernel serves the door, and only it (`readDoorSlot`).
111+
const authService = await readDoorSlot(deps, context, CoreServiceName.enum.auth);
111112
if (authService && typeof authService.handleRequest === 'function') {
112113
// [#5085] The auth service owns the routing, so whatever it THROWS is
113114
// unattributable here: this domain never inspected the sub-path, never

‎packages/runtime/src/domains/automation-hooks.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,9 @@ import {
9494
type InboundHookRouteMatch,
9595
} from '@objectstack/core';
9696
import { automationAddressRegistryOf } from './automation-address.js';
97-
import type { ITriggerApiService } from '@objectstack/spec/contracts';
9897
import type { HttpProtocolContext, HttpDispatcherResult } from '../http-dispatcher.js';
9998
import type { DomainHandlerDeps } from '../domain-handler-registry.js';
100-
import { catalogNotImplemented } from './own-door-bridge.js';
99+
import { catalogNotImplemented, readDoorSlot } from './own-door-bridge.js';
101100

102101
/** The slot the member lives on — the trigger package's own name (ADR-0041 §2). */
103102
const TRIGGER_API_SLOT = 'trigger-api';
@@ -181,8 +180,8 @@ export async function handleInboundHookRequest(
181180
context: HttpProtocolContext,
182181
hook: InboundHookRouteMatch,
183182
): Promise<HttpDispatcherResult> {
184-
const service = await deps.resolveService(context, TRIGGER_API_SLOT, context.environmentId) as
185-
Pick<ITriggerApiService, 'handleInboundHook'> | undefined;
183+
// The request's own kernel serves the door, and only it (`readDoorSlot`).
184+
const service = await readDoorSlot(deps, context, TRIGGER_API_SLOT);
186185
// [#37662] The `501` is the operation-message catalog's, in the request's
187186
// top `Accept-Language` tag, as the own-door bridge answers its own.
188187
if (!service) {
@@ -237,7 +236,8 @@ export async function handleInboundHookRequest(
237236
const hookId = decodeHookSegment(hook.hookId);
238237
if (hook.qualifier !== undefined) {
239238
const qualifier = decodeHookSegment(hook.qualifier);
240-
const engine = await deps.resolveService(context, 'automation', context.environmentId) as InboundHookEngine | undefined;
239+
// The request kernel's engine judges the address, as its member serves it (`readDoorSlot`).
240+
const engine = await readDoorSlot(deps, context, 'automation') as InboundHookEngine | undefined;
241241
const registry = await inboundHookRegistry(deps, context);
242242
const namespaceOwners = typeof registry?.getNamespaceOwners === 'function' ? registry.getNamespaceOwners(qualifier) ?? [] : [];
243243
const slot = typeof engine?.inboundHookSlot === 'function' ? engine.inboundHookSlot(flowName, { qualifier, namespaceOwners }) : undefined;

‎packages/runtime/src/domains/comments.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,9 @@
7474
*/
7575

7676
import { INTERNAL_ERROR_MESSAGE } from '@objectstack/types';
77-
import type { ICommentDoorsService } from '@objectstack/spec/contracts';
7877
import type { HttpProtocolContext, HttpDispatcherResult } from '../http-dispatcher.js';
7978
import type { DomainHandlerDeps, DomainRequest, DomainRoute } from '../domain-handler-registry.js';
80-
import { catalogNotImplemented } from './own-door-bridge.js';
79+
import { catalogNotImplemented, readDoorSlot } from './own-door-bridge.js';
8180

8281
/** The prefix the domain claims (a segment claim, narrowed by the handler). */
8382
export const COMMENTS_DOMAIN_PREFIX = '/comments';
@@ -157,8 +156,8 @@ export async function handleCommentsRequest(
157156
// the path got before this domain existed.
158157
if (!matchCommentDoorPath(req.method, req.path)) return { handled: true, response: deps.routeNotFound(req.path) };
159158

160-
const service = await deps.resolveService(context, COMMENTS_SLOT, context.environmentId) as
161-
Pick<ICommentDoorsService, 'handleCommentDoor'> | undefined;
159+
// The request's own kernel serves the door, and only it (`readDoorSlot`).
160+
const service = await readDoorSlot(deps, context, COMMENTS_SLOT);
162161
// [#37610] The `501` is the operation-message catalog's, in the request's
163162
// top `Accept-Language` tag, as the own-door bridge answers its own.
164163
if (!service) {

‎packages/runtime/src/domains/own-door-bridge.test.ts‎

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,3 +573,171 @@ describe('[#37662] every own-door bridge is tied to the catalog', () => {
573573
}
574574
});
575575
});
576+
577+
/**
578+
* A dispatcher door is served only by the request's own kernel. Every door
579+
* bridge forwards to one member on one slot; on a host that routes a request
580+
* to a kernel of its own, that member is read off the request's kernel alone.
581+
* A request kernel without the slot answers the door's typed not-available
582+
* `501`, and a member registered on the host kernel is never called.
583+
*
584+
* Driven through the REAL `HttpDispatcher.dispatch()`, with a `kernel-resolver`
585+
* that places the request on its own kernel and names its environment.
586+
*/
587+
describe('a dispatcher door is served only by the request\'s own kernel', () => {
588+
interface Door {
589+
name: string;
590+
slot: string;
591+
member: string;
592+
method: string;
593+
path: string;
594+
query?: Record<string, string>;
595+
body?: unknown;
596+
}
597+
const ownDoor = (bridge: OwnDoorBridge): Door => ({
598+
name: bridge.tag,
599+
slot: bridge.slot,
600+
member: bridge.member,
601+
method: bridge.doors[0]!.method,
602+
path: bridge.doors[0]!.pattern.replace(/:[a-z]+/gi, 'id_1'),
603+
});
604+
const DOORS: Door[] = [
605+
{ name: 'comments', slot: 'comments', member: 'handleCommentDoor', method: 'DELETE', path: '/comments/c_1' },
606+
{ name: 'approvals', slot: 'approvals', member: 'handleActionPage', method: 'GET', path: '/approvals/act', query: { token: 't_1' } },
607+
{ name: 'webhooks', slot: 'webhooks', member: 'handleRedeliver', method: 'POST', path: '/webhooks/redeliver', body: { deliveryId: 'd_1' } },
608+
{ name: 'automation-hooks', slot: 'trigger-api', member: 'handleInboundHook', method: 'POST', path: '/automation/hooks/flow_x/default', body: { event: 'e' } },
609+
{ name: 'auth', slot: 'auth', member: 'handleRequest', method: 'POST', path: '/auth/sign-in/email', body: { email: 'a@example.com' } },
610+
ownDoor(PERSONAL_VIEWS_BRIDGE),
611+
ownDoor(ATTACHMENTS_BRIDGE),
612+
ownDoor(PRINT_BRIDGE),
613+
];
614+
615+
const served = () => vi.fn(async () => new Response(JSON.stringify({ success: true }), { status: 200, headers: JSON_HEADERS }));
616+
617+
/** A host whose resolver places every request on `requestKernel`, in its own environment. */
618+
function hostWith(hostKernel: any, requestKernel: any) {
619+
const resolver: KernelResolver = {
620+
resolveKernel: async (context: HttpProtocolContext) => {
621+
context.environmentId = 'env_request';
622+
return requestKernel;
623+
},
624+
};
625+
return new HttpDispatcher(hostKernel, undefined, { kernelResolver: resolver, enforceProjectMembership: false });
626+
}
627+
628+
async function knock(dispatcher: HttpDispatcher, door: Door) {
629+
const search = door.query ? `?${new URLSearchParams(door.query)}` : '';
630+
const request = wire(door.method, `${door.path}${search}`, door.body);
631+
return dispatcher.dispatch(door.method, door.path, door.body ?? {}, door.query ?? {}, ctx(request));
632+
}
633+
634+
for (const door of DOORS) {
635+
for (const [variant, throwing] of [['throws', [door.slot]], ['answers nothing', []]] as const) {
636+
it(`${door.name}: a request kernel without the slot (its lookup ${variant}) answers 501, and the host kernel's member is never called`, async () => {
637+
const hostMember = served();
638+
const dispatcher = hostWith(kernelWith({ [door.slot]: { [door.member]: hostMember } }), kernelWith({}, throwing));
639+
640+
const result = await knock(dispatcher, door);
641+
642+
expect(envelope(result), JSON.stringify(result.response?.body)).toEqual({ status: 501, code: 'NOT_IMPLEMENTED' });
643+
expect(hostMember).not.toHaveBeenCalled();
644+
});
645+
}
646+
647+
it(`${door.name}: the request kernel's member serves the door`, async () => {
648+
const hostMember = served();
649+
const ownMember = served();
650+
const dispatcher = hostWith(
651+
kernelWith({ [door.slot]: { [door.member]: hostMember } }),
652+
kernelWith({ [door.slot]: { [door.member]: ownMember } }),
653+
);
654+
655+
const result = await knock(dispatcher, door);
656+
657+
expect(result.response, JSON.stringify(result.response?.body)).toBeUndefined();
658+
expect((result.result as Response).status).toBe(200);
659+
expect(ownMember).toHaveBeenCalledTimes(1);
660+
expect(hostMember).not.toHaveBeenCalled();
661+
});
662+
}
663+
664+
/**
665+
* A qualified hook's address is judged by the engine of the kernel whose
666+
* member serves the hook: the request's own.
667+
*/
668+
const QUALIFIED_HOOK: Door = {
669+
name: 'automation-hooks (qualified)', slot: 'trigger-api', member: 'handleInboundHook',
670+
method: 'POST', path: '/automation/hooks/ns_x/flow_x/default', body: { event: 'e' },
671+
};
672+
const engineSpies = () => ({ packagedFlowOwner: vi.fn(() => undefined), inboundHookSlot: vi.fn(() => undefined) });
673+
const triggerDoor = () => ({ handleInboundHook: served(), handleInboundSlotHook: served() });
674+
675+
it('automation-hooks: a request kernel without the automation engine never consults another kernel\'s engine for a qualified hook\'s address', async () => {
676+
const hostEngine = engineSpies();
677+
const dispatcher = hostWith(
678+
kernelWith({ automation: hostEngine, 'trigger-api': triggerDoor() }),
679+
kernelWith({ 'trigger-api': triggerDoor() }, ['automation']),
680+
);
681+
682+
await knock(dispatcher, QUALIFIED_HOOK);
683+
684+
expect(hostEngine.inboundHookSlot).not.toHaveBeenCalled();
685+
expect(hostEngine.packagedFlowOwner).not.toHaveBeenCalled();
686+
});
687+
688+
it('automation-hooks: the request kernel\'s engine judges a qualified hook\'s address', async () => {
689+
const hostEngine = engineSpies();
690+
const ownEngine = engineSpies();
691+
const dispatcher = hostWith(
692+
kernelWith({ automation: hostEngine, 'trigger-api': triggerDoor() }),
693+
kernelWith({ automation: ownEngine, 'trigger-api': triggerDoor() }),
694+
);
695+
696+
await knock(dispatcher, QUALIFIED_HOOK);
697+
698+
expect(ownEngine.inboundHookSlot).toHaveBeenCalledTimes(1);
699+
expect(hostEngine.inboundHookSlot).not.toHaveBeenCalled();
700+
expect(hostEngine.packagedFlowOwner).not.toHaveBeenCalled();
701+
});
702+
703+
/**
704+
* The net, stated exactly. A DOOR MODULE is any non-test module under
705+
* `src/domains/` (any depth) that takes the transport's request whole
706+
* (`context.request as Request`, the spelling every door here hands it on
707+
* with) or is built on the shared bridge body (`createOwnDoorBridgeDomain(`
708+
* / `handleOwnDoorBridgeRequest(`). A door module reads no service through
709+
* `deps.resolveService`, `deps.resolveServiceOrLoud`, `deps.getService` or a
710+
* `deps.getObjectQL` given an environment id anywhere in it, and one that reads
711+
* a slot itself reads it through `readDoorSlot`. Found, not listed, so a new
712+
* door module is held to this the day it lands. NOT covered: a module that
713+
* hands the request on some other way (building its own request from
714+
* `context.request`), and anything outside `src/domains/`.
715+
*/
716+
it('every door module reads its services through the request-kernel-only reader and no other', () => {
717+
const here = dirname(fileURLToPath(import.meta.url));
718+
const FALLING_BACK = /\bdeps\.(?:resolveServiceOrLoud|resolveService|getService)\s*(?:<[^(]*>)?\(|\bdeps\.getObjectQL\(\s*[\w.]+\s*,/g;
719+
const READS = /\b(readDoorSlot|deps\.getRequestKernelService|deps\.resolveServiceOrLoud|deps\.resolveService|deps\.getService|deps\.getObjectQL)\s*(?:<[^(]*>)?\(/g;
720+
const modules = (readdirSync(here, { recursive: true }) as string[])
721+
.filter((n) => n.endsWith('.ts') && !n.endsWith('.test.ts'))
722+
.map((n) => ({ name: n, source: readFileSync(join(here, n), 'utf8') }));
723+
const doors = modules.filter(({ source }) => source.includes('context.request as Request')
724+
|| source.includes('createOwnDoorBridgeDomain(') || source.includes('handleOwnDoorBridgeRequest('));
725+
726+
for (const { name, source } of doors) {
727+
expect([...source.matchAll(FALLING_BACK)].map((m) => m[0]), name).toEqual([]);
728+
if (source.includes('context.request as Request')) {
729+
expect(source.includes('readDoorSlot('), `${name} reads its member through readDoorSlot`).toBe(true);
730+
}
731+
}
732+
expect(doors.map(({ name }) => name)).toEqual(expect.arrayContaining([
733+
'approvals.ts', 'attachments.ts', 'auth.ts', 'automation-hooks.ts', 'comments.ts',
734+
'own-door-bridge.ts', 'personal-views.ts', 'print.ts', 'webhooks.ts',
735+
]));
736+
737+
// The reader itself reads the request kernel's slot and nothing else.
738+
const bridge = readFileSync(join(here, 'own-door-bridge.ts'), 'utf8');
739+
const body = bridge.slice(bridge.indexOf('export async function readDoorSlot'));
740+
const reader = body.slice(0, body.indexOf('\n}\n'));
741+
expect([...reader.matchAll(READS)].map((m) => m[1])).toEqual(['readDoorSlot', 'deps.getRequestKernelService']);
742+
});
743+
});

0 commit comments

Comments
 (0)