

























@@ -5,7 +5,6 @@ import {
55clearMemoryPluginState,
66registerMemoryPromptSection,
77} from "../../../plugins/memory-state.js";
8-import { derivePromptTokens } from "../../usage.js";
98import {
109type AttemptContextEngine,
1110buildLoopPromptCacheInfo,
@@ -16,8 +15,8 @@ import {
1615resolvePromptCacheTouchTimestamp,
1716runAttemptContextEngineBootstrap,
1817} from "./attempt.context-engine-helpers.js";
19-import { buildAfterTurnRuntimeContext } from "./attempt.prompt-helpers.js";
2018import {
19+cleanupTempPaths,
2120createContextEngineBootstrapAndAssemble,
2221expectCalledWithSessionKey,
2322getHoisted,
@@ -113,13 +112,15 @@ async function finalizeTurn(
113112114113describe("runEmbeddedAttempt context engine sessionKey forwarding", () => {
115114const sessionKey = "agent:main:discord:channel:test-ctx-engine";
115+const tempPaths: string[] = [];
116116beforeEach(() => {
117117resetEmbeddedAttemptHarness();
118118clearMemoryPluginState();
119119hoisted.runContextEngineMaintenanceMock.mockReset().mockResolvedValue(undefined);
120120});
121121122122afterEach(async () => {
123+await cleanupTempPaths(tempPaths);
123124clearMemoryPluginState();
124125vi.restoreAllMocks();
125126});
@@ -481,74 +482,6 @@ describe("runEmbeddedAttempt context engine sessionKey forwarding", () => {
481482);
482483});
483484484-it("derives deferred maintenance currentTokenCount from prompt-only usage", async () => {
485-const afterTurn = vi.fn(
486-async (_params: {
487-runtimeContext?: {
488-currentTokenCount?: number;
489-promptCache?: { lastCallUsage?: { total?: number } };
490-};
491-}) => {},
492-);
493-494-const messagesSnapshot = [
495-seedMessage,
496-{
497-role: "assistant",
498-content: "done",
499-timestamp: 2,
500-usage: {
501-input: 10,
502-output: 5,
503-cacheRead: 40,
504-cacheWrite: 2,
505-total: 57,
506-},
507-} as unknown as AgentMessage,
508-];
509-const promptCache = buildLoopPromptCacheInfo({
510- messagesSnapshot,
511-prePromptMessageCount: 1,
512-});
513-514-await finalizeTurn(sessionKey, createTestContextEngine({ afterTurn }), {
515- messagesSnapshot,
516-prePromptMessageCount: 1,
517-runtimeContext: buildAfterTurnRuntimeContext({
518-attempt: {
519- sessionKey,
520-config: {} as never,
521-skillsSnapshot: undefined,
522-senderIsOwner: true,
523-provider: "openai",
524-modelId: "gpt-test",
525-thinkLevel: "off",
526-reasoningLevel: undefined,
527-extraSystemPrompt: undefined,
528-ownerNumbers: undefined,
529-},
530-workspaceDir: "/tmp/workspace",
531-agentDir: "/tmp/agent",
532-tokenBudget: 2048,
533-currentTokenCount: derivePromptTokens(promptCache?.lastCallUsage),
534- promptCache,
535-}),
536-});
537-538-expect(afterTurn).toHaveBeenCalledWith(
539-expect.objectContaining({
540-runtimeContext: expect.objectContaining({
541-currentTokenCount: 52,
542-promptCache: expect.objectContaining({
543-lastCallUsage: expect.objectContaining({
544-total: 57,
545-}),
546-}),
547-}),
548-}),
549-);
550-});
551-552485it("skips maintenance when ingestBatch fails", async () => {
553486const { bootstrap, assemble } = createContextEngineBootstrapAndAssemble();
554487const ingestBatch = vi.fn(async () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。