Skip to content

Commit 95dd17e

Browse files
committed
test(dogfood): the artifact door keeps each namespace's agent and skill, and /layers?package= serves each package its own
A second boot in the AI-family file, through MetadataPlugin's artifact door (the os dev / os start path): two namespaces' same-named agent and skill are both held by the metadata service, and the layered read naming a package serves that package's code layer (it served the package registered last for both). Claude-Session: https://claude.ai/code/session_01WGufzfwcoEAvZuaoKybH16 Co-authored-by: Claude <noreply@anthropic.com>
1 parent 8c05af1 commit 95dd17e

1 file changed

Lines changed: 116 additions & 3 deletions

File tree

‎packages/qa/dogfood/test/bare-name-one-holder-ai-family.dogfood.test.ts‎

Lines changed: 116 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,27 @@
3535
// naming the holder and the rename, as before; of a package declaring the
3636
// held tool name is the same 422 naming both holders; none installs;
3737
// - CONTROL: a package declaring fresh agent, skill and tool names installs,
38-
// and every AI door serves it as before.
38+
// and every AI door serves it as before;
39+
// - [#32151, ADR-0150 D3/D4] on the ARTIFACT door (a second boot of its own,
40+
// the door `os dev` and `os start` load a compiled artifact through, which
41+
// registers every package body's items into the metadata service), the
42+
// metadata service keeps each package's agent and skill, and the layered
43+
// read `/meta/TYPE/NAME/layers?package=` serves each package's own code
44+
// layer (it served the package registered last for both).
3945

4046
import { mkdtempSync, rmSync } from 'node:fs';
4147
import { tmpdir } from 'node:os';
4248
import { join } from 'node:path';
4349
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
44-
import { type VerifyStack } from '@objectstack/verify';
50+
import { bootStack, type VerifyStack } from '@objectstack/verify';
4551
import { AppPlugin, HttpDispatcher } from '@objectstack/runtime';
4652
import { MarketplaceInstallLocalPlugin } from '@objectstack/cloud-connection';
4753
import { MCPServerPlugin } from '@objectstack/mcp';
48-
import { defineStack } from '@objectstack/spec';
54+
import { MetadataPlugin } from '@objectstack/metadata';
55+
import { composeStacks, defineStack } from '@objectstack/spec';
4956
import { PROTOCOL_MAJOR } from '@objectstack/spec/kernel';
5057
import { bootShowcase } from './showcase-boot.js';
58+
import { writeBuildShapedArtifact } from './build-shaped-artifact.js';
5159

5260
const AGENT = 'qa_shared_agent';
5361
const SKILL = 'qa_shared_skill';
@@ -356,3 +364,108 @@ describe('agent and skill names held per namespace, a tool name per deployment,
356364
expect(await promptText(`gamma-${SKILL}`)).toContain('gamma skill instructions');
357365
});
358366
});
367+
368+
/**
369+
* [#32151, ADR-0150 D3/D4] The artifact door, which the boot above does not
370+
* reach: `bootStack` mounts `AppPlugin` as the stack's one registrar and a
371+
* `MetadataPlugin` with no artifact, so the metadata service there holds no
372+
* agent or skill at all. `os dev` (HMR) and `os start` load the compiled
373+
* artifact through `MetadataPlugin`'s artifact door instead, which registers
374+
* every package body's items into the metadata service, stamped
375+
* `_packageId`. Its in-memory store was keyed by bare name for these types, so
376+
* the package registered last overwrote the other: on main 45f0f81f every
377+
* `get` of the name, the one naming the other package included, answered the
378+
* survivor, and `GET /meta/TYPE/NAME/layers?package=<the other>` served the
379+
* survivor's body as both the code and the effective layer, under the
380+
* survivor's `packageId`.
381+
*/
382+
describe('the artifact door keeps each namespace\'s agent and skill in the metadata service, and the layered read serves each package its own (#32151)', () => {
383+
const ALPHA = 'com.qa.bare.alpha';
384+
const BETA = 'com.qa.bare.beta';
385+
const SOLO_AGENT = 'qa_solo_agent';
386+
const SOLO_SKILL = 'qa_solo_skill';
387+
const artifactPackage = (p: 'alpha' | 'beta') => defineStack({
388+
manifest: { id: `com.qa.bare.${p}`, namespace: p, name: `qa_bare_${p}`, version: '1.0.0', type: p === 'alpha' ? 'app' : 'module' },
389+
objects: [item(p)],
390+
agents: [agent(p), ...(p === 'alpha' ? [agent(p, SOLO_AGENT)] : [])],
391+
skills: [skill(p), ...(p === 'alpha' ? [skill(p, SOLO_SKILL)] : [])],
392+
} as never);
393+
const artifact = composeStacks([artifactPackage('alpha'), artifactPackage('beta')], { manifest: 'preserve' });
394+
395+
let stack: VerifyStack;
396+
let admin: string;
397+
let dir: string;
398+
let metadata: { get(type: string, name: string, packageId?: string): Promise<any>; list(type: string): Promise<any[]> };
399+
400+
beforeAll(async () => {
401+
dir = mkdtempSync(join(tmpdir(), 'dogfood-slotted-store-ai-'));
402+
const artifactPath = join(dir, 'objectstack.json');
403+
writeBuildShapedArtifact(artifact as unknown as Record<string, unknown>, artifactPath);
404+
stack = await bootStack(artifact, {
405+
extraPlugins: [
406+
new MetadataPlugin({
407+
rootDir: dir, watch: false, artifactWatch: false, registerSystemObjects: false,
408+
artifactSource: { mode: 'local-file', path: artifactPath },
409+
}),
410+
],
411+
});
412+
admin = await stack.signIn();
413+
metadata = await stack.kernel.getServiceAsync('metadata');
414+
}, 300_000);
415+
416+
afterAll(async () => {
417+
await stack?.stop?.();
418+
if (dir) rmSync(dir, { recursive: true, force: true });
419+
});
420+
421+
const layers = async (type: string, name: string, pkg?: string) => {
422+
const r = await stack.apiAs(admin, 'GET', `/meta/${type}/${name}/layers${pkg ? `?package=${pkg}` : ''}`);
423+
const body = (await r.json()) as any;
424+
return { status: r.status, code: body?.code?.label, effective: body?.effective?.label, packageId: body?.packageId, body };
425+
};
426+
427+
it.each(['agent', 'skill'] as const)('%s: `/layers?package=` serves each package\'s own code and effective layer (BASE: both were the package registered last)', async (type) => {
428+
const name = type === 'agent' ? AGENT : SKILL;
429+
for (const p of ['alpha', 'beta'] as const) {
430+
const read = await layers(type, name, `com.qa.bare.${p}`);
431+
expect([read.status, read.code, read.effective, read.packageId], JSON.stringify(read.body).slice(0, 300))
432+
.toEqual([200, `${p} ${type}`, `${p} ${type}`, `com.qa.bare.${p}`]);
433+
}
434+
});
435+
436+
it.each(['agent', 'skill'] as const)('%s: the metadata service holds both packages\' items: a read naming each package answers its own, and the read naming none is refused naming both (BASE: every read answered the package registered last)', async (type) => {
437+
const name = type === 'agent' ? AGENT : SKILL;
438+
expect((await metadata.get(type, name, ALPHA))?.label).toBe(`alpha ${type}`);
439+
expect((await metadata.get(type, name, BETA))?.label).toBe(`beta ${type}`);
440+
expect((await metadata.list(type)).filter((i) => i?.name === name).map((i) => i?.label).sort()).toEqual([`alpha ${type}`, `beta ${type}`]);
441+
const refused = await metadata.get(type, name).then(() => undefined, (e: any) => e);
442+
expect([refused?.code, refused?.status], 'never one of them picked').toEqual(['RESOURCE_CONFLICT', 409]);
443+
for (const holder of [ALPHA, BETA]) expect(String(refused?.message)).toContain(holder);
444+
});
445+
446+
it.each(['agent', 'skill'] as const)('CONTROL — %s: the doors that already resolved by package answer as before: the bare read and the bare layered read refuse naming both, `?package=` serves each package\'s own', async (type) => {
447+
const name = type === 'agent' ? AGENT : SKILL;
448+
for (const path of [`/meta/${type}/${name}`, `/meta/${type}/${name}/layers`]) {
449+
const r = await stack.apiAs(admin, 'GET', path);
450+
expect(r.status, path).toBe(409);
451+
const text = await r.text();
452+
for (const holder of [ALPHA, BETA]) expect(text, path).toContain(holder);
453+
}
454+
for (const p of ['alpha', 'beta'] as const) {
455+
const r = await stack.apiAs(admin, 'GET', `/meta/${type}/${name}?package=com.qa.bare.${p}`);
456+
const it = ((await r.json()) as any)?.item;
457+
expect([r.status, it?.label, it?._packageId]).toEqual([200, `${p} ${type}`, `com.qa.bare.${p}`]);
458+
}
459+
});
460+
461+
it.each(['agent', 'skill'] as const)('CONTROL — %s: one holder per name: every read answers the one package\'s item, bare or by its package', async (type) => {
462+
const name = type === 'agent' ? SOLO_AGENT : SOLO_SKILL;
463+
expect((await metadata.get(type, name))?.label).toBe(`alpha ${type}`);
464+
expect((await metadata.get(type, name, ALPHA))?.label).toBe(`alpha ${type}`);
465+
const bare = await layers(type, name);
466+
expect([bare.status, bare.code, bare.packageId]).toEqual([200, `alpha ${type}`, ALPHA]);
467+
const r = await stack.apiAs(admin, 'GET', `/meta/${type}/${name}`);
468+
const it = ((await r.json()) as any)?.item;
469+
expect([r.status, it?.label, it?._packageId]).toEqual([200, `alpha ${type}`, ALPHA]);
470+
});
471+
});

0 commit comments

Comments
 (0)