From b13109e8e06d2b6cf7e7fa9e8539cf838e56d1b6 Mon Sep 17 00:00:00 2001 From: dan Date: Sun, 11 Jan 2026 21:24:03 -0800 Subject: [PATCH] fix: use absolute worktree paths, check sqlite3 availability - worktreePath() now returns absolute path using findMainRepoDir() - Fixes 'cannot change to worktrees/...' error from inside worktree - test-worker.sh now checks sqlite3 is available before running Co-Authored-By: Claude Opus 4.5 --- src/worker/tests/test-worker.sh | 26 ++++++++++++++------------ src/worker/utils.nim | 9 +++++---- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/worker/tests/test-worker.sh b/src/worker/tests/test-worker.sh index 404cd5a..c69dab7 100755 --- a/src/worker/tests/test-worker.sh +++ b/src/worker/tests/test-worker.sh @@ -34,9 +34,18 @@ TEST_DIR=$(mktemp -d) TEST_REPO="$TEST_DIR/repo" ORIG_DIR="$(pwd)" -# Set up SQLite library path -SQLITE_LIB=$(nix-build '' -A sqlite.out --no-out-link 2>/dev/null)/lib -export LD_LIBRARY_PATH="${SQLITE_LIB}:${LD_LIBRARY_PATH:-}" +# Set up SQLite library and binary paths +SQLITE_OUT=$(nix-build '' -A sqlite.out --no-out-link 2>/dev/null) +if [[ -d "${SQLITE_OUT}" ]]; then + export LD_LIBRARY_PATH="${SQLITE_OUT}/lib:${LD_LIBRARY_PATH:-}" + export PATH="${SQLITE_OUT}/bin:${PATH}" +fi + +# Verify sqlite3 is available +if ! command -v sqlite3 &>/dev/null; then + echo "ERROR: sqlite3 not found. Run tests with: nix-shell -p sqlite --run 'bash $0'" + exit 1 +fi cleanup() { cd "$ORIG_DIR" @@ -369,17 +378,10 @@ echo "## Invalid State Transitions" run_worker spawn --taskId=test-invalid --fromBranch=master > /dev/null run_worker start --task=test-invalid > /dev/null -# NOTE: Should return exit code 3 (ExitInvalidTransition) but currently returns 1 -# See skills-lxb9 for fix output=$(run_worker approve --taskId=test-invalid 2>&1) exit_code=$? -if [[ "$exit_code" != "0" ]]; then - echo -e "${GREEN}PASS${NC}: Approve from WORKING fails (exit code: $exit_code)" - ((PASSED++)) -else - echo -e "${RED}FAIL${NC}: Approve from WORKING should fail" - ((FAILED++)) -fi +assert_exit_code "Approve from WORKING returns ExitInvalidTransition" "3" "$exit_code" +assert_output_contains "Approve error message" "Cannot approve" "$output" # --- Review-Gate Integration --- echo "" diff --git a/src/worker/utils.nim b/src/worker/utils.nim index 5e1c410..c714e42 100644 --- a/src/worker/utils.nim +++ b/src/worker/utils.nim @@ -11,10 +11,6 @@ proc branchName*(taskId: string): string = ## Get the feature branch name for a task &"feat/{taskId}" -proc worktreePath*(taskId: string): string = - ## Get the worktree path for a task - &"{WorktreesDir}/{taskId}" - proc findMainRepoDir*(): string = ## Find the main repository directory, even when running from a worktree. ## Uses git to find the common git directory, then derives the main repo. @@ -34,6 +30,11 @@ proc findMainRepoDir*(): string = else: getCurrentDir() / gitCommonDir result = parentDir(mainGitDir) +proc worktreePath*(taskId: string): string = + ## Get the absolute worktree path for a task. + ## Uses repo root to ensure path works from any directory. + findMainRepoDir() / WorktreesDir / taskId + proc getMainRepoBusDbPath*(): string = ## Get the absolute path to bus.db in the main repository. ## Works correctly even when called from a worktree.