test(ui): the timeline and the preview, against generated fixtures

Two more IPC fixtures, both generated from the real Rust types rather than
hand-written.

`snapshot_list.json` carries one of each trigger, with the `Rollback` entry
*restoring* the `Plan` entry above it. That arrangement is the whole reason the
timeline labels anything: a restore snapshots the current state before restoring,
so one rollback moves `latest` twice, and two adjacent entries a minute apart are
otherwise indistinguishable — while one is the state the user wants back and the
other is the state they are leaving. A fixture with a single trigger could not
have proved the labels work.

`rollback_preview.json` has all three sections non-empty, including two
`unrestorable` lines. A preview fixture without them would let the component test
pass whether or not `PD-SNP-002` renders, which is exactly S6's exit criterion.

11 test files, 91 tests.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
poli0981andClaude Opus 5 committed 2026-08-09 21:46:25 +07:00
1 parent da30709f37
commit 05ff2c5aa0
5 files changed
+284

No files matched your search

+80
View File
@@ -27,6 +27,10 @@
//! That the set is the SP-5 tangle pays off twice: `numpy` has two dependents declaring two
//! *different* specifiers, which is what the uninstall guard's dialog exists to show, so
//! `guard_report.json` is computed from the same rows rather than invented.
//!
//! `snapshot_list.json` carries one of each trigger, with the `Rollback` entry restoring the
//! `Plan` entry above it — the arrangement that makes `latest` move twice across one restore, and
//! the reason the timeline has to label them.
use crate::model::{Dist, OutdatedDist, PkgName, Version};
use crate::pins::{Pin, PinMode};
@@ -209,6 +213,80 @@ fn guard_report() -> crate::graph::GuardReport {
])
}
/// What `snapshot_list` returns: one of each trigger, newest first.
///
/// All three on purpose. A `Rollback` entry *restoring* the `Plan` entry above it is the shape
/// that makes `latest` move twice across a single restore — the trap that made TESTING L2's first
/// run report every package as changed when the rollback had worked — so the timeline has to be
/// able to tell them apart, and a fixture with one trigger could not prove it does.
fn snapshot_list() -> Vec<crate::snapshot::Meta> {
use crate::snapshot::{Meta, Trigger};
let meta = |id: &str, at: &str, trigger: Trigger, count: usize| Meta {
id: id.to_owned(),
created_at: at.to_owned(),
trigger,
engine: crate::model::EngineId::Pip,
package_count: count,
app_version: "0.1.0".to_owned(),
};
vec![
meta(
"20260809T140000-0000000Z",
"2026-08-09T14:00:00Z",
Trigger::Rollback {
restoring: "20260809T120000-0000000Z".to_owned(),
},
6,
),
meta(
"20260809T130000-0000000Z",
"2026-08-09T13:00:00Z",
Trigger::Plan {
plan_id: "update-abc12345".to_owned(),
},
6,
),
meta(
"20260809T120000-0000000Z",
"2026-08-09T12:00:00Z",
Trigger::Manual,
5,
),
]
}
/// What `snapshot_rollback_preview` returns, with all three sections populated.
///
/// The `unrestorable` entry is the reason this fixture exists rather than an empty preview:
/// DATA-FLOW §8 requires those lines to be listed explicitly as `PD-SNP-002` before the confirm,
/// and a component test against a preview that has none would pass whether or not they render.
fn rollback_preview() -> crate::flow::RollbackPreview {
let pkg = |n: &str| PkgName::parse(n).unwrap_or_else(|e| panic!("fixture name {n:?}: {e:?}"));
crate::flow::RollbackPreview {
target: snapshot_list()
.into_iter()
.next_back()
.unwrap_or_else(|| unreachable!("the list is not empty")),
restore: crate::snapshot::RollbackPlan {
uninstall: vec![pkg("httpx")],
install: vec![
crate::model::PinnedSpec {
name: pkg("numpy"),
version: Version("1.26.4".to_owned()),
},
crate::model::PinnedSpec {
name: pkg("requests"),
version: Version("2.28.0".to_owned()),
},
],
},
unrestorable: vec![
"-e C:\\src\\editable-lib".to_owned(),
"local-wheel @ file:///C:/wheels/local_wheel-1.0-py3-none-any.whl".to_owned(),
],
}
}
/// Every fixture, as `(file name, contents)`.
///
/// # Errors
@@ -222,6 +300,8 @@ pub fn ipc_fixtures() -> serde_json::Result<Vec<(&'static str, String)>> {
("flow_step.json", render(&flow_step())?),
("execution_summary.json", render(&execution_summary())?),
("guard_report.json", render(&guard_report())?),
("snapshot_list.json", render(&snapshot_list())?),
("rollback_preview.json", render(&rollback_preview())?),
])
}
@@ -0,0 +1,61 @@
/**
* The rollback preview — DATA-FLOW §8's "listed explicitly; user may proceed partially".
*
* S6's exit criterion in component form: the unrestorable entries appear **before** the confirm,
* under their code, rather than turning up in the summary after the user has already agreed.
*/
import { render, screen, within } from '@testing-library/react'
import { describe, expect, it } from 'vitest'
import { PdRollbackPreview } from '@/components/PdRollbackPreview'
import type { RollbackPreview } from '@/ipc'
import previewFixture from '@/test/fixtures/rollback_preview.json'
const PREVIEW = previewFixture as RollbackPreview
function section(name: string) {
const el = document.querySelector(`[data-section="${name}"]`)
if (el === null) throw new Error(`no ${name} section`)
return el as HTMLElement
}
describe('PdRollbackPreview', () => {
it('lists what cannot be restored, with its code, before anything runs', () => {
render(<PdRollbackPreview preview={PREVIEW} />)
const stuck = section('unrestorable')
expect(within(stuck).getByText('PD-SNP-002')).toBeInTheDocument()
// Verbatim freeze lines — an editable install and a direct URL, exactly as recorded.
expect(within(stuck).getByText('-e C:\\src\\editable-lib')).toBeInTheDocument()
expect(within(stuck).getByText(/local-wheel @ file:/)).toBeInTheDocument()
})
it('says which packages go and which come back, with the versions', () => {
render(<PdRollbackPreview preview={PREVIEW} />)
expect(within(section('uninstall')).getByText('httpx')).toBeInTheDocument()
// At the snapshot's version, not a bare name: otherwise this reads as a plain reinstall.
expect(within(section('install')).getByText('numpy==1.26.4')).toBeInTheDocument()
expect(within(section('install')).getByText('requests==2.28.0')).toBeInTheDocument()
})
it('names the snapshot it would restore to', () => {
render(<PdRollbackPreview preview={PREVIEW} />)
expect(screen.getByText(PREVIEW.target.id)).toBeInTheDocument()
})
it('says there is nothing to do rather than showing three empty sections', () => {
render(
<PdRollbackPreview
preview={{
target: PREVIEW.target,
restore: { uninstall: [], install: [] },
unrestorable: [],
}}
/>,
)
expect(screen.getByText(/already matches the snapshot/)).toBeInTheDocument()
expect(document.querySelector('[data-section]')).toBeNull()
})
})
@@ -0,0 +1,80 @@
/**
* The timeline — UI-SPEC §4's "timeline of snapshots with trigger label".
*
* The trigger label is the point. A restore writes its own snapshot before restoring, so `latest`
* moves twice across one rollback; the labels are how a user tells the entry they want from the
* one the rollback just created.
*/
import { fireEvent, render, screen, within } from '@testing-library/react'
import { describe, expect, it, vi } from 'vitest'
import { PdSnapshotTimeline } from '@/components/PdSnapshotTimeline'
import type { SnapshotMeta } from '@/ipc'
import snapshotFixture from '@/test/fixtures/snapshot_list.json'
const SNAPSHOTS = snapshotFixture as SnapshotMeta[]
function setup(overrides: { selected?: string | null; selectable?: boolean } = {}) {
const props = {
snapshots: SNAPSHOTS,
selected: overrides.selected ?? null,
selectable: overrides.selectable ?? true,
onSelect: vi.fn(),
}
render(<PdSnapshotTimeline {...props} />)
return props
}
/** One timeline entry by snapshot id. */
function entry(id: string) {
const el = document.querySelector(`[data-snapshot="${id}"]`)
if (el === null) throw new Error(`no timeline entry for ${id}`)
return el as HTMLElement
}
describe('PdSnapshotTimeline', () => {
it('tells the three triggers apart', () => {
setup()
expect(within(entry('20260809T140000-0000000Z')).getByText(/before restoring/)).toBeTruthy()
expect(within(entry('20260809T130000-0000000Z')).getByText('before a change')).toBeTruthy()
expect(within(entry('20260809T120000-0000000Z')).getByText('taken by you')).toBeTruthy()
})
it('names the snapshot a rollback entry was restoring', () => {
// Without it, two adjacent entries a minute apart are indistinguishable — and one of them is
// the state the user is trying to get back to while the other is the state they are leaving.
setup()
expect(
within(entry('20260809T140000-0000000Z')).getByText(/20260809T120000-0000000Z/),
).toBeTruthy()
})
it('shows every id verbatim, because that is what the commands take', () => {
setup()
for (const meta of SNAPSHOTS) {
expect(screen.getByText(meta.id)).toBeInTheDocument()
}
})
it('hands back the id it was clicked on', () => {
const { onSelect } = setup()
fireEvent.click(entry('20260809T130000-0000000Z'))
expect(onSelect).toHaveBeenCalledWith('20260809T130000-0000000Z')
})
it('marks the selected entry for assistive tech, not only visually', () => {
setup({ selected: '20260809T130000-0000000Z' })
expect(entry('20260809T130000-0000000Z')).toHaveAttribute('aria-current', 'true')
expect(entry('20260809T120000-0000000Z')).toHaveAttribute('aria-current', 'false')
})
it('lists but does not offer an environment that cannot be read', () => {
// Snapshots outlive the interpreter that made them, so the history is still worth showing —
// but nothing can be diffed against a Python that is gone.
setup({ selectable: false })
for (const meta of SNAPSHOTS) {
expect(entry(meta.id)).toBeDisabled()
}
})
})
+29
View File
@@ -0,0 +1,29 @@
{
"target": {
"id": "20260809T120000-0000000Z",
"createdAt": "2026-08-09T12:00:00Z",
"trigger": "manual",
"engine": "pip",
"packageCount": 5,
"appVersion": "0.1.0"
},
"restore": {
"uninstall": [
"httpx"
],
"install": [
{
"name": "numpy",
"version": "1.26.4"
},
{
"name": "requests",
"version": "2.28.0"
}
]
},
"unrestorable": [
"-e C:\\src\\editable-lib",
"local-wheel @ file:///C:/wheels/local_wheel-1.0-py3-none-any.whl"
]
}
+34
View File
@@ -0,0 +1,34 @@
[
{
"id": "20260809T140000-0000000Z",
"createdAt": "2026-08-09T14:00:00Z",
"trigger": {
"rollback": {
"restoring": "20260809T120000-0000000Z"
}
},
"engine": "pip",
"packageCount": 6,
"appVersion": "0.1.0"
},
{
"id": "20260809T130000-0000000Z",
"createdAt": "2026-08-09T13:00:00Z",
"trigger": {
"plan": {
"planId": "update-abc12345"
}
},
"engine": "pip",
"packageCount": 6,
"appVersion": "0.1.0"
},
{
"id": "20260809T120000-0000000Z",
"createdAt": "2026-08-09T12:00:00Z",
"trigger": "manual",
"engine": "pip",
"packageCount": 5,
"appVersion": "0.1.0"
}
]