Skip to content

fix(devtools): resolve repo root from cwd, not hard-pin (#1209) - #1239

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/cli-wrapper-repo-root-1209
May 17, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/cli-wrapper-repo-root-1209

Conversation

@Sinity

@Sinity Sinity commented May 17, 2026

Copy link
Copy Markdown
Owner

Summary

The devtools CLI shell wrapper required POLYLOGUE_REPO_ROOT and dispatched against it unconditionally. The devshell exports that variable once at entry and it is then inherited by every subshell — including ones cd'd into a worktree — so devtools verify --quick run from a worktree silently validated the main checkout. This PR makes the wrapper worktree-aware and audits the other CLI wrappers (polylogue, polylogued, polylogue-mcp) for the same anti-pattern.

Problem

Solution

  • Move the wrapper body to nix/devtools-wrapper.sh so the same shell script is read into the Nix writeShellScriptBin (via builtins.readFile) and exercised by unit tests directly — no Nix build required for the regression test.
  • New resolution order in the wrapper:
    1. git rev-parse --show-toplevel from the caller's cwd, validated by the presence of devtools/__main__.py. This is the normal path and makes the wrapper worktree-aware.
    2. POLYLOGUE_REPO_ROOT, only when set and pointing at a real checkout. Documented fallback for tarball / non-git extraction cases.
    3. Loud error otherwise. No silent dispatch to a stale or wrong path.
  • Audit of the other wrappers:
    • polylogue, polylogued, polylogue-mcp are Python console-script entry points ([project.scripts] in pyproject.toml) — no path baking, they import the installed package.
    • flake.nix postFixup wraps them with wrapProgram that only scrubs PYTHON* env vars — no path pin.
    • nix/module.nix (NixOS module) sets only POLYLOGUE_CONFIG; no checkout path.
    • No /realm/project/polylogue literal exists anywhere in flake.nix or nix/ (only in a docstring example and test fixtures, both unrelated to the install surface).
  • The static side of the audit is enforced by test_repo_wrapper_script_has_no_hardcoded_paths, which keeps the script free of /realm/project/polylogue and free of any "POLYLOGUE_REPO_ROOT is not set" hard requirement.

The POLYLOGUE_REPO_ROOT="$PWD" export in the devshell shellHook is retained because it still serves as the documented fallback for tooling that wants an explicit hint; it is no longer load-bearing for devtools worktree dispatch.

Verification

$ python -m pytest tests/unit/devtools/test_cli_wrapper.py
6 passed in 8.41s

$ python -m devtools verify --quick
... "exit_code": 0

The new tests cover: cwd resolution, cwd-wins-over-env (the #1193 scenario), env-fallback outside git, invalid env-var ignored, no-checkout error path, and the static no-hardcoded-paths guard.

Closes #1209
Closes #1193

Problem: The `devtools` CLI wrapper (`devtoolsCli` in flake.nix) required
POLYLOGUE_REPO_ROOT to be set and dispatched against it unconditionally.
The devshell exports POLYLOGUE_REPO_ROOT="$PWD" once on entry, then
inherits it into every subshell — including ones cd'd into a worktree.
Result: `devtools verify --quick` run from a worktree silently validated
the main checkout, producing misleading green results (originally
observed during PR #1191 and filed as #1193). The audit goal of #1209
is to ensure no CLI wrapper carries the same hard-pin pattern.

Solution:
- Move the wrapper body to `nix/devtools-wrapper.sh` so the same script
  is both installed by Nix (via `writeShellScriptBin` + readFile) and
  unit-testable directly without building the flake.
- Resolve the checkout from the caller's cwd via
  `git rev-parse --show-toplevel`, validated by the presence of
  `devtools/__main__.py`. POLYLOGUE_REPO_ROOT remains as a documented
  fallback for callers outside any git checkout. Both paths are
  validated; a stale env var no longer wins over a real cwd.
- `polylogue`, `polylogued`, and `polylogue-mcp` are installed Python
  console scripts with no path baking — audited and confirmed.
- No `/realm/project/polylogue` literal exists in flake.nix or nix/
  (only in test fixtures and one docstring example, both unrelated).

Verification:
- `python -m pytest tests/unit/devtools/test_cli_wrapper.py` — 6 passed
- `python -m devtools verify --quick` — exit 0

Closes #1209
Closes #1193
@Sinity
Sinity merged commit c49b9b2 into master May 17, 2026
2 checks passed
@coderabbitai

coderabbitai Bot commented May 17, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Sinity has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 39 minutes and 2 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: b48d5ffe-d0b5-460d-9d75-88c551156d4a

📥 Commits

Reviewing files that changed from the base of the PR and between 3d26161 and 825ee30.

📒 Files selected for processing (3)
  • flake.nix
  • nix/devtools-wrapper.sh
  • tests/unit/devtools/test_cli_wrapper.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/cli-wrapper-repo-root-1209

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Sinity
Sinity deleted the feature/fix/cli-wrapper-repo-root-1209 branch May 17, 2026 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant