-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathhome_page.test.tsx
More file actions
444 lines (393 loc) · 20.6 KB
/
home_page.test.tsx
File metadata and controls
444 lines (393 loc) · 20.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
import { render, screen, within } from "@testing-library/react";
import type { ReactNode } from "react";
import { beforeEach, describe, expect, it, vi } from "vitest";
const { mockCookies } = vi.hoisted(() => ({
mockCookies: vi.fn(),
}));
vi.mock("next/link", () => ({
default: ({ href, children, prefetch: _prefetch, ...props }: { href: string; children: ReactNode; prefetch?: boolean }) => (
<a href={href} {...props}>
{children}
</a>
),
}));
vi.mock("../lib/api", () => ({
fetchRuns: vi.fn(),
fetchWorkflows: vi.fn(),
}));
vi.mock("next/headers", () => ({
cookies: mockCookies,
}));
vi.mock("next/navigation", () => ({
useRouter: () => ({
refresh: vi.fn(),
}),
usePathname: () => "/",
}));
import Home from "../app/page";
import RunsPage from "../app/runs/page";
import { metadata } from "../app/layout";
import DashboardShellChrome from "../components/DashboardShellChrome";
import { fetchRuns, fetchWorkflows } from "../lib/api";
import { getUiCopy } from "@cortexpilot/frontend-shared/uiCopy";
const ORIGINAL_PUBLIC_DOCS_BASE_URL = process.env.NEXT_PUBLIC_CORTEXPILOT_PUBLIC_DOCS_BASE_URL;
describe("dashboard home run-summary clarity", () => {
const mockFetchRuns = vi.mocked(fetchRuns);
const mockFetchWorkflows = vi.mocked(fetchWorkflows);
beforeEach(() => {
vi.clearAllMocks();
mockFetchRuns.mockResolvedValue([]);
mockFetchWorkflows.mockResolvedValue([]);
mockCookies.mockResolvedValue({
get: () => undefined,
toString: () => "",
});
if (ORIGINAL_PUBLIC_DOCS_BASE_URL === undefined) delete process.env.NEXT_PUBLIC_CORTEXPILOT_PUBLIC_DOCS_BASE_URL;
else process.env.NEXT_PUBLIC_CORTEXPILOT_PUBLIC_DOCS_BASE_URL = ORIGINAL_PUBLIC_DOCS_BASE_URL;
});
it("renders first-run CTA and onboarding guidance when no runs", async () => {
render(await Home());
const secondLayerGuides = screen.getByTestId("home-second-layer-guides");
secondLayerGuides.setAttribute("open", "");
expect(screen.getByRole("heading", { name: "The open command tower for AI engineering" })).toBeInTheDocument();
expect(
screen.getByText(/Stop babysitting AI coding work\./)
).toBeInTheDocument();
expect(screen.getByText("Second-layer guides, not the first impression")).toBeInTheDocument();
expect(screen.getByText("Open second-layer guides")).toBeInTheDocument();
expect(screen.getByText("Method layer, not the hero")).toBeInTheDocument();
expect(screen.getByText("Prompt Engineering")).toBeInTheDocument();
expect(screen.getByText("Context Engineering")).toBeInTheDocument();
expect(screen.getByText("Harness Engineering")).toBeInTheDocument();
expect(screen.getByRole("link", { name: "Start first task" })).toHaveAttribute("href", "/pm");
expect(screen.getAllByRole("link", { name: /Workflow Cases/ })[0]).toHaveAttribute("href", "/workflows");
const firstLoop = screen.getByLabelText("Start your first task in four steps");
expect(within(firstLoop).getByRole("link", { name: /Describe the request \(goal \+ acceptance\)/ })).toHaveAttribute("href", "/pm");
expect(within(firstLoop).getByRole("link", { name: /Watch live progress \(confirm it is moving\)/ })).toHaveAttribute("href", "/command-tower");
expect(within(firstLoop).getByRole("link", { name: /Confirm the Workflow Case/ })).toHaveAttribute("href", "/workflows");
expect(within(firstLoop).getByRole("link", { name: /Inspect Proof & Replay/ })).toHaveAttribute("href", "/runs");
expect(screen.getByRole("link", { name: /Approval checkpoint \(only when review is required\)/ })).toHaveAttribute("href", "/god-mode");
expect(within(firstLoop).getAllByText(/Step\s[1-4]/)).toHaveLength(4);
expect(within(firstLoop).getByText(/Start with the request, watch Command Tower, confirm the Workflow Case, then inspect Proof & Replay\./)).toBeInTheDocument();
expect(screen.getByText(/Each entry keeps the task ID, failure clue, and next operator action visible\./)).toBeInTheDocument();
expect(screen.getByText("Release-proven first run")).toBeInTheDocument();
expect(screen.getAllByRole("link", { name: /news_digest/i })[0]).toHaveAttribute("href", "/pm?template=news_digest");
expect(screen.getByText("Proof state: official public baseline")).toBeInTheDocument();
expect(screen.getByRole("link", { name: "Open proof pack" })).toHaveAttribute(
"href",
"https://xiaojiou176-open.github.io/OpenVibeCoding/use-cases/"
);
expect(screen.getByText("Extended surfaces")).toBeInTheDocument();
expect(screen.getByRole("link", { name: "See first proven workflow" })).toHaveAttribute(
"href",
"https://xiaojiou176-open.github.io/OpenVibeCoding/use-cases/"
);
expect(screen.queryByRole("link", { name: "Open compatibility matrix" })).not.toBeInTheDocument();
expect(screen.getByText("Compatibility matrix").closest("a")).toHaveAttribute(
"href",
"https://xiaojiou176-open.github.io/OpenVibeCoding/compatibility/"
);
expect(screen.getByText("Integration guide").closest("a")).toHaveAttribute(
"href",
"https://xiaojiou176-open.github.io/OpenVibeCoding/integrations/"
);
expect(screen.getByText("Skills quickstart").closest("a")).toHaveAttribute(
"href",
"https://xiaojiou176-open.github.io/OpenVibeCoding/skills/"
);
expect(screen.getByRole("link", { name: "Open AI + MCP + API surfaces" })).toHaveAttribute(
"href",
"https://xiaojiou176-open.github.io/OpenVibeCoding/ai-surfaces/"
);
expect(screen.getByRole("link", { name: "Open ecosystem map" })).toHaveAttribute(
"href",
"https://xiaojiou176-open.github.io/OpenVibeCoding/ecosystem/"
);
expect(screen.getByRole("link", { name: "Open builder quickstart" })).toHaveAttribute(
"href",
"https://xiaojiou176-open.github.io/OpenVibeCoding/builders/"
);
expect(screen.getByText("Read-only MCP quickstart").closest("a")).toHaveAttribute(
"href",
"https://xiaojiou176-open.github.io/OpenVibeCoding/mcp/"
);
expect(screen.getByText("API and contract quickstart").closest("a")).toHaveAttribute(
"href",
"https://xiaojiou176-open.github.io/OpenVibeCoding/api/"
);
expect(screen.getByText("Live Workflow Case gallery")).toBeInTheDocument();
expect(screen.getAllByRole("link", { name: "Open Workflow Cases" })[0]).toHaveAttribute("href", "/workflows");
expect(screen.getByRole("link", { name: "See first proven workflow" })).toHaveAttribute(
"href",
"https://xiaojiou176-open.github.io/OpenVibeCoding/use-cases/"
);
expect(screen.getByText("Risk summary")).toBeInTheDocument();
expect(screen.getByRole("link", { name: "Governance entry: open runs" })).toHaveAttribute("href", "/runs");
expect(screen.getByText("Stable: no recent failed runs (0%)")).toHaveClass("badge--success");
expect(screen.getByRole("progressbar", { name: "Failure share 0/0" })).toBeInTheDocument();
expect(screen.getByRole("link", { name: "View all runs" })).toHaveAttribute("href", "/runs");
expect(screen.getByText("Live command tower").closest("a")).toHaveAttribute("href", "/command-tower");
expect(screen.queryByRole("link", { name: "Quick approval" })).not.toBeInTheDocument();
}, 30000);
it("keeps the shared home copy contract aligned across locales", () => {
const en = getUiCopy("en").dashboard.homePhase2;
const zh = getUiCopy("zh-CN").dashboard.homePhase2;
expect(en.productSpineCards).toHaveLength(3);
expect(zh.productSpineCards).toHaveLength(en.productSpineCards.length);
expect(zh.publicTemplateCards).toHaveLength(en.publicTemplateCards.length);
expect(zh.publicAdvantageCards).toHaveLength(en.publicAdvantageCards.length);
expect(zh.integrationCards).toHaveLength(en.integrationCards.length);
expect(zh.firstTaskGuideSteps).toHaveLength(en.firstTaskGuideSteps.length);
expect(en.aiSurfacesActionHref).toBe("/ai-surfaces/");
expect(en.publicTemplatesActionHref).toBe("/use-cases/");
expect(zh.liveCaseGalleryActionHref).toBe("/workflows");
expect(en.optionalApprovalStep.href).toBe("/god-mode");
expect(zh.builderQuickstartCtaHref).toBe("/builders/");
});
it("routes public docs CTAs through the configured docs base", async () => {
process.env.NEXT_PUBLIC_CORTEXPILOT_PUBLIC_DOCS_BASE_URL = "https://docs.example/cortexpilot/";
render(await Home());
expect(screen.getByRole("link", { name: "Open AI + MCP + API surfaces" })).toHaveAttribute(
"href",
"https://docs.example/cortexpilot/ai-surfaces/"
);
expect(screen.getByRole("link", { name: "Open ecosystem map" })).toHaveAttribute(
"href",
"https://docs.example/cortexpilot/ecosystem/"
);
expect(screen.getByRole("link", { name: "Open builder quickstart" })).toHaveAttribute(
"href",
"https://docs.example/cortexpilot/builders/"
);
expect(screen.getByRole("link", { name: "See first proven workflow" })).toHaveAttribute(
"href",
"https://docs.example/cortexpilot/use-cases/"
);
expect(screen.getByText("Compatibility matrix").closest("a")).toHaveAttribute(
"href",
"https://docs.example/cortexpilot/compatibility/"
);
expect(screen.getByText("Integration guide").closest("a")).toHaveAttribute(
"href",
"https://docs.example/cortexpilot/integrations/"
);
expect(screen.getByText("Skills quickstart").closest("a")).toHaveAttribute(
"href",
"https://docs.example/cortexpilot/skills/"
);
expect(screen.getByText("Read-only MCP quickstart").closest("a")).toHaveAttribute(
"href",
"https://docs.example/cortexpilot/mcp/"
);
expect(screen.getByText("API and contract quickstart").closest("a")).toHaveAttribute(
"href",
"https://docs.example/cortexpilot/api/"
);
expect(screen.getByRole("link", { name: "Open ecosystem map" })).toHaveAttribute(
"href",
"https://docs.example/cortexpilot/ecosystem/"
);
});
it("switches CTA wording once run history exists", async () => {
mockFetchRuns.mockResolvedValueOnce([
{
run_id: "run-0",
task_id: "task-0",
status: "SUCCESS",
},
] as never[]);
render(await Home());
expect(screen.getByRole("link", { name: "Start new task" })).toHaveAttribute("href", "/pm");
expect(screen.queryByRole("link", { name: "Start first task" })).not.toBeInTheDocument();
expect(screen.queryByLabelText("Start your first task in four steps")).not.toBeInTheDocument();
});
it("renders zh-CN home copy when the locale cookie requests it", async () => {
mockCookies.mockResolvedValue({
get: (name: string) => (name === "cortexpilot.ui.locale" ? { value: "zh-CN" } : undefined),
toString: () => "cortexpilot.ui.locale=zh-CN",
});
render(await Home());
const secondLayerGuides = screen.getByTestId("home-second-layer-guides");
secondLayerGuides.setAttribute("open", "");
expect(screen.getByRole("heading", { name: "面向 AI 工程的开放指挥塔" })).toBeInTheDocument();
expect(screen.getByRole("link", { name: "启动首个任务" })).toHaveAttribute("href", "/pm");
expect(screen.getByText("延伸入口")).toBeInTheDocument();
expect(screen.getByRole("link", { name: "打开 AI + MCP + API 页面" })).toHaveAttribute(
"href",
"https://xiaojiou176-open.github.io/OpenVibeCoding/ai-surfaces/"
);
expect(screen.getByRole("link", { name: "打开证明包" })).toHaveAttribute(
"href",
"https://xiaojiou176-open.github.io/OpenVibeCoding/use-cases/"
);
expect(screen.getByRole("link", { name: "打开 builder 快速入口" })).toHaveAttribute(
"href",
"https://xiaojiou176-open.github.io/OpenVibeCoding/builders/"
);
expect(screen.getByRole("link", { name: "查看首个已证明工作流" })).toHaveAttribute(
"href",
"https://xiaojiou176-open.github.io/OpenVibeCoding/use-cases/"
);
expect(screen.queryByRole("link", { name: "打开 compatibility matrix" })).not.toBeInTheDocument();
expect(screen.getByText("Compatibility matrix").closest("a")).toHaveAttribute(
"href",
"https://xiaojiou176-open.github.io/OpenVibeCoding/compatibility/"
);
expect(screen.getByText("Integration guide").closest("a")).toHaveAttribute(
"href",
"https://xiaojiou176-open.github.io/OpenVibeCoding/integrations/"
);
expect(screen.getAllByText("Read-only MCP quickstart").length).toBeGreaterThan(0);
expect(screen.getAllByText("API and contract quickstart").length).toBeGreaterThan(0);
expect(screen.getByText("显示四步首跑流程")).toBeInTheDocument();
});
it("maps latest failure category to semantic label and provides governance link", async () => {
mockFetchRuns.mockResolvedValueOnce([
{
run_id: "run-1",
task_id: "task-1",
status: "FAILED",
failure_class: "manual",
action_hint_zh: "完成人工确认后继续",
},
] as never[]);
render(await Home());
expect(screen.getByText("Risk summary")).toBeInTheDocument();
expect(screen.getByText("Failure category: Manual review required")).toBeInTheDocument();
expect(screen.getByRole("link", { name: "Governance entry: inspect failure events" })).toHaveAttribute("href", "/events");
expect(screen.queryByText(/^manual$/i)).not.toBeInTheDocument();
expect(screen.getByRole("link", { name: "Run run-1" })).toHaveAttribute("href", "/runs/run-1");
expect(screen.getByText(/Task: task-1 · Manual review required/)).toBeInTheDocument();
const handleFailureLink = screen.getByRole("link", { name: "Handle failure run-1" });
expect(handleFailureLink).toHaveAttribute("href", "/events?run_id=run-1");
expect(handleFailureLink.closest("span")).toHaveClass("cell-danger");
});
it("shows high-risk distribution semantics when failure rate is high", async () => {
mockFetchRuns.mockResolvedValueOnce([
{ run_id: "run-1", task_id: "task-1", status: "FAILED" },
{ run_id: "run-2", task_id: "task-2", status: "ERROR" },
{ run_id: "run-3", task_id: "task-3", status: "FAILURE" },
{ run_id: "run-4", task_id: "task-4", status: "SUCCESS" },
] as never[]);
render(await Home());
expect(screen.getByText("Success 1 / Running 0 / Failed 3")).toHaveClass("metric-value--danger");
expect(screen.getByText("High risk: failure rate is elevated, investigate first (75%)")).toHaveClass("badge--failed");
expect(screen.queryByRole("alert")).not.toBeInTheDocument();
expect(screen.getByRole("link", { name: "Investigate high-risk failures" })).toHaveAttribute("href", "/events");
expect(screen.getAllByRole("link", { name: /Handle failure run-/ })).toHaveLength(3);
expect(screen.getByRole("link", { name: "Handle failure run-1" })).toHaveAttribute("href", "/events?run_id=run-1");
const progressBar = screen.getByRole("progressbar", { name: "Failure share 3/4" });
expect(progressBar).toHaveAttribute("max", "4");
expect(progressBar).toHaveAttribute("value", "3");
});
it("renders long run id with suffix-plus-task format for faster distinction", async () => {
mockFetchRuns.mockResolvedValueOnce([
{
run_id: "run-20260221-aaaaaaaa11111111",
task_id: "task-20260221-abcde12345",
status: "SUCCESS",
},
] as never[]);
render(await Home());
const runLink = screen.getByRole("link", { name: "Run run-20260221-aaaaaaaa11111111" });
expect(runLink).toHaveTextContent("aa11111111 · abcde12345");
expect(runLink).toHaveAttribute("title", "run-20260221-aaaaaaaa11111111");
});
it("falls back to raw timestamps and placeholder ids when run metadata is incomplete", async () => {
mockFetchRuns.mockResolvedValueOnce([
{
run_id: "",
task_id: "",
status: "RUNNING",
created_at: "not-a-date",
},
] as never[]);
render(await Home());
expect(screen.getAllByText("not-a-date")).toHaveLength(2);
expect(screen.getByText("Task: - · Unclassified")).toBeInTheDocument();
expect(screen.getByText("-", { selector: "span.mono.muted" })).toBeInTheDocument();
});
it("renders long run id head-tail format when task id is absent", async () => {
mockFetchRuns.mockResolvedValueOnce([
{
run_id: "run-20260221-aaaaaaaa11111111",
task_id: "",
status: "SUCCESS",
},
] as never[]);
render(await Home());
const runLink = screen.getByRole("link", { name: "Run run-20260221-aaaaaaaa11111111" });
expect(runLink).toHaveTextContent("run-2026…aa11111111");
expect(screen.getByText("Task: - · Unclassified")).toBeInTheDocument();
});
it("formats valid timestamps with en-US local display", async () => {
const createdAt = "2026-02-21T08:09:00Z";
mockFetchRuns.mockResolvedValueOnce([
{
run_id: "run-timestamp-1",
task_id: "task-timestamp-1",
status: "SUCCESS",
created_at: createdAt,
},
] as never[]);
render(await Home());
expect(screen.getAllByText(new Date(createdAt).toLocaleString("en-US", {
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
})).length).toBeGreaterThan(0);
});
it("renders runs governance entry and status-filter links for failed-focused triage", async () => {
mockFetchRuns.mockResolvedValueOnce([
{ run_id: "run-fail-1", task_id: "task-fail-1", status: "FAILED" },
{ run_id: "run-running-1", task_id: "task-running-1", status: "RUNNING" },
{ run_id: "run-success-1", task_id: "task-success-1", status: "SUCCESS" },
] as never[]);
render(await RunsPage({ searchParams: Promise.resolve({}) }));
expect(screen.getByRole("link", { name: "Open failed proof lane" })).toHaveAttribute("href", "/runs?status=FAILED");
expect(screen.getByRole("link", { name: "View failed events" })).toHaveAttribute("href", "/events");
expect(screen.getByRole("link", { name: "All runs" })).toHaveAttribute("href", "/runs");
expect(screen.getByRole("link", { name: "Failed" })).toHaveAttribute("href", "/runs?status=FAILED");
expect(screen.getByRole("link", { name: "Running" })).toHaveAttribute("href", "/runs?status=RUNNING");
expect(screen.getByRole("link", { name: "Succeeded" })).toHaveAttribute("href", "/runs?status=SUCCESS");
});
it("falls back governance CTA to PM creation when there is no failure", async () => {
mockFetchRuns.mockResolvedValueOnce([
{ run_id: "run-success-2", task_id: "task-success-2", status: "SUCCESS" },
] as never[]);
render(await RunsPage({ searchParams: Promise.resolve({ status: "SUCCESS" }) }));
expect(screen.getByRole("link", { name: "Start a new task" })).toHaveAttribute("href", "/pm");
expect(screen.queryByRole("link", { name: "View failed events" })).not.toBeInTheDocument();
});
it("shows degraded risk summary when runs data is unavailable", async () => {
const consoleSpy = vi.spyOn(console, "error").mockImplementation(() => {});
mockFetchRuns.mockRejectedValueOnce(new Error("runs down"));
render(await Home());
expect(screen.getByText("Data degraded")).toHaveClass("metric-value--warning");
expect(screen.getByText("Latest status: Data degraded")).toBeInTheDocument();
expect(screen.getByText("Failure category: unavailable while data is degraded")).toHaveClass("cell-warning");
expect(screen.getByRole("link", { name: "Governance entry: inspect data sources and the run list" })).toHaveAttribute("href", "/runs");
expect(screen.getByText("Data degraded: the run list is temporarily unavailable (0%)")).toHaveClass("badge--warning");
expect(screen.getByText("Total: -")).toBeInTheDocument();
consoleSpy.mockRestore();
});
it("renders the public shell with English-first layout metadata and chrome copy", () => {
expect(metadata.title).toBe("OpenVibeCoding | The open command tower for AI engineering");
expect(metadata.description).toContain("Stop babysitting AI coding work.");
render(
<DashboardShellChrome>
<div>content</div>
</DashboardShellChrome>
);
expect(screen.getByRole("link", { name: "Skip to dashboard content" })).toHaveAttribute("href", "#dashboard-content");
expect(screen.getAllByLabelText("Dashboard navigation").length).toBeGreaterThan(0);
expect(screen.getByText("OpenVibeCoding")).toBeInTheDocument();
expect(screen.getByText("plan / delegate / track / resume / prove")).toBeInTheDocument();
expect(screen.getByText("OpenVibeCoding command tower")).toBeInTheDocument();
expect(screen.getByLabelText("Platform status overview")).toBeInTheDocument();
expect(screen.getByText("Governance view")).toBeInTheDocument();
expect(screen.getByText("Live verification required")).toBeInTheDocument();
expect(screen.getByText("Page-level status")).toBeInTheDocument();
});
});