mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
refactor(gateway): share test fixture reset state
Amp-Thread-ID: https://ampcode.com/threads/T-019ff438-3b93-77b8-9828-1d3c586cb127
This commit is contained in:
@@ -356,6 +356,60 @@ function resetGatewayLifecycleTestState(options: { preserveRuntimeBindings: bool
|
||||
resetGatewayWorkAdmission();
|
||||
}
|
||||
|
||||
function resetGatewayMutableTestFixtures(): void {
|
||||
testTailnetIPv4.value = undefined;
|
||||
testTailscaleWhois.value = null;
|
||||
testState.gatewayBind = DEFAULT_GATEWAY_TEST_BIND;
|
||||
testState.gatewayAuth = { mode: "token", token: "test-gateway-token-1234567890" };
|
||||
testState.gatewayControlUi = undefined;
|
||||
testState.hooksConfig = undefined;
|
||||
testState.legacyIssues = [];
|
||||
testState.legacyParsed = {};
|
||||
testState.migrationConfig = null;
|
||||
testState.migrationChanges = [];
|
||||
testState.cronEnabled = false;
|
||||
testState.cronStorePath = undefined;
|
||||
testState.sessionConfig = undefined;
|
||||
testState.sessionStorePath = undefined;
|
||||
testState.agentConfig = undefined;
|
||||
testState.agentsConfig = undefined;
|
||||
testState.bindingsConfig = undefined;
|
||||
testState.channelsConfig = undefined;
|
||||
testState.allowFrom = undefined;
|
||||
lastSyncedSessionStorePath = testState.sessionStorePath;
|
||||
lastSyncedSessionConfigJson = serializeGatewayTestSessionConfig();
|
||||
testIsNixMode.value = false;
|
||||
cronIsolatedRun.mockReset();
|
||||
cronIsolatedRun.mockResolvedValue({ status: "ok", summary: "ok" });
|
||||
agentCommandMock.mockReset();
|
||||
agentCommandMock.mockResolvedValue(undefined);
|
||||
gatewayReplyMock.mockReset();
|
||||
gatewayReplyMock.mockResolvedValue(undefined);
|
||||
sendWhatsAppMock.mockReset();
|
||||
sendWhatsAppMock.mockResolvedValue({ messageId: "msg-1", toJid: "jid-1" });
|
||||
embeddedRunMock.activeIds.clear();
|
||||
embeddedRunMock.abortCalls = [];
|
||||
embeddedRunMock.waitCalls = [];
|
||||
embeddedRunMock.waitResults.clear();
|
||||
embeddedRunMock.endWaitCalls = [];
|
||||
for (const resolve of embeddedRunMock.endWaiters.values()) {
|
||||
resolve(false);
|
||||
}
|
||||
embeddedRunMock.endWaiters.clear();
|
||||
embeddedRunMock.resolveEndBeforeTimeoutIds.clear();
|
||||
embeddedRunMock.compactEmbeddedAgentSession.mockReset();
|
||||
embeddedRunMock.compactEmbeddedAgentSession.mockResolvedValue({
|
||||
ok: true,
|
||||
compacted: true,
|
||||
result: {
|
||||
summary: "summary",
|
||||
firstKeptEntryId: "entry-1",
|
||||
tokensBefore: 120,
|
||||
tokensAfter: 80,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async function resetGatewayTestState(options: { uniqueConfigRoot: boolean }) {
|
||||
// Some tests intentionally use fake timers; ensure they don't leak into gateway suites.
|
||||
vi.useRealTimers();
|
||||
@@ -417,57 +471,7 @@ async function resetGatewayTestState(options: { uniqueConfigRoot: boolean }) {
|
||||
resetConfigRuntimeState();
|
||||
invalidateSessionSharingSnapshot();
|
||||
resetTestPluginRegistry();
|
||||
testTailnetIPv4.value = undefined;
|
||||
testTailscaleWhois.value = null;
|
||||
testState.gatewayBind = DEFAULT_GATEWAY_TEST_BIND;
|
||||
testState.gatewayAuth = { mode: "token", token: "test-gateway-token-1234567890" };
|
||||
testState.gatewayControlUi = undefined;
|
||||
testState.hooksConfig = undefined;
|
||||
testState.legacyIssues = [];
|
||||
testState.legacyParsed = {};
|
||||
testState.migrationConfig = null;
|
||||
testState.migrationChanges = [];
|
||||
testState.cronEnabled = false;
|
||||
testState.cronStorePath = undefined;
|
||||
testState.sessionConfig = undefined;
|
||||
testState.sessionStorePath = undefined;
|
||||
testState.agentConfig = undefined;
|
||||
testState.agentsConfig = undefined;
|
||||
testState.bindingsConfig = undefined;
|
||||
testState.channelsConfig = undefined;
|
||||
testState.allowFrom = undefined;
|
||||
lastSyncedSessionStorePath = testState.sessionStorePath;
|
||||
lastSyncedSessionConfigJson = serializeGatewayTestSessionConfig();
|
||||
testIsNixMode.value = false;
|
||||
cronIsolatedRun.mockReset();
|
||||
cronIsolatedRun.mockResolvedValue({ status: "ok", summary: "ok" });
|
||||
agentCommandMock.mockReset();
|
||||
agentCommandMock.mockResolvedValue(undefined);
|
||||
gatewayReplyMock.mockReset();
|
||||
gatewayReplyMock.mockResolvedValue(undefined);
|
||||
sendWhatsAppMock.mockReset();
|
||||
sendWhatsAppMock.mockResolvedValue({ messageId: "msg-1", toJid: "jid-1" });
|
||||
embeddedRunMock.activeIds.clear();
|
||||
embeddedRunMock.abortCalls = [];
|
||||
embeddedRunMock.waitCalls = [];
|
||||
embeddedRunMock.waitResults.clear();
|
||||
embeddedRunMock.endWaitCalls = [];
|
||||
for (const resolve of embeddedRunMock.endWaiters.values()) {
|
||||
resolve(false);
|
||||
}
|
||||
embeddedRunMock.endWaiters.clear();
|
||||
embeddedRunMock.resolveEndBeforeTimeoutIds.clear();
|
||||
embeddedRunMock.compactEmbeddedAgentSession.mockReset();
|
||||
embeddedRunMock.compactEmbeddedAgentSession.mockResolvedValue({
|
||||
ok: true,
|
||||
compacted: true,
|
||||
result: {
|
||||
summary: "summary",
|
||||
firstKeptEntryId: "entry-1",
|
||||
tokensBefore: 120,
|
||||
tokensAfter: 80,
|
||||
},
|
||||
});
|
||||
resetGatewayMutableTestFixtures();
|
||||
for (const sessionKey of resolveGatewayTestMainSessionKeys()) {
|
||||
drainSystemEvents(sessionKey);
|
||||
}
|
||||
@@ -514,57 +518,7 @@ async function resetGatewayTestRuntimeOnly() {
|
||||
resetConfigRuntimeState();
|
||||
invalidateSessionSharingSnapshot();
|
||||
resetTestPluginRegistry();
|
||||
testTailnetIPv4.value = undefined;
|
||||
testTailscaleWhois.value = null;
|
||||
testState.gatewayBind = DEFAULT_GATEWAY_TEST_BIND;
|
||||
testState.gatewayAuth = { mode: "token", token: "test-gateway-token-1234567890" };
|
||||
testState.gatewayControlUi = undefined;
|
||||
testState.hooksConfig = undefined;
|
||||
testState.legacyIssues = [];
|
||||
testState.legacyParsed = {};
|
||||
testState.migrationConfig = null;
|
||||
testState.migrationChanges = [];
|
||||
testState.cronEnabled = false;
|
||||
testState.cronStorePath = undefined;
|
||||
testState.sessionConfig = undefined;
|
||||
testState.sessionStorePath = undefined;
|
||||
testState.agentConfig = undefined;
|
||||
testState.agentsConfig = undefined;
|
||||
testState.bindingsConfig = undefined;
|
||||
testState.channelsConfig = undefined;
|
||||
testState.allowFrom = undefined;
|
||||
lastSyncedSessionStorePath = testState.sessionStorePath;
|
||||
lastSyncedSessionConfigJson = serializeGatewayTestSessionConfig();
|
||||
testIsNixMode.value = false;
|
||||
cronIsolatedRun.mockReset();
|
||||
cronIsolatedRun.mockResolvedValue({ status: "ok", summary: "ok" });
|
||||
agentCommandMock.mockReset();
|
||||
agentCommandMock.mockResolvedValue(undefined);
|
||||
gatewayReplyMock.mockReset();
|
||||
gatewayReplyMock.mockResolvedValue(undefined);
|
||||
sendWhatsAppMock.mockReset();
|
||||
sendWhatsAppMock.mockResolvedValue({ messageId: "msg-1", toJid: "jid-1" });
|
||||
embeddedRunMock.activeIds.clear();
|
||||
embeddedRunMock.abortCalls = [];
|
||||
embeddedRunMock.waitCalls = [];
|
||||
embeddedRunMock.waitResults.clear();
|
||||
embeddedRunMock.endWaitCalls = [];
|
||||
for (const resolve of embeddedRunMock.endWaiters.values()) {
|
||||
resolve(false);
|
||||
}
|
||||
embeddedRunMock.endWaiters.clear();
|
||||
embeddedRunMock.resolveEndBeforeTimeoutIds.clear();
|
||||
embeddedRunMock.compactEmbeddedAgentSession.mockReset();
|
||||
embeddedRunMock.compactEmbeddedAgentSession.mockResolvedValue({
|
||||
ok: true,
|
||||
compacted: true,
|
||||
result: {
|
||||
summary: "summary",
|
||||
firstKeptEntryId: "entry-1",
|
||||
tokensBefore: 120,
|
||||
tokensAfter: 80,
|
||||
},
|
||||
});
|
||||
resetGatewayMutableTestFixtures();
|
||||
clearSessionStoreCacheForTest();
|
||||
await persistTestSessionConfig();
|
||||
for (const sessionKey of resolveGatewayTestMainSessionKeys()) {
|
||||
|
||||
Reference in New Issue
Block a user