web-agent-presets.e2e.ts 45 KB

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