Add missing test coverage for compareThought.ts#3976
Draft
Conversation
Co-authored-by: raineorshine <750276+raineorshine@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add missing test coverage for compareThought.ts
Add missing test coverage for compareThought.ts
Mar 19, 2026
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.
src/util/__tests__/compareThought.tshad zero direct tests for 9 exported functions and significant gaps in edge case coverage for partially-tested functions.New coverage
Entirely untested exports:
compareThought(ascending) — basic, meta-attributes, emojis, empty stringcompareReasonableDescending— formatting floats first, empty near top, plain text before punctuation, Z→A, dates/numbers descendingcompareStringsWithMetaAttributes— meta vs non-meta, both meta, neither metacompareThoughtByCreated/compareThoughtByCreatedDescending— timestamp ordering +compareReasonabletiebreak fallbackcompareThoughtByUpdated/compareThoughtByUpdatedDescending— same patterncompareThoughtByNoteAndRank/compareThoughtByNoteDescendingAndRank— notes-before-no-notes, note value ordering, rank tiebreaker; usesreducerFlow+importTextfor real state setupGap-filling for partially tested functions:
compareReasonable: empty string priority, punctuation/formatting/meta/emoji hierarchy, dates and numbers above plain text, full end-to-end priority interplaycompareThoughtDescending: empty string behavior, formatted text to top, date/number descending ordercompareDateStrings: dash-format with year (6-21-2025), year-based numeric ordering, cross-format cross-year comparisoncompareNumbers:₹/₠currencies, decimal numberscompareFormatting: tags with HTML attributes, mismatched tag behavior (documents that the regex does not enforce matching open/close tag names)comparePunctuationAndOther:!,#,$,(,.charactersmakeOrderedComparator: empty array base case ([]→ always0)Test count: 21 → 65.
Original prompt
Add Missing Test Coverage for
src/util/compareThought.tsThe file
src/util/__tests__/compareThought.tsis missing significant test coverage for the exported functions insrc/util/compareThought.ts. Please add tests to fill in the gaps identified below.🔴 Entirely Untested Exports
These are exported from
compareThought.tsbut never imported or tested:compareThought(ascending) — compares twoThoughtobjects by value ascending. OnlycompareThoughtDescendingis currently tested.compareThoughtByCreated— sort bycreatedtimestamp ascending, withcompareReasonablefallback for ties.compareThoughtByCreatedDescending— sort bycreatedtimestamp descending, withcompareReasonablefallback for ties.compareThoughtByUpdated— sort bylastUpdatedascending, withcompareReasonablefallback for ties.compareThoughtByUpdatedDescending— sort bylastUpdateddescending, withcompareReasonablefallback for ties.compareThoughtByNoteAndRank— sort by note value ascending, falling back to rank when notes are absent or equal.compareThoughtByNoteDescendingAndRank— sort by note value descending, falling back to rank when notes are absent or equal.compareStringsWithMetaAttributes— meta-attribute sort (only tested indirectly viacompareThoughtDescending).compareReasonableDescending— only tested indirectly viacompareThoughtDescending; no direct unit tests.🟡 Partially Tested / Missing Cases
compareReasonable''should sort firstcomparePunctuationAndOtherhas standalone tests, butcompareReasonablenever tests that punctuation-starting strings (=,#,!, etc.) sort above plain textcompareReasonablesuite for HTML-formatted strings sorting above plain textcompareReasonableascending suite"3/3"should sort before"apple""5"should sort before"apple"compareThoughtDescendingcompareDateStrings"6-21-2025"(only slash format used incompareDateStringstests)"3/3/2020"vs"3/3/2021""3/3/2020"vs"March 3, 2021"compareNumbers₹and₠currency symbols — present in the source regex but untested"1.5"vs"2.3"(isNumberuses!isNaNwhich accepts decimals)compareFormatting<span class="x">text</span>(the regex uses[^>]*to allow attributes)<b>text</i>should NOT be detected as valid formattingcomparePunctuationAndOther=is tested;!,#,$,(,.etc. are in the regex but never testedmakeOrderedComparator[]→ always returns0) is not testedImplementation Notes
thought()helper at the top of the test file to constructThoughtobjects for thought-level comparator tests.compareThoughtByNoteAndRankandcompareThoughtByNoteDescendingAndRank, these require aStateobject and look up note values vianoteValue(state, thoughtToPath(state, id)). Use the existing test infrastructure in the repo (look at other test files that usecreateTestAppor similar state helpers) to construct state with notes if needed, or mock/stub at a simpler level if state setup is complex.ByCreated,ByUpdated), constructThoughtobjects with differentcreated/lastUpdatedvalues. Thetimestamp()utility returns an ISO string — you can pass explicit strings like'2020-01-01T00:00:00.000Z'directly.'../compareThought'.The following is the prior conversation context from the user's chat exploration (may be truncated):
User: Summarize all the sort rules for the QA person in plain English.
Assistant: Here's a plain-English summary of all the sort rules, organized by sort mode:
How Thoughts Are Sorted
🔤 Text Normalization (applied before any...
This pull request was created from Copilot chat.
📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.