|
1 | 1 | // Full-entry coverage for retrying empty errored assistant turns. |
2 | 2 | import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; |
3 | 3 | import type { OpenClawTestState } from "../../test-utils/openclaw-test-state.js"; |
| 4 | +import { makeAssistantMessageFixture } from "../test-helpers/assistant-message-fixtures.js"; |
4 | 5 | import { makeAttemptResult } from "./run.overflow-compaction.fixture.js"; |
5 | 6 | import { |
6 | 7 | mockedClassifyAssistantFailoverReason, |
@@ -185,4 +186,75 @@ describe("runEmbeddedAgent silent-error retry", () => { |
185 | 186 | fallbackSafe: false, |
186 | 187 | }); |
187 | 188 | }); |
| 189 | + describe("current-assistant provenance", () => { |
| 190 | + it("ignores a historical refusal after compaction", async () => { |
| 191 | + const refusal = makeAssistantMessageFixture({ |
| 192 | + api: "anthropic-messages", |
| 193 | + provider: "anthropic", |
| 194 | + model: "claude-opus-5", |
| 195 | + stopReason: "error", |
| 196 | + content: [], |
| 197 | + errorMessage: "historical refusal", |
| 198 | + diagnostics: [{ type: "provider_refusal", timestamp: 1, details: { category: "cyber" } }], |
| 199 | + }); |
| 200 | + mockedRunEmbeddedAttempt |
| 201 | + .mockResolvedValueOnce( |
| 202 | + makeAttemptResult({ |
| 203 | + assistantTexts: [], |
| 204 | + lastAssistant: refusal, |
| 205 | + currentAttemptAssistant: undefined, |
| 206 | + currentAttemptCompletedAssistant: undefined, |
| 207 | + compactionCount: 1, |
| 208 | + }), |
| 209 | + ) |
| 210 | + .mockResolvedValueOnce(successAttempt("anthropic", "claude-opus-5")); |
| 211 | + |
| 212 | + const result = await runEmbeddedAgent({ |
| 213 | + ...createOverflowRunParams(state), |
| 214 | + provider: "anthropic", |
| 215 | + model: "claude-opus-5", |
| 216 | + runId: "run-historical-refusal-after-compaction", |
| 217 | + }); |
| 218 | + |
| 219 | + expect(mockedRunEmbeddedAttempt).toHaveBeenCalledTimes(2); |
| 220 | + expect(result.meta.error).toBeUndefined(); |
| 221 | + expect(result.payloads?.some((payload) => payload.text?.includes("refused"))).not.toBe(true); |
| 222 | + }); |
| 223 | + |
| 224 | + it("preserves a completed current refusal after transcript projection removes its slice", async () => { |
| 225 | + const refusal = makeAssistantMessageFixture({ |
| 226 | + api: "anthropic-messages", |
| 227 | + provider: "anthropic", |
| 228 | + model: "claude-opus-5", |
| 229 | + stopReason: "error", |
| 230 | + content: [], |
| 231 | + errorMessage: "current refusal", |
| 232 | + diagnostics: [{ type: "provider_refusal", timestamp: 2, details: { category: "cyber" } }], |
| 233 | + }); |
| 234 | + mockedRunEmbeddedAttempt |
| 235 | + .mockResolvedValueOnce( |
| 236 | + makeAttemptResult({ |
| 237 | + assistantTexts: [], |
| 238 | + lastAssistant: undefined, |
| 239 | + currentAttemptAssistant: undefined, |
| 240 | + currentAttemptCompletedAssistant: refusal, |
| 241 | + compactionCount: 1, |
| 242 | + }), |
| 243 | + ) |
| 244 | + .mockResolvedValueOnce(successAttempt("anthropic", "claude-opus-5")); |
| 245 | + |
| 246 | + const result = await runEmbeddedAgent({ |
| 247 | + ...createOverflowRunParams(state), |
| 248 | + provider: "anthropic", |
| 249 | + model: "claude-opus-5", |
| 250 | + runId: "run-completed-refusal-without-transcript-slice", |
| 251 | + }); |
| 252 | + |
| 253 | + expect(mockedRunEmbeddedAttempt).toHaveBeenCalledTimes(1); |
| 254 | + expect(result.payloads?.[0]).toMatchObject({ |
| 255 | + isError: true, |
| 256 | + text: "The provider refused this request (category: cyber). Revise the request and try again.", |
| 257 | + }); |
| 258 | + }); |
| 259 | + }); |
188 | 260 | }); |
0 commit comments