Spracherkennung für: .ts vermutete Sprache: Unknown {[0] [0] [0]} [Methode: Schwerpunktbildung, einfache Gewichte, sechs Dimensionen]
import { describe, expect, it, vi } from "vitest";
import type { SessionEntry } from "../../config/sessions.js";
import { createPersistCronSessionEntry, type MutableCronSession } from "./run-session-state.js";
function makeSessionEntry(overrides?: Partial<SessionEntry>): SessionEntry {
return {
sessionId: "run-session-id",
updatedAt: 1000,
systemSent: true,
...overrides,
};
}
function makeCronSession(entry = makeSessionEntry()): MutableCronSession {
return {
storePath: "/tmp/sessions.json",
store: {},
sessionEntry: entry,
systemSent: true,
isNewSession: true,
previousSessionId: undefined,
} as MutableCronSession;
}
describe("createPersistCronSessionEntry", () => {
it("persists a distinct run-session snapshot for isolated cron runs", async () => {
const cronSession = makeCronSession(
makeSessionEntry({
status: "running",
startedAt: 900,
skillsSnapshot: {
prompt: "old prompt",
skills: [{ name: "memory" }],
},
}),
);
const updateSessionStore = vi.fn(
async (_storePath, update: (store: Record<string, SessionEntry>) => void) => {
const store: Record<string, SessionEntry> = {};
update(store);
expect(store["agent:main:cron:job"]).toBe(cronSession.sessionEntry);
expect(store["agent:main:cron:job:run:run-session-id"]).not.toBe(cronSession.sessionEntry);
expect(store["agent:main:cron:job:run:run-session-id"]).toEqual(cronSession.sessionEntry);
},
);
const persist = createPersistCronSessionEntry({
isFastTestEnv: false,
cronSession,
agentSessionKey: "agent:main:cron:job",
runSessionKey: "agent:main:cron:job:run:run-session-id",
updateSessionStore,
});
await persist();
expect(cronSession.store["agent:main:cron:job"]).toBe(cronSession.sessionEntry);
expect(cronSession.store["agent:main:cron:job:run:run-session-id"]).not.toBe(
cronSession.sessionEntry,
);
cronSession.sessionEntry.status = "done";
cronSession.sessionEntry.skillsSnapshot!.skills[0].name = "changed";
expect(cronSession.store["agent:main:cron:job:run:run-session-id"]?.status).toBe("running");
expect(
cronSession.store["agent:main:cron:job:run:run-session-id"]?.skillsSnapshot?.skills[0]?.name,
).toBe("memory");
});
it("uses the shared session entry when the run key is the agent session key", async () => {
const cronSession = makeCronSession();
const updateSessionStore = vi.fn(
async (_storePath, update: (store: Record<string, SessionEntry>) => void) => {
const store: Record<string, SessionEntry> = {};
update(store);
expect(store["agent:main:session"]).toBe(cronSession.sessionEntry);
},
);
const persist = createPersistCronSessionEntry({
isFastTestEnv: false,
cronSession,
agentSessionKey: "agent:main:session",
runSessionKey: "agent:main:session",
updateSessionStore,
});
await persist();
expect(cronSession.store["agent:main:session"]).toBe(cronSession.sessionEntry);
});
});
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet am 2026-04-27)
¤
*© Formatika GbR, Deutschland