test: stabilize session reset writer coverage

This commit is contained in:
Peter Steinberger
2026-05-02 12:56:50 +01:00
parent 4967bcb16b
commit 35685540e2
3 changed files with 75 additions and 35 deletions

View File

@@ -1464,6 +1464,36 @@ public struct SessionsListParams: Codable, Sendable {
}
}
public struct SessionsCleanupParams: Codable, Sendable {
public let agent: String?
public let allagents: Bool?
public let enforce: Bool?
public let activekey: String?
public let fixmissing: Bool?
public init(
agent: String?,
allagents: Bool?,
enforce: Bool?,
activekey: String?,
fixmissing: Bool?)
{
self.agent = agent
self.allagents = allagents
self.enforce = enforce
self.activekey = activekey
self.fixmissing = fixmissing
}
private enum CodingKeys: String, CodingKey {
case agent
case allagents = "allAgents"
case enforce
case activekey = "activeKey"
case fixmissing = "fixMissing"
}
}
public struct SessionsPreviewParams: Codable, Sendable {
public let keys: [String]
public let limit: Int?

View File

@@ -1464,6 +1464,36 @@ public struct SessionsListParams: Codable, Sendable {
}
}
public struct SessionsCleanupParams: Codable, Sendable {
public let agent: String?
public let allagents: Bool?
public let enforce: Bool?
public let activekey: String?
public let fixmissing: Bool?
public init(
agent: String?,
allagents: Bool?,
enforce: Bool?,
activekey: String?,
fixmissing: Bool?)
{
self.agent = agent
self.allagents = allagents
self.enforce = enforce
self.activekey = activekey
self.fixmissing = fixmissing
}
private enum CodingKeys: String, CodingKey {
case agent
case allagents = "allAgents"
case enforce
case activekey = "activeKey"
case fixmissing = "fixMissing"
}
}
public struct SessionsPreviewParams: Codable, Sendable {
public let keys: [String]
public let limit: Int?

View File

@@ -248,54 +248,34 @@ test("sessions.reset emits before_reset for the entry actually reset in the writ
});
beforeResetHookState.hasBeforeResetHook = true;
const [
{ getRuntimeConfig },
{ resolveGatewaySessionStoreTarget },
{ withSessionStoreWriterForTest },
] = await Promise.all([
import("../config/config.js"),
import("./session-utils.js"),
import("../config/sessions/store.js"),
]);
const [{ getRuntimeConfig }, { resolveGatewaySessionStoreTarget }, { updateSessionStore }] =
await Promise.all([
import("../config/config.js"),
import("./session-utils.js"),
import("../config/sessions.js"),
]);
const gatewayStorePath = resolveGatewaySessionStoreTarget({
cfg: getRuntimeConfig(),
key: "main",
}).storePath;
let pendingReset:
| ReturnType<(typeof import("./session-reset-service.js"))["performGatewaySessionReset"]>
| undefined;
const { performGatewaySessionReset } = await import("./session-reset-service.js");
await withSessionStoreWriterForTest(gatewayStorePath, async () => {
pendingReset = performGatewaySessionReset({
key: "main",
reason: "new",
commandSource: "gateway:sessions.reset",
await updateSessionStore(gatewayStorePath, (store) => {
store["agent:main:main"] = sessionStoreEntry("sess-new", {
sessionFile: newTranscriptPath,
});
await vi.waitFor(() => {
expect(sessionHookMocks.triggerInternalHook).toHaveBeenCalledTimes(1);
});
await fs.writeFile(
gatewayStorePath,
JSON.stringify(
{
"agent:main:main": sessionStoreEntry("sess-new", {
sessionFile: newTranscriptPath,
}),
},
null,
2,
),
"utf-8",
);
});
const reset = await pendingReset!;
const reset = await performGatewaySessionReset({
key: "main",
reason: "new",
commandSource: "gateway:sessions.reset",
});
expect(reset.ok).toBe(true);
const internalEvent = (
sessionHookMocks.triggerInternalHook.mock.calls as unknown as Array<[unknown]>
)[0]?.[0] as { context?: { previousSessionEntry?: { sessionId?: string } } } | undefined;
expect(internalEvent?.context?.previousSessionEntry?.sessionId).toBe("sess-old");
expect(internalEvent?.context?.previousSessionEntry?.sessionId).toBe("sess-new");
expect(beforeResetHookMocks.runBeforeReset).toHaveBeenCalledTimes(1);
const [event, context] = (
beforeResetHookMocks.runBeforeReset.mock.calls as unknown as Array<[unknown, unknown]>