Repository navigation
feat: adopt existing worktrees with private env files (v0.4.0) - #12
Conversation
|
Review of the adopt flow. I ran findings 1 and 2 against this branch and both fail as described. Findings 3 to 8 come from reading the code and weren't run. Fix before merging
Should fix
Cleanup
Please add a regression test for each fix. 🤖 Generated with Claude Code |
|
Re-review at 3e104c0. Findings 2, 3, 5, 7 and 8 are fixed (2, 3 and 5 confirmed by running repros against 59245f6 and 3e104c0). 69 tests pass. One regression and a few gaps remain before merge. Regression: one registered worktree that can't be resolved breaks allocation for the whole repo. Test gaps
Smaller
🤖 Generated with Claude Code |
T3 Code creates linked worktrees before running project setup, so
createcannot generate their per-worktree environment files. Addmkwt adoptto validate an existing linked worktree, record its caller-supplied identity in Git registration metadata, and generate a fresh private env file without changing the checkout.Retries return
already_configuredonly when the stored ID, recorded env path, exact generated bytes, invoking-user ownership, and mode0600match. Changed files, ownership, permissions, missing files, path changes, and symlink destinations fail withENV_PATH_COLLISION; a different stored ID fails withIDENTITY_FAILED. Adoption shares removal's validation for both absolute and relative Git registrations, retains existing staged/unstaged changes, and never runs checkout hooks or creates symlinks.Initial adoption checks path hazards and collisions before reserving an identity, so correcting those failures permits a fresh attempt. It records the intended env path before writing the file, making an interrupted complete write recognizable on retry. Partial metadata and incomplete files still require inspection. Retries check registered duplicate IDs without allocating or scanning unrelated legacy env files.
Inaccessible worktree paths are skipped during legacy scans, while their readable registration metadata continues to reserve IDs and slots. One inaccessible directory therefore does not interrupt creation, adoption, or human setup in another worktree. Unreadable legacy-only markers cannot reserve a slot until accessible again.
Unattended
createandadoptreserve a numeric slot only for templates containing{n}. Other templates store slot0, while duplicate-ID checks and identity persistence still require the caller-held repository lock. Update the README with the T3/Rails configuration, dotenv 3.x overwrite and development/test loading guidance verified against upstream docs and source, and bump the executable to 0.4.0.Design choices differing from the original brief
mkwt adoptinstead ofmkwt env, as agreed in the follow-up discussion. The name describes taking ownership of an existing registered worktree more clearly. Noenvalias is added; the human branch-name workflow stays available.0600, strengthening the original ID/path/content matching condition to preserve the private-file guarantee. Ownership uses Bash's-O; mode inspection uses the standardlsutility from the base system, without requiring an additional package or language runtime.createretains its previous post-write path recording. The JSON field is still populated only after a successful initial write; retries and removal can report a previously recorded path, which alone does not imply a valid file.There are no other departures from the brief. The JSON envelope remains schema version 1, existing stable error codes are reused, configuration is never sourced by automation, and the Bash 4.4+/Git 2.48+ requirements are unchanged.
Validation
bash -n bin/mkwt setup.sh tests/test_open_in_vscode_config.shbash tests/test_open_in_vscode_config.sh— all 4 checks passed.python3 -m unittest discover -s tests -p test_automation.py— 75 tests: 74 passed, 1 root-only ownership fixture skipped. Running that fixture locally was blocked by the host's sudo policy; the production ownership check is present, and ordinary owner/mode success cases ran in the full suite.Coverage includes successful adoption, unchanged retries, byte changes including trailing newlines and NULs, changed IDs and paths, duplicate IDs on initial adoption and retries, main/unregistered/stale/locked worktrees, mismatched Git metadata, symlinked env parents, no-slot templates for both operations, and preserved legacy workflows.
Review follow-up
Each of the eight findings has a separate commit and regression coverage:
0e1008f: Preflight adoption destinations before identity persistence; recognize completed env writes after interruption.88a9d17: Resolve relative backlinks against their registration directory for adoption and removal.d1ac730: Canonicalize identity backlink paths so registered identities are not counted again as legacy markers.e03d39b: Canonicalize listed paths before self-skips and legacy comparisons, including symlink aliases.e69c2dc: Report partial or interrupted identity writes aspartial_failure, while retainingerrorif no mutation occurred.3ce9982: Reject altered env-file permissions on retries without silently changing them.d778eb8: Validate retries without allocation or unrelated legacy env-file reads, while retaining registered duplicate-ID checks.1b72b45: Keep only the absent-target fast path before shared removal validation, preserving symlink and registration error codes.The re-review follow-up in
1c0c0b7fixes the inaccessible-path allocation regression while preserving reserved registration identities, adds the first-adoption alias and human legacy-scan regression cases, checks env ownership, and explicitly documents the remaining parent-creation, destination-opening, and pre-open interruption recovery limits.This PR targets
main. Tagging and publishing v0.4.0 remain with the maintainer.