8000 test(golden): add v7 golden files written by 2.0.12 (#936) by adityamukho · Pull Request #952 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ Auto-migrates v7 → v8 on open (spec §9, with a backup meta page). v1–v6 are

## Test Coverage

**2213 tests** (2190 active, 23 ignored; unit + integration + example + doc). Browser-only inventory is separate: #925 adds eight wasm tests (103 main-thread / 136 dedicated-worker tests in total); see `docs/testing/925-browser-incoming-refs.md` for execution results. Engine answers once checked by the executor are frozen in `tests/answers/` (#551). The #924 Rust 1.99.1 dist binary is 1,250,568 bytes (+3,808 from the v3 base), below the 1,280,000-byte gate; [verification and acceptance mapping](docs/testing/924-incoming-refs.md).
**2213 tests** (2190 active, 23 ignored; unit + integration + example + doc). Browser-only inventory is separate: #925 adds eight wasm tests (103 main-thread / 136 dedicated-worker tests in total); see `docs/testing/925-browser-incoming-refs.md` for execution results. #936 adds one browser golden-migration test to each. Engine answers once checked by the executor are frozen in `tests/answers/` (#551). The #924 Rust 1.99.1 dist binary is 1,250,568 bytes (+3,808 from the v3 base), below the 1,280,000-byte gate; [verification and acceptance mapping](docs/testing/924-incoming-refs.md).
See `docs/TEST_COVERAGE.md` for the full per-file breakdown.

The #760 deterministic storage suite adds three native unit tests in a separate `--cfg minigraf_shuttle` build, outside the default count. Run only `graph::storage::deterministic::` with that cfg; ordinary unit tests do not enter its scheduler. `deterministic-schedules.yml` runs relevant v3 PRs on Linux/macOS/Windows plus Linux MSRV, and larger nightly/manual searches with replay artifacts. The identical main workflow activates the v3 schedule after both PRs merge. See `docs/testing/deterministic-schedules.md` for scope, controls and findings.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
members = ["."]
exclude = ["fuzz", "tests/golden/gen/v7", "tests/golden/gen/v8"]
exclude = ["fuzz", "tests/golden/gen/v7", "tests/golden/gen/v8", "tests/golden/gen/v7_2_0_12"]
resolver = "2"

[package]
Expand Down
2 changes: 2 additions & 0 deletions docs/TEST_COVERAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ These tests compare the database against an independent answer rather than a sin
- Seven v8 golden files: one checkpoint, seven copy-on-write checkpoints, a crash-left v2 WAL, an already-checkpointed v2 WAL, same-transaction multi-values, a v7 file migrated in place, and long values at the size limits.
- Every golden file is first opened read-only: its `tx_count` and queries are checked, and neither the file nor its WAL changes (#429).
- The `stale_wal` fixtures must have no WAL after a checkpoint (#457).
- #936 adds five v7 fixtures from the published 2.0.12 writer: basic, pending WAL, restored stale WAL, multi-values, and an append after torn-tail recovery. Every corpus phase now calls `verify()`; the migrated copy is also reopened read-only. Native test-count delta: 0 (the existing two tests cover all manifests).
- **Plan independence** (`tests/plan_independence_test.rs`, 16 tests, `test-hooks` only; #596)
- A matrix of queries gives the same bag of rows with clause reordering on and off (`minigraf::__reorder`), and with the engine's negation bodies and `or` branches chosen, forced hashed and forced correlated (`minigraf::__subplans`, #546).
- Run in memory and on file after a checkpoint and a reopen, through `execute` and a cursor.
Expand Down Expand Up @@ -826,6 +827,7 @@ These are not `#[test]`s; run them with `cargo kani` or `.github/workflows/kani.

None of these are counted in the summary. The wasm32 targets run in CI (`.github/workflows/wasm.yml`).

- **2.0.12 golden migration** (#936; `src/browser/golden_tests.rs`, one browser test): seeds the basic and multi-value v7 images into IndexedDB, checks manifest rows and integrity after migration and reopen, and confirms persisted v8 meta pages. Adds one test to each of the main-thread and worker inventories.
- **IndexedDB flush recovery** (#894; `src/browser/flush_tests.rs`, 13 new browser tests, plus the updated closed-connection case in `tx_tests.rs`): atomic puts/deletes after queue-time throws; abort-only settlement with a deadline; multiple request errors without callback exceptions; failed-handle refusal without counter/fact changes; execute/commit/checkpoint/smaller-import failures; missing dirty-page preparation errors; ordered overlaps and checkpoint boundaries; close/reopen with queued work; migration failure and intact-page-map recovery. Reopened exports pass the shared native image integrity walk, allowing absent free pages. Healthy operation retains no settled flush history. See [PR 1 evidence and scope](testing/894-idb-flush-recovery.md). Native test inventory is unchanged.

- **OPFS worker mode** (#441; `src/browser/opfs_tests.rs`, 34 worker tests plus one main-thread test):
Expand Down
98 changes: 98 additions & 0 deletions src/browser/golden_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
use super::{BrowserDb, IndexedDbBackend};
use crate::storage::PAGE_SIZE;
use serde_json::Value as Json;
use wasm_bindgen_test::*;

async fn check_manifest(db: &BrowserDb, manifest: &Json) {
assert_eq!(
db.inner.borrow().fact_storage.current_tx_count(),
manifest["tx_count"].as_u64().unwrap()
);
assert!(db.inner.borrow().pfs.verify().unwrap().problems.is_empty());
for query in manifest["queries"].as_array().unwrap() {
let result = db
.execute(query["query"].as_str().unwrap().to_owned())
.await
.unwrap();
let result: Json = serde_json::from_str(&result).unwrap();
let mut got: Vec<String> = result["results"]
.as_array()
.unwrap()
.iter()
.map(Json::to_string)
.collect();
let mut expected: Vec<String> = query["rows"]
.as_array()
.unwrap()
.iter()
.map(|row| {
let cells: Vec<Json> = row
.as_array()
.unwrap()
.iter()
.map(|cell| {
let text = cell.as_str().unwrap();
if text.starts_with(':') {
Json::String(text.to_owned())
} else if text == "nil" {
Json::Null
} else {
serde_json::from_str(text).unwrap()
}
})
.collect();
Json::Array(cells).to_string()
})
.collect();
got.sort();
expected.sort();
assert_eq!(got, expected, "{}", query["name"].as_str().unwrap());
}
}

#[wasm_bindgen_test]
async fn golden_v7_2_0_12_indexeddb_migration_reopen() {
let fixtures: &[(&[u8], &str)] = &[
(
include_bytes!("../../tests/golden/v7_2_0_12_basic.graph"),
include_str!("../../tests/golden/v7_2_0_12_basic.json"),
),
(
include_bytes!("../../tests/golden/v7_2_0_12_multivalue.graph"),
include_str!("../../tests/golden/v7_2_0_12_multivalue.json"),
),
];
for (bytes, manifest) in fixtures {
let manifest: Json = serde_json::from_str(manifest).unwrap();
let name = format!(
"golden-936-{}-{}-{}",
manifest["file"].as_str().unwrap(),
js_sys::Date::now(),
js_sys::Math::random()
);
let idb = IndexedDbBackend::open(&name).await.unwrap();
let pages = bytes
.chunks(PAGE_SIZE)
.enumerate()
.map(|(i, page)| (i as u64, page.to_vec()))
.collect();
idb.write_pages(pages, vec![]).await.unwrap();
let seeded = idb.load_all_pages().await.unwrap();
assert_eq!(&seeded[&0][4..8], &7u32.to_le_bytes());

let db = BrowserDb::open(&name).await.unwrap();
check_manifest(&db, &manifest).await;
db.close().unwrap();
let migrated = idb.load_all_pages().await.unwrap();
assert!([0, 1].iter().any(|slot| {
migrated.get(slot).is_some_and(|page| {
&page[..4] == b"MGRF" && page[4..8] == 8u32.to_le_bytes() && &page[8..12] == b"META"
})
}));
idb.db.close();

let db = BrowserDb::open(&name).await.unwrap();
check_manifest(&db, &manifest).await;
db.close().unwrap();
}
}
2 changes: 2 additions & 0 deletions src/browser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub mod buffer;
/// IndexedDB atomicity, settlement and ordered flush regressions (#894).
#[cfg(test)]
mod flush_tests;
#[cfg(test)]
mod golden_tests;
/// Incoming-reference lookup parity and JS boundary tests (#925).
#[cfg(test)]
mod incoming_tests;
Expand Down
63 changes: 58 additions & 5 deletions tests/golden/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ the results it must give (#391). `tests/golden_corpus_test.rs` opens a copy of e
file with the current build and checks its manifest:

1. The committed files still match the CRC32 values in the manifest.
2. After open, `tx_count` and every query result match the manifest.
2. After read-only and read-write open, `tx_count` and every query result match
the manifest, and `verify()` reports no problems. The read-only open leaves
both the database and WAL bytes unchanged.
3. After a checkpoint and a reopen, they still match.
4. One more write moves `tx_count` past the file's value and survives a reopen.

On v3 and later, a v7 file must also have a v8 meta page after its first open
On v3 and later, a v7 file must also have a v8 meta page after its first read-write open
(it is migrated in place), give the same results when the migrated copy is
reopened, and lose its WAL at the checkpoint.
reopened read-write and read-only, and lose its WAL at the checkpoint. Integrity
is checked at every open and after the additional write. `verify()` checks
committed pages; queries check the replayed WAL facts.

Manifests for a newer format than the reader supports are skipped.

Expand Down Expand Up @@ -63,6 +67,11 @@ entity ids, because ids are not a stable output.
| `v7_pending_wal` | 2.0.3 | Shared dataset checkpointed, then two transactions held only in a v1 WAL (the session ended without running destructors, as a crash would) |
| `v7_stale_wal` | 2.0.3 | Same as `v7_pending_wal`, but the session closed normally: the facts are in the file, and the WAL next to it holds only entries already checkpointed (#447 shape) |
| `v7_multivalue` | 2.0.3 | Same-transaction multi-values and a batched retract (#371). v2.x reads these wrong |
| `v7_2_0_12_basic` | 2.0.12 | Scalars, a reference, Unicode, a valid-time window, an age retraction and replacement; three transactions, one checkpoint |
| `v7_2_0_12_pending_wal` | 2.0.12 | Basic dataset plus a name and a retraction in an uncheckpointed v1 WAL |
| `v7_2_0_12_stale_wal` | 2.0.12 | Same facts as pending WAL, checkpointed, with the saved WAL restored beside the database |
| `v7_2_0_12_multivalue` | 2.0.12 | Same-transaction multi-values and a batched retract (#371) |
| `v7_2_0_12_recovered_append` | 2.0.12 | An intact WAL entry, a torn final entry, then recovery by reopen and a new append (#513); both surviving entries remain in the WAL |
| `v8_basic` | `v3` at 23aa57c | Shared dataset, one checkpoint |
| `v8_multi_checkpoint` | `v3` at 23aa57c | As `v7_multi_checkpoint`: seven copy-on-write checkpoints, alternating meta slots, reused free pages |
| `v8_pending_wal` | `v3` at 23aa57c | As `v7_pending_wal`, with a v2 WAL (records its base generation) |
Expand All @@ -74,8 +83,8 @@ entity ids, because ids are not a stable output.
## Generators

`gen/v7/` is a standalone crate pinned to `minigraf = "=2.0.3"` from crates.io,
with a committed `Cargo.lock`. It records how each v7 file was made. It is not part
of the workspace and is never re-run to replace a file: it refuses to write over an
with a committed `Cargo.lock`. It records how the original six v7 files were made.
It is not part of the workspace and is never re-run to replace a file: it refuses to write over an
existing one.

`gen/v8/` is the same for the v8 files, pinned by git rev to the `v3` branch at
Expand All @@ -87,3 +96,47 @@ index on open.
cd tests/golden/gen/v7 && cargo run -- <empty-dir>
cd tests/golden/gen/v8 && cargo run -- <empty-dir>
```

`gen/v7_2_0_12/` is a separate standalone crate pinned to
`minigraf = "=2.0.12"` from crates.io, with its own committed `Cargo.lock`. It
refuses to replace existing files. Run it only into an empty directory:

```sh
cargo run --locked --manifest-path tests/golden/gen/v7_2_0_12/Cargo.toml -- <empty-dir>
```

The expected rows are derived from its transaction statements. Its printed CRCs
identify the generated bytes; transaction timestamps prevent byte-for-byte
reproduction. The 2.0.3 generator and its files remain unchanged. These fixtures
add release and WAL coverage to the checkpointed 2.0.11 fixtures in
[`docs/benchmarks/838-migration`](../../docs/benchmarks/838-migration/README.md).
2.0.12 is the latest v7 writer at the time of this addition, not necessarily the
last v2 release.

In 2.0.12, `wal_checkpoint_threshold(usize::MAX)` suppresses close-time as well as
automatic checkpoints (#476). The pending-WAL recipe therefore closes normally
and retains its WAL. The stale-WAL recipe saves those bytes, checkpoints, closes,
and restores them, modelling the state between saving the facts and deleting the
WAL (#457).

For #513, the published crate has no public failure injection: `tear_next_append`
is `pub(crate)` and gated by `cfg(test)` in `src/wal.rs`. The recipe checkpoints
the basic dataset, writes `"before"`, records the WAL length, writes `"torn"`, and
closes without checkpointing. It truncates the final entry to nine bytes and
syncs the file. Reopening with 2.0.12 must remove that tail, retain `"before"`, and
restore `tx_count` to 4. Only then does it append `"after"` at transaction 5. A
second reopen checks both surviving values and the absence of `"torn"`. This
models the disk state of a failed append; it does not inject an append error or
test WAL-007 on a live handle. Recovery is explicit because a real failed append
poisons later writes until checkpoint or reopen.

`src/browser/golden_tests.rs` seeds IndexedDB with the 2.0.12 basic and multivalue
page images, opens them through `BrowserDb`, checks every manifest query and
integrity, checks that v8 meta pages reached IndexedDB, then closes and reopens
and repeats the manifest and integrity checks. Browser storage has no native WAL
sidecar, so the three WAL fixtures run in the native corpus only. Run this browser
test with the repository's wasm-bindgen setup, filtered to the golden test:

```sh
wasm-pack test --headless --firefox --features browser --lib golden_v7_2_0_12_indexeddb_migration_reopen
```
Loading
Loading
0