test-infra: make local_instrumented.sh CWD-independent #287

Merged
JMR-dev merged 2 commits from test-infra-284-helper-cwd into main 2026-07-04 05:58:58 +00:00
JMR-dev commented 2026-07-04 05:22:50 +00:00 (Migrated from github.com)

Closes #284

What

local_instrumented.sh resolved GRADLEW as an absolute path from its own script
location, but never made that the build's project directory. The gradlew wrapper
picks the project to build from the process's current directory, not from the wrapper
script's own location — so invoking the helper from a CWD outside its tree (e.g. another
worktree) silently built the wrong repo's :app. That's exactly what a peer agent hit:
first run built the main repo's APK and got a ClassNotFoundException for a test class
that only existed in the intended worktree; re-running with CWD manually set to the
worktree fixed it.

Fix

Added one cd "${REPO_ROOT}" (with a die on failure) right after the existing
preconditions, before gradlew is invoked. REPO_ROOT was already resolved correctly
and CWD-independently (via SCRIPT_DIR/BASH_SOURCE), so this is the minimal change:
make the actual build target that root too, instead of only using it to locate the
wrapper script. Everything else (orphan-kill preamble, manual boot, EXIT-trap teardown)
is untouched.

Also updated local_instrumented.README.md's usage note, which previously said "from
the repo root" — that's no longer a requirement, so the note now explains the
CWD-independence and why it matters (running the right worktree's copy of the script).

Validation

No emulator boot (script/review only, per the ticket):

  • bash -n .claude/skills/preflight/local_instrumented.sh — syntax OK.
  • Manual review of the diff and full script confirming every other path used
    (AVD_HOME, JDK_HOME, EMU_LOG) is already absolute, so the new cd doesn't affect
    anything else in the script.
  • shellcheck was not available locally, so it was skipped (not required by the ticket
    unless available).

🤖 Generated with Claude Code

Closes #284 ## What `local_instrumented.sh` resolved `GRADLEW` as an absolute path from its own script location, but never made that the *build's* project directory. The gradlew wrapper picks the project to build from the process's current directory, not from the wrapper script's own location — so invoking the helper from a CWD outside its tree (e.g. another worktree) silently built the wrong repo's `:app`. That's exactly what a peer agent hit: first run built the main repo's APK and got a `ClassNotFoundException` for a test class that only existed in the intended worktree; re-running with CWD manually set to the worktree fixed it. ## Fix Added one `cd "${REPO_ROOT}"` (with a `die` on failure) right after the existing preconditions, before `gradlew` is invoked. `REPO_ROOT` was already resolved correctly and CWD-independently (via `SCRIPT_DIR`/`BASH_SOURCE`), so this is the minimal change: make the actual build target that root too, instead of only using it to locate the wrapper script. Everything else (orphan-kill preamble, manual boot, EXIT-trap teardown) is untouched. Also updated `local_instrumented.README.md`'s usage note, which previously said "from the repo root" — that's no longer a requirement, so the note now explains the CWD-independence and why it matters (running the right worktree's copy of the script). ## Validation No emulator boot (script/review only, per the ticket): - `bash -n .claude/skills/preflight/local_instrumented.sh` — syntax OK. - Manual review of the diff and full script confirming every other path used (`AVD_HOME`, `JDK_HOME`, `EMU_LOG`) is already absolute, so the new `cd` doesn't affect anything else in the script. - `shellcheck` was not available locally, so it was skipped (not required by the ticket unless available). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign in to join this conversation.