feat(core): restore MessageBus optionality for soft migration (Phase 1) (#15774)

This commit is contained in:
Abhi
2026-01-04 14:59:35 -05:00
committed by GitHub
parent d3c206c677
commit eec5d5ebf8
16 changed files with 105 additions and 82 deletions
@@ -56,22 +56,19 @@ class TestToolInvocation extends BaseToolInvocation<TestParams, TestResult> {
override async shouldConfirmExecute(
abortSignal: AbortSignal,
): Promise<false> {
// This conditional is here to allow testing of the case where there is no message bus.
if (this.messageBus) {
const decision = await this.getMessageBusDecision(abortSignal);
if (decision === 'ALLOW') {
return false;
}
if (decision === 'DENY') {
throw new Error('Tool execution denied by policy');
}
const decision = await this.getMessageBusDecision(abortSignal);
if (decision === 'ALLOW') {
return false;
}
if (decision === 'DENY') {
throw new Error('Tool execution denied by policy');
}
return false;
}
}
class TestTool extends BaseDeclarativeTool<TestParams, TestResult> {
constructor(messageBus?: MessageBus) {
constructor(messageBus: MessageBus) {
super(
'test-tool',
'Test Tool',
@@ -90,7 +87,7 @@ class TestTool extends BaseDeclarativeTool<TestParams, TestResult> {
);
}
protected createInvocation(params: TestParams, messageBus?: MessageBus) {
protected createInvocation(params: TestParams, messageBus: MessageBus) {
return new TestToolInvocation(params, messageBus);
}
}
@@ -220,16 +217,6 @@ describe('Message Bus Integration', () => {
);
});
it('should fall back to default behavior when no message bus', async () => {
const tool = new TestTool(); // No message bus
const invocation = tool.build({ testParam: 'test-value' });
const result = await invocation.shouldConfirmExecute(
new AbortController().signal,
);
expect(result).toBe(false);
});
it('should ignore responses with wrong correlation ID', async () => {
vi.useFakeTimers();
@@ -260,28 +247,6 @@ describe('Message Bus Integration', () => {
});
});
describe('Backward Compatibility', () => {
it('should work with existing tools that do not use message bus', async () => {
const tool = new TestTool(); // No message bus
const invocation = tool.build({ testParam: 'test-value' });
// Should execute normally
const result = await invocation.execute(new AbortController().signal);
expect(result.testValue).toBe('test-value');
expect(result.llmContent).toBe('Executed with test-value');
});
it('should work with tools that have message bus but use default confirmation', async () => {
const tool = new TestTool(messageBus);
const invocation = tool.build({ testParam: 'test-value' });
// Should execute normally even with message bus available
const result = await invocation.execute(new AbortController().signal);
expect(result.testValue).toBe('test-value');
expect(result.llmContent).toBe('Executed with test-value');
});
});
describe('Error Handling', () => {
it('should handle message bus publish errors gracefully', async () => {
const tool = new TestTool(messageBus);