



















@@ -1150,6 +1150,7 @@ describe("runMemoryFlushIfNeeded", () => {
11501150totalTokensFresh: false,
11511151};
115211521153+let directTranscriptStats: unknown[] = [];
11531154try {
11541155await runMemoryFlushIfNeeded({
11551156cfg: { agents: { defaults: { compaction: { memoryFlush: {} } } } },
@@ -1169,13 +1170,13 @@ describe("runMemoryFlushIfNeeded", () => {
11691170isHeartbeat: false,
11701171replyOperation: createReplyOperation(),
11711172});
1173+directTranscriptStats = statSpy.mock.calls.filter(
1174+([target]) => String(target) === sessionFile,
1175+);
11721176} finally {
11731177statSpy.mockRestore();
11741178}
117511791176-const directTranscriptStats = statSpy.mock.calls.filter(
1177-([target]) => String(target) === sessionFile,
1178-);
11791180expect(directTranscriptStats).toEqual([]);
11801181expect(runEmbeddedAgentMock).toHaveBeenCalledTimes(1);
11811182});
@@ -1540,7 +1541,7 @@ describe("runMemoryFlushIfNeeded", () => {
15401541usage: { input: 40_000, output: 2_000 },
15411542},
15421543}),
1543-].join("\n"),
1544+].join("\n") + "\n",
15441545"utf8",
15451546);
15461547registerMemoryFlushPlanResolverForTest(() => ({
@@ -1557,26 +1558,40 @@ describe("runMemoryFlushIfNeeded", () => {
15571558updatedAt: Date.now(),
15581559totalTokensFresh: false,
15591560};
1561+const originalStat = fsCore.promises.stat.bind(fsCore.promises);
1562+const statSpy = vi
1563+.spyOn(fsCore.promises, "stat")
1564+.mockImplementation(async (target, options) => originalStat(target, options));
156015651561-const entry = await runPreflightCompactionIfNeeded({
1562-cfg: { agents: { defaults: { compaction: { memoryFlush: {} } } } },
1563-followupRun: createTestFollowupRun({
1564-sessionId: "session",
1565- sessionFile,
1566+let entry: SessionEntry | undefined;
1567+let directTranscriptStats: unknown[] = [];
1568+try {
1569+entry = await runPreflightCompactionIfNeeded({
1570+cfg: { agents: { defaults: { compaction: { memoryFlush: {} } } } },
1571+followupRun: createTestFollowupRun({
1572+sessionId: "session",
1573+ sessionFile,
1574+sessionKey: "main",
1575+}),
1576+defaultModel: "anthropic/claude-opus-4-6",
1577+agentCfgContextTokens: 100_000,
1578+ sessionEntry,
1579+sessionStore: { main: sessionEntry },
15661580sessionKey: "main",
1567-}),
1568-defaultModel: "anthropic/claude-opus-4-6",
1569-agentCfgContextTokens: 100_000,
1570-sessionEntry,
1571-sessionStore: { main: sessionEntry },
1572-sessionKey: "main",
1573-storePath: path.join(rootDir, "sessions.json"),
1574- isHeartbeat: false,
1575-replyOperation: createReplyOperation(),
1576-});
1581+ storePath: path.join(rootDir, "sessions.json"),
1582+ isHeartbeat: false,
1583+ replyOperation: createReplyOperation(),
1584+});
1585+directTranscriptStats = statSpy.mock.calls.filter(
1586+ ([target]) => String(target) === sessionFile,
1587+);
1588+} finally {
1589+statSpy.mockRestore();
1590+}
1577159115781592expect(entry).toBe(sessionEntry);
15791593expect(compactEmbeddedAgentSessionMock).not.toHaveBeenCalled();
1594+expect(directTranscriptStats).toEqual([]);
15801595});
1581159615821597it("does not treat raw transcript metadata bytes as token pressure", async () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。