shipped-composition.e2e.ts 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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 HTTP, 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. './expected/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 transport, catalog, guidance, and defaults', async () => {
  72. scaffold = await launchWebScaffold({ deepSeekMissingCredential: true })
  73. const ctx = scaffold.ctx
  74. const index = await fetch(`http://127.0.0.1:${String(ctx.webServer.port)}`, {
  75. headers: { 'accept-encoding': 'gzip' },
  76. })
  77. expect(index.headers.get('content-encoding')).toBe('gzip')
  78. expect(index.headers.get('vary')).toContain('Accept-Encoding')
  79. await index.body?.cancel()
  80. expect(ctx.llm.providerRetryPolicy('deepseek-official')).toMatchInlineSnapshot(`
  81. {
  82. "initialDelayMs": 500,
  83. "jitterRatio": 0.1,
  84. "maxDelayMs": 10000,
  85. "maxRetries": 5,
  86. "mode": "normal",
  87. "retryableCodes": [
  88. "EMPTY_RESPONSE",
  89. "RATE_LIMIT",
  90. "SERVER",
  91. "TIMEOUT",
  92. "TRANSPORT",
  93. ],
  94. }
  95. `)
  96. await ctx.settings.update(settingsNamespace('llm-deepseek'), {
  97. retryPolicy: { mode: 'always', maxRetries: 5 },
  98. })
  99. expect(ctx.llm.providerRetryPolicy('deepseek-official')).toMatchInlineSnapshot(`
  100. {
  101. "initialDelayMs": 500,
  102. "jitterRatio": 0.1,
  103. "maxDelayMs": 10000,
  104. "mode": "always",
  105. }
  106. `)
  107. await ctx.settings.update(settingsNamespace('llm-pi-ai'), {
  108. providers: {
  109. openai: {},
  110. anthropic: { retryPolicy: { mode: 'always' } },
  111. },
  112. })
  113. expect(ctx.llm.providerRetryPolicy('openai')).toMatchInlineSnapshot(`
  114. {
  115. "initialDelayMs": 500,
  116. "jitterRatio": 0.1,
  117. "maxDelayMs": 10000,
  118. "maxRetries": 5,
  119. "mode": "normal",
  120. "retryableCodes": [
  121. "EMPTY_RESPONSE",
  122. "RATE_LIMIT",
  123. "SERVER",
  124. "TIMEOUT",
  125. "TRANSPORT",
  126. ],
  127. }
  128. `)
  129. expect(ctx.llm.providerRetryPolicy('anthropic')).toMatchInlineSnapshot(`
  130. {
  131. "initialDelayMs": 500,
  132. "jitterRatio": 0.1,
  133. "maxDelayMs": 10000,
  134. "mode": "always",
  135. }
  136. `)
  137. // The catalog belongs to an AGENT, not to the process: every model-facing row
  138. // now lives in a preset mounted under one session's scope, so the global
  139. // layer holds nothing and a caller must name the agent to see anything. This
  140. // composes from the deployment default — what a session that names no preset
  141. // gets — which is the shape this test has always been about.
  142. expect(ctx.tools.schemas().map(schema => schema.name)).toEqual([])
  143. const handle = await ctx.agents.create({
  144. sessionId: SessionId('shipped-composition'),
  145. setup: agentCtx => ctx.agentPresets.mount(agentCtx).then(() => undefined),
  146. })
  147. try {
  148. const names = ctx.tools.schemas(handle.agent).map(schema => schema.name).sort()
  149. expect(names.filter(name => !RIPGREP_TOOLS.includes(name))).toEqual(EXPECTED_TOOLS)
  150. // The packaged ripgrep binary ships with the dependency, so the pair is a
  151. // fixed roster member on every host.
  152. expect(names.filter(name => RIPGREP_TOOLS.includes(name))).toEqual(RIPGREP_TOOLS)
  153. const fileReferenceSection = (await ctx.systemPrompt.assemble({ scope: handle.agent })).sections
  154. .find(section => section.name === 'ui:deliverable-file-references')
  155. expect(fileReferenceSection?.text).toBe(readFileSync(FILE_REFERENCE_PROMPT, 'utf8').trimEnd())
  156. } finally {
  157. await handle.dispose()
  158. }
  159. // `workspace-write` is not "the workspace and nothing else": the shared roots
  160. // helper always admits the temp directories too. Pinning it against an
  161. // explicit mode keeps the claim independent of this surface's default, and
  162. // keeps a future sandbox-confinement test from being run inside /tmp — where an
  163. // "escape" write succeeds by design and reads as a sandbox failure.
  164. expect(writableRoots(scaffold.ctx.sandboxPolicy.resolve({ mode: 'workspace-write' }))).toEqual(
  165. expect.arrayContaining([canonicalPath('/tmp'), canonicalPath(tmpdir())]),
  166. )
  167. expect(scaffold.ctx.sandboxPolicy.defaultMode).toBe('workspace-write')
  168. expect(scaffold.ctx.approval.config.policy).toBe('ask')
  169. expect(scaffold.ctx.permissionPresets.defaultPreset).toBe('workspace-write')
  170. const commandHandle = await scaffold.ctx.agents.create({
  171. sessionId: SessionId('shipped-command-catalog'),
  172. meta: { cwd: scaffold.workspaceCwd },
  173. agentOptions: { provider: 'deepseek-official', model: 'deepseek-v4-flash' },
  174. })
  175. try {
  176. expect(scaffold.ctx.commands.list(commandHandle.agent)).toContainEqual({
  177. name: 'feedback',
  178. description: 'record feedback about this session',
  179. input: { hint: '<text>' },
  180. })
  181. } finally {
  182. await commandHandle.dispose()
  183. }
  184. }, 120_000)
  185. it('lets a preset producer reach the background-job registry', async () => {
  186. scaffold = await launchWebScaffold()
  187. const ctx = scaffold.ctx
  188. const handle = await ctx.agents.create({
  189. sessionId: SessionId('shipped-background-job'),
  190. meta: { cwd: scaffold.workspaceCwd },
  191. setup: agentCtx => ctx.agentPresets.mount(agentCtx).then(() => undefined),
  192. })
  193. try {
  194. const signal = new AbortController().signal
  195. // `tool-bash` is a preset row and `tasks` is a host registry; the producer
  196. // resolves it with `ctx.get`, so a registry hidden behind a preset realm
  197. // fails here — with every task control still listed in the catalog above.
  198. const started = await ctx.tools.execute({
  199. signal,
  200. callId: CallId('shipped-bash-background'),
  201. name: 'bash',
  202. arguments: {
  203. command: 'printf SHIPPED_BACKGROUND_OK',
  204. description: 'shipped background probe',
  205. run_in_background: true,
  206. },
  207. agent: handle.agent,
  208. })
  209. expect({ isError: started.isError, content: started.content }).toEqual({
  210. isError: false,
  211. content: [{ type: 'text', text: 'started background job bash-1' }],
  212. })
  213. // The controller reads what the producer started: same registry, one
  214. // owner. A per-preset registry would list nothing here even on success.
  215. const listed = await ctx.tools.execute({
  216. signal,
  217. callId: CallId('shipped-task-list'),
  218. name: 'job_list',
  219. arguments: {},
  220. agent: handle.agent,
  221. })
  222. expect(listed.isError).toBe(false)
  223. expect(listed.content).toEqual([
  224. { type: 'text', text: expect.stringContaining('bash-1 [bash]') as unknown as string },
  225. ])
  226. // The full round trip: the output a host-plane producer wrote is collected
  227. // through a preset-plane control, which is the linkage the realm severed.
  228. const collected = await ctx.tools.execute({
  229. signal,
  230. callId: CallId('shipped-task-output'),
  231. name: 'job_output',
  232. arguments: { job_id: 'bash-1', wait: true },
  233. agent: handle.agent,
  234. })
  235. expect(collected.isError).toBe(false)
  236. expect(collected.content).toEqual([
  237. { type: 'text', text: expect.stringContaining('SHIPPED_BACKGROUND_OK') as unknown as string },
  238. ])
  239. } finally {
  240. await handle.dispose()
  241. }
  242. }, 120_000)