Three files. Save each section under the name in its ==> header <== in one directory; run-proof.sh expects the other two beside it. ==> run-proof.sh <== #!/usr/bin/env bash # GODEBUG proof for pingdotgg/t3code#28468. Run it from a scratch t3code checkout with deps # installed, never one you are working in: it checks out each ref in turn, then restores the # starting ref. # run-proof.sh # For each ref it runs the real CLI entry (bin.ts) with the host GODEBUG, then feeds the GODEBUG # that bin.ts leaves behind into T3's real VcsProcess running gh. set -u S=$(cd "$(dirname "$0")" && pwd) CHECKOUT=$(git rev-parse --show-toplevel) if [ -n "$(git -C "$CHECKOUT" status --porcelain)" ]; then echo "run-proof.sh needs a clean scratch checkout" >&2 exit 1 fi START_REF=$(git symbolic-ref --quiet --short HEAD || git rev-parse HEAD) trap 'git -C "$CHECKOUT" checkout -q "$START_REF"' EXIT HOST_GODEBUG="tlskyber=0,http2client=0" echo "## Go's rule, straight from the shell: gh $(gh --version | head -1 | cut -d' ' -f3), built with $(strings "$(command -v gh)" | grep -m1 -oE 'go1\.[0-9]+\.[0-9]+')" for value in tlskyber=0 tlskyber=1 http2client=0; do out=$(cd /tmp && GODEBUG=$value gh --version 2>&1) code=$? echo "GODEBUG=$value gh --version: exit=$code $(head -1 <<<"$out")" done run_vcs() { # $1 = env assignment or empty for unset GODEBUG (cd "$CHECKOUT/apps/server" && if [ -n "$1" ]; then env "$1" node "$S/vcs-gh-version.ts" "$PWD/../.."; else env -u GODEBUG node "$S/vcs-gh-version.ts" "$PWD/../.."; fi) 2>&1 | grep -v '^\s*$' } for spec in "main:$1" "pr-28468:$2" "patch:$3"; do name=${spec%%:*} ref=${spec#*:} git -C "$CHECKOUT" checkout -q --detach "$ref" echo echo "## $name at $(git -C "$CHECKOUT" rev-parse --short HEAD), host GODEBUG=$HOST_GODEBUG" home=$(mktemp -d "$S/t3home.XXXXXX") out=$(mktemp "$S/godebug.XXXXXX") echo "### real CLI entry: node src/bin.ts --version (T3CODE_HOME=)" (cd "$CHECKOUT/apps/server" && T3CODE_HOME=$home GODEBUG=$HOST_GODEBUG PROOF_GODEBUG_OUT=$out \ node --import "$S/entry-probe.mjs" src/bin.ts --version 2>&1) echo "### real VcsProcess + GitHub CLI discovery probe, with the GODEBUG bin.ts left" run_vcs "$(cat "$out")" rm -rf "$home" "$out" if [ "$name" = main ]; then echo "### control on main: VcsProcess with GODEBUG=http2client=0 (a setting Go still has)" run_vcs "GODEBUG=http2client=0" echo "### control on main: VcsProcess with GODEBUG unset" run_vcs "" fi done ==> entry-probe.mjs <== // Preload for the real CLI entry (`node --import entry-probe.mjs src/bin.ts --version`). // At exit it reports the GODEBUG this process holds, which every child it spawned after bin.ts // started inherits, and starts `gh --version` with that environment as such a child would. import { spawnSync } from "node:child_process"; import { writeFileSync, writeSync } from "node:fs"; const atStart = process.env.GODEBUG; process.on("exit", () => { const atExit = process.env.GODEBUG; const gh = spawnSync("gh", ["--version"], { env: process.env, encoding: "utf8" }); const firstLine = (gh.status === 0 ? gh.stdout : gh.stderr).split("\n")[0]; writeSync( 2, `[entry-probe] GODEBUG at start=${JSON.stringify(atStart)} after bin.ts=${JSON.stringify(atExit)}\n` + `[entry-probe] child gh --version: exit=${gh.status} ${JSON.stringify(firstLine)}\n`, ); if (process.env.PROOF_GODEBUG_OUT) { writeFileSync(process.env.PROOF_GODEBUG_OUT, atExit === undefined ? "" : `GODEBUG=${atExit}`); } }); ==> vcs-gh-version.ts <== // Runs `gh --version` through T3's real VcsProcess (VcsProcess.layer -> ProcessRunner.layer -> // NodeServices' ChildProcessSpawner) with this process's environment, then runs the real GitHub // source-control discovery probe (GitHubSourceControlProvider's `discovery` spec) with authArgs // swapped to `--version`, so no `gh auth` command runs and no credential is read. // // Usage, from /apps/server: // GODEBUG=... node vcs-gh-version.ts "$PWD/../.." import { createRequire } from "node:module"; import { pathToFileURL } from "node:url"; const checkout = process.argv[2]; if (!checkout) throw new Error("usage: vcs-gh-version.ts "); const req = createRequire(`${checkout}/apps/server/package.json`); const load = (specifier: string) => import(pathToFileURL(req.resolve(specifier)).href); const redact = (text: string) => text.replaceAll(checkout, ""); const Effect = await load("effect/Effect"); const NodeServices = await load("@effect/platform-node/NodeServices"); const VcsProcess = await import(`${checkout}/apps/server/src/vcs/VcsProcess.ts`); const Discovery = await import(`${checkout}/packages/source-control-core/src/server/discovery.ts`); const GitHub = await import( `${checkout}/packages/source-control-github/src/server/GitHubSourceControlProvider.ts` ); console.log(`GODEBUG in server env: ${JSON.stringify(process.env.GODEBUG)}`); const program = Effect.gen(function* () { const vcs = yield* VcsProcess.VcsProcess; const run = yield* Effect.result( vcs.run({ operation: "proof.gh.version", command: "gh", args: ["--version"], cwd: checkout }), ); if (run._tag === "Success") { console.log(`VcsProcess.run gh --version: OK ${JSON.stringify(run.success.stdout.split("\n")[0])}`); } else { const e = run.failure; console.log( `VcsProcess.run gh --version: FAILED ${e._tag} exitCode=${e.exitCode} failureKind=${e.failureKind}`, ); } const item = yield* Discovery.probeSourceControlProvider({ spec: { ...GitHub.discovery, authArgs: ["--version"] }, process: { run: vcs.run }, cwd: checkout, }); const unwrap = (o: { _tag: string; value?: unknown }) => (o._tag === "Some" ? o.value : null); console.log( redact( `GitHub CLI discovery probe (probeSourceControlProvider): status=${item.status} version=${JSON.stringify(unwrap(item.version))} detail=${JSON.stringify(unwrap(item.detail))}`, ), ); }); await Effect.runPromise( program.pipe(Effect.provide(VcsProcess.layer), Effect.provide(NodeServices.layer)), );