From b7b3d7048337ae6a5e802041a24fd383c160547b Mon Sep 17 00:00:00 2001 From: orveth Date: Mon, 20 Apr 2026 11:42:54 -0700 Subject: [PATCH] fix(core/reviews): default k=38172 + derive a in test helpers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR #33's P0.3 change tightened `ReviewRow` so `k` (38172 | 38173) and `a` (::) are required. Three test files use a local `makeReview` helper whose `Partial` input kept both fields optional, so the spread into `ReviewRow` fails the stricter CI TS check even though our flake-pinned local TS was lenient. Result: CI has been red on merged PRs #33 and #34 plus open #35, all with the same error. Fix: each helper now defaults `k` to 38172 (Cashu) and derives `a` from `kind:pubkey:d` per NIP-87. One call site (the Fedimint gate test in upsert.test.ts) already passes `k: 38173` and now flows through the spread override — confirmed still green. No production code touched. Test count unchanged (247 passing). Co-Authored-By: Claude Opus 4.7 --- packages/core/src/reviews/aggregate.test.ts | 15 ++++++++++++--- packages/core/src/reviews/rank.test.ts | 8 +++++++- packages/core/src/reviews/upsert.test.ts | 14 +++++++++++--- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/packages/core/src/reviews/aggregate.test.ts b/packages/core/src/reviews/aggregate.test.ts index f70b484..77bf6d3 100644 --- a/packages/core/src/reviews/aggregate.test.ts +++ b/packages/core/src/reviews/aggregate.test.ts @@ -29,12 +29,21 @@ const D_A = "5fe928ae0970844f3c5253d2e85a88788486edcbd96c070334a4a2d0d0154a77"; const D_B = "0".repeat(63) + "1"; function makeReview(over: Partial & { d?: string } = {}): ReviewRow { + const pubkey = over.pubkey ?? `pk${Math.random().toString(36).slice(2, 10)}${"0".repeat(50)}`; + const d = over.d ?? D_A; + const kind = 38000 as const; + // `k` defaults to Cashu (38172) — tests in this file don't differentiate + // Cashu vs Fedimint; parse-level `k` handling is covered in parse.test.ts. + // `a` is derived from kind/pubkey/d per NIP-87's `::`. + const k = over.k ?? 38172; return { - pubkey: `pk${Math.random().toString(36).slice(2, 10)}${"0".repeat(50)}`, - kind: 38000, - d: over.d ?? D_A, + pubkey, + kind, + d, eventId: `${"0".repeat(58)}${Math.random().toString(36).slice(2, 8)}`, createdAt: 1_700_000_000, + k, + a: `${kind}:${pubkey}:${d}`, content: "", rawTags: [], rating: 5, diff --git a/packages/core/src/reviews/rank.test.ts b/packages/core/src/reviews/rank.test.ts index 192b908..2a76175 100644 --- a/packages/core/src/reviews/rank.test.ts +++ b/packages/core/src/reviews/rank.test.ts @@ -34,10 +34,16 @@ function dForIndex(n: number): string { } function makeReview(over: Partial & { pubkey: string; d: string }): ReviewRow { + const kind = 38000 as const; + // `k` defaults to Cashu (38172); rank.test only exercises sort order, + // which is `k`-agnostic. `a` is derived per NIP-87 `::`. + const k = over.k ?? 38172; return { - kind: 38000, + kind, eventId: `${"0".repeat(58)}${over.pubkey.slice(-6)}`, createdAt: 1_700_000_000, + k, + a: `${kind}:${over.pubkey}:${over.d}`, content: "", rawTags: [], rating: 5, diff --git a/packages/core/src/reviews/upsert.test.ts b/packages/core/src/reviews/upsert.test.ts index 8a167d2..2ad15b8 100644 --- a/packages/core/src/reviews/upsert.test.ts +++ b/packages/core/src/reviews/upsert.test.ts @@ -42,12 +42,20 @@ const EID_LOW = `${"0".repeat(60)}aaaa`; const EID_HIGH = `${"0".repeat(60)}ffff`; function makeReview(over: Partial = {}): ReviewRow { + const pubkey = over.pubkey ?? `pk${"0".repeat(60)}1`; + const d = over.d ?? D_VALID; + const kind = 38000 as const; + // `k` defaults to Cashu (38172); one test below overrides to 38173 for the + // Fedimint path. `a` is derived per NIP-87 `::`. + const k = over.k ?? 38172; return { - pubkey: `pk${"0".repeat(60)}1`, - kind: 38000, - d: D_VALID, + pubkey, + kind, + d, eventId: EID_LOW, createdAt: 1_700_000_000, + k, + a: `${kind}:${pubkey}:${d}`, content: "", rawTags: [], rating: 5,