Skip to content

Commit 6909064

Browse files
committed
test: move sharing alias coverage to doctor
1 parent 760e4c7 commit 6909064

2 files changed

Lines changed: 12 additions & 55 deletions

File tree

‎src/commands/doctor-session-canonical-keys.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,11 @@ describe("doctor canonical session-key repair", () => {
720720
"INSERT INTO conversation_deliveries (operation_id, operation_kind, conversation_id, source_session_key, message_hash, status, created_at, updated_at) VALUES ('trimmed-alias-operation', 'turn', ?, 'agent:main:main', 'hash', 'sent', 10, 10)",
721721
)
722722
.run(repairConversation.conversationRef);
723+
database.db
724+
.prepare(
725+
"INSERT INTO session_members (session_key, identity_id, added_by, added_at) VALUES ('agent:main:main ', 'profile-1', 'profile-1', 10)",
726+
)
727+
.run();
723728
database.db
724729
.prepare(
725730
`UPDATE session_windows
@@ -790,6 +795,13 @@ describe("doctor canonical session-key repair", () => {
790795
)
791796
.get(),
792797
).toEqual({ source_session_key: "agent:main:work" });
798+
expect(
799+
database.db
800+
.prepare(
801+
"SELECT session_key, identity_id FROM session_members WHERE identity_id = 'profile-1'",
802+
)
803+
.get(),
804+
).toEqual({ session_key: "agent:main:work", identity_id: "profile-1" });
793805
expect(() =>
794806
replaceSessionEntrySync(
795807
{ agentId: "main", env, sessionKey: "agent:main:main", storePath },

‎src/gateway/server-methods/sessions-sharing.test.ts‎

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ import {
1111
listSessionMembers,
1212
removeSessionMember,
1313
} from "../../config/sessions/session-sharing-store.js";
14-
import { clearSessionStoreCacheForTest } from "../../config/sessions/store-writer-state.js";
1514
import {
1615
closeOpenClawAgentDatabasesForTest,
17-
openOpenClawAgentDatabase,
1816
resolveIncognitoOpenClawAgentSqlitePath,
1917
} from "../../state/openclaw-agent-db.js";
2018
import { ensureProfileForEmail, listProfiles, setDisplayName } from "../../state/user-profiles.js";
@@ -478,59 +476,6 @@ describe("session sharing handlers", () => {
478476
});
479477
});
480478

481-
it("stores and lists membership against an alias-backed session row", async () => {
482-
await withOpenClawTestState({ scenario: "minimal" }, async (state) => {
483-
const canonicalKey = "agent:ops:work";
484-
const aliasKey = "agent:ops:main";
485-
const cfg = {
486-
session: { mainKey: "work" },
487-
agents: { list: [{ id: "ops", default: true }] },
488-
} as ReturnType<GatewayRequestContext["getRuntimeConfig"]>;
489-
const profile = ensureProfileForEmail("[email protected]");
490-
await upsertSessionEntry(
491-
{ agentId: "ops", sessionKey: canonicalKey },
492-
{ sessionId: "session-alias-member", updatedAt: 1, visibility: "read-only" },
493-
);
494-
const database = openOpenClawAgentDatabase({ agentId: "ops", env: state.env });
495-
database.db.exec("PRAGMA foreign_keys = OFF;");
496-
try {
497-
database.db
498-
.prepare("UPDATE session_nodes SET session_key = ? WHERE session_key = ?")
499-
.run(aliasKey, canonicalKey);
500-
database.db
501-
.prepare("UPDATE session_windows SET session_key = ? WHERE session_key = ?")
502-
.run(aliasKey, canonicalKey);
503-
} finally {
504-
database.db.exec("PRAGMA foreign_keys = ON;");
505-
}
506-
expect(
507-
database.db
508-
.prepare("SELECT session_key FROM session_nodes WHERE session_key = ?")
509-
.get(canonicalKey),
510-
).toBeUndefined();
511-
clearSessionStoreCacheForTest();
512-
const requestContext = context(vi.fn(), cfg);
513-
514-
expect(
515-
await call(
516-
"session.members.add",
517-
{ sessionKey: aliasKey, identityId: profile.id },
518-
requestContext,
519-
),
520-
).toEqual([
521-
[true, { ok: true, sessionKey: canonicalKey, identityId: profile.id }, undefined],
522-
]);
523-
expect(listSessionMembers({ agentId: "ops", sessionKey: aliasKey })).toEqual([
524-
expect.objectContaining({ identityId: profile.id }),
525-
]);
526-
const listed = await call("session.members.list", { sessionKey: aliasKey }, requestContext);
527-
expect(listed[0]?.[1]).toMatchObject({
528-
sessionKey: canonicalKey,
529-
members: [expect.objectContaining({ identityId: profile.id })],
530-
});
531-
});
532-
});
533-
534479
it("authorizes board tickets against their signed agent-relative session", async () => {
535480
await withOpenClawTestState({ scenario: "minimal" }, async () => {
536481
await upsertSessionEntry(

0 commit comments

Comments
 (0)