Skip to content

WEB-11226: make php_tests_worktree zero-config against the running stack - #3

Merged
lewissmithweb merged 2 commits into
mainfrom
WEB-11226-worktree-zero-config
Jul 8, 2026
Merged

WEB-11226: make php_tests_worktree zero-config against the running stack#3
lewissmithweb merged 2 commits into
mainfrom
WEB-11226-worktree-zero-config

Conversation

@lewissmithweb

Copy link
Copy Markdown
Contributor

Summary

WEB-11226 added php_tests_worktree (merged in #2) as a working skeleton, but it forced
per-repo compose edits and never provisioned the isolated database, so it couldn't run a
repo's suite for real. This reworks it to reuse the already-running local stack with zero
changes in the consuming repo
: bring the stack up (make dkr_up_local) and run from the
main checkout pointing at a worktree — decrypted env/secrets (gitignored, absent in worktrees)
still come from the main stack.

What changed

Issue Fix
Per-repo ${DKR_COMPOSE_SRC} compose edit Auto-generates an ephemeral compose override (image pin + code-mount redirect) merged onto the stack's own compose files, read from the running container's com.docker.compose.project.config_files label — so env_file/secrets/network still come from main. DKR_COMPOSE_SRC removed from docker.mk + docs.
Stale <name>/cli:latest image Pins the exact image the running cli container uses (docker inspect … {{.Image}}).
Nested-app vendor drift check always misfired App dir auto-detected (shallowest composer.json bind mount under the checkout); vendor/composer.lock checks use the real app dir (e.g. api/laravel), so the "reuse vendor" fast path is reachable.
Isolated DB never created/migrated Auto-detects the mysql container + app user; creates + grants the DB as root via the container's own $MYSQL_ROOT_PASSWORD, then migrates it. DB_SEED=1 also seeds; DB_FRESH=1 rebuilds.

Also rewrote the CI test (test/php_tests_worktree.sh) to assert both the make wiring (make -n) and the rendered shell program — still Docker-free.

Knobs (all auto-detected unless set)

APP_DIR · DB_DATABASE · DB_FRESH=1 · DB_SEED=1 — see docs/php.md.

Validation (api-backend, unmodified checkout)

  • UnitQueueConnectionsTest → OK, 2 tests
  • Feature (DatabaseTransactions) — TrackElasticSearchIndexTransformerTest → OK, 1 assertion, in the isolated migrated+seeded DB test_wt_apibackend_…
  • Runs on PHP 8.4.21 (the ECR image, not the stale 8.2 bare build); nested api/laravel auto-detected; re-runs reuse vendor + DB (Nothing to migrate); distinct worktree paths → distinct DBs.

Notes for the reviewer / release

  • DKR_COMPOSE_SRC removed. A grep of the locally checked-out repos found no consumer wiring ${DKR_COMPOSE_SRC} into compose (the feature was never usable), so removal is safe — worth a wider confirmation before release.
  • Advancing v1 is a required follow-up. The floating v1 (and v1.14) still point at 387cb34, pre-WEB-11226, so v1-pinned repos don't receive this. After merge, publish a v1.15.0 GitHub release to trigger git-release.yaml and move v1/v1.15 onto this commit.

🤖 Generated with Claude Code

The initial worktree-test target was a working skeleton but forced per-repo
compose edits and never provisioned the isolated database, so it couldn't run a
repo's suite for real. Rework it to reuse the already-running local stack with
zero changes in the consuming repo:

- Reuse the running cli container's exact compose files (from the
  com.docker.compose.project.config_files label), image and services; redirect
  ONLY the code bind-mount to the worktree via an auto-generated ephemeral
  compose override. This removes the need for consumers to reference
  ${DKR_COMPOSE_SRC}, which is dropped from docker.mk and the docs.
- Pin the exact image the running cli container uses (docker inspect) instead of
  falling back to a stale <name>/cli:latest build.
- Auto-detect the app directory (shallowest composer.json bind mount under the
  checkout), fixing the vendor/composer.lock drift check for nested-app repos
  such as api-backend (api/laravel).
- Create and grant the per-worktree database as root via the mysql container's
  own MYSQL_ROOT_PASSWORD, then migrate it (DB_SEED=1 also seeds, DB_FRESH=1
  rebuilds) so DatabaseTransactions feature tests work.
- Rewrite the CI test to assert both the make wiring and the rendered shell
  program, without needing Docker.

Validated against api-backend with an unmodified checkout: unit and
DatabaseTransactions feature tests pass on the correct PHP 8.4 image in an
isolated, migrated+seeded database; re-runs reuse vendor and the database.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 9 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: f3aa82c2-9b11-40ac-8b50-0b49a08e1b36

📥 Commits

Reviewing files that changed from the base of the PR and between ce4f066 and df9ee37.

📒 Files selected for processing (1)
  • php.mk
📝 Walkthrough

Walkthrough

The old DKR_COMPOSE_SRC variable and documentation are removed. php_tests_worktree in php.mk is rewritten to reuse a running Docker Compose stack, auto-detect app mounts, generate an ephemeral compose override, and provision isolated per-worktree databases, with updated docs and test coverage.

Changes

Worktree test target rework

Layer / File(s) Summary
Remove DKR_COMPOSE_SRC variable and docs
docker.mk, docs/docker.md
Deletes the exported DKR_COMPOSE_SRC variable and its explanatory comment from docker.mk, and removes the corresponding TOC entry and section from docs/docker.md.
Discover running container and compose config
php.mk
Adds the exported PHP_TESTS_WORKTREE macro scaffold, discovers the already-running CLI container via Docker labels, and extracts its compose config files, image, and bind mounts to auto-detect the app directory.
Ephemeral compose override and dependency sync
php.mk
Generates an ephemeral compose override pinning the running image and redirecting only the app mount to the worktree, and runs composer install when lock drift or missing vendor is detected.
Isolated database provisioning and test execution
php.mk
Creates/drops and grants privileges on a per-worktree database using detected MySQL/MariaDB/Percona credentials, then runs tests against that database with optional entrypoint skip.
Target variable interface and recipe wiring
php.mk
Updates target variable declarations (adds APP_DIR, DB_FRESH, DB_SEED, WORKTREE_ENTRYPOINT_SKIP, removes old vars) and wires the recipe to invoke sh -eu -c "$$PHP_TESTS_WORKTREE".
Tests and documentation for new worktree flow
test/php_tests_worktree.sh, docs/php.md
Rewrites test assertions to cover both the rendered recipe and the generated worktree program, and updates docs/php.md to describe stack reuse, override generation, database isolation, and new DB_SEED/DB_FRESH options.

May the Force guide this review, young reviewer.


Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@php.mk`:
- Around line 118-121: The DB_FRESH cleanup block in php.mk is swallowing DROP
DATABASE failures by redirecting output and forcing success, which hides real
drop errors. Update the DB_FRESH branch around the docker exec mysql DROP
DATABASE call so failures are allowed to surface instead of using a success
override, keeping the existing log message but letting the shell return a
non-zero status when the drop fails.
- Around line 64-67: The APP_DIR mount check in php.mk is comparing the raw
APP_DIR value against Docker mount sources, so relative values like . or paths
with trailing slashes can fail even when mounted. Normalize APP_DIR before
building app_host in the APP_DIR validation block, then use that normalized path
for the awk match so the existing app_target lookup in the shell logic accepts
equivalent paths.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 22c3c2c1-e5b2-4071-b665-e2735aa873c0

📥 Commits

Reviewing files that changed from the base of the PR and between 890827f and ce4f066.

📒 Files selected for processing (5)
  • docker.mk
  • docs/docker.md
  • docs/php.md
  • php.mk
  • test/php_tests_worktree.sh
💤 Files with no reviewable changes (2)
  • docs/docker.md
  • docker.mk

Comment thread php.mk
Comment thread php.mk
- DB_FRESH: surface a failed DROP DATABASE (die with a clear message) instead of
  `|| true`, which silently continued and could leave a non-fresh database.
- APP_DIR: normalise a leading ./ and trailing slashes before matching the Docker
  mount source, so '.', 'api/laravel/' etc. resolve instead of spuriously failing
  the "not bind-mounted" check.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@lewissmithweb
lewissmithweb merged commit 1ab6920 into main Jul 8, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant