Skip to content

test(engine/php): real coverage for detect, env, extract and workspace - #51

Merged
Snider merged 2 commits into
mainfrom
test/php-detect-coverage
Aug 8, 2026
Merged

test(engine/php): real coverage for detect, env, extract and workspace#51
Snider merged 2 commits into
mainfrom
test/php-detect-coverage

Conversation

@Snider

@Snider Snider commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

engine/php had 363 running tests and 0.7% coverage. They were empty bodies and tautologies:

func TestDetect_IsLaravelProject_Good(t *T) {
	subject := IsLaravelProject          // a func reference, non-nil by construction
	AssertNotNil(t, subject)
	AssertEqual(t, "good", "good")       // a literal equals itself
}
func TestDetect_IsFrankenPHPProject_Good(t *T) {}   // and many simply empty

Same family #46 deleted 94 of elsewhere. Here they're replaced, not deleted, for four files.

Coverage: 0.7% → 7.6%

file per-function
detect.go all 12 at 100.0%
probe.go 100.0% / 85.7%
workspace.go 100.0% / 93.8% / 84.6% / 100.0%
env.go 76.2% / 100.0% / 85.7% / 92.3%, resolveDataDir 35.3%
extract.go 70.6%

resolveDataDir cannot exceed ~35% in a single run — only one GOOS branch executes. The remainder of extract.go is core.MkdirTemp / PathRel / MkdirAll failures with no injection point. Both stated rather than papered over.

Hermetic, with real fault injection

t.TempDir fixtures, fstest.MapFS for the embedded tree, t.Setenv to redirect HOME so PrepareRuntimeEnvironment never touches a real user profile, t.Chdir for the workspace search.

Faults injected: truncated and non-JSON composer.json, "require" as a string, unreadable octane config, unwritable data dir and Laravel root, a filesystem whose reads fail mid-walk, malformed and unsupported-version workspace.yaml.

Some assertions are about properties that matter rather than shape — TestLoadOrGenerateAppKey_Stable and TestWriteEnvFile_Ugly pin that the APP_KEY survives regeneration, because a key that changed on restart would invalidate every session and every encrypted column.

One production change — a defect the tests exposed

A second instance of the go-io os.Root class fixed in #49, this time in detect.go. Project probing ran through the coreio local medium, which refuses any path leaving its root — including one that merely traverses a symlink. Handed a symlinked project path (~/Sites/app pointing at a volume, a git worktree, a bind-mounted container path), every file read as absent:

IsLaravelProject(real)     = true      IsLaravelProject(symlink)     = false
GetLaravelAppName(real)    = "Probe"   GetLaravelAppName(symlink)    = ""

So IsLaravelProject returned false for a Laravel project. Silently — no error, just a wrong answer, and every downstream service-detection decision follows it.

probe.go adds probeExists / probeRead over core.Stat / core.ReadFile — the same os-level probing already used by workspace.go and display/webkit/pkg/container/core_helpers.go. go-io is correct and untouched; coreio media stay for sandboxed I/O. TestIsLaravelProject_ThroughSymlink pins the two paths as equal.

The medium seam is unaffected in practice: SetMedium has no callers outside its own build-tagged example.

Gates

  • engine/php green under -race
  • whole library: 59 packages ok, 0 failures
  • vet + gofmt clean

Still open in this package

cmd_ci.go (31 uncovered funcs), quality.go (25), services.go (23), cmd_dev.go (21), php.go (19) — these shell out to php/composer/gh and need either a command seam or a tagged integration lane. Deliberately not attempted here; a clean partial at a file boundary beats a rushed total.

🤖 Generated with Claude Code
Co-Authored-By: Virgil virgil@lethean.io

engine/php had 363 running tests and 0.7% coverage. They were empty
bodies and tautologies — `subject := IsLaravelProject; AssertNotNil(t,
subject); AssertEqual(t, "good", "good")` takes a func reference (non-nil
by construction) and asserts a literal equals itself. Same family PR #46
deleted 94 of elsewhere. Replaced, not deleted, for four files.

Coverage 0.7% -> 7.6%. Per function in the files touched:

  detect.go     all 12 at 100.0%
  probe.go      100.0% / 85.7%
  workspace.go  100.0% / 93.8% / 84.6% / 100.0%
  env.go        76.2% / 100.0% / 85.7% / 92.3%, resolveDataDir 35.3%
  extract.go    70.6%

resolveDataDir cannot exceed ~35% in one run: only one GOOS branch
executes. The rest of extract.go is core.MkdirTemp / PathRel / MkdirAll
failures with no injection point.

Tests are hermetic — t.TempDir fixtures, fstest.MapFS for the embedded
tree, t.Setenv to redirect HOME so PrepareRuntimeEnvironment never
touches a real user profile, t.Chdir for the workspace search. Fault
injection is real: truncated and non-JSON composer.json, unreadable
octane config, unwritable data dir and Laravel root, a filesystem whose
reads fail mid-walk, malformed and unsupported-version workspace.yaml.

ONE PRODUCTION CHANGE, from a defect the tests exposed — a second
instance of the go-io os.Root class fixed in #49, this time in
detect.go. Project probing ran through the coreio local medium, which
refuses any path leaving its root, including one that merely traverses a
symlink. Handed a symlinked project path — ~/Sites/app pointing at a
volume, a git worktree, a bind-mounted container path — every file read
as absent, so IsLaravelProject returned false FOR A LARAVEL PROJECT and
GetLaravelAppName returned "". Silently: no error, just a wrong answer.

  probe.go adds probeExists / probeRead over core.Stat / core.ReadFile,
  the same os-level probing already used by workspace.go and
  display/webkit/pkg/container. go-io is correct and untouched; coreio
  media stay for sandboxed I/O.

  Receipt: probed before the fix —
    IsLaravelProject(real)=true   IsLaravelProject(symlink)=false
    GetLaravelAppName(real)="Probe"  GetLaravelAppName(symlink)=""
  TestIsLaravelProject_ThroughSymlink now pins both as equal.

The medium seam is unaffected in practice: SetMedium has no callers
outside its own build-tagged example.

Gates: engine/php green under -race; whole library 59 packages ok, 0
failures; vet + gofmt clean.

Co-Authored-By: Virgil <virgil@lethean.io>
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Snider, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 58 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

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: CHILL

Plan: Pro Plus

Run ID: 22d09a68-7a96-4858-89f3-986d9319ad3d

📥 Commits

Reviewing files that changed from the base of the PR and between fa48ab3 and 920fb09.

📒 Files selected for processing (6)
  • go/engine/php/detect.go
  • go/engine/php/detect_test.go
  • go/engine/php/env_test.go
  • go/engine/php/extract_test.go
  • go/engine/php/probe.go
  • go/engine/php/workspace_symlink_test.go

Warning

Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

TestExtract_Bad and TestExtract_Ugly snapshotted the whole system temp
directory either side of the call, so any unrelated process creating a
temporary file between the two reads would be reported as a leaked
extraction. On a busy CI runner that is a flake that looks like a real
failure.

Only entries carrying Extract's own "go-php-laravel-" prefix are counted
now, which is still a true leak check and immune to unrelated activity.

Receipt: go test -run TestExtract_ -count=2 ./engine/php/ green.

Co-Authored-By: Virgil <virgil@lethean.io>
@Snider
Snider merged commit 29b32fc into main Aug 8, 2026
2 checks passed
@Snider
Snider deleted the test/php-detect-coverage branch August 8, 2026 10:40
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