react-doctor icon indicating copy to clipboard operation
react-doctor copied to clipboard

test(regressions): pin PR #249 Bugbot fixes

Open aidenybai opened this issue 6 months ago • 2 comments

Two regression tests covering the Bugbot findings from #249. Both have been validated and rely on existing test helpers.

What's locked in

1. 'score unavailable' message branches on offline vs API failure (#249)

Added to cli-and-output.test.ts. Bugbot caught that noScoreMessage was unconditionally "Score unavailable in offline mode.", so a scan that ran online but couldn't reach the score API would falsely tell the user they were offline. The fix branches the message on options.offline; these two tests pin both wordings:

  • --offline: true → stdout contains "Score unavailable in offline mode" and does not contain "could not reach the score API".
  • --offline: false + mocked fetch throwing → stdout contains "could not reach the score API" and does not contain "in offline mode".

Both go through real inspect() runs via the existing captureScanOutput helper — black-box, no string scrubbing in source.

2. shared constants between core and project-info (#249)

New package-boundary-integrity.test.ts. Bugbot also caught that SOURCE_FILE_PATTERN, GIT_LS_FILES_MAX_BUFFER_BYTES, and IGNORED_DIRECTORIES were independently re-declared in both core/src/constants.ts and project-info/src/constants.ts — pure drift risk. The fix re-exports these from project-info through core's barrel; the test pins it with strict reference-equality:

expect(core.SOURCE_FILE_PATTERN).toBe(projectInfo.SOURCE_FILE_PATTERN);
expect(core.GIT_LS_FILES_MAX_BUFFER_BYTES).toBe(projectInfo.GIT_LS_FILES_MAX_BUFFER_BYTES);
expect(core.IGNORED_DIRECTORIES).toBe(projectInfo.IGNORED_DIRECTORIES);

If anyone re-declares any of these in core/constants.ts (even with the same value), .toBe() fails because the new RegExp/Set is a different reference. Inline HACK: comment points future failures at the correct fix (re-export, not the test).

Convention compliance (vs AGENTS.md)

  • Arrow functions only ✓
  • All non-trivial comments carry the HACK: prefix ✓
  • Test files in kebab-case ✓
  • Descriptive variable names (no shorthands) ✓
  • Updated cli-and-output.test.ts "Covered closed issues" header to add #249 ✓
  • No DRY violation — collapsed 3 separate it() blocks into 1 with 3 inline asserts in the dedup file ✓

Test plan

  • [x] pnpm test — 78 files, 713 tests passing
  • [x] pnpm typecheck — clean
  • [x] pnpm lint — 0/0
  • [x] Verified new tests appear in verbose runner output under their named describe blocks

[!NOTE] Medium Risk Mostly adds regression tests, but introduces repo-wide source scanning and strict export/reference checks that could be brittle across environments or future refactors.

Overview Fixes inspect() output so the "score unavailable" text distinguishes user-requested --offline from score API failures, by centralizing both messages in cli/utils/constants.ts and using them in inspect.ts.

Adds regression coverage: cli-and-output.test.ts now parameterizes offline vs multiple API-failure modes (fetch throw, non-2xx, malformed body) and asserts the correct message, and a new silent-drift-defenses.test.ts enforces "single source of truth" rules (no duplicated score messages/URLs, no re-declared @react-doctor/types types in consumers, and @react-doctor/core shared exports must be true re-exports from @react-doctor/project-info).

Reviewed by Cursor Bugbot for commit fd1efb39183b07c03be43ab0a077aa02d01b1012. Bugbot is set up for automated code reviews on this repo. Configure here.

aidenybai avatar May 15 '26 09:05 aidenybai

🔴 React Review — 0/100 (unchanged) · 0 ❌ errors · 4 ⚠️ warnings

Copy prompt for agent
Check if these React Review issues are valid. If so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.

Run this before and after your changes to verify the result:
npx react-doctor@latest --verbose --diff

Do not modify the react-doctor configuration unless explicitly asked.
Fix the underlying code issues instead of changing or suppressing the rules.

React Review found 0 errors and 4 warnings. This PR leaves the React health score unchanged.

<file name="packages/react-doctor/tests/regressions/silent-drift-defenses.test.ts">

<violation number="1" location="packages/react-doctor/tests/regressions/silent-drift-defenses.test.ts:120">
Severity: Warning

.filter().map() iterates the array twice — combine into a single loop with .reduce() or for...of

Combine `.map().filter()` (or similar chains) into a single pass with `.reduce()` or a `for...of` loop to avoid iterating the array twice

Rule: `js-combine-iterations`
</violation>

<violation number="2" location="packages/react-doctor/tests/regressions/silent-drift-defenses.test.ts:172">
Severity: Warning

.filter().map() iterates the array twice — combine into a single loop with .reduce() or for...of

Combine `.map().filter()` (or similar chains) into a single pass with `.reduce()` or a `for...of` loop to avoid iterating the array twice

Rule: `js-combine-iterations`
</violation>

<violation number="3" location="packages/react-doctor/tests/regressions/silent-drift-defenses.test.ts:215">
Severity: Warning

.filter().map() iterates the array twice — combine into a single loop with .reduce() or for...of

Combine `.map().filter()` (or similar chains) into a single pass with `.reduce()` or a `for...of` loop to avoid iterating the array twice

Rule: `js-combine-iterations`
</violation>

<violation number="4" location="packages/react-doctor/tests/regressions/silent-drift-defenses.test.ts:233">
Severity: Warning

.map().filter() iterates the array twice — combine into a single loop with .reduce() or for...of

Combine `.map().filter()` (or similar chains) into a single pass with `.reduce()` or a `for...of` loop to avoid iterating the array twice

Rule: `js-combine-iterations`
</violation>

</file>

Reviewed by react-review for commit fd1efb39183b07c03be43ab0a077aa02d01b1012. Configure here.

react-doctor[bot] avatar May 15 '26 09:05 react-doctor[bot]

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
react-doctor-website Ready Ready Preview, Comment May 15, 2026 10:39am

vercel[bot] avatar May 15 '26 09:05 vercel[bot]