refactor(slack): reuse fetchAgentsForProject in lookupAgentName#2283
refactor(slack): reuse fetchAgentsForProject in lookupAgentName#2283amikofalvy merged 1 commit intomainfrom
Conversation
Remove duplicated API call logic from lookupAgentName and delegate to the existing fetchAgentsForProject utility, reducing maintenance surface. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: ece5d8f The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
PR Review Summary
(0) Total Issues | Risk: Low
This is a clean deduplication refactor that consolidates ~70 lines of duplicated internal API call logic into a reuse of the existing fetchAgentsForProject utility. The behavioral semantics are preserved, error handling is correctly delegated, and the test mock updates are appropriate.
💭 Consider (1) 💭
💭 1) agent-resolution.ts Timeout increased from 5s to 10s
Issue: The original lookupAgentName used a 5-second timeout, while fetchAgentsForProject uses 10 seconds.
Why: This is a minor behavioral difference—agent name lookups will now wait longer before timing out. This is likely acceptable (more lenient for slow networks) but worth being aware of for observability/debugging purposes.
Fix: No action needed unless you want to preserve the original 5-second timeout. If so, consider adding an optional timeout parameter to fetchAgentsForProject.
Refs: Original timeout in diff · INTERNAL_FETCH_TIMEOUT_MS
🧹 While You're Here (1) 🧹
🧹 1) agent-resolution.test.ts Enrichment code path has no test coverage
Issue: The lookupAgentName enrichment logic (triggered when agentName is missing or equals agentId) is not tested. All existing tests provide agentName in their mocks, bypassing this code path.
Why: This is pre-existing (not introduced by this PR), but since you're refactoring lookupAgentName, it's a good opportunity to add coverage. A regression here would show agent IDs instead of human-readable names in Slack responses.
Fix: Optional—add a test case that exercises the enrichment path:
it('should enrich agentName from manage API when agentName equals agentId', async () => {
const { findWorkAppSlackChannelAgentConfig } = await import('@inkeep/agents-core');
const { fetchAgentsForProject } = await import('../../slack/services/events/utils');
vi.mocked(findWorkAppSlackChannelAgentConfig).mockReturnValue(
vi.fn().mockResolvedValue({
agentId: 'agent-123',
projectId: 'proj-1',
agentName: 'agent-123', // Name equals ID, triggers enrichment
enabled: true,
grantAccessToMembers: true,
})
);
vi.mocked(fetchAgentsForProject).mockResolvedValue([
{ id: 'agent-123', name: 'My Friendly Agent', projectId: 'proj-1', projectName: 'Project' },
]);
const { resolveEffectiveAgent } = await import('../../slack/services/agent-resolution');
const result = await resolveEffectiveAgent({ tenantId: 't1', teamId: 'T1', channelId: 'C1' });
expect(result?.agentName).toBe('My Friendly Agent');
expect(fetchAgentsForProject).toHaveBeenCalledWith('t1', 'proj-1');
});Refs: agent-resolution.ts:137-146
✅ APPROVE
Summary: Clean refactor that eliminates code duplication without changing behavior. The consolidation improves maintainability by centralizing internal API call logic in one place. Ship it! 🚀
Discarded (1)
| Location | Issue | Reason Discarded |
|---|---|---|
agent-resolution.ts |
Error handling delegation no longer explicitly tested | Intentional design—the refactor correctly delegates error handling to the shared utility, which already has its own error handling. Not a problem. |
Reviewers (3)
| Reviewer | Returned | Main Findings | Consider | While You're Here | Inline Comments | Pending Recs | Discarded |
|---|---|---|---|---|---|---|---|
pr-review-standards |
0 | 0 | 0 | 0 | 0 | 0 | 0 |
pr-review-consistency |
0 | 0 | 0 | 0 | 0 | 0 | 0 |
pr-review-tests |
2 | 0 | 0 | 1 | 0 | 0 | 1 |
| Total | 2 | 0 | 1 | 1 | 0 | 0 | 1 |
Note: Standards and consistency reviewers found no issues—this is a well-executed refactor that follows existing patterns.
Ito Test Report ✅14 test cases ran. 14 passed. This test run verified the backend refactor in PR #2283 that moves ✅ Passed (14)📋 View Recording |
Summary
lookupAgentNameinagent-resolution.tsto delegate to the existingfetchAgentsForProjectutility fromevents/utils.tsinstead of duplicating the internal API call logic (token generation, fetch, error handling)generateInternalServiceToken,getInProcessFetch,InternalServices,env)fetchAgentsForProjectinagent-resolution.test.tsto fix tests after the import changeTest plan
agent-resolution.test.tstests pass🤖 Generated with Claude Code