| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- import { spawn, type ChildProcessWithoutNullStreams } from 'node:child_process'
- import { mkdtemp, rm } from 'node:fs/promises'
- import { tmpdir } from 'node:os'
- import { join } from 'node:path'
- import { fileURLToPath } from 'node:url'
- import { afterEach, describe, expect, it } from 'vitest'
- /**
- * Keyless Loader-path smoke for examples/coding-agent: boot the REAL example
- * through its `cordis.yml` (the cordis Loader, `unwrapExports`, the full plugin
- * tree incl. the extracted `@deepseek-ai/dsh-ui-stdio`), then close stdin with
- * no prompt and assert the ready banner + a clean exit.
- *
- * No prompt is ever sent, so the model is NEVER called — this is why it runs
- * without a real key. coding-agent's `cordis.yml` loads `llm-deepseek`, whose
- * `apply()` only requires a key to be PRESENT (it does not validate it and only
- * uses it when a stream actually starts), so a dummy key lets the tree boot
- * while the absence of any prompt guarantees no network call. The value is the
- * real-Loader-path guard for the shared UI plugin's export shape (a broken
- * `export default` that drops `inject` would crash here — see postmortem 0001),
- * complementing coding-agent's with-key e2e suites which prove the real product.
- */
- const startScript = fileURLToPath(new URL('../start.ts', import.meta.url))
- const tsxLoader = fileURLToPath(import.meta.resolve('tsx'))
- // Dev/test run UNBUILT: resolve `@deepseek-ai/dsh-*` through the root tsconfig
- // `paths` map; tsx searches UP from cwd, and we spawn from a temp dir outside
- // the repo, so point it at the repo tsconfig (root is four levels up).
- const repoTsconfig = fileURLToPath(new URL('../../../tsconfig.json', import.meta.url))
- let child: ChildProcessWithoutNullStreams | undefined
- let workdir: string | undefined
- afterEach(async () => {
- if (child !== undefined && child.exitCode === null) child.kill('SIGKILL')
- child = undefined
- if (workdir !== undefined) await rm(workdir, { recursive: true, force: true })
- workdir = undefined
- })
- async function bootAndEof(): Promise<{ stdout: string; code: number }> {
- workdir = await mkdtemp(join(tmpdir(), 'coding-smoke-'))
- const cwd = workdir
- return new Promise((resolve, reject) => {
- const proc = spawn(
- process.execPath,
- // --expose-internals: cordis.yml loads the HMR plugin (mirrors demo:coding).
- ['--expose-internals', '--import', tsxLoader, startScript],
- {
- cwd,
- env: {
- ...process.env,
- TSX_TSCONFIG_PATH: repoTsconfig,
- // A dummy key so llm-deepseek's apply() (key-PRESENT check only) boots.
- // No prompt is sent, so the adapter never streams — no network call.
- DEEPSEEK_API_KEY: 'keyless-smoke-no-call',
- },
- stdio: ['pipe', 'pipe', 'pipe'],
- },
- )
- child = proc
- let stdout = ''
- let stderr = ''
- proc.stdout.setEncoding('utf8')
- proc.stdout.on('data', (chunk: string) => { stdout += chunk })
- proc.stderr.setEncoding('utf8')
- proc.stderr.on('data', (chunk: string) => { stderr += chunk })
- const timer = setTimeout(() => {
- proc.kill('SIGKILL')
- reject(new Error(`coding-agent did not exit within 10s. stdout:\n${stdout}\nstderr:\n${stderr}`))
- }, 10_000)
- proc.on('exit', (code) => {
- clearTimeout(timer)
- if (code === 0) resolve({ stdout, code })
- else reject(new Error(`coding-agent exited ${code}. stderr:\n${stderr}`))
- })
- proc.on('error', (err) => { clearTimeout(timer); reject(err) })
- // No prompt — just EOF, so the stdio UI exits without ever running a turn.
- proc.stdin.end()
- })
- }
- describe('coding-agent keyless smoke (real cordis.yml via the Loader)', () => {
- it('boots the full plugin tree, prints its banner, and exits cleanly on EOF', async () => {
- const { stdout, code } = await bootAndEof()
- expect(code).toBe(0)
- expect(stdout).toContain('coding-agent ready.')
- }, 15_000)
- })
|