

























@@ -80,7 +80,11 @@ async function createTestMcpLoopbackServer(port = 0) {
8080}
81818282function createCliBackendConfig(
83-params: { systemPromptOverride?: string | null; bundleMcp?: boolean } = {},
83+params: {
84+systemPromptOverride?: string | null;
85+bundleMcp?: boolean;
86+reseedFromRawTranscriptWhenUncompacted?: boolean;
87+} = {},
8488): OpenClawConfig {
8589return {
8690agents: {
@@ -97,6 +101,9 @@ function createCliBackendConfig(
97101sessionMode: "existing",
98102output: "text",
99103input: "arg",
104+ ...(params.reseedFromRawTranscriptWhenUncompacted
105+ ? { reseedFromRawTranscriptWhenUncompacted: true }
106+ : {}),
100107 ...(params.bundleMcp
101108 ? { bundleMcp: true, bundleMcpMode: "claude-config-file" as const }
102109 : {}),
@@ -561,6 +568,89 @@ describe("shouldSkipLocalCliCredentialEpoch", () => {
561568}
562569});
563570571+it("prepares raw-tail history for safe invalidations only when the backend opts in", async () => {
572+const { dir, sessionFile } = createSessionFile();
573+appendTranscriptEntry(sessionFile, {
574+id: "msg-1",
575+parentId: null,
576+timestamp: new Date(1).toISOString(),
577+message: {
578+role: "user",
579+content: "prior no-compaction ask",
580+timestamp: 1,
581+},
582+});
583+584+try {
585+const context = await prepareCliRunContext({
586+sessionId: "session-test",
587+ sessionFile,
588+workspaceDir: dir,
589+prompt: "latest ask",
590+provider: "test-cli",
591+model: "test-model",
592+timeoutMs: 1_000,
593+runId: "run-test-raw-reseed-opt-in",
594+extraSystemPrompt: "changed stable prompt",
595+extraSystemPromptStatic: "changed stable prompt",
596+cliSessionBinding: {
597+sessionId: "cli-session",
598+extraSystemPromptHash: hashCliSessionText("old stable prompt"),
599+},
600+config: createCliBackendConfig({
601+systemPromptOverride: null,
602+reseedFromRawTranscriptWhenUncompacted: true,
603+}),
604+});
605+606+expect(context.reusableCliSession).toEqual({ invalidatedReason: "system-prompt" });
607+expect(context.openClawHistoryPrompt).toContain("prior no-compaction ask");
608+expect(context.openClawHistoryPrompt).toContain("latest ask");
609+} finally {
610+fs.rmSync(dir, { recursive: true, force: true });
611+}
612+});
613+614+it("prepares opted-in raw-tail history for session-expired retry without disabling native resume", async () => {
615+const { dir, sessionFile } = createSessionFile();
616+appendTranscriptEntry(sessionFile, {
617+id: "msg-1",
618+parentId: null,
619+timestamp: new Date(1).toISOString(),
620+message: {
621+role: "user",
622+content: "prior resumable ask",
623+timestamp: 1,
624+},
625+});
626+627+try {
628+const context = await prepareCliRunContext({
629+sessionId: "session-test",
630+ sessionFile,
631+workspaceDir: dir,
632+prompt: "latest ask",
633+provider: "test-cli",
634+model: "test-model",
635+timeoutMs: 1_000,
636+runId: "run-test-session-expired-reseed-opt-in",
637+cliSessionBinding: {
638+sessionId: "cli-session",
639+},
640+config: createCliBackendConfig({
641+systemPromptOverride: null,
642+reseedFromRawTranscriptWhenUncompacted: true,
643+}),
644+});
645+646+expect(context.reusableCliSession).toEqual({ sessionId: "cli-session" });
647+expect(context.openClawHistoryPrompt).toContain("prior resumable ask");
648+expect(context.openClawHistoryPrompt).toContain("latest ask");
649+} finally {
650+fs.rmSync(dir, { recursive: true, force: true });
651+}
652+});
653+564654it("applies direct-run prepend system context helpers on the CLI path", async () => {
565655const { dir, sessionFile } = createSessionFile();
566656try {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。