Repository navigation
test(terminal): check the runtime's workspace layout against structural rules - #26673
Conversation
…al rules A pure rules check over the runtime's session partitions: a terminal in two panes, a pane in two tabs, a tab outside exactly one group, tab rows and tab bar disagreeing, two tab orders, and ids changing for the same pane, tab or group across an update. Wired into the seeded layout model test after every step, plus late-spawn cases (one known on main, kept as an expected failure).
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughThe change adds workspace layout validation for pane, terminal, tab, group, ordering, and identity consistency. It adds shared session fixture helpers and checks layout rules during topology model operations, including randomized races and cold reopen. New persistence tests cover stale pane layouts and late terminal bindings. Two tests are marked as expected failures. Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to The test-only change has no identified merge-blocking issue after normal checks. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…mands with the window The layout model now checks the structural rules on every in-memory workspace-session write, not only at each step's end, naming the writer of any breach. Three documented two-writer transients (main mints a tab row before the window writes its tab bar) are allow-listed by rule, op and writer; they must still heal by the step's end. New model ops race a stale window save against a paired client's tab close, a host-created split, and main's PTY-exit retirement. A new file runs main's updateMobileSessionPaneLayout (old phone pane trees) against the real Store; the case with no topology revision is an it.fails: main drops a live pane and its binding there.
ELI5
Before reworking how workspace tabs and panes are owned, we want a checker that says "this layout is broken" without a person reading code. This PR adds the first piece: a function that looks at the layout the app's main process holds and lists every rule it breaks, for example one terminal shown in two panes, or one pane in two tabs. It is test code only; the app behaves exactly as before.
What Changed
src/main/persistence/terminal-topology/workspace-layout-rules.ts(+-rule-types.ts,-id-stability.ts): a pure function. Input: the main process's saved session for each host (local, SSH, remote mirror), and optionally the previous one. Output: one entry per broken rule:It reuses the existing ownership helpers (
collectTerminalLeafOwners,isSameTerminal), so "same terminal" means the same thing it does in the rest of main.terminal-topology-model.test.ts) now runs the full rules check, including id stability, after every one of its random steps and after a cold reload, instead of the two ownership rules it checked before. Its stand-in for the window now keeps a tab bar the way the real window does (moved toterminal-topology-window-session-fixture.ts).terminal-late-bind-layout-rules.test.ts: a terminal start that lands after its tab was closed must not bring the tab back (passes on main). A terminal start that lands after its pane was dragged into a new tab must not put the pane back into the old tab: this fails on main (main grafts the pane back, so it is in two tabs; only the window's "no drag before the shell starts" guard hides it today). It is marked as an expected failure so CI stays green, and must be flipped when fixed.Before/after for users: none.
Added after review:
Promise.all). Every order is expected to give the user's outcome.terminal-stale-pane-tree-client.test.ts): main's realsession.tabs.updatePaneLayouthandler, with no window, receives stale whole pane trees: one missing a pane another client split, one naming a closed pane, one naming a dragged-out pane. Fails on main in one case, kept as an expected failure: on a headless host whose repo has no layout revision yet, an old phone's tree that omits a pane wipes that pane and its terminal binding.Why
The previous attempt at this rework went through many rounds of static review without converging. An automatic, pass/fail check that is proven on main first lets each rework PR be judged by whether anything new breaks. The rules check is the piece every other check builds on (the end-to-end scenarios in the follow-up PR run it after every step). A pure function over the saved session was chosen over hooks inside the app so production code is untouched.
Proof that it catches real regressions (each fix reverted locally on main, then the test run):
pane_in_two_tabs.tab_lists_disagreeand the tab row coming back.200 random seeds pass on unmodified main.
Linked Issue
Part of the workspace tab layout rework (STA-9417, STA-9259).
Visual Proof
N/A: test code only, no UI or behavior change.
Testing
pnpm test src/main/persistence/terminal-topology/(63 pass, 2 expected failures), 400 seeds of the model test, default seeds 3 times.The three reverts above, each in a scratch tree.
pnpm tc,pnpm run check:code-quality:changed.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Notes
Test-only; no security, platform, SSH, mobile or performance impact. SSH partitions are checked together with local ones (ids can move between them for old relay rows); a remote server's mirrored partition is checked on its own.
Checklist
N/Afor visuals with reasonpnpm typecheck,pnpm test(changed files) pass locally