← Back to Pull requests

[200~add CreateResponseCapped conformance cases (#120) #127

Closed
unknown closed this pull request without merging on Nov 30, 2026 20:25 UTC
View on GitHub
unknown unknown commented on Nov 30, 2026 18:58 UTC
Author

Closes #120. Follow-up to #117.

Why

#117 made CreateResponseCapped mandatory on surveys.Repository, so an adapter without it won't compile. But internal/store/storetest only called CreateResponse, so nothing checked how the cap behaves. A future adapter (e.g. Postgres) could pass conformance and still enforce it wrong.

What

New subtests in RunSurveyRepository (internal/store/storetest/surveytest.go), using only the surveys.Repository interface:

| Subtest | Pins |
|---|---|
| CreateResponseCappedEnforcesPerRiderCap | A rider at maxPerRider gets ErrTooManyResponses and nothing is stored (the rejected public ID is ErrNotFound; the rider's count stays at the cap). Another rider on the same survey, and the same rider on another survey, are unaffected. Responses written through plain CreateResponse count toward the cap. The cap is 2, so "at the cap" isn't confused with "has any response". |
| CreateResponseCappedNonPositiveMeansNoCap | A maxPerRider of 0 or -1 lets every create land. |
| CreateResponseCappedUnknownSurvey | An unknown survey is ErrNotFound with and without a cap, not a raw FK error. |
| CreateResponseCappedConcurrentSameUser | Moved from internal/store/sqlite/capped_test.go (deleted). With maxPerRider=1, exactly one of 8 concurrent creates from one rider succeeds. |

Concurrency test: moved and strengthened

It only ever needed the Repository interface, so it now lives in the suite and any future adapter inherits it. The SQLite conformance run still goes through the production Open, so the _txlock=immediate DSN it relies on is unchanged.

Mutation testing showed the single-round version was weak. With the cap counted before BEGIN, the exact race it exists to catch, it failed in only 3 of 50 runs. It now runs 25 rounds, each with a fresh rider on the same survey, and fails in 50 of 50 runs under that mutation. The test takes about 0.2s.

Mutation check

Each case was confirmed to fail against a deliberately broken SQLite adapter (source restored after each):

| Mutation | Caught by |
|---|---|
| n > maxPerRider (off-by-one) | EnforcesPerRiderCap, ConcurrentSameUser |
| maxPerRider >= 0 (0 treated as a cap) | NonPositiveMeansNoCap, EnforcesPerRiderCap |
| maxPerRider != 0 (-1 treated as a cap) | NonPositiveMeansNoCap |
| count ignores user_identifier | EnforcesPerRiderCap |
| count ignores survey_id | EnforcesPerRiderCap, NonPositiveMeansNoCap |
| survey-existence check removed | UnknownSurvey |
| rejected create committed anyway | EnforcesPerRiderCap, ConcurrentSameUser |
| cap counted before BEGIN | ConcurrentSameUser (50/50 runs) |

Verification

  • make fmt-check vet lint (golangci-lint 2.12.2): 0 issues

  • make test test-race web-check: pass

  • TestSurveyConformance with -count=1 under TZ=UTC and TZ=Asia/Kathmandu: pass

  • make generate-check not run locally (sqlc not installed); no .sql or gen/ files touched
  • Diff: 371 lines (+278 / -93) across 4 files Reviewer: aaronbrethorst Review duration: 86m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 371 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.354
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #127"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.8% (MEDIUM) · Higher = larger blast radius
    42.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.9% · Safe to merge
    16.9%