diff --git a/CHANGELOG.md b/CHANGELOG.md index 296d8df..ccaa904 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Genetic map download, 2026-11-15 (K653, owner's N124 A). A Genetic map card on the Kits screen offers the HapMap-derived GRCh37 map (about 24 MB) from the Beagle site at the University of Washington. It says where the map comes from and that no license is stated, downloads only after a yes, checks the pinned size and SHA-256, and can remove the map again. Comparisons use it when both raw files are on GRCh37; the demo always uses the approximate rule. Tested with made-up archives, and once by hand with the real archive (chromosome 1 comes out at 286 cM). The card hasn't been clicked in the built app. + - 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. diff --git a/README.md b/README.md index 4cc133e..bffbfbe 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ DNA-first genetic genealogy for Mac. OneFamily groups your DNA matches before yo - a simulator of made-up families with planted answers - importers for Genealogy Assistant-style match lists you export yourself (allowed by the owner's reading of the terms, pending a legal review), and for raw DNA in five companies' layouts - match grouping from the DNA alone (ADR 0006) -- kit-to-kit comparison, triangulation and segment painting +- kit-to-kit comparison, triangulation and segment painting, with an approximate map or the GRCh37 map the app downloads after a yes - sibling phasing, half-kits and rebuilt relatives (made-up data only) - the hypothesis engine with odds (ADR 0008) - the library with checked, encrypted backups @@ -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. -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. +275 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/genetic-map.ts b/apps/desktop/host/genetic-map.ts new file mode 100644 index 0000000..7059bba --- /dev/null +++ b/apps/desktop/host/genetic-map.ts @@ -0,0 +1,144 @@ +/** + * The GRCh37 genetic map, downloaded onto this Mac when the person asks (owner, 2026-11-11, N124 A; K653). + * + * OneFamily doesn't bundle it: no license is stated where it's published. The app names the source, downloads + * the file from there only after a yes, checks it against the size and SHA-256 pinned here, and keeps the + * autosomes and X as one PLINK file in the app's own folder, with a note saying where it came from. Without + * it, comparisons use the approximate 1 cM per Mb rule and say so. + */ +import { createHash } from 'node:crypto' +import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs' +import { join } from 'node:path' +import { inflateRawSync } from 'node:zlib' +import { parsePlinkMap, type GeneticMap } from '@extantape/onefamily-core' + +export const GRCH37_MAP = { + name: 'HapMap Phase II, GRCh37 (Beagle PLINK files)', + url: 'https://bochet.gcc.biostat.washington.edu/beagle/genetic_maps/plink.GRCh37.map.zip', + bytes: 23_913_120, + sha256: '8e88141345844571bc63efac6c043ee29e8ca41f26087dc51b7f1918943a077b', + publisher: 'the Beagle genetic maps page at the University of Washington', + madeBy: 'The HapMap Phase II map (2007), lifted to GRCh37 by Adam Auton (2010), in PLINK format by Brian Browning.', + license: 'No license is stated on the download page.', +} as const + +const CHROMOSOMES = [...Array.from({ length: 22 }, (_, i) => String(i + 1)), 'X'] + +export class MapError extends Error {} + +const dir = (stateDir: string) => join(stateDir, 'genetic-maps', 'GRCh37') +const mapFile = (stateDir: string) => join(dir(stateDir), 'plink.GRCh37.map') +const noteFile = (stateDir: string) => join(dir(stateDir), 'SOURCE.md') + +/** The files in a zip archive, by name. Only stored and deflated entries, which is all this archive uses. */ +export function readZip(buf: Buffer): Map { + let end = -1 + for (let i = buf.length - 22; i >= Math.max(0, buf.length - 65_557); i--) if (buf.readUInt32LE(i) === 0x06054b50) { end = i; break } + if (end < 0) throw new MapError('The download isn’t a zip archive.') + const count = buf.readUInt16LE(end + 10) + let p = buf.readUInt32LE(end + 16) + const files = new Map() + for (let n = 0; n < count; n++) { + if (buf.readUInt32LE(p) !== 0x02014b50) throw new MapError('The zip archive’s directory is damaged.') + const method = buf.readUInt16LE(p + 10) + const packed = buf.readUInt32LE(p + 20) + const size = buf.readUInt32LE(p + 24) + const nameLen = buf.readUInt16LE(p + 28) + const extraLen = buf.readUInt16LE(p + 30) + const commentLen = buf.readUInt16LE(p + 32) + const local = buf.readUInt32LE(p + 42) + const name = buf.subarray(p + 46, p + 46 + nameLen).toString('utf8') + const start = local + 30 + buf.readUInt16LE(local + 26) + buf.readUInt16LE(local + 28) + const data = buf.subarray(start, start + packed) + if (method === 0) files.set(name, Buffer.from(data)) + else if (method === 8) files.set(name, inflateRawSync(data)) + else throw new MapError(`${name} uses a compression this app doesn’t read.`) + if (files.get(name)!.length !== size) throw new MapError(`${name} didn’t unpack to its stated size.`) + p += 46 + nameLen + extraLen + commentLen + } + return files +} + +/** Checks a downloaded archive and installs the map. Nothing is written unless every check passes. */ +export function installMap(stateDir: string, archive: Uint8Array, today: string, expected: { bytes: number; sha256: string } = GRCH37_MAP): void { + const buf = Buffer.from(archive) + if (buf.length !== expected.bytes) throw new MapError(`The download is ${buf.length.toLocaleString()} bytes, not the expected ${expected.bytes.toLocaleString()}. Nothing was installed.`) + const sha = createHash('sha256').update(buf).digest('hex') + if (sha !== expected.sha256) throw new MapError('The download doesn’t match the checksum this app expects. Nothing was installed.') + const files = readZip(buf) + const parts = CHROMOSOMES.map((c) => { + const f = files.get(`plink.chr${c}.GRCh37.map`) + if (!f) throw new MapError(`The archive has no map for chromosome ${c}. Nothing was installed.`) + return f.toString('utf8').trimEnd() + }) + const text = parts.join('\n') + '\n' + parsePlinkMap(GRCH37_MAP.name, text) // refuses a malformed map + mkdirSync(dir(stateDir), { recursive: true }) + const tmp = `${mapFile(stateDir)}.partial` + writeFileSync(tmp, text) + writeFileSync( + noteFile(stateDir), + [ + '# Genetic map (GRCh37)', + '', + `Downloaded on ${today} from ${GRCH37_MAP.publisher}, at the person's request:`, + GRCH37_MAP.url, + '', + GRCH37_MAP.madeBy, + GRCH37_MAP.license, + '', + `Archive SHA-256: ${sha}`, + 'Kept here: chromosomes 1 to 22 and X, joined into plink.GRCh37.map. Delete this folder to go back to the approximate rule.', + '', + ].join('\n'), + ) + renameSync(tmp, mapFile(stateDir)) +} + +export type MapStatus = { + installed: boolean + name: string + publisher: string + url: string + megabytes: number + madeBy: string + license: string + installedOn: string | null +} + +export function mapStatus(stateDir: string): MapStatus { + const installed = existsSync(mapFile(stateDir)) + const note = installed && existsSync(noteFile(stateDir)) ? readFileSync(noteFile(stateDir), 'utf8') : '' + return { + installed, + name: GRCH37_MAP.name, + publisher: GRCH37_MAP.publisher, + url: GRCH37_MAP.url, + megabytes: Math.round(GRCH37_MAP.bytes / 1_000_000), + madeBy: GRCH37_MAP.madeBy, + license: GRCH37_MAP.license, + installedOn: /Downloaded on (\d{4}-\d{2}-\d{2})/.exec(note)?.[1] ?? null, + } +} + +let cached: { file: string; map: GeneticMap } | null = null + +/** The installed map, or null. */ +export function loadMap(stateDir: string): GeneticMap | null { + const file = mapFile(stateDir) + if (!existsSync(file)) return null + if (cached?.file !== file) cached = { file, map: parsePlinkMap(GRCH37_MAP.name, readFileSync(file, 'utf8')) } + return cached.map +} + +export function removeMap(stateDir: string): void { + rmSync(dir(stateDir), { recursive: true, force: true }) + cached = null +} + +/** Downloads the archive from its publisher. */ +export async function downloadArchive(fetchImpl: typeof fetch = fetch): Promise { + const res = await fetchImpl(GRCH37_MAP.url) + if (!res.ok) throw new MapError(`The map’s publisher answered ${res.status}. Nothing was installed.`) + return new Uint8Array(await res.arrayBuffer()) +} diff --git a/apps/desktop/host/handlers.ts b/apps/desktop/host/handlers.ts index 213a2de..f4a1d6f 100644 --- a/apps/desktop/host/handlers.ts +++ b/apps/desktop/host/handlers.ts @@ -17,6 +17,7 @@ import { import type { PedigreeDocument } from '@extantape/onepedigree-core' import { withCandidateFathers, type TreePerson } from '../src/pedigree' import { createDemoLibrary, DEMO_NOTE } from './demo' +import { downloadArchive, installMap, loadMap, mapStatus, removeMap } from './genetic-map' import { createExtensionBridge, type ExtensionData } from './extension/bridge' import { extensionRegister } from './extension/terms' import { PUBLISHED_EXTENSION_ID } from './extension/wire' @@ -53,6 +54,9 @@ export function createHost(opts: { now?: () => Date /** The real services' terms files (name → text) for the extension's register. Without them every real service is refused. */ termsFiles?: Readonly> + /** Where the genetic map comes from. Tests pass a made-up archive and its own size and checksum. */ + downloadMap?: () => Promise + mapExpected?: { bytes: number; sha256: string } }) { const keys = opts.keys ?? noKeyStore const now = opts.now ?? (() => new Date()) @@ -66,6 +70,17 @@ export function createHost(opts: { return s.current } + /** + * The map for comparing two kits: the downloaded GRCh37 map when it's installed and both raw files are on + * GRCh37, otherwise the approximate rule. Ancestry and FamilyTreeDNA files don't state a build; both are + * GRCh37. The demo's positions are made up, so it always uses the approximate rule. + */ + const mapFor = (lib: string, ...kits: LoadedKit[]) => { + if (existsSync(join(lib, DEMO_NOTE))) return ONE_CM_PER_MB + const on37 = (k: LoadedKit) => k.raw?.details.build === '37' || (k.raw?.details.build == null && ['ancestry', 'ftdna'].includes(k.raw?.details.service ?? '')) + return (kits.every(on37) && loadMap(opts.stateDir)) || ONE_CM_PER_MB + } + // --- Library and decisions const decisions = (lib: string) => readDecisions(decisionsPath(lib)) @@ -429,6 +444,29 @@ export function createHost(opts: { return status() }, + // --- Genetic map (N124 A, K653) + + async geneticMap() { + return mapStatus(opts.stateDir) + }, + + /** Downloads the GRCh37 map from its publisher. Only after a yes: `confirm` must be true. */ + async downloadGeneticMap({ confirm }) { + if (confirm !== true) throw new HostError('Downloading the genetic map needs a yes first.') + const archive = await (opts.downloadMap ?? downloadArchive)() + try { + installMap(opts.stateDir, archive, now().toISOString().slice(0, 10), opts.mapExpected) + } catch (e) { + throw new HostError((e as Error).message) + } + return mapStatus(opts.stateDir) + }, + + async removeGeneticMap() { + removeMap(opts.stateDir) + return mapStatus(opts.stateDir) + }, + // --- Screens async kits(): Promise { @@ -454,7 +492,7 @@ export function createHost(opts: { const a = data.kits[i]! 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 }) + const c = compareKits(a.raw.calls, b.raw.calls, { map: mapFor(lib, a, b), 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, fits: fittingRelationships(c.totalCm).map((r) => RELATIONSHIP_WORDS[r]) }) } return { kits, comparisons } @@ -487,18 +525,20 @@ export function createHost(opts: { }, async segments({ a, b }) { - const data = await load(current()) + const lib = current() + const data = await load(lib) const ka = data.kits.find((k) => k.result.kit === a) const kb = data.kits.find((k) => k.result.kit === b) if (!ka || !kb) throw new HostError('That kit isn’t in this library.') if (!ka.raw || !kb.raw) throw new HostError('Both kits need a raw DNA file to be compared.') - const c = compareKits(ka.raw.calls, kb.raw.calls, { map: ONE_CM_PER_MB, errorTolerance: 50 }) + const map = mapFor(lib, ka, kb) + const c = compareKits(ka.raw.calls, kb.raw.calls, { map, errorTolerance: 50 }) const chromosomes = [...ka.raw.calls.keys()].filter((chr) => /^\d+$/.test(chr) && kb.raw!.calls.has(chr)).map((chr) => { const pos = ka.raw!.calls.get(chr)!.position return { chromosome: chr, - startCm: ONE_CM_PER_MB.toCm(chr, Number(pos[0] ?? 0)), - endCm: ONE_CM_PER_MB.toCm(chr, Number(pos[pos.length - 1] ?? 0)), + startCm: map.toCm(chr, Number(pos[0] ?? 0)), + endCm: map.toCm(chr, Number(pos[pos.length - 1] ?? 0)), segments: c.segments.filter((s) => s.chromosome === chr).map((s) => ({ startCm: s.startCm, endCm: s.endCm, cm: s.cm, markers: s.markers })), } }) diff --git a/apps/desktop/host/protocol.ts b/apps/desktop/host/protocol.ts index f683556..3113ab0 100644 --- a/apps/desktop/host/protocol.ts +++ b/apps/desktop/host/protocol.ts @@ -136,6 +136,8 @@ export type GedmatchStatus = { kits: { kit: string; name: string; hasRaw: boolean; gedmatchId: string | null; setting: 'opt-in' | 'opt-out' | 'research' | 'private' | null; minor: boolean; recordedAt: string | null; warnings: string[]; recommended: boolean }[] } +export type MapStatus = { installed: boolean; name: string; publisher: string; url: string; megabytes: number; madeBy: string; license: string; installedOn: string | null } + export type HostApi = { status: { params: Record; result: Status } chooseLibrary: { params: { path: string }; result: Status } @@ -188,5 +190,10 @@ export type HostApi = { /** Trust a developer build of the extension, by its ID. Recorded in the decisions log; `confirm` must be true. */ trustDeveloperExtension: { params: { id: string; confirm: boolean }; result: ExtensionView } untrustDeveloperExtension: { params: { id: string }; result: ExtensionView } + /** The GRCh37 genetic map: whether it's on this Mac, and where it comes from. */ + geneticMap: { params: Record; result: MapStatus } + /** Download it from its publisher, checked against a pinned checksum. `confirm` must be true. */ + downloadGeneticMap: { params: { confirm: boolean }; result: MapStatus } + removeGeneticMap: { params: Record; result: MapStatus } } export type HostMethod = keyof HostApi diff --git a/apps/desktop/src/screens/GeneticMap.tsx b/apps/desktop/src/screens/GeneticMap.tsx new file mode 100644 index 0000000..2a23313 --- /dev/null +++ b/apps/desktop/src/screens/GeneticMap.tsx @@ -0,0 +1,84 @@ +import { useEffect, useState } from 'react' +import type { MapStatus } from '../../host/protocol' +import { call } from '../api' + +/** + * The GRCh37 genetic map card (owner, 2026-11-11, N124 A). Names the source before anything is downloaded, + * downloads only after a yes, and can remove the map again. + */ +export function GeneticMapCard({ onChange }: { onChange?: () => void }) { + const [status, setStatus] = useState(null) + const [confirming, setConfirming] = useState(false) + const [busy, setBusy] = useState(false) + const [error, setError] = useState(null) + + useEffect(() => { + call('geneticMap').then(setStatus, (e: Error) => setError(e.message)) + }, []) + + const run = async (f: () => Promise) => { + setBusy(true) + setError(null) + try { + setStatus(await f()) + onChange?.() + } catch (e) { + setError((e as Error).message) + } finally { + setBusy(false) + setConfirming(false) + } + } + + if (!status) return error ?

{error}

: null + return ( +
+

+ Genetic map +

+ {status.installed ? ( + <> +

+ Using the {status.name} map, downloaded {status.installedOn ? `on ${status.installedOn} ` : ''}from {status.publisher}. Kits whose raw files are on + GRCh37 are measured with it. The made-up demo always uses the approximate rule, because its positions are invented. +

+ + + ) : ( + <> +

+ Comparisons use an approximate rule of 1 cM per million base pairs. A published genetic map measures segments more accurately. OneFamily doesn’t + include one, but it can download the usual GRCh37 map onto this Mac for you. +

+ {!confirming ? ( + + ) : ( +
+

+ This downloads about {status.megabytes} MB from {status.publisher}: +
+ {status.url} +

+

+ {status.madeBy} {status.license} The file is checked against a fixed checksum before it’s used, and nothing about you or your DNA is sent. +

+
+ + +
+
+ )} + + )} + {error &&

{error}

} +
+ ) +} diff --git a/apps/desktop/src/screens/Kits.tsx b/apps/desktop/src/screens/Kits.tsx index 971c7e5..1c12cfc 100644 --- a/apps/desktop/src/screens/Kits.tsx +++ b/apps/desktop/src/screens/Kits.tsx @@ -1,6 +1,7 @@ import { Eye, EyeOff } from 'lucide-react' import type { KitsResult } from '../../host/protocol' import { Facts, Icon, useNames } from '../ui' +import { GeneticMapCard } from './GeneticMap' const RAW_NAMES: Record = { ancestry: 'AncestryDNA layout', '23andme': '23andMe layout', myheritage: 'MyHeritage layout', ftdna: 'FamilyTreeDNA layout', livingdna: 'Living DNA layout' } @@ -68,11 +69,11 @@ 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. 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. + Measured from their raw DNA on this Mac, with {data.comparisons[0]!.map}. The approximate rule is good enough to see close 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/genetic-map.test.ts b/apps/desktop/test/genetic-map.test.ts new file mode 100644 index 0000000..43ce233 --- /dev/null +++ b/apps/desktop/test/genetic-map.test.ts @@ -0,0 +1,109 @@ +import { createHash } from 'node:crypto' +import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs' +import { tmpdir } from 'node:os' +import { join } from 'node:path' +import { crc32, deflateRawSync } from 'node:zlib' +import { afterEach, describe, expect, it } from 'vitest' +import { GRCH37_MAP, installMap, loadMap, MapError, mapStatus, readZip, removeMap } from '../host/genetic-map' +import { createHost } from '../host/handlers' + +// A made-up archive shaped like the real one: one PLINK file per chromosome, some stored and some deflated. +function zip(files: Record, deflate: (name: string) => boolean = () => false): Buffer { + const locals: Buffer[] = [] + const centrals: Buffer[] = [] + let offset = 0 + for (const [name, text] of Object.entries(files)) { + const raw = Buffer.from(text) + const method = deflate(name) ? 8 : 0 + const data = method === 8 ? deflateRawSync(raw) : raw + const n = Buffer.from(name) + const crc = crc32(raw) + const local = Buffer.alloc(30) + local.writeUInt32LE(0x04034b50, 0); local.writeUInt16LE(20, 4); local.writeUInt16LE(method, 8) + local.writeUInt32LE(crc, 14); local.writeUInt32LE(data.length, 18); local.writeUInt32LE(raw.length, 22); local.writeUInt16LE(n.length, 26) + const central = Buffer.alloc(46) + central.writeUInt32LE(0x02014b50, 0); central.writeUInt16LE(20, 4); central.writeUInt16LE(20, 6); central.writeUInt16LE(method, 10) + central.writeUInt32LE(crc, 16); central.writeUInt32LE(data.length, 20); central.writeUInt32LE(raw.length, 24); central.writeUInt16LE(n.length, 28) + central.writeUInt32LE(offset, 42) + locals.push(local, n, data) + centrals.push(central, n) + offset += 30 + n.length + data.length + } + const cd = Buffer.concat(centrals) + const end = Buffer.alloc(22) + end.writeUInt32LE(0x06054b50, 0); end.writeUInt16LE(centrals.length / 2, 8); end.writeUInt16LE(centrals.length / 2, 10) + end.writeUInt32LE(cd.length, 12); end.writeUInt32LE(offset, 16) + return Buffer.concat([...locals, cd, end]) +} + +const chroms = [...Array.from({ length: 22 }, (_, i) => String(i + 1)), 'X'] +const files = (skip?: string) => { + const f: Record = { 'README.txt': 'made up' } + for (const c of chroms) if (c !== skip) f[`plink.chr${c}.GRCh37.map`] = `${c}\t.\t0.0\t1000000\n${c}\t.\t2.0\t2000000\n${c}\t.\t10.0\t3000000\n` + f['plink.chrX_par1.GRCh37.map'] = 'X\t.\t0.0\t1\nX\t.\t1.0\t2\n' + return f +} +const expected = (b: Buffer) => ({ bytes: b.length, sha256: createHash('sha256').update(b).digest('hex') }) + +const dirs: string[] = [] +const temp = () => { const d = mkdtempSync(join(tmpdir(), 'of-map-')); dirs.push(d); return d } +afterEach(() => { for (const d of dirs.splice(0)) rmSync(d, { recursive: true, force: true }) }) + +describe('the GRCh37 genetic map (N124 A, K653)', () => { + it('reads stored and deflated zip entries', () => { + const z = zip({ a: 'stored text', b: 'deflated text '.repeat(50) }, (n) => n === 'b') + const out = readZip(z) + expect(out.get('a')!.toString()).toBe('stored text') + expect(out.get('b')!.toString()).toBe('deflated text '.repeat(50)) + }) + + it('installs a checked archive with a note naming its source, and converts positions with it', () => { + const dir = temp() + const z = zip(files(), (n) => n.includes('chr1.')) + installMap(dir, z, '2026-11-15', expected(z)) + const s = mapStatus(dir) + expect(s).toMatchObject({ installed: true, installedOn: '2026-11-15', url: GRCH37_MAP.url }) + const note = readFileSync(join(dir, 'genetic-maps', 'GRCh37', 'SOURCE.md'), 'utf8') + expect(note).toContain(GRCH37_MAP.url) + expect(note).toContain('No license is stated') + const map = loadMap(dir)! + expect(map.toCm('1', 1_500_000)).toBeCloseTo(1) + expect(map.toCm('X', 2_500_000)).toBeCloseTo(6) + removeMap(dir) + expect(mapStatus(dir).installed).toBe(false) + expect(loadMap(dir)).toBeNull() + }) + + it('refuses a download with the wrong size or checksum, or a missing chromosome, and writes nothing', () => { + const dir = temp() + const z = zip(files()) + expect(() => installMap(dir, z, '2026-11-15', { ...expected(z), bytes: z.length + 1 })).toThrow(/bytes/) + expect(() => installMap(dir, z, '2026-11-15', { ...expected(z), sha256: '0'.repeat(64) })).toThrow(MapError) + const short = zip(files('7')) + expect(() => installMap(dir, short, '2026-11-15', expected(short))).toThrow(/chromosome 7/) + expect(existsSync(join(dir, 'genetic-maps'))).toBe(false) + }) + + it('pins the real archive', () => { + expect(GRCH37_MAP.sha256).toMatch(/^[0-9a-f]{64}$/) + expect(GRCH37_MAP.url.startsWith('https://')).toBe(true) + }) +}) + +describe('the host downloads it only after a yes', () => { + it('refuses without confirm, installs with it, and the demo keeps the approximate rule', async () => { + const root = temp() + const z = zip(files()) + let calls = 0 + const h = createHost({ stateDir: join(root, 'state'), downloadMap: async () => { calls++; return z }, mapExpected: expected(z) }).handlers + await expect(h.downloadGeneticMap({ confirm: false })).rejects.toThrow(/yes/) + expect(calls).toBe(0) + expect((await h.downloadGeneticMap({ confirm: true })).installed).toBe(true) + expect(calls).toBe(1) + await h.chooseLibrary({ path: join(root, 'lib') }) + await h.openDemo({ seed: 1 }) + const { comparisons } = await h.kits({}) + expect(comparisons[0]!.map).toMatch(/approximate/) + expect((await h.removeGeneticMap({})).installed).toBe(false) + }) +}) diff --git a/docs/decisions.md b/docs/decisions.md index 3c9260c..e62a7fc 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -26,3 +26,4 @@ Dated decisions for this repo, newest last. The fuller design plan is kept priva - 2026-11-11 (owner, N126 B): anyone may partly rebuild the DNA of a relative who never tested, on real data too, once they've chosen to and the 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. Enforced by `rebuildFromDescendants`. - 2026-11-11 (owner, N131 A, B, A): no Chrome Web Store listing yet; only a developer build trusted on the app's Extension screen can connect. The extension's toolbar button turns privacy on and off, as built. The collecting cap stays at 100 pages a day, as built. - 2026-11-15 (Genealogy session, K338): OneFamily for Mac ships the official Node build inside the app, checked against a pinned SHA-256, instead of asking people to install Node. About 45 MB more in the download. See ADR 0007. +- 2026-11-15 (Genealogy session, K653, applying N124 A): the Kits screen offers the GRCh37 map from the Beagle genetic maps page at the University of Washington. It names the source, size and missing license before asking, downloads only after a yes, checks the archive against a pinned size and SHA-256, and keeps chromosomes 1 to 22 and X in the app's own folder with a note saying where they came from. It's used only when both raw files are on GRCh37; the demo keeps the approximate rule. diff --git a/docs/test-audit.md b/docs/test-audit.md index 28c47a6..f94035e 100644 --- a/docs/test-audit.md +++ b/docs/test-audit.md @@ -55,6 +55,7 @@ Kept by this repo's owning session (Genealogy), per `~/Code/CLAUDE.md`, "Test se - **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. +- **Genetic map download (K653):** 2026-11-15, `apps/desktop/test/genetic-map.test.ts` (5 tests): stored and deflated zip entries; install writes a note naming the source and converts positions; a wrong size, a wrong checksum or a missing chromosome writes nothing; the host refuses without a yes and calls the downloader only once after it; the demo keeps the approximate rule. The real archive was checked by hand once, not in CI, to keep CI off the network. The card hasn't been clicked in the built app. - **S8, the stability report between runs:** not built, since there's only one run so far. Filed as a task. - **S9, claims checked against the data:** theories aren't stored as data yet. Filed as a task. - **S10, the owner approves theory status changes:** no theory editing exists yet. It's part of S9's task. diff --git a/packages/core/src/genetic-map.ts b/packages/core/src/genetic-map.ts index 5a1eca4..49a1393 100644 --- a/packages/core/src/genetic-map.ts +++ b/packages/core/src/genetic-map.ts @@ -3,8 +3,9 @@ * format published maps commonly use ("chromosome id cM position" per line, whitespace-separated). Between * listed points it interpolates linearly; past the ends it extends at the nearest interval's rate. * - * OneFamily doesn't ship a map until its license is confirmed (see the repo's docs/decisions.md). - * Without one, comparisons use the approximate 1 cM per Mb rule and say so. + * OneFamily doesn't ship a map, because no license is stated for the usual one (see the repo's docs/decisions.md). + * The Mac app can download it onto the person's own Mac after a yes (N124 A). Without one, comparisons use the + * approximate 1 cM per Mb rule and say so. */ import type { GeneticMap } from './compare.js'