diff --git a/bin/gstack-pregate b/bin/gstack-pregate index fee4fbb5c..1eeb9bb09 100755 --- a/bin/gstack-pregate +++ b/bin/gstack-pregate @@ -37,6 +37,7 @@ import { describeLane, discoverLanes } from '../lib/pregate/workflows'; import { REMOTE_GATE_LANE } from '../lib/pregate/checks/lanes'; import { describeSubstitution } from '../lib/pregate/remote-receipt'; import { ensureTmpExcluded } from '../lib/restamp'; +import { normalizeRemoteUrl } from '../lib/ship-queue-train-record'; import { RESULT_CODES, resultCodeSuffix, resultLine } from '../lib/result-codes'; import { DEFAULT_STALL_TIMEOUT_S } from '../lib/pregate/context'; import { cancelActive } from '../lib/pregate/supervise'; @@ -252,7 +253,7 @@ function runCheck(root: string, lane: string, allowRepoCommands: boolean): RunCh // Unknown profiles are treated as present: a lane is cleared unverified only once the base shows it has no profile. if (isConfigUnavailable(loaded)) return { error: `the base branch's ${PREGATE_CONFIG_PATH} is unreadable (${loaded.detail}); run profiles come only from the base`, profiled: true }; if (loaded.errors.length) return { error: `the base branch's ${PREGATE_CONFIG_PATH} is invalid: ${loaded.errors.map(e => `${e.path}: ${e.message}`).join('; ')}`, profiled: true }; - const repo = /github\.com[:/]([\w.-]+\/[\w.-]+?)(?:\.git)?\/?$/.exec(gitOut(root, ['remote', 'get-url', 'origin']) ?? '')?.[1]; + const repo = /^https:\/\/github\.com\/(.+)$/.exec(normalizeRemoteUrl(gitOut(root, ['config', '--get', 'remote.origin.url']) ?? ''))?.[1]; if (!repo) return { error: 'origin is not a github.com repository; run evidence is read from GitHub Actions', profiled: lane === REMOTE_GATE_LANE ? !!loaded.config.remote_gate_runs : !!loaded.config.run_profiles[lane] }; return { repo, deps: ghRunDeps(repo, root), profiles: loaded.config.run_profiles, gateRuns: loaded.config.remote_gate_runs, now: new Date(), diff --git a/changelog.d/capy-gsta156-run-evidence.md b/changelog.d/capy-gsta156-run-evidence.md index 326fee1be..188341d69 100644 --- a/changelog.d/capy-gsta156-run-evidence.md +++ b/changelog.d/capy-gsta156-run-evidence.md @@ -9,4 +9,4 @@ ### Tests - `test/run-evidence.test.ts`: every refusal reason, including the re-run cases (a red re-run of an older run vetoes; re-running the candidate does not hide a failure in between), a run that changes attempts while being checked, malformed counts and paths, and profile validation. -- `test/pregate-clear-runs.test.ts`: on a fixture repository, clear on the same tree, verify offline, and bind the ship receipt. Also covers a stamp-only predecessor, a non-stamp difference, uncovered files, runs on different trees, base mismatch, repeated runs, the profile-to-run assignment, the profiled-lane matrix (`--run-url`, `--bundle-lane`, `--run`), a non-GitHub origin failing closed, and an unreadable base config refusing `--run-url` on every lane. The `--run-url` fallback test failed before the fix. +- `test/pregate-clear-runs.test.ts`: on a fixture repository, clear on the same tree, verify offline, and bind the ship receipt. Also covers a stamp-only predecessor, a non-stamp difference, uncovered files, runs on different trees, base mismatch, repeated runs, the profile-to-run assignment, the profiled-lane matrix (`--run-url`, `--bundle-lane`, `--run`), a non-GitHub origin failing closed, an origin that `url.insteadOf` rewrites to a proxy (Capy's git.capy.ai) still read as the GitHub repository, and an unreadable base config refusing `--run-url` on every lane. The `--run-url` fallback test failed before the fix. diff --git a/test/pregate-clear-runs.test.ts b/test/pregate-clear-runs.test.ts index 9f92ea7d7..8b0937857 100644 --- a/test/pregate-clear-runs.test.ts +++ b/test/pregate-clear-runs.test.ts @@ -209,6 +209,19 @@ describe.skipIf(process.platform === 'win32')('clear --run: Actions runs as remo expect(verifyPregate(repo.work, forged, { tree: file.tree } as any)).toMatchObject({ ok: false, code: 'PREGATE_REMOTE_UNCLEARED' }); }, 120_000); + test('origin is read before url.insteadOf, so a Capy git.capy.ai proxy still names the GitHub repository', async () => { + const repo = fixture(); + const file = await pregateAt(repo); + fs.mkdirSync(path.join(repo.work, '.gstack/tmp'), { recursive: true }); + fs.writeFileSync(path.join(repo.work, '.gstack/tmp/pregate.json'), JSON.stringify(file)); + repo.git('remote', 'set-url', 'origin', 'https://github.com/fx/fx.git'); + repo.git('config', 'url.https://git.capy.ai/.insteadOf', 'https://github.com/'); + expect(repo.git('remote', 'get-url', 'origin')).toBe('https://git.capy.ai/fx/fx.git'); + const r = runBin(repo, 'gstack-pregate', ['clear', '--remote', LANE, '--run', '200', '--run', '201', '--allow-repo-commands']); + expect(r.err).not.toContain('origin is not a github.com repository'); + expect([r.status, r.err]).toEqual([EXIT.usage, expect.stringContaining('declares remote_gate_runs')]); + }, 120_000); + test('the bin refuses --run when the base declares no run profiles, and keeps the --receipt route unchanged', async () => { const repo = fixture(); const file = await pregateAt(repo);