Skip to content

test(session): round-trip the window snapshot instead of grepping it - #568

Merged
PathGao merged 1 commit into
masterfrom
test/window-state
Aug 10, 2026
Merged

test(session): round-trip the window snapshot instead of grepping it#568
PathGao merged 1 commit into
masterfrom
test/window-state

Conversation

@PathGao

@PathGao PathGao commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

What this is

Fourth slice (after #564, #565, #567). windowStateRestore.test.ts only; no source changes.

Mechanism

The two assertions covering serializeState / restoreState were a blocklist of spellings their source must not contain:

assert.doesNotMatch(fn, /\.\.\.t/);
assert.doesNotMatch(fn, /rawContent/);
assert.doesNotMatch(fn, /originalContent/);
assert.doesNotMatch(fn, /isDirty/);
assert.doesNotMatch(fn, /history/);

Five names is not the property they stand for. The property is: the file written on every window close contains layout and no document text. A field spelled anything else — buffer, text, t.content — satisfies every line above and ships a window-layout file that is also a copy of every open document, including one the user never saved anywhere.

tabManager is an exported singleton and both functions are ordinary methods, so the property can be asserted rather than approximated. The snapshot is now built from a tab holding unsaved text, and the test looks for that text in the JSON. It then compares the persisted entry's key set against the ten window-state fields, so adding a field is a deliberate act that fails here first.

Five behaviour tests replace the two, covering what a blocklist cannot see:

  • the round trip preserves per-tab layout (isSplit, splitRatio, scrollPercentage)
  • restored tabs arrive clean and empty, whatever was in the buffer when the snapshot was taken
  • an activeTabId naming an entry that was dropped on the way in still lands on a real tab — otherwise restore produces a window with files in the tab bar and nothing open
  • HOME and untitled entries from older builds are rejected on the way in as well as on the way out

Scope

  • The other seven assertions in the file are unchanged. They cover windowSession.restore, canCloseTab, and an ordering inside MarkdownViewer.svelte's close handler — wiring in a Svelte component this runner cannot import. The file already grouped them separately.
  • No shared harness. The rune/__TAURI_INTERNALS__ stubs are the same eight lines the other store-driving tests carry.

Tests

Restoring the defect the blocklist was written against — .map((t) => ({ ...t, … })) with the hasRealFilePath filter removed — turns the first two red and leaves the other ten green. Ran it, then reverted.

Verification

npm run check   # 674 files, 0 errors
npm test        # 952 pass, 0 fail

Not verified: what the OS actually writes and reads back. The snapshot is exercised as a string in memory; the file round trip through Rust is covered by sessionRestoreResilience.

🤖 Generated with Claude Code

The two assertions covering `serializeState` and `restoreState` were a
list of things their source must not contain — `doesNotMatch(/\.\.\.t/)`,
`/rawContent/`, `/originalContent/`, `/isDirty/`, `/history/` — plus
`match(/isDirty: false/)` on the way back. A blocklist of five spellings
is not the property it stands for, which is: the file written on every
close must contain window layout and no document text.

Both functions are methods on an exported singleton, so the property can
be asserted directly. The snapshot is now built from a tab holding
unsaved text, and the test looks for that text in the JSON, then compares
the key set of the persisted entry against the ten window-state fields —
so a field added by hand fails here rather than shipping a layout file
that is also a copy of every open document.

Five behaviour tests replace the two, covering what the blocklist could
not see: the round trip preserves per-tab layout, restored tabs arrive
clean and empty, an activeTabId pointing at a dropped entry still lands
on a real tab rather than none, and 'HOME'/untitled entries from older
builds are rejected on the way in as well as on the way out.

Replacing the field list with `...t` — the exact defect the blocklist was
written against — turns the first two red.

The seven assertions about windowSession, documentSession and
MarkdownViewer are unchanged: those are wiring inside a Svelte component
or an ordering between two calls, and the file already groups them apart.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@PathGao
PathGao merged commit efd34d1 into master Aug 10, 2026
4 checks passed
@PathGao
PathGao deleted the test/window-state branch August 10, 2026 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant