# End-to-end smoke test for the `wt` worktree helpers. # Builds a throwaway source repo, converts it with `wt clone`, then exercises # path mapping, creation, listing and `wt add` without PR lookups. # Run: nu nushell/tests/wt-smoke.nu use ../modules/git.nu * def fail [message: string] { print $"FAIL ($message)" exit 1 } def check [label: string, actual: any, expected: any] { if $actual == $expected { print $"ok ($label)" } else { fail $"($label): got ($actual), want ($expected)" } } let tmp = (mktemp -d) let src = ([$tmp "source"] | path join) mkdir $src cd $src ^git init --initial-branch trunk . | ignore ^git config user.email test@example.com ^git config user.name test "seed" | save --force seed.txt ^git add seed.txt ^git commit -m seed | ignore # Note: Windows cannot store loose refs named `CON` or containing `<`, so those # names are only exercised through the path mapping, never as real branches here. for branch in ["features/make-it-good" "release/1.0"] { ^git branch $branch trunk } cd $tmp wt clone $src repo --no-submodules | ignore let root = (wt root) check "root" ($root | path basename) "repo" check "main worktree is nested-free" (pwd | path basename) "trunk" # Branch name -> path mapping. check "flat branch" (wt path "trunk") ([$root "trunk"] | path join) check "nested branch keeps hierarchy" (wt path "features/make-it-good") ([$root "features" "make-it-good"] | path join) check "win32-illegal chars normalized" (wt path "weird") ([$root "weird-name"] | path join) check "DOS reserved name escaped" (wt path "CON") ([$root "CON-"] | path join) # Creating a nested worktree must create parent directories. let nested = (wt new "features/make-it-good" --no-submodules) check "nested worktree path" $nested ([$root "features" "make-it-good"] | path join) check "nested worktree exists" ($nested | path exists) true check "wt ls sees two worktrees" (wt ls | length) 2 check "wt ls marks current" (wt ls | where current == true | get branch | first) "trunk" # `wt add` without --pr must not touch gh/fj and must resolve a local branch. let added = (wt add "release/1.0" --no-submodules) check "wt add nested path" $added ([$root "release" "1.0"] | path join) check "wt add created worktree" ($added | path exists) true check "wt ls sees three worktrees" (wt ls | length) 3 # `--pr` only looks at PRs; this fixture has none, so it must fail cleanly # instead of falling back to local or remote branches. let pr_error = (try { wt add --pr --no-submodules; "no error" } catch {|e| $e.msg }) check "wt add --pr ignores branches" ($pr_error | str contains "no branches or PRs available") true cd ($tmp | path dirname) rm -rf $tmp print "all wt smoke checks passed"