MCPcopy Create free account
hub / github.com/docker/docker-agent / TestInputCompactionFieldsSerialize

Function TestInputCompactionFieldsSerialize

pkg/hooks/hooks_test.go:952–980  ·  view source on GitHub ↗

TestInputCompactionFieldsSerialize pins the wire format for the compaction-specific Input fields so external (command-type) hooks can rely on it.

(t *testing.T)

Source from the content-addressed store, hash-verified

950// compaction-specific Input fields so external (command-type) hooks can
951// rely on it.
952func TestInputCompactionFieldsSerialize(t *testing.T) {
953 t.Parallel()
954
955 input := &Input{
956 SessionID: "sess-789",
957 HookEventName: EventBeforeCompaction,
958 InputTokens: 120_000,
959 OutputTokens: 8_000,
960 ContextLimit: 200_000,
961 CompactionReason: "overflow",
962 }
963
964 data, err := input.ToJSON()
965 require.NoError(t, err)
966
967 var parsed map[string]any
968 require.NoError(t, json.Unmarshal(data, &parsed))
969
970 assert.Equal(t, "sess-789", parsed["session_id"])
971 assert.Equal(t, "before_compaction", parsed["hook_event_name"])
972 assert.EqualValues(t, 120_000, parsed["input_tokens"])
973 assert.EqualValues(t, 8_000, parsed["output_tokens"])
974 assert.EqualValues(t, 200_000, parsed["context_limit"])
975 assert.Equal(t, "overflow", parsed["compaction_reason"])
976 // Summary is omitted on before_compaction inputs (it's only set on
977 // after_compaction so handlers receive the produced summary).
978 _, hasSummary := parsed["summary"]
979 assert.False(t, hasSummary)
980}

Callers

nothing calls this directly

Calls 1

ToJSONMethod · 0.95

Tested by

no test coverage detected