Skip to content

feat: detect down containers in preflight (+ pin release to 2.1.0) - #29

Merged
TerrorSquad merged 2 commits into
mainfrom
feat/preflight-container-check
Jul 18, 2026
Merged

feat: detect down containers in preflight (+ pin release to 2.1.0)#29
TerrorSquad merged 2 commits into
mainfrom
feat/preflight-container-check

Conversation

@TerrorSquad

Copy link
Copy Markdown
Owner

Follow-up to the preflight work, answering the container-down and performance questions.

Container-down handling

A tool pinned to a ddev/docker backend previously passed preflight (container tools were assumed available) and then failed mid-run with a cryptic docker exec error if the container was down. Now preflight checks the container is running and fails fast:

run failed: cannot run hook, some tools are unavailable:
  - phpstan — container "my-app-web" is not running
install/start them, set SKIP_<TOOL>=1 to skip, or disable the tool in forge.toml

forge does not start the container — a commit hook must not spin up infrastructure. It tells you to ddev start and retry (or SKIP_/disable).

Performance (measured)

  • Host preflight = exec.LookPath, ~20–28µs/tool — sub-millisecond for a whole hook, dwarfed by the tools themselves (10–1000ms each).
  • Container check = docker inspect, memoized once per container per run (added in the previous PR), shared across preflight and execution.
  • No meaningful slowdown; nothing worth caching across runs (would go stale when you install a tool).

Release

Includes Release-As: 2.1.0 to override the pending 3.0.0 release PR — per request, this ships as a minor. (The earlier feat! behavior change will still be noted in the changelog; say the word if you want that history reworded for a fully clean minor.)

Tests & verification

  • New backend tests: container-down → error, host missing/present.
  • Updated the missing-tool assertion to the new message.
  • E2E verified: container-pinned tool with container down → clear preflight failure, exit 1.
  • go build/vet/gofmt clean; full -race suite passes; site builds.

🤖 Generated with Claude Code

A tool pinned to a ddev/docker backend used to pass preflight (container
tools were assumed available) and then fail mid-run with a raw `docker
exec` error when the container was down. Preflight now verifies the
container is running and fails fast with an actionable message — without
starting the container, since a git hook must not spin up infrastructure.

Host binary checks are unchanged. Container-running checks are memoized,
so the added cost is at most one `docker inspect` per container per run;
host preflight is a ~20us PATH lookup per tool.

Release-As: 2.1.0

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

@TerrorSquad TerrorSquad left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Self-review. Behavior verified end-to-end and the logic is sound. One test gap:

The DDEV preflight branch isn't directly covered. TestPreflightTool_DockerContainerDown exercises the shared isDockerContainerRunning path via DockerBackend, but the *DdevBackend case also does ddevContainerName (parses .ddev/config.yaml) and emits a distinct start it with ddev start message — none of which is tested. Adding a fixture test for it.

No correctness issues otherwise: auto-detect still falls back to host before reaching the ddev branch; memoization is shared with ResolveBackend; skip exemptions unchanged.

Adds a fixture test for the *DdevBackend path (.ddev/config.yaml parsing
+ the `ddev start` guidance message), which the DockerBackend test didn't
reach. Addresses review.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@TerrorSquad
TerrorSquad merged commit 69e505f into main Jul 18, 2026
1 check passed
@TerrorSquad
TerrorSquad deleted the feat/preflight-container-check branch July 18, 2026 00:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant