Skip to content

Commit be124de

Browse files
steipeteampagent
andauthored
test: slim gateway session creation coverage (#122789)
* test: slim gateway session creation coverage * test: move incognito initialization to its owner --------- Co-authored-by: Amp <[email protected]>
1 parent 99a9827 commit be124de

4 files changed

Lines changed: 209 additions & 558 deletions

File tree

‎src/auto-reply/reply/session.test.ts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
appendTranscriptEvent,
1616
loadSessionEntry,
1717
loadTranscriptEvents,
18+
upsertSessionEntryCore,
1819
} from "../../config/sessions/session-accessor.js";
1920
import { runExclusiveSessionStoreWrite } from "../../config/sessions/store-writer.js";
2021
import { formatZonedTimestamp } from "../../infra/format-time/format-datetime.ts";
@@ -36,6 +37,10 @@ import {
3637
runExclusiveSessionLifecycleMutation,
3738
} from "../../sessions/session-lifecycle-admission.js";
3839
import { listSessionStateEventsSince } from "../../sessions/session-state-events.js";
40+
import {
41+
closeOpenClawAgentDatabasesForTest,
42+
resolveIncognitoOpenClawAgentSqlitePath,
43+
} from "../../state/openclaw-agent-db.js";
3944
import { closeOpenClawStateDatabaseForTest } from "../../state/openclaw-state-db.js";
4045
import {
4146
createChannelTestPluginBase,
@@ -428,6 +433,47 @@ afterEach(async () => {
428433
await sessionMcpTesting.resetSessionMcpRuntimeManager();
429434
});
430435
describe("initSessionState guarded initialization", () => {
436+
it("pins an admitted non-default-agent incognito session to its process-local store", async () => {
437+
const stateDir = await makeCaseDir("openclaw-session-incognito-init-");
438+
await withEnvAsync({ OPENCLAW_STATE_DIR: stateDir }, async () => {
439+
const agentId = "work";
440+
const sessionId = "incognito-work-session";
441+
const sessionKey = "agent:work:dashboard:incognito-work-session";
442+
const storePath = resolveIncognitoOpenClawAgentSqlitePath({ agentId });
443+
await upsertSessionEntryCore(
444+
{ agentId, sessionKey, storePath },
445+
{ sessionId, incognito: true, updatedAt: Date.now() },
446+
);
447+
448+
try {
449+
await expect(
450+
initSessionState({
451+
cfg: {
452+
agents: { list: [{ id: "main", default: true }, { id: agentId }] },
453+
session: { store: path.join(stateDir, "durable", "{agentId}", "sessions.json") },
454+
} as OpenClawConfig,
455+
ctx: {
456+
Body: "hello from incognito webchat",
457+
Provider: "webchat",
458+
SessionKey: sessionKey,
459+
Surface: "webchat",
460+
},
461+
expectedExistingSessionId: sessionId,
462+
pinExpectedExistingSession: true,
463+
requestedSessionId: sessionId,
464+
resumeRequestedSession: true,
465+
}),
466+
).resolves.toMatchObject({
467+
sessionId,
468+
sessionKey,
469+
storePath,
470+
});
471+
} finally {
472+
closeOpenClawAgentDatabasesForTest();
473+
}
474+
});
475+
});
476+
431477
it("rejects inbound work for an archived session", async () => {
432478
const storePath = await createStorePath("openclaw-session-init-archived-");
433479
const sessionKey = "agent:main:telegram:chat:archived";

0 commit comments

Comments
 (0)