Repository navigation
refactor: one worktree owner function, one built-meta lookup, and two follow-ups - #219
Conversation
Configs::find and find_optional had no caller, and nothing read Configs.here: both callers took .owner and fell back to their own workspace on any error. worktree::owner(here) does exactly that.
…::primary_dir Its body was crate::worktree::primary_dir(dir) with the same signature; the four callers call primary_dir, whose doc keeps the one sentence set_source's added (a set without an owner file stands for itself).
Six test helpers each joined meta{EXE_SUFFIX} to the profile folder and
asserted it was a file. meta_plugin::testing::built_meta() does it once, in
built_program_dir(), which already finds the folder only where that meta is.
A test run started inside a meta call (meta exec -- cargo test) inherited META_DEPTH, so every meta a test started counted the outer calls too and could refuse to run at the depth limit. The sandbox already removes the other META_* variables a surrounding shell or meta sets.
It has no hits on main (clippy --workspace --all-targets --all-features); the deny keeps a match-and-return from coming back where let-else says it.
|
No actionable comments were generated in the recent review. WalkthroughThe changes replace worktree owner lookups with ChangesWorktree Owner Resolution
Test Binary Resolution
Clippy Lint
Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Refactor Possibly related PRs
Suggested reviewers: Merge Risk:
|
…ther META_ variables meta_plugin's client module is behind the client feature, which testing doesn't enable, so cargo check -p meta_plugin failed on the constant.
… folder built_program_dir climbed every ancestor of the test executable, so with target/debug/meta missing it could take a stale target/meta or any meta higher up. It now looks only in the profile folder holding the test's deps/ (or build/<package>/<hash>/out/) and fails there, as the CARGO_BIN_EXE lookups it replaces did.
… built_meta() It joined "meta" to CARGO_BIN_EXE_meta-git's folder by hand, without the executable suffix.
+100 / −121 (net −21): production files and
Cargo.toml+35 / −67; test code and the test kit (meta_plugin/src/testing.rs,meta_mcp/src/test_support.rs, thehere.rstest module,tests/) +65 / −54. No behaviour change for users; the test kit's built-metalookup is now stricter (item 3).Follow-ups the recent cleanup pass left for after its PRs landed (they needed files other open PRs owned then). One commit per item, except: item 3 has three (the helper, the stricter lookup, the last site) and item 4 two (the change, then naming the variable as text so
meta_pluginbuilds on its own).What changes, and why each is obviously right
worktree::Configs→ oneworktree::owner(&Workspace) -> Workspace(meta_core).Configs::find(which only calledConfigs::find_optional) andfind_optionalhad no caller outside themselves, and nothing readConfigs.here. Both callers ofConfigs::of(plugin_worktreeinmeta_core/src/worktree.rs,in_worktrees_folderinmeta_cli/src/invoke.rs) took.ownerand fell back to their own workspace on any error.owner()does exactly that: the set's source checkout when the folder is in a set with an owner file and that checkout is a folder; its config, or an emptyWorkspaceat that folder when it has none; else, and on any error,here.WorkspacederivesDefault(every field already has one) so the empty owner is written..Default::default()instead of naming each field.config::set_source, a forwarder: its body wascrate::worktree::primary_dir(dir), same signature and return type. Its five callers wereConfigs::of(gone with item 1,owner()callsprimary_dir),config::workspace_meta_dirs,meta_cli'smain.rsandproject.rs, and one test; they callprimary_dir. The one sentence its doc added ("a set without an owner file stands for itself, as a second workspace can") moved toprimary_dir's doc.meta_plugin::testing::built_meta()for themetabuilt beside the tests. Seven places did it by hand: four helper functions (meta_mcp'suse_built_metaintest_support.rsandmeta()intests/cli.rs,meta_git_cli'suse_built_metain thehere.rstests andas_meta_startsintests/common/mod.rs) and three inline blocks (tests/races.rs,tests/where_sets_go.rs,tests/recursive_inventory.rs, the last without the.exesuffix). Each joinedmeta{EXE_SUFFIX}to a folder and asserted it was a file;built_meta()joins it tobuilt_program_dir(), which returns only a folder where thatmetais a file and fails with "build the workspace first" otherwise.Five of the sites took the folder of
CARGO_BIN_EXE_meta-git(four) orCARGO_BIN_EXE_meta-mcp(one), which is the test's profile folder, and failed whenmetawasn't there.built_program_dir()used to climb every ancestor of the test executable, so withtarget/debug/metamissing it could take a staletarget/metaor anymetahigher up. It now looks only in the test executable's own profile folder, the one holding itsdeps/(cargo before 1.100) orbuild/<package>/<hash>/out/(since), and fails there, so no site can pick up a differentmetathan before. New unit testbuilt_program_dir_never_takes_a_meta_from_above_the_profile(it fails onmain); the existing one for both cargo layouts still passes.Sandbox::commandclearsMETA_DEPTH. A test run started inside a meta call (meta exec -- cargo test) inherited it, so everymetaa test started counted the outer calls too and could be refused at the depth limit. The sandbox already removesMETA_WORKTREES,META_GITHUB_URLandMETA_PLATFORMfor the same reason; like them it is named as text, becausemeta_plugin'sclientmodule (where the constant lives) is behind a featuretestingdoesn't enable. New unit testa_meta_around_the_tests_does_not_reach_themchecks the command removes it (it fails onmain, where the variable is left alone).clippy::manual_let_elsein the workspace lint table. Measured onmain(c7f9c66) withcargo clippy --workspace --all-targets --all-features -- -W clippy::manual_let_else: 0 hits, so it costs no fixes and keeps match-and-return blocks from coming back wherelet … elsesays it.Deleted public items, and the search that proved them unused
meta_core::worktree::Configs(withfind,find_optional,of) andmeta_core::config::set_source.rg -w 'Configs|set_source'over this repo finds only the call sites changed here. Searched every repo that depends on meta's crates or binary as well (all local checkouts of the workspace's repos, nested ones included, withrg --no-ignore): no other use.meta_coreis a workspace library, not published.Checks (Linux arm64 build machine, head of this branch)
cargo fmt --all -- --check;cargo clippy --workspace --all-targets --locked -- -D warnings, with default features and with--all-features: clean.cargo check -p <crate> --all-targetsfor each crate on its own: clean.cargo test --workspace --locked --no-fail-fast: 675 passed, 0 failed (two more thanmain: the two new tests).bats tests/(at the previous head; this push changes only Rust test helpers, which bats doesn't use): 656 tests, none failed.Overlaps
meta_cli/src/main.rsis also touched by fix(meta_cli, meta_plugin): plugin update installs the release it names and keeps the old one on failure; versions compare by number #220 (plugin update fixes), in different hunks (update_plugincalls near lines 1330 and 1397; this PR changes one line near 1535).git merge-treeof the two branches is clean.Cargo.tomlis also touched by chore(main): release 0.4.0 #187 (release-please version bump), on different lines (this PR adds one lint to the lint table).Considered, not done
build.build-dir(test executables built apart fromtarget-dir): the shared lookup starts from the test executable, so it would look in the build dir. Two of the six former lookups (here.rs,meta_mcp'stest_support.rs) already worked that way onmain, so such a setup already failed those tests; nothing in this repo or its CI setsbuild-dir. Anchoring onCARGO_BIN_EXE_*again would bring back per-site copies.meta_cliintegration tests that useenv!("CARGO_BIN_EXE_meta")are left: that is their own crate's binary, which cargo names directly.path_with_built()helper (built folder in front ofPATH): the sites buildPATHfrom different bases (the process's, the command's own, or with a fixture folder in front), so one helper would need parameters; not simpler.forbidinstead ofdenyfor the panic lints: a workspace-tableforbidcollides with the file-level#![expect]s in 16 integration-test files and the feature-gated test kit (meta_plugin/src/testing.rs), error E0453. Moving the lints to the crate roots ascfg_attr(not(test), forbid(...))is a separate change.Sandbox::commandcould also clearMETA_EXE; every test that needs it sets it, and nothing showed a failure from an inherited one, so it is left.Not verified
Summary by CodeRabbit