fix: preserve persisted option contracts #2259
Mergedjp-knj(GitHub profile, opens in a new tab)merged 6 commits into
main fromrefs/pull/2259/headmerged by KyleAMathews jp-knj(GitHub profile, opens in a new tab) changed the title
KyleAMathews changed the title
- packages/db-sqlite-persistence-core/tests/persisted-options-type-oracle.ts lines 545 to 560OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +540,21 @@540+ const property = fc.asyncProperty(shapeArbitrary, (shape) => {541+ reach.beginHistory()542+ for (const state of check(shape)) reach.reach(state)543+ return Promise.resolve()544+ })545+ const parameters =546+ campaign === `fixed`547+ ? { numRuns: oracleRuns(12), seed: 2259 }548+ : oraclePropertyOptions(12, propertyName)549+ await fc.assert(property, parameters)550+ // Replays use the same check but do not inflate generated reach. An551+ // explicitly requested seed/path goes directly to its generated history.552+ if (campaign !== `replay`) {553+ for (const shape of replayShapes) check(shape)554+ }555+ reach.assertReached()556+ console.info(557+ `${propertyName} ${campaign} reach`,558+ Object.fromEntries(reach.counts()),559+ )560+ }, 120_000)
- docs/contributing/oracle-reviews/pr-2259-persisted-option-types.md line 303OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +283,21 @@283+### Law, experiment, inference, and enforcement284+285+| Law and authority | Experiment and inference | Final enforcement and limits |286+| --- | --- | --- |287+| Public persistence utilities retain required/optional signatures, alongside caller utilities. Authority: PersistedCollectionUtils API and SQLite guide. | Removing the local result intersection passes the reviewed full campaign. The expanded comparison rejects TS2344 at LocalCapabilities. | Independent signatures observe acceptMutations, optional getLeadershipState and optional forceReloadSubset. PendingMutation/LoadSubsetOptions are trusted domain carriers, not expected-result helpers. |288+| Documented persistence options and contextual callbacks remain usable across schema/sync configurations. Authority: SQLite guide and public SyncConfig/option contracts. | Old grammar omits those options and uses no-argument sync functions. Widening schemaVersion, initialRender strategy, syncMode or contextual sync input now rejects TS2344. | Twelve extra configurations per shape cross schema and sync modes with eager/on-demand/network-first. Network-first is eager. Generated schemaVersion is 1–100 and timeout is 0–10000. This checks types, not runtime option validation. |289+| Query composition preserves its documented closed capabilities. Authority: QueryCollectionUtils public reference and the guide's adapter composition. | isLoading:any survives the reviewed full browser campaign. The independent model rejects it, widened refetch options, and an extra optional adapter capability. | Generated row/key write signatures plus exact state fields and refetch parameters. Non-any Promise-array envelope is independent; supplemental before/after equality preserves the full return payload. No independent QueryObserverResult payload semantics are claimed. |290+| A fresh sync:undefined argument must fail for sync admission, rather than collateral corruption. | Undefined-sync admission alone already failed the old directive. Adding unrelated getKey:42 to the negative expressions masks it and passes the old full campaign. New paired observations reject that compound corruption. | Unsuppressed TS2769 must point at the exact fresh sync property. The legal neighbor changes only sync and must compile. Every other diagnostic remains fatal. Structural extra properties carried through variables have different TypeScript freshness semantics and are not this rejection claim. |291+| Run budget, receiving configuration and diagnostic fidelity must remain effective. | Multiplier10 originally registers 120 runs but 120000ms. Revised registration gives 1200000ms. Source-only TS2322 and declaration-only TS4094 controls reject. | Receiver tsconfig, one compiler per receiver across campaigns, dependency caching, all original diagnostic classes, and event-loop yields between generated histories. No generated-file-only diagnostic filtering. |292+293+### Lossless finding ledger294+295+| ID | Supplied claim | Technical verdict / evidence | PR action | Durable value |296+| --- | --- | --- | --- | --- |297+| E1 | Local-added utilities are unchecked; removing their result intersection survives. | Confirmed by full reviewed-campaign survivor and new TS2344 rejection. | fixed-now: independent LocalCapabilities comparison. | Primary owner and local-utils recipe. |298+| E2 | Deleted schemaVersion/markReady examples lost coverage; initialRender/syncMode absent. | Confirmed grammar omissions. No new runtime defect claimed. | fixed-now: generated legal options, exact declared option law, contextual readiness signature and reaches. | Primary grammar; four option/callback mutants. |299+| E3 | Unused schema generic silently drops a schema; using never in inputs fixes it. | Refuted as stated. Eighteen compiler probes show current and proposed inputs both accept no-value phantom generic, reject an actual schema value (TS2769), and retain correct schema-input composition. Suggested change has no effect. | refuted: no production edit. | Two phantom-generic paths preserve useful normalization coverage. |300+| E4 | Whole-program work repeats; timeout ignores multiplier; check only generated file and share compiler. | Timeout confirmed. Repeated dependency checking is avoidable. Generated-only diagnostics would hide source errors. | fixed-now: semantic builder shared across campaigns, scaled timeout, retained source/declaration diagnostics. | Deterministic affected-file telemetry and budget/source controls. |301+| E5 | Fixed refetch/nonexistent-method examples violate law-only policy. | Confirmed standalone concrete expressions in Query driver. | fixed-now: reusable closed capability model replaces them. | Model parameterized by generated rows/keys, not fixed call examples. |302+| E6 | Expected Query utils derive from production; shared erasure can pass. | Independent judgment gap confirmed by isLoading:any survivor. Whole-namespace any was overstated: old negative writes already detect some erasure. | fixed-now: independent model plus supplemental transparency relation. | State, namespace and refetch corruption controls. |303+| E7 | Named campaigns omit runners; tests can only get12 runs. | Registration omission confirmed. Hardcoded12 claim refuted: multiplier3 helper experiment executes36 fixed and36 random checks; normal package test globs already include runners. | fixed-now: package/root test:oracles registration. | Distinguish selection, count, reach and completion. |scripts/calibrate-persisted-option-types.mjs lines 17 to 19OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +1,19 @@1+/** Run compiler-host mutants without changing production files on disk. */2+import { execFileSync, spawnSync } from 'node:child_process'3+import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'4+import { resolve } from 'node:path'5+6+const [mutation = `none`, ownerRef] = process.argv.slice(2)7+const root = process.cwd()8+const packageRoot = resolve(root, `packages/db-sqlite-persistence-core`)9+const ownerPath = `packages/db-sqlite-persistence-core/tests/persisted-options-type-oracle.ts`10+let source = ownerRef11+ ? execFileSync(`git`, [`show`, `${ownerRef}:${ownerPath}`], {12+ encoding: `utf8`,13+ })14+ : readFileSync(ownerPath, `utf8`)15+const mutations = {16+ none: ``,17+ parent: `if (name === resolve(packageRoot, 'src/persisted.ts')) {18+ source = ts.createSourceFile(name, ${JSON.stringify(execFileSync(`git`, [`show`, `d2935d0fcac164163adc231c6a796b8a4c234d9b:packages/db-sqlite-persistence-core/src/persisted.ts`], { encoding: `utf8` }))}, languageVersion, true);19+ }`,scripts/calibrate-persisted-option-types.mjs lines 203 to 211Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +82,21 @@82+ ),83+ 'blanket-never': (text) =>84+ text.replace(85+ /(\): Persisted(?:Sync|LocalOnly)OptionsResult<\n InferSchemaOutput<TSchema>,\n TKey,\n )TSchema,/g,86+ `$1never,`,87+ ),88+ 'contextual-key': (text) =>89+ text.replaceAll(90+ `schema: TSchema\n },`,91+ `schema: TSchema\n getKey: (row: any) => TKey\n },`,92+ ),93+})) {94+ const original = readFileSync(95+ resolve(packageRoot, `src/persisted.ts`),96+ `utf8`,97+ )98+ const altered = transform(original)99+ if (original === altered) throw new Error(`Missing mutation target: ${name}`)100+ mutations[name] =101+ `if (name === resolve(packageRoot, 'src/persisted.ts')) { source = ts.createSourceFile(name, ${JSON.stringify(altered)}, languageVersion, true); }`102+}scripts/calibrate-persisted-option-types.mjs lines 125 to 130OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +110,21 @@110+ .replace(111+ `return this._state.getWithVirtualProps(key)`,112+ `return this._state.getWithVirtualProps(key)!`,113+ ),114+ 'extra-read-field': (text) =>115+ text116+ .replace(117+ `public get(key: TKey): WithVirtualProps<TOutput, TKey> | undefined {`,118+ `public get(key: TKey): (WithVirtualProps<TOutput, TKey> & { leaked: boolean }) | undefined {`,119+ )120+ .replace(121+ `return this._state.getWithVirtualProps(key)`,122+ `return this._state.getWithVirtualProps(key) as (WithVirtualProps<TOutput, TKey> & { leaked: boolean }) | undefined`,123+ ),124+})) {125+ const original = readFileSync(126+ resolve(root, `packages/db/src/collection/index.ts`),127+ `utf8`,128+ )129+ mutations[name] =130+ `if (name.endsWith('/db/src/collection/index.ts')) { source = ts.createSourceFile(name, ${JSON.stringify(transform(original))}, languageVersion, true); }`
KyleAMathews changed the title
- @@ -0,0 +535,21 @@535+**Weight and limits:** The production bundle grows 64 gzip bytes and 29536+ brotli bytes against the merge-base on fetched origin/main. Reusing the537+ existing utility object and inlining its acceptance callback avoids a second538+ name registry and helper. The new rejection branch accounts for the growth.539+ Type evidence remains source-only on TS 5.9.3. Runtime evidence stops at540+ wrapper admission and does not establish database I/O, schema parsing,541+ Collection mutation behavior, native hosts, or published package resolution.542+543+From each receiving package, the normal persisted-options.test.ts command runs544+both type and admission campaigns. To select admission alone, add545+`-t 'reserved local utility'`. Direct runtime replay uses seed 2259, path546+`0:0:0`, and property `persisted-options.utilities.core` or `.browser`.547+548+The following repository-root commands use only versioned inputs:549+550+```sh551+# Old grammar accepts the readonly-stripping getter.552+TANSTACK_DB_ORACLE_PATH=0 node scripts/calibrate-persisted-option-types.mjs readonly-row 39065e399553+554+# Current grammar rejects these controls. Use the browser receiver for readonly-row too.555+TANSTACK_DB_ORACLE_PATH=0:0:0:0:0:0:0:0:0:0:0:0:0 node scripts/calibrate-persisted-option-types.mjs readonly-row
KyleAMathews merged this45c3329
KyleAMathews closed this
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: 6826665af042e1562111a15c414118cde6d423e9
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 12 packages
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR