From e6c6cdf5fdac124865b7e648f100a5d3e3cefccf Mon Sep 17 00:00:00 2001 From: Kirill Pimenov Date: Fri, 29 May 2026 22:29:17 +0200 Subject: [PATCH] fix: correct reprint threshold display and de-duplicate the formula (F5) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- src/util/shards.ts | 8 ++++++++ src/views/Print.vue | 20 ++++++++++++-------- src/views/Share.vue | 3 ++- tests/unit/shards.spec.ts | 24 ++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 9 deletions(-) create mode 100644 src/util/shards.ts create mode 100644 tests/unit/shards.spec.ts diff --git a/src/util/shards.ts b/src/util/shards.ts new file mode 100644 index 0000000..e270646 --- /dev/null +++ b/src/util/shards.ts @@ -0,0 +1,8 @@ +// Banana Split's fixed threshold policy: reconstruction requires a majority of +// the shards, i.e. floor(total / 2) + 1. This lives in one place so the +// generator (Share.vue) and the reprint view (Print.vue) can never disagree — +// they did once: Print.vue re-implemented the formula as floor(total/2)+2 and +// displayed the wrong "you need N more" count on reprints (finding F5). +export function defaultThreshold(totalShards: number): number { + return Math.floor(totalShards / 2) + 1; +} diff --git a/src/views/Print.vue b/src/views/Print.vue index a207e74..79ef98c 100644 --- a/src/views/Print.vue +++ b/src/views/Print.vue @@ -11,7 +11,7 @@
@@ -64,6 +64,7 @@