Skip to content

test(terminal): check the runtime's workspace layout against structural rules - #26673

Merged
Jinwoo-H merged 2 commits into
mainfrom
layout-oracle-rules
Oct 9, 2026
Merged

Jinwoo-H merged 2 commits into
mainfrom
layout-oracle-rules

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​889 $\color{#cf222e}{\Huge{\mathbf{−}}}$​138 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​751
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​537 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​537

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:
    • a terminal shown in two panes; a pane in two tabs, or twice in one tab; panes or terminal bindings with no tab;
    • a tab row listed under two worktrees; a tab in no group, in two groups, or in a group it does not name; a group naming a tab that does not exist; terminal tab rows and the tab bar listing different tabs; a worktree with tabs but no tab bar;
    • tab rows ordered differently from their group's tab bar (more than one tab order);
    • with the previous state: a pane, tab or group that got a new id while holding the same thing (what remounts a view).
      It reuses the existing ownership helpers (collectTerminalLeafOwners, isSameTerminal), so "same terminal" means the same thing it does in the rest of main.
  • The seeded layout model test (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 to terminal-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:

  • The model test now runs the rules after every write to main's session (not only after each step), tagging each breach with the gesture and writer. Three gaps main has today are allow-listed by rule, gesture and writer, and must still heal by the end of the step: main writes a new tab's row before the window writes its tab bar (on spawn and on pane move).
  • Concurrency: new model steps where a paired client or the CLI acts through main while the window still holds a stale copy. The client closes a tab, the client splits a pane (host-created binding), or a terminal exits; the window's stale save lands before or after (via Promise.all). Every order is expected to give the user's outcome.
  • Old phone builds (terminal-stale-pane-tree-client.test.ts): main's real session.tabs.updatePaneLayout handler, 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.
  • Each new check was shown to bite by reverting a main guard locally (leaf move source update, the split's source-binding fence, tab-bar removal on close, the revision bump on close, the rebase's pane-membership check).

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):

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

  • This PR is small and focused
  • I explained what changed and why
  • N/A for visuals with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered
  • pnpm typecheck, pnpm test (changed files) pass locally

…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).
@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2b8ef860-3370-4b78-bf94-55c3295ced14
📥 Commits

Reviewing files that changed from the base of the PR and between 214ad95 and 92bafdc.

📒 Files selected for processing (2)
  • src/main/persistence/terminal-topology/terminal-stale-pane-tree-client.test.ts
  • src/main/persistence/terminal-topology/terminal-topology-model.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

The 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 92baf

The test-only change has no identified merge-blocking issue after normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 25.81% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 31 functions across 8 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly and concisely describes the primary change: adding structural workspace-layout checks in terminal tests.
Description check Passed The description is detailed and covers the required explanation, changes, rationale, linked issues, visual proof, testing, notes, and checklist. It clearly identifies the test-only scope and expected …
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…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.
@Jinwoo-H
Jinwoo-H merged commit d010c83 into main Oct 9, 2026
58 of 60 checks passed
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