base.spec.ts 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * The bundle's substance is its patch file: the `dsh.bundle.patch` manifest
  3. * field must name a real, parseable patch list.
  4. */
  5. import { existsSync, readFileSync } from 'node:fs'
  6. import { fileURLToPath } from 'node:url'
  7. import { resolve } from 'node:path'
  8. import { describe, expect, it } from 'vitest'
  9. import * as yaml from 'js-yaml'
  10. import { entryListSchema } from '@deepseek-ai/cordis-plugin-include'
  11. import { evaluate } from '@deepseek-ai/cordis-plugin-loader'
  12. describe('dsh-base bundle', () => {
  13. it('declares a parseable patch list through the dsh.bundle.patch manifest field', () => {
  14. const root = fileURLToPath(new URL('..', import.meta.url))
  15. const manifest = JSON.parse(
  16. readFileSync(resolve(root, 'package.json'), 'utf8'),
  17. ) as {
  18. dependencies?: Record<string, string>
  19. dsh?: { bundle?: { patch?: string } }
  20. }
  21. expect(manifest.dsh?.bundle?.patch).toBe('./cordis.patch.yml')
  22. const parsed = yaml.load(
  23. readFileSync(resolve(root, manifest.dsh!.bundle!.patch!), 'utf8'),
  24. { schema: entryListSchema },
  25. )
  26. expect(Array.isArray(parsed)).toBe(true)
  27. // The base layer is one insert list over the empty profile root.
  28. const rows = (parsed as { insert?: { id?: string; config?: Record<string, unknown>; disabled?: boolean }[] }[]).flatMap(
  29. patch => patch.insert ?? [],
  30. )
  31. expect(rows.length).toBeGreaterThan(50)
  32. expect(rows.some(row => row.id === 'agent-loop')).toBe(true)
  33. expect(rows.find(row => row.id === 'session-telemetry-otel')?.config?.['mode']).toEqual({
  34. __jsExpr: "process.env.DSH_TELEMETRY_MODE || 'FEEDBACK_ONLY'",
  35. })
  36. expect(rows.find(row => row.id === 'hmr')).toMatchObject({
  37. disabled: true,
  38. config: { root: ['.'] },
  39. })
  40. expect(rows.filter(row => row.id === 'subagent-codex')).toHaveLength(0)
  41. expect(rows.filter(row => row.id === 'subagent-claude-code')).toHaveLength(0)
  42. expect(rows.find(row => row.id === 'web')?.config).toMatchObject({ fetchProvider: 'http' })
  43. expect(rows.find(row => row.id === 'web-fetch-http')).toBeDefined()
  44. expect(rows.find(row => row.id === 'tool-web')?.config).toMatchObject({ fetch: true })
  45. expect(manifest.dependencies).not.toHaveProperty('@deepseek-ai/dsh-subagent-codex')
  46. expect(manifest.dependencies).not.toHaveProperty('@deepseek-ai/dsh-subagent-claude-code')
  47. expect(manifest.dependencies).toHaveProperty('@deepseek-ai/dsh-web-fetch-http')
  48. })
  49. it('gates each shell stack by platform with a symmetric disabled expression', () => {
  50. const root = fileURLToPath(new URL('..', import.meta.url))
  51. const parsed = yaml.load(
  52. readFileSync(resolve(root, 'cordis.patch.yml'), 'utf8'),
  53. { schema: entryListSchema },
  54. )
  55. if (!Array.isArray(parsed)) throw new TypeError('base patch must parse to a patch list')
  56. const rows = parsed.flatMap((patch): Record<string, unknown>[] =>
  57. typeof patch === 'object' && patch !== null
  58. ? (patch as { insert?: Record<string, unknown>[] }).insert ?? []
  59. : [],
  60. )
  61. // Symmetric gating: each stack's executor and tool rows carry the same
  62. // platform fact, inverted between the bash and pwsh twins, so exactly one
  63. // shell stack mounts per host. Evaluate with a platform-scoped context
  64. // (the `with` scope shadows the global `process`) so both outcomes pin on
  65. // every host.
  66. for (const [id, win32, linux] of [
  67. ['bash-sandbox', true, false],
  68. ['tool-bash', true, false],
  69. ['pwsh-sandbox', false, true],
  70. ['tool-pwsh', false, true],
  71. ] as const) {
  72. const row = rows.find(candidate => candidate.id === id)
  73. if (row === undefined) throw new Error(`base patch must mount ${id}`)
  74. const expression = (row.disabled as { __jsExpr?: string } | undefined)?.__jsExpr
  75. if (expression === undefined) throw new Error(`${id} must gate on a !!js disabled expression`)
  76. expect(Boolean(evaluate({ process: { platform: 'win32' } }, expression)), `${id} on win32`).toBe(win32)
  77. expect(Boolean(evaluate({ process: { platform: 'linux' } }, expression)), `${id} on linux`).toBe(linux)
  78. }
  79. // The platform layer folded into these rows: no separate patch file ships.
  80. expect(existsSync(resolve(root, 'windows.cordis.patch.yml'))).toBe(false)
  81. })
  82. })