GitNexus/gitnexus/test/helpers/detect-changes-stderr-child.ts
Gergő Magyar a3eb34b27c
Some checks are pending
Devcontainer Smoke / Config-transform unit tests (push) Waiting to run
Devcontainer Smoke / Host importer tests (macos-latest) (push) Waiting to run
Devcontainer Smoke / Host importer tests (windows-latest) (push) Waiting to run
Devcontainer Smoke / Build devcontainer image (default) (push) Waiting to run
Devcontainer Smoke / Build devcontainer image (ui) (push) Waiting to run
CodeQL / Analyze (javascript-typescript) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
Publish Development Images / publish (core) (push) Waiting to run
Publish Development Images / publish (ui) (push) Waiting to run
Gitleaks / gitleaks (push) Waiting to run
Publish / ci (push) Blocked by required conditions
Publish / Publish to npm (push) Blocked by required conditions
Publish / Classify release event (push) Waiting to run
Publish / RC guard (marker + release-PR skip) (push) Blocked by required conditions
Publish / Build & Push RC Docker images (push) Blocked by required conditions
Scorecard / Scorecard analysis (push) Waiting to run
Trivy Image Scan / Trivy (gitnexus-cli) (push) Waiting to run
Trivy Image Scan / Trivy (gitnexus-web) (push) Waiting to run
fix(mcp): contain detect_changes git stderr (#3841)
2026-11-08 05:50:10 +00:00

39 lines
1.3 KiB
TypeScript

/**
* Child process for #3837.
*
* Spawned as `node --import <tsx> --import detect-changes-stderr-hooks.mjs
* detect-changes-stderr-child.ts <scope> [base_ref]`, with DETECT_CHANGES_REPO
* pointing at a temp git checkout. Prints the `detect_changes` payload as
* JSON on stdout. Git's own stderr is left on this process's stderr so the
* parent can assert it does not leak.
*/
import { LocalBackend } from '../../src/mcp/local/local-backend.js';
const repo = process.env.DETECT_CHANGES_REPO;
const scope = process.argv[2];
const baseRef = process.argv[3];
if (!repo || !scope) {
process.stderr.write('usage: detect-changes-stderr-child.ts <scope> [base_ref]\n');
process.exit(2);
}
const backend = new LocalBackend();
try {
const ready = await backend.init();
if (!ready) {
throw new Error('LocalBackend.init found no repository');
}
const result = await backend.callTool('detect_changes', {
scope,
repo: 'autocrlf-repo',
...(baseRef ? { base_ref: baseRef } : {}),
});
process.stdout.write(JSON.stringify(result));
} catch (err) {
const message = err instanceof Error ? (err.stack ?? err.message) : String(err);
process.stdout.write(JSON.stringify({ crashed: true, message }));
process.exitCode = 1;
} finally {
await backend.dispose();
}