base.spec.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 || 'DISABLED'",
  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(manifest.dependencies).not.toHaveProperty('@deepseek-ai/dsh-subagent-codex')
  43. expect(manifest.dependencies).not.toHaveProperty('@deepseek-ai/dsh-subagent-claude-code')
  44. })
  45. it('gates each shell stack by platform with a symmetric disabled expression', () => {
  46. const root = fileURLToPath(new URL('..', import.meta.url))
  47. const parsed = yaml.load(
  48. readFileSync(resolve(root, 'cordis.patch.yml'), 'utf8'),
  49. { schema: entryListSchema },
  50. )
  51. if (!Array.isArray(parsed)) throw new TypeError('base patch must parse to a patch list')
  52. const rows = parsed.flatMap((patch): Record<string, unknown>[] =>
  53. typeof patch === 'object' && patch !== null
  54. ? (patch as { insert?: Record<string, unknown>[] }).insert ?? []
  55. : [],
  56. )
  57. // Symmetric gating: each stack's executor and tool rows carry the same
  58. // platform fact, inverted between the bash and pwsh twins, so exactly one
  59. // shell stack mounts per host. Evaluate with a platform-scoped context
  60. // (the `with` scope shadows the global `process`) so both outcomes pin on
  61. // every host.
  62. for (const [id, win32, linux] of [
  63. ['bash-sandbox', true, false],
  64. ['tool-bash', true, false],
  65. ['pwsh-sandbox', false, true],
  66. ['tool-pwsh', false, true],
  67. ] as const) {
  68. const row = rows.find(candidate => candidate.id === id)
  69. if (row === undefined) throw new Error(`base patch must mount ${id}`)
  70. const expression = (row.disabled as { __jsExpr?: string } | undefined)?.__jsExpr
  71. if (expression === undefined) throw new Error(`${id} must gate on a !!js disabled expression`)
  72. expect(Boolean(evaluate({ process: { platform: 'win32' } }, expression)), `${id} on win32`).toBe(win32)
  73. expect(Boolean(evaluate({ process: { platform: 'linux' } }, expression)), `${id} on linux`).toBe(linux)
  74. }
  75. // The platform layer folded into these rows: no separate patch file ships.
  76. expect(existsSync(resolve(root, 'windows.cordis.patch.yml'))).toBe(false)
  77. })
  78. })