shipped-composition.e2e.ts 7.5 KB

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