feat(ui): the summary offers the rollback its copy already promises
`plan.cancelledDetail` has told the user since S3 that "the snapshot below restores the environment exactly as it was", and the sheet printed the id with no way to act on it. The existing test even said so in its own name — "still shows the snapshot when the run was clean, because rollback is still offered" — while nothing was offered. `onRollback` is optional and the button is absent without it, so the sheet stays presentational and does not reach for a store to work out whether a restore is possible. `PdPlanPanel` supplies it only when the store still knows which environment the run was against, and never *from* a rollback: offering to undo an undo from its own summary is a loop with no obvious exit. `App`'s `onFinished` now refetches the timeline with `force`. A rollback writes its own pre-rollback snapshot, so the list behind the panel is stale the moment the run ends — and `snapshotsFor` still matches, so without `force` the refetch is suppressed and the timeline shows the state from before. That is the `latest`-moves-twice trap one layer up from where L2 first hit it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d6ae948cda
commit
da30709f37
6 files changed
+75
-8
No files matched your search
@@ -47,6 +47,7 @@ export function App() {
|
||||
const loadPackages = useEnvStore((s) => s.loadPackages)
|
||||
const loadOutdated = useEnvStore((s) => s.loadOutdated)
|
||||
const clearSelection = useEnvStore((s) => s.clearSelection)
|
||||
const loadSnapshots = useEnvStore((s) => s.loadSnapshots)
|
||||
// A plan belongs to the app, not to a screen: there is one at a time (PD-RES-003) and it can be
|
||||
// started from Updates *or* from the Search dock bay. Owning it here is what stops an install
|
||||
// resolving into nowhere because the tab that renders the preview is not the tab you are on.
|
||||
@@ -125,6 +126,10 @@ export function App() {
|
||||
clearSelection()
|
||||
void loadPackages()
|
||||
void loadOutdated()
|
||||
// A rollback writes its own pre-rollback snapshot, so the timeline behind this
|
||||
// panel is stale the moment the run finishes. `force`, because `snapshotsFor`
|
||||
// still matches and would suppress the refetch.
|
||||
void loadSnapshots(true)
|
||||
}}
|
||||
/>
|
||||
) : (SCREENS[nav] ?? (
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* rows are most likely to disagree.
|
||||
*/
|
||||
|
||||
import { render, screen, within } from '@testing-library/react'
|
||||
import { fireEvent, render, screen, within } from '@testing-library/react'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { PdSummarySheet } from '@/components/PdSummarySheet'
|
||||
@@ -16,7 +16,7 @@ import summaryFixture from '@/test/fixtures/execution_summary.json'
|
||||
|
||||
const SUMMARY = summaryFixture as ExecutionSummary
|
||||
|
||||
function setup(overrides: Partial<ExecutionOutcome> = {}) {
|
||||
function setup(overrides: Partial<ExecutionOutcome> = {}, onRollback?: () => void) {
|
||||
const onDone = vi.fn()
|
||||
const outcome: ExecutionOutcome = {
|
||||
summary: SUMMARY,
|
||||
@@ -32,7 +32,13 @@ function setup(overrides: Partial<ExecutionOutcome> = {}) {
|
||||
},
|
||||
...overrides,
|
||||
}
|
||||
render(<PdSummarySheet outcome={outcome} onDone={onDone} />)
|
||||
render(
|
||||
<PdSummarySheet
|
||||
outcome={outcome}
|
||||
onDone={onDone}
|
||||
{...(onRollback === undefined ? {} : { onRollback })}
|
||||
/>,
|
||||
)
|
||||
return { onDone, outcome }
|
||||
}
|
||||
|
||||
@@ -80,6 +86,23 @@ describe('the cancelled case', () => {
|
||||
setup({ summary: { ...SUMMARY, cancelled: false } })
|
||||
expect(screen.getByText('2026-08-04T10-00-00Z')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('offers the rollback its own copy has been promising', () => {
|
||||
// `plan.cancelledDetail` has said "the snapshot below restores the environment exactly as it
|
||||
// was" since S3, with nothing behind it. The button hands back the id, so the caller does not
|
||||
// have to reach into the outcome it already passed in.
|
||||
const onRollback = vi.fn()
|
||||
setup({}, onRollback)
|
||||
fireEvent.click(screen.getByText('Roll back to this'))
|
||||
expect(onRollback).toHaveBeenCalledWith('2026-08-04T10-00-00Z')
|
||||
})
|
||||
|
||||
it('offers no rollback when the caller cannot perform one', () => {
|
||||
// Presentational: the sheet does not reach for a store to decide whether a restore is
|
||||
// possible, so no handler means no button.
|
||||
setup()
|
||||
expect(screen.queryByText('Roll back to this')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('the post-run check', () => {
|
||||
|
||||
@@ -21,6 +21,13 @@ import type { ExecutionOutcome, StepResult } from '@/ipc'
|
||||
interface PdSummarySheetProps {
|
||||
outcome: ExecutionOutcome
|
||||
onDone: () => void
|
||||
/**
|
||||
* Restore the snapshot this run took, when the caller can.
|
||||
*
|
||||
* Optional, and the button is absent without it — the component stays presentational and does
|
||||
* not reach for a store to find out whether a rollback is possible.
|
||||
*/
|
||||
onRollback?: (id: string) => void
|
||||
}
|
||||
|
||||
function ResultRow({ result }: { result: StepResult }) {
|
||||
@@ -58,7 +65,7 @@ function ResultRow({ result }: { result: StepResult }) {
|
||||
)
|
||||
}
|
||||
|
||||
export function PdSummarySheet({ outcome, onDone }: PdSummarySheetProps) {
|
||||
export function PdSummarySheet({ outcome, onDone, onRollback }: PdSummarySheetProps) {
|
||||
const { t } = useTranslation()
|
||||
const { summary, snapshot } = outcome
|
||||
const results = summary.results ?? []
|
||||
@@ -88,10 +95,27 @@ export function PdSummarySheet({ outcome, onDone }: PdSummarySheetProps) {
|
||||
) : null}
|
||||
|
||||
{snapshot === undefined ? null : (
|
||||
<p className="text-data text-text-dim">
|
||||
{/* The id is data, never translated — it is what `pipdock snapshot rollback` takes. */}
|
||||
{t('plan.snapshotTaken')} <code className="font-mono">{snapshot.id}</code>
|
||||
</p>
|
||||
<div className="flex flex-wrap items-baseline gap-2">
|
||||
<p className="text-data text-text-dim">
|
||||
{/* The id is data, never translated — it is what `pipdock snapshot rollback` takes. */}
|
||||
{t('plan.snapshotTaken')} <code className="font-mono">{snapshot.id}</code>
|
||||
</p>
|
||||
{/* The cancelled banner has promised since S3 that "the snapshot below restores the
|
||||
environment exactly as it was", with nothing behind it. This is the button that
|
||||
sentence has been describing. */}
|
||||
{onRollback === undefined ? null : (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
onRollback(snapshot.id)
|
||||
}}
|
||||
data-action="rollback"
|
||||
className="rounded-pd border border-danger px-2 py-0.5 text-data text-danger"
|
||||
>
|
||||
{t('snapshots.rollbackThis')}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Post-run `pip check`. A finding here means the environment is inconsistent *after* a run
|
||||
|
||||
@@ -178,6 +178,7 @@
|
||||
"diffChanged_one": "{{count}} package at a different version",
|
||||
"diffChanged_other": "{{count}} packages at different versions",
|
||||
"rollback": "Rollback…",
|
||||
"rollbackThis": "Roll back to this",
|
||||
"rollbackTitle": "Roll back",
|
||||
"restoringTo": "Restoring the environment to",
|
||||
"alreadyMatches": "Nothing to do — this environment already matches the snapshot.",
|
||||
|
||||
@@ -168,6 +168,7 @@
|
||||
"diffRemoved_other": "{{count}} gói có trong ảnh chụp nhưng chưa cài — khôi phục sẽ cài lại",
|
||||
"diffChanged_other": "{{count}} gói đang ở phiên bản khác",
|
||||
"rollback": "Khôi phục…",
|
||||
"rollbackThis": "Khôi phục về ảnh này",
|
||||
"rollbackTitle": "Khôi phục",
|
||||
"restoringTo": "Khôi phục môi trường về",
|
||||
"alreadyMatches": "Không có gì để làm — môi trường này vốn đã khớp với ảnh chụp.",
|
||||
|
||||
@@ -39,6 +39,8 @@ export function PdPlanPanel({ onFinished }: PdPlanPanelProps) {
|
||||
const outcome = usePlanStore((s) => s.outcome)
|
||||
const error = usePlanStore((s) => s.error)
|
||||
const cancelling = usePlanStore((s) => s.cancelling)
|
||||
const env = usePlanStore((s) => s.env)
|
||||
const rollback = usePlanStore((s) => s.rollback)
|
||||
|
||||
const choose = usePlanStore((s) => s.choose)
|
||||
const submitDecisions = usePlanStore((s) => s.submitDecisions)
|
||||
@@ -88,6 +90,17 @@ export function PdPlanPanel({ onFinished }: PdPlanPanelProps) {
|
||||
reset()
|
||||
onFinished()
|
||||
}}
|
||||
// Only when the store still knows which environment this was, and never *from* a
|
||||
// rollback — offering to undo an undo from its own summary is a loop with no
|
||||
// obvious exit.
|
||||
{...(env !== null && kind !== 'rollback'
|
||||
? {
|
||||
onRollback: (id: string) => {
|
||||
reset()
|
||||
void rollback(env, id)
|
||||
},
|
||||
}
|
||||
: {})}
|
||||
/>
|
||||
)}
|
||||
{outcome === null && error === null ? null : (
|
||||
|
||||
Reference in new issue
Block a user