



























@@ -4,6 +4,7 @@ import path from "node:path";
44import type { AgentMessage } from "@mariozechner/pi-agent-core";
55import { SessionManager } from "@mariozechner/pi-coding-agent";
66import type { EmbeddedRunAttemptParams } from "openclaw/plugin-sdk/agent-harness";
7+import { embeddedAgentLog } from "openclaw/plugin-sdk/agent-harness-runtime";
78import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
89import type { ContextEngine } from "../../../../src/context-engine/types.js";
910import type { CodexServerNotification } from "./protocol.js";
@@ -365,6 +366,41 @@ describe("runCodexAppServerAttempt context-engine lifecycle", () => {
365366);
366367});
367368369+it("logs assemble failures as a formatted message instead of the raw error object", async () => {
370+const sessionFile = path.join(tempDir, "session.jsonl");
371+const workspaceDir = path.join(tempDir, "workspace");
372+const rawError = new Error("Authorization: Bearer sk-abcdefghijklmnopqrstuv");
373+const contextEngine = createContextEngine({
374+assemble: vi.fn(async () => {
375+throw rawError;
376+}),
377+bootstrap: undefined,
378+});
379+const warn = vi.spyOn(embeddedAgentLog, "warn").mockImplementation(() => undefined);
380+const harness = createStartedThreadHarness();
381+const params = createParams(sessionFile, workspaceDir);
382+params.contextEngine = contextEngine;
383+384+const run = runCodexAppServerAttempt(params);
385+await harness.waitForMethod("turn/start");
386+await harness.completeTurn();
387+await run;
388+389+expect(warn).toHaveBeenCalledWith(
390+"context engine assemble failed; using Codex baseline prompt",
391+{
392+error: expect.any(String),
393+},
394+);
395+const warning = warn.mock.calls.find(
396+([message]) => message === "context engine assemble failed; using Codex baseline prompt",
397+);
398+expect(warning?.[1]).not.toEqual({ error: rawError });
399+expect(String((warning?.[1] as { error?: unknown } | undefined)?.error)).not.toContain(
400+"sk-abcdefghijklmnopqrstuv",
401+);
402+});
403+368404it("falls back to ingestBatch and skips turn maintenance on prompt failure", async () => {
369405const sessionFile = path.join(tempDir, "session.jsonl");
370406const workspaceDir = path.join(tempDir, "workspace");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。