Repository navigation
Convert unit tests to expect tests - #82
Merged
Merged
Conversation
Snapshot readable outputs (tables of input -> output, compact per-item summaries) instead of hand-written assertions. Named assertions remain for must-hold rules: thrown errors, permission denials, data-loss guards. Also give extractSearchTerms one shared home; its test previously covered a copy pasted into the test file. written with claude-opus-5-5 in T3 Code
People count, repeating-reminder return value, collaborator note result, and note text persisting into later demo scenes. written with claude-opus-5-5 in T3 Code
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Ban hand-written matchers in src unit tests (vitest/no-restricted-matchers). Must-hold rules opt out with a disable comment that states why; the description is required. Convert the remaining assertions, and test the real extractRemindersForSync instead of a copy in the test file. written with claude-opus-5-5 in T3 Code
Replace the matcher denylist with an allowlist rule (architecture/expect-tests-only) plus a processor that enforces '-- invariant:' opt-outs, covering .spec files, expect.soft, assert, custom matchers and comparisons hidden inside snapshots. Restore dropped checks (search counts, note identity in cleanup, empty vs missing demo notes) and make redactNoise alias ids consistently so relationships stay visible. written with claude-opus-5-5 in T3 Code
Report boolean-typed expect subjects (type-aware) instead of matching comparison syntax, fail bare boolean snapshots at runtime, lint shared test helpers, and ban throw directly in test bodies. expectTypeOf and assertType stay allowed. written with claude-opus-5-5 in T3 Code
Lint expect usage across all of src, reject expect aliases, chai and assert in any form, boolean conversions, snapshot property matchers, dynamic snapshot text and setup-only APIs outside vitest.setup.ts. Require at least one assertion per test and reject boxed booleans at runtime. written with claude-opus-5-5 in T3 Code
This branch was successfully deployed
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.
Why
Hand-written assertions repeat the logic under test, and they only check what the author thought to check. Expect tests (vitest
toMatchInlineSnapshot) record the real output. You review it once, and after that any change shows up as a diff. When a change is intended,vitest -urewrites the snapshot.What
input -> outputline per case"pinned-1 · Ada · pinned"redactNoiseinsrc/shared/tools/test-helpers.ts.extractSearchTermswas duplicated intext-highlight.tsxandmarkdown-with-highlight.tsx. Its test exercised a third copy pasted into the test file. It now lives insrc/shared/lib/search-terms.ts, and the test covers the real function.use-sync-reminders-to-sw.test.ts, which tested a copy ofextractRemindersForSync. The function is now exported from the hook module, unchanged, and tested directly.Enforcement
Two ESLint rules in
tools/eslint-plugin-architecturekeep plain assertions from creeping back in. A few runtime checks back them up.expect-tests-onlyruns on all ofsrc. It doesn't need type information, so it's fast.toMatchInlineSnapshotandtoThrow*. The snapshot text must be a written string with no${}..notexpectused other than by calling it directly: aliases, the test context'sexpect,.calland.bindassertin any form, including dynamic importsexpect.extendand custom serializers outsidevitest.setup.tsexpect.assertions(0)throwdirectly in a test bodyexpector the test globals in non-test filesexpect-tests-no-booleansruns on test files and test helpers. It uses type information to report a value that is onlytrue/false: directly, inside a template string, converted withString,Number,JSON.stringifyor a? :with literal branches, or as an array of booleans. Booleans as fields of an object are allowed.requireAssertions).// eslint-disable-next-line architecture/expect-tests-only -- invariant: <why>. A processor rejects opt-outs withoutinvariant:, file-wide disables andeslint ... offcomments, after ESLint applies disable comments. The codebase has 4 such opt-outs.*.test-d.ts.docs/testing.md.Stress test: Codex tried 105 ways to get a hand-written assertion past these checks. Every realistic bypass is now caught by lint or by the test run. Still open, and left to review:
Reflect.getthrowhidden in a helper functionNot converted
RuleTestertests: they are already tables of valid and invalid code.Weight
bun.lock).delete-covalue.test.ts(352 → 114 lines).Review
One review pass compared every rewritten file against
mainby mutating the source code. It found 4 checks the conversion had dropped:All 4 are restored (second commit). The count and repeating-reminder fixes were re-checked with the same mutations: the restored tests fail.
Second review (Claude + Codex)
Fixed, each proven by deliberately breaking the code under test or by running ESLint:
.specfiles,expect.soft,assert,toMatch,toSatisfy, custom matchers, comparisons hidden in snapshots, and opt-outs with any reason.redactNoisenow walks the value. It replaces only whole-string timestamps and IDs, and gives the same ID the same<id:N>alias, so relationships stay visible.reminder-datesnow sets differentcreatedAtandupdatedAt, andgetPersonOwnerNameuses a real profile name.Risks
-u, read the diff.markdown-with-highlightnow trims the query insideextractSearchTerms. Its caller already trimmed, so behaviour is unchanged.Checks
bun checkpasses.No UI changes, so no screenshots.
written with claude-opus-5-5 in T3 Code