|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { resolveSessionStorePathCore, type SessionEntry } from "../../../config/sessions.js"; |
| 3 | +import type { OpenClawConfig } from "../../../config/types.openclaw.js"; |
| 4 | +import { |
| 5 | + resolveSubagentSessionCompletion, |
| 6 | + type SubagentSessionStoreCache, |
| 7 | +} from "./subagent-session-reconciliation.js"; |
| 8 | + |
| 9 | +const configuredStorePath = "/virtual/openclaw-subagent-reconciliation-sessions.json"; |
| 10 | +const cfg = { |
| 11 | + session: { store: configuredStorePath }, |
| 12 | +} satisfies OpenClawConfig; |
| 13 | +const storePath = resolveSessionStorePathCore(configuredStorePath, { agentId: "main" }); |
| 14 | + |
| 15 | +const terminalSession: SessionEntry = { |
| 16 | + sessionId: "sibling-session", |
| 17 | + status: "done", |
| 18 | + startedAt: 1_000, |
| 19 | + updatedAt: 2_000, |
| 20 | + endedAt: 2_000, |
| 21 | +}; |
| 22 | + |
| 23 | +function resolveCompletion(childSessionKey: string, storedSessionKey: string) { |
| 24 | + const storeCache: SubagentSessionStoreCache = new Map([ |
| 25 | + [storePath, { [storedSessionKey]: terminalSession }], |
| 26 | + ]); |
| 27 | + return resolveSubagentSessionCompletion({ |
| 28 | + childSessionKey, |
| 29 | + fallbackEndedAt: 3_000, |
| 30 | + notBeforeMs: 0, |
| 31 | + storeCache, |
| 32 | + cfg, |
| 33 | + }); |
| 34 | +} |
| 35 | + |
| 36 | +describe("subagent session reconciliation keys", () => { |
| 37 | + it("matches case-insensitive structural session-key segments", () => { |
| 38 | + expect( |
| 39 | + resolveCompletion("Agent:MAIN:telegram:group:ROOM", "agent:main:telegram:group:room"), |
| 40 | + ).toMatchObject({ endedAt: 2_000, outcome: { status: "ok" } }); |
| 41 | + }); |
| 42 | + |
| 43 | + it.each([ |
| 44 | + { |
| 45 | + channel: "Matrix", |
| 46 | + childSessionKey: "agent:main:matrix:group:!Room:server", |
| 47 | + storedSessionKey: "agent:main:matrix:group:!room:server", |
| 48 | + }, |
| 49 | + { |
| 50 | + channel: "Signal", |
| 51 | + childSessionKey: "agent:main:signal:group:AbCdEf==", |
| 52 | + storedSessionKey: "agent:main:signal:group:abcdef==", |
| 53 | + }, |
| 54 | + ])( |
| 55 | + "does not match a case-distinct $channel opaque peer", |
| 56 | + ({ childSessionKey, storedSessionKey }) => { |
| 57 | + expect(resolveCompletion(childSessionKey, storedSessionKey)).toBeNull(); |
| 58 | + }, |
| 59 | + ); |
| 60 | +}); |
0 commit comments