Skip to content

Commit b66092b

Browse files
committed
docs: record the redo fix, its tests and the new model laws
- `docs/LEAN4_RUST_CORRESPONDENCE.adoc`: a redo section saying which model statements exist (Idris2 only; Lean and Coq have no redo stack), what the Rust `redo` does now, and what is not modelled. - `EXPLAINME.adoc` proof ledger: one `proven-with-postulates` row for the undo/redo stack laws and one `tested-only` row for the Rust round trip. - `CHANGELOG.adoc`: the fix and the defects found and not fixed. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4QvDiC97Fg2LvDpuFCz95
1 parent d07f70b commit b66092b

3 files changed

Lines changed: 103 additions & 0 deletions

File tree

‎CHANGELOG.adoc‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,37 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4747
row can be `proven`; the Mizar target swallows failure (`|| echo`). Both are
4848
logged as AP-6, AP-7 and AP-8 in the audit.
4949

50+
=== Fixed — 2026-11-17 (redo keeps undo data; undo of redirections)
51+
52+
- `redo` recorded the re-applied operation with no undo data, so
53+
`rm f; undo; redo; undo` restored `f` empty, a redone `chmod`/`chown` changed
54+
nothing and could not be undone, and a second redo of `cp`/`ln -s` failed.
55+
Each operation now has one function that checks its preconditions, captures
56+
its undo data and applies it; the command and `redo` both call it.
57+
- `redo` now restores what an operation produced (the mode of a `chmod`, the
58+
owner of a `chown`, the bytes a `>`/`>>` redirection wrote, a variable's
59+
value). `undo` reads that state just before reversing it and keeps it in
60+
memory with the redo entry. File content over `VSH_REDO_CAPTURE_LIMIT` bytes
61+
(shell or environment variable; default 10 MiB; `0` = no limit) is not kept,
62+
and redo of that entry says so.
63+
- A `redo` that fails changes nothing and stays on the redo stack. `redo` of
64+
`cp`, `mv` and `touch` no longer overwrites a path that reappeared after the
65+
undo.
66+
- Undo of a `>`/`>>` redirection failed whenever the sandbox root was not `/`
67+
(the default root is the current directory): the history held an absolute
68+
path that undo resolved under the root a second time. History paths for
69+
redirections are now relative to the root.
70+
- `touch` creates its file with `create_new`, so it no longer writes through a
71+
dangling symbolic link.
72+
- Idris2 model: `redoUndoIdentity`, `undoRedoUndoIdentity`,
73+
`redoUndoComposition` added to `Filesystem.Composition` (`proven` for the
74+
model; the Rust link stays `tested-only`).
75+
- Known and *not* fixed here (tests exclude them, see
76+
`impl/rust-cli/tests/redo_roundtrip_tests.rs`): undo of `rm`/`rmdir` does
77+
not restore the mode; undo of `unset` does not restore the exported flag;
78+
`rm`, `chmod` and redirections follow symbolic links and their undo does not
79+
account for it.
80+
5081
=== Planned
5182
- Glob expansion (*.txt, ?.rs, [a-z]*)
5283
- Quote processing (proper escaping, single/double quotes)

‎EXPLAINME.adoc‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,18 @@ reproduce. Absence of a tool is an open obligation, not a passing leg
144144
| `impl/rust-cli/tests/model_oracle_correspondence.rs`
145145
| Sampled, precondition-respecting sequences only; a divergence would be a real bug but agreement is not a proof
146146

147+
| Undo then redo, and redo then undo, are identities on the undo/redo stack model (single step and `n`-fold)
148+
| proven-with-postulates
149+
| Idris2 0.8.0, `idris2 --build valence-shell.ipkg` (`--total`), re-run 2026-11-17, plus the `believe_me` gate; CI `idris-verification.yml`
150+
| `proofs/idris2/src/Filesystem/Composition.idr`: `undoRedoIdentity`, `undoRedoComposition`, and (2026-11-17) `redoUndoIdentity`, `undoRedoUndoIdentity`, `redoUndoComposition`
151+
| `redoUndoIdentity` and `redoUndoComposition` use no axiom; they are conditional on a per-step reversibility premise. `undoRedoIdentity` and its corollary `undoRedoUndoIdentity` discharge that premise through lemmas resting on the registered `axStringEqRefl`. The model has five operations (mkdir, rmdir, touch, rm, write) on a flat path map: no cp, mv, links, modes, ownership, variables or redirections. It says nothing about the Rust `redo`
152+
153+
| The Rust `undo`/`redo` round trip restores state for every operation type that reaches the history
154+
| tested-only
155+
| `cargo test --test redo_roundtrip_tests` (22 tests: 19 operation scenarios, 48 random sequences via `proptest`) and `test_redo_then_undo_correspondence`
156+
| `impl/rust-cli/tests/redo_roundtrip_tests.rs`, `impl/rust-cli/tests/correspondence_tests.rs`
157+
| Whole-sandbox comparison (bytes, modes, owners, link targets, one shell variable). Three scenarios assert only the redo laws because undo itself loses data there (mode on `rm`/`rmdir`, exported flag on `unset`); random sequences exclude symbolic links for the same reason; the `chown` scenario runs only as root. Not a proof and not a refinement of the Idris2 model
158+
147159
| Idris2 ABI layout, encodings and round-trips match the C header
148160
| tested-only
149161
| `--total`, plus `scripts/check-abi-layout.sh`

‎docs/LEAN4_RUST_CORRESPONDENCE.adoc‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,66 @@ let op = Operation::new(OperationType::DeleteFile, path.to_string(), None)
478478
* ✅ Restored on undo
479479
* ✅ Correspondence maintained
480480

481+
==== Redo, and redo followed by undo (added 2026-11-17)
482+
483+
The redo stack is modelled only in Idris2
484+
(`+proofs/idris2/src/Filesystem/Composition.idr+`); the Lean and Coq
485+
developments state single-step and sequence undo, with no redo stack.
486+
487+
[cols="2,3",options="header"]
488+
|===
489+
| Model statement (Idris2) | What it says
490+
491+
| `+undoRedoIdentity+`
492+
| `+undo (execute op s) >>= redo = Just (execute op s)+`. The equality is on
493+
the whole `+UndoState+`: filesystem, undo stack and redo stack.
494+
495+
| `+undoRedoUndoIdentity+`
496+
| Undo, redo, undo equals undo. Corollary of the above.
497+
498+
| `+redoUndoIdentity+`
499+
| From any state with an operation to redo, redo then undo is the identity,
500+
given that the operation inverts at the current filesystem.
501+
502+
| `+redoUndoComposition+`
503+
| `+n+` redos followed by `+n+` undos is the identity, over a `+Redoable+`
504+
witness (mirror of `+undoRedoComposition+`).
505+
|===
506+
507+
Status: `proven` for the model (five operations: mkdir, rmdir, touch, rm,
508+
write, on a flat path map). The link to the Rust code is `tested-only`.
509+
510+
The model re-applies the *same* operation value on redo, so the redone entry
511+
on the undo stack is identical to the original. The Rust `+redo+` did not do
512+
that before 2026-11-17: it re-executed the operation and recorded it with no
513+
undo data, so the filesystem matched after a redo but the history record did
514+
not, and the next undo restored an empty file (`+rm f; undo; redo; undo+`).
515+
The existing tests compared only the filesystem after a redo, so they did not
516+
see it.
517+
518+
What the Rust does now (`+impl/rust-cli/src/commands.rs+`):
519+
520+
* Each operation has one `+apply_*+` function that checks its preconditions,
521+
captures its undo data and changes the filesystem. The command and `+redo+`
522+
both call it, so a redone record carries freshly captured undo data.
523+
* What an operation *produced* (the mode a `+chmod+` set, the bytes a
524+
redirection wrote, a variable's new value) is read by `+undo+` just before it
525+
reverses the operation and kept on the in-memory redo entry
526+
(`+state::RedoData+`). File content over `+VSH_REDO_CAPTURE_LIMIT+` bytes
527+
(default 10 MiB, `+0+` for no limit) is not kept; redo of that entry fails
528+
with the reason.
529+
* A redo that fails changes nothing and stays on the redo stack.
530+
531+
Tests (`tested-only`): `+impl/rust-cli/tests/redo_roundtrip_tests.rs+`
532+
(every operation type, random sequences, the capture limit) and
533+
`+test_redo_then_undo_correspondence+` in `+correspondence_tests.rs+`, which
534+
compares the history records as well as the filesystem.
535+
536+
Not covered by the model: cp, mv, symbolic links, chmod, chown, variables,
537+
redirections, nested directories. Known undo defects that these tests
538+
exclude are listed in the test file (`+undo_is_exact: false+` and the note on
539+
symbolic links).
540+
481541
'''''
482542

483543
=== Composition Theorems

0 commit comments

Comments
 (0)