From 9d79da0c62421e4e58646ed9e9b31409596913f3 Mon Sep 17 00:00:00 2001 From: Turtle Date: Mon, 10 Aug 2026 20:26:36 +0800 Subject: [PATCH] test(cli): pin source build-first launch --- apps/cli/tests/source-launch.compat.spec.ts | 31 +++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/apps/cli/tests/source-launch.compat.spec.ts b/apps/cli/tests/source-launch.compat.spec.ts index 68b4f73158..e32b217f98 100644 --- a/apps/cli/tests/source-launch.compat.spec.ts +++ b/apps/cli/tests/source-launch.compat.spec.ts @@ -1,3 +1,6 @@ +import { chmod, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises' +import { delimiter, join } from 'node:path' +import { tmpdir } from 'node:os' import { fileURLToPath } from 'node:url' import { execa } from 'execa' import { describe, expect, it } from 'vitest' @@ -16,6 +19,34 @@ const repoRoot = fileURLToPath(new URL('../../../', import.meta.url)) const dshSourceBin = 'apps/cli/src/bin.ts' describe('dsh SOURCE launcher (node --import tsx/esm)', () => { + it('runs the repository build before launching the source CLI', async () => { + const stubDir = await mkdtemp(join(tmpdir(), 'dsh-source-launch-')) + const invocationLog = join(stubDir, 'pnpm-args.json') + const stubBody = "const { appendFileSync } = require('node:fs')\nappendFileSync(process.env.DSH_TEST_PNPM_LOG, JSON.stringify(process.argv.slice(2)))\n" + await writeFile(join(stubDir, 'pnpm'), `#!/usr/bin/env node\n${stubBody}`) + await chmod(join(stubDir, 'pnpm'), 0o755) + await writeFile(join(stubDir, 'pnpm-stub.cjs'), stubBody) + await writeFile(join(stubDir, 'pnpm.cmd'), '@echo off\r\nnode "%~dp0pnpm-stub.cjs" %*\r\n') + + const pathKey = Object.keys(process.env).find(key => key.toUpperCase() === 'PATH') ?? 'PATH' + try { + const result = await execa(process.execPath, ['--import', 'tsx/esm', 'scripts/run-source-dsh.ts', '--help'], { + cwd: repoRoot, + env: { + ...process.env, + [pathKey]: `${stubDir}${delimiter}${process.env[pathKey] ?? ''}`, + DSH_TEST_PNPM_LOG: invocationLog, + }, + reject: false, + }) + expect(result.exitCode).toBe(0) + expect(result.stdout).toMatch(/^Usage: dsh /) + await expect(readFile(invocationLog, 'utf8')).resolves.toBe('["run","build"]') + } finally { + await rm(stubDir, { recursive: true, force: true }) + } + }) + it('builds without mixing build logs into CLI stdout', async () => { const result = await execa('pnpm', ['dsh', '--help'], { cwd: repoRoot,