test: extract parsing helpers into a tested module (audit bucket 4a — H2 part 1) - #4
Merged
Merged
Conversation
Extract the framework-free helpers (sortDate, shouldFilterDeclinedEvent, getAttendeeName, formatParticipants, isCancelledEvent, parseLocation, templateFormatter) from index.ts into parsing.ts so they can be unit-tested without a live Logseq environment. They no longer read the logseq global — hideDeclinedEvents / participantEmailFallback are passed in by the caller. Behavior unchanged; extraction dropped the tsc error count 65 -> 50 and parsing.ts is strict-clean. Add a Jest + ts-jest suite (31 tests) exercising every extracted function, including a regression test for L1 (a repeated template variable must be replaced at every occurrence) that was verified to fail red against the pre-fix String.replace code. Wire 'npm test' to jest and add a blocking 'test' CI job. Also adds types/url-regex-safe.d.ts (the package ships no types). The recurrence/timezone engine in rawParser is extracted+tested separately in part 2. typecheck stays non-blocking until that lands (rawParser still untyped). Tests + typecheck run locally green; build verified via CI (arm64 host can't build the native deps). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019cVCdCtNzUJmy1yen3JyBk
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.
What changed
Audit bucket 4, part 1 (finding H2). Splits the big H2 into a reviewable first PR: extract the pure helpers and test them. The recurrence/timezone engine follows in part 2.
parsing.ts— extractedsortDate,shouldFilterDeclinedEvent,getAttendeeName,formatParticipants,isCancelledEvent,parseLocation,templateFormatterfromindex.ts. They no longer read thelogseqglobal; settings are passed in by the caller. Behavior unchanged.parsing.test.ts— 31 Jest tests, including a regression test for L1 (repeated template variable replaced everywhere), verified to fail red against the pre-fixString.replacecode.testCI job;npm test→ jest.types/url-regex-safe.d.ts— types for the untyped package.tscerrors 65 → 50;parsing.tsis strict-clean.Why
H2: the date/recurrence/timezone core had zero tests, and the code was untestable because it's coupled to the
logseqglobal with module-level side effects. Extracting the pure logic makes it testable and starts shrinking the type-debt.Testing
npm test: 31 passed. L1 regression test confirmed to fail against.replace, pass against.replaceAll.npm run typecheck: 50 errors (down from 65);parsing.ts= 0.Follow-up
rawParserrecurrence/timezone/EXDATE engine.typecheckflips to a required gate after part 2 (rawParser still untyped until then).Reviewer note
No automated PR reviewer configured; self-reviewed — extraction is behavior-preserving (settings threaded through as params), tests are role/behavior-based, no secrets, blast radius is the parsing module + its callers.
🤖 Generated with Claude Code
https://claude.ai/code/session_019cVCdCtNzUJmy1yen3JyBk