acpmux tests: library unit test threads get the daemon's worker stack (base red: 22 clap tests overflow since #27603)

Merged
LA
5d ago
+52-0

Summary

Base red on feat since da664a2fc79 (#27603): 22 acpmux library unit tests abort with "has overflowed its stack". They are clap parse tests: cli::command::help_contract_tests (8), cli::help_examples, cli::mesh_control, cli::unknown_command, cli::unknown_flag and config_set_tests. The run that showed them is the #26662 Rust run (hq run 41243245910). At feat 902ddaca the 8 help_contract_tests fail alone too (job a59dd7ee650ffb7c9bab6dcb).

Culprit (first-parent bisect on Linux, each run rebuilt acpmux for its own commit and listed its own test count): green at ba52c5169203 (job f2fd7abb...-class run clapc-18), red at da664a2fc79 (#27603, "cmux vm: run --sync, scoped VM tokens, in process in the NEXT bundle", clapc-17). The 12 points between the known good b6eb8491 and the bad 4f957edc are in the bisect table below.

Cause. #27603 changes no acpmux code. It links the cmux-vm crate (workers/cmux-vm/cli) into cmux-tui, and that workspace asks for clap's env feature (clap = { features = ["derive", "env"] }). Cargo unifies features across the build, so acpmux's clap gets env too. Before, no crate in the cmux-tui workspace enabled it (acpmux asks only for derive). With env, clap's argument types are larger, and the unoptimized clap code of the cli parse tests no longer fits on libtest's 2 MiB test thread.

Why only tests abort. The daemon runs this code on 8 MiB runtime workers (cli::entry::WORKER_STACK_BYTES), and release builds are optimized. #29511 gave the integration-test binaries that stack (tests/support/daemon_env.rs), but not the library's own unit-test binary.

Fix. src/test_stack.rs (#[cfg(test)] only, so only the library's unit-test binary has it) sets RUST_MIN_STACK to WORKER_STACK_BYTES from an initializer the loader runs before main, unless the environment already names one. It uses the same mechanism daemon_env.rs uses before main. Production code is unchanged.

Testing

runrefwhereresult
red: test_stack::3cf5f5870471 (test only)Linux, job dc39b367ada18307999df877the new test aborts: stack overflow
green: test_stack::head f1794eca3796Linux 38256daf188b6212fa80f129; macOS aws-m4pro-6 a4d0ffd43f43407980a5e367pass, pass
green: cli::headLinux c52592d709b9d52db4642ba3; macOS aws-m4pro-2 ae593549233d4577c87752ffall 469 acpmux cli tests pass on each OS (incl. the 8 help_contract_tests), no stack overflow
clippy -D warningsheadLinux db473ce5dcbf58f2ff46801dpass

The cli:: filter also matched two cmux-tui tests (not acpmux): cli::cloud_help::tests::help_lists_exactly_the_offered_cloud_verbs and cli::tests::remote_cli_docs::cloud_help_lists_every_offered_cloud_action. They fail on both OSes. This PR touches only the acpmux crate's unit-test binary, so it cannot reach them. They are a separate cmux-tui red.

Bisect (cli::command::help_contract_tests, Linux, first parent b6eb8491..4f957edc, newest first):

pointcommitresult
13a87eed838 FAIL (stack overflow)
14-171092eaef, 5d6bb23b, 23bdcfc9, da664a2f8 FAIL each
18-26ba52c516 ... 3d34450a8 pass each

Observed / Not run

Observed: everything above, on fleet Linux and macOS. Not run: the full workspace suite at this head.

Changelog

none

Proof

No capture: a test-environment change.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.


Summary by cubic

Fixes the 22 acpmux library unit tests that abort with stack overflow by giving their threads the daemon's worker stack (cli::entry::WORKER_STACK_BYTES).

  • The overflow came from #27603 linking cmux-vm into cmux-tui, whose clap asks for the env feature; Cargo unifies that into acpmux's clap, and the larger clap types push the unoptimized cli parse tests past libtest's 2 MiB thread.
  • test_stack.rs (cfg(test) only) sets RUST_MIN_STACK to the worker stack size from a loader-run initializer before main, unless the environment already names one.
  • Adds a regression test needing about 3 MiB of stack to verify the unit-test thread has it.
  • Production code is unchanged; the initializer compiles only into the library's unit-test binary.

All 469 acpmux cli tests pass on Linux and macOS, including the 8 help_contract_tests; the new stack test passes and clippy -D warnings is clean.