Skip to content

Commit 6ef6540

Browse files
committed
fix: make checkAgentEndpoint accept Hono router 404 as proof runtime is mounted
1 parent 74fc015 commit 6ef6540

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

showcase/tests/e2e/helpers.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,36 +89,44 @@ export async function checkAgentEndpoint(
8989
baseUrl: string,
9090
agentPath: string = "/api/copilotkit",
9191
): Promise<AgentCheckResult> {
92-
// Try GET /info first (CopilotKit runtime info endpoint)
93-
// then fall back to POST on the base path
92+
// Try GET /info first (CopilotKit runtime info endpoint — returns runtime
93+
// metadata on starters that support it). Then fall back to POST on the base
94+
// path. The key check is that we get ANY response from the CopilotKit runtime
95+
// (even a 404 from its internal Hono router) rather than a Next.js 404 page.
9496
const infoPaths = [`${agentPath}/info`, agentPath];
9597

9698
for (const path of infoPaths) {
9799
try {
98100
const res = await request.get(`${baseUrl}${path}`, { timeout: 15_000 });
99-
if (res.status() >= 200 && res.status() < 500) {
100-
return {
101-
ok: true,
102-
status: res.status(),
103-
body: await res.text(),
104-
};
101+
const body = await res.text();
102+
// Accept 2xx as definitive success
103+
if (res.status() >= 200 && res.status() < 300) {
104+
return { ok: true, status: res.status(), body };
105+
}
106+
// A 405 "Method not allowed" proves the route exists (just wrong method)
107+
if (res.status() === 405) {
108+
return { ok: true, status: res.status(), body };
105109
}
106110
} catch {
107111
// try next path
108112
}
109113
}
110114

111-
// All failed — try POST on base path as last resort
115+
// Fall back to POST — the CopilotKit Hono router may return its own 404
116+
// for a bare POST (expects sub-path), but that still proves the runtime
117+
// is mounted. Distinguish from a Next.js 404 by checking for JSON body.
112118
try {
113119
const res = await request.post(`${baseUrl}${agentPath}`, {
114120
headers: { "Content-Type": "application/json" },
115121
data: { messages: [], tools: [], agentId: "agentic_chat" },
116122
timeout: 15_000,
117123
});
124+
const body = await res.text();
125+
const isRuntimeResponse = body.includes('"error"') || res.status() !== 404;
118126
return {
119-
ok: res.status() >= 200 && res.status() < 500,
127+
ok: isRuntimeResponse,
120128
status: res.status(),
121-
body: await res.text(),
129+
body,
122130
};
123131
} catch (e: unknown) {
124132
const msg = e instanceof Error ? e.message : String(e);

0 commit comments

Comments
 (0)