Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/brown-ghosts-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@inkeep/agents-core": minor
"@inkeep/agents-manage-api": minor
"@inkeep/agents-manage-ui": minor
"@inkeep/agents-run-api": minor
---

Changing available tools implementation
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,29 @@ vi.mock('../../../tools/mcp-client.js', () => ({
})),
}));

// Mock dbResultToMcpTool to avoid network calls during tests
vi.mock('@inkeep/agents-core', async () => {
const actual = await vi.importActual('@inkeep/agents-core');
return {
...actual,
dbResultToMcpTool: vi.fn().mockImplementation((tool) =>
Promise.resolve({
...tool,
status: 'healthy',
availableTools: [],
createdAt: new Date(tool.createdAt),
updatedAt: new Date(tool.updatedAt),
// Transform null to undefined for optional fields (matches real behavior)
credentialReferenceId: tool.credentialReferenceId || undefined,
headers: tool.headers || undefined,
capabilities: tool.capabilities || undefined,
lastError: tool.lastError || undefined,
imageUrl: tool.imageUrl || undefined,
})
),
};
});

describe('Agent Tool Relations CRUD Routes - Integration Tests', () => {
const projectId = 'default';

Expand Down Expand Up @@ -419,43 +442,6 @@ describe('Agent Tool Relations CRUD Routes - Integration Tests', () => {
});
});

describe('GET /agent/{agentId}/tools', () => {
it('should get tools for a specific agent', async () => {
const tenantId = createTestTenantId('agent-tool-relations-get-tools-for-agent');
await ensureTestProject(tenantId, 'default');
const { agentId, graphId } = await createTestAgent({ tenantId });
const { toolId: toolId1 } = await createTestTool({ tenantId, suffix: ' 1' });
const { toolId: toolId2 } = await createTestTool({ tenantId, suffix: ' 2' });

// Create relations
await createTestAgentToolRelation({ tenantId, agentId, toolId: toolId1, graphId });
await createTestAgentToolRelation({ tenantId, agentId, toolId: toolId2, graphId });

const res = await app.request(
`/tenants/${tenantId}/projects/${projectId}/graphs/${graphId}/agent-tool-relations/agent/${agentId}/tools`
);
expect(res.status).toBe(200);

const body = await res.json();
expect(body.data).toHaveLength(2);
expect(body.data.every((relation: any) => relation.agentId === agentId)).toBe(true);
});

it('should return empty array when agent has no tools', async () => {
const tenantId = createTestTenantId('agent-tool-relations-get-tools-empty');
await ensureTestProject(tenantId, 'default');
const { agentId, graphId } = await createTestAgent({ tenantId });

const res = await app.request(
`/tenants/${tenantId}/projects/${projectId}/graphs/${graphId}/agent-tool-relations/agent/${agentId}/tools`
);
expect(res.status).toBe(200);

const body = await res.json();
expect(body.data).toHaveLength(0);
});
});

describe('GET /tool/{toolId}/agents', () => {
it('should get agents for a specific tool', async () => {
const tenantId = createTestTenantId('agent-tool-relations-get-agents-for-tool');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,10 @@ describe('Credential CRUD Routes - Integration Tests', () => {
await ensureTestProject(tenantId, projectId);

const credentialData = createCredentialData({ suffix });
const createRes = await makeRequest(
`/tenants/${tenantId}/projects/${projectId}/credentials`,
{
method: 'POST',
body: JSON.stringify(credentialData),
}
);

console.log('createRes', createRes);
const createRes = await makeRequest(`/tenants/${tenantId}/projects/${projectId}/credentials`, {
method: 'POST',
body: JSON.stringify(credentialData),
});

expect(createRes.status).toBe(201);
const createBody = await createRes.json();
Expand Down
28 changes: 0 additions & 28 deletions agents-manage-api/src/__tests__/routes/crud/graphFull.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1423,13 +1423,6 @@ describe('Graph Full CRUD Routes - Integration Tests', () => {
}
}

// These can be strings or undefined
if (firstTool.lastHealthCheck) {
expect(typeof firstTool.lastHealthCheck).toBe('string');
}
if (firstTool.lastToolsSync) {
expect(typeof firstTool.lastToolsSync).toBe('string');
}
if (firstTool.lastError) {
expect(typeof firstTool.lastError).toBe('string');
}
Expand Down Expand Up @@ -1501,23 +1494,13 @@ describe('Graph Full CRUD Routes - Integration Tests', () => {
expect(tool.capabilities === null || typeof tool.capabilities === 'object').toBe(true);
}

if (tool.lastHealthCheck !== undefined) {
expect(tool.lastHealthCheck === null || typeof tool.lastHealthCheck === 'string').toBe(
true
);
}

if (tool.lastError !== undefined) {
expect(tool.lastError === null || typeof tool.lastError === 'string').toBe(true);
}

if (tool.availableTools !== undefined) {
expect(tool.availableTools === null || Array.isArray(tool.availableTools)).toBe(true);
}

if (tool.lastToolsSync !== undefined) {
expect(tool.lastToolsSync === null || typeof tool.lastToolsSync === 'string').toBe(true);
}
});
});

Expand Down Expand Up @@ -1580,17 +1563,13 @@ describe('Graph Full CRUD Routes - Integration Tests', () => {
expect(createdTool).toHaveProperty('config');
expect(createdTool).toHaveProperty('status');
expect(createdTool).toHaveProperty('capabilities');
expect(createdTool).toHaveProperty('lastHealthCheck');
expect(createdTool).toHaveProperty('lastError');
expect(createdTool).toHaveProperty('availableTools');
expect(createdTool).toHaveProperty('lastToolsSync');

// The values should be null/default since they're read-only
expect(createdTool.status).toBe('unknown');
expect(createdTool.availableTools).toBeNull();
expect(createdTool.lastToolsSync).toBeNull();
expect(createdTool.capabilities).toBeNull();
expect(createdTool.lastHealthCheck).toBeNull();
});

it('should preserve tool full schema fields on graph retrieval', async () => {
Expand Down Expand Up @@ -1625,15 +1604,12 @@ describe('Graph Full CRUD Routes - Integration Tests', () => {
// Verify all ToolApiFullSchema fields are present
expect(tool).toHaveProperty('status');
expect(tool).toHaveProperty('capabilities');
expect(tool).toHaveProperty('lastHealthCheck');
expect(tool).toHaveProperty('lastError');
expect(tool).toHaveProperty('availableTools');
expect(tool).toHaveProperty('lastToolsSync');

// The createTestToolData helper includes these fields, so they should have values
expect(tool.status).toBe('unknown');
expect(tool.capabilities).toEqual({ tools: true });
expect(tool.lastHealthCheck).toBeDefined();
expect(tool.availableTools).toBeDefined();
}
});
Expand Down Expand Up @@ -1867,10 +1843,8 @@ describe('Graph Full CRUD Routes - Integration Tests', () => {
for (const tool of tools) {
expect(tool).toHaveProperty('status');
expect(tool).toHaveProperty('capabilities');
expect(tool).toHaveProperty('lastHealthCheck');
expect(tool).toHaveProperty('lastError');
expect(tool).toHaveProperty('availableTools');
expect(tool).toHaveProperty('lastToolsSync');
}
});

Expand Down Expand Up @@ -1969,10 +1943,8 @@ describe('Graph Full CRUD Routes - Integration Tests', () => {
const tool = body.data.tools[toolId];
expect(tool).toHaveProperty('status');
expect(tool).toHaveProperty('capabilities');
expect(tool).toHaveProperty('lastHealthCheck');
expect(tool).toHaveProperty('lastError');
expect(tool).toHaveProperty('availableTools');
expect(tool).toHaveProperty('lastToolsSync');
});
});
});
Loading