Skip to content

🐛 fix(sink/git): pin LC_ALL=C so git stderr classification is locale-independent (REL-01) - #169

Merged
konih merged 1 commit into
mainfrom
fix/rel-01-git-locale-pin
Aug 2, 2026
Merged

konih merged 1 commit into
mainfrom
fix/rel-01-git-locale-pin

Conversation

@konih

@konih konih commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

REL-01 (P2) — git CLI error classification was locale-fragile

Surfaced by the 2026-08-02 /project-audit (reliability + tests lenses; live-reproduced). Git CLI error classifiers (isCLIEmptyRemote, isNonFastForwardError, isTransientTransportError, isAuthFailure) match ENGLISH stderr substrings, but applyCLIEnv only set cmd.Env when auth/SSL extraEnv existed — so under a non-English operator locale (reachable via the documented spec.git.engine: cli) git emitted localized stderr → transient pushes misclassified terminal (no retry), non-fast-forward undetected (no rebase recovery), first-export-to-empty-remote failed.

Fix

applyCLIEnv now ALWAYS pins LC_ALL=C/LANG=C (appended after os.Environ(), before auth/SSL extraEnv so those still win) on every git subprocess. This also makes the git test suite hermetic — the ~8 previously locale-flaky tests now pass regardless of ambient LANG.

Review

Independent review caught a P1 (a pre-existing sibling test dumped cmd.Env on failure → token-leak class, widened because the fix always sets cmd.Env); fixed and fresh-re-reviewed → APPROVE. Re-review confirmed no test failure path prints the environment, the locale pin covers all 5 git spawns, and the test is a genuine (non-tautological) driver. Gates green.

Related security note (INBOX): live tokens were printed into an implementer transcript during the pre-fix fail-before demo — rotate GITLAB_TOKEN/GITHUB_COM_TOKEN/VAULT_TOKEN/CONFLUENCE_TOKEN/INFRACOST_TOKEN.

Copilot AI review requested due to automatic review settings August 2, 2026 11:11
@konih
konih merged commit 8564bb0 into main Aug 2, 2026
21 of 22 checks passed
@konih
konih deleted the fix/rel-01-git-locale-pin branch August 2, 2026 11:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the git CLI execution path by forcing a deterministic C locale for every git subprocess, ensuring stderr-based error classification remains reliable under non-English operator locales (REL-01), and makes the related tests non-leaky and locale-hermetic.

Changes:

  • Always set LC_ALL=C and LANG=C for git CLI subprocesses via applyCLIEnv, independent of auth/SSL env configuration.
  • Adjust tests to avoid logging cmd.Env (preventing secret leakage) and add a regression test that proves locale pinning overrides ambient locale.
  • Add a small test helper to validate “last effective value” semantics for env key overrides.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
internal/sink/git/cli_env.go Always pins LC_ALL/LANG for all git CLI subprocesses by default.
internal/sink/git/cli_env_test.go Prevents env leakage in failures and adds a regression test ensuring locale pinning works under non-C ambient locale.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +239 to +240
// lastValue returns the value of the final key=... entry in env, mirroring the
// last-wins semantics the OS applies to a process environment.
Comment on lines +113 to +120
// Always pin a deterministic locale so git stderr is English, then layer
// any auth/SSL extraEnv on top. Both are appended after os.Environ() so
// later entries win over inherited values.
env := append(os.Environ(), deterministicLocaleEnv...)
if cli != nil && len(cli.extraEnv) > 0 {
cmd.Env = append(os.Environ(), cli.extraEnv...)
env = append(env, cli.extraEnv...)
}
cmd.Env = env
@codecov

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@sonarqubecloud

sonarqubecloud Bot commented Aug 2, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants