Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Adding a Statistical Test

Run the site checklist first. make sites ARGS="new-op test" prints every file and declaration a new TEST_* lands in — derived from where the existing ones appear — with the tests to rerun and the goldens to regenerate; make sites ARGS="op <NAME>" does the same for an existing one. See Finding Change Sites. This recipe explains each step.

Embedding Pulse, not contributing to it? This recipe adds a built-in in internal/processing/, which embedders cannot import. To add your own operator, implement the matching contract in the public extend package instead — see Extension Points.

Audience: internals contributors adding a new TEST_* operator — tier-1 (row-stream) or tier-2 (post-test on the materialised result set).

The recipe mirrors the aggregator and feature recipes; the test-specific moving parts are streamability, the test catalog, and the registered-test capability table. The binding companion list is the operator row of .claude/reference/update-demand/operators-and-guidance.md.

1. Decide tier

  • Tier 1. Runs against the raw row stream, alongside aggregators. Online-moments tests (TEST_T, TEST_WELCH, TEST_CHISQ, TEST_ANOVA_F) stay in the streaming Process path. Sort-required tests (TEST_KS) force the buffered path.
  • Tier 2. Runs after the result set is materialised, in req.PostTests. Always buffered.

2. Declare the type constant

Add to types/types.go:

const (
    // ... existing constants ...
    TEST_GINI_TREND TestType = "TEST_GINI_TREND"
)

Add it to types.AllTestTypes().

3. Implement and register

Tests live in internal/processing/test_*.go. Existing examples to mirror:

  • internal/processing/test_t.go — online tier-1 test.
  • internal/processing/test_anova.go — tier-1 ANOVA with grouper support.
  • internal/processing/test_post.go and internal/processing/test_post_more.go — tier-2 post-tests.
  • internal/processing/test_studentized.go — numerical integration utilities (used by TEST_TUKEY_HSD).

Register the test in internal/processing/test.go (the registry construction calls). For tier-2 variants, declare both the base type and the variant identifier the post-test surface uses.

4. Streamability

Add a case in types/streamability.go for the new TestType:

func (t TestType) Streamable() bool {
    switch t {
    // ...
    case TEST_GINI_TREND:
        return false // sort-based
    }
}

Add the matching row in types/streamability_test.go so TestStreamability_TestsKnown passes.

5. Capability declaration

Add a row to internal/descriptor/capabilities_tests.go:

  • For a tier-1 test, declare it in the tier-1 catalog (testCapabilities).
  • For a tier-2 post-test, declare it in postTestCapabilities.

TestManifestTestsComplete and TestManifestPostTestsComplete enforce that the manifest enumerates every registered test.

6. Skill update

Write the atomic skill skills/op-test-gini-trend.md (the operator name lowercased, _ → -: skills.OperatorStem) (.claude/reference/skill-pack.md; copy skills/op-test-t.md): family, inputs, outputs (statistic, p, df, effect size, …), and any preconditions (the error codes it can raise). For tier-2 variants, also document the variant field shape the post-test API exposes. Touch the topical skills/statistical-testing.md (“Decision criteria”, “Picking the tier”) when the test changes which test an agent should pick.

7. Tests

Use the same TDD pattern as for aggregators. The processing package has rich existing test files to model new cases against: processor_test_pipeline_test.go, test_parametric_test.go, test_nonparametric_test.go, test_post_more_test.go. Add hermetic fixtures that exercise the streaming and buffered paths.

8. Error codes

Reuse an existing code where one fits. A new failure mode follows Adding an Error Code: the constant in errors/codes.go, a codeMetadata entry (Message + Fixups) in errors/fixup_metadata.go, and an owner in internal/descriptor/error_owners.go.

9. The other per-operator tables

Every test also has an entry in internal/weighting/weighting.go, builtinFeatures (internal/descriptor/features.go), internal/descriptor/purposes_stattests.go, internal/descriptor/interpretations_stattests.go, internal/descriptor/validation_registry.go, the Explain response reader (internal/guide/explain_response.go) and, for most, the accepted-types table (internal/fieldaccept/fieldaccept.go). make sites ARGS="new-op test" names each with an exemplar line. Add an internal/examples/tests/NN_<name>.json example whose _meta.operators names the test (TestEveryOperatorHasAnExampleTag). CLAUDE.md is not a companion.

10. Run the gates

make sites ARGS="op TEST_GINI_TREND" prints the full gate set. At minimum:

go test -count=1 ./types/ -run TestStreamability_TestsKnown
go test -count=1 ./internal/processing/ -run 'TestProcessor_Tier1|TestProcessor_PostTest'
go test -count=1 ./descriptor/ ./internal/descriptor/ -run TestManifest
go test -count=1 ./internal/skills/ -run 'TestOperatorHasAtomicSkill|TestSkillsCoverAll'
go test -count=1 ./internal/weighting/ ./internal/guide/ ./internal/examples/
go test -count=1 ./descriptor/ -update && go test -count=1 ./descriptor/
make docs

See The Update Demand.