|
35 | 35 | // naming the holder and the rename, as before; of a package declaring the |
36 | 36 | // held tool name is the same 422 naming both holders; none installs; |
37 | 37 | // - 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). |
39 | 45 |
|
40 | 46 | import { mkdtempSync, rmSync } from 'node:fs'; |
41 | 47 | import { tmpdir } from 'node:os'; |
42 | 48 | import { join } from 'node:path'; |
43 | 49 | import { describe, it, expect, beforeAll, afterAll } from 'vitest'; |
44 | | -import { type VerifyStack } from '@objectstack/verify'; |
| 50 | +import { bootStack, type VerifyStack } from '@objectstack/verify'; |
45 | 51 | import { AppPlugin, HttpDispatcher } from '@objectstack/runtime'; |
46 | 52 | import { MarketplaceInstallLocalPlugin } from '@objectstack/cloud-connection'; |
47 | 53 | import { MCPServerPlugin } from '@objectstack/mcp'; |
48 | | -import { defineStack } from '@objectstack/spec'; |
| 54 | +import { MetadataPlugin } from '@objectstack/metadata'; |
| 55 | +import { composeStacks, defineStack } from '@objectstack/spec'; |
49 | 56 | import { PROTOCOL_MAJOR } from '@objectstack/spec/kernel'; |
50 | 57 | import { bootShowcase } from './showcase-boot.js'; |
| 58 | +import { writeBuildShapedArtifact } from './build-shaped-artifact.js'; |
51 | 59 |
|
52 | 60 | const AGENT = 'qa_shared_agent'; |
53 | 61 | const SKILL = 'qa_shared_skill'; |
@@ -356,3 +364,108 @@ describe('agent and skill names held per namespace, a tool name per deployment, |
356 | 364 | expect(await promptText(`gamma-${SKILL}`)).toContain('gamma skill instructions'); |
357 | 365 | }); |
358 | 366 | }); |
| 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