Skip to content

Commit f22aae2

Browse files
committed
chore(core): match remote-session-invocation test to remote-invocation branch
1 parent 04389ae commit f22aae2

1 file changed

Lines changed: 82 additions & 7 deletions

File tree

packages/core/src/agents/remote-session-invocation.test.ts

Lines changed: 82 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ describe('RemoteSessionInvocation', () => {
216216
RemoteSessionInvocation as unknown as {
217217
sessionState: Map<string, unknown>;
218218
}
219-
).sessionState.set('test-agent', priorState);
219+
).sessionState.set('test-agent::http://test-agent/card', priorState);
220220

221221
setupMockSession();
222222

@@ -258,7 +258,7 @@ describe('RemoteSessionInvocation', () => {
258258
RemoteSessionInvocation as unknown as {
259259
sessionState: Map<string, { contextId?: string; taskId?: string }>;
260260
}
261-
).sessionState.get('test-agent');
261+
).sessionState.get('test-agent::http://test-agent/card');
262262
expect(storedState).toEqual(newState);
263263
});
264264

@@ -496,11 +496,12 @@ describe('RemoteSessionInvocation', () => {
496496
// ---------------------------------------------------------------------------
497497

498498
describe('SessionState Management', () => {
499-
it('should use definition.name as session state key', async () => {
499+
it('should use composite name::url as session state key', async () => {
500500
const secondDefinition: RemoteAgentDefinition = {
501501
...mockDefinition,
502502
name: 'other-agent',
503503
displayName: 'Other Agent',
504+
agentCardUrl: 'http://other-agent/card',
504505
};
505506

506507
// First agent
@@ -533,9 +534,81 @@ describe('RemoteSessionInvocation', () => {
533534
}
534535
).sessionState;
535536

536-
// Each agent should have its own entry
537-
expect(stateMap.get('test-agent')).toEqual({ contextId: 'ctx-a' });
538-
expect(stateMap.get('other-agent')).toEqual({ contextId: 'ctx-b' });
537+
// Each agent should have its own entry keyed by name::url
538+
expect(stateMap.get('test-agent::http://test-agent/card')).toEqual({
539+
contextId: 'ctx-a',
540+
});
541+
expect(stateMap.get('other-agent::http://other-agent/card')).toEqual({
542+
contextId: 'ctx-b',
543+
});
544+
});
545+
546+
it('should isolate same-name agents with different URLs', async () => {
547+
const defA: RemoteAgentDefinition = {
548+
...mockDefinition,
549+
agentCardUrl: 'http://host-a/card',
550+
};
551+
const defB: RemoteAgentDefinition = {
552+
...mockDefinition,
553+
agentCardUrl: 'http://host-b/card',
554+
};
555+
556+
// Agent A
557+
setupMockSession({ sessionState: { contextId: 'ctx-a' } });
558+
const invA = new RemoteSessionInvocation(
559+
defA,
560+
mockContext,
561+
{ query: 'hi' },
562+
mockMessageBus,
563+
);
564+
await invA.execute({ abortSignal: new AbortController().signal });
565+
566+
// Agent B (same name, different URL)
567+
setupMockSession({ sessionState: { contextId: 'ctx-b' } });
568+
const invB = new RemoteSessionInvocation(
569+
defB,
570+
mockContext,
571+
{ query: 'hi' },
572+
mockMessageBus,
573+
);
574+
await invB.execute({ abortSignal: new AbortController().signal });
575+
576+
const stateMap = (
577+
RemoteSessionInvocation as unknown as {
578+
sessionState: Map<string, { contextId?: string; taskId?: string }>;
579+
}
580+
).sessionState;
581+
582+
expect(stateMap.get('test-agent::http://host-a/card')).toEqual({
583+
contextId: 'ctx-a',
584+
});
585+
expect(stateMap.get('test-agent::http://host-b/card')).toEqual({
586+
contextId: 'ctx-b',
587+
});
588+
});
589+
590+
it('should fall back to name-only key when URL is unavailable', async () => {
591+
const noUrlDef: RemoteAgentDefinition = {
592+
...mockDefinition,
593+
agentCardUrl: undefined,
594+
};
595+
596+
setupMockSession({ sessionState: { contextId: 'ctx-no-url' } });
597+
const inv = new RemoteSessionInvocation(
598+
noUrlDef,
599+
mockContext,
600+
{ query: 'hi' },
601+
mockMessageBus,
602+
);
603+
await inv.execute({ abortSignal: new AbortController().signal });
604+
605+
const stateMap = (
606+
RemoteSessionInvocation as unknown as {
607+
sessionState: Map<string, { contextId?: string; taskId?: string }>;
608+
}
609+
).sessionState;
610+
611+
expect(stateMap.get('test-agent')).toEqual({ contextId: 'ctx-no-url' });
539612
});
540613

541614
it('should persist state even on error', async () => {
@@ -562,7 +635,9 @@ describe('RemoteSessionInvocation', () => {
562635
}
563636
).sessionState;
564637

565-
expect(stateMap.get('test-agent')).toEqual(stateOnError);
638+
expect(stateMap.get('test-agent::http://test-agent/card')).toEqual(
639+
stateOnError,
640+
);
566641
});
567642
});
568643
});

0 commit comments

Comments
 (0)