Skip to content

[testify-expert] Improve Test Quality: ./pkg/atif/convert_test.go #77821

Done

Description

@github-actions

Current state

  • File: ./pkg/atif/convert_test.go (438 lines, package atif)
  • Source pair: pkg/atif/convert.go
  • Test functions: 15 top-level Test* functions with 11 t.Run subtests
  • Assertions: require only (no assert import)
  • Coverage: not measured in this run because the Go module download failed in the sandbox

Strengths

  • TestConvertEngineVersion and TestConvertRejectsInvalidInput are table-driven, and the latter checks messages with ErrorContains
  • Metric tests (TestConvertMetrics, TestConvertReconcilesMetricSnapshots, TestConvertMetricScopes) use subtests for each scenario
  • TestConvertConversation checks determinism, and most index access is guarded by require.Len

Prioritized improvements

1. Missing or high-value tests

  • Validate() in trajectory.go (lines 73-111) has several error branches: non-sequential step IDs, invalid source, agent-only fields, invalid timestamp, invalid tool call, and unsupported schema. Only the unmatched ATIF observation branch is asserted, through Encode at line 411. Add a table test that checks each message with ErrorContains.
  • Encode (trajectory.go line 114) has no test for a writer that fails. Add a failing io.Writer and assert the error is returned.
  • reconcileMetrics (metrics.go) has a fallback for a usage field that is present but not a JSON object. No test input reaches it.
  • The oversize check at line 391 uses bare require.Error. Switch it to require.ErrorContains so the 64 MiB message is pinned.

2. Testify assertion upgrades

  • Validation checks in TestConvertConversation and TestConvertTools can use assert so one failing run reports every mismatch. Keep require for setup steps such as require.NoError on Convert and require.Len before indexing.
  • TestConvertToolProvenanceScope (lines 174-177) indexes Steps[0], Steps[1], and Steps[3] with no require.Len guard.
  • Unchecked type assertions at lines 98 and 125 panic on mismatch instead of failing cleanly.
Before and after example for the type assertion
// before
raw := trajectory.Steps[6].Extra["unified_event"].(json.RawMessage)

// after
raw, ok := trajectory.Steps[6].Extra["unified_event"].(json.RawMessage)
require.True(t, ok, "unified_event should be json.RawMessage")

3. Table-driven refactors

  • TestConvertNestedCallerContext, TestConvertToolProvenanceScope, and TestEncodeRejectsInvalidTrajectory each check a single case. Convert them to table tests when they share setup or when more cases are added.

4. Organization and readability

  • repeatingReader is defined in convert_test.go (package atif), and spec_test.go (package atif_test) has its own reader helper. Consolidate the duplicated logic into one test helper file.
  • TestCompatibilityFixtures writes files as a side effect when ATIF_VALIDATION_DIR is set. Isolate that path in its own test so the side effect is explicit.

Acceptance checklist

  • Add a table test for each Validate() error message
  • Add a failing-writer test for Encode
  • Add a reconcileMetrics test with a non-object usage value
  • Change the oversize check to require.ErrorContains
  • Add require.Len guards in TestConvertToolProvenanceScope
  • Replace unchecked json.RawMessage assertions with checked assertions
  • Move post-setup validations from require to assert
  • Run make fmt, then make lint
  • Run make test-unit and confirm pkg/atif passes
  • Measure coverage with go test -coverprofile before and after the change

Generated by 🧪 Daily Testify Uber Super Expert · copilot · routed: haiku55 xhigh · ~8 AIC · ⌖ ~2 AIC · ⊞ 3.9K · ◷

  • expires on Nov 16, 2026, 10:10 AM UTC-08:00

Activity

  1. github-actions commented on Nov 14, 2026

    @github-actions
    ContributorAuthor

    🍪 Issue Monster selected this for Copilot

    I've identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.

    If assignment succeeds, Copilot will analyze the issue and create a pull request with the fix.

    Om nom nom! 🍪

    🍪 Om nom nom by Issue Monster · pi · gpt50 · ~1 AIC · ⌖ ~1 AIC · ⊞ 9.4K · ◷

  2. linked a pull request that will close this issueImprove ATIF conversion test coverage #77823on Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions