@@ -72,7 +72,11 @@ const subagentRegistryReadMock = vi.hoisted(() => {
|
72 | 72 | |
73 | 73 | vi.mock("../agents/subagent-registry-read.js", () => subagentRegistryReadMock); |
74 | 74 | |
75 | | -import { loadGatewaySessionRow } from "./session-utils.js"; |
| 75 | +import { |
| 76 | +listSessionsFromStore, |
| 77 | +listSessionsFromStoreAsync, |
| 78 | +loadGatewaySessionRow, |
| 79 | +} from "./session-utils.js"; |
76 | 80 | |
77 | 81 | const MAIN_AGENT_ID = "main"; |
78 | 82 | const TEST_MODEL = "openai/gpt-5.4"; |
@@ -238,6 +242,62 @@ describe("single gateway session row child-session cache", () => {
|
238 | 242 | ); |
239 | 243 | }); |
240 | 244 | |
| 245 | +test("builds shared subagent metadata context for single-row session lists", async () => { |
| 246 | +await withSingleRowCacheStore( |
| 247 | +"openclaw-single-row-list-context-", |
| 248 | +"/tmp/openclaw-single-row-list-context", |
| 249 | +async ({ now, storePath }) => { |
| 250 | +const store: Record<string, SessionEntry> = { |
| 251 | +"agent:main:discord:channel:parent": parentSession("parent", now), |
| 252 | +}; |
| 253 | +const cfg: OpenClawConfig = { |
| 254 | +agents: { |
| 255 | +list: [ |
| 256 | +{ |
| 257 | +id: MAIN_AGENT_ID, |
| 258 | +default: true, |
| 259 | +workspace: "/tmp/openclaw-single-row-list-context", |
| 260 | +}, |
| 261 | +], |
| 262 | +defaults: { model: { primary: TEST_MODEL } }, |
| 263 | +}, |
| 264 | +} as OpenClawConfig; |
| 265 | + |
| 266 | +const syncListed = listSessionsFromStore({ |
| 267 | + cfg, |
| 268 | + storePath, |
| 269 | + store, |
| 270 | +opts: { agentId: MAIN_AGENT_ID, limit: 1 }, |
| 271 | +}); |
| 272 | + |
| 273 | +expect(syncListed.sessions).toHaveLength(1); |
| 274 | +expect(subagentRegistryReadMock.buildSubagentRunReadIndex).toHaveBeenCalledTimes( |
| 275 | +1, |
| 276 | +); |
| 277 | +expect( |
| 278 | +subagentRegistryReadMock.getSessionDisplaySubagentRunByChildSessionKey, |
| 279 | +).not.toHaveBeenCalled(); |
| 280 | + |
| 281 | +vi.clearAllMocks(); |
| 282 | + |
| 283 | +const asyncListed = await listSessionsFromStoreAsync({ |
| 284 | + cfg, |
| 285 | + storePath, |
| 286 | + store, |
| 287 | +opts: { agentId: MAIN_AGENT_ID, limit: 1 }, |
| 288 | +}); |
| 289 | + |
| 290 | +expect(asyncListed.sessions).toHaveLength(1); |
| 291 | +expect(subagentRegistryReadMock.buildSubagentRunReadIndex).toHaveBeenCalledTimes( |
| 292 | +1, |
| 293 | +); |
| 294 | +expect( |
| 295 | +subagentRegistryReadMock.getSessionDisplaySubagentRunByChildSessionKey, |
| 296 | +).not.toHaveBeenCalled(); |
| 297 | +}, |
| 298 | +); |
| 299 | +}); |
| 300 | + |
241 | 301 | test("rebuilds store child candidates after same-object session store writes", async () => { |
242 | 302 | await withSingleRowCacheStore( |
243 | 303 | "openclaw-single-row-cache-write-version-", |
|