test(engine/php): real coverage for detect, env, extract and workspace - #51
Conversation
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>
|
Warning Review limit reached
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 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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
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. Comment |
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>
engine/phphad 363 running tests and 0.7% coverage. They were empty bodies and tautologies:Same family #46 deleted 94 of elsewhere. Here they're replaced, not deleted, for four files.
Coverage: 0.7% → 7.6%
detect.goprobe.goworkspace.goenv.goresolveDataDir35.3%extract.goresolveDataDircannot exceed ~35% in a single run — only oneGOOSbranch executes. The remainder ofextract.goiscore.MkdirTemp/PathRel/MkdirAllfailures with no injection point. Both stated rather than papered over.Hermetic, with real fault injection
t.TempDirfixtures,fstest.MapFSfor the embedded tree,t.Setenvto redirectHOMEsoPrepareRuntimeEnvironmentnever touches a real user profile,t.Chdirfor 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-versionworkspace.yaml.Some assertions are about properties that matter rather than shape —
TestLoadOrGenerateAppKey_StableandTestWriteEnvFile_Uglypin 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.Rootclass fixed in #49, this time indetect.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/apppointing at a volume, a git worktree, a bind-mounted container path), every file read as absent:So
IsLaravelProjectreturned false for a Laravel project. Silently — no error, just a wrong answer, and every downstream service-detection decision follows it.probe.goaddsprobeExists/probeReadovercore.Stat/core.ReadFile— the same os-level probing already used byworkspace.goanddisplay/webkit/pkg/container/core_helpers.go. go-io is correct and untouched; coreio media stay for sandboxed I/O.TestIsLaravelProject_ThroughSymlinkpins the two paths as equal.The medium seam is unaffected in practice:
SetMediumhas no callers outside its own build-tagged example.Gates
engine/phpgreen under-raceStill 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 tophp/composer/ghand 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