Skip to content

perf(ci): run the Rust test lanes on cargo nextest; fix the host heal fixtures - #1614

Merged
huichen merged 7 commits into
mainfrom
pr/huichen
Nov 14, 2026
Merged

huichen merged 7 commits into
mainfrom
pr/huichen

Conversation

@huichen

@huichen huichen commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

The Rust test lanes in CI move from cargo test to cargo nextest: every test runs in its own process, one hanging test no longer blocks the rest of the lane, and the job reports per-test timings. scripts/ci/setup-rust.mjs installs the pinned binary, and the host heal fixtures now install their own mock Agent channel instead of borrowing one from whichever test ran first.

Commits

  • perf(ci): run the Rust test lanes on cargo nextest
  • test(host): install the mock Agent channel in the heal fixtures that borrow it
  • test(host): keep the fixture helper as public as its neighbours
  • perf(ci): drop the nextest profile file; the default already has no deadline

Verification

Local, pinned toolchain (rust-toolchain.toml -> rustc 1.99.1), ulimit -n 8192:

  • cargo fmt -p future-host -- --check -> clean
  • cargo clippy -p future-host --all-targets -- -D warnings -> clean
  • cargo test -p future-host --lib -> 2254 passed, 0 failed, 15 ignored (444.75s)
  • node --check scripts/ci/rust-checks.mjs, node --check scripts/ci/setup-rust.mjs -> clean
  • All five pinned cargo-nextest 0.9.152 release archives were downloaded and their sha256 compared against NEXTEST_ASSETS: five of five match, including the universal Apple asset shared by both Apple triples.
  • The three phases rust-checks.mjs now emits were executed with the real pinned cargo-nextest 0.9.152 against -p future-logging: nextest list -E 'not binary(=gui_main_thread_drive)' parses the filter, nextest run --locked --no-tests=pass --no-run --timings ... writes target/cargo-timings/cargo-timing.html, and nextest run --locked --no-tests=pass --no-fail-fast ... -- --skip remote reports 6/6 passed. The -- filter passthrough and --no-tests=pass are both accepted.

Notes

  • No executable doctest is dropped: every doc code fence in this workspace is tagged text, ignore or json, so cargo test --doc compiles zero tests.
  • desktop/src-tauri's gui_main_thread_drive target is harness = false and speaks no listing protocol, so it is excluded from the nextest selection and still run through cargo test --test gui_main_thread_drive whenever futureos is in the package set.
  • nextest adds no per-test deadline: a slow-but-passing test is reported SLOW and still passes, which keeps the old cargo test behaviour.
  • The install lives in setup-rust.mjs rather than a workflow step because .github/workflows/ edits need the workflow OAuth scope the maintainer's token does not carry.

User-visible changes

  • CI only; no product behaviour change for end users. Developers see the Rust lanes reported per test (PASS / FAIL plus per-test timings) instead of libtest output, the Rust jobs download a checksum-pinned cargo-nextest binary during setup, and cargo nextest becomes a hard requirement for reproducing a Rust lane locally. Rollback: revert a976672be (the profile-file removal in c9d4f139d belongs to the same change).
  • Test isolation changes shape: one process per test means a test that relied on process-global state shared with a neighbour can now fail or contend. The two host heal fixtures that did (host/src/agent_bridge/import.rs) are fixed here in 24e217c6e.

`cargo test` serializes test binaries: libtest runs one binary at a time, and
`--no-fail-fast` only continues to the next binary after a failure. nextest
schedules every test from every binary in one pool, which is what the lane was
paying for.

`rust-checks.mjs` keeps its contract: the same package selection, the same
`--no-fail-fast` and libtest filter semantics (nextest emulates the arguments
after `--`, so `remote` / `--skip remote` pass through unchanged), the Host Linux
branch through `host-tests.py --with-broker --suite` untouched, and the fmt and
clippy phases as they were. `build` becomes `nextest run --no-run` and still
forwards `--timings` to the cargo build, so target/cargo-timings keeps uploading.

Two nextest behaviours are pinned rather than assumed:

- `--no-tests=pass`, because libtest exits 0 when a filter matches nothing.
- `desktop/src-tauri`'s `gui_main_thread_drive` target is `harness = false` and
  speaks no listing protocol, so nextest exits while enumerating it. Only that
  binary is filtered out of the nextest selection, and its target is run through
  `cargo test` afterwards, so that test still runs.

`.config/nextest.toml` keeps `cargo test`'s absence of a per-test deadline:
nextest's default profile terminates a test after two 60 s slow periods.

`setup-rust.mjs` installs the pinned nextest (prebuilt, digest-checked) because
nothing else can: editing `.github/workflows/` needs the `workflow` OAuth scope
the maintainer's token does not carry. The install is gated on `CI_PACKAGES`,
which only rust-ci.yml sets, so release and fixture jobs that share this script
do not download a tool they never use. A missing nextest is a hard failure --
there is deliberately no silent fallback to `cargo test`.
…borrow it

Three `agent_bridge::import` fixtures assert on the healed title after
`import_one`, whose heal path asks the Agent for the session's first message.
They passed only because an earlier test in the same process had installed the
fixture Channel runtime as a side effect: alone under `cargo test`

    cargo test -p future-host --lib -- --exact \
      agent_bridge::import::tests::import_one_syncs_an_agent_name_into_a_stale_title

panics with `Entry must configure the Agent channel runtime before starting
services`, and one process per test (`cargo nextest`) made all three fail
deterministically. The suite is only green while the order happens to help.

Each fixture now installs what it needs. Two measured dead ends are recorded on
`mock_agent_without_reset` rather than in the tests: calling `mock_agent()`
there wipes the shared script and truncates a neighbour's stream (three
neighbours then hung for over 60 s), and holding the fixture lock across a
reader's body serializes the module behind one stuck reader. Installing the
runtime and the mock server and dropping the guard is what keeps both the
one-process run and the one-process-per-test run green.
clippy's `-D dead-code` on the Rust check lane builds `future-host`'s library
without its test targets (`-p future-cli -p futureos --all-targets`), where a
`pub(crate)` fixture that only `#[cfg(test)]` code calls is unused. `mock_agent`
and `mock_agent_with_cleanup` are `pub` for the same reason; this matches them.
Measured with the lane's own shape: `cargo clippy -p future-cli -- -D warnings`
failed before this commit and passes after it.
…eadline

The profile added in a976672 pinned `slow-timeout = { period = "300s" }` on the
belief that nextest's default terminates a test after two 60 s slow periods.
Measured on 0.9.152 with a test that sleeps 150 s and no profile file: it is
reported `SLOW [> 60.000s]`, then `SLOW [>120.000s]`, then `PASS [ 150.012s]`.
Nothing terminates, so the file changed no behaviour and only added a knob to
maintain. The measurement now lives as a comment next to the nextest arguments
instead, which is where a reader of the lane will look.
@huichen
huichen enabled auto-merge (squash) November 14, 2026 20:26
@huichen
huichen merged commit d78ab8c into main Nov 14, 2026
51 checks passed
@huichen
huichen deleted the pr/huichen branch November 14, 2026 20:50
huichen added a commit that referenced this pull request Nov 15, 2026
… nextest

Local iteration is Cargo, and two settings were leaving money on the table.

`dev`/`test` kept Cargo's default `debug = 2` (full type and variable
debuginfo). Line tables are all a panic backtrace needs for `file.rs:LINE`,
so `debug = 1` keeps a failing test's location and halves the artefacts:

    cargo build -p future-agent, cold, 32-core Mac
      default  50 s  2,608 MB in target/debug
      debug=1  37 s  1,911 MB
    cargo nextest run -p future-agent --no-run, cold
      default  79 s  4,179 MB
      debug=1  64 s  3,261 MB
    incremental rebuild after a one-line edit: 601 ms vs 612 ms (unchanged)

`debug = 0` is not used: it was measurably slower cold than `1` (44 s), because
rustc then redoes work it would otherwise reuse, and it drops backtraces to
`??`. Line coverage is unaffected — `cargo llvm-cov` on `future-config` reports
the same 135 lines found / 114 hit (84.4%) under both levels, because llvm-cov
maps hits through exactly these line tables.

`make test-*` now go through scripts/run-rust-tests.mjs, which runs cargo
nextest with one process per test and falls back to `cargo test` when nextest
is not installed, so a fresh clone still works before anyone installs it. This
mirrors CI, which #1614/#1615 already moved to nextest; measured warm on this
workspace: `future-goal` (1301 tests) 8 s against 50 s for `cargo test
--no-fail-fast`, because libtest serialises per test binary and lets the slowest
one set the lane's wall time. `test-desktop-rust` stays on `cargo test`:
`desktop/src-tauri`'s `gui_main_thread_drive` target is `harness = false`, so
nextest exits while enumerating it.
huichen added a commit that referenced this pull request Nov 15, 2026
…plans, markdown fences (#1616)

* feat(choice): answer cards on remote desktop, and carry the pick into the queue

Steps 5 and 7 of docs/design/choice-cards.zh-CN.md §11, the two the first
pass left undone.

Remote desktop (§5.4, step 5). The peer drew the card already — it goes
through the same `MessageBlock` — but nothing could be clicked: the answer
lived only in the local composer. `RemoteComposer` now keeps it in its own
draft, offers it as a chip above the field, folds it into the sent text in
`sendNow` (the one path that puts text on the wire), and exposes
`selectChoice` so the transcript can write a pick back. The disable
conditions are the part that matters: `hasDraft` counts the answer, because
`(!text.trim() && uploads.length === 0)` would otherwise keep Send grey for
a reader who has answered and typed nothing — the exact bug the design
records in §5.2.1.

Queue (§5.8, step 7). A queued message drawn from a card now carries the
pick, not just the sentence it wrote. `QueuedRunState` grows a `choice`
field beside `attachments` — the same precedent — so the row can offer the
card's other options instead of asking the reader to re-type a sentence.
On the desktop and the phone the chip *is* the button: those rows already
have a pencil for their words, and a second one a few pixels away meaning
something else is the ambiguity the whole design exists to remove. Changing
a pick rewrites the bracketed head of the text and leaves whatever the
reader typed after it alone, so `edit_queued_run` stays the one path.

Wire: `RpcCommand.choice`, `QueuedRunChoice`, and an `edit_queued_run`
that carries the pick alongside the new text. Absent means "no change";
an empty `selectedIds` is a real answer and stores the card without a pick.

* docs(choice): record steps 1–8 as implemented, and whitelist the prompt asset

The design doc's status line still said steps 1–3, written before the remote
and queue work landed. It now names 1–8 and says plainly that step 9 — the
visual regression that swaps the injected prototypes for the real
components — is the one left.

Two §11 entries described the implementation differently from what shipped,
so they are corrected rather than left to mislead the next reader: the queue
row opens its options through a portal-positioned `SelectMenu` (not
`ChoicePopover`, which is positioned inside the editor's wrapper), and the
phone's `ChoiceSheet` is owned by `ComposerDock` because a sheet is a `Modal`
and does not belong inside a list of rows.

`check-docs` was failing on main because `agent/src/prompt/choice.md` — a
compiled prompt asset loaded through `include_str!`, like its four
neighbours — was never added to the placement whitelist.

* test(choice): pin the two things the design says must not break

No production code changes — the assertions the first pass owed.

Remote (step 5). The acceptance is not "the card has a button", it is "a pick
goes out with nothing typed". `hasDraft` is what decides that, so the test
that guards it was mutated to prove it: dropping `choice !== null` from
`hasDraft` turns exactly one test red — "is sendable with nothing typed" —
and restoring it brings back 89/89. Mutating the send order (`[answer] words`
→ `words [answer]`) reddens the other one. Both are state assertions, not
screenshots.

Drafts written before the answer field existed now have two cases. They are
built the way this build actually wrote them — save through the public API,
delete the `choice` key — rather than hand-written JSON, so the test cannot
drift from the real envelope. A loader that demanded the key reddens both,
plus the two older shape tests.

Queue (step 7), both panels rather than one:

- Wire compatibility: absent `choice` stays `undefined` (never an invented
  empty answer), a malformed answer is dropped, and an answer with no option
  left to switch to is not offered — because a chip that opens an empty list
  is worse than no chip. A mutant that turns absent into `{}` reddens five
  tests across the two surfaces.
- Serialized shape: `undefined` does not survive JSON, so a relay writes the
  same bytes it always wrote. Asserted on `JSON.stringify`, not on the parsed
  key list, which would pin an in-memory detail the `attachments` precedent
  already settles the other way.
- Render, desktop: the chip is a BUTTON carrying one non-pencil icon, it
  opens the card's own rows, and picking returns the whole answer (not just
  an id — the question and the other options have to survive). The row's own
  pencil and bin stay exactly one each. Swapping the chevron for a pencil
  reddens that, which is the point: two pencils a few pixels apart meaning
  different things is the ambiguity the design exists to remove.
- Render, phone: same constraint on the separate implementation — one chip,
  the row's `send-queue-edit` and `send-queue-remove` untouched. Renaming the
  row's pencil reddens it.

Mobile queue parsing had zero `choice` coverage before this; it has the same
three cases now, and the pre-existing "rows come back in the session's own
order and shape" test turned out to guard the invariant too.

* refactor(choice): one signature for a changed queued answer

The desktop panel handed a change up as the whole answer; the phone handed up
the picked ids and rebuilt the object from the row. Same name, two meanings —
the kind of drift that makes the next change wrong on one surface only.

The object wins. An id list cannot gain a field (a note attached to an answer,
say) without the signature changing again, and rebuilding from the row on the
phone silently dropped whatever the caller knew and the row did not. No dual
signature is kept: this is an internal handoff with no outside consumer, and
accepting both shapes would let the mistake be written again.

Two assertions, one per surface, and each proves the shape rather than the
behaviour: `Array.isArray(answer)` is false and the object carries the card's
question and every option. Reverting either side to ids reddens exactly its own
test — checked both ways. Behaviour alone was not enough to lock this: a handler
that rebuilt from the row still passed, which is precisely the bug the change
removes.

* perf(build): cut local build cost with line-tables-only debuginfo and nextest

Local iteration is Cargo, and two settings were leaving money on the table.

`dev`/`test` kept Cargo's default `debug = 2` (full type and variable
debuginfo). Line tables are all a panic backtrace needs for `file.rs:LINE`,
so `debug = 1` keeps a failing test's location and halves the artefacts:

    cargo build -p future-agent, cold, 32-core Mac
      default  50 s  2,608 MB in target/debug
      debug=1  37 s  1,911 MB
    cargo nextest run -p future-agent --no-run, cold
      default  79 s  4,179 MB
      debug=1  64 s  3,261 MB
    incremental rebuild after a one-line edit: 601 ms vs 612 ms (unchanged)

`debug = 0` is not used: it was measurably slower cold than `1` (44 s), because
rustc then redoes work it would otherwise reuse, and it drops backtraces to
`??`. Line coverage is unaffected — `cargo llvm-cov` on `future-config` reports
the same 135 lines found / 114 hit (84.4%) under both levels, because llvm-cov
maps hits through exactly these line tables.

`make test-*` now go through scripts/run-rust-tests.mjs, which runs cargo
nextest with one process per test and falls back to `cargo test` when nextest
is not installed, so a fresh clone still works before anyone installs it. This
mirrors CI, which #1614/#1615 already moved to nextest; measured warm on this
workspace: `future-goal` (1301 tests) 8 s against 50 s for `cargo test
--no-fail-fast`, because libtest serialises per test binary and lets the slowest
one set the lane's wall time. `test-desktop-rust` stays on `cargo test`:
`desktop/src-tauri`'s `gui_main_thread_drive` target is `harness = false`, so
nextest exits while enumerating it.

* perf(ci): reclaim the Actions cache quota and document build-speed tooling

The repository-wide Actions cache quota is 10 GB and only `refs/heads/main`
entries are restorable, so a per-ref entry is pure liability: it takes quota
nobody else can read and evicts the entries that were hitting.

Measured 2026-11-15: 27 entries / 10.19 GB, of which 21 entries / 6.40 GB were
`node-cache-*` written by actions/setup-node with `cache: npm`. That keys the
tarball by ref, so each PR wrote its own ~318 MB (Linux) + ~305 MB (macOS) copy
— once per closed PR, plus one on `dev-huichen` — while the six `v0-rust-*`
entries the Rust lanes actually restore (0.48–0.94 GB each) were being evicted
to make room.

scripts/ci/prune-node-caches.sh lists those entries and deletes them with
`--apply`. Deleting a cache needs only `repo` scope, not `workflow` scope, so it
runs on a machine whose token cannot push workflow edits. Applying it took the
total from 10.19 GB to 3.79 GB with all six Rust entries intact.

The durable fix — stop writing per-ref npm caches — belongs in the workflow
(setup-node without `cache: npm`, or saving only on main), because `npm ci` still
measures 27–88 s per TypeScript job and the cache is worth keeping where it can
be shared. That change needs `workflow` scope this machine does not have.

scripts/dev/prune-target-incremental.sh reclaims target/debug/incremental, which
is regenerable accelerator state and was 67 GB of a 148 GB `target/` on a volume
down to 54 GB free; it refuses to run while a cargo/rustc process is alive.
Deleting it cost one cold rebuild (5.8 s for `cargo check -p future-config`).

Documents both scripts, the profile levels, `--profile local` and the nextest
fallback in build-and-install.md/.zh-CN.md, and the quota arithmetic in
ci.md/.zh-CN.md.

* style(desktop): order the choice-card imports

* perf(ci): make the npm-cache and Windows-agent plans executable

Both remaining CI items were prose with no numbers or file coordinates, so
whoever picks them up had to re-investigate. Write them as checklists against
this tree, and land the half that is not blocked on a `workflow` token.

Cache quota: the seven `cache: npm` sites are enumerated with file and line, and
the durable shape is a restore-only `actions/cache/restore` step whose key omits
`github.ref`, because a per-ref write is invisible to every other PR. Removing
the cache outright is explicitly ruled out: `npm ci` cost 883 s over 22
invocations (mean 40.1 s, max 88 s) in run 43637520669.

Runner cost: measured run 43637520669 at 22.4 min wall clock over 51 jobs, with
peak concurrency 20 and a single job -- Rust Windows test / agent -- occupying
21.9 of those minutes at Build 245 s + Tests 981 s. Its 981 s predates nextest
(1024 s in run 43635381613). Collapsing crates per OS would cost 35.5/55.5/35.6
min, worse than today, so the plan shards that one lane instead: 2-way takes the
run to ~14 min, 3-way to ~11 min.

Implemented here, since neither needs workflow scope: `shardedTestGroups()`
publishes a second matrix the Windows caller alone consumes (the three OS callers
share one `rust_tests` JSON, so sharding it would hit all three), and
`rust-checks.mjs` turns `CI_TEST_SHARD=n/N` into `--partition hash:n/N`,
rejecting anything that is not n/N. Verified: `--partition` splits 7 tests 3+4
with no overlap, and the invalid form exits 1.

* fix(markdown): read a quoted document fence as nested

A reply that quotes a whole Markdown file inside a ```markdown fence puts
another fence (`futureos-choice`) inside it, and CommonMark gives a fence no
way to nest: the inner run closes the outer block. Everything the author meant
to be inside it was then parsed as the reply's own Markdown — measured on a
real reply, the list under the quoted file became untitled bullets in the
middle of the message, the heading after it vanished into a second empty code
block, and a shell transcript below was read as prose with its `$(…)` turned
into an inline formula.

The author's intent is unambiguous, so read those fences as nested. The repair
is applied to the source and is length-preserving: instead of lengthening the
outer fence past its body, whose inserted characters would shift every mdast
offset the streaming projector and `splitStreamingMarkdown` slice by, the outer
delimiters are swapped to tildes of the same width. A backtick run is content
inside a tilde fence and vice versa, so the characters stay at their offsets
and only the grouping changes; delimiters are never part of the rendered code,
so the block still reads exactly as written.

Only fences whose info string names a document language (`markdown`, `md`) get
the treatment — in any other language ``` is ordinary text, which CommonMark
already handles. Applied in `parseMdast`, the single entry every parse path
shares, and in the desktop streaming processor, which parses on its own.

* test(tui): run the empty-detail driver test on a big-stack thread

`a_row_with_no_body_keeps_the_detail_pane_a_box` aborted with a stack
overflow on both the Linux and the Windows `tui-cli` legs of run
43673617419 (jobs 132689090751 and 132689090757) while the macOS leg
passed, and a rerun reproduced it.

Nothing recurses: the test is one async fn, and a debug build lays every
local and every awaited future of it into a single ~1 MiB frame — the
same figure measured at 1, 2 and 4 MiB of stack, so it is a fixed frame
and not an unbounded expansion. Its steps then need as much again, which
is over the 2 MiB a `cargo test` thread gets; the per-frame cost of the
debug codegen is what puts Linux and Windows over it and macOS under it.
No product code is involved, and `tui/src/rpc/types.rs` (the only TUI
change in this PR) is not on the path.

Run the body on a thread with a 32 MiB stack, the way
`live::tests::with_big_stack` already does for `Live::apply`, whose frame
is bigger still. The body, its assertions and its waits are unchanged;
the test now passes with the test thread's stack forced down to 1 MiB,
which is what aborted before.
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