tests/eject/persist-written: count the worker's own snapshot of a visit

The persist worker snapshots about a second after a save (k_fs_saves).
When the probe's exit reaches the page later than that (a loaded host),
that snapshot stores the probe's file and the page's last one has nothing
left to store: "stored 0 file(s)" for a visit that wrote one. The page now
reports what every snapshot of the visit stored (app.js state
persistedWrote), the worker's own included. With the last snapshot held
back 3 s, the old check fails visits 1 and 2 as the loaded gate did; this
one passes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_c8c04c00da9a4525ab21b0b9f146c598
This commit is contained in:
velzieandClaude Opus 5.5 committed 2026-10-25 13:10:54 -04:00
1 parent eda608505f
commit 687d1f9def
2 files changed
+8 -2

No files matched your search

+5 -1
View File
@@ -5,7 +5,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>persist-written</title>
<!-- tests/eject/persist-written.sh: /save kept in IndexedDB; ?visit=N is the
probe's argument. After the probe exits the page takes a snapshot. -->
probe's argument. After the probe exits the page takes a snapshot; the
status names what every snapshot of the visit stored. -->
<style>html, body { margin: 0; background: #0b0b0d; color: #ddd; font: 14px/1.4 system-ui, sans-serif; }</style>
</head>
<body>
@@ -36,6 +37,9 @@ try {
st.textContent = 'running';
const code = await app.exited;
const r = await globalThis.__ntPersist?.();
// What the visit stored: the worker's own snapshot soon after the probe's
// save may already have stored it, leaving this last one nothing to do.
if (r) r.wrote = app.state.persistedWrote ?? r.wrote;
st.textContent = `exited (${code}) synced ${JSON.stringify(r)}`;
} catch (e) {
st.textContent = 'failed: ' + (e?.message ?? e);
+3 -1
View File
@@ -697,7 +697,9 @@ async function begin(opts, base, at, state, meter) {
if (keep) {
const p = persist(keep.db, keep.dir, await globalKernel(), {
every: Number(sw.persistms || 30000),
onSync: (m) => { state.persisted = m; },
// `persistedWrote`: the files every snapshot of this visit stored,
// the ones it took of its own after a save included.
onSync: (m) => { state.persisted = m; state.persistedWrote = (state.persistedWrote ?? 0) + (m.wrote ?? 0); },
});
globalThis.__ntPersist = () => p?.sync();
}