Skip to content
This repository was archived by the owner on Dec 3, 2026. It is now read-only.

refactor: one worktree owner function, one built-meta lookup, and two follow-ups - #219

Merged
gold-silver-copper merged 8 commits into
mainfrom
refactor/audit-followups
Nov 20, 2026
Merged

gold-silver-copper merged 8 commits into
mainfrom
refactor/audit-followups

Conversation

@gold-silver-copper

@gold-silver-copper gold-silver-copper commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

+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, the here.rs test module, tests/) +65 / −54. No behaviour change for users; the test kit's built-meta lookup 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_plugin builds on its own).

What changes, and why each is obviously right

  1. worktree::Configs → one worktree::owner(&Workspace) -> Workspace (meta_core).
    Configs::find (which only called Configs::find_optional) and find_optional had no caller outside themselves, and nothing read Configs.here. Both callers of Configs::of (plugin_worktree in meta_core/src/worktree.rs, in_worktrees_folder in meta_cli/src/invoke.rs) took .owner and 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 empty Workspace at that folder when it has none; else, and on any error, here. Workspace derives Default (every field already has one) so the empty owner is written ..Default::default() instead of naming each field.
  2. Drop config::set_source, a forwarder: its body was crate::worktree::primary_dir(dir), same signature and return type. Its five callers were Configs::of (gone with item 1, owner() calls primary_dir), config::workspace_meta_dirs, meta_cli's main.rs and project.rs, and one test; they call primary_dir. The one sentence its doc added ("a set without an owner file stands for itself, as a second workspace can") moved to primary_dir's doc.
  3. One meta_plugin::testing::built_meta() for the meta built beside the tests. Seven places did it by hand: four helper functions (meta_mcp's use_built_meta in test_support.rs and meta() in tests/cli.rs, meta_git_cli's use_built_meta in the here.rs tests and as_meta_starts in tests/common/mod.rs) and three inline blocks (tests/races.rs, tests/where_sets_go.rs, tests/recursive_inventory.rs, the last without the .exe suffix). Each joined meta{EXE_SUFFIX} to a folder and asserted it was a file; built_meta() joins it to built_program_dir(), which returns only a folder where that meta is a file and fails with "build the workspace first" otherwise.
    Five of the sites took the folder of CARGO_BIN_EXE_meta-git (four) or CARGO_BIN_EXE_meta-mcp (one), which is the test's profile folder, and failed when meta wasn't there. built_program_dir() used to climb 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 test executable's own profile folder, the one holding its deps/ (cargo before 1.100) or build/<package>/<hash>/out/ (since), and fails there, so no site can pick up a different meta than before. New unit test built_program_dir_never_takes_a_meta_from_above_the_profile (it fails on main); the existing one for both cargo layouts still passes.
  4. Sandbox::command clears META_DEPTH. A test run started inside a meta call (meta exec -- cargo test) inherited it, so every meta a test started counted the outer calls too and could be refused at the depth limit. The sandbox already removes META_WORKTREES, META_GITHUB_URL and META_PLATFORM for the same reason; like them it is named as text, because meta_plugin's client module (where the constant lives) is behind a feature testing doesn't enable. New unit test a_meta_around_the_tests_does_not_reach_them checks the command removes it (it fails on main, where the variable is left alone).
  5. Deny clippy::manual_let_else in the workspace lint table. Measured on main (c7f9c66) with cargo 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 where let … else says it.

Deleted public items, and the search that proved them unused

meta_core::worktree::Configs (with find, find_optional, of) and meta_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, with rg --no-ignore): no other use. meta_core is 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-targets for each crate on its own: clean.
  • cargo test --workspace --locked --no-fail-fast: 675 passed, 0 failed (two more than main: 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

Considered, not done

  • A separate cargo build.build-dir (test executables built apart from target-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's test_support.rs) already worked that way on main, so such a setup already failed those tests; nothing in this repo or its CI sets build-dir. Anchoring on CARGO_BIN_EXE_* again would bring back per-site copies.
  • The meta_cli integration tests that use env!("CARGO_BIN_EXE_meta") are left: that is their own crate's binary, which cargo names directly.
  • A path_with_built() helper (built folder in front of PATH): the sites build PATH from different bases (the process's, the command's own, or with a fixture folder in front), so one helper would need parameters; not simpler.
  • forbid instead of deny for the panic lints: a workspace-table forbid collides 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 as cfg_attr(not(test), forbid(...)) is a separate change.
  • Sandbox::command could also clear META_EXE; every test that needs it sets it, and nothing showed a failure from an inherited one, so it is left.

Not verified

  • Not built locally on Windows or macOS; CI builds both. No platform-gated code changes.

Summary by CodeRabbit

  • Bug Fixes
    • Worktree commands now resolve the workspace they operate on more consistently. When a worktree set has no owner, it is treated as its own workspace; when a source workspace has no configuration, commands can fall back to the workspace configuration directory.
    • Orphan checks and project listings now use the primary workspace location when determining which workspace to inspect or display.

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.
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The changes replace worktree owner lookups with worktree::owner and primary_dir, centralize test lookup of the built meta executable, remove META_DEPTH from sandbox commands, and deny the manual_let_else Clippy lint.

Changes

Worktree Owner Resolution

Layer / File(s) Summary
Resolve worktree owners
meta_core/src/worktree.rs, meta_core/src/config.rs
owner replaces Configs and resolves the workspace used by worktree commands. Configuration source lookups call primary_dir directly, and Workspace no longer derives Default.
Use owner resolution in worktree callers
meta_cli/src/invoke.rs, meta_cli/src/main.rs, meta_cli/src/project.rs, meta_core/src/worktree.rs
CLI and plugin worktree callers use owner or primary_dir instead of Configs and set_source.

Test Binary Resolution

Layer / File(s) Summary
Resolve the built meta executable
meta_plugin/src/testing.rs
built_program_dir recognizes Cargo deps/ and build/.../out/ layouts. built_meta returns the executable path. Tests cover rejecting an executable above the recognized profile folder and removing META_DEPTH from sandbox commands.
Use built_meta in test helpers
meta_git_cli/src/here.rs, meta_git_cli/tests/*, meta_mcp/src/test_support.rs, meta_mcp/tests/cli.rs
Git CLI and MCP test helpers use built_meta instead of deriving the executable path from another binary or the build directory.

Clippy Lint

Layer / File(s) Summary
Deny manual_let_else
Cargo.toml
The workspace Clippy configuration denies the manual_let_else lint.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Possibly related PRs

  • gitkb/meta#174: Establishes the worktree set owner-file contract used by the worktree owner resolution changes.

Suggested reviewers: rluisb, mateodelnorte

Merge Risk: Minimal · up to 7f128

This refactor changes internal worktree owner resolution and test-binary lookup, with no identified user-facing behavior change or merge-blocking risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names a refactor and two test-support follow-ups. The changeset does include a single worktree owner function (worktree::owner replacing Configs) and one built-meta lookup (meta_plugin::test…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names a refactor and two test-support follow-ups. The changeset does include a single worktree owner function (worktree::owner replacing Configs) and one built-meta lookup (meta_plugin::testing::built_meta used across test files). It also touches set_source removal and the Clippy lint table, which the title does not mention. The title is an accurate, partially complete summary of the main changes, and it is not misleading. It avoids vague terms, but "two follow-ups" is not specific.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit checks where worktrees start,
Then finds the meta path with care.
Cargo’s folders guide the way,
The test commands clear old depth,
And Clippy keeps one lint at bay.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Team
  • Run ID: 18f7304f-1957-4625-8a79-d33561019988
Commits

Reviewing files that changed from the base of the PR and between c7f9c66 and 7f12835.

Files selected for processing: 14

  • Cargo.toml
  • meta_cli/src/invoke.rs
  • meta_cli/src/main.rs
  • meta_cli/src/project.rs
  • meta_core/src/config.rs
  • meta_core/src/worktree.rs
  • meta_git_cli/src/here.rs
  • meta_git_cli/tests/common/mod.rs
  • meta_git_cli/tests/races.rs
  • meta_git_cli/tests/recursive_inventory.rs
  • meta_git_cli/tests/where_sets_go.rs
  • meta_mcp/src/test_support.rs
  • meta_mcp/tests/cli.rs
  • meta_plugin/src/testing.rs

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

…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.
@gold-silver-copper
gold-silver-copper merged commit 8874c5d into main Nov 20, 2026
13 of 14 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant