From 7233d40fc915214b6fe2b13db9075f4f660d15d1 Mon Sep 17 00:00:00 2001 From: Yichen Jiang Date: Fri, 7 Aug 2026 13:21:03 +0800 Subject: [PATCH] test: cover the two locations the composition test was carrying MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Moving `web-agent-presets` to the built lane took its coverage with it, and the per-file gate named what it had been the only reach for: the session header's `agentPreset` type check, and the preset subtree's `write()` override. Neither belonged to a real-composition boot — a header validation case and a subtree behaviour are package-level facts. The `write()` test states why the override exists: the inherited method persists the tree whenever the Loader thinks the config moved, and disposing an agent disposes its subtree, so inheriting it truncates the shipped preset to `[]` the first time a session ends. --- packages/core/session/tests/session.spec.ts | 1 + .../preset/agent-presets/tests/mount.spec.ts | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/packages/core/session/tests/session.spec.ts b/packages/core/session/tests/session.spec.ts index 1394db01e3..f3d81659aa 100644 --- a/packages/core/session/tests/session.spec.ts +++ b/packages/core/session/tests/session.spec.ts @@ -1319,6 +1319,7 @@ describe('SessionStore', () => { { meta: { delegationDepth: '1' }, error: /delegationDepth must be a non-negative safe integer/ }, { meta: { delegationDepth: 0.5 }, error: /delegationDepth must be a non-negative safe integer/ }, { meta: { delegationDepth: -1 }, error: /delegationDepth must be a non-negative safe integer/ }, + { meta: { agentPreset: 1 }, error: /agentPreset must be a string/ }, ] for (const [index, { meta, error }] of cases.entries()) { diff --git a/packages/preset/agent-presets/tests/mount.spec.ts b/packages/preset/agent-presets/tests/mount.spec.ts index 3ece3db20e..93b77d0047 100644 --- a/packages/preset/agent-presets/tests/mount.spec.ts +++ b/packages/preset/agent-presets/tests/mount.spec.ts @@ -1,3 +1,4 @@ +import { readFile } from 'node:fs/promises' import { dirname, join } from 'node:path' import { fileURLToPath, pathToFileURL } from 'node:url' import { Context } from 'cordis' @@ -217,6 +218,25 @@ describe('a roster with nothing in it', () => { }) describe('attributing a service to a subtree', () => { + it('never writes the preset file back, however the subtree changes', async () => { + const handle = await ctx.agents.create({ + sessionId: SessionId('sess-write'), + setup: async (agentCtx: Context) => void await ctx.agentPresets.mount(agentCtx, 'standard'), + }) + const [mount] = livePresetMounts().filter(entry => entry.presetId === 'standard') + expect(mount).toBeDefined() + const file = join(FIXTURES, 'system', 'standard', 'agent.cordis.yml') + const before = await readFile(file, 'utf8') + + // The inherited `write()` persists the tree whenever the Loader thinks the + // config moved, and disposing an agent disposes its whole subtree — which + // is enough to trigger it. Inheriting that truncates the shipped preset to + // `[]` the first time a session ends. + await handle.dispose() + + expect(await readFile(file, 'utf8')).toBe(before) + }) + it('attributes nothing to a subtree that is already torn down', async () => { const handle = await ctx.agents.create({ sessionId: SessionId('sess-torn'),