mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 05:30:42 +00:00
test: stabilize session reset writer coverage
This commit is contained in:
@@ -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?
|
||||
|
||||
@@ -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?
|
||||
|
||||
@@ -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]>
|
||||
|
||||
Reference in New Issue
Block a user