built-bin.e2e.ts 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
  2. import { tmpdir } from 'node:os'
  3. import { join } from 'node:path'
  4. import { fileURLToPath, pathToFileURL } from 'node:url'
  5. import { startMockLlmServer } from '@deepseek-ai/dsh-llm-mock-server'
  6. import { execa } from 'execa'
  7. import { afterEach, beforeEach, describe, expect, it } from 'vitest'
  8. /** Published-entry acceptance for argument errors, profile lifecycle, and boot-free config dumps. */
  9. const repoRoot = fileURLToPath(new URL('../../../', import.meta.url))
  10. const dshBin = join(repoRoot, 'apps/cli/lib/bin.js')
  11. const invalidProvider = fileURLToPath(new URL('./fixtures/invalid-provider.cordis.yml', import.meta.url))
  12. async function runBuiltBin(
  13. args: readonly string[] = [],
  14. env: Readonly<Record<string, string | undefined>> = {},
  15. cwd?: string,
  16. ): Promise<{ stdout: string; code: number; stderr: string }> {
  17. const childEnv = Object.fromEntries(
  18. Object.entries({ ...process.env, ...env })
  19. .filter((entry): entry is [string, string] => entry[1] !== undefined),
  20. )
  21. const result = await execa(process.execPath, [dshBin, ...args], {
  22. input: '',
  23. timeout: 25_000,
  24. killSignal: 'SIGKILL',
  25. reject: false,
  26. env: childEnv,
  27. extendEnv: false,
  28. ...cwd === undefined ? {} : { cwd },
  29. })
  30. if (result.timedOut) {
  31. throw new Error(`dsh built bin did not exit within 25s. stdout:\n${result.stdout}\nstderr:\n${result.stderr}`)
  32. }
  33. return { stdout: result.stdout, code: result.exitCode ?? -1, stderr: result.stderr }
  34. }
  35. async function waitForFile(file: string): Promise<void> {
  36. const deadline = Date.now() + 20_000
  37. while (!existsSync(file)) {
  38. if (Date.now() >= deadline) throw new Error(`dsh profile lifecycle marker did not appear: ${file}`)
  39. await new Promise(resolve => setTimeout(resolve, 20))
  40. }
  41. }
  42. interface ProfileLifecycleFixture {
  43. home: string
  44. ready: string
  45. settled: string
  46. disposed: string
  47. interrupt: string
  48. }
  49. /**
  50. * A minimal custom profile: one lifecycle-marker plugin bundle listed in
  51. * dsh.profile.bundles, no dsh-base — proving out-of-box composition machinery without
  52. * booting the entire product tree.
  53. */
  54. function createProfileLifecycleFixture(): ProfileLifecycleFixture {
  55. const home = mkdtempSync(join(tmpdir(), 'dsh-profile-lifecycle-'))
  56. const ready = join(home, 'ready')
  57. const settled = join(home, 'settled')
  58. const disposed = join(home, 'disposed')
  59. const interrupt = join(home, 'interrupt')
  60. const bundleDir = join(home, 'lifecycle-bundle')
  61. mkdirSync(bundleDir, { recursive: true })
  62. writeFileSync(join(bundleDir, 'plugin.mjs'), [
  63. "import { existsSync, writeFileSync } from 'node:fs'",
  64. "import { join } from 'node:path'",
  65. "export const name = 'profile-lifecycle-fixture'",
  66. 'export function apply(ctx, config = {}) {',
  67. ' let active = true',
  68. ' // Keep the event loop alive so process lifetime is signal-owned, like a real surface.',
  69. ' // Windows has no deliverable SIGTERM; the marker emits the same process event there.',
  70. ' let interrupted = false',
  71. ' const heartbeat = setInterval(() => {',
  72. ' if (interrupted || !existsSync(process.env.RAW_INTERRUPT_FILE)) return',
  73. ' interrupted = true',
  74. " process.emit('SIGTERM')",
  75. ' }, 20)',
  76. ' // Echo the mounted generation so the hot-reload e2e can assert both an',
  77. ' // applied override and its removal reverting to this bundle default.',
  78. " writeFileSync(join(process.env.DSH_HOME, 'config-echo'), String(config.generation ?? 'bundle-default'))",
  79. " writeFileSync(process.env.RAW_READY_FILE, 'ready')",
  80. ' void ctx.loader.await().then(() => {',
  81. " if (active) writeFileSync(process.env.RAW_SETTLED_FILE, 'settled')",
  82. ' })',
  83. ' ctx.effect(() => () => {',
  84. ' active = false',
  85. ' clearInterval(heartbeat)',
  86. " writeFileSync(process.env.RAW_DISPOSED_FILE, 'disposed')",
  87. ' })',
  88. '}',
  89. '',
  90. ].join('\n'))
  91. writeFileSync(join(bundleDir, 'cordis.patch.yml'), [
  92. '- insert:',
  93. ' - id: profile-lifecycle-fixture',
  94. ` name: ${pathToFileURL(join(bundleDir, 'plugin.mjs')).href}`,
  95. '',
  96. ].join('\n'))
  97. writeFileSync(join(bundleDir, 'package.json'), JSON.stringify({
  98. name: 'dsh-lifecycle-bundle',
  99. version: '0.0.0',
  100. type: 'module',
  101. dsh: { bundle: { patch: './cordis.patch.yml' } },
  102. }, undefined, 2))
  103. const profileDir = join(home, 'profiles', 'lifecycle')
  104. mkdirSync(join(profileDir, 'node_modules'), { recursive: true })
  105. writeFileSync(join(profileDir, 'package.json'), JSON.stringify({
  106. name: 'dsh-profile-lifecycle',
  107. private: true,
  108. dependencies: {},
  109. dsh: { profile: { bundles: ['dsh-lifecycle-bundle'] } },
  110. }, undefined, 2))
  111. // Hand-place the "installed" bundle where profile resolution finds it.
  112. writeFileSync(join(profileDir, 'cordis.patch.yml'), '[]\n')
  113. const linkTarget = join(profileDir, 'node_modules', 'dsh-lifecycle-bundle')
  114. mkdirSync(join(profileDir, 'node_modules'), { recursive: true })
  115. try {
  116. rmSync(linkTarget, { recursive: true, force: true })
  117. } catch { /* fresh dir */ }
  118. // Copy-free: a package.json redirecting via a relative main is enough for require.resolve.
  119. mkdirSync(linkTarget, { recursive: true })
  120. for (const file of ['package.json', 'cordis.patch.yml', 'plugin.mjs']) {
  121. writeFileSync(join(linkTarget, file), readFileSync(join(bundleDir, file)))
  122. }
  123. return { home, ready, settled, disposed, interrupt }
  124. }
  125. function startProfileLifecycle(fixture: ProfileLifecycleFixture) {
  126. return execa(process.execPath, [dshBin, '--profile', 'lifecycle'], {
  127. cwd: fixture.home,
  128. input: '',
  129. reject: false,
  130. env: {
  131. DSH_HOME: fixture.home,
  132. RAW_READY_FILE: fixture.ready,
  133. RAW_SETTLED_FILE: fixture.settled,
  134. RAW_DISPOSED_FILE: fixture.disposed,
  135. RAW_INTERRUPT_FILE: fixture.interrupt,
  136. },
  137. })
  138. }
  139. function requestProfileShutdown(
  140. child: ReturnType<typeof startProfileLifecycle>,
  141. fixture: ProfileLifecycleFixture,
  142. ): void {
  143. if (process.platform === 'win32') {
  144. writeFileSync(fixture.interrupt, 'interrupt')
  145. return
  146. }
  147. child.kill('SIGTERM')
  148. }
  149. function createEnvironmentProbeProfile(home: string, project: string): void {
  150. const pluginFile = join(project, 'environment-probe.mjs')
  151. writeFileSync(pluginFile, [
  152. "export const name = 'environment-probe'",
  153. "export const inject = ['llm']",
  154. 'export function apply(ctx) {',
  155. ' void ctx.loader.await().then(async () => {',
  156. " let text = ''",
  157. ' for await (const chunk of ctx.llm.stream({',
  158. " provider: 'deepseek-official',",
  159. " model: 'deepseek-v4-flash',",
  160. ' messages: [],',
  161. ' maxTokens: 32,',
  162. ' })) {',
  163. " if (chunk.type === 'text-delta') text += chunk.text",
  164. ' }',
  165. ' process.stdout.write(`${text}\\n`)',
  166. " if (process.platform === 'win32') process.emit('SIGTERM')",
  167. " else process.kill(process.pid, 'SIGTERM')",
  168. ' })',
  169. '}',
  170. '',
  171. ].join('\n'))
  172. const profileDir = join(home, 'profiles', 'environment-probe')
  173. mkdirSync(profileDir, { recursive: true })
  174. writeFileSync(join(profileDir, 'package.json'), JSON.stringify({
  175. name: 'dsh-profile-environment-probe',
  176. private: true,
  177. dependencies: {},
  178. dsh: { profile: { bundles: ['@deepseek-ai/dsh-base'] } },
  179. }, undefined, 2))
  180. writeFileSync(join(profileDir, 'cordis.patch.yml'), [
  181. '- insert:',
  182. ' - id: environment-probe',
  183. ` name: ${pathToFileURL(pluginFile).href}`,
  184. '',
  185. ].join('\n'))
  186. }
  187. describe.skipIf(!existsSync(dshBin))('dsh BUILT bin (node lib/bin.js, no tsx)', () => {
  188. it('requires --profile and rejects inputs outside the current grammar', async () => {
  189. const bare = await runBuiltBin()
  190. expect(bare.code).toBe(1)
  191. expect(bare.stdout).toBe('')
  192. expect(bare.stderr).toContain('--profile <name> is required')
  193. const help = await runBuiltBin(['--help'])
  194. expect(help.code).toBe(0)
  195. expect(help.stdout).toContain('dsh --profile web')
  196. expect(help.stdout).toContain('dsh run "run the tests"')
  197. expect(help.stdout).toContain('dsh plugin --profile')
  198. expect(help.stdout).not.toMatch(/^\s+(?:tui|meta|upgrade)\b/mu)
  199. for (const outsideGrammar of [['tui'], ['--config', 'x.yml'], ['-p', 'task'], ['--profile', 'headless', 'task']]) {
  200. const result = await runBuiltBin(outsideGrammar)
  201. expect(result.code).toBe(1)
  202. }
  203. }, 30_000)
  204. it('prints run help without initializing the selected profile', async () => {
  205. const parent = mkdtempSync(join(tmpdir(), 'dsh-run-help-'))
  206. const home = join(parent, 'not-created')
  207. try {
  208. const result = await runBuiltBin(['run', '--help'], { DSH_HOME: home })
  209. expect(result.code).toBe(0)
  210. expect(result.stderr).toBe('')
  211. expect(result.stdout).toContain('Usage: dsh run [options] <task...>')
  212. expect(existsSync(home)).toBe(false)
  213. } finally {
  214. rmSync(parent, { recursive: true, force: true })
  215. }
  216. })
  217. it('runs the default headless profile through the published run command', async () => {
  218. const apiKey = 'built-dsh-run-key'
  219. const server = await startMockLlmServer({
  220. sequence: ['success'],
  221. apiKey,
  222. successText: 'published dsh run reached the mock',
  223. })
  224. const home = mkdtempSync(join(tmpdir(), 'dsh-built-run-'))
  225. try {
  226. const result = await runBuiltBin(['run', 'answer', 'from', 'the', 'published', 'entry'], {
  227. DSH_HOME: home,
  228. DSH_TELEMETRY_DISABLED: '1',
  229. DEEPSEEK_API_KEY: apiKey,
  230. DEEPSEEK_BASE_URL: server.baseURL,
  231. })
  232. expect(result.code, result.stderr).toBe(0)
  233. expect(result.stdout).toBe('published dsh run reached the mock')
  234. expect(result.stderr).toBe('')
  235. expect(server.requests.length).toBeGreaterThan(0)
  236. expect(server.requests.every(request => request.path === '/chat/completions')).toBe(true)
  237. expect(JSON.stringify(server.requests.map(request => request.body))).toContain('answer from the published entry')
  238. } finally {
  239. await server.close()
  240. rmSync(home, { recursive: true, force: true })
  241. }
  242. }, 30_000)
  243. it('does not load a project environment for --version', async () => {
  244. const project = mkdtempSync(join(tmpdir(), 'dsh-version-project-'))
  245. writeFileSync(join(project, '.env'), 'PATH=/project-only-path\n')
  246. try {
  247. const result = await runBuiltBin(['--version'], {}, project)
  248. expect(result).toEqual({ code: 0, stdout: '0.0.1', stderr: '' })
  249. } finally {
  250. rmSync(project, { recursive: true, force: true })
  251. }
  252. })
  253. it('fails loud on a nonexistent profile with the plugin-command hint', async () => {
  254. const home = mkdtempSync(join(tmpdir(), 'dsh-missing-profile-'))
  255. try {
  256. const result = await runBuiltBin(['--profile', 'nope'], { DSH_HOME: home })
  257. expect(result.code).toBe(1)
  258. expect(result.stderr).toContain('profile "nope" does not exist')
  259. expect(result.stderr).toContain('dsh plugin --profile nope add')
  260. } finally {
  261. rmSync(home, { recursive: true, force: true })
  262. }
  263. }, 30_000)
  264. it('uses the Harness-home environment and managed credential through the published entry', async () => {
  265. const apiKey = 'built-home-layer-key'
  266. const server = await startMockLlmServer({
  267. sequence: ['success'],
  268. apiKey,
  269. successText: 'home environment reached the mock',
  270. })
  271. const home = mkdtempSync(join(tmpdir(), 'dsh-home-environment-'))
  272. const project = mkdtempSync(join(tmpdir(), 'dsh-home-project-'))
  273. writeFileSync(join(home, '.env'), `DEEPSEEK_BASE_URL=${server.baseURL}\n`)
  274. writeFileSync(join(home, '.credentials.yaml'), `DEEPSEEK_API_KEY: ${apiKey}\n`, { mode: 0o600 })
  275. createEnvironmentProbeProfile(home, project)
  276. try {
  277. const result = await runBuiltBin(
  278. ['--profile', 'environment-probe'],
  279. {
  280. DSH_HOME: home,
  281. DSH_TELEMETRY_DISABLED: '1',
  282. DEEPSEEK_API_KEY: undefined,
  283. DEEPSEEK_BASE_URL: undefined,
  284. },
  285. project,
  286. )
  287. expect(
  288. result.code,
  289. `${result.stderr}\nstdout:\n${result.stdout}\nmock requests: ${String(server.requests.length)}`,
  290. ).toBe(0)
  291. expect(result.stdout).toBe('home environment reached the mock')
  292. expect(result.stdout).not.toContain(apiKey)
  293. expect(result.stderr).not.toContain(apiKey)
  294. expect(server.requests).toHaveLength(1)
  295. expect(server.requests[0]?.path).toBe('/chat/completions')
  296. expect(server.requests[0]?.headers.authorization).toBe(`Bearer ${apiKey}`)
  297. expect(JSON.stringify(server.requests[0]?.body)).not.toContain(apiKey)
  298. } finally {
  299. await server.close()
  300. rmSync(home, { recursive: true, force: true })
  301. rmSync(project, { recursive: true, force: true })
  302. }
  303. }, 30_000)
  304. it('reports a patch-overlay boot failure without hanging', async () => {
  305. // An HMR main-watcher initial scan that refreshes the include
  306. // mid-initial-apply deadlocks the failing apply's rollback against the
  307. // refresh drain: dsh exits 13 with no diagnostic instead of settling
  308. // ([Agent Note](../../../.agents/notes/implemented/bug-fix/2026-08-03-hmr-initial-scan-boot-deadlock.md)).
  309. const home = mkdtempSync(join(tmpdir(), 'dsh-invalid-patch-'))
  310. try {
  311. const result = await runBuiltBin(['--profile', 'web', '--patch', invalidProvider], {
  312. DSH_HOME: home,
  313. DEEPSEEK_API_KEY: 'keyless-invalid-config',
  314. DSH_TELEMETRY_DISABLED: '1',
  315. })
  316. expect(result.code).toBe(1)
  317. expect(result.stdout).toBe('')
  318. expect(result.stderr).toContain('llm-pi-ai')
  319. } finally {
  320. rmSync(home, { recursive: true, force: true })
  321. }
  322. }, 30_000)
  323. it('applies a custom profile bundle and disposes it on a startup-time signal', async () => {
  324. const fixture = createProfileLifecycleFixture()
  325. const child = startProfileLifecycle(fixture)
  326. try {
  327. await waitForFile(fixture.ready)
  328. requestProfileShutdown(child, fixture)
  329. const result = await child
  330. expect(result.exitCode, `${result.stderr}\nstdout:\n${result.stdout}\nsignal: ${String(result.signal)}`).toBe(0)
  331. expect(result.signal).toBeUndefined()
  332. expect(existsSync(fixture.disposed)).toBe(true)
  333. } finally {
  334. child.kill('SIGKILL')
  335. rmSync(fixture.home, { recursive: true, force: true })
  336. }
  337. }, 30_000)
  338. it('fully settles a custom profile, hot-reloads its patch layer with removal reverting, and disposes on a signal', async () => {
  339. const fixture = createProfileLifecycleFixture()
  340. const child = startProfileLifecycle(fixture)
  341. const profilePatch = join(fixture.home, 'profiles', 'lifecycle', 'cordis.patch.yml')
  342. const configFile = join(fixture.home, 'config-echo')
  343. try {
  344. await waitForFile(fixture.settled)
  345. // The live profile layer: even without an hmr row in the composition,
  346. // the launcher mounts a config-only watcher, so an edited
  347. // cordis.patch.yml lands in the running tree (the reload disposes the
  348. // patched row's old fiber — observable as the disposed marker — and
  349. // mounts the new config, which echoes its generation and re-writes the
  350. // ready marker).
  351. rmSync(fixture.ready)
  352. writeFileSync(profilePatch, [
  353. '- id: profile-lifecycle-fixture',
  354. ' config:',
  355. ' generation: 2',
  356. '',
  357. ].join('\n'))
  358. await waitForFile(fixture.ready)
  359. expect(readFileSync(configFile, 'utf8')).toBe('2')
  360. // Removal reverts: the bundle's inserted row must return to its own
  361. // default config, not keep the removed override — the insert-aliasing
  362. // regression (a shared patch object mutated in place by a former
  363. // generation would make this impossible).
  364. rmSync(fixture.ready)
  365. writeFileSync(profilePatch, '[]\n')
  366. await waitForFile(fixture.ready)
  367. expect(readFileSync(configFile, 'utf8')).toBe('bundle-default')
  368. // The home-level user layer ($DSH_HOME/cordis.patch.yml) is live too
  369. // and outranks the per-profile layer.
  370. rmSync(fixture.ready)
  371. writeFileSync(join(fixture.home, 'cordis.patch.yml'), [
  372. '- id: profile-lifecycle-fixture',
  373. ' config:',
  374. ' generation: home',
  375. '',
  376. ].join('\n'))
  377. await waitForFile(fixture.ready)
  378. expect(readFileSync(configFile, 'utf8')).toBe('home')
  379. requestProfileShutdown(child, fixture)
  380. const result = await child
  381. expect(result.exitCode, `${result.stderr}\nstdout:\n${result.stdout}\nsignal: ${String(result.signal)}`).toBe(0)
  382. expect(result.signal).toBeUndefined()
  383. expect(existsSync(fixture.disposed)).toBe(true)
  384. } finally {
  385. child.kill('SIGKILL')
  386. rmSync(fixture.home, { recursive: true, force: true })
  387. }
  388. }, 30_000)
  389. it('anchors a relative add spec to the invoking directory, not the profile', async () => {
  390. // `dsh plugin --profile x add .` from a plugin checkout must install THAT
  391. // checkout — pnpm's cwd is the profile directory, so an un-anchored `.`
  392. // would self-link the profile.
  393. const home = mkdtempSync(join(tmpdir(), 'dsh-plugin-anchor-'))
  394. const checkout = mkdtempSync(join(tmpdir(), 'dsh-plugin-checkout-'))
  395. try {
  396. writeFileSync(join(checkout, 'package.json'), JSON.stringify({
  397. name: 'anchored-bundle',
  398. version: '1.0.0',
  399. dsh: { bundle: { patch: './cordis.patch.yml' } },
  400. }))
  401. writeFileSync(join(checkout, 'cordis.patch.yml'), '[]\n')
  402. const result = await execa(process.execPath, [dshBin, 'plugin', '--profile', 'anchor', 'add', '.'], {
  403. cwd: checkout,
  404. input: '',
  405. timeout: 60_000,
  406. killSignal: 'SIGKILL',
  407. reject: false,
  408. env: { DSH_HOME: home },
  409. })
  410. expect(result.exitCode).toBe(0)
  411. const manifest = JSON.parse(readFileSync(join(home, 'profiles', 'anchor', 'package.json'), 'utf8')) as {
  412. dependencies: Record<string, string>
  413. dsh: { profile: { bundles: string[] } }
  414. }
  415. expect(Object.keys(manifest.dependencies)).toEqual(['anchored-bundle'])
  416. expect(manifest.dsh.profile.bundles).toContain('anchored-bundle')
  417. } finally {
  418. rmSync(home, { recursive: true, force: true })
  419. rmSync(checkout, { recursive: true, force: true })
  420. }
  421. }, 90_000)
  422. it('activates a dependency that gained dsh.bundle in a later update', async () => {
  423. // Reconcile runs against the INSTALLED state on every successful pnpm
  424. // run, so `update` (not only `add`) activates a package whose newer
  425. // version declares dsh.bundle. Simulated without a registry: hand-place
  426. // the installed package, flip its manifest, and run a benign pnpm verb.
  427. const home = mkdtempSync(join(tmpdir(), 'dsh-plugin-update-'))
  428. try {
  429. const profileDir = join(home, 'profiles', 'up')
  430. const installed = join(profileDir, 'node_modules', 'late-bundle')
  431. mkdirSync(installed, { recursive: true })
  432. writeFileSync(join(profileDir, 'package.json'), JSON.stringify({
  433. name: 'dsh-profile-up',
  434. private: true,
  435. dependencies: { 'late-bundle': 'file:./late-bundle' },
  436. dsh: { profile: { bundles: ['@deepseek-ai/dsh-base'] } },
  437. }))
  438. writeFileSync(join(profileDir, 'cordis.patch.yml'), '[]\n')
  439. // v1: no dsh manifest — a plain dependency.
  440. writeFileSync(join(installed, 'package.json'), JSON.stringify({ name: 'late-bundle', version: '1.0.0' }))
  441. const first = await runBuiltBin(['plugin', '--profile', 'up', 'root'], { DSH_HOME: home })
  442. expect(first.code).toBe(0)
  443. let manifest = JSON.parse(readFileSync(join(profileDir, 'package.json'), 'utf8')) as { dsh: { profile: { bundles: string[] } } }
  444. expect(manifest.dsh.profile.bundles).toEqual(['@deepseek-ai/dsh-base'])
  445. // v2: the installed package now declares dsh.bundle (an update landed).
  446. writeFileSync(join(installed, 'package.json'), JSON.stringify({
  447. name: 'late-bundle', version: '2.0.0', dsh: { bundle: { patch: './cordis.patch.yml' } },
  448. }))
  449. writeFileSync(join(installed, 'cordis.patch.yml'), '[]\n')
  450. const second = await runBuiltBin(['plugin', '--profile', 'up', 'root'], { DSH_HOME: home })
  451. expect(second.code).toBe(0)
  452. manifest = JSON.parse(readFileSync(join(profileDir, 'package.json'), 'utf8')) as { dsh: { profile: { bundles: string[] } } }
  453. expect(manifest.dsh.profile.bundles).toEqual(['@deepseek-ai/dsh-base', 'late-bundle'])
  454. } finally {
  455. rmSync(home, { recursive: true, force: true })
  456. }
  457. }, 30_000)
  458. describe('config dump', () => {
  459. let home: string
  460. beforeEach(() => { home = mkdtempSync(join(tmpdir(), 'dsh-dump-bin-')) })
  461. afterEach(() => { rmSync(home, { recursive: true, force: true }) })
  462. it('prints the web profile bundle layers without a user layer', async () => {
  463. const { stdout, code, stderr } = await runBuiltBin(['--profile', 'web', '--dump-default-config'], { DSH_HOME: home })
  464. expect(code).toBe(0)
  465. expect(stderr).toBe('')
  466. expect(stdout).toContain("name: '@deepseek-ai/dsh-agent-loop'")
  467. expect(stdout).toContain('agents: []')
  468. expect(stdout).toContain('# == @deepseek-ai/dsh-base')
  469. expect(stdout).toContain("name: '@deepseek-ai/dsh-host-webserver'")
  470. }, 30_000)
  471. it('prints a headless profile with no Host, HTTP, or browser rows', async () => {
  472. const { stdout, code, stderr } = await runBuiltBin(
  473. ['--profile', 'headless', '--dump-default-config'],
  474. { DSH_HOME: home },
  475. )
  476. expect(code).toBe(0)
  477. expect(stderr).toBe('')
  478. expect(stdout).toContain("name: '@deepseek-ai/dsh-agent-default-model'")
  479. expect(stdout).toContain("name: '@deepseek-ai/dsh-headless'")
  480. expect(stdout).not.toContain("name: '@deepseek-ai/dsh-host-")
  481. expect(stdout).not.toContain("name: '@deepseek-ai/dsh-web-app'")
  482. expect(stdout).not.toContain("name: '@deepseek-ai/dsh-client-")
  483. }, 30_000)
  484. it('composes the profile user layer and a --patch overlay in order', async () => {
  485. // Auto-init the web profile first, then write its user layer.
  486. const init = await runBuiltBin(['--profile', 'web', '--dump-default-config'], { DSH_HOME: home })
  487. expect(init.code).toBe(0)
  488. const profilePatch = join(home, 'profiles', 'web', 'cordis.patch.yml')
  489. writeFileSync(profilePatch, [
  490. '- id: agent-loop',
  491. ' config:',
  492. ' agents:',
  493. ' - id: personal',
  494. ' provider: personal-provider',
  495. ' model: personal-model',
  496. '- id: absent-row',
  497. ' config:',
  498. ' x: 1',
  499. '',
  500. ].join('\n'))
  501. const overlay = join(home, 'overlay.cordis.yml')
  502. writeFileSync(overlay, [
  503. '- id: agent-loop',
  504. ' config:',
  505. ' agents:',
  506. ' - id: configured',
  507. ' provider: configured-provider',
  508. ' model: configured-model',
  509. '',
  510. ].join('\n'))
  511. const { stdout, code, stderr } = await runBuiltBin(
  512. ['--profile', 'web', '--patch', overlay, '--dump-config'],
  513. { DSH_HOME: home },
  514. )
  515. expect(code).toBe(0)
  516. expect(stdout).toContain('provider: configured-provider')
  517. expect(stdout).not.toContain('personal-provider')
  518. // Both layers patched the row; the comment lists them in application order.
  519. expect(stdout).toContain(`patched by ${profilePatch}, ${overlay}`)
  520. expect(stderr).toContain('patch: entry "absent-row" not found')
  521. }, 30_000)
  522. })
  523. })