5fe5d51b1b
AI Proxy (was AI Router): - server/lib/ai-proxies.js, proxy-apply.js, routes/ai-proxies.js mounted at /api/ai-proxies and the old /api/ai-routers; `router` still accepted on the start routes; profiles move to <CLAUDE_HOME>/agenthub-proxies/ - dashboard_runs.router renamed in place to proxy: an older build on the same DB fails on that column, so dev and prod sharing one DB update together - a proxy's baseUrl stored as its root (a typed /v1 made /v1/v1/messages); Test probes Claude /v1/messages and Codex /v1/responses - Settings → AI Proxy (/settings/ai-router redirects), ProxyPicker Updates: - every tab reloads onto the new UI build when its WebSocket reconnects to a server of another version (lib/newBuildReload.ts, once per version) - Update now stops waiting on a plugin chain that failed or pulled nothing (the old server never goes down), and reloads as soon as a new version answers Also: - a pane whose command exits at once says so (EPANEEXITED) instead of "Command failed: tmux set-option … mouse on" - the pane drag preview draws where the pane actually lands
296 lines
11 KiB
TypeScript
296 lines
11 KiB
TypeScript
/**
|
|
* @file Regression test for the lane card's status badge. Every lane status
|
|
* the server can set must have a real translated word behind
|
|
* `t("status." + lane.status)`; before this test existed, no locale defined
|
|
* any `status.*` key, and i18next's default missing-key behavior (return the
|
|
* key itself) hid that from the `||` fallback, so the badge showed literal
|
|
* text like `status.active`.
|
|
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
|
|
*/
|
|
|
|
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
import { render, screen } from "@testing-library/react";
|
|
import userEvent from "@testing-library/user-event";
|
|
import LaneCard from "../LaneCard";
|
|
import type { Lane } from "../../../lib/types";
|
|
import { api } from "../../../lib/api";
|
|
|
|
vi.mock("../../../lib/api", () => ({
|
|
api: {
|
|
lanes: {
|
|
git: vi.fn(),
|
|
runtime: vi.fn(),
|
|
up: vi.fn(),
|
|
down: vi.fn(),
|
|
preflight: vi.fn().mockResolvedValue({ blocked: [], warnings: [] }),
|
|
mcpSync: vi.fn(),
|
|
},
|
|
locks: {
|
|
list: vi.fn(),
|
|
},
|
|
aiProxies: {
|
|
list: vi.fn(),
|
|
},
|
|
run: {
|
|
kill: vi.fn(),
|
|
start: vi.fn(),
|
|
},
|
|
},
|
|
}));
|
|
|
|
beforeEach(() => {
|
|
vi.mocked(api.lanes.git).mockReset();
|
|
vi.mocked(api.lanes.git).mockResolvedValue({ available: false });
|
|
// A lane with no profile is the default fixture: most lanes never run a
|
|
// stack, so the runtime strip and its button stay absent unless a test opts in.
|
|
vi.mocked(api.lanes.runtime).mockReset();
|
|
vi.mocked(api.lanes.runtime).mockResolvedValue({ available: false });
|
|
// Only the built-in profile by default: a user who never opened the AI Proxy
|
|
// tab has nothing to switch between, so the row stays out of every other test.
|
|
vi.mocked(api.aiProxies.list).mockReset();
|
|
vi.mocked(api.aiProxies.list).mockResolvedValue({ items: [] });
|
|
});
|
|
vi.mocked(api.locks.list).mockReset();
|
|
vi.mocked(api.locks.list).mockResolvedValue({ locks: [] });
|
|
|
|
function makeLane(overrides: Partial<Lane> = {}): Lane {
|
|
// `as Lane`: spreading a Partial<Lane> widens every field it may carry to
|
|
// `T | undefined`, which no longer satisfies Lane's required fields. The
|
|
// base object below still lists all of them, so the cast asserts what the
|
|
// literal already proves.
|
|
return {
|
|
id: 1,
|
|
title: "demo",
|
|
cwd: "/work/demo",
|
|
branch: "lane/demo",
|
|
kind: "adopted",
|
|
tool: "claude",
|
|
source_repo: null,
|
|
pipeline: "default",
|
|
session_id: null,
|
|
run_id: null,
|
|
stage: "plan",
|
|
stage_since: null,
|
|
status: "idle",
|
|
gate_decision: null,
|
|
ci_status: null,
|
|
needs_action: null,
|
|
links: {},
|
|
stages: {},
|
|
notes: null,
|
|
pipeline_name: "Default",
|
|
pipeline_nodes: [],
|
|
progress: 0,
|
|
stage_seconds: null,
|
|
last_event_seconds: null,
|
|
liveness: "idle",
|
|
detected_stage: null,
|
|
detected_signal: null,
|
|
slot: null,
|
|
ports: {},
|
|
...overrides,
|
|
} as Lane;
|
|
}
|
|
|
|
describe("LaneCard lane tool badge", () => {
|
|
// The strip tile already names the CLI; a card holding only that tag was an
|
|
// empty frame in the lane detail.
|
|
it("renders nothing for a codex or antigravity lane with nothing else to show", () => {
|
|
for (const tool of ["codex", "antigravity"] as const) {
|
|
const { container, unmount } = render(
|
|
<LaneCard {...{ lane: makeLane({ tool }), onAction: vi.fn() }} />
|
|
);
|
|
expect(container.querySelector('[data-testid="lane-card-1"]')).toBeEmptyDOMElement();
|
|
unmount();
|
|
}
|
|
});
|
|
});
|
|
|
|
describe("LaneCard child worktrees", () => {
|
|
it("lists worktrees provisioned from this lane and jumps to one on click", async () => {
|
|
const onSelectLane = vi.fn();
|
|
const worktree = makeLane({ id: 8, title: "Worktree A", status: "running" });
|
|
render(
|
|
<LaneCard
|
|
lane={makeLane({ id: 1 })}
|
|
onAction={vi.fn()}
|
|
childWorktrees={[worktree]}
|
|
onSelectLane={onSelectLane}
|
|
/>
|
|
);
|
|
|
|
expect(screen.getByTestId("lane-child-worktrees")).toBeInTheDocument();
|
|
const user = userEvent.setup();
|
|
await user.click(screen.getByRole("button", { name: /Worktree A/ }));
|
|
expect(onSelectLane).toHaveBeenCalledWith(8);
|
|
});
|
|
|
|
it("renders nothing when there are no child worktrees", () => {
|
|
render(<LaneCard lane={makeLane({ id: 1 })} onAction={vi.fn()} />);
|
|
expect(screen.queryByTestId("lane-child-worktrees")).not.toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
const pipelineNodes: Lane["pipeline_nodes"] = [
|
|
{ id: "intake", label: "intake", icon: "📥", gate: false, state: "done" },
|
|
{ id: "plan", label: "plan", icon: "🧭", gate: false, state: "done" },
|
|
{ id: "implement", label: "implement", icon: "🛠", gate: false, state: "current" },
|
|
{ id: "tests", label: "tests", icon: "🧪", gate: false, state: "pending" },
|
|
];
|
|
|
|
describe("LaneCard rebuilt layout", () => {
|
|
const full = (over: Partial<Lane> = {}) =>
|
|
makeLane({
|
|
id: 7,
|
|
title: "Rename Metric to Rule",
|
|
kind: "managed",
|
|
status: "running",
|
|
liveness: "active",
|
|
stage: "plan",
|
|
stage_seconds: 152,
|
|
progress: 48,
|
|
ci_status: "green",
|
|
pipeline_nodes: pipelineNodes,
|
|
...over,
|
|
});
|
|
|
|
it("labels the card with the lane id", () => {
|
|
render(<LaneCard lane={full()} onAction={vi.fn()} />);
|
|
expect(screen.getByTestId("lane-card-7")).toBeInTheDocument();
|
|
});
|
|
|
|
// The pipeline map below this card draws the same progress as named nodes,
|
|
// so the card no longer repeats it as a bar and a percent.
|
|
it("leaves progress to the pipeline map rather than drawing its own bar", () => {
|
|
render(<LaneCard lane={full()} onAction={vi.fn()} />);
|
|
expect(screen.queryByTestId("lane-progress-fill")).toBeNull();
|
|
expect(screen.queryByText("48%")).toBeNull();
|
|
});
|
|
|
|
it("leaves the needs-you message to the strip card", () => {
|
|
render(<LaneCard lane={full({ needs_action: "waiting on approval" })} onAction={vi.fn()} />);
|
|
expect(screen.queryByText(/waiting on approval/)).toBeNull();
|
|
});
|
|
|
|
it("keeps reset behind the ⋯ menu rather than showing it directly", async () => {
|
|
render(<LaneCard lane={full()} onAction={vi.fn()} />);
|
|
expect(screen.queryByTestId("lane-action-reset")).toBeNull();
|
|
|
|
await userEvent.setup().click(screen.getByTestId("lane-more"));
|
|
expect(screen.getByTestId("lane-action-reset")).toBeInTheDocument();
|
|
});
|
|
|
|
it("routes reset through the confirmation modal rather than firing it", async () => {
|
|
const onAction = vi.fn();
|
|
render(<LaneCard lane={full()} onAction={onAction} />);
|
|
const user = userEvent.setup();
|
|
await user.click(screen.getByTestId("lane-more"));
|
|
await user.click(screen.getByTestId("lane-action-reset"));
|
|
expect(onAction).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("offers the ⋯ menu only for a managed lane", async () => {
|
|
const user = userEvent.setup();
|
|
const { unmount } = render(<LaneCard lane={full()} onAction={vi.fn()} />);
|
|
await user.click(screen.getByTestId("lane-more"));
|
|
expect(screen.getByTestId("lane-action-reset")).toBeInTheDocument();
|
|
unmount();
|
|
|
|
// An adopted lane has no worktree to reset, so there is no ⋯ to open.
|
|
render(<LaneCard lane={full({ kind: "adopted" })} onAction={vi.fn()} />);
|
|
expect(screen.queryByTestId("lane-more")).toBeNull();
|
|
expect(screen.queryByTestId("lane-action-reset")).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("LaneCard git block", () => {
|
|
it("carries no working-copy row — that heads the Changes panel now", async () => {
|
|
render(<LaneCard lane={makeLane({ id: 4 })} onAction={vi.fn()} />);
|
|
expect(await screen.findByTestId("lane-card-4")).toBeInTheDocument();
|
|
expect(screen.queryByTestId("lane-git")).toBeNull();
|
|
expect(api.lanes.git).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
describe("LaneCard — the lane's own application stack", () => {
|
|
const upRuntime = {
|
|
available: true as const,
|
|
provisioned: true as const,
|
|
slot: 3,
|
|
kind: "managed" as const,
|
|
hooks: ["boot", "health"],
|
|
profileDir: "/work/demo/.agenthub/profile",
|
|
services: [{ name: "web", pid: 4242, alive: true }],
|
|
ports: { api: { port: 8003, expected: 8003, listening: true } },
|
|
steppedAside: false,
|
|
up: true,
|
|
healthy: true,
|
|
logs: ["boot.log"],
|
|
logDir: "/lanes/.state/lane3/logs",
|
|
lastError: null,
|
|
};
|
|
|
|
it("shows nothing at all for a lane whose repo declares no profile", async () => {
|
|
vi.mocked(api.lanes.runtime).mockResolvedValue({ available: false });
|
|
render(<LaneCard lane={makeLane()} onAction={vi.fn()} />);
|
|
|
|
expect(await screen.findByTestId("lane-card-1")).toBeInTheDocument();
|
|
expect(screen.queryByTestId("lane-runtime-1")).toBeNull();
|
|
});
|
|
|
|
it("lists each declared port with its listening state", async () => {
|
|
vi.mocked(api.lanes.runtime).mockResolvedValue(upRuntime);
|
|
render(<LaneCard lane={makeLane()} onAction={vi.fn()} />);
|
|
|
|
expect(await screen.findByTestId("lane-runtime-1")).toBeInTheDocument();
|
|
expect(screen.getByText(":8003")).toBeInTheDocument();
|
|
expect(screen.getByTestId("lane-runtime-state")).toHaveTextContent(/healthy/i);
|
|
});
|
|
|
|
it("flags a port that stepped aside from its base, showing the expected number", async () => {
|
|
vi.mocked(api.lanes.runtime).mockResolvedValue({
|
|
...upRuntime,
|
|
steppedAside: true,
|
|
ports: { api: { port: 8103, expected: 8003, listening: true } },
|
|
});
|
|
render(<LaneCard lane={makeLane()} onAction={vi.fn()} />);
|
|
|
|
expect(await screen.findByText(":8103")).toBeInTheDocument();
|
|
expect(screen.getByText(/8003/)).toBeInTheDocument();
|
|
});
|
|
|
|
it("surfaces the last boot error when nothing is streaming", async () => {
|
|
vi.mocked(api.lanes.runtime).mockResolvedValue({
|
|
...upRuntime,
|
|
up: false,
|
|
healthy: false,
|
|
lastError: { at: "2026-08-03T00:00:00Z", code: "EUNHEALTHY", message: "health check failed" },
|
|
});
|
|
render(<LaneCard lane={makeLane()} onAction={vi.fn()} />);
|
|
|
|
expect(await screen.findByText(/EUNHEALTHY/)).toBeInTheDocument();
|
|
expect(screen.getByText(/health check failed/)).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
describe("LaneCard — named locks", () => {
|
|
it("shows a lock badge when this lane holds a named lock", async () => {
|
|
vi.mocked(api.locks.list).mockResolvedValue({
|
|
locks: [{ name: "build", holder: "lane1", since: 0, ageSec: 120 }],
|
|
});
|
|
render(<LaneCard lane={makeLane({ slot: 1 })} onAction={vi.fn()} />);
|
|
|
|
expect(await screen.findByTestId("lane-locks-1")).toBeInTheDocument();
|
|
expect(screen.getByText(/lock/i)).toBeInTheDocument();
|
|
});
|
|
|
|
it("shows no lock badge when locks belong to a different lane", async () => {
|
|
vi.mocked(api.locks.list).mockResolvedValue({
|
|
locks: [{ name: "build", holder: "lane99", since: 0, ageSec: 120 }],
|
|
});
|
|
render(<LaneCard lane={makeLane({ slot: 1 })} onAction={vi.fn()} />);
|
|
|
|
expect(screen.queryByTestId("lane-locks-1")).not.toBeInTheDocument();
|
|
});
|
|
});
|