shipped-composition.e2e.ts 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. 'send_message',
  39. 'skill',
  40. 'subagent',
  41. 'subagent_fork',
  42. 'task_kill',
  43. 'task_list',
  44. 'task_output',
  45. 'todo_write',
  46. 'update_goal',
  47. 'web_search',
  48. 'workflow',
  49. 'write',
  50. ]
  51. /**
  52. * `glob` and `grep` come from `dsh-tool-fs-search`, which spawns the PACKAGED
  53. * ripgrep binary (`@vscode/ripgrep`) through the subprocess seam, so the pair
  54. * is always present on every host — asserted as fixed members, not a host
  55. * dependency.
  56. */
  57. const RIPGREP_TOOLS = ['glob', 'grep']
  58. let scaffold: WebScaffold | undefined
  59. afterEach(async () => {
  60. await scaffold?.close()
  61. scaffold = undefined
  62. })
  63. it('assembles the shipped Web catalog with the confined access default', async () => {
  64. scaffold = await launchWebScaffold()
  65. const ctx = scaffold.ctx
  66. // The catalog belongs to an AGENT, not to the process: every model-facing row
  67. // now lives in a preset mounted under one session's scope, so the global
  68. // layer holds nothing and a caller must name the agent to see anything. This
  69. // composes from the deployment default — what a session that names no preset
  70. // gets — which is the shape this test has always been about.
  71. expect(ctx.tools.schemas().map(schema => schema.name)).toEqual([])
  72. const handle = await ctx.agents.create({
  73. sessionId: SessionId('shipped-composition'),
  74. setup: agentCtx => ctx.agentPresets.mount(agentCtx).then(() => undefined),
  75. })
  76. try {
  77. const names = ctx.tools.schemas(handle.agent).map(schema => schema.name).sort()
  78. expect(names.filter(name => !RIPGREP_TOOLS.includes(name))).toEqual(EXPECTED_TOOLS)
  79. // The packaged ripgrep binary ships with the dependency, so the pair is a
  80. // fixed roster member on every host.
  81. expect(names.filter(name => RIPGREP_TOOLS.includes(name))).toEqual(RIPGREP_TOOLS)
  82. } finally {
  83. await handle.dispose()
  84. }
  85. // `workspace-write` is not "the workspace and nothing else": the shared roots
  86. // helper always admits the temp directories too. Pinning it against an
  87. // explicit mode keeps the claim independent of this surface's default, and
  88. // keeps a future sandbox-confinement test from being run inside /tmp — where an
  89. // "escape" write succeeds by design and reads as a sandbox failure.
  90. expect(writableRoots(scaffold.ctx.sandboxPolicy.resolve({ mode: 'workspace-write' }))).toEqual(
  91. expect.arrayContaining([canonicalPath('/tmp'), canonicalPath(tmpdir())]),
  92. )
  93. expect(scaffold.ctx.sandboxPolicy.defaultMode).toBe('workspace-write')
  94. expect(scaffold.ctx.approval.config.policy).toBe('ask')
  95. expect(scaffold.ctx.permission.defaultPreset).toBe('workspace-write')
  96. const commandHandle = await scaffold.ctx.agents.create({
  97. sessionId: SessionId('shipped-command-catalog'),
  98. meta: { cwd: scaffold.workspaceCwd },
  99. agentOptions: { provider: 'deepseek-official', model: 'deepseek-v4-flash' },
  100. })
  101. try {
  102. expect(scaffold.ctx.commands.list(commandHandle.agent)).toContainEqual({
  103. name: 'feedback',
  104. description: 'record feedback about this session',
  105. input: { hint: '<text>' },
  106. })
  107. } finally {
  108. await commandHandle.dispose()
  109. }
  110. }, 120_000)
  111. it('lets a preset producer reach the background-task registry', async () => {
  112. scaffold = await launchWebScaffold()
  113. const ctx = scaffold.ctx
  114. const handle = await ctx.agents.create({
  115. sessionId: SessionId('shipped-background-task'),
  116. meta: { cwd: scaffold.workspaceCwd },
  117. setup: agentCtx => ctx.agentPresets.mount(agentCtx).then(() => undefined),
  118. })
  119. try {
  120. const signal = new AbortController().signal
  121. // `tool-bash` is a preset row and `tasks` is a host registry; the producer
  122. // resolves it with `ctx.get`, so a registry hidden behind a preset realm
  123. // fails here — with every task control still listed in the catalog above.
  124. const started = await ctx.tools.execute({
  125. signal,
  126. callId: CallId('shipped-bash-background'),
  127. name: 'bash',
  128. arguments: {
  129. command: 'printf SHIPPED_BACKGROUND_OK',
  130. description: 'shipped background probe',
  131. run_in_background: true,
  132. },
  133. agent: handle.agent,
  134. })
  135. expect({ isError: started.isError, content: started.content }).toEqual({
  136. isError: false,
  137. content: [{ type: 'text', text: 'started background task bash-1' }],
  138. })
  139. // The control surface reads what the producer started: same registry, one
  140. // owner. A per-preset registry would list nothing here even on success.
  141. const listed = await ctx.tools.execute({
  142. signal,
  143. callId: CallId('shipped-task-list'),
  144. name: 'task_list',
  145. arguments: {},
  146. agent: handle.agent,
  147. })
  148. expect(listed.isError).toBe(false)
  149. expect(listed.content).toEqual([
  150. { type: 'text', text: expect.stringContaining('bash-1 [bash]') as unknown as string },
  151. ])
  152. // The full round trip: the output a host-plane producer wrote is collected
  153. // through a preset-plane control, which is the linkage the realm severed.
  154. const collected = await ctx.tools.execute({
  155. signal,
  156. callId: CallId('shipped-task-output'),
  157. name: 'task_output',
  158. arguments: { task_id: 'bash-1', wait: true },
  159. agent: handle.agent,
  160. })
  161. expect(collected.isError).toBe(false)
  162. expect(collected.content).toEqual([
  163. { type: 'text', text: expect.stringContaining('SHIPPED_BACKGROUND_OK') as unknown as string },
  164. ])
  165. } finally {
  166. await handle.dispose()
  167. }
  168. }, 120_000)