Skip to content

Commit ac0f928

Browse files
fix(verify): a bootStack artifact boot registers its metadata door ahead of the app, as os dev does (#38638)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9St4eUWHFcCKuRUrCZPperJ)_ Fixes #36274 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:用户无感;变化在测试工具里,开发者用它启动编译产物时,演示数据的读法现在和本地开发启动一致。 - 为什么做:替应用作者和车队解决“测试工具里演示数据关联都对、本地开发启动却存错”的假绿,上一张修复的种子关联缺陷在测试工具里测不出来。 - 出错会怎样:只影响用这个测试工具启动编译产物的测试;万一有问题,表现为这类测试里元数据读到的对象和以前不同,撤回本次改动即恢复原样。 - 要你做什么:无 ## What changes **Cause (measured).** Both boots seed through the same `SeedLoaderService`; what differs is what `metadata.getObject` holds when the inline seed runs in `AppPlugin.start()`. - `os dev` over a compiled artifact (`createStandaloneStack`, and the CLI's dev artifact door) registers a `MetadataPlugin` with `artifactSource` AHEAD of the app. Its `start()` loads each object as its own package wrote it, so by seed time the metadata service's copy of the extended object lacks the field another package adds through `objectExtensions`. - `bootStack` never got there. With `BootOptions.artifact` it composed only the artifact-less lazy `MetadataPlugin`. With a caller's `MetadataPlugin({ artifactSource })` in `extraPlugins`, that plugin was registered in the `extraPlugins` slot, AFTER `AppPlugin`, so its artifact load ran after the seed. Either way the seed read the copy ObjectQL's one-shot bridge had put into the empty metadata service (the harness's `ObjectQLPlugin` has no `environmentId`): the registry's folded object, extension included. So the pre-#36272 resolver (metadata copy first) resolved the natural key under verify and stored it raw under `os dev`. - Not the cause: the registrar option and `unwrapEnvelope`. `loadCompiledArtifact` already reads with `unwrapEnvelope: true`. The registrar decides who registers the four security collections; it does not touch the object copy a seed reads. **Fix (`packages/verify/src/harness.ts`): the `metadata` slot boots like `os dev`.** - `bootStack(config, { artifact })` composes `MetadataPlugin({ watch: false, artifactWatch: false, artifactSource: { mode: 'local-file', path }, rootDir: hostRoot })` over the same file the app is mounted from. It is registered in the metadata slot, ahead of `AppPlugin`, and the app gets `securityMetadataRegistrar: 'artifact-door'`, exactly as `createStandaloneStack` declares both. One value (`composesArtifactDoor`) decides both. - A `MetadataPlugin` in `extraPlugins` is registered in the metadata slot, ahead of the app, and skipped in the `extraPlugins` loop. The harness still composes none of its own beside it. - A source boot (no `artifact`, no caller `MetadataPlugin`) is unchanged, and so is an app that declares a `MetadataPlugin` in its own `plugins`. - `loadCompiledArtifact` now also returns the `location` it resolved. The docblocks of `bootStack`, `BootOptions.artifact` and `BootOptions.extraPlugins` say where the door sits and why. `packages/verify/README.md` names the door and its slot. - `.changeset/36274-verify-artifact-metadata-door.md`: `@objectstack/verify` patch. ## Tests New pin: `packages/verify/src/harness.seed-extension-lookup.test.ts`. It boots a two-package artifact of the #35254 shape: module `com.example.sxl.mod` adds `quote_ref` (lookup to `sxl_quote`) to the app's `sxl_order` through `objectExtensions`, and seeds `O-1` with `quote_ref: 'Acme Quote'`. There are two legs, `bootStack(config, { artifact })` and `bootStack(artifact, { extraPlugins: [MetadataPlugin({ artifactSource })] })`. Each leg asserts: - precondition: the metadata service's copy of `sxl_order` has no `quote_ref`, which is the copy `os dev` holds; - `quote_ref` stores the quote's id; - CONTROL: `account_ref`, the owner's own lookup, stores the account's id. <details> <summary>Measurement: what getObject held at seed time, per boot (pre-#36272 resolver)</summary> The resolver body of `8925d5bc^` was put back in the worktree, never committed (blob 2713d6f4cb, the same blob #36272's ablation used). `@objectstack/metadata-protocol` was rebuilt, and `ablation-dist-preflight.mjs @objectstack/metadata-protocol 'fromMetadata?.fields'` read the marker present in `dist/`. A scratch probe (not committed) wrapped `SeedLoaderService.prototype.resolveObjectDefinition` and recorded, for the extended object, whether the metadata copy and the engine schema carried the extension field. | boot | harness | metadata copy at seed time | engine schema | stored `quote_ref` | |:--|:--|:--|:--|:--| | `bootStack(config)` (source) | origin/main | has the field | has it | quote id | | `bootStack(config, { artifact })` | origin/main | has the field | has it | quote id | | `bootStack(artifact, { extraPlugins: [MetadataPlugin(artifactSource)] })` | origin/main | has the field (after boot: absent) | has it | quote id | | `createStandaloneStack({ artifactPath })` kernel (the `os dev` composition) | n/a | **absent** | has it | not read (see below) | | `bootStack(config, { artifact })` | this branch | **absent** | has it | **`"Acme Quote"`** | | `bootStack(artifact, { extraPlugins: [MetadataPlugin(artifactSource)] })` | this branch | **absent** | has it | **`"Acme Quote"`** | The standalone-stack leg composes only the stack's own plugins (no `AuthPlugin`), so its rows were refused for a missing organization. Its seed-time reading is the measurement there. That `os dev` stores the raw key on this resolver was measured on #36272 (`os dev --fresh`, PR body table). </details> <details> <summary>Ablation of the pin (rebuild + on-disk mutation proof)</summary> The fix was committed first (d11ad49). The red leg used the same put-back resolver as above, with the dist marker present (preflight exit 0): - `vitest run src/harness.seed-extension-lookup.test.ts`: 2 failed, 4 passed. Both seed pins were red: `expected 'Acme Quote' to be 'Jxi4WdPdRfw5yZh3'` (artifact leg) and `expected 'Acme Quote' to be 'uI0EwppDilcGU-qA'` (caller-door leg). The two preconditions and the two CONTROLs stayed green. - Restore: `git checkout HEAD -- packages/metadata-protocol/src/seed-loader.ts`. The blob reads fdbca4a, the HEAD blob, and `git status --porcelain` showed only the untracked scratch probe, since deleted. After the rebuild, `--absent` read the marker absent from all 24 built files. - Green: 6 of 6 pin tests pass. </details> <details> <summary>Suite and gate readings</summary> - `pnpm --filter @objectstack/verify typecheck`: exit 0 (`check:test-typecheck: OK`). - `pnpm --filter @objectstack/verify exec vitest run --maxWorkers=2` (whole package): `Test Files 56 passed (56)`, `Tests 515 passed (515)`. - Flip sweep: every dogfood file that hands `bootStack` a `MetadataPlugin` or an `artifact` (16 files), run against the rebuilt `@objectstack/verify` dist: `Test Files 16 passed (16)`, `Tests 206 passed (206)`. No existing test flipped. - `dispatch-gates.mjs --commands` at ce65d57 derived 75 families, and every one ran locally, each exit captured before any pipe. 74 exited 0. `node scripts/check-plugin-teardown-shape.mjs --self-test` exited 3 (PREREQUISITE NOT MET: its fixture commit is out of this shallow clone's reach), so it is NOT MEASURED locally and CI runs it. `--ran` reconciliation: "75 derived, 74 run, 1 NOT-MEASURED, 0 UNRUN", exit 0. - The first pass at da23bd2 caught `check:test-source-alias` exiting 1 on the new pin, which loaded `@objectstack/service-automation` inside a case's clock. ce65d57 adds the module-top side-effect imports, and the gate exits 0. The whole list was re-run on that head (the reading above). The pin re-ran there too: `Tests 6 passed (6)`. `typecheck` exit 0. </details> ## Acceptance notes - **The dogfood-guidance sentence is not owed.** The Done-when offers it only for a harness that seeds through another path on purpose. The measurement shows the divergence was an accident of slot order, now fixed, so `.claude/skills/dogfood-verification/SKILL.md` is untouched. - **Not changed, same shape:** a `MetadataPlugin` declared in the app's own `plugins` is still registered in the app-plugins slot after `AppPlugin`, while `serve` registers it ahead of the wrap. No producer was measured; noted, not filed. - **Not changed:** a caller's `MetadataPlugin` with an `artifactSource` leaves the app's registrar at `'app-plugin'`. The harness cannot know that the caller's door reads the same file the app is mounted from, so both still register the four security collections, as before this change. - **Not changed:** the harness's `ObjectQLPlugin` still has no `environmentId`, so its one-shot bridge still copies registry objects the artifact does not carry into the metadata service. The door's load supersedes the bridge for every object the artifact carries. ## Verification Files to read first, by risk: 1. `packages/verify/src/harness.ts`, the metadata-slot hunk (`callerMetadataPlugins` / `composesArtifactDoor`) and the `extraPlugins` loop's skip. 2. `packages/verify/src/harness.seed-extension-lookup.test.ts`. 3. `.changeset/36274-verify-artifact-metadata-door.md`. Two-minute check: `pnpm --filter @objectstack/verify exec vitest run --maxWorkers=2 src/harness.seed-extension-lookup.test.ts` should print `Tests 6 passed (6)`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01ADHkmRar3Kkg6SpwVgaaVE <!-- signed: repo:objectstack#3 · os-steve · session_01ADHkmRar3Kkg6SpwVgaaVE --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6eb23c8 commit ac0f928

4 files changed

Lines changed: 271 additions & 20 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@objectstack/verify': patch
3+
---
4+
5+
fix(verify): a `bootStack` boot of a compiled artifact fills its `metadata` slot the way `os dev` does, so it seeds the way `os dev` seeds
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
`bootStack` could pass a seed that `os dev` stored wrongly. The case measured: a module package adds a lookup to the app package's object through `objectExtensions`, and seeds it by the target's natural key. On `os dev` the metadata service holds each object as its own package wrote it, because the `MetadataPlugin` that loads the artifact starts before the app seeds. Under `bootStack` that plugin started after the app's seed, or was not composed at all, so the seed read the registry's copy with the extension folded in. With the seed loader as it was before it learned to read the engine's schema first, `os dev` stored the raw key and `bootStack` stored the target's id, so a `bootStack` test could not catch the defect.
11+
12+
Now:
13+
14+
- `bootStack(config, { artifact })` composes a `MetadataPlugin` that loads the same artifact, ahead of the app, and the app leaves the four security collections (`positions`, `permissions`, `capabilities`, `sharingRules`) to it, as `os dev` declares it.
15+
- A `MetadataPlugin` passed in `extraPlugins` is registered in the `metadata` slot, ahead of the app, instead of after it. The harness composes no `MetadataPlugin` of its own beside it, as before.
16+
17+
A source boot (no `artifact`, no `MetadataPlugin` in `extraPlugins`) is unchanged.

‎packages/verify/README.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,17 @@ await expect(shipped.hooks.run('crm_lead', 'insert', { last_name: 'Ada' }, { sys
450450
in-process here as under `objectstack start`. `objectstack build
451451
--strict-body` refuses it at build time instead, and its artifact is
452452
body-only.
453+
- The `metadata` slot is the door `objectstack dev` composes for an artifact:
454+
a `MetadataPlugin` that loads the same file, registered ahead of the app,
455+
which leaves the four security collections to it. So a seed reads the
456+
metadata copy `os dev` reads: each object as its own package wrote it, with
457+
a field another package adds through `objectExtensions` in the engine's
458+
folded schema only. A `MetadataPlugin` you pass in `extraPlugins` takes the
459+
door's place, and is registered in the same slot, ahead of the app, so one
460+
that loads an artifact has loaded it before the app's inline seed runs.
461+
Before this, the door loaded after the seed (or was not composed), the seed
462+
read the registry's folded copy, and a verify boot could resolve a seed
463+
reference that `os dev` stored as the raw natural key.
453464
- Refused before anything boots: an artifact that cannot be loaded
454465
(`RESOURCE_NOT_FOUND` / 404; the boot never falls back to the source), one
455466
built from another app (`RESOURCE_CONFLICT` / 409), and a configuration
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* #36274 — a `bootStack` boot of a compiled artifact seeds the way
5+
* `objectstack dev` seeds it, so it can pin a seed defect the real boot shows.
6+
*
7+
* The shape is #35254's: a module package adds a lookup to the app package's
8+
* object through `objectExtensions`, and seeds it by the target's natural key.
9+
* On `os dev` the metadata service holds each object as its own package wrote
10+
* it (the artifact door loads it before the app seeds), so the extension's
11+
* lookup is in the engine's folded schema only, and the seed loader resolved
12+
* the natural key only once it read the engine first (PR #36272).
13+
*
14+
* Measured before this change (`origin/main` eec2bc3e, the resolver of
15+
* `8925d5bc^` put back): both `bootStack` legs below stored the quote's id, and
16+
* the metadata service's copy read at seed time carried `quote_ref`. The
17+
* `MetadataPlugin` that loads the artifact was registered after the app (a
18+
* caller's, in the `extraPlugins` slot) or not composed at all (the
19+
* `artifact` option), so the seed read ObjectQL's bridged, folded copy. A
20+
* `createStandaloneStack` boot of the same artifact (the `os dev` composition)
21+
* read `quote_ref` absent from that copy at seed time.
22+
*
23+
* Every leg has a CONTROL: `account_ref`, the lookup the owning package
24+
* authored on the same object. The `metadata` assertion is the precondition:
25+
* the boot holds the copy `os dev` holds, or the seed pin proves nothing.
26+
*/
27+
28+
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
29+
import { tmpdir } from 'node:os';
30+
import { join } from 'node:path';
31+
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
32+
// Paid at collection, not inside a case's clock (check:test-source-alias).
33+
import '@objectstack/service-datasource';
34+
import '@objectstack/service-automation';
35+
import { MetadataPlugin } from '@objectstack/metadata';
36+
import { composeStacks, defineStack } from '@objectstack/spec';
37+
import { bootStack, type VerifyStack } from './harness.js';
38+
39+
const BOOT_TIMEOUT = 120_000;
40+
const APP = 'com.example.sxl.app';
41+
const MOD = 'com.example.sxl.mod';
42+
43+
/** The two-package artifact, built again per call: the instance rule keys on identity. */
44+
function artifact(): Record<string, unknown> {
45+
const app = {
46+
manifest: { id: APP, namespace: 'sxl', name: 'sxl_app', version: '1.0.0', type: 'app' },
47+
objects: [
48+
{ name: 'sxl_account', label: 'Account', sharingModel: 'public_read_write', fields: { name: { type: 'text', label: 'Name' } } },
49+
{
50+
name: 'sxl_order',
51+
label: 'Order',
52+
sharingModel: 'public_read_write',
53+
fields: {
54+
name: { type: 'text', label: 'Name' },
55+
account_ref: { type: 'lookup', label: 'Account', reference: 'sxl_account' },
56+
},
57+
},
58+
],
59+
data: [{ object: 'sxl_account', mode: 'upsert', externalId: 'name', records: [{ name: 'Acme' }] }],
60+
};
61+
const mod = {
62+
manifest: {
63+
id: MOD, namespace: 'sxl', name: 'sxl_mod', version: '1.0.0', type: 'module', dependencies: { [APP]: '^1.0.0' },
64+
},
65+
objects: [{ name: 'sxl_quote', label: 'Quote', sharingModel: 'public_read_write', fields: { name: { type: 'text', label: 'Name' } } }],
66+
objectExtensions: [{ extend: 'sxl_order', fields: { quote_ref: { type: 'lookup', label: 'Quote', reference: 'sxl_quote' } } }],
67+
data: [
68+
{ object: 'sxl_quote', mode: 'upsert', externalId: 'name', records: [{ name: 'Acme Quote' }] },
69+
{ object: 'sxl_order', mode: 'upsert', externalId: 'name', records: [{ name: 'O-1', account_ref: 'Acme', quote_ref: 'Acme Quote' }] },
70+
],
71+
};
72+
// JSON, as an artifact is: the inputs carry no callable to lose.
73+
return JSON.parse(
74+
JSON.stringify(
75+
composeStacks(
76+
[defineStack(app as never), defineStack(mod as never, { artifactObjects: ['sxl_account', 'sxl_order'] } as never)],
77+
{ manifest: 'preserve' },
78+
),
79+
),
80+
) as Record<string, unknown>;
81+
}
82+
83+
interface Reading {
84+
quoteRef: unknown;
85+
accountRef: unknown;
86+
quoteId: unknown;
87+
accountId: unknown;
88+
/** Whether the metadata service's copy of the order carries the extension's field. */
89+
metadataCopyHasQuoteRef: boolean;
90+
}
91+
92+
async function read(stack: VerifyStack): Promise<Reading> {
93+
const [order] = await stack.rows('sxl_order');
94+
const [quote] = await stack.rows('sxl_quote');
95+
const [account] = await stack.rows('sxl_account');
96+
const copy = (await stack.kernel.getService<{ getObject(name: string): Promise<any> }>('metadata').getObject('sxl_order')) as
97+
| { fields?: Record<string, unknown> }
98+
| undefined;
99+
return {
100+
quoteRef: order?.quote_ref,
101+
accountRef: order?.account_ref,
102+
quoteId: quote?.id,
103+
accountId: account?.id,
104+
metadataCopyHasQuoteRef: Boolean(copy?.fields && 'quote_ref' in copy.fields),
105+
};
106+
}
107+
108+
let dir: string;
109+
let path: string;
110+
const readings = new Map<string, Reading>();
111+
112+
beforeAll(async () => {
113+
dir = mkdtempSync(join(tmpdir(), 'verify-seed-extension-lookup-'));
114+
path = join(dir, 'objectstack.json');
115+
writeFileSync(path, JSON.stringify(artifact()));
116+
117+
// The `artifact` option: verify's own door.
118+
const viaArtifact = await bootStack(artifact(), { artifact: path, hostRoot: dir });
119+
try {
120+
readings.set('artifact', await read(viaArtifact));
121+
} finally {
122+
await viaArtifact.stop();
123+
}
124+
125+
// A caller's `MetadataPlugin` over the artifact: the dogfood suites' shape.
126+
const viaCallerDoor = await bootStack(artifact(), {
127+
hostRoot: dir,
128+
extraPlugins: [
129+
new MetadataPlugin({
130+
rootDir: dir, watch: false, artifactWatch: false, registerSystemObjects: false,
131+
artifactSource: { mode: 'local-file', path },
132+
}),
133+
],
134+
});
135+
try {
136+
readings.set('caller-door', await read(viaCallerDoor));
137+
} finally {
138+
await viaCallerDoor.stop();
139+
}
140+
}, BOOT_TIMEOUT * 2);
141+
142+
afterAll(() => {
143+
if (dir) rmSync(dir, { recursive: true, force: true });
144+
});
145+
146+
describe('[#36274] a bootStack artifact boot seeds a lookup another package adds through objectExtensions as os dev does', () => {
147+
for (const leg of ['artifact', 'caller-door'] as const) {
148+
it(`${leg}: the metadata service holds the order as its package wrote it, without the extension's field`, () => {
149+
expect(readings.get(leg)?.metadataCopyHasQuoteRef).toBe(false);
150+
});
151+
152+
it(`${leg}: the extension's lookup stores the quote's id, not its natural key`, () => {
153+
const r = readings.get(leg)!;
154+
expect(r.quoteId).toEqual(expect.any(String));
155+
expect(r.quoteRef).toBe(r.quoteId);
156+
});
157+
158+
it(`${leg}: CONTROL — the owner's own lookup stores the account's id`, () => {
159+
const r = readings.get(leg)!;
160+
expect(r.accountId).toEqual(expect.any(String));
161+
expect(r.accountRef).toBe(r.accountId);
162+
});
163+
}
164+
});

‎packages/verify/src/harness.ts‎

Lines changed: 79 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,15 @@ export interface BootOptions {
537537
* is refused too (`RESOURCE_NOT_FOUND`, `status: 404`), never replaced by
538538
* the source. A stale artifact boots stale bodies: build before the run.
539539
*
540+
* [#36274] The `metadata` slot is the door `objectstack dev` composes for
541+
* an artifact: a `MetadataPlugin` that loads this same file, ahead of the
542+
* app, which then leaves the four security collections to it
543+
* (`securityMetadataRegistrar: 'artifact-door'`). So the metadata service
544+
* holds each object as its own package wrote it, the copy a seed reads on
545+
* `os dev`, and a field another package adds through `objectExtensions`
546+
* is in the engine's folded schema only. A `MetadataPlugin` in
547+
* {@link BootOptions.extraPlugins} takes the door's place.
548+
*
540549
* ⛔ Nothing is lowered here. The build's lowering lives in
541550
* `@objectstack/cli`, which depends on this package, so the caller builds
542551
* the artifact and this boot reads it.
@@ -639,6 +648,13 @@ export interface BootOptions {
639648
* mounted, and this instance is the one the boot keeps.
640649
*
641650
* So a suite that needs one of those configured its own way passes it here.
651+
*
652+
* [#36274] A `MetadataPlugin` (`@objectstack/metadata`) here is the one
653+
* exception to the slot: it is registered in the `metadata` slot, ahead of
654+
* the app, where `objectstack dev` registers its artifact door, so one that
655+
* loads an artifact has loaded it before the app's inline seed reads the
656+
* metadata service. The harness then composes no `MetadataPlugin` of its own.
657+
*
642658
* {@link BootOptions.security} and {@link BootOptions.analytics} take
643659
* precedence over an app plugin of the same `name` the same way.
644660
*/
@@ -793,7 +809,7 @@ async function loadCompiledArtifact(
793809
artifact: unknown,
794810
config: unknown,
795811
hostRoot: string,
796-
): Promise<Record<string, unknown>> {
812+
): Promise<{ bundle: Record<string, unknown>; location: string }> {
797813
if (typeof artifact !== 'string' || artifact.trim() === '') {
798814
throw bootRefusal(
799815
`verify: BootOptions.artifact must name a compiled artifact (a path or an http(s):// URL), not ` +
@@ -839,7 +855,15 @@ async function loadCompiledArtifact(
839855
409,
840856
);
841857
}
842-
return bundle as Record<string, unknown>;
858+
return { bundle: bundle as Record<string, unknown>, location };
859+
}
860+
861+
/** Whether a plugin is `@objectstack/metadata`'s `MetadataPlugin`, by its registered name or its class name. */
862+
function isMetadataPlugin(plugin: unknown): boolean {
863+
return (
864+
registeredName(plugin) === 'com.objectstack.metadata' ||
865+
(plugin as { constructor?: { name?: unknown } } | null | undefined)?.constructor?.name === 'MetadataPlugin'
866+
);
843867
}
844868

845869
/**
@@ -938,8 +962,10 @@ function claimConfiguration(config: unknown): ConfigurationClaim {
938962
* harness's service set, its `metadata` slot held by the artifact-less
939963
* `MetadataPlugin` (`@objectstack/metadata`) `serve` composes for a host
940964
* configuration, so a declared `apis` endpoint is matched as `serve` matches
941-
* it (a `MetadataPlugin` in {@link BootOptions.extraPlugins} or in the app's
942-
* `plugins` takes its place); the providers `serve` mounts for it — the ones the
965+
* it (a `MetadataPlugin` in {@link BootOptions.extraPlugins}, registered in
966+
* that slot ahead of the app, or one in the app's `plugins` takes its place;
967+
* with {@link BootOptions.artifact}, the `MetadataPlugin` that loads the
968+
* artifact, as `objectstack dev` composes it); the providers `serve` mounts for it — the ones the
943969
* app's `requires` names and the always-on slate `serve` mounts for every app
944970
* (`queue`, `job`, `cache`, `settings`, `email`, `storage`, `sms`, `sharing`,
945971
* `messaging`, `analytics`, `package-registry`), each built from the app's
@@ -1052,8 +1078,9 @@ async function bootClaimed(
10521078
// artifact built from it (see BootOptions.artifact). Read before the posture
10531079
// is requested and the kernel is built, so a refused artifact leaves nothing
10541080
// to undo.
1055-
const appBundle: unknown =
1056-
opts.artifact === undefined ? config : await loadCompiledArtifact(opts.artifact, config, hostRoot);
1081+
const compiled =
1082+
opts.artifact === undefined ? undefined : await loadCompiledArtifact(opts.artifact, config, hostRoot);
1083+
const appBundle: unknown = compiled === undefined ? config : compiled.bundle;
10571084

10581085
// [ADR-0105 D1] `multiTenant: true` REQUESTS the hard organization wall —
10591086
// posture `isolated`, what `OS_MULTI_ORG_ENABLED=true` historically meant.
@@ -1145,28 +1172,57 @@ async function bootClaimed(
11451172
// collections included.
11461173
// - `rootDir` is the app's root, as `serve` hands it, so the repository the
11471174
// plugin attaches sits under the app; attaching writes nothing.
1148-
// - A `MetadataPlugin` the caller hands in `extraPlugins`, or the app
1149-
// declares in its own `plugins`, takes its place by identity — `serve`'s
1150-
// "no MetadataPlugin in `plugins`" condition, read on the same two keys.
1175+
// - A `MetadataPlugin` the app declares in its own `plugins` takes its
1176+
// place — `serve`'s "no MetadataPlugin in `plugins`" condition, read on
1177+
// the same two keys.
1178+
//
1179+
// [#36274] Two boots fill the slot the way `objectstack dev` fills it for a
1180+
// compiled artifact (`createStandaloneStack`, and the CLI's dev artifact
1181+
// door): a `MetadataPlugin` that loads the artifact, registered HERE, ahead
1182+
// of the app.
1183+
// - `BootOptions.artifact`: the harness composes that door over the same
1184+
// file, and the app is told the door registers the four security
1185+
// collections (`securityMetadataRegistrar: 'artifact-door'`), as both
1186+
// dev boots declare it. One value decides both.
1187+
// - A `MetadataPlugin` the caller hands in `extraPlugins` is registered in
1188+
// this slot, not in the `extraPlugins` slot after the app.
1189+
// The order is what a seed reads. The door's `start()` loads each object as
1190+
// its own package wrote it, so a field another package adds through
1191+
// `objectExtensions` is absent from the metadata service's copy, while
1192+
// ObjectQL's one-shot bridge (this kernel has no `environmentId`) had copied
1193+
// the registry's folded object into the empty service a moment earlier.
1194+
// After the app, the door loaded after the inline seed had run, so the seed
1195+
// read the folded copy, and a verify boot resolved a seed that `os dev`
1196+
// stored as a raw natural key. Before the app, the seed reads the copy
1197+
// `os dev` reads.
11511198
// No catch: a boot that cannot compose its `metadata` occupant fails, rather
11521199
// than falling back to the matcher-less one quietly.
11531200
const declaredPlugins = (config as { plugins?: unknown } | null | undefined)?.plugins;
1154-
const holdsMetadataPlugin = [
1155-
...(opts.extraPlugins ?? []),
1156-
...(Array.isArray(declaredPlugins) ? declaredPlugins : []),
1157-
].some(
1158-
(plugin) =>
1159-
registeredName(plugin) === 'com.objectstack.metadata' ||
1160-
(plugin as { constructor?: { name?: unknown } } | null | undefined)?.constructor?.name === 'MetadataPlugin',
1161-
);
1162-
if (!holdsMetadataPlugin) {
1163-
await kernel.use(new MetadataPlugin({ watch: false, config: { bootstrap: 'lazy' }, rootDir: hostRoot }));
1201+
const callerMetadataPlugins = (opts.extraPlugins ?? []).filter(isMetadataPlugin);
1202+
const declaresMetadataPlugin = Array.isArray(declaredPlugins) && declaredPlugins.some(isMetadataPlugin);
1203+
let composesArtifactDoor = false;
1204+
if (callerMetadataPlugins.length > 0) {
1205+
for (const plugin of callerMetadataPlugins) await kernel.use(plugin as any);
1206+
} else if (!declaresMetadataPlugin) {
1207+
composesArtifactDoor = compiled !== undefined;
1208+
await kernel.use(
1209+
compiled === undefined
1210+
? new MetadataPlugin({ watch: false, config: { bootstrap: 'lazy' }, rootDir: hostRoot })
1211+
: new MetadataPlugin({
1212+
watch: false,
1213+
artifactWatch: false,
1214+
artifactSource: { mode: 'local-file', path: compiled.location },
1215+
rootDir: hostRoot,
1216+
}),
1217+
);
11641218
}
11651219

11661220
// The app under test (objects, datasets, cubes, flows, seed data): the
11671221
// configuration, or [#22301] the compiled artifact `BootOptions.artifact`
11681222
// names, whose hook and action `body`s AppPlugin binds to the sandbox.
1169-
await kernel.use(new AppPlugin(appBundle));
1223+
await kernel.use(
1224+
new AppPlugin(appBundle, undefined, composesArtifactDoor ? { securityMetadataRegistrar: 'artifact-door' } : {}),
1225+
);
11701226

11711227
// Platform infrastructure `os serve` auto-injects into every served kernel:
11721228
// the `sys_migration` flag ledger (#4243) and the `sys_secret` cipher store
@@ -1355,7 +1411,10 @@ async function bootClaimed(
13551411

13561412
// Caller-supplied optional service pairs (see BootOptions.extraPlugins).
13571413
// Before SecurityPlugin, mirroring the CLI's ordering for service pairs.
1414+
// A `MetadataPlugin` among them is already registered, in the `metadata`
1415+
// slot above (#36274).
13581416
for (const plugin of opts.extraPlugins ?? []) {
1417+
if (callerMetadataPlugins.includes(plugin)) continue;
13591418
handHarnessCryptoToAuditPlugin(plugin, cryptoProvider);
13601419
await kernel.use(plugin as any);
13611420
}

0 commit comments

Comments
 (0)