Skip to content

Bridge AST-to-SSA name gap to reach 90% mapping accuracy (SC-003) #6

Closed

Description

@jflowers

Problem

The quality.MapAssertionsToEffects() function traces SSA data flow to link test assertions to the side effects they verify. However, SSA register names (t0, t1, etc.) do not match AST variable names (got, err, etc.), so the mapping engine cannot bridge the gap between detected assertion sites and traced target values.

Current state: 0% mapping accuracy (0/42 assertions mapped across 6 test fixtures).
Spec target: SC-003 requires >= 90% accuracy for standard Go test patterns.

Impact

  • Contract Coverage metrics report 0% coverage even for well-tested functions
  • gaze quality output shows all assertions as unmapped
  • GazeCRAP scores (once wired) would be inflated due to missing contract coverage data

Technical Context

The mapping pipeline works in three stages:

  1. Assertion detection (AST-based) -- working correctly, finds 42+ assertion sites
  2. Target value tracing (SSA-based) -- working correctly, traces return values and mutations
  3. Linking -- broken: SSA values are identified by register names, AST assertions reference source-level variable names

The fix requires bridging AST positions to SSA values. Possible approaches:

  • Use go/types position info to correlate AST nodes with SSA instructions at the same source position
  • Build an AST-to-SSA map using ssautil.ValueForExpr() or similar
  • Use ssa.DebugRef instructions that link SSA values back to source-level names

References

  • internal/quality/mapping.go -- MapAssertionsToEffects(), traceTargetValues(), traceUses()
  • internal/quality/quality_test.go:1037-1070 -- TestSC003_MappingAccuracy with ratchet floor
  • cmd/gaze/main_test.go:773-776 -- TestRunQuality_ThresholdPass documents the limitation
  • Spec 003 spec.md SC-003 success criterion

Activity

  1. added
    enhancement
    on Feb 23, 2026
  2. added this to the v1.4.0 milestone on Mar 15, 2026
  3. jflowers commented on Mar 15, 2026

    @jflowers
    CollaboratorAuthor

    PR #56 partially addresses this issue with helper parameter bridging:

    Mapping accuracy: 78.8% (52/66) → 84.8% (56/66)

    Added CallerArgs to AssertionSite and buildHelperBridge to mapping.go. When a test calls assertEqual(t, got, 12), the assertion inside the helper now resolves got (helper param) → got (test variable) → side effect ID at confidence 70.

    Remaining gap to 90% (10/66 unmapped):

    • Inline call returns (if f() != x) — ~3-4
    • Complex helper patterns (multi-level, variadic) — ~3
    • Cross-target assertions — ~3

    Ratchet floor raised from 76.0% to 83.0%. Issue remains open for the remaining ~5% gap.

  4. jflowers commented on Mar 16, 2026

    @jflowers
    CollaboratorAuthor

    Closing as substantially addressed across multiple PRs in this session:

    Mechanical accuracy: 78.8% → 86.4%

    AI fallback for the remaining ~14%:

    Ratchet floor: Raised from 76.0% to 85.0%

    The remaining 9/66 unmapped assertions are cross-target assertions (test exercises function A but asserts on function B's output), go-cmp patterns with stub type info, and helper-internal variables — all addressable via the AI fallback path. The 90% target for mechanical-only mapping is not achievable without CodeQL-level interprocedural data flow analysis, which was evaluated and deferred (see session notes on CodeQL feasibility).

    Follow-up issues for continued improvement:

  5. added 3 commits that reference this issue on Aug 12, 2026
  6. added a commit that references this issue on Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions