fix: correct reprint threshold display and de-duplicate the formula#124
Open
kirushik wants to merge 1 commit into
Open
fix: correct reprint threshold display and de-duplicate the formula#124kirushik wants to merge 1 commit into
kirushik wants to merge 1 commit into
Conversation
Print.vue recomputed the recovery threshold as floor(total/2)+2 and stored the *total* in a field misleadingly named `requiredShards`. The reprint sheets therefore overstated how many more QR codes are needed (e.g. total=5 showed "need 4" instead of the correct 3) — misleading during recovery, though the QR payloads themselves were always untouched. Root cause: the threshold policy was duplicated. Share.vue computes floor(total/2)+1; Print.vue re-implemented it and drifted. Extract a single `defaultThreshold()` helper (src/util/shards.ts) and use it in both, so they can never disagree again. Rename Print.vue's field to `totalShards` to match what it actually holds. Add unit tests for the helper, including the exact F5 case (total=5 -> 3) and a strict-majority invariant across the whole 3..255 UI range. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR centralizes the shard reconstruction threshold logic and fixes the Print view so it uses the same threshold policy as Share, preventing UI/count mismatches.
Changes:
- Added
defaultThreshold(totalShards)utility to define the “majority required” policy in one place. - Updated
Share.vueandPrint.vueto usedefaultThreshold(and corrected Print’s model/prop usage). - Added unit tests covering
defaultThresholdacross key values and the full UI range.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tests/unit/shards.spec.ts | Adds unit tests validating the centralized threshold policy. |
| src/views/Share.vue | Uses the shared defaultThreshold for required shard count. |
| src/views/Print.vue | Fixes total-vs-threshold handling; uses shared threshold for required-shards. |
| src/util/shards.ts | Introduces the single source of truth for threshold calculation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
13
to
17
| id="totalShards" | ||
| v-model.number="requiredShards" | ||
| v-model.number="totalShards" | ||
| type="number" | ||
| min="3" | ||
| max="255" |
Comment on lines
+98
to
105
| return this.totalShards !== undefined && this.shards.length !== this.totalShards; | ||
| }, | ||
| remainingCodes(): number { | ||
| if (!this.requiredShards) { | ||
| if (!this.totalShards) { | ||
| return 0; | ||
| } else { | ||
| return this.requiredShards - this.shards.length; | ||
| return this.totalShards - this.shards.length; | ||
| } |
Comment on lines
+107
to
+108
| threshold(): number { | ||
| return this.totalShards ? defaultThreshold(this.totalShards) : 0; |
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.
Print.vuerecomputed the recovery threshold asfloor(total/2)+2and stored the total in a field misleadingly namedrequiredShards. The reprint sheets therefore overstated how many more QR codes are needed (e.g. total=5 showed "need 4" instead of the correct 3) — misleading during recovery, though the QR payloads themselves were always untouched.Root cause: the threshold policy was duplicated.
Share.vuecomputesfloor(total/2)+1;Print.vuere-implemented it and the formula drifted. Extract a singledefaultThreshold()helper (src/util/shards.ts) and use it in both, so they can never disagree again. RenamePrint.vue's field tototalShardsto match what it actually holds.Adds some unit tests for this new helper, including a (rather naïve) "
defaultThreshold()should always be greater than n/2"