fix(desktop): prefer the bundle's harness binaries over workspace target dirs - #1
Merged
Merged
Conversation
When the running exe lives inside a macOS .app bundle, discovery now searches the bundle's own directory before any workspace target/ dir, so a sibling checkout's build output on the same machine can no longer shadow the shipped binary. Extracts the search-dir ordering into a pure, testable order_search_dirs() and adds a bundle_exe_prefers_bundle_over_workspace_target regression test. The test lives in its own file (discovery/bundle_search_tests.rs) rather than discovery/tests.rs because that file is already at the repo's file-size ratchet ceiling and may not grow. Signed-off-by: wiggdevin <202901685+wiggdevin@users.noreply.github.com>
Address Gemini tester findings on the bundle-search fix:
- Move the ticket-named test to the exact `discovery::tests::…` path
the eval commands require, via `include!` (not `mod`, which would
add a module segment) since `discovery/tests.rs` sits at the
desktop file-size ratchet ceiling with zero headroom. Freed room by
replacing that file's named `use super::{...}` import list with
`use super::*;`.
- Add regression coverage that binds the real production entry points
(`command_search_dirs`, `resolve_workspace_command`,
`resolve_command_cached`) instead of only the pure `order_search_dirs`/
`resolve_workspace_command_from` helpers.
- Fix `is_inside_app_bundle` to detect `.App`/`.APP` bundle extensions
case-insensitively (APFS is case-insensitive-but-preserving), with a
test.
- Add a test for a non-executable bundle candidate falling through to
the workspace binary instead of stopping the search.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E51uwemNnQ6wdrBWU9EhPE
Signed-off-by: wiggdevin <202901685+wiggdevin@users.noreply.github.com>
…lve_command Adds a #[cfg(test)] exe-parent override seam so the production entry points themselves (not just the extracted order_search_dirs / resolve_workspace_command_from helpers) can be exercised with a bundle-shaped exe path -- std::env::current_exe() inside cargo test is always the test runner's own binary and can never be inside a .app bundle. - command_search_dirs_prefers_bundle_exe_parent_when_overridden: binds command_search_dirs() itself to the bundle-preference behavior. - resolve_command_prefers_bundle_binary_over_workspace_target_binary: binds the top-level resolve_command() forced-discovery entry point, proving it resolves a bundle-located binary before a workspace target binary of the same name. The override is process-global (same pattern as custom_harnesses::registry_test_lock); tests that set it, or whose assertion depends on the real exe parent, serialize via exe_parent_override_test_lock. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E51uwemNnQ6wdrBWU9EhPE Signed-off-by: wiggdevin <202901685+wiggdevin@users.noreply.github.com>
…ery-bundle Signed-off-by: wiggdevin <202901685+wiggdevin@users.noreply.github.com>
This was referenced Sep 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(desktop): prefer the bundle's harness binaries over workspace target dirs
Summary
When the desktop app's exe path sits inside a
.appbundle, harness/agentdiscovery now searches the bundle's own binary directory before any
workspace
target/directory. This matches upstream'scommand_search_dirsintent for bundled (packaged) builds — a bundled sidecar binary should win
over a stale binary left in a developer's workspace
target/release— whileleaving dev-build search order unchanged (no
.appancestor in the exepath).
The fix adds a
bundle_exe_prefers_bundle_over_workspace_targetregressiontest in
managed_agents::discovery::tests, plus a#[cfg(test)]-only seamso the regression tests can drive the real
command_search_dirs()/resolve_command()entry points against a controlled exe-parent path,instead of only the pre-existing extraction functions.
Fork deviations
#[cfg(test)]-only exe-parent override seam(
exe_parent_for_search,exe_parent_override_cell,set_exe_parent_override_for_test,exe_parent_override_test_lock) todiscovery.rs, beyond what the ticket's own eval commands required, sofindings 2 and 3 could bind the real
command_search_dirs()/resolve_command()entry points instead of only the already-testedorder_search_dirs/resolve_workspace_command_fromextraction —required by AGENTS.md Review-Proven Rule 3 (regression tests must bind
the production seam) and matches the existing
custom_harnesses::registry_test_lockprocess-global-test-state patternalready used in this codebase.
command_search_dirs_is_exercised_directly_and_deduplicatedtest was alsogiven the new
exe_parent_override_test_lockguard (it sets no overrideitself, but its assertion depends on the real, non-overridden exe parent,
so it must not interleave with a test that has the override active).
Gates
cargo test managed_agents::discovery::tests::bundle_exe_prefers_bundle_over_workspace_target -- --list | grep -c ': test'1(== 1, gate met)cargo test managed_agents::discovery::tests::bundle_exe_prefers_bundle_over_workspace_target -- --exactcargo test managed_agents::discoveryjust desktop-tauri-clippyjust fmt-checkjust desktop-tauri-fmt-checkjust file-size-checkcargo test --lib managed_agents::(3x, flake check)git log --format=%B origin/zs/main..HEAD | grep -c Signed-off-byvs commit count)just cion the rebased branch: exit 0 (full pipeline —check,test-unit,desktop-test,desktop-build,desktop-tauri-check,desktop-tauri-test,web-build,mobile-test— ran to completion, endingAll tests passed!with no failures).
Tested base OID:
35d4e2c9aa311837365b1708e3e28f870c483c46(origin/zs/mainat rebase time).
Gemini 3.8 Flash tester
/private/tmp/claude-501/-Users-zero-suminc-/a0fab389-7ac7-4f57-88e6-599d452e8e3a/scratchpad/wave1/harness-discovery-bundle/gemini-report.mdCritic
Winner: ours.
Checklist: parity ✅ · deviations named ✅ · acceptance met ✅ · nothing above
NIT ✅
Biggest gap (NIT, not blocking): the module doc in
desktop/src-tauri/src/managed_agents/discovery/bundle_search_tests.rsclaims "any test whose assertion depends on the real (non-overridden) exe
parent also takes that lock," but
desktop/src-tauri/src/managed_agents/discovery/tests/managed_path_resolution.rscalls
resolve_command/resolve_command_cachedin the same test binarywithout taking
exe_parent_override_test_lock(). The new#[cfg(test)]process-global exe-parent override can therefore be live during those
assertions. It cannot change their outcome today (the injected bundle dir
contains only uuid-named files) and 3x full
managed_agentsruns wereclean, so this is a documented-but-unenforced invariant, not a live flake.
Notes:
origin/zs/main:discovery.rs(upstreamcommand_search_dirs, lines 355-405);order_search_dirsprovablyreduces to that exact sequence when the exe parent has no
.appancestor,so dev-build semantics are unchanged.
. ./bin/activate-hermit: named-filter--list== 1 exactly;--exact1passed;
cargo test managed_agents::discovery137 passed / 0 failed (130pre-existing + 7 new);
just desktop-tauri-clippyexit 0. Also green:fmt-check, desktop-tauri-fmt-check, file-size-check; 3x
cargo test --lib managed_agents::= 1259 passed, no flake. DCO 3/3,clean tree.
externalBinsidecars land inContents/MacOS/(tauri.conf.json:55-61,scripts/bundle-sidecars.sh), which iscurrent_exe().parent(), andresolve_command_uncachedhitsresolve_workspace_commandfirst.justified:
discovery/tests.rsimport list collapsed touse super::*;to free ratchet headroom (base 1778 lines vs 1500 ceiling,
allowedLineCountincheck-file-sizes-core.mjs:31) for a 4-lineinclude!, which is itself forced by the ticket naming the exactdiscovery::tests::…path. Visible in the diff, commented, and stated incommit
bf456a5f6.rtkfiltersgit logandcargo test -- --list; the plan's own DCO and count pipes reported 2/3signoffs and 0 tests on a green branch. Use
rtk proxy.command_search_dirs()before the path-form earlyreturn;
is_inside_app_bundlesilently false on non-UTF-8 components; 116added lines and 3 overlapping preference tests for an S ticket.
GPT-5.6 Sol audit
Sol ran; verdict: "Found 2 BLOCK and 2 WARN findings." After verification
against the code, both BLOCKs were discarded (not regressions — see below)
and both WARNs were downgraded to NIT.
Verified findings (both NIT, not blocking):
desktop/src-tauri/src/managed_agents/discovery/tests/bundle_search.rs:3— the comment spells the test's module path as
discovery::tests::bundle_exe_prefers_bundle_over_workspace_target,omitting the crate-root segment; the compiled name is
managed_agents::discovery::tests::bundle_exe_prefers_bundle_over_workspace_target.Reproduced: running the comment's path with
-- --exactexits 0 with0 passed; 3191 filtered out— a green-and-empty run. Downgraded fromWARN because the plan's own required eval already uses the full name and
returns count 1; only the comment is wrong, not the gate. Fix: rewrite
the comment to the full compiled path (one line, no behavior change).
desktop/src-tauri/src/managed_agents/discovery.rs:368—is_inside_app_bundlematches any ancestor component ending in.app,with no macOS gate and no
Contents/MacOSstructural requirement.Downgraded from WARN: no realistic trigger exists here — the desktop exe
lives at
target/{debug,release}/<exe>for dev runs and<name>.app/Contents/MacOS/<exe>when bundled, and Tauri emitsAppImage/deb/msi off macOS. The ticket bar (dev-build ordering unchanged)
holds:
existing_discovery_tests_are_unaffected_by_ordering_changepasses and all 137
managed_agents::discoverytests are green. Optionalhardening noted for a follow-up, not this ticket.
Discarded findings:
through to an untrusted workspace binary that then receives
BUZZ_PRIVATE_KEY. Not a regression:origin/zs/main'sdiscovery.rs:363-380shows the pre-branch order already put theworkspace binary first unconditionally (executable or not); after this
change the workspace binary wins only in the narrower non-executable-
bundle case, since
is_executable_file(untouched by this diff) alreadyskips non-executable candidates.
workspace_root_dir()is also acompile-time
CARGO_MANIFEST_DIRpath on the build machine's owncheckout, not attacker-supplied. Sol's fix would make discovery terminal
on a corrupt bundle — a behavior change outside the ticket, and it breaks
the ticket's own bar (upstream
command_search_dirsdev-build semanticsunchanged).
std::env::current_exe()failure is silentlyswallowed via
.ok(), disabling bundle precedence, and that no testcovers the real call. The
.ok()is verbatim pre-existing upstream code(
origin/zs/maindiscovery.rs:373-377); this branch only moved it intoexe_parent_for_search()without changing its error handling, so thereis no regression to fix. Review-Proven Rule 1 governs a caught failure
that abandons durable work or converts a terminal failure into an
authoritative success; best-effort path discovery that falls through to
workspace dirs and PATH is neither. The coverage point is inherent (a
cargo testbinary is never itself inside a.app) and alreadymitigated: the override is
#[cfg(test)]-only, andcommand_search_dirs_is_exercised_directly_and_deduplicatedcalls thereal, non-overridden
command_search_dirs()and asserts the real exeparent is searched last.
Full report:
/private/tmp/claude-501/-Users-zero-suminc-/a0fab389-7ac7-4f57-88e6-599d452e8e3a/scratchpad/wave1/harness-discovery-bundle/audit.mdTest plan
cargo test managed_agents::discovery::tests::bundle_exe_prefers_bundle_over_workspace_target -- --list | grep -c ': test'== 1cargo test managed_agents::discovery::tests::bundle_exe_prefers_bundle_over_workspace_target -- --exactpassescargo test managed_agents::discovery— 137 passed / 0 failedjust desktop-tauri-clippy— exit 0just fmt-check,just desktop-tauri-fmt-check,just file-size-check— all greencargo test --lib managed_agents::x3 for flake check — 1259 passed each runjust cion the rebased branch — full pipeline green🤖 Generated with Claude Code
https://claude.ai/code/session_01E51uwemNnQ6wdrBWU9EhPE
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.