Skip to content
Merged
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
10 changes: 7 additions & 3 deletions agents-manage-ui/cypress/e2e/agent-tools.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ describe('Agent Tools', () => {
cy.contains('Create agent').click();
cy.get('[name=name]').type(generateId(), { delay: 0 });
cy.get('button[type=submit]').click();
cy.get('.react-flow__node').should('exist');
cy.get('.react-flow__node', { timeout: 10000 }).should('have.length', 1);

dragNode('[aria-label="Drag Function Tool node"]');
cy.get('.react-flow__node', { timeout: 10000 }).should('have.length', 2);
connectEdge('[data-handleid="target-function-tool"]');
cy.typeInMonaco('code.jsx', 'function () {}');
dragNode('[aria-label="Drag MCP node"]');
cy.get('.react-flow__node', { timeout: 10000 }).should('have.length', 3);
cy.contains('Geocode address').click();
connectEdge('[data-handleid="target-mcp"]');
saveAndAssert();
Expand All @@ -38,10 +40,12 @@ describe('Agent Tools', () => {
saveAndAssert();

function saveAndAssert() {
cy.intercept('POST', '**/agents/*').as('saveAgent');
cy.contains('Save changes').click();
cy.contains('Agent saved').should('exist');
cy.wait('@saveAgent');
Comment on lines +43 to +45
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 CRITICAL: Intercept pattern won't match actual API calls

Issue: The pattern POST **/agents/* won't match the save API call. The test flow is:

  1. Create agent → POST to /agents (no trailing segment)
  2. Add tools via drag-and-drop
  3. Save changes → PUT to /agent/{agentId} (singular, not plural)

The intercept expects POST to **/agents/*, but the save operation uses PUT to /agent/... (singular). This means cy.wait('@saveAgent') will never receive a matching request.

Why: The race condition this fix aims to solve will remain. cy.wait('@saveAgent') will either:

  • Timeout after the default command timeout, causing test failure, OR
  • If Cypress falls through (depending on version/config), reload will proceed without waiting for save, causing the original flakiness

Fix:

Suggested change
cy.intercept('POST', '**/agents/*').as('saveAgent');
cy.contains('Save changes').click();
cy.contains('Agent saved').should('exist');
cy.wait('@saveAgent');
cy.intercept('PUT', '**/agent/**').as('saveAgent');
cy.contains('Save changes').click();
cy.wait('@saveAgent').its('response.statusCode').should('eq', 200);

This pattern correctly matches the update flow (PUT to /agent/{id}) and adds status validation to catch API failures early.

Refs:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggestion to use PUT is incorrect for this codebase. The save goes through Next.js server actions — the browser sends a POST request to the current page URL (with a Next-Action header), and the PUT /agent/{id} call happens server-side within the action handler. Cypress cy.intercept() only catches browser-initiated requests, so it can see the POST server action but NOT the server-side PUT.

This is exactly why the earlier attempt with cy.intercept('PUT', '**/agent/**') failed with No request ever occurred — the PUT never passes through the browser.

The POST **/agents/* pattern correctly matches the server action POST to URLs like /default/projects/my-weather-project/agents/<id>. Both CI runs (Cypress + main CI) passed with this approach, confirming the pattern works.

cy.contains('Agent saved', { timeout: 10000 }).should('exist');
cy.reload();
cy.get('.react-flow__node').should('have.length', 3);
cy.get('.react-flow__node', { timeout: 10000 }).should('have.length', 3);
}
});

Expand Down
Loading