(t *testing.T)
| 66 | } |
| 67 | |
| 68 | func TestCollectMemoryExtractorOutput(t *testing.T) { |
| 69 | t.Parallel() |
| 70 | |
| 71 | t.Run("Should preserve streamed JSONL chunks without synthetic newlines", func(t *testing.T) { |
| 72 | t.Parallel() |
| 73 | |
| 74 | events := make(chan acp.AgentEvent, 4) |
| 75 | events <- acp.AgentEvent{Type: acp.EventTypeAgentMessage, Text: "```jsonl\n{\"type\":\"reference\",\"scope"} |
| 76 | events <- acp.AgentEvent{ |
| 77 | Type: acp.EventTypeAgentMessage, |
| 78 | Text: "\":\"workspace\",\"agent_tier\":\"workspace\",\"content\":\"Channel marketing already exists.\",\"evidence\":\"seq=52\"", |
| 79 | } |
| 80 | events <- acp.AgentEvent{ |
| 81 | Type: acp.EventTypeAgentMessage, |
| 82 | Text: ",\"entity\":\"ws-test\",\"attribute\":\"network_channel_marketing_exists\"}\n```", |
| 83 | } |
| 84 | close(events) |
| 85 | |
| 86 | output, err := collectMemoryExtractorOutput(testutil.Context(t), events) |
| 87 | if err != nil { |
| 88 | t.Fatalf("collectMemoryExtractorOutput() error = %v", err) |
| 89 | } |
| 90 | if strings.Contains(output, "scope\n") { |
| 91 | t.Fatalf("output = %q, want no synthetic newline inside streamed JSON key", output) |
| 92 | } |
| 93 | |
| 94 | turn := memcontract.TurnRecord{ |
| 95 | SessionID: "sess-parent", |
| 96 | RootSessionID: "sess-parent", |
| 97 | AgentID: "cto", |
| 98 | ActorKind: "agent_root", |
| 99 | WorkspaceID: "ws-test", |
| 100 | SinceMessageSeq: 32, |
| 101 | UntilMessageSeq: 52, |
| 102 | Snapshot: memcontract.TranscriptSnapshot{ |
| 103 | Messages: []memcontract.TranscriptMessage{{ |
| 104 | Sequence: 52, |
| 105 | Role: "assistant", |
| 106 | Content: "Channel marketing exists.", |
| 107 | At: time.Date(2026, 5, 26, 21, 1, 52, 0, time.UTC), |
| 108 | }}, |
| 109 | }, |
| 110 | Trigger: memcontract.TriggerPostMessage, |
| 111 | } |
| 112 | candidates, err := parseMemoryExtractorCandidates( |
| 113 | output, |
| 114 | turn, |
| 115 | "/workspace/test", |
| 116 | time.Date(2026, 5, 26, 21, 2, 0, 0, time.UTC), |
| 117 | ) |
| 118 | if err != nil { |
| 119 | t.Fatalf("parseMemoryExtractorCandidates() error = %v", err) |
| 120 | } |
| 121 | if len(candidates) != 1 { |
| 122 | t.Fatalf("candidates = %#v, want one parsed candidate", candidates) |
| 123 | } |
| 124 | candidate := candidates[0] |
| 125 | if candidate.Scope != memcontract.ScopeWorkspace || candidate.Frontmatter.Type != memcontract.TypeReference { |
nothing calls this directly
no test coverage detected