shipped-composition.e2e.ts 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. // Boots the shipped Web composition over the built dist this lane already uses
  2. // and asserts what that composition produces: the model-visible tool catalog
  3. // and the sandbox/approval knobs it ships with. No browser and no model call —
  4. // these are composition facts, and the browser scenarios in this lane cover the
  5. // surface itself.
  6. import { tmpdir } from 'node:os'
  7. import { afterEach, expect, it } from 'vitest'
  8. import { CallId } from '@deepseek-ai/dsh-llm'
  9. import { canonicalPath, writableRoots } from '@deepseek-ai/dsh-sandbox'
  10. import { SessionId } from '@deepseek-ai/dsh-session'
  11. // Empty type imports carry the tools/sandboxPolicy/approval Context merges.
  12. import type {} from '@deepseek-ai/dsh-tools'
  13. import type {} from '@deepseek-ai/dsh-sandbox-policy'
  14. import type {} from '@deepseek-ai/dsh-user-approval'
  15. import type {} from '@deepseek-ai/dsh-permission'
  16. import type {} from '@deepseek-ai/dsh-agent-presets'
  17. import type {} from '@deepseek-ai/dsh-commands'
  18. import { launchWebScaffold, type WebScaffold } from './scaffold.ts'
  19. /**
  20. * The catalog the shipped Web composition puts in front of the model, minus the
  21. * ripgrep-dependent pair below. The absences are deliberate, not incidental
  22. * gaps: the `cordis_*` toolset executes model-written JavaScript that no
  23. * sandbox row confines, `web_fetch` chooses its own request target, and
  24. * `mcp_*` servers spawn outside `ctx.bash`. The composition Agent Note owns the
  25. * rationale and its sources.
  26. */
  27. const EXPECTED_TOOLS = [
  28. 'ask_user_question',
  29. 'bash',
  30. 'create_goal',
  31. 'edit',
  32. 'exit_plan_mode',
  33. 'get_goal',
  34. 'interrupt_agent',
  35. 'list_agents',
  36. 'ralph',
  37. 'read',
  38. 'read_image',
  39. 'send_message',
  40. 'skill',
  41. 'subagent',
  42. 'subagent_fork',
  43. 'task_kill',
  44. 'task_list',
  45. 'task_output',
  46. 'todo_write',
  47. 'update_goal',
  48. 'web_search',
  49. 'workflow',
  50. 'write',
  51. ]
  52. /**
  53. * `glob` and `grep` come from `dsh-tool-fs-search`, which spawns the PACKAGED
  54. * ripgrep binary (`@vscode/ripgrep`) through the subprocess seam, so the pair
  55. * is always present on every host — asserted as fixed members, not a host
  56. * dependency.
  57. */
  58. const RIPGREP_TOOLS = ['glob', 'grep']
  59. let scaffold: WebScaffold | undefined
  60. afterEach(async () => {
  61. await scaffold?.close()
  62. scaffold = undefined
  63. })
  64. it('assembles the shipped Web catalog with the confined access default', async () => {
  65. scaffold = await launchWebScaffold()
  66. const ctx = scaffold.ctx
  67. // The catalog belongs to an AGENT, not to the process: every model-facing row
  68. // now lives in a preset mounted under one session's scope, so the global
  69. // layer holds nothing and a caller must name the agent to see anything. This
  70. // composes from the deployment default — what a session that names no preset
  71. // gets — which is the shape this test has always been about.
  72. expect(ctx.tools.schemas().map(schema => schema.name)).toEqual([])
  73. const handle = await ctx.agents.create({
  74. sessionId: SessionId('shipped-composition'),
  75. setup: agentCtx => ctx.agentPresets.mount(agentCtx).then(() => undefined),
  76. })
  77. try {
  78. const names = ctx.tools.schemas(handle.agent).map(schema => schema.name).sort()
  79. expect(names.filter(name => !RIPGREP_TOOLS.includes(name))).toEqual(EXPECTED_TOOLS)
  80. // The packaged ripgrep binary ships with the dependency, so the pair is a
  81. // fixed roster member on every host.
  82. expect(names.filter(name => RIPGREP_TOOLS.includes(name))).toEqual(RIPGREP_TOOLS)
  83. } finally {
  84. await handle.dispose()
  85. }
  86. // `workspace-write` is not "the workspace and nothing else": the shared roots
  87. // helper always admits the temp directories too. Pinning it against an
  88. // explicit mode keeps the claim independent of this surface's default, and
  89. // keeps a future sandbox-confinement test from being run inside /tmp — where an
  90. // "escape" write succeeds by design and reads as a sandbox failure.
  91. expect(writableRoots(scaffold.ctx.sandboxPolicy.resolve({ mode: 'workspace-write' }))).toEqual(
  92. expect.arrayContaining([canonicalPath('/tmp'), canonicalPath(tmpdir())]),
  93. )
  94. expect(scaffold.ctx.sandboxPolicy.defaultMode).toBe('workspace-write')
  95. expect(scaffold.ctx.approval.config.policy).toBe('ask')
  96. expect(scaffold.ctx.permission.defaultPreset).toBe('workspace-write')
  97. const commandHandle = await scaffold.ctx.agents.create({
  98. sessionId: SessionId('shipped-command-catalog'),
  99. meta: { cwd: scaffold.workspaceCwd },
  100. agentOptions: { provider: 'deepseek-official', model: 'deepseek-v4-flash' },
  101. })
  102. try {
  103. expect(scaffold.ctx.commands.list(commandHandle.agent)).toContainEqual({
  104. name: 'feedback',
  105. description: 'record feedback about this session',
  106. input: { hint: '<text>' },
  107. })
  108. } finally {
  109. await commandHandle.dispose()
  110. }
  111. }, 120_000)
  112. it('lets a preset producer reach the background-task registry', async () => {
  113. scaffold = await launchWebScaffold()
  114. const ctx = scaffold.ctx
  115. const handle = await ctx.agents.create({
  116. sessionId: SessionId('shipped-background-task'),
  117. meta: { cwd: scaffold.workspaceCwd },
  118. setup: agentCtx => ctx.agentPresets.mount(agentCtx).then(() => undefined),
  119. })
  120. try {
  121. const signal = new AbortController().signal
  122. // `tool-bash` is a preset row and `tasks` is a host registry; the producer
  123. // resolves it with `ctx.get`, so a registry hidden behind a preset realm
  124. // fails here — with every task control still listed in the catalog above.
  125. const started = await ctx.tools.execute({
  126. signal,
  127. callId: CallId('shipped-bash-background'),
  128. name: 'bash',
  129. arguments: {
  130. command: 'printf SHIPPED_BACKGROUND_OK',
  131. description: 'shipped background probe',
  132. run_in_background: true,
  133. },
  134. agent: handle.agent,
  135. })
  136. expect({ isError: started.isError, content: started.content }).toEqual({
  137. isError: false,
  138. content: [{ type: 'text', text: 'started background task bash-1' }],
  139. })
  140. // The controller reads what the producer started: same registry, one
  141. // owner. A per-preset registry would list nothing here even on success.
  142. const listed = await ctx.tools.execute({
  143. signal,
  144. callId: CallId('shipped-task-list'),
  145. name: 'task_list',
  146. arguments: {},
  147. agent: handle.agent,
  148. })
  149. expect(listed.isError).toBe(false)
  150. expect(listed.content).toEqual([
  151. { type: 'text', text: expect.stringContaining('bash-1 [bash]') as unknown as string },
  152. ])
  153. // The full round trip: the output a host-plane producer wrote is collected
  154. // through a preset-plane control, which is the linkage the realm severed.
  155. const collected = await ctx.tools.execute({
  156. signal,
  157. callId: CallId('shipped-task-output'),
  158. name: 'task_output',
  159. arguments: { task_id: 'bash-1', wait: true },
  160. agent: handle.agent,
  161. })
  162. expect(collected.isError).toBe(false)
  163. expect(collected.content).toEqual([
  164. { type: 'text', text: expect.stringContaining('SHIPPED_BACKGROUND_OK') as unknown as string },
  165. ])
  166. } finally {
  167. await handle.dispose()
  168. }
  169. }, 120_000)