Skip to content

fix(action): strip ANSI colors and fix diff mode on PRs#80

Open
bdsqqq wants to merge 6 commits intomillionco:mainfrom
bdsqqq:fix/action-ansi-and-diff
Open

fix(action): strip ANSI colors and fix diff mode on PRs#80
bdsqqq wants to merge 6 commits intomillionco:mainfrom
bdsqqq:fix/action-ansi-and-diff

Conversation

@bdsqqq
Copy link
Contributor

@bdsqqq bdsqqq commented Feb 23, 2026

fixes two bugs in the github action introduced in #63.

ANSI escape codes in PR comments

react-doctor uses picocolors for terminal output. the action pipes this through tee into a file, then posts it raw as a PR comment. ANSI codes (^[[32m, etc.) show up as literal text in the markdown code block.

fix: set NO_COLOR=1 in the env block. picocolors respects this natively — no stripping needed.

--diff mode falls back to full scan

actions/checkout checks out a detached HEAD merge commit on pull_request events. getCurrentBranch() in get-diff-files.ts:13 returns null for detached HEAD (branch === "HEAD" ? null : branch), causing getDiffInfo() to short-circuit at line 75 and fall back to a full scan.

fix: when diff input is set on a PR, checkout the actual head ref (github.head_ref) and fetch the base branch. this puts git on a real branch so getCurrentBranch() succeeds.

evidence

spotted in axiomhq/app#7259 — the action posted a comment with raw ANSI and ran a full scan instead of diffing.

— igor's agent

two bugs when using the action in pull_request workflows:

1. ANSI escape codes leaked into PR comments — react-doctor uses
   picocolors which respects NO_COLOR. set NO_COLOR=1 in the env
   so output piped to the comment is plain text.

2. --diff mode fell back to full scan — actions/checkout checks out
   a detached HEAD merge commit on pull_request events. react-doctor's
   getCurrentBranch() returns null for detached HEAD, causing
   getDiffInfo() to short-circuit. fix: checkout the actual head ref
   and fetch the base branch when diff input is set.

Amp-Thread-ID: https://ampcode.com/threads/T-019c8b27-dfde-7343-a012-143f4d72c106
Co-authored-by: Amp <amp@ampcode.com>
@vercel
Copy link

vercel bot commented Feb 23, 2026

@bdsqqq is attempting to deploy a commit to the Million Team on Vercel.

A member of the Team first needs to authorize it.

Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
@bdsqqq
Copy link
Contributor Author

bdsqqq commented Feb 24, 2026

before/after from a real CI run

tested on a private monorepo (~800 tsx files) by pointing the action at this fix branch.

before (millionco/react-doctor@main):

  • ANSI escapes leaked into PR comment (^[[32m, ^[[39m, etc.)
  • diff mode ignored: "No feature branch or uncommitted changes detected. Running full scan." — scanned all files
react-doctor v0.0.29

^[[32m✔^[[39m Select projects to scan ^[[2m›^[[22m @axiomhq/console
^[[33mNo feature branch or uncommitted changes detected. Running full scan.^[[39m

^[[2mScanning /home/runner/work/app/app/apps/console...^[[22m

  ^[[31m✗^[[39m React Compiler can't optimize this code^[[31m (36)^[[39m
^[[2m    Todo: (BuildHIR::lowerExpression) Handle BigIntLiteral expressions^[[22m
  ... (hundreds of lines of findings across all files)

after (bdsqqq/react-doctor@fix/action-ansi-and-diff):

  • clean text, no ANSI
  • diff mode working: "Scanning changes: test/react-doctor-fix-verify → main"
react-doctor v0.0.29

✔ Select projects to scan › @axiomhq/console
Scanning changes: test/react-doctor-fix-verify → main

No changed source files in /home/runner/work/app/app/apps/console, skipping.

— igor's agent

bdsqqq and others added 3 commits February 24, 2026 12:50
--depth=1 can shallow the local clone and break git merge-base,
which react-doctor uses to find changed files. the bare catch{}
in getChangedFilesSinceBranch silently returns [] on failure,
making diff mode report no changed files.

callers using fetch-depth: 0 already have full history; the
shallow fetch was clobbering it.

Amp-Thread-ID: https://ampcode.com/threads/T-019c8b27-dfde-7343-a012-143f4d72c106
Co-authored-by: Amp <amp@ampcode.com>
git fetch origin main stores the result as FETCH_HEAD, not as
a local branch ref. git merge-base main HEAD then fails with
'Not a valid object name main'.

fix: git fetch origin main:main creates a local ref that
merge-base can resolve.

Amp-Thread-ID: https://ampcode.com/threads/T-019c8b27-dfde-7343-a012-143f4d72c106
Co-authored-by: Amp <amp@ampcode.com>
@bdsqqq
Copy link
Contributor Author

bdsqqq commented Feb 24, 2026

update: diff mode now fully working

previous comment showed ANSI fix working but diff mode was still broken — "No changed source files" even with source changes.

root cause: git fetch origin main stores the ref as FETCH_HEAD, not a local branch main. git merge-base main HEAD (used by react-doctor internally) fails with "Not a valid object name main". the bare catch {} in getChangedFilesSinceBranch silently returns [].

fix: git fetch origin "$BASE_REF":"$BASE_REF" — creates a local ref.

after (verified):

✔ Select projects to scan › @axiomhq/console
Scanning changes: test/react-doctor-diff-verify → main

Scanning /home/runner/work/app/app/apps/console...

  ✗ React Compiler can't optimize this code (2)
    Todo: (BuildHIR::lowerExpression) Handle BigIntLiteral expressions
    src/hubs/dash/components/traces/SpanDurationHeatmap.tsx: 26, 27

  99 / 100  Great
  ✗ 2 errors  across 1/1 files  in 784ms

only the touched file was scanned (1/1), only its findings shown. the broken full scan had 36+ findings across dozens of files.

— igor's agent

- fetch inputs.diff (not github.base_ref) so diff: staging works
  even when PR targets main
- use git branch -f to avoid non-fast-forward failures on
  self-hosted runners
- graceful fallback (|| true) if fetch/checkout fail — tool
  reverts to full scan instead of crashing

Amp-Thread-ID: https://ampcode.com/threads/T-019c8b27-dfde-7343-a012-143f4d72c106
Co-authored-by: Amp <amp@ampcode.com>
@bdsqqq
Copy link
Contributor Author

bdsqqq commented Feb 24, 2026

note: fetch-depth requirement for diff mode

the diff step needs git merge-base which requires commit history. callers must use fetch-depth: 0 in their actions/checkout for diff mode to work. if they use the default (fetch-depth: 1), the action gracefully falls back to a full scan.

worth documenting in the README action usage section, something like:

# diff mode requires full git history
- uses: actions/checkout@v5
  with:
    fetch-depth: 0
- uses: millionco/react-doctor@main
  with:
    diff: main
    github-token: ${{ secrets.GITHUB_TOKEN }}

happy to add this to the README in a follow-up PR if you want.

— igor's agent

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.

1 participant