yangzheli 4efc8d404f
feat(frontend): set up Vitest frontend testing infrastructure with CI workflow (#2147)
* feat: set up Vitest frontend testing infrastructure with CI workflow

Migrate existing 4 frontend test files from Node.js native test runner
(node:test + node:assert/strict) to Vitest, reorganize test directory
structure under tests/unit/ mirroring src/ layout, and add a dedicated
CI workflow for frontend unit tests.

- Add vitest as devDependency, remove tsx
- Create vitest.config.ts with @/ path alias
- Migrate tests to Vitest API (test/expect/vi)
- Rename .mjs test files to .ts
- Move tests from src/ to tests/unit/ (mirrors src/ layout)
- Add frontend/Makefile `test` target
- Add .github/workflows/frontend-unit-tests.yml (parallel to backend)
- Update CONTRIBUTING.md, README.md, AGENTS.md, CLAUDE.md

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* style: fix the lint error

* style: fix the lint error

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Willem Jiang <willem.jiang@gmail.com>
2026-04-12 18:00:43 +08:00

47 lines
1.3 KiB
TypeScript

import { expect, test } from "vitest";
import { pathOfThread } from "@/core/threads/utils";
test("uses standard chat route when thread has no agent context", () => {
expect(pathOfThread("thread-123")).toBe("/workspace/chats/thread-123");
expect(
pathOfThread({
thread_id: "thread-123",
}),
).toBe("/workspace/chats/thread-123");
});
test("uses agent chat route when thread context has agent_name", () => {
expect(
pathOfThread({
thread_id: "thread-123",
context: { agent_name: "researcher" },
}),
).toBe("/workspace/agents/researcher/chats/thread-123");
});
test("uses provided context when pathOfThread is called with a thread id", () => {
expect(pathOfThread("thread-123", { agent_name: "ops agent" })).toBe(
"/workspace/agents/ops%20agent/chats/thread-123",
);
});
test("uses agent chat route when thread metadata has agent_name", () => {
expect(
pathOfThread({
thread_id: "thread-456",
metadata: { agent_name: "coder" },
}),
).toBe("/workspace/agents/coder/chats/thread-456");
});
test("prefers context.agent_name over metadata.agent_name", () => {
expect(
pathOfThread({
thread_id: "thread-789",
context: { agent_name: "from-context" },
metadata: { agent_name: "from-metadata" },
}),
).toBe("/workspace/agents/from-context/chats/thread-789");
});