Skip to content

Fix knip gate on Expensify/App#102126 (split stack) - #74

Closed
sosek108 wants to merge 1 commit into
split/lhn-search-preview-parity-stackfrom
fix/knip-clear-alternate-text-cache-test
Closed

sosek108 wants to merge 1 commit into
split/lhn-search-preview-parity-stackfrom
fix/knip-clear-alternate-text-cache-test

Conversation

@sosek108

Copy link
Copy Markdown

Why

Expensify/App#102126 (head split/lhn-search-preview-parity-stack @ 9ef80392b52) fails exactly one functional gate: Compare knip issues against main (workflow Knip check, run 35972536658, job 107545343764). Every other gate on that head is green (typecheck, Jest Unit Tests jobs 1-8, ESLint, Oxfmt, Bun tests, React Compiler, Reassure perf tests).

CI output from that job:

Knip comparison:
  main : 132
  PR   : 133 (delta +1)
  added by PR    : 1
  resolved by PR : 0

New issues introduced:
  exports (1):
    src/libs/OptionsListUtils/index.ts::clearAlternateTextCache
##[error][exports] clearAlternateTextCache
##[error]PR introduces 1 new knip finding(s) (resolved 0, delta +1).

Root cause

Commit 9ef80392b52 ("S4: cache resolved Search previews per report; add perf harness") added a new public export clearAlternateTextCache to src/libs/OptionsListUtils/index.ts. Knip reports it as an unused export:

{"file": "src/libs/OptionsListUtils/index.ts",
 "exports": [{"namespace": "OptionsListUtils", "name": "clearAlternateTextCache", "line": 3407, "col": 5}]}

The only file that imports it is tests/perf-test/OptionsListChatPreview.perf-test.ts, and knip.json lists tests/perf-test/** under ignore, so that importer is not counted as a consumer. The export therefore has zero counted usage and the delta gate fails. This is not a mock-spread or re-export artifact.

Fix

Give the export a counted consumer in an existing knip entry: tests/unit/OptionsListUtilsTest.tsx now imports clearAlternateTextCache and calls it in the top-level beforeEach, next to the clearFilteredOptionListCache() call that already lives there.

This is not a knip silencer. That test file clears the module-level filtered-option-list cache in beforeEach precisely to keep cases order-independent, and the resolved chat-preview cache added by 9ef80392b52 is the same kind of module-level state: its guarded inputs can survive Onyx.clear(), so a case that resolves a preview text first can otherwise leak into the next case. Resetting it alongside clearFilteredOptionListCache() is the same invariant the file already enforces. The diff is 5 lines (1 import, 1 call, 2 comment lines, 1 blank).

Verification

All commands run in a clean worktree of split/lhn-search-preview-parity-stack @ 9ef80392b52, plus this one commit. Knip version 6.34.0, same as CI.

Knip, using CI's exact invocations (KNIP=true npx knip --reporter json --no-exit-code for each ref, then the repo comparator):

$ git checkout origin/main            # 2fc21f48d8c, the baseline CI compares against
$ KNIP=true npx knip --reporter json --no-exit-code > /tmp/knip-main.json

$ git checkout <this commit>
$ KNIP=true npx knip --reporter json --no-exit-code > /tmp/knip-final.json

$ npx bun ./scripts/compareKnipReports.ts --mainPath=/tmp/knip-main.json --prPath=/tmp/knip-before.json   # before the fix
  main : 132
  PR   : 133 (delta +1)
  added by PR    : 1
  resolved by PR : 0
  New issues introduced:
    exports (1):
      src/libs/OptionsListUtils/index.ts::clearAlternateTextCache
::error::PR introduces 1 new knip finding(s) (resolved 0, delta +1).

$ npx bun ./scripts/compareKnipReports.ts --mainPath=/tmp/knip-main.json --prPath=/tmp/knip-final.json    # after the fix
Knip comparison:
  main : 132
  PR   : 132 (delta +0)
  added by PR    : 0
  resolved by PR : 0

PR introduces no new knip findings.
comparator exit=0

Reproduces the CI failure byte-for-byte before the change, and clears it after, with no other finding added or resolved.

Type-check (CI's npm run typecheck, which drives bun scripts/typecheck.ts over every referenced project including tsconfig.jest.json, the project that owns tests/):

$ npm run typecheck
Type checking ./tsconfig.app.json...
Type checking ./tsconfig.jest.json...
Type checking ./tsconfig.bun.json...
Type checking ./tsconfig.node.json...
Type checking ./server/victory-chart-renderer...

Type checking passed.
typecheck exit=0

Jest on the touched suite (clearAlternateTextCache() in beforeEach must not make any case order-dependent or change an assertion):

$ CI=true npx jest tests/unit/OptionsListUtilsTest.tsx
Test Suites: 1 passed, 1 total
Tests:       343 passed, 343 total
Snapshots:   0 total
Time:        44.1 s
jest exit=0

Lint / format on the touched file:

$ npx eslint tests/unit/OptionsListUtilsTest.tsx
Lint done.                       eslint exit=0
$ npx oxfmt --check tests/unit/OptionsListUtilsTest.tsx
All matched files use the correct format.

Commit is GPG-signed with the same key as the rest of the stack, matching the "Verify signed commits" gate convention on this branch.

Notes

  • The task brief for this fix named tests/unit/SearchRouterTest.test.tsx; that file does not exist on 9ef80392b52, on Expensify/App main, or anywhere in this repo's history. tests/unit/OptionsListUtilsTest.tsx is the file that owns the clearFilteredOptionListCache() beforeEach anchor the brief describes, and it is a knip entry, so it is where the counted consumer belongs.
  • Local npm run typecheck needs bun on PATH; it ships in node_modules/.bin, so this run used PATH="$PWD/node_modules/.bin:$PATH".
  • Not verified locally: Reassure Performance Tests and the sharded full Jest Unit Tests run (out of scope for a 5-line test-file change, and both already pass on the base head). The Knip check itself will re-run on the stack branch once this merges.

@coderabbitai

coderabbitai Bot commented Sep 25, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

Comment @coderabbitai help to get the list of available commands.

@sosek108 sosek108 closed this Sep 25, 2026
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