1
0

loader.spec.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * REAL-composition tier (packages/AGENTS.md): boot the examples-owned
  3. * tool-pwsh Loader fixture as a subprocess through the same app/boot path a
  4. * deployment uses, execute real foreground and background pwsh commands
  5. * through the tool registry, and assert the assembled model-visible surface:
  6. * schema, prompt section, and rendered results. Self-skips when no `pwsh`
  7. * executable exists (a CI accommodation for hosts without PowerShell).
  8. */
  9. import { readFile } from 'node:fs/promises'
  10. import { join } from 'node:path'
  11. import { fileURLToPath } from 'node:url'
  12. import { spawnSync } from 'node:child_process'
  13. import { describe, expect, it } from 'vitest'
  14. import { LOADER_SMOKE_TEST_TIMEOUT_MS, runLoaderSmoke } from '@deepseek-ai/dsh-loader-smoke'
  15. import { resolvePwshPath } from '@deepseek-ai/dsh-pwsh-local'
  16. // The probe follows the executor's own resolution (Program Files installs on
  17. // Windows are found even when bare `pwsh` is not on PATH).
  18. const hasPwsh = spawnSync(resolvePwshPath(), ['-NoLogo', '-NoProfile', '-NonInteractive', '-Command', '$true'], { encoding: 'utf8' }).status === 0
  19. const driver = fileURLToPath(new URL(
  20. '../../../../examples/acp-agent/tests/fixtures/bash/tool-pwsh/driver.ts',
  21. import.meta.url,
  22. ))
  23. const configPath = fileURLToPath(new URL(
  24. '../../../../examples/acp-agent/tests/fixtures/bash/tool-pwsh/cordis.yml',
  25. import.meta.url,
  26. ))
  27. const repoTsconfig = fileURLToPath(new URL('../../../../tsconfig.json', import.meta.url))
  28. interface PwshLoaderReport {
  29. schemaHasRunInBackground: boolean
  30. promptHasMarkerSection: boolean
  31. foregroundText: string
  32. backgroundText: string
  33. }
  34. describe.skipIf(!hasPwsh)('tool-pwsh through a real Loader composition', () => {
  35. it('registers the pwsh surface and renders real foreground and background results', async () => {
  36. let report: PwshLoaderReport | undefined
  37. const { stderr } = await runLoaderSmoke({
  38. label: 'tool-pwsh loader smoke',
  39. tempDirPrefix: 'tool-pwsh-loader-',
  40. binScript: driver,
  41. libBinScript: driver,
  42. configPath,
  43. tsconfigPath: repoTsconfig,
  44. inspect: async (cwd) => {
  45. report = JSON.parse(await readFile(join(cwd, 'pwsh-loader-report.json'), 'utf8')) as PwshLoaderReport
  46. },
  47. })
  48. expect(stderr).not.toContain('UNHANDLED')
  49. expect(report).toBeDefined()
  50. expect(report).toMatchObject({
  51. schemaHasRunInBackground: true,
  52. promptHasMarkerSection: true,
  53. })
  54. expect(report?.foregroundText).toBe('loader-ok\n')
  55. expect(report?.backgroundText).toContain('loader-bg-ok')
  56. expect(report?.backgroundText).toContain('[status: completed, exit code: 0]')
  57. }, LOADER_SMOKE_TEST_TIMEOUT_MS)
  58. })