web-agent-presets.e2e.ts 45 KB

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