Skip to content

refactor: consolidate safeSSABuild into shared internal/ssaguard package - #240

Merged
jflowers merged 1 commit into
unbound-force:mainfrom
yvonnedevlinrh:opsx/consolidate-ssa-guard
Aug 31, 2026
Merged

refactor: consolidate safeSSABuild into shared internal/ssaguard package#240
jflowers merged 1 commit into
unbound-force:mainfrom
yvonnedevlinrh:opsx/consolidate-ssa-guard

Conversation

@yvonnedevlinrh

Copy link
Copy Markdown
Contributor

Summary

Extract the byte-identical safeSSABuild recover-guard — previously duplicated in internal/analysis/mutation.go and internal/quality/pairing.go — into a new stdlib-only leaf package internal/ssaguard with an exported SafeSSABuild. Reverses spec-021 R3 (duplication-for-dependency-lightness), which no longer applies because the guard has zero external dependencies.

Closes #238.

What changed

  • New internal/ssaguard — exported SafeSSABuild(buildFn func()) (panicVal any), zero imports. GoDoc documents the ssa.BuildSerially caller precondition and the goroutine-scoped recover() rationale (spec 033); the guard is documentation-only and does not validate build mode at runtime.
  • Both callers delegateanalysis.BuildSSA and quality.BuildTestSSA call ssaguard.SafeSSABuild(prog.Build), retaining ssa.BuildSerially in the mode flags and the caller-side log.Warn/log.Debug calls (preserves pkg.PkgPath diagnostic context — logging deliberately not moved into the guard).
  • Duplication removed — local safeSSABuild defs, the SafeSSABuild export_test.go shims, and the duplicated TestSafeSSABuild_* test triads; deleted the now-empty internal/quality/pairing_test.go.
  • Tests consolidated — 3 canonical tests in internal/ssaguard/ssaguard_test.go (100% branch coverage). Net test count -3, behavioral coverage neutral.
  • Docs — updated AGENTS.md (Architecture list + Recent Changes) and docs/concepts/analysis-pipeline.md.

How to Test

go build ./cmd/gaze
go test -race -count=1 ./internal/ssaguard/
go test -race -count=1 -short ./internal/analysis/ ./internal/quality/
go test -race -count=1 -short ./...
golangci-lint run

Verify duplication is gone:

# no local definition anywhere
grep -rn "func safeSSABuild" internal/    # expect: no matches

# exactly the new shared call sites + tests
grep -rn "ssaguard.SafeSSABuild" internal/    # mutation.go, pairing.go, ssaguard_test.go

Acceptance scenarios (from openspec/changes/consolidate-ssa-guard/specs/ssaguard/spec.md):

  • SafeSSABuild returns nil when buildFn does not panic.
  • SafeSSABuild returns the recovered value when buildFn panics with a string.
  • SafeSSABuild returns the recovered value when buildFn panics with an error.
  • GoDoc documents the ssa.BuildSerially invariant (documentation-only, no runtime validation).
  • Both SSA build sites use the shared guard and retain their caller-side log.Warn/log.Debug calls.

How to Demo

gaze analyze ./...
gaze quality ./...

Both run through BuildSSA / BuildTestSSA and exercise the shared guard; a panicking SSA build for any package is recovered and logged with its pkg.PkgPath rather than crashing the process.

Key Files Changed

File Change
internal/ssaguard/ssaguard.go New — exported SafeSSABuild, stdlib-only, BuildSerially GoDoc
internal/ssaguard/ssaguard_test.go New — 3 canonical tests (100% branch coverage)
internal/analysis/mutation.go BuildSSA delegates to ssaguard.SafeSSABuild; local guard removed
internal/quality/pairing.go BuildTestSSA delegates; local guard + R3 lineage comment removed
internal/analysis/mutation_test.go Removed dup TestSafeSSABuild_*; comment updated
internal/analysis/export_test.go Removed SafeSSABuild shim
internal/quality/export_test.go Removed SafeSSABuild shim
internal/quality/pairing_test.go Deleted (held only the dup triad)
AGENTS.md Architecture list + Recent Changes entry
docs/concepts/analysis-pipeline.md Updated guard reference
openspec/changes/consolidate-ssa-guard/** OpenSpec artifacts

This PR was generated by /uf.finale (AI-assisted).

@yvonnedevlinrh yvonnedevlinrh self-assigned this Aug 31, 2026
@yvonnedevlinrh yvonnedevlinrh added enhancement New feature or request refactor Improvements or cleanup of code labels Aug 31, 2026
@yvonnedevlinrh yvonnedevlinrh moved this to Ready for Review 👀 in Unbound Force Planning Aug 31, 2026
@yvonnedevlinrh
yvonnedevlinrh requested a review from a team August 31, 2026 13:05

@jflowers jflowers left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

PR Review: #240 — refactor: consolidate safeSSABuild into shared internal/ssaguard package

Clean, well-scoped DRY consolidation. All 8 acceptance criteria from #238 satisfied. No alignment, security, or constitution compliance findings.

CI: All 5 checks green (MegaLinter, Unit+Integration Go 1.24/1.25, E2E Go 1.24/1.25).

Key verifications: GoDoc correctly documents the BuildSerially goroutine-scoping invariant (spec-033). Logging retained at call sites (preserves pkg.PkgPath diagnostic context). stdlib-only — zero external dependencies. 100% branch coverage in canonical tests.

This review was generated by /uf.review-pr (AI-assisted).

Extract the byte-identical safeSSABuild recover-guard (duplicated in
internal/analysis/mutation.go and internal/quality/pairing.go) into a new
stdlib-only package internal/ssaguard with exported SafeSSABuild. Reverses
spec-021 R3 (duplication-for-dependency-lightness) since the guard has zero
external dependencies.

- Add internal/ssaguard with GoDoc documenting the ssa.BuildSerially caller
  precondition and goroutine-scoped recover() rationale (spec 033)
- Update BuildSSA and BuildTestSSA to call ssaguard.SafeSSABuild, retaining
  caller-side log.Warn/log.Debug (preserves pkg-path context)
- Remove duplicated TestSafeSSABuild_* triads and export_test.go shims;
  delete now-empty internal/quality/pairing_test.go
- Consolidate to 3 canonical tests (100% branch coverage); net test -3,
  behavioral coverage neutral
- Add OpenSpec artifacts and AGENTS.md/docs updates

Closes unbound-force#238

Assisted-by: claude-opus
Generated with AI assistance (claude-opus)
@jflowers
jflowers force-pushed the opsx/consolidate-ssa-guard branch from c3d5f5a to 61f42c2 Compare August 31, 2026 18:37
@jflowers
jflowers merged commit de3b4b5 into unbound-force:main Aug 31, 2026
5 checks passed
@yvonnedevlinrh
yvonnedevlinrh deleted the opsx/consolidate-ssa-guard branch September 1, 2026 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request refactor Improvements or cleanup of code

Projects

Status: Ready for Review 👀

Development

Successfully merging this pull request may close these issues.

refactor: consolidate safeSSABuild into a shared package

3 participants