Skip to content

feat(tui): a perceptual audit; platform-correct mention fixtures - #1368

Merged
huichen merged 11 commits into
mainfrom
pr/huichen
Oct 26, 2026
Merged

huichen merged 11 commits into
mainfrom
pr/huichen

Conversation

@huichen

@huichen huichen commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Frozen snapshot of dev-huichen at e70a311d (0 behind current origin/main).

What lands

  • perceptual audit (d486150c): a third acceptance driver that asserts only things true on screen, not in the model — visible records occupy consecutive rows, each row draws its own record, exactly one row carries the selection arrow and it is the selected one, one keypress moves the arrow exactly one row, and the selection never scrolls out of frame. 13 surfaces × 5 widths = 1198 assertions. It caught two real defects the earlier drivers could not see (records wrapping across rows; pageUp/pageDown dead in all nine list overlays while the help table advertised them).
  • mention test fixtures (5d9c718d): three assertions only held on POSIX. format!("{}/note.md", cwd) hard-coded / where Path::join yields \ on Windows; the trailing-dot case assumed Win32 does not strip the dot (it does); workspace_files was compared against /-joined strings. Worse, file.starts_with("target/") was vacuously true on Windows — pruning could fail entirely and the test stayed green. Now expected values go through Path/display(), pruning compares path components, and the trailing-dot case keeps its invariant on both platforms (#[cfg(windows)] asserts the dot reached the filesystem and still resolved; #[cfg(not(windows))] keeps the original assertion). Nothing was deleted to make it pass.

Why these fixtures mattered

Those commits were only on dev-huichen, never in main, so no Windows CI had ever compiled them. The first PR carrying them would have gone red on Rust Windows test / tui-cli and looked like a flake.

Verification reported by the implementing session

  • 1201 library tests + 6 cli + 8 i18n + 1 perf pass; clippy -D warnings --all-targets, fmt, 344-doc check clean.
  • Every new assertion was proved to have teeth by reverting the fix under it: hard-coded / → red; code trimming the trailing dot → red; target pruning disabled → red.
  • Its own honest gap: the #[cfg(not(windows))] branch was only statically verified (swapping the cfgs compiles); Linux/macOS CI executes it, not this machine.

Not in this PR

The three audit drivers are not wired into CI, Makefile defaults or branch protection — whether they become a delivery gate is a product decision (tracked separately).

huichen and others added 11 commits October 26, 2026 13:29
Ports the `@` / `#` completion menu out of the 8958cf069 snapshot and onto the
workbench as it stands: the draft is an `EditorState` now, the chrome comes from
the i18n table, and the composer is a box whose top edge the menu must not sit
on.

The menu is *derived* from the draft rather than owned by it — `sync_mention`
re-reads the token ending at the caret on every event and on every frame — so
the query and the menu cannot disagree, and a paste (one event, no keystroke
after it) opens it at the next paint. A token that merely contains a sigil
(`[email protected]`, `x#y`) is text, not a menu.

`@` lists files under the session's working directory: `git ls-files` when it is
a repository, a pruned walk otherwise, read once per directory so a keystroke is
not a listing. `#` lists conversations and inserts the same
`futureos://session/<id>` link every other surface uses.

Painted above the composer rather than as an overlay: it completes the line the
reader is still typing, so it must not own the keys nor cover the draft.

Tests: the token boundaries, the file and conversation lists, the insert that
replaces exactly the token, escape that closes without touching the draft, an
unmatched list that still submits, the painted box's position above the
composer, and the two listing roads (`git ls-files` honouring .gitignore; the
walk pruning build output).

Ported from 8958cf069 (wip snapshot), which stays as it is.
…anscript

`@path` completion was half an affordance: the menu inserted a path the agent
then had to go and open itself, which it can only do when it happens to guess
the same working directory. Now every `@path` naming a readable file under the
session's directory becomes the same `<file name="…">…</file>` block
`future run @README.md` sends, and the transcript keeps what the reader typed —
that is what was said; the files are what was meant.

The limits are stated rather than silent: at most 8 files, 256 KB each, and a
file that is skipped (too large, binary, unreadable) is named in the prompt with
the reason, so the model is told what it did not get. A token that names nothing
(`@team`) stays exactly as typed, and trailing sentence punctuation is put back
after the block — the reader's comma is not the path's.

Tests: the block shape and the replaced token, the three "cannot inline" notes,
the size limit, punctuation, an e-mail address that is not a mention, and a
draft with no mention returned byte for byte.

Two in-source i18n markers and BUDGET 35 -> 37: those notes are prompt text for
the model, never drawn, so they are not chrome the table should carry.

Ported from 8958cf069 (wip snapshot), which stays as it is.
The slash menu listed only the twelve verbs the surface answers, so a reader had
to already know a skill's name to type it. Skills are written `/name` in the
draft exactly like a command is, so they belong in the same list: commands
first, then the installed skills, each kind under its own heading, and `tab`
completes the highlighted row into the draft so arguments can follow.

`enter` on a skill fills the draft rather than running it: a skill is a prompt
token the *agent* expands, and claiming it here would be a command the agent
never sees. The same rule for a click on its row.

Ported to the current palette rather than beside it: `palette_entries()` returns
`PaletteRow`s and takes the data (skills come from it), the heading lines are
counted into the hit regions so a click cannot land a row off, and the list is
capped so a machine with many skills does not turn `/` into a scroll.

Tests: the two kinds and their order, filtering to a skill by name, `enter`
filling rather than running, `tab` completing with the caret after the command,
the painted headings, and a click staying aligned with what was drawn.

Ported from 8958cf069 (wip snapshot), which stays as it is.
Two flaky tests that reproduced on a 32-core host, both because something
outside the code under test decided the outcome.

`mcp_client`/`mcp_servers`: every fake MCP server parsed the request id by
piping the frame through `sed`, i.e. through an external binary resolved from
the *inherited* PATH. The spawn does not clear the environment, and libtest
runs the binary's tests in parallel while several of them rewrite HOME/PATH via
test_env::EnvGuard (this module takes no lock_env at all), so a torn copy of
environ can drop /usr/bin: `sed: command not found`, an empty id, an unreadable
frame, and `the_stderr_tail_keeps_the_last_lines_and_drops_the_oldest` fails its
handshake with "expected value at line 1 column 23" — 2 of 2 full-suite runs,
green when run alone. Ten sites now use shell parameter expansion and need no
external binary at all: with `PATH` pointing at an empty directory the old
script prints `sed: command not found` and the new one parses the id correctly.

Desktop skills bootstrap: the CLI probe kills its child after PROBE_DEADLINE
(3 s), and the bootstrap tests wait for a fixture shell script to answer, so
their outcome was a race between a busy host's scheduler and that clock — the
suite's red runs took 98/104 s against 64-67 s. The crate already had the
anti-race seam and its doc comment argues this exact case, but it was gated
`#[cfg(test)]`, which is false when Desktop compiles future-host as a
dependency of its test binary. The seam now shares the fixtures' gate
(`any(test, feature = "test-support")`), `ProbeDeadlineGuard` is public with
`without_deadline()`, and the two bodies that assert what discovery *captured*
arm it. The arm that asserts the kill keeps the production budget, which is
what pins the constant to 3 s; production is unchanged. It stays thread-local:
libtest gives each test a thread and the bootstrap body runs in a re-exec'd
child, so arming it there cannot reach another test's probe.

Falsified both: arming 1 ns instead of no deadline reproduces the original CI
failure verbatim (same two lines, same assertion); the old script with PATH
stripped reproduces the `sed` failure while the new one parses correctly.
After: `cargo test -p future-cli --lib` green 3/3 (1399 each, was 2/2 red) and
`cargo test -p futureos --lib` green 3/3 (365 each, was 2 of 6 red).

The audit that this task actually resolved to — five documented flakes already
fixed by earlier work, one no longer reproducing, three CI-only or
environmental — is in docs/testing/flaky-audit-2026-10-26.md.
A list of `✔ P0 收敛两份实现` with no title is what made a reader ask "what is
this 待办?". The panel now prints the goal's own objective above the rows, read
from the same `registry.json` the control plane writes, and — when the workspace
has no goal in progress — says so and names the command that would create one
instead of showing an unexplained empty list.

`goal_board()` returns the objective and the todos together, so the panel reads
the ledger once rather than twice, and `/todo` focuses the panel the way
`/skills` and `/usage` already do.

All four new sentences are i18n keys, including the panel's own empty states, so
the `待办` board reads the same in either language. `PanelEmptyTodo` stays for
the case that has no goal name to print.

The panel's empty-state test now covers the board's two shapes (with a goal and
without) rather than relying on one sentence containing another.

Ported from 8958cf069 (wip snapshot), which stays as it is.
…ing them

A read that carries more than one key was handed to the draft as text, so a held
`ctrl+y`, or two arrow presses landing in the same read, put raw control bytes
into what the reader was writing. A chunk is now split into its keys — control
bytes one at a time, escape sequences at their own boundaries — and only when
every piece really is a complete key.

Two limits are deliberate: a chunk with text in it is never re-split (the parser
folds a trailing control byte into a chord, so `b\x13` would become `ctrl+s`),
and an unfinished sequence stays whole for the next read rather than having half
of it read as an `escape`.

Tests: two ctrl bytes, two arrows, text with a trailing control byte, a tab
between letters, a lone trailing escape and a truncated CSI.

Ported from 8958cf069 (wip snapshot), which stays as it is.
`os.write` on a pty master returns a short count once the child's input queue is
full, and the capture ignored the return value: a scripted line could arrive
truncated, which looks exactly like the program under test losing keystrokes.

Every write now loops until the payload is gone. Nothing else about the capture
changes, and `tui --scenario chat` still renders the same frame.

Ported from 8958cf069 (wip snapshot), which stays as it is.
The bilingual pair states what could be shown to work and what could not: six
units landed (mentions, inlined mentions, palette skills, the goal-named to-do
board, the key-chunk split, the capture write), four function points did not and
why (a scope picker with no consumer left, a redundant permission picker, status
segments whose targets are half gone, a frame de-duplication the loop already
solves differently), and the keybinding table that decides the cycle keys.

Also records the two hardest conflict resolutions — the palette's row identity
with headings inserted into it, and the mention edit against an `EditorState`
instead of a plain string — plus the i18n accounting (14 keys, BUDGET 35 -> 37
for two prompt-text literals) and why no screenshot was refreshed.
The `down`-skips-two-rows report got through two audits that both looked
thorough. The reason is in what they asserted: `workbench_semantics` compared
"region N opens record N" and `workbench_interaction` compared "region id at
its own coordinates", and *both stay true for any number of painted rows per
record*. Neither ever crossed from index space to screen space, so a record that
occupied two rows was invisible to them. Their fixtures made it worse: short
ASCII names (`session 3`, `D:/w/3`) cannot wrap at all.

`workbench_perceptual` asks only questions about the picture: visible records
occupy consecutive rows; each row carries its own record's text and no
neighbour's; exactly one row carries the selection arrow and it is the selected
record's; one keypress moves that arrow one row (then the list scrolls under it);
the selection never leaves the box. It runs 13 surfaces — the five list
overlays, the queue, the palette, preferences, the shortcut editor, three
pickers, the sidebar and the launchpad — at five sizes with hostile data.

It found the reported defect plus a second one of the same family: `pageUp` and
`pageDown` added to `overlay_scroll`, which list overlays never read, so the page
keys were inert on all nine list surfaces while the help table advertised them.
The renderer now records how many list rows it showed and the keys move the
cursor by that many; a detail card scrolls instead, and the diff follows
whichever pane has the keys.

Both audits keep their place: `workbench_interaction` proves every painted
control answers, `workbench_semantics` proves the answer matches the record, and
this one proves the record is where the reader sees it. Each mutation of the
four fixed behaviours is caught by the new audit and by a unit test.
Three fixtures could only pass on POSIX. They were never run by CI — the
commits that introduced them (2d7ece7, bec1c33) are newer than the last run
on this branch — so the first PR to carry them would have gone red on
`Rust Windows test / tui-cli`, looking like a flake.

None of it was a product defect: `expand_mentions` opens
`root.join(path)` and names the block with the absolute path it actually read,
and `workspace_files` reports each file relative to `cwd` in the platform's
form, which is what the menu hands back for the reader to type.

* the `<file name="...">` expectation is now built with `Path::join` instead of
  a pasted `/`;
* the trailing-full-stop case holds one invariant on both platforms — the stop
  reaches the filesystem instead of being trimmed — and says what that costs on
  each: Win32 strips trailing dots, so `note.md.` resolves and the block names
  it with the stop still on it (a trimmer would have produced `note.md` and left
  the stop outside the tag); on POSIX it names nothing and the token stays as
  typed. The assertion is kept, not deleted;
* the walk's listings and its pruning checks compare by `Path`, so
  `starts_with("target")` is a component test. The previous string form was not
  merely wrong on Windows: it passed vacuously, so a regression that listed
  `target` would have gone unnoticed there.

Verified on Windows (this host): `cargo test -p future-tui` is
1210 + 6 + 8 + 1 passed, 0 failed; fmt and clippy clean. Each fixed assertion is
also shown to still catch its own regression — a pasted separator, a trimmed
full stop, and `target` no longer pruned each turn the test red again. The
`#[cfg(not(windows))]` branch was typechecked by flipping the cfgs and building
without running; its behaviour is not exercised on this host, so Linux and macOS
confirm it.
@huichen
huichen enabled auto-merge (squash) October 26, 2026 05:56
@huichen
huichen merged commit 5c0aef5 into main Oct 26, 2026
21 checks passed
@huichen
huichen deleted the pr/huichen branch October 26, 2026 06:16
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