test: 新增测试代码文件

This commit is contained in:
claude-code-best
2026-04-02 14:44:56 +08:00
parent 9c3803d16b
commit 006ad97fbb
32 changed files with 1102 additions and 68 deletions

View File

@@ -1,5 +1,5 @@
import { describe, expect, test } from "bun:test";
import { validateUuid } from "../uuid";
import { validateUuid, createAgentId } from "../uuid";
describe("validateUuid", () => {
test("validates correct UUID", () => {
@@ -9,7 +9,7 @@ describe("validateUuid", () => {
test("validates uppercase UUID", () => {
const result = validateUuid("550E8400-E29B-41D4-A716-446655440000");
expect(result).not.toBeNull();
expect(result).toBe("550E8400-E29B-41D4-A716-446655440000");
});
test("returns null for non-string", () => {
@@ -31,4 +31,21 @@ describe("validateUuid", () => {
test("returns null for UUID with invalid chars", () => {
expect(validateUuid("550e8400-e29b-41d4-a716-44665544000g")).toBeNull();
});
test("returns null for UUID with leading/trailing whitespace", () => {
expect(validateUuid(" 550e8400-e29b-41d4-a716-446655440000")).toBeNull();
expect(validateUuid("550e8400-e29b-41d4-a716-446655440000 ")).toBeNull();
});
});
describe("createAgentId", () => {
test("generates id without label in correct format", () => {
const id = createAgentId();
expect(id).toMatch(/^a[0-9a-f]{16}$/);
});
test("generates id with label in correct format", () => {
const id = createAgentId("compact");
expect(id).toMatch(/^acompact-[0-9a-f]{16}$/);
});
});