Skip to content

fix: make TestLockPortSameDirectory_NoError resilient to busy ports#83

Merged
dapi merged 12 commits intomasterfrom
fix/flaky-test-lock-same-dir
Mar 27, 2026
Merged

fix: make TestLockPortSameDirectory_NoError resilient to busy ports#83
dapi merged 12 commits intomasterfrom
fix/flaky-test-lock-same-dir

Conversation

@dapi
Copy link
Copy Markdown
Owner

@dapi dapi commented Mar 2, 2026

Summary

  • Replace hardcoded port 3003 in TestLockPortSameDirectory_NoError with dynamically discovered free port
  • Scans the configured range (3000-4000) for an available port before running the test
  • Prevents flakiness when port 3003 is occupied by other services (e.g. docker-proxy)

Test plan

  • TestLockPortSameDirectory_NoError passes
  • Full test suite passes (go test ./...)

🤖 Generated with Claude Code

@dapi dapi closed this Mar 2, 2026
@dapi dapi reopened this Mar 2, 2026
dapi and others added 12 commits March 27, 2026 19:12
Instead of hardcoding port 3003, dynamically find a free port within
the configured range (3000-4000). This prevents flakiness when the
hardcoded port is in use by other services (e.g. docker-proxy).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Revert err2 back to idiomatic err (no shadowing conflict)
- Fix "Step 1" comment: allocate -> allocate and lock
- Add allocation state verification after re-lock (matches sibling test pattern)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Move port discovery after setup to minimize TOCTOU window
- Use t.Skipf instead of t.Fatalf for first --lock call (matches project
  pattern for port-unavailable scenarios)
- Add .gitignore entries for pr-review-fix-loop artifacts

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Narrow t.Skipf guard on first --lock call to only skip for TOCTOU-related
failures ("in use", "busy"). All other failures now use t.Fatalf so real
regressions in the --lock code path are not silently skipped.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Check for external allocation path in Step 1 output after success.
If port was claimed by external process between discovery and lock,
skip the test instead of continuing with misleading state.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Change t.Fatal to t.Skipf when no free port is found in range,
matching project convention for port-unavailability scenarios.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Check fmt.Sscanf error return value (errcheck)
- Add unreachable return after t.Fatal to satisfy staticcheck SA5011
  (staticcheck doesn't recognize t.Fatal as terminating)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Use port-specific TOCTOU string matching instead of generic "in use"/"busy"
- Verify external allocation state instead of blindly skipping
- Add comment explaining why Step 2 is immune to TOCTOU
- Log last error when no free port found in scan
- Validate parsed port range (1-65535) in Sscanf test
- Verify Name field preserved after re-lock

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…nalAllocations

Deep spec review revealed CLAUDE.md covered only ~30% of actual functionality.

CLAUDE.md updates:
- Add all 15 undocumented CLI commands (--list, --forget, --scan, --lock, etc.)
- Update Project Structure with debug/, docker/, pathutil/, procinfo.go
- Document full AllocationInfo model (13 fields vs 5 in old spec)
- Add sections: Named Allocations, External Allocations, Docker Integration,
  Process Discovery, Lock Decision Matrix
- Document allocationTTL config, freezePeriod vs TTL semantics
- Update logging events (AllocExternal, AllocRefresh)
- Clarify STDOUT rules for different command modes

Code fixes:
- Fix help text: default.yaml -> config.yaml (was referencing wrong filename)
- Replace panic with error return in RefreshExternalAllocations (CLI tools
  should not panic on nil arguments)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…vention

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Instead of skipping the test on first TOCTOU, retry with the next free
port. This reduces flaky skips in busy environments (CI, parallel runs).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dapi dapi force-pushed the fix/flaky-test-lock-same-dir branch from 8aa364a to f6f8bdc Compare March 27, 2026 19:16
@dapi dapi merged commit a632619 into master Mar 27, 2026
7 checks passed
@dapi dapi deleted the fix/flaky-test-lock-same-dir branch March 27, 2026 19:17
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