base.spec.ts 3.7 KB

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