From 67a265e20c1f42293f9044deb54b5046cc8b1e26 Mon Sep 17 00:00:00 2001 From: Michael Gilardi <11632652+mgilardi@users.noreply.github.com> Date: Sun, 15 Nov 2026 05:57:02 -0700 Subject: [PATCH] Enforce the cross-kit check in phasing and rebuilding S7 was built but nothing called it. Phasing with a parent and rebuilding from children both rest on stated relationships, so they now measure the raw kits first and stop with SanityStop unless the DNA fits: parent-child for the parent, full siblings for the children. The Kits screen lists the relationships each measured pair fits. Tested on simulated kits: a stranger or grandparent as parent, a wrong other parent and half siblings all stop. The Kits screen text hasn't been seen in the built app. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 + README.md | 2 +- apps/desktop/host/handlers.ts | 4 +- apps/desktop/host/protocol.ts | 3 +- apps/desktop/src/screens/Kits.tsx | 5 ++- apps/desktop/test/host.test.ts | 1 + docs/architecture/0003-safeguards.md | 2 +- docs/test-audit.md | 2 +- packages/connectors/test/raw-extras.test.ts | 20 +++++++++- packages/core/src/raw-extras.ts | 7 ++++ packages/core/src/sanity.ts | 44 +++++++++++++++++++++ packages/core/test/sanity.test.ts | 10 ++++- 12 files changed, 92 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea70f87..296d8df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- The cross-kit check (S7) is enforced, 2026-11-15 (K655). Phasing a kit with a parent now stops unless the two share parent-child cM, and rebuilding someone also needs the children to share full-sibling cM. `fittingRelationships` and `RELATIONSHIP_WORDS` say which relationships a cM fits, and the Kits screen lists them for each pair compared on the Mac. Tested on simulated kits; the screen text hasn't been seen in the built app. + - The app carries its own Node, 2026-11-15 (K338). `pnpm fetch:node` downloads Node v26.13.0 from nodejs.org, checks the pinned SHA-256 and puts it where Tauri bundles it, so the Mac app no longer needs Node installed. A release build never falls back to another Node on the Mac. Also fixed two faults in the packaged helper that kept a built app from opening a library: its shared code was split into chunk files the app didn't include, and the build dropped the `node:` prefix from `node:sqlite`. Checked by building the app and running its helper with no PATH; the app window wasn't clicked through. - Theory chart, 2026-11-15: the Theory screen now draws both candidate fathers side by side, each on its own branch marked uncertain with its chance, using OnePedigree's branches mode. A switch goes back to the tree as recorded. Tested in logic tests; not yet clicked in the built app. diff --git a/README.md b/README.md index 475bf94..4cc133e 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ DNA-first genetic genealogy for Mac. OneFamily groups your DNA matches before yo - OneFamily for Mac, v0: runs on a made-up demo family. It's been built and opened locally, not released. It carries its own copy of Node, so nothing extra needs installing (ADR 0007). - the Chrome extension the app collects with (`apps/extension`, ADR 0009). It stores nothing, talks to the app only through Chrome's native messaging, and asks for your OK in the app. It only works with a local mock site: every DNA service's terms say no to automated page visits. It's been tested with Vitest against the mock site, and hasn't been loaded into Chrome yet. -266 tests pass locally. The raw layouts haven't been checked against a real downloaded file. The register's verdicts are a careful reading of public pages, not legal advice, and a legal review is still to come. +270 tests pass locally. The raw layouts haven't been checked against a real downloaded file. The register's verdicts are a careful reading of public pages, not legal advice, and a legal review is still to come. ## What it will do diff --git a/apps/desktop/host/handlers.ts b/apps/desktop/host/handlers.ts index afcc311..213a2de 100644 --- a/apps/desktop/host/handlers.ts +++ b/apps/desktop/host/handlers.ts @@ -7,7 +7,7 @@ import { createHash } from 'node:crypto' import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs' import { DatabaseSync } from 'node:sqlite' import { isAbsolute, join, relative, resolve, sep } from 'node:path' -import { BlindGate, compareKits, ONE_CM_PER_MB, sha256Hex, TermsRegister, type Unblinding } from '@extantape/onefamily-core' +import { BlindGate, compareKits, fittingRelationships, ONE_CM_PER_MB, RELATIONSHIP_WORDS, sha256Hex, TermsRegister, type Unblinding } from '@extantape/onefamily-core' import { clusterKit, type ClusterRun } from '@extantape/onefamily-analysis' import { importCollectedPages, importGenealogyAssistant, importRawDna, type ImportResult, type RawImport } from '@extantape/onefamily-connectors' import { @@ -455,7 +455,7 @@ export function createHost(opts: { const b = data.kits[j]! if (!a.raw || !b.raw) continue const c = compareKits(a.raw.calls, b.raw.calls, { map: ONE_CM_PER_MB, errorTolerance: 50 }) - comparisons.push({ a: a.result.kit, b: b.result.kit, totalCm: Math.round(c.totalCm), segments: c.segments.length, longestCm: Math.round(c.longestCm), map: c.map }) + comparisons.push({ a: a.result.kit, b: b.result.kit, totalCm: Math.round(c.totalCm), segments: c.segments.length, longestCm: Math.round(c.longestCm), map: c.map, fits: fittingRelationships(c.totalCm).map((r) => RELATIONSHIP_WORDS[r]) }) } return { kits, comparisons } }, diff --git a/apps/desktop/host/protocol.ts b/apps/desktop/host/protocol.ts index cbb7a59..f683556 100644 --- a/apps/desktop/host/protocol.ts +++ b/apps/desktop/host/protocol.ts @@ -77,7 +77,8 @@ export type KitSummary = { export type KitsResult = { kits: KitSummary[] /** The family kits compared with each other on this Mac, from their raw DNA. */ - comparisons: { a: string; b: string; totalCm: number; segments: number; longestCm: number; map: string }[] + /** `fits`: every published relationship (Shared cM Project v4) whose range holds totalCm, in plain words. */ + comparisons: { a: string; b: string; totalCm: number; segments: number; longestCm: number; map: string; fits: string[] }[] } export type MatchRow = { diff --git a/apps/desktop/src/screens/Kits.tsx b/apps/desktop/src/screens/Kits.tsx index 560a5eb..971c7e5 100644 --- a/apps/desktop/src/screens/Kits.tsx +++ b/apps/desktop/src/screens/Kits.tsx @@ -62,13 +62,14 @@ export function KitsScreen({ data }: { data: KitsResult }) {

From their raw DNA, using an approximate map of 1 cM per million base pairs ({data.comparisons[0]!.map}). That’s good enough to see close - relatives, not to measure small segments exactly. + relatives, not to measure small segments exactly. The relationships listed are every one whose observed range in the Shared cM Project (version 4) holds that number, from DNA alone. Phasing and rebuilding stop if the DNA doesn’t fit the relationship they rely on.

)} diff --git a/apps/desktop/test/host.test.ts b/apps/desktop/test/host.test.ts index d4f4047..49cbdef 100644 --- a/apps/desktop/test/host.test.ts +++ b/apps/desktop/test/host.test.ts @@ -258,6 +258,7 @@ describe('the demo family', () => { expect(kits.every((k) => k.blind && k.matches > 0 && k.raw && k.raw.markers > 10000)).toBe(true) // The two family kits are parent and child: about half the genome, compared on this Mac. expect(comparisons[0]!.totalCm).toBeGreaterThan(3000) + expect(comparisons[0]!.fits).toContain('parent or child') // The chromosome browser's data: parent and child share along all 22 chromosomes. const seg = await h.segments({ a: kits[0]!.kit, b: kits[1]!.kit }) diff --git a/docs/architecture/0003-safeguards.md b/docs/architecture/0003-safeguards.md index 16e6276..5456770 100644 --- a/docs/architecture/0003-safeguards.md +++ b/docs/architecture/0003-safeguards.md @@ -12,7 +12,7 @@ Each safeguard is enforced in code and covered by tests. A promise that's only w | S4 | Import checks fail loudly | Expected columns and types, values in range (shared cM 6 to 3,600; longest segment no bigger than the total), known date formats | | S5 | Count reconciliation | Unique IDs; previous export + new − gone = this export; the row count equals the count the service showed, when recorded | | S6 | Spot checks against the source | A sample of matches compared with the service's own pages, where the terms register allows it | -| S7 | Genetic sanity across kits | Family kits share cM in range for their DNA relationship; side assignments agree across kits. Built in `sanity.ts` (2026-11-15): out-of-range pairs, missing close relatives and more than 5% of shared matches on the wrong side stop the run; relationships with no published range are reported as not checked | +| S7 | Genetic sanity across kits | Family kits share cM in range for their DNA relationship; side assignments agree across kits. Built in `sanity.ts` (2026-11-15): out-of-range pairs, missing close relatives and more than 5% of shared matches on the wrong side stop the run; relationships with no published range are reported as not checked. Enforced since 2026-11-15 (K655): `phaseWithParent` and `rebuildFromDescendants` measure the raw kits first and stop unless the parent and child share parent-child cM and the children share full-sibling cM; a relationship with no range can't be relied on there. The Kits screen lists what each measured pair fits. Any later analysis that combines kits must call `assertSane` first | | S8 | Stability report | A run stops for review if more than a few percent of placed people change lines | | S9 | Claims checked against data | Every match cited in a theory is checked against the stored observations | | S10 | People decide conclusions | A theory's status changes only with the user's approval, which is logged | diff --git a/docs/test-audit.md b/docs/test-audit.md index eb11471..28c47a6 100644 --- a/docs/test-audit.md +++ b/docs/test-audit.md @@ -52,7 +52,7 @@ Kept by this repo's owning session (Genealogy), per `~/Code/CLAUDE.md`, "Test se **Gaps skipped, and why:** - **S6, spot checks against a service's own pages:** they need automated visits to real services, which the terms register refuses. Revisit with a partnership. -- **S7, genetic sanity across family kits:** built 2026-11-15 in `packages/core/src/sanity.ts`, covered by `packages/core/test/sanity.test.ts` (9 tests): pairs in and out of range both ways, a missing close relative, an unranged relationship reported as not checked, lists that disagree, sides that agree and disagree for a mother and a father, small matches ignored, and too few to judge. No app screen calls it yet; combined runs must call `assertSane` first. +- **S7, genetic sanity across family kits:** built 2026-11-15 in `packages/core/src/sanity.ts`, covered by `packages/core/test/sanity.test.ts` (9 tests): pairs in and out of range both ways, a missing close relative, an unranged relationship reported as not checked, lists that disagree, sides that agree and disagree for a mother and a father, small matches ignored, and too few to judge. Since 2026-11-15 (K655) it guards phasing and rebuilding: `packages/connectors/test/raw-extras.test.ts` shows phasing stops on a stranger and on a grandparent stated as parent, and rebuilding stops on a wrong other parent and on half siblings; `fittingRelationships` is covered in core, and the Kits screen's list in the host test. There are no combined runs in the app yet, so there's nothing else to guard. - **Theory chart, both candidate fathers (K337):** 2026-11-15, `apps/desktop/test/logic.test.ts` checks that a theory document drawn with OnePedigree's `uncertainParents: 'branches'` shows both the recorded and the candidate father, each joined by an uncertain line. The screen's radio switch itself is covered only by the typecheck; it hasn't been clicked in the built app. - **Bundled Node (K338):** 2026-11-15, checked by hand: `tauri build --bundles app`, then the app's own `Contents/MacOS/node` ran `host.mjs` under `env -i` (no PATH) and answered a `status` request. That run found the chunk and `node:sqlite` faults, now fixed. Not automated: CI doesn't build the Mac app yet, and a unit test of the download script would only re-check the pinned hash. Worth adding a CI step that runs the built helper once the Mac build moves to CI. - **S8, the stability report between runs:** not built, since there's only one run so far. Filed as a task. diff --git a/packages/connectors/test/raw-extras.test.ts b/packages/connectors/test/raw-extras.test.ts index de13a59..f486038 100644 --- a/packages/connectors/test/raw-extras.test.ts +++ b/packages/connectors/test/raw-extras.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest' import { fileURLToPath } from 'node:url' -import { compareHalves, compareKits, phaseWithParent, rebuildFromDescendants, RebuildRefused, xPathPossible } from '@extantape/onefamily-core' +import { checkRawPair, compareHalves, compareKits, phaseWithParent, rebuildFromDescendants, RebuildRefused, SanityStop, xPathPossible } from '@extantape/onefamily-core' import { loadTermsRegister } from '../../core/src/node.js' import { AlleleBook, child, founderGenome, genotypesOf, makePanel, Rng, writeRaw, type Genome } from '@extantape/onefamily-simulate' import { importRawDna } from '../src/index.js' @@ -66,6 +66,24 @@ describe('rebuilding someone who never tested', async () => { }) }) +describe('the cross-kit check guards both (S7)', async () => { + const halfSib = child(P, R, rng) + const [q, x, g1, hs, ...ch] = await Promise.all([kitOf(Q), kitOf(stranger), kitOf(G1), kitOf(halfSib), ...kids.map(kitOf)]) + it('phasing stops when the stated parent is a stranger or a grandparent', () => { + expect(() => phaseWithParent(ch[0]!, x)).toThrow(SanityStop) + expect(() => phaseWithParent(ch[0]!, g1)).toThrow(/outside 2376 to 3720 cM for parent-child/) + }) + it('rebuilding stops when the other parent is wrong, or the children are only half siblings', () => { + expect(() => rebuildFromDescendants(ch, x, { synthetic: true })).toThrow(SanityStop) + expect(() => rebuildFromDescendants([ch[0]!, hs], q, { synthetic: true })).toThrow(/child 1 and child 2.*full-sibling/) + }) + it('measures a pair and reports what was stated against what fits', () => { + const r = checkRawPair({ label: 'A', calls: ch[0]! }, { label: 'B', calls: ch[1]! }, 'full-sibling') + expect(r.cm).toBeGreaterThan(1613) + expect(r.issues).toEqual([]) + }) +}) + describe('X-DNA paths', () => { it('a man gets his X only from his mother', () => { expect(xPathPossible(['M', 'F', 'M', 'F'])).toBe(true) diff --git a/packages/core/src/raw-extras.ts b/packages/core/src/raw-extras.ts index 10ab5c2..119de11 100644 --- a/packages/core/src/raw-extras.ts +++ b/packages/core/src/raw-extras.ts @@ -7,9 +7,12 @@ * do it, on real data too, once they've chosen to and that choice is recorded in their decisions log. The * result is always labelled "rebuilt, partial", stays in their own library, and is never uploaded or shared * by the app. Without a recorded choice it's refused. + * - Both stop with `SanityStop` (S7, ADR 0003) unless the DNA fits the relationships they rest on: the + * parent and child share parent-child cM, and the children share full-sibling cM. * - `xPathPossible`: whether X DNA can pass along a line, which rules branches in or out for X matches. */ import type { KitCalls } from './compare.js' +import { requireRawRelationship } from './sanity.js' type Calls = { rsid: string[]; position: number[]; call: string[] } export type HalfKit = Map @@ -22,6 +25,7 @@ const alleles = (g: string): [string, string] | null => (g.length === 2 && g !== * parent and child that contradict each other (a likely error). */ export function phaseWithParent(childKit: KitCalls, parentKit: KitCalls): { fromParent: HalfKit; fromOther: HalfKit; resolved: number; total: number } { + requireRawRelationship({ label: 'the child', calls: childKit }, { label: 'the tested parent', calls: parentKit }, 'parent-child') const fromParent: HalfKit = new Map() const fromOther: HalfKit = new Map() let resolved = 0 @@ -76,6 +80,9 @@ export const REBUILT_LABEL = 'rebuilt, partial' as const export function rebuildFromDescendants(children: readonly KitCalls[], partner: KitCalls, consent: RebuildConsent): { label: typeof REBUILT_LABEL; rebuilt: Map; halves: HalfKit[]; known: number; halfKnown: number; total: number } { if (!('synthetic' in consent) && consent.decision?.kind !== 'rebuild-consent') throw new RebuildRefused() if (children.length < 2) throw new Error('rebuilding needs at least two children') + for (let i = 0; i < children.length; i++) + for (let j = i + 1; j < children.length; j++) + requireRawRelationship({ label: `child ${i + 1}`, calls: children[i]! }, { label: `child ${j + 1}`, calls: children[j]! }, 'full-sibling') const seen = new Map }>() const halves: HalfKit[] = [] for (const ch of children) { diff --git a/packages/core/src/sanity.ts b/packages/core/src/sanity.ts index d5856a1..52181fc 100644 --- a/packages/core/src/sanity.ts +++ b/packages/core/src/sanity.ts @@ -7,9 +7,13 @@ * with its tested father on the paternal side. A real disagreement rate means a side label, a kit or a * stated relationship is wrong. * + * - Raw kits: analyses that rest on a stated relationship between two raw kits (phasing with a parent, + * rebuilding from children) measure it first with `requireRawRelationship` and stop if it doesn't fit. + * * Nothing is repaired. Each problem is an Issue; `assertSane` stops a run on any error. A relationship with no * known range is reported as not checked, never passed. */ +import { compareKits, type CompareOptions, type KitCalls } from './compare.js' import type { MatchObservation } from './model.js' import type { Issue } from './issues.js' @@ -28,6 +32,21 @@ export const RELATIONSHIP_RANGES = { 'second-cousin': [41, 592], } as const satisfies Record +/** Plain words for each relationship, for screens and reports. */ +export const RELATIONSHIP_WORDS: Record = { + 'parent-child': 'parent or child', + 'full-sibling': 'full sibling', + 'half-sibling': 'half sibling', + grandparent: 'grandparent or grandchild', + 'aunt-uncle': 'aunt, uncle, niece or nephew', + 'half-aunt-uncle': 'half aunt, uncle, niece or nephew', + 'great-grandparent': 'great-grandparent or great-grandchild', + 'first-cousin': 'first cousin', + 'half-first-cousin': 'half first cousin', + 'first-cousin-once-removed': 'first cousin once removed', + 'second-cousin': 'second cousin', +} + export type Relationship = keyof typeof RELATIONSHIP_RANGES | (string & {}) export type KitPair = { @@ -114,3 +133,28 @@ export function checkSides(child: readonly MatchObservation[], parent: readonly export function assertSane(issues: readonly Issue[]): void { if (issues.some((i) => i.severity === 'error')) throw new SanityStop(issues) } + +/** Every published relationship whose observed range includes this cM. Several usually fit. */ +export function fittingRelationships(cm: number): (keyof typeof RELATIONSHIP_RANGES)[] { + return (Object.entries(RELATIONSHIP_RANGES) as [keyof typeof RELATIONSHIP_RANGES, readonly [number, number]][]) + .filter(([, [lo, hi]]) => cm >= lo && cm <= hi) + .map(([r]) => r) +} + +export type RawKit = { label: string; calls: KitCalls } + +/** Measures two raw kits against each other and checks the stated relationship (S7). */ +export function checkRawPair(a: RawKit, b: RawKit, stated: Relationship, opts: CompareOptions = {}): { cm: number; issues: Issue[] } { + const cm = Math.round(compareKits(a.calls, b.calls, opts).totalCm) + return { cm, issues: checkKitPairs([{ a: a.label, b: b.label, stated, aSeesB: cm }]) } +} + +/** + * Stops unless the two raw kits share cM that fits the stated relationship. A relationship with no published + * range can't be checked, so it's refused too: an analysis that rests on it can't go ahead unchecked. + */ +export function requireRawRelationship(a: RawKit, b: RawKit, stated: keyof typeof RELATIONSHIP_RANGES, opts: CompareOptions = {}): number { + const { cm, issues } = checkRawPair(a, b, stated, opts) + assertSane(issues.map((i) => (i.code === 'kits.unchecked' ? { ...i, severity: 'error' as const } : i))) + return cm +} diff --git a/packages/core/test/sanity.test.ts b/packages/core/test/sanity.test.ts index b43f0a9..ab68e8d 100644 --- a/packages/core/test/sanity.test.ts +++ b/packages/core/test/sanity.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest' -import { assertSane, checkKitPairs, checkSides, SanityStop, type MatchObservation, type MatchSide } from '../src/index.js' +import { assertSane, checkKitPairs, checkSides, fittingRelationships, SanityStop, type MatchObservation, type MatchSide } from '../src/index.js' const obs = (kit: string, match: string, cm: number, side: MatchSide = 'unassigned'): MatchObservation => ({ service: 'planted', kit, match, name: match, sharedCm: cm, unweightedCm: cm, longestCm: Math.min(cm, 50), segments: 3, side, @@ -57,3 +57,11 @@ describe('sides (S7)', () => { expect(checkSides(child, father, 'father')[0]!.code).toBe('sides.disagree') }) }) + +describe('what a cM fits', () => { + it('lists every published relationship whose range holds it, and none outside', () => { + expect(fittingRelationships(3400)).toEqual(['parent-child', 'full-sibling']) + expect(fittingRelationships(4000)).toEqual([]) + expect(fittingRelationships(500)).toEqual(expect.arrayContaining(['great-grandparent', 'first-cousin', 'second-cousin'])) + }) +})