Repository navigation
Expand file tree
/
Copy pathtest_summarizer.cpp
More file actions
158 lines (123 loc) · 5.75 KB
/
Copy pathtest_summarizer.cpp
File metadata and controls
158 lines (123 loc) · 5.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include "summarizer.h"
#include "inference.h"
#include <cassert>
#include <print>
#include <string>
using ragger::is_system_injected_turn;
using ragger::summarize_transcript;
using ragger::strip_thinking;
// System-injected user turns: should be detected (summarizer skips them).
void test_detects_system_markers() {
std::print(" test_detects_system_markers...");
assert(is_system_injected_turn(
"[System note: Your previous turn was interrupted before you could "
"process the last tool result(s)."));
assert(is_system_injected_turn(
"[Note: model was just switched from claude-sonnet-4-6 to "
"claude-opus-4-8 via Anthropic. Adjust your self-identification.]"));
assert(is_system_injected_turn(
"[CONTEXT COMPACTION — REFERENCE ONLY] Earlier turns were compacted."));
assert(is_system_injected_turn(
"[IMPORTANT: Background process proc_b623911a9a5d completed (exit code 1)."));
// Leading whitespace must not defeat detection.
assert(is_system_injected_turn(" \n[System note: foo"));
std::println(" ok");
}
// Genuine human messages: must NOT be treated as system-injected.
void test_ignores_human_turns() {
std::print(" test_ignores_human_turns...");
assert(!is_system_injected_turn("Next item: storing system messages."));
assert(!is_system_injected_turn("stop. leaving it blank is appropriate."));
assert(!is_system_injected_turn(""));
// A bracketed but non-system opener is left alone.
assert(!is_system_injected_turn("[note] check this out"));
// OUT-OF-BAND wraps a real human message — intentionally NOT a marker.
assert(!is_system_injected_turn(
"[OUT-OF-BAND USER MESSAGE] actually, do it the other way"));
std::println(" ok");
}
// Assistant-only turns (system-injected user side blanked upstream): the
// trivial-turn shortcut must return the assistant text cleanly, never a
// degenerate "User: " prefix or empty-prompt artifact. This path returns
// before any inference call, so an empty-endpoint client is safe.
void test_assistant_only_trivial() {
std::print(" test_assistant_only_trivial...");
ragger::InferenceClient inf({}, "", 4096); // no endpoints — never called
// Short assistant-only turn (<120 chars) → verbatim assistant text.
auto s = summarize_transcript(inf, {{ std::string{}, "Stopped." }});
assert(s == "Stopped.");
// Empty user + empty assistant → empty (nothing to summarize).
auto e = summarize_transcript(inf, {{ std::string{}, std::string{} }});
assert(e.empty());
// Normal short pair still joins user | assistant.
auto p = summarize_transcript(inf, {{ "hi", "hello there" }});
assert(p == "hi | hello there");
std::println(" ok");
}
// Stripping: capture-time removal of leading system annotations.
void test_strip_system_prefix() {
std::print(" test_strip_system_prefix...");
using ragger::strip_system_injected_prefix;
// The reported case: system note + the real one-word message.
assert(strip_system_injected_prefix(
"[System note: Your previous turn was interrupted before you could "
"process the last tool result(s). The conversation history contains "
"tool outputs you haven't responded to yet.]\n\nstop") == "stop");
// Note with nothing after it → empty.
assert(strip_system_injected_prefix(
"[System note: interrupted, please continue.]\n\n").empty());
// Model-switch note + real message.
assert(strip_system_injected_prefix(
"[Note: model was just switched from a to b via X.]\n\nturn 154")
== "turn 154");
// Stacked notes strip in sequence.
assert(strip_system_injected_prefix(
"[Note: model was just switched from a to b via X.]\n"
"[System note: interrupted.]\n\ngo") == "go");
// Leading whitespace before the marker is tolerated.
assert(strip_system_injected_prefix(" \n[System note: x]\n\nhi") == "hi");
// A normal human message is returned untouched (trimmed).
assert(strip_system_injected_prefix("just a normal message")
== "just a normal message");
// Brackets inside the real message are preserved (only a LEADING marker
// block is stripped).
assert(strip_system_injected_prefix("use arr[0] not arr[1]")
== "use arr[0] not arr[1]");
// Unterminated note → nothing trustworthy follows → empty.
assert(strip_system_injected_prefix(
"[System note: truncated with no close").empty());
std::println(" ok");
}
void test_strip_thinking() {
std::print(" test_strip_thinking...");
// Basic <think>…</think> block stripped
assert(strip_thinking("<think>some reasoning</think>The actual answer.")
== "The actual answer.");
// Unterminated <think> — drop to end
assert(strip_thinking("<think>reasoning never closed").empty());
// Multiple blocks
assert(strip_thinking("<think>a</think>Answer<think>b</think> here.")
== "Answer here.");
// Bare "Thinking Process:\n…\n\n" preamble
assert(strip_thinking("Thinking Process:\n\n1. Do X\n2. Do Y\n\nThe real summary.")
== "The real summary.");
// Leading whitespace before preamble
assert(strip_thinking("\n\nThinking Process:\nstuff\n\nActual answer here.")
== "Actual answer here.");
// Normal summary untouched
assert(strip_thinking("Reid deployed the daemon successfully.")
== "Reid deployed the daemon successfully.");
// Empty input
assert(strip_thinking("").empty());
std::println(" ok");
}
int main() {
std::println("test_summarizer:");
test_detects_system_markers();
test_ignores_human_turns();
test_assistant_only_trivial();
test_strip_system_prefix();
test_strip_thinking();
std::println("All summarizer tests passed.");
return 0;
}