mirror of
https://github.com/garrytan/gstack.git
synced 2026-10-03 01:46:55 +02:00
- A1: the retired Eng lexical oracle (evaluateEngSeedCoverage, isEngSeedDecisionAUQ), the completion-handoff detector and the retained corpus had no paid caller since v1.87.6; delete their 26 replay files, ~2.6k helper LOC and fixtures, and the dead blocks in 8 mixed files (live hasNativePlanTerminal / batching assertions stay). - A2: dead viewport approvers in autoplan-artifact-permission and their 11 replay files + fixtures; recorder/launcher cases stay. - A3: never-wired oracles and seeders (autoplan-phase-order, eng-finding-fixture, ceo-paired-fixture, design-ui-scope, plan-skill-completion, pty-current-screen, required-reads, transcript-section-logger); plan-seed-submission now decodes through the production createPtyScreen; section manifests name their actual guard. - A4: zero-reference helper exports, plus execGit and invokeAndObserve found by the reachability pass. - 52 fixtures orphaned by the deletions; touchfile and selection-table entries for every deleted path.
67 lines
2.6 KiB
TypeScript
67 lines
2.6 KiB
TypeScript
/**
|
|
* scratch-repo — shared test fixture for throwaway git repos.
|
|
*
|
|
* One copy of the hermetic git incantation: identity pinned AND signing
|
|
* disabled (`commit.gpgsign=false tag.gpgsign=false`). Fixture commits must
|
|
* never invoke the operator's gpg — gpg-agent fails with "Cannot allocate
|
|
* memory" under parallel shard load and breaks test SETUP, not the code under
|
|
* test. Three suites duplicated this incantation before extraction (and one
|
|
* copy had already drifted).
|
|
*/
|
|
|
|
import { execSync, spawnSync } from 'child_process';
|
|
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
import * as os from 'os';
|
|
|
|
const GIT_HERMETIC_ARGS = [
|
|
'-c', 'user.email=t@test',
|
|
'-c', 'user.name=t',
|
|
'-c', 'commit.gpgsign=false',
|
|
'-c', 'tag.gpgsign=false',
|
|
] as const;
|
|
|
|
const GIT_HERMETIC_FLAGS = GIT_HERMETIC_ARGS.join(' ');
|
|
|
|
/** Run a git command string in a scratch repo (hermetic identity, no gpg). */
|
|
export function gitIn(repoDir: string, args: string): string {
|
|
return execSync(`git ${GIT_HERMETIC_FLAGS} ${args}`, { cwd: repoDir, encoding: 'utf-8', timeout: 10000 });
|
|
}
|
|
|
|
/** Argv-array variant for callers that avoid shell quoting. */
|
|
export function gitArgvIn(repoDir: string, args: string[], timeout = 5000) {
|
|
return spawnSync('git', [...GIT_HERMETIC_ARGS, ...args], { cwd: repoDir, timeout });
|
|
}
|
|
|
|
/** Recursively find files with a given suffix under a directory. */
|
|
export function findFilesBySuffix(root: string, suffix: string): string[] {
|
|
const found: string[] = [];
|
|
const walk = (d: string) => {
|
|
if (!fs.existsSync(d)) return;
|
|
for (const e of fs.readdirSync(d, { withFileTypes: true })) {
|
|
const p = path.join(d, e.name);
|
|
if (e.isDirectory()) walk(p);
|
|
else if (e.name.endsWith(suffix)) found.push(p);
|
|
}
|
|
};
|
|
walk(root);
|
|
return found;
|
|
}
|
|
|
|
/**
|
|
* Create a fake `gh` on PATH that behaves per `mode`, keeping bun/git/etc
|
|
* resolvable. Returns the PATH value to pass into env. Used to exercise the
|
|
* post-spawn gh branches (success, failure, garbage JSON) without network.
|
|
*/
|
|
export function makeGhShimPath(mode: 'fail' | 'json' | 'garbage', jsonPayload = '{}'): { pathEnv: string; shimDir: string } {
|
|
const shimDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-gh-shim-'));
|
|
const body =
|
|
mode === 'fail'
|
|
? '#!/bin/sh\necho "shim: gh failed" >&2\nexit 1\n'
|
|
: mode === 'garbage'
|
|
? '#!/bin/sh\necho "this is not json"\nexit 0\n'
|
|
: `#!/bin/sh\ncat <<'SHIM_JSON'\n${jsonPayload}\nSHIM_JSON\nexit 0\n`;
|
|
fs.writeFileSync(path.join(shimDir, 'gh'), body, { mode: 0o755 });
|
|
return { pathEnv: `${shimDir}:${process.env.PATH ?? ''}`, shimDir };
|
|
}
|