chore(core): revert registry changes in agent-tool branch

This commit is contained in:
Adam Weidman
2026-05-12 17:49:20 -04:00
parent 490799741e
commit 989035328d
2 changed files with 22 additions and 36 deletions
+19 -32
View File
@@ -1011,57 +1011,44 @@ describe('AgentRegistry', () => {
);
});
it('should override an existing agent but warn on duplicate name', async () => {
it('should overwrite an existing agent definition', async () => {
await registry.testRegisterAgent(MOCK_AGENT_V1);
expect(registry.getDefinition('MockAgent')?.description).toBe(
'Mock Description V1',
);
const feedbackSpy = vi.spyOn(coreEvents, 'emitFeedback');
await registry.testRegisterAgent(MOCK_AGENT_V2);
// Should override to V2 (preserves existing precedence)
expect(registry.getDefinition('MockAgent')?.description).toBe(
'Mock Description V2 (Updated)',
);
expect(registry.getAllDefinitions()).toHaveLength(1);
// But should emit a warning about the duplicate
expect(feedbackSpy).toHaveBeenCalledWith(
'warning',
expect.stringContaining("Duplicate agent name 'MockAgent'"),
);
});
it('should not warn when re-registering the same definition (refresh)', async () => {
await registry.testRegisterAgent(MOCK_AGENT_V1);
expect(registry.getDefinition('MockAgent')?.description).toBe(
'Mock Description V1',
);
// Re-registering the exact same object should succeed without warning
const feedbackSpy = vi.spyOn(coreEvents, 'emitFeedback');
await registry.testRegisterAgent(MOCK_AGENT_V1);
expect(registry.getDefinition('MockAgent')?.description).toBe(
'Mock Description V1',
);
expect(feedbackSpy).not.toHaveBeenCalledWith(
'warning',
expect.stringContaining('Duplicate'),
);
});
it('should warn on duplicate in debug logs', async () => {
it('should log overwrites when in debug mode', async () => {
const debugConfig = makeMockedConfig({ debugMode: true });
const debugRegistry = new TestableAgentRegistry(debugConfig);
const warnSpy = vi
.spyOn(debugLogger, 'warn')
const debugLogSpy = vi
.spyOn(debugLogger, 'log')
.mockImplementation(() => {});
await debugRegistry.testRegisterAgent(MOCK_AGENT_V1);
await debugRegistry.testRegisterAgent(MOCK_AGENT_V2);
expect(warnSpy).toHaveBeenCalledWith(
expect.stringContaining('Overriding agent'),
expect(debugLogSpy).toHaveBeenCalledWith(
`[AgentRegistry] Overriding agent 'MockAgent'`,
);
});
it('should not log overwrites when not in debug mode', async () => {
const debugLogSpy = vi
.spyOn(debugLogger, 'log')
.mockImplementation(() => {});
await registry.testRegisterAgent(MOCK_AGENT_V1);
await registry.testRegisterAgent(MOCK_AGENT_V2);
expect(debugLogSpy).not.toHaveBeenCalledWith(
`[AgentRegistry] Overriding agent 'MockAgent'`,
);
});
+3 -4
View File
@@ -328,10 +328,9 @@ export class AgentRegistry {
}
/**
* Registers an agent definition. If an agent with the same name already
* exists from a different definition, a warning is emitted to surface
* potential state collision. The new definition still overwrites the old
* one to preserve existing precedence order (user project extension).
* Registers an agent definition. If an agent with the same name exists,
* it will be overwritten, respecting the precedence established by the
* initialization order.
*/
protected async registerAgent<TOutput extends z.ZodTypeAny>(
definition: AgentDefinition<TOutput>,