|
1 | 1 | import type { AgentMessage } from "openclaw/plugin-sdk/agent-harness-runtime"; |
2 | 2 | import { describe, expect, it } from "vitest"; |
3 | 3 | import { projectSettledCodexMessages } from "./settled-turn-projection.js"; |
| 4 | +import { attachUpstreamUserText } from "./upstream-prompt-provenance.js"; |
4 | 5 |
|
5 | 6 | function message(value: unknown): AgentMessage { |
6 | 7 | return value as AgentMessage; |
@@ -196,6 +197,53 @@ describe("projectSettledCodexMessages", () => { |
196 | 197 | }); |
197 | 198 | }); |
198 | 199 |
|
| 200 | + it("preserves upstream user text above the ordinary message limit", () => { |
| 201 | + const upstreamUserText = "x".repeat(64 * 1024 + 1); |
| 202 | + |
| 203 | + expect( |
| 204 | + projectSettledCodexMessages([ |
| 205 | + attachUpstreamUserText( |
| 206 | + message({ role: "user", content: "[Telegram metadata] decorated prompt" }), |
| 207 | + upstreamUserText, |
| 208 | + ), |
| 209 | + toolCall(), |
| 210 | + toolResult(), |
| 211 | + ])[0], |
| 212 | + ).toEqual({ |
| 213 | + type: "message", |
| 214 | + role: "user", |
| 215 | + content: [{ type: "input_text", text: upstreamUserText }], |
| 216 | + }); |
| 217 | + }); |
| 218 | + |
| 219 | + it("rejects upstream user text above the projection limit", () => { |
| 220 | + expect(() => |
| 221 | + projectSettledCodexMessages([ |
| 222 | + attachUpstreamUserText( |
| 223 | + message({ role: "user", content: "[Telegram metadata] decorated prompt" }), |
| 224 | + "x".repeat(512 * 1024 + 1), |
| 225 | + ), |
| 226 | + toolCall(), |
| 227 | + toolResult(), |
| 228 | + ]), |
| 229 | + ).toThrow("oversized upstream user text"); |
| 230 | + }); |
| 231 | + |
| 232 | + it("charges upstream user text against the aggregate byte limit", () => { |
| 233 | + expect(() => |
| 234 | + projectSettledCodexMessages([ |
| 235 | + attachUpstreamUserText( |
| 236 | + message({ role: "user", content: "decorated" }), |
| 237 | + "x".repeat(400 * 1024), |
| 238 | + ), |
| 239 | + message({ role: "user", content: "x".repeat(60 * 1024) }), |
| 240 | + message({ role: "user", content: "x".repeat(60 * 1024) }), |
| 241 | + toolCall(), |
| 242 | + toolResult(), |
| 243 | + ]), |
| 244 | + ).toThrow("exceeds the byte limit"); |
| 245 | + }); |
| 246 | + |
199 | 247 | it("does not let provenance hide non-text user content", () => { |
200 | 248 | expect(() => |
201 | 249 | projectSettledCodexMessages([ |
|
0 commit comments