|
2 | 2 | import { describe, expect, it } from "vitest"; |
3 | 3 | import { |
4 | 4 | filterHeartbeatTranscriptArtifacts, |
| 5 | + isExecCompletionUserMessage, |
5 | 6 | isHeartbeatOkResponse, |
6 | 7 | isHeartbeatUserMessage, |
7 | 8 | } from "./heartbeat-filter.js"; |
8 | 9 | import { |
| 10 | + EXEC_COMPLETION_TRANSCRIPT_PROMPT, |
9 | 11 | HEARTBEAT_RESPONSE_TOOL_PROMPT, |
10 | 12 | HEARTBEAT_PROMPT, |
11 | 13 | HEARTBEAT_TRANSCRIPT_PROMPT, |
@@ -46,6 +48,13 @@ describe("isHeartbeatUserMessage", () => { |
46 | 48 | }), |
47 | 49 | ).toBe(true); |
48 | 50 |
|
| 51 | + expect( |
| 52 | + isHeartbeatUserMessage({ |
| 53 | + role: "user", |
| 54 | + content: EXEC_COMPLETION_TRANSCRIPT_PROMPT, |
| 55 | + }), |
| 56 | + ).toBe(true); |
| 57 | + |
49 | 58 | const customHeartbeatPrompt = "Check the handoff queue."; |
50 | 59 | expect( |
51 | 60 | isHeartbeatUserMessage( |
@@ -136,6 +145,49 @@ describe("isHeartbeatOkResponse", () => { |
136 | 145 | }); |
137 | 146 | }); |
138 | 147 |
|
| 148 | +describe("isExecCompletionUserMessage", () => { |
| 149 | + it("matches exec completion transcript prompt", () => { |
| 150 | + expect( |
| 151 | + isExecCompletionUserMessage({ |
| 152 | + role: "user", |
| 153 | + content: EXEC_COMPLETION_TRANSCRIPT_PROMPT, |
| 154 | + }), |
| 155 | + ).toBe(true); |
| 156 | + }); |
| 157 | + |
| 158 | + it("matches exec completion prompt with exec details appended", () => { |
| 159 | + expect( |
| 160 | + isExecCompletionUserMessage({ |
| 161 | + role: "user", |
| 162 | + content: `${EXEC_COMPLETION_TRANSCRIPT_PROMPT}\n\nExec completed (session-id, code 0) :: done`, |
| 163 | + }), |
| 164 | + ).toBe(true); |
| 165 | + }); |
| 166 | + |
| 167 | + it("rejects non-exec messages", () => { |
| 168 | + expect( |
| 169 | + isExecCompletionUserMessage({ |
| 170 | + role: "user", |
| 171 | + content: "hello", |
| 172 | + }), |
| 173 | + ).toBe(false); |
| 174 | + |
| 175 | + expect( |
| 176 | + isExecCompletionUserMessage({ |
| 177 | + role: "user", |
| 178 | + content: HEARTBEAT_TRANSCRIPT_PROMPT, |
| 179 | + }), |
| 180 | + ).toBe(false); |
| 181 | + |
| 182 | + expect( |
| 183 | + isExecCompletionUserMessage({ |
| 184 | + role: "assistant", |
| 185 | + content: EXEC_COMPLETION_TRANSCRIPT_PROMPT, |
| 186 | + }), |
| 187 | + ).toBe(false); |
| 188 | + }); |
| 189 | +}); |
| 190 | + |
139 | 191 | describe("filterHeartbeatTranscriptArtifacts", () => { |
140 | 192 | it("removes no-op heartbeat pairs", () => { |
141 | 193 | const messages = [ |
@@ -991,4 +1043,24 @@ describe("filterHeartbeatTranscriptArtifacts", () => { |
991 | 1043 | messages, |
992 | 1044 | ); |
993 | 1045 | }); |
| 1046 | + |
| 1047 | + it("removes exec completion pairs alongside heartbeat pairs", () => { |
| 1048 | + const messages = [ |
| 1049 | + { role: "user", content: "Hello" }, |
| 1050 | + { role: "assistant", content: "Hi!" }, |
| 1051 | + { role: "user", content: EXEC_COMPLETION_TRANSCRIPT_PROMPT }, |
| 1052 | + { role: "assistant", content: "HEARTBEAT_OK" }, |
| 1053 | + { role: "user", content: HEARTBEAT_TRANSCRIPT_PROMPT }, |
| 1054 | + { role: "assistant", content: "HEARTBEAT_OK" }, |
| 1055 | + { role: "user", content: "What time is it?" }, |
| 1056 | + { role: "assistant", content: "3pm." }, |
| 1057 | + ]; |
| 1058 | + |
| 1059 | + expect(filterHeartbeatTranscriptArtifacts(messages, undefined, HEARTBEAT_PROMPT)).toEqual([ |
| 1060 | + { role: "user", content: "Hello" }, |
| 1061 | + { role: "assistant", content: "Hi!" }, |
| 1062 | + { role: "user", content: "What time is it?" }, |
| 1063 | + { role: "assistant", content: "3pm." }, |
| 1064 | + ]); |
| 1065 | + }); |
994 | 1066 | }); |
0 commit comments