Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion spec/tests/test_12_worktree.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,50 @@ else
fail "try . without name should show error" "error about name" "$output" "command_line.md#worktree"
fi

# Test: try . <name> inside a git subdirectory still emits git worktree add
mkdir -p "$FAKE_REPO/sub/nested"
output=$(cd "$FAKE_REPO/sub/nested" && try_run --path="$TEST_TRIES" exec . subfeature 2>&1)
if echo "$output" | grep -q "worktree add"; then
pass
else
fail "try . <name> in git subdir should emit git worktree add" "worktree add command" "$output" "command_line.md#worktree"
fi

# Test: try ./nonexistent inside a git repo does not falsely detect parent .git
output=$(cd "$FAKE_REPO" && try_run --path="$TEST_TRIES" exec ./does-not-exist nonexist-try 2>&1)
if echo "$output" | grep -q "worktree add"; then
fail "try ./does-not-exist should not emit git worktree add" "plain mkdir without worktree add" "$output" "command_line.md#worktree"
else
pass
fi

# Test: dot-prefixed query (e.g. .env) is treated as search, not worktree path
output=$(try_run --path="$TEST_TRIES" --and-exit exec .env 2>&1)
if echo "$output" | grep -q "mkdir -p"; then
fail "try .env should open selector instead of mkdir" "TUI output without mkdir -p" "$output" "command_line.md#worktree"
else
pass
fi

# Test: worktree with spaces and single quotes in repo/tries paths executes cleanly
SPACE_ROOT=$(mktemp -d)
SPACE_REPO="$SPACE_ROOT/my repo's dir"
SPACE_TRIES="$SPACE_ROOT/my tries's dir"
mkdir -p "$SPACE_REPO" "$SPACE_TRIES"
git -C "$SPACE_REPO" init -q
git -C "$SPACE_REPO" -c user.name=test -c user.email=test@example.com commit --allow-empty -q -m "init"
wt_script=$(cd "$SPACE_REPO" && try_run --path="$SPACE_TRIES" exec . space-wt)
if echo "$wt_script" | bash -n 2>/dev/null; then
(cd "$SPACE_REPO" && eval "$(echo "$wt_script" | grep -v '^#')") >/dev/null 2>&1
wt_created=$(find "$SPACE_TRIES" -maxdepth 1 -type d -name "*-space-wt" | head -1)
if [ -n "$wt_created" ] && git -C "$wt_created" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
pass
else
fail "worktree with spaces/quotes should create real git worktree" "valid git worktree" "$wt_script" "command_line.md#worktree"
fi
else
fail "worktree script with spaces/quotes should be valid bash" "valid bash syntax" "$wt_script" "command_line.md#worktree"
fi

# Cleanup
rm -rf "$FAKE_REPO" "$PLAIN_DIR"
rm -rf "$FAKE_REPO" "$PLAIN_DIR" "$SPACE_ROOT"
8 changes: 8 additions & 0 deletions spec/tests/test_16_delete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,13 @@ else
fail "Delete should use basename in rm -rf" "rm -rf 'name'" "$output" "delete_spec.md#per-item-delete-commands"
fi

# Test: Multi-delete across different search filters deletes all marked items
output=$(try_run --path="$DEL_TEST_DIR" --and-keys='TYPE=first,CTRL-D,CTRL-U,TYPE=third,CTRL-D,ENTER,Y,E,S,ENTER' exec 2>/dev/null)
if echo "$output" | grep -q "rm -rf '2025-11-01-first'" && echo "$output" | grep -q "rm -rf '2025-11-03-third'"; then
pass
else
fail "Multi-delete across filters should delete all marked items" "both first and third in rm -rf" "$output" "delete_spec.md#script-structure"
fi

# Cleanup
rm -rf "$DEL_TEST_DIR"
33 changes: 33 additions & 0 deletions spec/tests/test_20_scroll_behavior.sh
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,38 @@ else
fail "scroll should stop at first entry" "selection visible" "$output" "tui_spec.md#scroll-bounds"
fi

# Test: Scrolling reaches items beyond initial viewport height
SCROLL_DEEP_DIR=$(mktemp -d)
for i in $(seq 1 25); do
d="$SCROLL_DEEP_DIR/2025-11-01-item-$(printf '%02d' $i)"
mkdir -p "$d"
# Give item-01 newest mtime, item-25 oldest mtime so order is deterministic
touch -t "202511$(printf '%02d' $((26 - i)))0000" "$d"
done
keys=""
for i in $(seq 1 24); do
keys="${keys}DOWN,"
done
keys="${keys}ENTER"
output=$(TRY_HEIGHT=12 try_run --path="$SCROLL_DEEP_DIR" --and-keys="$keys" exec 2>/dev/null)
if echo "$output" | grep -q "2025-11-01-item-25"; then
pass
else
fail "scrolling past viewport should reach last entry (item-25)" "2025-11-01-item-25" "$output" "tui_spec.md#scroll-bounds"
fi

# Test: Selecting 'Create new' when matches exceed viewport keeps it visible
keys="TYPE=item,"
for i in $(seq 1 25); do
keys="${keys}DOWN,"
done
output=$(TRY_HEIGHT=12 try_run --path="$SCROLL_DEEP_DIR" --and-keys="${keys%,}" exec 2>&1)
if echo "$output" | strip_ansi | grep -q "Create new:"; then
pass
else
fail "Create new should remain visible when selected past full viewport" "Create new:" "$output" "tui_spec.md#scroll-bounds"
fi

rm -rf "$SCROLL_DEEP_DIR"
cleanup_scroll_dirs

9 changes: 9 additions & 0 deletions spec/tests/test_32_git_uri.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,12 @@ if echo "$output" | grep -qE "cd '.*repo'"; then
else
fail "Clone output should use single-quoted paths" "single-quoted cd" "$output" "git_uri"
fi

# Test: Clone URI with single quote is safely shell-escaped (no command injection)
inj_uri="https://github.com/user/repo';echo INJECTED_CLONE;#.git"
inj_script=$(try_run --path="$TEST_TRIES" exec clone "$inj_uri")
if echo "$inj_script" | bash -n 2>/dev/null && echo "$inj_script" | grep -qF "'\"'\"'"; then
pass
else
fail "Clone URI with single quote should be properly escaped" "valid bash syntax with escaped quote" "$inj_script" "git_uri"
fi
19 changes: 18 additions & 1 deletion spec/tests/test_34_shell_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,22 @@ else
fail "--path= form should show directories from specified path" "unique-marker-dir in output" "$output" "shell_init"
fi

# Test: init accepts relative path and expands it
REL_BASE=$(mktemp -d)
rel_out=$(cd "$REL_BASE" && SHELL=/bin/bash try_run init ./my-rel-tries 2>&1)
if echo "$rel_out" | grep -qF -- "--path '$REL_BASE/my-rel-tries'"; then
pass
else
fail "init should expand relative path" "--path '$REL_BASE/my-rel-tries'" "$rel_out" "shell_init"
fi

# Test: init safely escapes paths containing single quotes
quote_out=$(SHELL=/bin/bash try_run init "/tmp/it's-tries" 2>&1)
if echo "$quote_out" | bash -n 2>/dev/null && echo "$quote_out" | grep -qF "'\"'\"'"; then
pass
else
fail "init should safely escape single-quoted paths in bash" "valid bash syntax" "$quote_out" "shell_init"
fi

# Cleanup
rm -rf "$INIT_DIR" "$INIT_DIR2"
rm -rf "$INIT_DIR" "$INIT_DIR2" "$REL_BASE"
6 changes: 3 additions & 3 deletions spec/tests/test_36_shell_eval.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mkdir -p "$EVAL_DIR/2025-01-01-hello"
# --- bash ---

# Test: bash can eval the init output and defines try function
bash_out=$(bash -c "
bash_out=$(LC_ALL=C bash -c "
eval \"\$('$TRY_BIN_PATH' init --path '$EVAL_DIR')\"
type try
" 2>&1)
Expand All @@ -36,7 +36,7 @@ fi

if command -v zsh >/dev/null 2>&1; then
# Test: zsh can eval the init output and defines try function
zsh_out=$(zsh -c "
zsh_out=$(LC_ALL=C zsh -c "
eval \"\$('$TRY_BIN_PATH' init --path '$EVAL_DIR')\"
whence -w try
" 2>&1)
Expand Down Expand Up @@ -65,7 +65,7 @@ fi

if command -v nix-shell >/dev/null 2>&1; then
# Test: fish can eval the init output and defines try function
fish_out=$(nix-shell -p fish --run "SHELL=fish fish -c 'eval ($TRY_BIN_PATH init --path $EVAL_DIR | string collect); type try'" 2>&1)
fish_out=$(nix-shell -p fish --run "LC_ALL=C SHELL=fish fish -c 'eval ($TRY_BIN_PATH init --path $EVAL_DIR | string collect); type try'" 2>&1)
if echo "$fish_out" | grep -qi "try is a function\|function try"; then
pass
else
Expand Down
35 changes: 30 additions & 5 deletions spec/tests/test_37_graduate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ WT_DIR=$(mktemp -d)
mkdir -p "$WT_DIR/2025-06-01-worktree-test"
echo "gitdir: /tmp/fake-repo/.git/worktrees/worktree-test" > "$WT_DIR/2025-06-01-worktree-test/.git"
output=$(try_run --path="$WT_DIR" --and-keys='CTRL-G,ENTER' exec 2>/dev/null)
if echo "$output" | grep -q "git worktree move"; then
if echo "$output" | grep -qE "git (-C .+ )?worktree move"; then
pass
else
fail "Git worktree should use git worktree move" "git worktree move" "$output" "graduate"
fail "Git worktree should use git worktree move" "git [-C ...] worktree move" "$output" "graduate"
fi

# Test: Regular directory uses plain mv (not git worktree move)
output=$(try_run --path="$GRAD_DIR" --and-keys='CTRL-G,ENTER' exec 2>/dev/null)
if echo "$output" | grep -q "git worktree move"; then
if echo "$output" | grep -qE "git (-C .+ )?worktree move"; then
fail "Non-worktree should use mv, not git worktree move" "plain mv" "$output" "graduate"
else
pass
Expand Down Expand Up @@ -201,7 +201,7 @@ fi
REG_DIR=$(mktemp -d)
mkdir -p "$REG_DIR/2025-06-01-regular-repo/.git/objects"
output=$(try_run --path="$REG_DIR" --and-keys='CTRL-G,ENTER' exec 2>/dev/null)
if echo "$output" | grep -q "git worktree move"; then
if echo "$output" | grep -qE "git (-C .+ )?worktree move"; then
fail "Regular .git directory should use mv, not git worktree move" "plain mv" "$output" "graduate"
else
pass
Expand All @@ -222,4 +222,29 @@ else
fail "Should strip YYYY-MM-DD- prefix from various dates" "year-end" "$output" "graduate"
fi

rm -rf "$GRAD_DIR" "$PROJ_DIR" "$NO_DATE_DIR" "$WT_DIR" "$EDIT_DIR" "$E2E_DIR" "$E2E_DEST" "$REG_DIR" "$MULTI_DIR"
# Test: Ctrl-G on already-graduated symlink is blocked
output=$(try_run --path="$E2E_DIR" --and-keys='CTRL-G,ENTER,ESC' exec 2>/dev/null)
if echo "$output" | grep -q "mv \|ln -s "; then
fail "Ctrl-G on symlink should not graduate again" "no mv or ln -s" "$output" "graduate"
else
pass
fi

# Test: E2E git worktree graduate succeeds when invoked from outside the repo
WT_E2E_ROOT=$(mktemp -d)
WT_E2E_REPO="$WT_E2E_ROOT/main-repo"
WT_E2E_TRIES="$WT_E2E_ROOT/tries"
WT_E2E_PROJ="$WT_E2E_ROOT/projects"
mkdir -p "$WT_E2E_REPO" "$WT_E2E_TRIES" "$WT_E2E_PROJ"
git -C "$WT_E2E_REPO" init -q
git -C "$WT_E2E_REPO" -c user.name=test -c user.email=test@example.com commit --allow-empty -q -m "init"
git -C "$WT_E2E_REPO" worktree add --detach -q "$WT_E2E_TRIES/2025-06-01-wt-grad"
wt_script=$(cd /tmp && TRY_PROJECTS="$WT_E2E_PROJ" eval $TRY_CMD exec --path="$WT_E2E_TRIES" --and-keys='CTRL-G,ENTER' 2>/dev/null)
(cd /tmp && eval "$(echo "$wt_script" | grep -v '^#')") >/dev/null 2>&1
if [ -d "$WT_E2E_PROJ/wt-grad" ] && [ -L "$WT_E2E_TRIES/2025-06-01-wt-grad" ]; then
pass
else
fail "E2E worktree graduate should succeed from outside repo" "graduated dir and symlink" "$wt_script" "graduate"
fi

rm -rf "$GRAD_DIR" "$PROJ_DIR" "$NO_DATE_DIR" "$WT_DIR" "$EDIT_DIR" "$E2E_DIR" "$E2E_DEST" "$REG_DIR" "$MULTI_DIR" "$WT_E2E_ROOT"
4 changes: 2 additions & 2 deletions spec/tests/tmux/test_21_tmux_rename.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ tui_wait 0.3
tui_send C-r
tui_wait 0.2
tui_capture
if echo "$TUI_LAST_OUTPUT" | grep -q "📝"; then
if echo "$TUI_LAST_OUTPUT" | grep -q "✏"; then
pass
else
fail "Rename mode should show pencil emoji" "📝" "$TUI_LAST_OUTPUT"
fail "Rename mode should show pencil emoji" "✏️" "$TUI_LAST_OUTPUT"
fi

# Test: Rename shows current name
Expand Down
56 changes: 56 additions & 0 deletions test/try_selector_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -459,3 +459,59 @@ def test_no_raise_when_winch_unsupported
end
end

# -------------------------------------------------------------------
# finalize_ascend / run_ascend_dialog / render_delete_dialog regressions
# -------------------------------------------------------------------
class AscendAndDeleteRegressionTest < TrySelectorTestCase
def test_finalize_ascend_empty_destination_returns_error
sel = build_selector
entry = TrySelector::TryEntry.new(
{ basename: "2025-06-01-demo", text: "2025-06-01-demo", path: File.join(@tmpdir, "2025-06-01-demo"), is_symlink: false },
1.0, []
)
assert_equal "Destination cannot be empty", sel.send(:finalize_ascend, entry, " ")
end

def test_run_ascend_dialog_blocks_symlink
sel = build_selector
entry = TrySelector::TryEntry.new(
{ basename: "2025-06-01-linked", text: "2025-06-01-linked", path: @tmpdir, is_symlink: true },
1.0, []
)
sel.send(:run_ascend_dialog, entry)
assert_equal "Already graduated (symlink)", sel.instance_variable_get(:@delete_status)
assert_nil sel.instance_variable_get(:@selected)
end

def test_render_delete_dialog_keeps_confirm_prompt_visible_with_many_items
old_height = ENV["TRY_HEIGHT"]
ENV["TRY_HEIGHT"] = "12"
sel = build_selector
items = (1..20).map do |i|
TrySelector::TryEntry.new(
{ basename: "2025-06-01-dir-#{i}", text: "2025-06-01-dir-#{i}", path: File.join(@tmpdir, "2025-06-01-dir-#{i}") },
1.0, []
)
end

# Capture STDERR output from render_delete_dialog via a pipe
r, w = IO.pipe
saved_stderr = STDERR.dup
STDERR.reopen(w)
begin
sel.send(:render_delete_dialog, items, "", 0)
ensure
STDERR.reopen(saved_stderr)
saved_stderr.close
w.close
end
output = r.read
r.close

assert_includes output, "Type YES to confirm:"
assert_includes output, "more"
ensure
ENV["TRY_HEIGHT"] = old_height
end
end

Loading