web-agent-presets.e2e.ts 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970
  1. import { randomUUID } from 'node:crypto'
  2. import { mkdir, mkdtemp, readFile, stat, symlink, writeFile } from 'node:fs/promises'
  3. import { tmpdir } from 'node:os'
  4. import { fileURLToPath } from 'node:url'
  5. import { dirname, join } from 'node:path'
  6. import { Context } from '@deepseek-ai/cordis'
  7. import { boot, healProfilesModuleFallback, loadOverlayPatches, loadProfile } from '@deepseek-ai/dsh-app-boot'
  8. import { provideCmdline } from '@deepseek-ai/dsh-cmdline'
  9. import { SessionId } from '@deepseek-ai/dsh-session'
  10. import type { Agent } from '@deepseek-ai/dsh-agent'
  11. import type { PatchOptions } from '@deepseek-ai/cordis-plugin-include'
  12. import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'
  13. import { settingsNamespace } from '@deepseek-ai/dsh-settings'
  14. import { SUBAGENT_MODEL_SELECTION_SETTINGS_NAMESPACE } from '@deepseek-ai/dsh-tool-subagent/model-selection-settings'
  15. import { SETTINGS_NAMESPACE, SHIPPED_PRESET_ROOT } from '@deepseek-ai/dsh-agent-presets'
  16. import { applyChildComposition, childSessionMeta } from '@deepseek-ai/dsh-subagent'
  17. import { ToolCallId } from '@deepseek-ai/dsh-llm'
  18. import type {} from '@deepseek-ai/dsh-compaction-basic'
  19. import type {} from '@deepseek-ai/dsh-skill'
  20. import type {} from '@deepseek-ai/dsh-tools'
  21. // Type-only: resolves `ctx.get('sessionProjections')` and `ctx.get('tokenMeter')`.
  22. import type {} from '@deepseek-ai/dsh-session-projection'
  23. import type {} from '@deepseek-ai/dsh-token-meter'
  24. const REPO_ROOT = fileURLToPath(new URL('../../..', import.meta.url))
  25. /** The shipped Web surface: the dsh-base and dsh-web-app bundle patches over an empty preset root. */
  26. const BASE_PATCH = join(REPO_ROOT, 'packages/bundle/base/cordis.patch.yml')
  27. const WEB_PATCH = join(REPO_ROOT, 'packages/bundle/web-app/cordis.patch.yml')
  28. const CODEX_PACKAGE_DIR = join(REPO_ROOT, 'packages/subagent/subagent-codex')
  29. const CLAUDE_CODE_PACKAGE_DIR = join(REPO_ROOT, 'packages/subagent/subagent-claude-code')
  30. /** The installation anchor whose dependency surface the preset module fallback mirrors. */
  31. const INSTALL_ANCHOR = join(REPO_ROOT, 'apps/cli/package.json')
  32. const MINIMAL_PROMPT = 'You are a helpful software engineer assistant.'
  33. const MINIMAL_BASH_DESCRIPTION = `Run commands in a bash shell
  34. * When invoking this tool, the contents of the "command" parameter does NOT need to be XML-escaped.
  35. * You don't have access to the internet via this tool.
  36. * You do have access to a mirror of common linux and python packages via apt and pip.
  37. * State is persistent across command calls and discussions with the user.
  38. * To inspect a particular line range of a file, e.g. lines 10-25, try 'sed -n 10,25p /path/to/the/file'.
  39. * Please avoid commands that may produce a very large amount of output.
  40. * Please run long lived commands in the background, e.g. 'sleep 10 &' or start a server in the background.`
  41. /**
  42. * Boot the shipped Web composition, minus the rows that would bind a port,
  43. * touch the network, or write outside the test. Everything that decides an
  44. * agent's capabilities is the real thing, including both shipped presets.
  45. */
  46. async function bootWeb(
  47. settingsFile: string,
  48. extra: PatchOptions[] = [],
  49. profilePackages: readonly string[] = [],
  50. profileBundles?: readonly string[],
  51. ): Promise<Context> {
  52. const storageRoot = join(dirname(settingsFile), 'storages')
  53. const overrides: PatchOptions[] = [
  54. // The settings row defaults to `$DSH_HOME/settings.yaml`. Left alone it
  55. // reads the developer's own document — and since the default preset is a
  56. // setting, a stored `agent-presets.default` would decide this file's
  57. // outcome. Point it at a temp file for the same reason the roster row
  58. // below pins `includeUserRoot` off.
  59. { id: 'settings', config: { path: settingsFile, watch: false } },
  60. // storage-json's root is anchored to the real $DSH_HOME. Unpinned, this
  61. // file writes the developer's own `~/.dsh/storages/` — and then reads it
  62. // back on the next run, so a stored document from any other build decides
  63. // this test's boot. Same reason the settings row above is pinned.
  64. { id: 'storage-json', config: { root: storageRoot } },
  65. // Host rows with side effects outside this process: a bound port, a served
  66. // asset tree, a telemetry exporter. `api-gateway` and `directory-picker`
  67. // stay ENABLED on purpose — the api-proxy is the host row that injects
  68. // `subagents`, `workspace`, and the rest of the agent plane, so disabling
  69. // it would hide exactly the breakage this file exists to catch: a service
  70. // moved into the presets that a host row still waits for. The boot audit
  71. // is that assertion.
  72. { id: 'webserver', disabled: true },
  73. // The web bundle's runtime row injects `webServer`, so it cannot
  74. // activate without the bound port disabled above. It owns dist serving
  75. // and the URL prompt line — surface glue, not anything that decides an
  76. // agent's capabilities, which is all this file asserts.
  77. { id: 'web-runtime', disabled: true },
  78. { id: 'session-telemetry-otel', disabled: true },
  79. // A deployment-level skill on the host registry's GLOBAL layer — the same
  80. // registration shape a repository plugin's skill root uses. The layered
  81. // skills test below proves it reaches preset-composed agents.
  82. { id: 'skill-badge', disabled: false },
  83. { id: 'modules', disabled: true },
  84. { id: 'connection', disabled: true },
  85. // Export owns a Connection Fetch route, so this Host-only composition
  86. // disables it with the transport service above.
  87. { id: 'session-log-download', disabled: true },
  88. // The always-on reload chain waits for the browser roster and bound port
  89. // disabled above.
  90. { id: 'client-hmr', disabled: true },
  91. // The shipped `-auto` chooser resolves its interaction from a running
  92. // host and so waits for the webserver disabled above; the browse variant
  93. // supplies `directoryPicker` without one.
  94. { id: 'directory-picker', disabled: true },
  95. { insert: [
  96. { id: 'directory-picker-browse', name: '@deepseek-ai/dsh-host-directory-picker-browse' },
  97. { id: 'ui-directory-picker-browse', name: '@deepseek-ai/dsh-client-ui-directory-picker-browse' },
  98. ] },
  99. // Pin the roster away from the developer's machine: `includeUserRoot`
  100. // false keeps `~/.dsh/.agent-presets` from changing a test's outcome.
  101. // `default` here is the COMPOSITION default — the base layer the settings
  102. // document overrides. No `roots` entry: the plugin bundles the shipped
  103. // presets itself and prepends their root.
  104. { id: 'agent-presets', config: { default: 'standard', includeUserRoot: false } },
  105. ...extra,
  106. ]
  107. // The surface is patch layers over an empty preset root, so the root sits
  108. // outside this workspace and bare plugin names cannot resolve by Node's
  109. // upward walk. The flat fallback the preset boot maintains is what makes
  110. // them resolvable — the same mechanism, not a test-only shim.
  111. const home = dirname(settingsFile)
  112. await healProfilesModuleFallback({ installAnchor: INSTALL_ANCHOR, home })
  113. const profileDir = join(home, 'profiles', 'spec')
  114. await mkdir(profileDir, { recursive: true })
  115. // Product Bundles are installed into the Profile, not the dsh app. Model
  116. // pnpm's package link for only the selected products; their own production
  117. // dependencies resolve from the linked workspace packages, while shared
  118. // peers still resolve through the installation fallback above.
  119. for (const packageDir of profilePackages) {
  120. const manifest = JSON.parse(await readFile(join(packageDir, 'package.json'), 'utf8')) as { name: string }
  121. const link = join(profileDir, 'node_modules', manifest.name)
  122. await mkdir(dirname(link), { recursive: true })
  123. await symlink(packageDir, link, 'junction')
  124. }
  125. let bundlePatches: PatchOptions[] = [
  126. ...loadOverlayPatches('dsh-test', BASE_PATCH),
  127. ...loadOverlayPatches('dsh-test', WEB_PATCH),
  128. ]
  129. if (profileBundles !== undefined) {
  130. await writeFile(join(profileDir, 'package.json'), JSON.stringify({
  131. private: true,
  132. dependencies: Object.fromEntries(profileBundles.map(name => [name, 'workspace:*'])),
  133. dsh: { profile: { bundles: profileBundles } },
  134. }, null, 2) + '\n')
  135. const profile = loadProfile('dsh-test', 'spec', INSTALL_ANCHOR, home, { userLayer: false })
  136. bundlePatches = profile.layers.flatMap(layer => layer.patches)
  137. }
  138. const rootConfig = join(profileDir, 'cordis.yml')
  139. await writeFile(rootConfig, '[]\n')
  140. return await boot('dsh-test', rootConfig, [...bundlePatches, ...overrides], (bootCtx) => {
  141. provideCmdline(bootCtx, { args: [], exit: () => {} })
  142. })
  143. }
  144. const toolNames = (ctx: Context, agent?: Agent): string[] =>
  145. ctx.tools.schemas(agent).map(schema => schema.name).sort()
  146. function toolParameterNames(ctx: Context, agent: Agent, toolName: string): string[] {
  147. const schema = ctx.tools.schemas(agent).find(tool => tool.name === toolName)
  148. if (schema === undefined) throw new Error(`missing tool schema ${toolName}`)
  149. const properties = schema.parameters.properties
  150. if (typeof properties !== 'object' || properties === null || Array.isArray(properties)) {
  151. throw new Error(`${toolName} has invalid parameter properties`)
  152. }
  153. return Object.keys(properties).sort()
  154. }
  155. function enablePresetTool(composition: string, id: string): string {
  156. const row = ` - id: ${id}\n`
  157. const start = composition.indexOf(row)
  158. if (start < 0) throw new Error(`missing preset row ${id}`)
  159. const end = composition.indexOf('\n - id:', start + row.length)
  160. const disabled = composition.indexOf(' disabled: true\n', start)
  161. if (disabled < 0 || (end >= 0 && disabled > end)) {
  162. throw new Error(`preset row ${id} is not disabled`)
  163. }
  164. return composition.slice(0, disabled) + composition.slice(disabled + ' disabled: true\n'.length)
  165. }
  166. let ctx: Context
  167. beforeAll(async () => {
  168. const settingsFile = join(await mkdtemp(join(tmpdir(), 'dsh-web-presets-')), 'settings.yaml')
  169. await writeFile(settingsFile, '{}\n')
  170. ctx = await bootWeb(settingsFile)
  171. }, 120_000)
  172. describe('the shipped Web composition', () => {
  173. it('leaves the global tool layer empty', () => {
  174. // Every model-facing tool belongs to a preset, `ask_user_question`
  175. // included: a tool in the global layer reaches EVERY agent regardless of
  176. // which preset composed it, so a two-tool benchmark surface would really
  177. // present three. A regression here means an agent-plane row came back to
  178. // the host composition.
  179. expect(toolNames(ctx)).toEqual([])
  180. })
  181. it('keeps the token meter and its context-meter projections on the host plane', async () => {
  182. // Read before any preset in this file mounts, which is what makes this an
  183. // ownership assertion rather than a mount-order coincidence: a preset-side
  184. // meter sits behind an `isolate` realm and is invisible to `ctx.get`.
  185. //
  186. // The projection registry is process-wide rather than scope-layered, so a
  187. // preset-side meter would also make the browser's context meter appear for
  188. // a `minimal` session the moment some OTHER session mounted a preset that
  189. // carries one, and vanish entirely in a process that only ever ran
  190. // `minimal`. Host ownership is what makes the meter a per-session fact.
  191. expect(ctx.get('tokenMeter')).toBeDefined()
  192. const projections = ctx.get('sessionProjections')
  193. if (projections === undefined) throw new Error('the Web composition must compose a projection registry')
  194. const handle = await ctx.agents.create({
  195. sessionId: SessionId('preset-minimal-meter'),
  196. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'minimal').then(() => undefined),
  197. })
  198. try {
  199. // A subset assertion: `tasks`, `goal`, and the rest register into the
  200. // same process-wide table, and this is about the meter's three units.
  201. expect(Object.keys(projections.snapshot(handle.agent.session).values))
  202. .toEqual(expect.arrayContaining(['contextBreakdown', 'contextPressure', 'tokenUsage']))
  203. } finally {
  204. await handle.dispose()
  205. }
  206. })
  207. it('supplies both shipped presets, and only those, from the system root', async () => {
  208. const listed = await ctx.agentPresets.list()
  209. expect(listed.map(preset => preset.id).sort()).toEqual(['cordis', 'minimal', 'ptc', 'standard'])
  210. expect(listed.every(preset => preset.trust === 'system')).toBe(true)
  211. expect(ctx.agentPresets.defaultId).toBe('standard')
  212. })
  213. it('composes the full agent from `standard`', async () => {
  214. const handle = await ctx.agents.create({
  215. sessionId: SessionId('preset-standard'),
  216. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'standard').then(() => undefined),
  217. })
  218. try {
  219. // The EXACT catalog, not a spot-check: an omission is this design's
  220. // quietest failure mode, because a row that registers into the wrong
  221. // layer mounts cleanly and simply contributes nothing. `glob`/`grep` are
  222. // excluded for the reason the TUI composition e2e excludes them — they
  223. // depend on ripgrep being present on the machine.
  224. expect(toolNames(ctx, handle.agent).filter(name => name !== 'glob' && name !== 'grep')).toEqual([
  225. 'ask_user_question', 'bash', 'create_goal', 'edit', 'exit_plan_mode',
  226. 'get_goal', 'interrupt_agent', 'job_kill', 'job_list', 'job_output', 'list_agents', 'ralph', 'read', 'read_image', 'send_message', 'skill',
  227. 'subagent', 'subagent_fork', 'todo_write', 'update_goal', 'web_fetch', 'web_search',
  228. 'workflow', 'write',
  229. ])
  230. expect(ctx.commands.find(handle.agent, 'goal')).toBeDefined()
  231. } finally {
  232. await handle.dispose()
  233. }
  234. })
  235. it('applies the default-off subagent model allowlist only to new sessions', async () => {
  236. await ctx.settings.update(SUBAGENT_MODEL_SELECTION_SETTINGS_NAMESPACE, {
  237. enabled: false,
  238. allowedModels: [],
  239. })
  240. const disabled = await ctx.agents.create({
  241. sessionId: SessionId('preset-model-selection-disabled'),
  242. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'standard').then(() => undefined),
  243. })
  244. await ctx.settings.update(SUBAGENT_MODEL_SELECTION_SETTINGS_NAMESPACE, {
  245. enabled: true,
  246. allowedModels: [{ provider: 'deepseek-official', model: 'deepseek-v4-flash' }],
  247. })
  248. const enabled = await ctx.agents.create({
  249. sessionId: SessionId('preset-model-selection-enabled'),
  250. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'standard').then(() => undefined),
  251. })
  252. try {
  253. expect(toolNames(ctx, disabled.agent)).not.toContain('list_subagent_models')
  254. expect(toolParameterNames(ctx, disabled.agent, 'subagent')).not.toEqual(expect.arrayContaining([
  255. 'model', 'provider', 'reasoning_effort',
  256. ]))
  257. expect(toolNames(ctx, enabled.agent)).toContain('list_subagent_models')
  258. expect(toolParameterNames(ctx, enabled.agent, 'subagent')).toEqual(expect.arrayContaining([
  259. 'model', 'provider', 'reasoning_effort',
  260. ]))
  261. expect(toolNames(ctx, disabled.agent)).not.toContain('list_subagent_models')
  262. } finally {
  263. await ctx.settings.update(SUBAGENT_MODEL_SELECTION_SETTINGS_NAMESPACE, { enabled: false })
  264. await enabled.dispose()
  265. await disabled.dispose()
  266. }
  267. })
  268. it('composes the exact RL prompt and two tools from `minimal`', async () => {
  269. const handle = await ctx.agents.create({
  270. sessionId: SessionId('preset-minimal'),
  271. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'minimal').then(() => undefined),
  272. })
  273. try {
  274. const assembly = await ctx.systemPrompt.assemble({ scope: handle.agent })
  275. expect(assembly.sections).toEqual([
  276. { name: 'deployment:persona', text: MINIMAL_PROMPT },
  277. ])
  278. expect(assembly.tools.map(tool => tool.name)).toEqual(['bash', 'str_replace_editor'])
  279. expect(assembly.tools.find(tool => tool.name === 'bash')?.description).toBe(MINIMAL_BASH_DESCRIPTION)
  280. expect(JSON.stringify(assembly.tools.find(tool => tool.name === 'str_replace_editor')?.parameters))
  281. .toContain('Absolute path')
  282. expect(ctx.commands.find(handle.agent, 'goal')).toBeUndefined()
  283. expect(ctx.agentPresets.serviceFor(handle.agent, 'compaction')).toBeUndefined()
  284. expect(handle.agent.ctx.get('compaction')).toBeUndefined()
  285. } finally {
  286. await handle.dispose()
  287. }
  288. })
  289. it('keeps two differently composed sessions independent', async () => {
  290. const full = await ctx.agents.create({
  291. sessionId: SessionId('preset-both-full'),
  292. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'standard').then(() => undefined),
  293. })
  294. const minimal = await ctx.agents.create({
  295. sessionId: SessionId('preset-both-minimal'),
  296. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'minimal').then(() => undefined),
  297. })
  298. try {
  299. expect(toolNames(ctx, minimal.agent)).toEqual(['bash', 'str_replace_editor'])
  300. expect(toolNames(ctx, full.agent).length).toBeGreaterThan(10)
  301. await minimal.dispose()
  302. // Tearing the minimal session down leaves the full one whole.
  303. expect(toolNames(ctx, full.agent).length).toBeGreaterThan(10)
  304. expect(toolNames(ctx)).toEqual([])
  305. } finally {
  306. await full.dispose()
  307. }
  308. })
  309. it('composes the cordis agent with its own toolset', async () => {
  310. const handle = await ctx.agents.create({
  311. sessionId: SessionId('preset-cordis'),
  312. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'cordis').then(() => undefined),
  313. })
  314. try {
  315. const tools = toolNames(ctx, handle.agent)
  316. // The self-referential toolset is what distinguishes this preset.
  317. expect(tools).toEqual(expect.arrayContaining([
  318. 'cordis_inspect_list', 'cordis_inspect_query', 'cordis_inspect_self',
  319. 'cordis_define', 'cordis_run', 'cordis_stop', 'cordis_undefine',
  320. ]))
  321. // And it keeps the standard agent's own tools rather than replacing them.
  322. expect(tools).toEqual(expect.arrayContaining(['bash', 'read', 'edit', 'skill']))
  323. expect(tools).not.toContain('str_replace_editor')
  324. expect(ctx.commands.find(handle.agent, 'goal')).toBeDefined()
  325. // The preset's own authoring skill registers into ITS layer of the host
  326. // registry: the cordis agent's view carries it, the global view does not.
  327. const scoped = (await ctx.skills.list({ scope: handle.agent })).map(skill => skill.name)
  328. expect(scoped).toContain('editing-cordis-compositions')
  329. expect((await ctx.skills.list()).map(skill => skill.name)).not.toContain('editing-cordis-compositions')
  330. } finally {
  331. await handle.dispose()
  332. }
  333. })
  334. it('presents `ptc` as PTC mode without disturbing a native session beside it', async () => {
  335. const coded = await ctx.agents.create({
  336. sessionId: SessionId('preset-ptc'),
  337. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'ptc').then(() => undefined),
  338. })
  339. const native = await ctx.agents.create({
  340. sessionId: SessionId('preset-ptc-native'),
  341. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'standard').then(() => undefined),
  342. })
  343. try {
  344. // One tool reaches the MODEL: the transport. The registry's catalog for
  345. // this agent is unchanged — PTC mode collapses the presentation, not
  346. // the capabilities — so the assembly is what carries the claim.
  347. const assembly = await ctx.systemPrompt.assemble({ scope: coded.agent })
  348. expect(assembly.tools.map(tool => tool.name)).toEqual(['run_code'])
  349. expect(toolNames(ctx, coded.agent)).not.toContain('str_replace_editor')
  350. expect(ctx.commands.find(coded.agent, 'goal')).toBeDefined()
  351. const sdk = assembly.sections.find(section => section.name === 'tools:sdk')?.text ?? ''
  352. expect(sdk).not.toContain('str_replace_editor')
  353. expect(sdk).toContain('web_search')
  354. // The presentation is this agent's alone: the deployment default is
  355. // native, and the session composed from `standard` still sees it.
  356. const nativeAssembly = await ctx.systemPrompt.assemble({ scope: native.agent })
  357. expect(nativeAssembly.tools.map(tool => tool.name)).toContain('bash')
  358. expect(nativeAssembly.tools.map(tool => tool.name)).not.toContain('run_code')
  359. expect(nativeAssembly.sections.some(section => section.name === 'tools:sdk')).toBe(false)
  360. } finally {
  361. await native.dispose()
  362. await coded.dispose()
  363. }
  364. })
  365. it('keeps the self-referential toolset out of every other preset', async () => {
  366. const handle = await ctx.agents.create({
  367. sessionId: SessionId('preset-no-cordis'),
  368. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'standard').then(() => undefined),
  369. })
  370. try {
  371. // Editing the live runtime is opt-in per session, not ambient.
  372. expect(toolNames(ctx, handle.agent)).not.toContain('cordis_define')
  373. } finally {
  374. await handle.dispose()
  375. }
  376. })
  377. it('ships the composition-authoring skill inside the preset directory', async () => {
  378. // The preset's skill root is derived from its own `baseUrl`, so the skill
  379. // travels with the directory wherever the preset is installed.
  380. const skill = join(
  381. SHIPPED_PRESET_ROOT, 'cordis', 'skills', 'editing-cordis-compositions', 'SKILL.md',
  382. )
  383. expect((await readFile(skill, 'utf8')).startsWith('---\nname: editing-cordis-compositions')).toBe(true)
  384. })
  385. it('merges the global skill layer into a preset agent\'s catalog, keeping local discovery preset-side', async () => {
  386. const proj = await mkdtemp(join(tmpdir(), 'dsh-preset-skill-proj-'))
  387. await mkdir(join(proj, '.dsh', 'skills', 'project-proof'), { recursive: true })
  388. await writeFile(join(proj, '.dsh', 'skills', 'project-proof', 'SKILL.md'), [
  389. '---',
  390. 'name: project-proof',
  391. 'description: Proves the preset layer discovers project skills beside global ones.',
  392. '---',
  393. '',
  394. 'Project proof body.',
  395. '',
  396. ].join('\n'))
  397. const handle = await ctx.agents.create({
  398. // Unique per run: the composition persists into the ambient DSH home,
  399. // and a fixed id would collide with a log an earlier run left there.
  400. sessionId: SessionId(`preset-skills-standard-${randomUUID()}`),
  401. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'standard').then(() => undefined),
  402. })
  403. try {
  404. // The host (global) view carries the deployment-level provider alone:
  405. // local discovery moved behind the presets with `skill-filesystem`.
  406. expect((await ctx.skills.list({ cwd: proj })).map(skill => skill.name)).toEqual(['dsh-badge'])
  407. // The standard agent's view merges the global layer with its preset's
  408. // own local discovery over the session cwd.
  409. const scoped = (await ctx.skills.list({ cwd: proj, scope: handle.agent })).map(skill => skill.name)
  410. expect(scoped).toContain('dsh-badge')
  411. expect(scoped).toContain('project-proof')
  412. // The preset's own loader tool resolves the global-layer skill.
  413. const loaded = await ctx.tools.execute({
  414. callId: ToolCallId('preset-skills-load'),
  415. name: 'skill',
  416. arguments: { name: 'dsh-badge' },
  417. signal: new AbortController().signal,
  418. agent: handle.agent,
  419. })
  420. expect(loaded.isError).toBe(false)
  421. expect(JSON.stringify(loaded.content)).toContain('powered by dsh')
  422. } finally {
  423. await handle.dispose()
  424. }
  425. })
  426. it('shows a minimal agent the global layer but no loader tool', async () => {
  427. const handle = await ctx.agents.create({
  428. sessionId: SessionId(`preset-skills-minimal-${randomUUID()}`),
  429. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'minimal').then(() => undefined),
  430. })
  431. try {
  432. // Layer visibility is the registry's; whether an agent can USE skills
  433. // stays the preset's choice — minimal mounts no `tool-skill`, so its
  434. // tool table has no loader even though the global layer is readable.
  435. expect((await ctx.skills.list({ scope: handle.agent })).map(skill => skill.name)).toContain('dsh-badge')
  436. expect(toolNames(ctx, handle.agent)).toEqual(['bash', 'str_replace_editor'])
  437. } finally {
  438. await handle.dispose()
  439. }
  440. })
  441. it('never rewrites the preset file it composed from', async () => {
  442. // The Loader persists a tree whose plugin self-disposed, and tearing an
  443. // agent down disposes its whole subtree. Inherited, that rewrote the
  444. // shipped composition — truncating it to `[]` the first time a session
  445. // ended — so `PresetTree` refuses to write at all.
  446. const path = join(SHIPPED_PRESET_ROOT, 'standard', 'agent.cordis.yml')
  447. const before = await readFile(path, 'utf8')
  448. const handle = await ctx.agents.create({
  449. sessionId: SessionId('preset-readonly'),
  450. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'standard').then(() => undefined),
  451. })
  452. await handle.dispose()
  453. // Slack, not a race the number has to win. The write is driven by the
  454. // Loader's fiber-unload listener, which fires as the subtree's fibers
  455. // settle rather than when `dispose()` resolves, and the Loader exposes no
  456. // flush to await. A regression writes synchronously inside that listener,
  457. // so any wait past settlement fails; a longer one only slows the test.
  458. await new Promise(resolve => setTimeout(resolve, 50))
  459. expect(await readFile(path, 'utf8')).toBe(before)
  460. })
  461. })
  462. describe('product Bundle and user-preset intersection', () => {
  463. const presetIds = ['products-none', 'products-codex', 'products-claude', 'products-both'] as const
  464. type Product = 'codex' | 'claude-code'
  465. type PresetId = typeof presetIds[number]
  466. async function bootProducts(installed: readonly Product[]): Promise<Context> {
  467. const root = await mkdtemp(join(tmpdir(), 'dsh-product-presets-'))
  468. const userRoot = join(root, 'presets')
  469. const settingsFile = join(root, 'settings.yaml')
  470. const standard = await readFile(join(SHIPPED_PRESET_ROOT, 'standard', 'agent.cordis.yml'), 'utf8')
  471. await writeFile(settingsFile, '{}\n')
  472. for (const id of presetIds) {
  473. let composition = standard
  474. if (id === 'products-codex' || id === 'products-both') {
  475. composition = enablePresetTool(composition, 'tool-subagent-codex')
  476. }
  477. if (id === 'products-claude' || id === 'products-both') {
  478. composition = enablePresetTool(composition, 'tool-subagent-claude-code')
  479. }
  480. const directory = join(userRoot, id)
  481. await mkdir(directory, { recursive: true })
  482. await writeFile(join(directory, 'agent.cordis.yml'), composition)
  483. }
  484. const packageDir = (product: Product): string => (
  485. product === 'codex' ? CODEX_PACKAGE_DIR : CLAUDE_CODE_PACKAGE_DIR
  486. )
  487. const packageName = (product: Product): string => (
  488. product === 'codex'
  489. ? '@deepseek-ai/dsh-subagent-codex'
  490. : '@deepseek-ai/dsh-subagent-claude-code'
  491. )
  492. return await bootWeb(settingsFile, [
  493. {
  494. id: 'agent-presets',
  495. config: {
  496. default: 'standard',
  497. // The shipped root is the plugin's own, prepended before this.
  498. roots: [{ path: userRoot, trust: 'user' }],
  499. includeUserRoot: false,
  500. },
  501. },
  502. ], installed.map(packageDir), [
  503. '@deepseek-ai/dsh-base',
  504. '@deepseek-ai/dsh-web-app',
  505. ...installed.map(packageName),
  506. ])
  507. }
  508. it('composes the intersection of installed Bundles and enabled preset rows', async () => {
  509. const enabledByPreset: Record<PresetId, Product[]> = {
  510. 'products-none': [],
  511. 'products-codex': ['codex'],
  512. 'products-claude': ['claude-code'],
  513. 'products-both': ['codex', 'claude-code'],
  514. }
  515. const scenarios: Array<{ installed: Product[]; presets: readonly PresetId[] }> = [
  516. { installed: [], presets: ['products-both'] },
  517. { installed: ['codex'], presets: ['products-both'] },
  518. { installed: ['claude-code'], presets: ['products-both'] },
  519. { installed: ['codex', 'claude-code'], presets: presetIds },
  520. ]
  521. for (const { installed, presets } of scenarios) {
  522. const productCtx = await bootProducts(installed)
  523. const spawn = vi.spyOn(productCtx.subprocess, 'spawn')
  524. try {
  525. expect(productCtx.subagents.list()
  526. .filter(name => name === 'codex' || name === 'claude-code')
  527. .sort())
  528. .toEqual([...installed].sort())
  529. for (const id of presets) {
  530. const handle = await productCtx.agents.create({
  531. sessionId: SessionId(`preset-${id}-${installed.join('-') || 'none'}-${randomUUID()}`),
  532. setup: agentCtx => productCtx.agentPresets.mount(agentCtx, id).then(() => undefined),
  533. })
  534. try {
  535. const productTools = enabledByPreset[id]
  536. .filter(product => installed.includes(product))
  537. .map(product => product === 'codex' ? 'subagent_codex' : 'subagent_claude_code')
  538. .sort()
  539. const tools = toolNames(productCtx, handle.agent)
  540. expect(tools.filter(name => name === 'subagent_codex' || name === 'subagent_claude_code'))
  541. .toEqual(productTools)
  542. expect(tools).toEqual(expect.arrayContaining(['job_kill', 'job_list', 'job_output']))
  543. for (const productTool of productTools) {
  544. expect(toolParameterNames(productCtx, handle.agent, productTool)).toEqual([
  545. 'description', 'prompt', 'run_in_background',
  546. ])
  547. }
  548. } finally {
  549. await handle.dispose()
  550. }
  551. }
  552. expect(spawn).not.toHaveBeenCalled()
  553. } finally {
  554. spawn.mockRestore()
  555. await productCtx.fiber.dispose()
  556. }
  557. }
  558. }, 120_000)
  559. it('applies a product-row edit only to later sessions on the preset', async () => {
  560. const productCtx = await bootProducts(['codex'])
  561. const preset = await productCtx.agentPresets.resolve('products-none')
  562. const original = await readFile(preset.path, 'utf8')
  563. const existing = await productCtx.agents.create({
  564. sessionId: SessionId('preset-product-generation-existing'),
  565. setup: agentCtx => productCtx.agentPresets.mount(agentCtx, 'products-none').then(() => undefined),
  566. })
  567. try {
  568. expect(toolNames(productCtx, existing.agent)).not.toContain('subagent_codex')
  569. await writeFile(preset.path, enablePresetTool(original, 'tool-subagent-codex'))
  570. const later = await productCtx.agents.create({
  571. sessionId: SessionId('preset-product-generation-later'),
  572. setup: agentCtx => productCtx.agentPresets.mount(agentCtx, 'products-none').then(() => undefined),
  573. })
  574. try {
  575. expect(toolNames(productCtx, existing.agent)).not.toContain('subagent_codex')
  576. expect(toolNames(productCtx, later.agent)).toContain('subagent_codex')
  577. } finally {
  578. await later.dispose()
  579. }
  580. } finally {
  581. await existing.dispose()
  582. await writeFile(preset.path, original)
  583. await productCtx.fiber.dispose()
  584. }
  585. }, 120_000)
  586. })
  587. describe('a switch survives the session', () => {
  588. it('records the choice so the log states what the agent runs', async () => {
  589. const handle = await ctx.agents.create({
  590. sessionId: SessionId('preset-switch-logged'),
  591. meta: { agentPreset: 'standard' },
  592. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'standard').then(() => undefined),
  593. })
  594. try {
  595. // The api-proxy's select does exactly this pair while the session is blank.
  596. expect(ctx.commands.find(handle.agent, 'goal')).toBeDefined()
  597. await ctx.agentPresets.recompose(handle.agent.ctx, 'minimal')
  598. handle.agent.session.append('agent-preset/selected', { agentPreset: 'minimal' })
  599. expect(ctx.commands.find(handle.agent, 'goal')).toBeUndefined()
  600. // The header keeps the creation fact; the log carries what it runs.
  601. expect(handle.agent.session.header.agentPreset).toBe('standard')
  602. expect(ctx.sessionProjections.stateOf(handle.agent.session, 'agentPreset')).toBe('minimal')
  603. } finally {
  604. await handle.dispose()
  605. }
  606. })
  607. })
  608. describe('a forked session', () => {
  609. it('inherits the composition its seeded history was produced under', async () => {
  610. const parent = await ctx.agents.create({
  611. sessionId: SessionId('preset-fork-parent'),
  612. meta: { agentPreset: 'minimal' },
  613. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'minimal').then(() => undefined),
  614. })
  615. const inherited = ctx.sessionProjections.stateOf(parent.agent.session, 'agentPreset') ?? undefined
  616. const child = await ctx.agents.create({
  617. sessionId: SessionId('preset-fork-child'),
  618. meta: {
  619. parentSession: SessionId('preset-fork-parent'),
  620. seedLength: 0,
  621. ...inherited === undefined ? {} : { agentPreset: inherited },
  622. },
  623. setup: agentCtx => ctx.agentPresets.mount(agentCtx, inherited).then(() => undefined),
  624. })
  625. try {
  626. // Composing nothing would leave the child empty: this layer moved every
  627. // model-facing row out of the host plane, so there is nothing to inherit
  628. // for free any more.
  629. expect(toolNames(ctx, child.agent)).toEqual(toolNames(ctx, parent.agent))
  630. expect(toolNames(ctx, child.agent).length).toBeGreaterThan(0)
  631. } finally {
  632. await child.dispose()
  633. await parent.dispose()
  634. }
  635. })
  636. })
  637. describe('a delegated child', () => {
  638. it('runs on the composition its parent runs on', async () => {
  639. const parent = await ctx.agents.create({
  640. sessionId: SessionId('preset-child-parent'),
  641. meta: { agentPreset: 'standard' },
  642. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'standard').then(() => undefined),
  643. })
  644. // Exactly what an in-process subagent driver's creation window does.
  645. const child = await parent.agent.ctx.agents.create({
  646. sessionId: SessionId('preset-child'),
  647. meta: childSessionMeta(parent.agent, 1, 0),
  648. setup: (agentCtx) => {
  649. applyChildComposition(agentCtx, parent.agent, {})
  650. },
  651. })
  652. try {
  653. expect(toolNames(ctx, child.agent)).toEqual(toolNames(ctx, parent.agent))
  654. // The shipped `standard` preset is the whole coding agent; an empty
  655. // child here is the defect, and equality alone would not catch it.
  656. expect(toolNames(ctx, child.agent)).toContain('bash')
  657. expect(child.agent.session.header.agentPreset).toBe('standard')
  658. } finally {
  659. await child.dispose()
  660. await parent.dispose()
  661. }
  662. })
  663. it('follows a parent that switched preset while blank', async () => {
  664. const parent = await ctx.agents.create({
  665. sessionId: SessionId('preset-child-switch-parent'),
  666. meta: { agentPreset: 'standard' },
  667. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'standard').then(() => undefined),
  668. })
  669. await ctx.agentPresets.recompose(parent.agent.ctx, 'minimal')
  670. const child = await parent.agent.ctx.agents.create({
  671. sessionId: SessionId('preset-child-switch'),
  672. meta: childSessionMeta(parent.agent, 1, 0),
  673. setup: (agentCtx) => {
  674. applyChildComposition(agentCtx, parent.agent, {})
  675. },
  676. })
  677. try {
  678. // The live scope chain is the authority, not the parent's creation
  679. // header — which still names `standard`.
  680. expect(toolNames(ctx, child.agent)).toEqual(toolNames(ctx, parent.agent))
  681. expect(child.agent.session.header.agentPreset).toBe('minimal')
  682. } finally {
  683. await child.dispose()
  684. await parent.dispose()
  685. }
  686. })
  687. })
  688. describe('a launcher that configures no writable root', () => {
  689. // The claim this default exists for, asserted through the real shipped
  690. // bundles rather than a hand-built context: `apps/cli` patches in only the
  691. // system root, and a person's own presets are found anyway because the
  692. // roster derives `<dshHome>/.agent-presets` itself. `$DSH_HOME` is pointed
  693. // at a temp home BEFORE boot — the derived root is resolved when the plugin
  694. // is constructed, and an unpinned run would read the developer's own.
  695. let derivedCtx: Context
  696. let previousHome: string | undefined
  697. beforeAll(async () => {
  698. const home = await mkdtemp(join(tmpdir(), 'dsh-preset-derived-'))
  699. previousHome = process.env.DSH_HOME
  700. process.env.DSH_HOME = home
  701. await mkdir(join(home, '.agent-presets', 'derived-mine'), { recursive: true })
  702. await writeFile(
  703. join(home, '.agent-presets', 'derived-mine', 'agent.cordis.yml'),
  704. '- id: tool-todo\n name: \'@deepseek-ai/dsh-tool-todo\'\n config:\n allowParallelInProgress: true\n',
  705. )
  706. const settingsFile = join(await mkdtemp(join(tmpdir(), 'dsh-preset-derived-settings-')), 'settings.yaml')
  707. await writeFile(settingsFile, '{}\n')
  708. // No configured roots: the shipped one is the plugin's own, and the
  709. // writable one is the roster's own default rather than this patch's job.
  710. derivedCtx = await bootWeb(settingsFile, [{
  711. id: 'agent-presets',
  712. config: { default: 'standard', includeUserRoot: true },
  713. }])
  714. }, 120_000)
  715. afterAll(async () => {
  716. if (previousHome === undefined) delete process.env.DSH_HOME
  717. else process.env.DSH_HOME = previousHome
  718. await derivedCtx.fiber.dispose()
  719. })
  720. it('discovers and mounts a preset the person authored under the harness home', async () => {
  721. const listed = await derivedCtx.agentPresets.list()
  722. const mine = listed.find(preset => preset.id === 'derived-mine')
  723. expect(mine).toMatchObject({ trust: 'user' })
  724. // Omitted rather than undefined: a healthy row carries no `broken` key.
  725. expect(mine?.broken).toBeUndefined()
  726. expect(derivedCtx.agentPresets.authorable).toBe(true)
  727. const handle = await derivedCtx.agents.create({
  728. sessionId: SessionId('preset-derived-root'),
  729. setup: agentCtx => derivedCtx.agentPresets.mount(agentCtx, 'derived-mine').then(() => undefined),
  730. })
  731. try {
  732. expect(toolNames(derivedCtx, handle.agent)).toContain('todo_write')
  733. } finally {
  734. await handle.dispose()
  735. }
  736. })
  737. })
  738. describe('authoring a preset on the shipped composition', () => {
  739. let authorCtx: Context
  740. let userRoot: string
  741. beforeAll(async () => {
  742. userRoot = join(await mkdtemp(join(tmpdir(), 'dsh-preset-authoring-')), 'profiles')
  743. const settingsFile = join(await mkdtemp(join(tmpdir(), 'dsh-preset-authoring-settings-')), 'settings.yaml')
  744. await writeFile(settingsFile, '{}\n')
  745. authorCtx = await bootWeb(settingsFile, [{
  746. id: 'agent-presets',
  747. config: {
  748. default: 'standard',
  749. // The root does not exist yet: a deployment whose user has authored
  750. // nothing is the normal first-run state. The shipped root is the
  751. // plugin's own, prepended before this.
  752. roots: [{ path: userRoot, trust: 'user' }],
  753. includeUserRoot: false,
  754. },
  755. }])
  756. })
  757. it('refuses to copy over or delete a shipped preset', async () => {
  758. await expect(authorCtx.agentPresets.copy('minimal', 'standard')).rejects.toThrow(/already exists/)
  759. await expect(authorCtx.agentPresets.remove('standard')).rejects.toThrow(/ships with the deployment/)
  760. })
  761. it.each(['../escape', 'a/b', '/abs', 'Upper'])('refuses the uncontainable id %j', async (id) => {
  762. // The id becomes a directory name under the user root, so containment is
  763. // checked on the id rather than on the joined path afterwards.
  764. await expect(authorCtx.agentPresets.copy('minimal', id)).rejects.toThrow()
  765. })
  766. it('copies a shipped preset a session then really composes from', async () => {
  767. await authorCtx.agentPresets.copy('minimal', 'my-agent', '我的模式')
  768. // Round-trips through the roster as a `user` row carrying the given name
  769. // and the source's description, over the source's own composition text.
  770. const preset = await authorCtx.agentPresets.resolve('my-agent')
  771. const source = await authorCtx.agentPresets.resolve('minimal')
  772. expect(preset.trust).toBe('user')
  773. expect(preset.name).toBe('我的模式')
  774. expect(preset.description).toBe(source.description)
  775. expect(await authorCtx.agentPresets.read('my-agent')).toBe(await authorCtx.agentPresets.read('minimal'))
  776. // Owner-only, in an owner-only directory: a composition is executable
  777. // configuration on a machine that may have other users.
  778. expect((await stat(preset.path)).mode & 0o777).toBe(0o600)
  779. const handle = await authorCtx.agents.create({
  780. sessionId: SessionId('preset-authored'),
  781. setup: agentCtx => authorCtx.agentPresets.mount(agentCtx, 'my-agent').then(() => undefined),
  782. })
  783. try {
  784. // The same tools the shipped `minimal` composes, from a directory copied
  785. // through the service into a root outside the installed harness.
  786. expect(toolNames(authorCtx, handle.agent)).toEqual(['bash', 'str_replace_editor'])
  787. } finally {
  788. await handle.dispose()
  789. }
  790. })
  791. it('deletes what it copied', async () => {
  792. await authorCtx.agentPresets.copy('minimal', 'doomed')
  793. await authorCtx.agentPresets.remove('doomed')
  794. expect((await authorCtx.agentPresets.list()).map(preset => preset.id)).not.toContain('doomed')
  795. })
  796. })
  797. /**
  798. * Which preset an unnamed session gets is a user setting layered over the
  799. * composition's own default. The package suite proves the layering against a
  800. * hand-built context; this proves it through the shipped `cordis.yml` — that
  801. * the roster and the settings provider are actually wired to each other, and
  802. * that the id the setting names is the one a session composes from.
  803. */
  804. describe('the default preset as a user setting', () => {
  805. it('composes an unnamed session from the stored default, not the composed one', async () => {
  806. expect(ctx.agentPresets.defaultId).toBe('standard')
  807. await ctx.settings.update(settingsNamespace(SETTINGS_NAMESPACE), { default: 'minimal' })
  808. try {
  809. expect(ctx.agentPresets.defaultId).toBe('minimal')
  810. const handle = await ctx.agents.create({
  811. sessionId: SessionId('preset-user-default'),
  812. setup: agentCtx => ctx.agentPresets.mount(agentCtx).then(() => undefined),
  813. })
  814. try {
  815. // `mount()` with no id resolves the effective default. Two tools, not
  816. // `standard`'s catalog: the setting decided the composition.
  817. expect(toolNames(ctx, handle.agent)).toEqual(['bash', 'str_replace_editor'])
  818. } finally {
  819. await handle.dispose()
  820. }
  821. } finally {
  822. // The context is shared with the rest of the file. `replace({})` drops
  823. // the user section wholesale so the field re-inherits the composition
  824. // base; `update` merges, and would leave the override standing.
  825. await ctx.settings.replace(settingsNamespace(SETTINGS_NAMESPACE), {})
  826. }
  827. expect(ctx.agentPresets.defaultId).toBe('standard')
  828. })
  829. })
  830. describe('a session keeps the preset it was created with', () => {
  831. it('refuses to adopt a live session under a different preset', async () => {
  832. const handle = await ctx.agents.create({
  833. sessionId: SessionId('preset-locked'),
  834. meta: { agentPreset: 'minimal' },
  835. setup: agentCtx => ctx.agentPresets.mount(agentCtx, 'minimal').then(() => undefined),
  836. })
  837. try {
  838. // The api-proxy guard reads exactly this: the header records what the
  839. // session runs, so naming anything else is a caller error rather than a
  840. // switch. Its history was produced under `minimal`'s two tools.
  841. expect(handle.agent.session.header.agentPreset).toBe('minimal')
  842. } finally {
  843. await handle.dispose()
  844. }
  845. })
  846. })
  847. describe('a composition that configures its own preset roots', () => {
  848. let rootsCtx: Context
  849. let teamRoot: string
  850. beforeAll(async () => {
  851. const home = await mkdtemp(join(tmpdir(), 'dsh-preset-roots-'))
  852. const settingsFile = join(home, 'settings.yaml')
  853. await writeFile(settingsFile, '{}\n')
  854. // A workspace-shared root beside the deployment: one preset of its own,
  855. // plus a directory that claims a shipped id.
  856. teamRoot = join(home, 'team-presets')
  857. const minimalComposition = await readFile(join(SHIPPED_PRESET_ROOT, 'minimal', 'agent.cordis.yml'), 'utf8')
  858. for (const id of ['team-spec', 'minimal']) {
  859. await mkdir(join(teamRoot, id), { recursive: true })
  860. await writeFile(join(teamRoot, id, 'agent.cordis.yml'), minimalComposition)
  861. }
  862. // The user layer of the reported regression: a profile's cordis.patch.yml
  863. // configuring a shared preset root. The plugin must EXTEND it with its
  864. // own shipped root, never lose it.
  865. rootsCtx = await bootWeb(settingsFile, [{
  866. id: 'agent-presets',
  867. config: {
  868. default: 'standard',
  869. roots: [{ path: teamRoot, trust: 'user' }],
  870. includeUserRoot: false,
  871. },
  872. }])
  873. }, 120_000)
  874. afterAll(async () => {
  875. await rootsCtx.fiber.dispose()
  876. })
  877. it('keeps configured roots alongside the always-prepended shipped root', async () => {
  878. expect(rootsCtx.agentPresets.roots.map(root => root.path)).toEqual([
  879. SHIPPED_PRESET_ROOT,
  880. teamRoot,
  881. ])
  882. const listed = await rootsCtx.agentPresets.list()
  883. expect(listed.map(preset => preset.id).sort()).toEqual(['cordis', 'minimal', 'ptc', 'standard', 'team-spec'])
  884. expect(listed.every(preset => preset.broken === undefined)).toBe(true)
  885. // The shipped root comes first: a configured directory claiming a shipped
  886. // id is shadowed, never the other way around.
  887. expect(listed.find(preset => preset.id === 'minimal')?.trust).toBe('system')
  888. expect(listed.find(preset => preset.id === 'team-spec')?.trust).toBe('user')
  889. })
  890. it('composes an agent from a configured-root preset', async () => {
  891. const handle = await rootsCtx.agents.create({
  892. sessionId: SessionId('preset-team-spec'),
  893. setup: agentCtx => rootsCtx.agentPresets.mount(agentCtx, 'team-spec').then(() => undefined),
  894. })
  895. try {
  896. expect(toolNames(rootsCtx, handle.agent)).toEqual(['bash', 'str_replace_editor'])
  897. } finally {
  898. await handle.dispose()
  899. }
  900. })
  901. })