shipped-composition.e2e.ts 9.0 KB

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