Add unit tests for paletteIndexForColor — zero coverage on a non-trivial algorithm #99
Labels
No labels
blocked:commit-ready-failed
blocked:gate-fetch
blocked:gate-lint
blocked:gate-plan
blocked:gate-research
blocked:needs-attention
blocked:needs-decision
blocked:needs-human
blocked:no-changes
blocked:verify-failed
bug
deferred
feature-request
in-progress
needs-decompose
needs-triage
quickfix
security/medium
triage-approved
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Mark/Kimi_Agent_Brother_10_Digitizing_App#99
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Where:
src/components/workspace/useWorkspace.ts:768-781(paletteIndexForColor).Why:
paletteIndexForColoris a private helper used atuseWorkspace.ts:603toassign
paletteIndexvalues to incomingColorRegions. The function isnon-trivial (early-return inside a loop,
seen.addin both branches) andis called with whatever
response.regionsshape the easystitch-servicereturns. Today it has zero direct tests.
I proposed a (false-positive) bug against it earlier this session that turned
out to be wrong, but the exercise showed the lack of unit coverage is the
real problem — without a test, both false positives AND genuine regressions
slip through. Recommend adding coverage so the algorithm can't drift.
Test cases the existing function passes (verified by node 22 inline repro
extracted from source):
The function relies on early-return inside the matching branch to keep
seen.add(region.color)from polluting the count with post-match colors.That's an easy thing to break in a refactor (e.g. moving
seen.add(color)outside the
if, or removing thereturnto fall through). Without tests,this breaks silently and the symptom is misaligned thread palette in the
BottomThreadBar / export.
Suggested fix:
Export
paletteIndexForColorfromuseWorkspace.ts(or move it tosrc/lib/palette.tsas a pure helper and import it back) and addsrc/lib/palette.test.tscovering:[0..N-1].[0,1,0].[0,1,0,2,0].0.0.SET_COLOR_REGIONSwithduplicated-color regions, assert resulting
colorRegions[i].paletteIndexmatches the unique-position (not the occurrence index).
Acceptance:
src/lib/palette.test.ts(or alongside the helper if moved).npm testshows the new file in the run summary.Closing as duplicate — the recommendation in this issue was implemented under #98:
b87c4b3test(#98): lock in paletteIndexForColor behavior; tidy dead seen.add in match branchThat commit already shipped on
main:paletteIndexForColorfromuseWorkspace.ts(so it can be unit-tested directly).src/components/workspace/issue-98.test.tswith 7 cases covering all 6 acceptance criteria from this issue (already-unique regions, non-adjacent duplicates, longer alternating sequences, empty list, missing color, end-to-end through the reducer).seen.add(color)after the early return.Per #98 comment #56141 the original false-positive was also confirmed against the shipped code. This issue is a follow-up recommendation to that work and the recommendation is fulfilled.