test: avoid platform-specific transcript stat assertion

This commit is contained in:
Peter Steinberger
2026-05-28 04:29:31 -04:00
parent 9f7006407f
commit bd02977e29
2 changed files with 16 additions and 31 deletions

View File

@@ -1558,40 +1558,25 @@ describe("runMemoryFlushIfNeeded", () => {
updatedAt: Date.now(),
totalTokensFresh: false,
};
const originalStat = fsCore.promises.stat.bind(fsCore.promises);
const statSpy = vi
.spyOn(fsCore.promises, "stat")
.mockImplementation(async (target, options) => originalStat(target, options));
let entry: SessionEntry | undefined;
let directTranscriptStats: unknown[] = [];
try {
entry = await runPreflightCompactionIfNeeded({
cfg: { agents: { defaults: { compaction: { memoryFlush: {} } } } },
followupRun: createTestFollowupRun({
sessionId: "session",
sessionFile,
sessionKey: "main",
}),
defaultModel: "anthropic/claude-opus-4-6",
agentCfgContextTokens: 100_000,
sessionEntry,
sessionStore: { main: sessionEntry },
const entry = await runPreflightCompactionIfNeeded({
cfg: { agents: { defaults: { compaction: { memoryFlush: {} } } } },
followupRun: createTestFollowupRun({
sessionId: "session",
sessionFile,
sessionKey: "main",
storePath: path.join(rootDir, "sessions.json"),
isHeartbeat: false,
replyOperation: createReplyOperation(),
});
directTranscriptStats = statSpy.mock.calls.filter(
([target]) => String(target) === sessionFile,
);
} finally {
statSpy.mockRestore();
}
}),
defaultModel: "anthropic/claude-opus-4-6",
agentCfgContextTokens: 100_000,
sessionEntry,
sessionStore: { main: sessionEntry },
sessionKey: "main",
storePath: path.join(rootDir, "sessions.json"),
isHeartbeat: false,
replyOperation: createReplyOperation(),
});
expect(entry).toBe(sessionEntry);
expect(compactEmbeddedAgentSessionMock).not.toHaveBeenCalled();
expect(directTranscriptStats).toEqual([]);
});
it("does not treat raw transcript metadata bytes as token pressure", async () => {

View File

@@ -560,7 +560,7 @@ async function readLastNonzeroUsageFromSessionLog(logPath: string): Promise<Sess
return usage
? {
usage,
trailingBytes: 0,
trailingBytes: Math.max(0, stat.size - Buffer.byteLength(leadingPartial, "utf8")),
byteSize: stat.size,
}
: { byteSize: stat.size };