Skip to content

Commit bd02977

Browse files
committed
test: avoid platform-specific transcript stat assertion
1 parent 9f70064 commit bd02977

2 files changed

Lines changed: 16 additions & 31 deletions

File tree

src/auto-reply/reply/agent-runner-memory.test.ts

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,40 +1558,25 @@ describe("runMemoryFlushIfNeeded", () => {
15581558
updatedAt: Date.now(),
15591559
totalTokensFresh: false,
15601560
};
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));
1565-
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 },
1561+
const entry = await runPreflightCompactionIfNeeded({
1562+
cfg: { agents: { defaults: { compaction: { memoryFlush: {} } } } },
1563+
followupRun: createTestFollowupRun({
1564+
sessionId: "session",
1565+
sessionFile,
15801566
sessionKey: "main",
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-
}
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+
});
15911577

15921578
expect(entry).toBe(sessionEntry);
15931579
expect(compactEmbeddedAgentSessionMock).not.toHaveBeenCalled();
1594-
expect(directTranscriptStats).toEqual([]);
15951580
});
15961581

15971582
it("does not treat raw transcript metadata bytes as token pressure", async () => {

src/auto-reply/reply/agent-runner-memory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ async function readLastNonzeroUsageFromSessionLog(logPath: string): Promise<Sess
560560
return usage
561561
? {
562562
usage,
563-
trailingBytes: 0,
563+
trailingBytes: Math.max(0, stat.size - Buffer.byteLength(leadingPartial, "utf8")),
564564
byteSize: stat.size,
565565
}
566566
: { byteSize: stat.size };

0 commit comments

Comments
 (0)