fix VerseRef.verseNum setter mis-port - #60
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #60 +/- ##
==========================================
+ Coverage 83.93% 84.68% +0.74%
==========================================
Files 4 4
Lines 330 333 +3
Branches 77 80 +3
==========================================
+ Hits 277 282 +5
+ Misses 33 30 -3
- Partials 20 21 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The setter assigned the backing field and nothing else, marked with a `ToDo`
placeholder. It was missing both of the other things the C# `VerseRef.VerseNum`
setter does:
if (value < 0)
throw new VerseRefException("VerseNum can not be negative");
verseNum = (short)value;
verse = null;
So negative verse numbers were accepted, and assigning `verseNum` left the
range/segment string in place. Setting `verseNum = 9` on `LUK 3:4b-5a` left a
stale `4b-5a` in the `verse` getter and `hasMultiple` still `true`.
Uses `this._verse = undefined` rather than `null`, per the repo convention of
preferring `undefined` for missing values. The C# `(short)` cast is not
replicated.
The C# test that covers the range-clearing is `CopyVerseFrom`, which sets
`VerseNum = 9` on a `LUK 3:4b-6a` source and then asserts the copied `Verse` is
`"9"`. That test cannot be ported yet — `copyVerseFrom` is not implemented in
this port — so the cases are added as TS-only tests instead: the negative
guard, the zero boundary, and the clearing of both a range and a segment.
`BuildVerseRefByProps` already exercised `verseNum = 0/15/17` and still passes;
those are plain numbers with no verse string to clear.
Behaviour change for consumers: unlike the sibling `chapterNum` setter fixed in
#58, this setter worked before, so code reading `verse`/`hasMultiple` after
assigning `verseNum` will see different results.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
irahopkinson
force-pushed
the
fix-versenum-setter
branch
from
August 10, 2026 03:42
03101cb to
89f5f67
Compare
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.
The
verseNumsetter assigned the backing field and nothing else, still carryingits
ToDoplaceholder:The C#
VerseRef.VerseNumit ports does two more things:
So the TS accepted negative verse numbers, and assigning
verseNumleft anyrange or segment string in place:
This mirrors #58, which fixed the sibling
chapterNumsetter the same way.this._verse = undefinedis used rather thannull, per the repo convention ofpreferring
undefinedfor missing values, and the C#(short)cast is notreplicated.
Tests
Worked TDD: tests written first, confirmed red (3 failures — no throw on
negative,
'4b-5a'and'4b'both stale), then fixed.The C# test that actually covers the range-clearing is
CopyVerseFrom— it setsVerseNum = 9on aLUK 3:4b-6asource, then asserts the copiedVerseis"9"rather than"4b-6a". It can't be ported yet:copyVerseFromisn'timplemented in this port. Nothing else in
VerseRefTests.csassignsVerseNumon a ranged ref, so the cases go in the existing
describe('Extra (TS-only tests)') > describe('Property setters')blockalongside the
chapterNumones:VerseRefExceptionverseNumclears a range ('4b-5a'→'9',hasMultiplefalse)verseNumclears a segment ('4b'→'9')BuildVerseRefByPropsalready exercisedverseNum = 0/15/17and still passes —those are plain numbers with no verse string to clear.
Also removes the now-fixed
set verseNumbullet from CLAUDE.md's "Known portinggaps".
Unlike
chapterNum— which recursed into itself and blew the stack on everyassignment, so nothing could have depended on it — this setter works today.
Clearing
_versechanges what theversegetter andhasMultiplereturn forcode that currently functions: anything that assigns
verseNumto a ref holdinga range or segment and then reads
versewill now get the new number instead ofthe old range string.
That is the correct, C#-faithful behaviour, and the old value was stale — but it
is a break, not a pure bugfix in the semver sense. The downstream survey below
bounds the actual blast radius.
Downstream usage survey
Surveyed for real reachability of both setters across the
paranextorg (38repos),
eten-tech-foundation/scripture-editors,and
sillsdev/scripture-forge-platform-extensions.No consumer reaches either setter.
Every
.verseNum =/.chapterNum =assignment found is on a plain object, nota
VerseRefinstance —SerializedVerseRefis aninterface(src/verse-ref.ts:10),so those are data properties with no accessor:
platform-scripture-editor.utils.ts:198,300SerializedVerseRefinventory.web-view.tsx:97–104SerializedVerseRefchecks-side-panel.web-view.tsx:167–168SerializedVerseRefusj-reader-writer.ts:3085–3162{bookId, chapterNum, verseNum}send-receive.web-view.tsx:260demos/…/usj-reader-writer.tspackages/scribe/…/useModifiedMarkersForMenu.ts:45–47Canon,SerializedVerseRefThe
VerseRefclass is barely used downstream. Only three TypeScriptnew VerseRef(...)sites exist across all three targets, and each is a read-onlychained expression that never stores the instance:
paranext-coreextensions/src/quick-verse/src/main.ts:191—new VerseRef(selector).toJSON()paranext-corelib/platform-bible-utils/src/scripture/scripture-util.ts:325,336—.BBBCCC/.BBBCCCVVVscripture-editorsdemos/platform/lib/platform-bible-utils/src/scripture-util.ts:225,236— same twoVerseRef.fromJSONhas zero uses, and there are no: VerseRefannotations oras VerseRefcasts anywhere. With noVerseRefinstance ever held in avariable, there is nothing for the setter to be invoked on. The same holds for
chapterNum, which also retroactively confirms #58 was safe.(The many other
new VerseRefhits inparanext-coreare C# underc-sharp/and
c-sharp-tests/, using libpalaso's own class — unrelated to this package.)Method: local clones grepped for assignment patterns, plus GitHub code search
across all three targets. Code search indexes default-branch HEAD, so it
reflects current
mainregardless of clone freshness; the commits the localclones were behind by were separately diffed and introduce no new assignments
and no new
new VerseRef. Blind spot: any private repo not visible to thetoken used.
Bearing on the version bump
All four consumers declare
"@sillsdev/scripture": "^2.0.5"(paranext-corepackage.jsonandextensions/package.json, scripture-editorspackages/platform/package.json, scripture-forge-platform-extensionspackage.json).So a
3.0.0would not propagate to any of them until someone widens the rangeby hand, whereas a
2.xrelease is picked up on the next install — and per thesurvey would be a no-op for all four. The practical risk to known consumers is
zero either way; a major would only be a conservative signal to unknown ones.
No version bump is included here — that call is left to the maintainer.
Verification
Rebased onto
mainat 2.0.6 (#61, #62) and re-verified from a cleannpm ciagainst the updated lockfile, since dependencies changed underneath this branch:
lint— clean at--max-warnings 0prettier:ci— no files differbuild—tscclean,dist/regenerated with no unexpected diffvitest run— 47 passed (3 files)npx tsc -p tsconfig.test.json --noEmit— clean (CI doesn't run this; testfiles are otherwise unchecked)
🤖 Generated with Claude Code