Skip to content
Merged
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
41 changes: 2 additions & 39 deletions config/quality/vitest-exclusions.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,5 @@
{
"_comment": "Inventário dos arquivos de teste excluídos do Vitest. Toda entrada precisa de uma issue de rastreio ABERTA. Gate: npm run check:vitest-exclusions. Contexto: #13204.",
"_measured": "2026-09-10 — cada arquivo rodado isoladamente com as exclusões removidas",
"excluded": [
{
"file": "tests/unit/ui/agent-card.test.tsx",
"issue": "#13204",
"measured": "2026-09-10",
"status": "Tests 3 failed | 1 passed (4)"
},
{
"file": "src/app/(dashboard)/dashboard/cache/__tests__/CacheTrends.test.tsx",
"issue": "#13204",
"measured": "2026-09-10",
"status": "Tests 7 failed | 6 passed (13)"
},
{
"file": "src/app/(dashboard)/dashboard/cache/__tests__/IdempotencyLayer.test.tsx",
"issue": "#13204",
"measured": "2026-09-10",
"status": "Tests 9 failed | 4 passed (13)"
},
{
"file": "src/app/(dashboard)/dashboard/cache/__tests__/CachePerformance.test.tsx",
"issue": "#13204",
"measured": "2026-09-10",
"status": "Tests 10 failed | 4 passed (14)"
},
{
"file": "tests/unit/ui/combos-page-smoke.test.tsx",
"issue": "#13204",
"measured": "2026-09-10",
"status": "Tests 1 failed (1)"
},
{
"file": "tests/unit/ui/evals-tab-smoke.test.tsx",
"issue": "#13204",
"measured": "2026-09-10",
"status": "Tests 1 failed (1)"
}
]
"_measured": "2026-09-22 — six repaired files returned to normal discovery after 46/46 focused tests passed",
"excluded": []
}
41 changes: 29 additions & 12 deletions tests/unit/ui/agent-card.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React from "react";
import { act } from "react";
import { createRoot } from "react-dom/client";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { AgentBridgeServerState } from "@/app/(dashboard)/dashboard/tools/agent-bridge/AgentBridgePageClient";

vi.mock("next-intl", () => ({
useTranslations: () => (key: string) => key,
Expand All @@ -25,6 +26,17 @@ globalThis.fetch = vi.fn().mockResolvedValue({
} as unknown as Response);

const cleanupCallbacks: Array<() => void> = [];
const serverState: AgentBridgeServerState = {
running: true,
port: 20128,
certTrusted: false,
upstreamCa: null,
lastStartedAt: null,
activeConns: 0,
interceptedCount: 0,
dnsConfigured: false,
orphanedStateDetected: false,
};

function makeContainer(): HTMLElement {
const container = document.createElement("div");
Expand Down Expand Up @@ -66,18 +78,19 @@ describe("AgentCard", { timeout: 30000 }, () => {
});

it("renders agent name and hosts", async () => {
const { AgentCard } = await import(
"../../../src/app/(dashboard)/dashboard/tools/agent-bridge/components/AgentCard"
);
const { AgentCard } =
await import("../../../src/app/(dashboard)/dashboard/tools/agent-bridge/components/AgentCard");

const container = makeContainer();
await act(async () => {
const root = createRoot(container);
cleanupCallbacks.push(() => act(() => root.unmount()));
root.render(
React.createElement(AgentCard, {
target: mockTarget,
agentState: undefined,
serverRunning: false,
serverState: { ...serverState, running: false },
mappings: [],
onDnsToggle: vi.fn(),
onMappingsSave: vi.fn(),
Expand All @@ -90,18 +103,19 @@ describe("AgentCard", { timeout: 30000 }, () => {
}, 30000);

it("expands on click and shows DNS toggle", async () => {
const { AgentCard } = await import(
"../../../src/app/(dashboard)/dashboard/tools/agent-bridge/components/AgentCard"
);
const { AgentCard } =
await import("../../../src/app/(dashboard)/dashboard/tools/agent-bridge/components/AgentCard");

const container = makeContainer();
await act(async () => {
const root = createRoot(container);
cleanupCallbacks.push(() => act(() => root.unmount()));
root.render(
React.createElement(AgentCard, {
target: mockTarget,
agentState: undefined,
serverRunning: true,
serverState,
mappings: [],
onDnsToggle: vi.fn(),
onMappingsSave: vi.fn(),
Expand All @@ -120,9 +134,8 @@ describe("AgentCard", { timeout: 30000 }, () => {
}, 30000);

it("calls onDnsToggle when DNS button clicked", async () => {
const { AgentCard } = await import(
"../../../src/app/(dashboard)/dashboard/tools/agent-bridge/components/AgentCard"
);
const { AgentCard } =
await import("../../../src/app/(dashboard)/dashboard/tools/agent-bridge/components/AgentCard");

// Simulate that the per-agent RiskNoticeModal (Fix4 M5) has already been
// accepted for this agent — otherwise the DNS click opens the modal first
Expand All @@ -136,6 +149,7 @@ describe("AgentCard", { timeout: 30000 }, () => {

await act(async () => {
const root = createRoot(container);
cleanupCallbacks.push(() => act(() => root.unmount()));
root.render(
React.createElement(AgentCard, {
target: mockTarget,
Expand All @@ -148,6 +162,7 @@ describe("AgentCard", { timeout: 30000 }, () => {
last_error: null,
},
serverRunning: true,
serverState,
mappings: [],
onDnsToggle,
onMappingsSave: vi.fn(),
Expand Down Expand Up @@ -175,18 +190,19 @@ describe("AgentCard", { timeout: 30000 }, () => {
}, 30000);

it("opens wizard when setup wizard button clicked", async () => {
const { AgentCard } = await import(
"../../../src/app/(dashboard)/dashboard/tools/agent-bridge/components/AgentCard"
);
const { AgentCard } =
await import("../../../src/app/(dashboard)/dashboard/tools/agent-bridge/components/AgentCard");

const container = makeContainer();
await act(async () => {
const root = createRoot(container);
cleanupCallbacks.push(() => act(() => root.unmount()));
root.render(
React.createElement(AgentCard, {
target: mockTarget,
agentState: undefined,
serverRunning: true,
serverState,
mappings: [],
onDnsToggle: vi.fn(),
onMappingsSave: vi.fn(),
Expand All @@ -204,6 +220,7 @@ describe("AgentCard", { timeout: 30000 }, () => {
const wizardBtn = Array.from(document.querySelectorAll("button")).find((b) =>
b.textContent?.includes("setupWizard")
);
expect(wizardBtn).toBeDefined();

await act(async () => {
wizardBtn?.dispatchEvent(new MouseEvent("click", { bubbles: true }));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// @vitest-environment jsdom
import { describe, it, expect, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import "@testing-library/jest-dom/vitest";
import { render, screen, within } from "@testing-library/react";
import React from "react";
import CachePerformance from "../components/CachePerformance";
import CachePerformance from "@/app/(dashboard)/dashboard/cache/components/CachePerformance";

vi.mock("next-intl", () => ({
useTranslations: () => (key: string) => key,
Expand Down Expand Up @@ -31,7 +32,9 @@ describe("CachePerformance", () => {

it("renders hit rate percentage", () => {
render(<CachePerformance {...defaultProps} />);
expect(screen.getByText("85.0%")).toBeInTheDocument();
const meter = screen.getByRole("progressbar", { name: "cachePerformanceHitRate" });
expect(meter).toHaveAttribute("aria-valuenow", "85");
expect(within(meter).getByText("85.0%")).toBeInTheDocument();
});

it("renders total requests", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
// @vitest-environment jsdom
import { describe, it, expect, vi } from "vitest";
import "@testing-library/jest-dom/vitest";
import { render, screen } from "@testing-library/react";
import React from "react";
import CacheTrends from "../components/CacheTrends";
import CacheTrends from "@/app/(dashboard)/dashboard/cache/components/CacheTrends";

vi.mock("next-intl", () => ({
useTranslations: () => (key: string) => key,
}));

const sampleTrendData = [
{ timestamp: "2026-04-01T00:00:00Z", requests: 120, hits: 100, misses: 20, hitRate: 83.3 },
{ timestamp: "2026-04-01T01:00:00Z", requests: 95, hits: 80, misses: 15, hitRate: 84.2 },
{ timestamp: "2026-04-01T02:00:00Z", requests: 200, hits: 180, misses: 20, hitRate: 90.0 },
{
timestamp: "2026-04-01T00:00:00Z",
requests: 120,
cachedRequests: 100,
inputTokens: 1200,
cachedTokens: 1000,
cacheCreationTokens: 0,
},
{
timestamp: "2026-04-01T01:00:00Z",
requests: 95,
cachedRequests: 80,
inputTokens: 950,
cachedTokens: 800,
cacheCreationTokens: 0,
},
{
timestamp: "2026-04-01T02:00:00Z",
requests: 200,
cachedRequests: 180,
inputTokens: 2000,
cachedTokens: 1800,
cacheCreationTokens: 0,
},
];

describe("CacheTrends", () => {
Expand All @@ -33,9 +55,9 @@ describe("CacheTrends", () => {
expect(screen.getByRole("heading")).toBeInTheDocument();
});

it("renders peak hit rate from data", () => {
it("renders peak cached requests against the maximum requests", () => {
render(<CacheTrends data={sampleTrendData} />);
expect(screen.getByText("90.0")).toBeInTheDocument();
expect(screen.getByText("180 / 200")).toBeInTheDocument();
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// @vitest-environment jsdom
import { describe, it, expect, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import "@testing-library/jest-dom/vitest";
import { render, screen, within } from "@testing-library/react";
import React from "react";
import IdempotencyLayer from "../components/IdempotencyLayer";
import IdempotencyLayer from "@/app/(dashboard)/dashboard/cache/components/IdempotencyLayer";

vi.mock("next-intl", () => ({
useTranslations: () => (key: string) => key,
Expand All @@ -20,7 +21,8 @@ describe("IdempotencyLayer", () => {
describe("renders with data", () => {
it("renders deduplicated request count", () => {
render(<IdempotencyLayer {...defaultProps} />);
expect(screen.getByText("47")).toBeInTheDocument();
const metric = screen.getByText("deduplicatedRequests").parentElement!;
expect(within(metric).getByText("47")).toBeInTheDocument();
});

it("renders deduplication window duration", () => {
Expand Down Expand Up @@ -53,7 +55,8 @@ describe("IdempotencyLayer", () => {

it("displays values once loading is complete", () => {
render(<IdempotencyLayer {...defaultProps} loading={false} />);
expect(screen.getByText("47")).toBeInTheDocument();
const metric = screen.getByText("deduplicatedRequests").parentElement!;
expect(within(metric).getByText("47")).toBeInTheDocument();
});
});

Expand Down
10 changes: 4 additions & 6 deletions tests/unit/ui/combos-page-smoke.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// @vitest-environment jsdom
import { describe, it, expect } from "vitest";
import CombosPage from "@/app/(dashboard)/dashboard/combos/page";

describe("combos page memoization", () => {
it("combos page module exports a default component", async () => {
const mod = await import(
"@/app/(dashboard)/dashboard/combos/page"
);
expect(mod.default).toBeDefined();
expect(typeof mod.default).toBe("function");
it("combos page module exports a default component", () => {
expect(CombosPage).toBeDefined();
expect(typeof CombosPage).toBe("function");
});
});
10 changes: 4 additions & 6 deletions tests/unit/ui/evals-tab-smoke.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// @vitest-environment jsdom
import { describe, it, expect } from "vitest";
import EvalsTab from "@/app/(dashboard)/dashboard/usage/components/EvalsTab";

describe("EvalsTab memoization", () => {
it("EvalsTab page module exports a default component", async () => {
const mod = await import(
"@/app/(dashboard)/dashboard/usage/components/EvalsTab"
);
expect(mod.default).toBeDefined();
expect(typeof mod.default).toBe("function");
it("EvalsTab page module exports a default component", () => {
expect(EvalsTab).toBeDefined();
expect(typeof EvalsTab).toBe("function");
});
});
7 changes: 0 additions & 7 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ export default defineConfig({
// in this jsdom job. They have their own runners + vitest.e2e-live.config.ts.
"tests/e2e/ecosystem.test.ts",
"tests/e2e/protocol-clients.test.ts",
// ── Pre-existing failures tracked by #8618 ───────────────────────────────
"tests/unit/ui/agent-card.test.tsx", // #13204 — falha real; remover esta exclusão quando consertado
"src/app/(dashboard)/dashboard/cache/__tests__/CacheTrends.test.tsx", // #13204 — falha real; remover esta exclusão quando consertado
"src/app/(dashboard)/dashboard/cache/__tests__/IdempotencyLayer.test.tsx", // #13204 — falha real; remover esta exclusão quando consertado
"src/app/(dashboard)/dashboard/cache/__tests__/CachePerformance.test.tsx", // #13204 — falha real; remover esta exclusão quando consertado
"tests/unit/ui/combos-page-smoke.test.tsx", // #13204 — falha real; remover esta exclusão quando consertado
"tests/unit/ui/evals-tab-smoke.test.tsx", // #13204 — falha real; remover esta exclusão quando consertado
],

coverage: {
Expand Down
Loading