test(cli): make cmd-ci dry-run snapshot branch-agnostic#1434
Open
John-David Dalton (jdalton) wants to merge 1 commit into
Open
test(cli): make cmd-ci dry-run snapshot branch-agnostic#1434John-David Dalton (jdalton) wants to merge 1 commit into
John-David Dalton (jdalton) wants to merge 1 commit into
Conversation
Collaborator
Author
|
CI confirms the fix: The remaining red |
The `socket ci` integration test hardcoded `branchName: "main"` in its dry-run inline snapshot. The CLI resolves the branch from the ambient git checkout (`git symbolic-ref`) or the CI env (GITHUB_HEAD_REF / GITHUB_REF_NAME), so the emitted value is whatever branch the test runs on. It only matched on a `main` push; on EVERY non-main PR the received value was the PR head branch and the snapshot mismatched — reddening the Test check across all open socket-cli PRs. Fix at the snapshot-scrubber boundary, alongside the existing [PROJECT] / [TIMESTAMP] / [UUID] normalizations: scrubSnapshotData now pins the human-readable `branchName: "…"` details line to `branchName: "[BRANCH]"` (new `branches` option, default true; only matches the details form, not JSON `"branchName":"…"`). Snapshot updated to `[BRANCH]`. The branch-resolution behavior itself stays covered by the unit specs that mock `gitBranch` (handle-ci / cmd-ci unit tests assert 'develop'/'feature-branch'/'(default)'), so no real coverage is lost. Proof: on branch `fix/cmd-ci-branch-snapshot` the raw CLI emits `branchName: "fix/cmd-ci-branch-snapshot"` (would fail the old snapshot); with the scrub, `vitest run --config vitest.integration.config.mts test/integration/cli/cmd-ci.test.mts` passes (2/2). Added 5 scrubber unit tests (main / slashed feature branch / detached-HEAD hash / JSON-form left intact / disabled) — 35/35 pass.
John-David Dalton (jdalton)
force-pushed
the
fix/cmd-ci-branch-snapshot
branch
from
July 24, 2026 21:52
46b82fe to
d0c02a9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The
socket ciintegration test (packages/cli/test/integration/cli/cmd-ci.test.mts) hardcodedbranchName: "main"in its dry-run inline snapshot. That value is environment-dependent, so the test passed only on amainpush and failed on every non-main PR — reddening the🧪 Testcheck across the whole open-PR fleet (I hit it on an unrelated workflow PR, #1429).Root cause
The CLI resolves the branch at runtime (
packages/cli/src/util/git/git-remote-info.mts→gitBranch):git symbolic-ref --short HEAD— the current branch when on one (local / worktree runs).GITHUB_HEAD_REF(PR head branch), elseGITHUB_REF_NAMEwhen the ref is a branch.So the dry-run details print whatever branch the test runs on —
"main"on a main push, the PR head branch on a PR build, the local feature branch from a worktree. The snapshot only matched case 1-on-main.Before/after proof (run on a non-main branch)
On branch
fix/cmd-ci-branch-snapshot, the raw built CLI emits the feature branch (would fail the old"main"snapshot):With the scrub in place, the integration test passes on that same non-main branch:
Fix
Handled at the snapshot-scrubber boundary (
packages/cli/test/util/scrub-snapshot-data.mts), alongside the existing[PROJECT]/[TIMESTAMP]/[UUID]/[IP]normalizations — the same place volatile, environment-specific values are already pinned:scrubSnapshotDatanow replaces the human-readablebranchName: "…"details line withbranchName: "[BRANCH]"(newbranchesoption, defaulttrue). The regex only matches the details form (unquoted key +: "), not JSON output ("branchName":"…"), so machine-readable snapshots are untouched.branchName: "[BRANCH]").No real coverage lost: branch-resolution behavior stays asserted by the unit specs that mock
gitBranch(handle-ci/cmd-ciunit tests assertdevelop/feature-branch/(default)with deterministic inputs). This test only verifies the dry-run details block renders — which it still does.Testing
scrub-snapshot-data.test.mts: 35/35 pass.cmd-ciintegration test: 2/2 pass on a non-main branch (was red before — see proof above).tsgo --noEmitreports zero errors in changed files (the pre-existing TS4111 errors inoutput-purls-shallow-score.mtsare onmain, untouched here).Impact
Unblocks the
🧪 Testcheck for all non-main socket-cli PRs.Note
Low Risk
Test-only changes to snapshot scrubbing; no CLI runtime or branch-resolution logic is modified.
Overview
Fixes flaky
socket ciintegration snapshots that assumedbranchName: "main"while the CLI prints the ambient git/CI branch.scrubSnapshotDatanow normalizes human-readable dry-run details lines (branchName: "…") tobranchName: "[BRANCH]"via a newbranchesoption (default on). JSON-style"branchName":"…"output is left unchanged. Thecmd-cidry-run inline snapshot expects[BRANCH], and five scrubber unit tests cover main, feature branches, detached HEAD hashes, JSON passthrough, and opt-out.Reviewed by Cursor Bugbot for commit 46b82fe. Configure here.