@@ -8,19 +8,22 @@ import {
88 type SnapshotDatabaseIdentity ,
99 type SnapshotSummary ,
1010} from "../../src/snapshot/snapshot-provider.js" ;
11- import type { ReliabilityReport , ReliabilityStateProof } from "./sqlite-reliability-contract.js" ;
11+ import {
12+ assertSameCompactionPayload ,
13+ type CompactionPayloadProof ,
14+ type ReliabilityReport ,
15+ type ReliabilityStateProof ,
16+ } from "./sqlite-reliability-contract.js" ;
1217
1318type RepositoryCrashPoint = "after-commit" | "before-pending" | "pending" ;
1419type RepositoryExit =
1520 ReliabilityReport [ "maintenanceProof" ] [ "repositoryInterruption" ] [ "beforePending" ] [ "exit" ] ;
16- type RepositoryPayload =
17- ReliabilityReport [ "maintenanceProof" ] [ "repositoryInterruption" ] [ "beforePending" ] [ "payload" ] ;
1821type CrashPointResult = {
1922 crashSnapshotVerifiedAfterCrash : boolean ;
2023 crashSnapshotVisibleAfterCrash : boolean ;
2124 exit : RepositoryExit ;
2225 incompleteEntries : number ;
23- payload : RepositoryPayload ;
26+ payload : CompactionPayloadProof ;
2427 stagingEntries : number ;
2528 state : ReliabilityStateProof ;
2629 visibleSnapshotsAfterCrash : number ;
@@ -47,22 +50,6 @@ function assertSameState(
4750 }
4851}
4952
50- function assertSamePayload (
51- actual : RepositoryPayload ,
52- expected : RepositoryPayload ,
53- label : string ,
54- ) : void {
55- if (
56- actual . bytes !== expected . bytes ||
57- actual . idSum !== expected . idSum ||
58- actual . rows !== expected . rows
59- ) {
60- throw new Error (
61- `${ label } changed compaction payload: expected rows=${ expected . rows } bytes=${ expected . bytes } idSum=${ expected . idSum } , got rows=${ actual . rows } bytes=${ actual . bytes } idSum=${ actual . idSum } ` ,
62- ) ;
63- }
64- }
65-
6653function formatWorkerStderr ( stderr : string ) : string {
6754 const text = stderr . trim ( ) ;
6855 return text ? ` stderr=${ JSON . stringify ( text ) } ` : "" ;
@@ -158,17 +145,21 @@ function assertForcedExit(exit: RepositoryExit): void {
158145}
159146
160147async function verifySnapshot ( params : {
161- expectedPayload : RepositoryPayload ;
148+ expectedPayload : CompactionPayloadProof ;
162149 expectedState : ReliabilityStateProof ;
163150 provider : ReturnType < typeof createLocalSqliteSnapshotProvider > ;
164151 snapshot : SnapshotSummary ;
165- verifyPayload : ( databasePath : string ) => RepositoryPayload ;
152+ verifyPayload : ( databasePath : string ) => CompactionPayloadProof ;
166153 verifyState : ( databasePath : string ) => ReliabilityStateProof ;
167154} ) : Promise < void > {
168155 await params . provider . verify ( params . snapshot . ref ) ;
169156 const artifactPath = path . join ( params . snapshot . ref . path , SNAPSHOT_SQLITE_FILENAME ) ;
170157 assertSameState ( params . verifyState ( artifactPath ) , params . expectedState , artifactPath ) ;
171- assertSamePayload ( params . verifyPayload ( artifactPath ) , params . expectedPayload , artifactPath ) ;
158+ assertSameCompactionPayload (
159+ params . verifyPayload ( artifactPath ) ,
160+ params . expectedPayload ,
161+ artifactPath ,
162+ ) ;
172163}
173164
174165function listRepositoryEntries ( repositoryPath : string ) : string [ ] {
@@ -177,14 +168,14 @@ function listRepositoryEntries(repositoryPath: string): string[] {
177168
178169async function runCrashPoint ( params : {
179170 crashPoint : RepositoryCrashPoint ;
180- expectedPayload : RepositoryPayload ;
171+ expectedPayload : CompactionPayloadProof ;
181172 expectedState : ReliabilityStateProof ;
182173 identity : SnapshotDatabaseIdentity ;
183174 provider : ReturnType < typeof createLocalSqliteSnapshotProvider > ;
184175 repositoryPath : string ;
185176 sourcePath : string ;
186177 validationRootPath : string ;
187- verifyPayload : ( databasePath : string ) => RepositoryPayload ;
178+ verifyPayload : ( databasePath : string ) => CompactionPayloadProof ;
188179 verifyState : ( databasePath : string ) => ReliabilityStateProof ;
189180} ) : Promise < CrashPointResult > {
190181 const visibleBefore = await params . provider . list ( ) ;
@@ -248,7 +239,11 @@ async function runCrashPoint(params: {
248239 const sourceState = params . verifyState ( params . sourcePath ) ;
249240 assertSameState ( sourceState , params . expectedState , `${ params . crashPoint } source` ) ;
250241 const sourcePayload = params . verifyPayload ( params . sourcePath ) ;
251- assertSamePayload ( sourcePayload , params . expectedPayload , `${ params . crashPoint } source` ) ;
242+ assertSameCompactionPayload (
243+ sourcePayload ,
244+ params . expectedPayload ,
245+ `${ params . crashPoint } source` ,
246+ ) ;
252247
253248 const crashSnapshotNames = new Set (
254249 crashSnapshots . map ( ( snapshot ) => path . basename ( snapshot . ref . path ) ) ,
@@ -302,13 +297,13 @@ async function runCrashPoint(params: {
302297}
303298
304299export async function runRepositoryInterruptionProof ( params : {
305- expectedPayload : RepositoryPayload ;
300+ expectedPayload : CompactionPayloadProof ;
306301 expectedState : ReliabilityStateProof ;
307302 identity : SnapshotDatabaseIdentity ;
308303 repositoryPath : string ;
309304 sourcePath : string ;
310305 validationRootPath : string ;
311- verifyPayload : ( databasePath : string ) => RepositoryPayload ;
306+ verifyPayload : ( databasePath : string ) => CompactionPayloadProof ;
312307 verifyState : ( databasePath : string ) => ReliabilityStateProof ;
313308} ) : Promise < ReliabilityReport [ "maintenanceProof" ] [ "repositoryInterruption" ] > {
314309 const provider = createLocalSqliteSnapshotProvider ( {
0 commit comments