diff --git a/scripts/diffex-test.ps1 b/scripts/diffex-test.ps1 index b4c2f5f04..0ce1e05f1 100644 --- a/scripts/diffex-test.ps1 +++ b/scripts/diffex-test.ps1 @@ -59,13 +59,14 @@ if ($noEnv) { Write-Host "Running without API keys..." } -$tsxBin = Join-Path $repoRoot "node_modules/.bin/tsx.cmd" -if (-not (Test-Path -LiteralPath $tsxBin)) { - throw "tsx not found at $tsxBin. Run npm install from the repository root first." +$tsxLoader = Join-Path $repoRoot "node_modules/tsx/dist/loader.mjs" +if (-not (Test-Path -LiteralPath $tsxLoader)) { + throw "tsx not found at $tsxLoader. Run npm install from the repository root first." } $cliPath = Join-Path $repoRoot "packages/coding-agent/src/cli.ts" -& $tsxBin $cliPath @forwardArgs +$env:TSX_TSCONFIG_PATH = Join-Path $repoRoot "tsconfig.json" +& node --import $tsxLoader $cliPath @forwardArgs $exitCode = $LASTEXITCODE if ($exitCode -ne 0) { exit $exitCode diff --git a/scripts/diffex-test.sh b/scripts/diffex-test.sh index b08768775..064f2d42b 100755 --- a/scripts/diffex-test.sh +++ b/scripts/diffex-test.sh @@ -64,4 +64,5 @@ if [[ "$NO_ENV" == "true" ]]; then echo "Running without API keys..." fi -exec "$REPO_ROOT/node_modules/.bin/tsx" --tsconfig "$REPO_ROOT/tsconfig.json" "$REPO_ROOT/packages/coding-agent/src/cli.ts" ${ARGS[@]+"${ARGS[@]}"} +export TSX_TSCONFIG_PATH="$REPO_ROOT/tsconfig.json" +exec node --import "$REPO_ROOT/node_modules/tsx/dist/loader.mjs" "$REPO_ROOT/packages/coding-agent/src/cli.ts" ${ARGS[@]+"${ARGS[@]}"} diff --git a/scripts/diffex-test.test.mjs b/scripts/diffex-test.test.mjs new file mode 100644 index 000000000..8e0657e75 --- /dev/null +++ b/scripts/diffex-test.test.mjs @@ -0,0 +1,24 @@ +import assert from "node:assert/strict"; +import { spawnSync } from "node:child_process"; +import { mkdtempSync, rmSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { fileURLToPath } from "node:url"; +import test from "node:test"; + +const launcher = fileURLToPath(new URL("./diffex-test.sh", import.meta.url)); + +test("source launcher runs from another directory and forwards arguments", (t) => { + const root = mkdtempSync(join(tmpdir(), "diffex-launcher-test-")); + t.after(() => rmSync(root, { recursive: true, force: true })); + const result = spawnSync(launcher, ["--no-env", "--help"], { + cwd: root, + env: { ...process.env, DIFFEX_CODING_AGENT_DIR: join(root, "agent"), DIFFEX_OFFLINE: "1" }, + encoding: "utf8", + timeout: 30_000, + }); + assert.ifError(result.error); + assert.equal(result.status, 0, result.stderr); + assert.match(result.stdout, /^Running without API keys\.\.\.\nDiffex - AI coding assistant/m); + assert.match(result.stdout, /Usage:\n diffex \[options\]/); +});