Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
import { describe, expect, it } from "vite-plus/test";
import {
needsWorkspaceBasenameLookup,
pickWorkspaceBasenameMatch,
} from "./workspaceBasenameLookup";
describe("needsWorkspaceBasenameLookup", () => {
it("flags bare filenames", () => {
expect(needsWorkspaceBasenameLookup("ChatView.tsx")).toBe(true);
expect(needsWorkspaceBasenameLookup("Makefile")).toBe(true);
});
it("leaves anything with a directory alone", () => {
expect(needsWorkspaceBasenameLookup("apps/web/src/components/ChatView.tsx")).toBe(false);
expect(needsWorkspaceBasenameLookup("apps\\web\\ChatView.tsx")).toBe(false);
expect(needsWorkspaceBasenameLookup(" ")).toBe(false);
});
});
describe("pickWorkspaceBasenameMatch", () => {
const entries = [
{ path: "apps/web/src/components/ChatView.test.tsx", kind: "file" as const },
{ path: "apps/web/src/components/ChatView.tsx", kind: "file" as const },
];
it("takes the first exact filename match, not the closest fuzzy one", () => {
expect(pickWorkspaceBasenameMatch("ChatView.tsx", entries)).toBe(
"apps/web/src/components/ChatView.tsx",
);
});
it("ignores directories", () => {
expect(
pickWorkspaceBasenameMatch("components", [
{ path: "apps/web/src/components", kind: "directory" },
{ path: "apps/web/src/components/components", kind: "file" },
]),
).toBe("apps/web/src/components/components");
});
it("prefers the exactly-cased file over a case-only twin", () => {
expect(
pickWorkspaceBasenameMatch("foo.ts", [
{ path: "src/Foo.ts", kind: "file" },
{ path: "src/foo.ts", kind: "file" },
]),
).toBe("src/foo.ts");
});
it("falls back to case-insensitive when only the casing differs", () => {
expect(pickWorkspaceBasenameMatch("chatview.tsx", entries)).toBe(
"apps/web/src/components/ChatView.tsx",
);
});
it("returns null when the case-insensitive fallback is ambiguous", () => {
expect(
pickWorkspaceBasenameMatch("FOO.ts", [
{ path: "src/Foo.ts", kind: "file" },
{ path: "src/foo.ts", kind: "file" },
]),
).toBeNull();
});
it("returns null when nothing matches the name", () => {
expect(pickWorkspaceBasenameMatch("ChatView.tsx", [])).toBeNull();
expect(
pickWorkspaceBasenameMatch("ChatView.tsx", [
{ path: "apps/web/src/components/ChatHeader.tsx", kind: "file" },
]),
).toBeNull();
});
});