+
Skip to content
Open
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
124 changes: 123 additions & 1 deletion agents-manage-api/src/__tests__/routes/crud/agentGraph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ describe('Agent Graph CRUD Routes - Integration Tests', () => {
});

// Helper function to create test agent graph data
const createAgentGraphData = ({ defaultAgentId = null }: { defaultAgentId?: string | null } = {}) => {
const createAgentGraphData = ({ defaultAgentId = null, description }: { defaultAgentId?: string | null; description?: string } = {}) => {
const id = nanoid();
return {
id,
name: id, // Use the same ID as the name for test consistency
description: description || undefined,
defaultAgentId,
contextConfigId: null, // Set to null since it's optional and we don't need it for these tests
};
Expand Down Expand Up @@ -646,4 +647,125 @@ describe('Agent Graph CRUD Routes - Integration Tests', () => {
expect(body.data.agents[agentId].canUse).toEqual([]);
});
});

describe('Description consistency between endpoints', () => {
it('should return consistent description in both list and single graph endpoints', async () => {
const tenantId = createTestTenantId('agent-graphs-description-consistency');
await ensureTestProject(tenantId, projectId);

// Create graph with specific description like the user reported
const testDescription = 'this is my graph';
const { agentGraphData, agentGraphId } = await createTestAgentGraph({
tenantId,
});

// Update the graph with the description via PUT request
const updateRes = await makeRequest(
`/tenants/${tenantId}/projects/${projectId}/agent-graphs/${agentGraphId}`,
{
method: 'PUT',
body: JSON.stringify({
defaultAgentId: agentGraphData.defaultAgentId,
description: testDescription
}),
}
);
expect(updateRes.status).toBe(200);

// Create agent for the graph
const { agentId } = await createTestAgent({ tenantId, graphId: agentGraphId });

// Update graph with default agent
await makeRequest(
`/tenants/${tenantId}/projects/${projectId}/agent-graphs/${agentGraphId}`,
{
method: 'PUT',
body: JSON.stringify({ defaultAgentId: agentId }),
}
);

// Test 1: List all graphs endpoint (should return stored description)
const listRes = await app.request(
`/tenants/${tenantId}/projects/${projectId}/agent-graphs`
);
expect(listRes.status).toBe(200);
const listBody = await listRes.json();
const graphFromList = listBody.data.find((g: any) => g.id === agentGraphId);
expect(graphFromList).toBeDefined();
expect(graphFromList.description).toBe(testDescription);

// Test 2: Single graph endpoint (should return same description)
const singleRes = await app.request(
`/tenants/${tenantId}/projects/${projectId}/agent-graphs/${agentGraphId}`
);
expect(singleRes.status).toBe(200);
const singleBody = await singleRes.json();
expect(singleBody.data.description).toBe(testDescription);

// Test 3: Full graph endpoint (should return same description)
const fullRes = await app.request(
`/tenants/${tenantId}/projects/${projectId}/agent-graphs/${agentGraphId}/full`
);
expect(fullRes.status).toBe(200);
const fullBody = await fullRes.json();
expect(fullBody.data.description).toBe(testDescription);

// All descriptions should be identical
expect(graphFromList.description).toBe(singleBody.data.description);
expect(singleBody.data.description).toBe(fullBody.data.description);

// None should have the fallback pattern
expect(graphFromList.description).not.toContain('Agent graph');
expect(singleBody.data.description).not.toContain('Agent graph');
expect(fullBody.data.description).not.toContain('Agent graph');
});

it('should handle null/empty descriptions consistently', async () => {
const tenantId = createTestTenantId('agent-graphs-empty-description');
await ensureTestProject(tenantId, projectId);

// Create graph without description (should be undefined/null)
const { agentGraphData, agentGraphId } = await createTestAgentGraph({
tenantId,
});

// Create agent for the graph
const { agentId } = await createTestAgent({ tenantId, graphId: agentGraphId });

// Update graph with default agent
await makeRequest(
`/tenants/${tenantId}/projects/${projectId}/agent-graphs/${agentGraphId}`,
{
method: 'PUT',
body: JSON.stringify({ defaultAgentId: agentId }),
}
);

// Test all endpoints return consistent empty/null description
const listRes = await app.request(
`/tenants/${tenantId}/projects/${projectId}/agent-graphs`
);
const listBody = await listRes.json();
const graphFromList = listBody.data.find((g: any) => g.id === agentGraphId);

const singleRes = await app.request(
`/tenants/${tenantId}/projects/${projectId}/agent-graphs/${agentGraphId}`
);
const singleBody = await singleRes.json();

const fullRes = await app.request(
`/tenants/${tenantId}/projects/${projectId}/agent-graphs/${agentGraphId}/full`
);
const fullBody = await fullRes.json();

// All should be consistent (either null, undefined, or empty string)
expect(graphFromList.description).toBe(singleBody.data.description);
expect(singleBody.data.description).toBe(fullBody.data.description);

// None should have the fallback pattern when description is intentionally empty
expect(graphFromList.description || '').not.toContain('Agent graph');
expect(singleBody.data.description || '').not.toContain('Agent graph');
expect(fullBody.data.description || '').not.toContain('Agent graph');
});
});
});
2 changes: 2 additions & 0 deletions agents-manage-api/src/routes/agentGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ app.openapi(
projectId,
id: validatedBody.id || nanoid(),
name: validatedBody.name,
description: validatedBody.description,
defaultAgentId: validatedBody.defaultAgentId,
contextConfigId: validatedBody.contextConfigId ?? undefined,
});
Expand Down Expand Up @@ -291,6 +292,7 @@ app.openapi(
data: {
defaultAgentId: validatedBody.defaultAgentId,
contextConfigId: validatedBody.contextConfigId ?? undefined,
description: validatedBody.description,
},
});

Expand Down
2 changes: 1 addition & 1 deletion agents-run-api/src/data/agentGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async function hydrateGraph({
// Create AgentCard for the graph (representing it as a single agent)
const agentCard: AgentCard = {
name: dbGraph.name,
description: dbGraph.description || `Agent graph: ${dbGraph.name}`,
description: dbGraph.description || '',
url: baseUrl ? `${baseUrl}/a2a` : '',
version: '1.0.0',
capabilities: {
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载