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 { EnvironmentId } from "@akeru/contracts";
import { describe, expect, it, vi } from "vite-plus/test";
vi.mock("@effect/atom-react", () => ({ useAtomValue: () => null }));
vi.mock("../hooks/useTheme", () => ({ useTheme: () => ({ resolvedTheme: "dark" }) }));
vi.mock("../state/use-atom-query-runner", () => ({ useAtomQueryRunner: () => vi.fn() }));
vi.mock("../state/use-atom-command", () => ({ useAtomCommand: () => vi.fn() }));
vi.mock("../state/session", async (importOriginal) => ({
...(await importOriginal<typeof import("../state/session")>()),
usePreparedConnection: () => ({ _tag: "Loading" }),
}));
vi.mock("../state/entities", () => ({
readThreadShell: () => null,
useProjects: () => [],
}));
vi.mock("../localShellAccess", () => ({
useLocalShellAccess: () => ({ isLocal: true, isResolved: true }),
}));
vi.mock("../editorPreferences", () => ({
useOpenInPreferredEditor: () => vi.fn(),
usePreferredEditor: () => [null, vi.fn()],
}));
import {
canUseMarkdownFileShellActions,
hasMarkdownFilePrimaryAction,
shouldUseMarkdownFileBrowserPrimaryAction,
} from "./ChatMarkdown";
describe("canUseMarkdownFileShellActions", () => {
const environmentId = EnvironmentId.make("environment-1");
it("allows editor and file manager actions for local environments", () => {
expect(canUseMarkdownFileShellActions(environmentId, { isLocal: true, isResolved: true })).toBe(
true,
);
});
it("hides shell actions until the environment mode is resolved", () => {
expect(
canUseMarkdownFileShellActions(environmentId, { isLocal: true, isResolved: false }),
).toBe(false);
});
it("hides editor and file manager actions for remote environments", () => {
expect(
canUseMarkdownFileShellActions(environmentId, { isLocal: false, isResolved: true }),
).toBe(false);
});
it("hides shell actions when no environment owns the markdown", () => {
expect(canUseMarkdownFileShellActions(null, { isLocal: true, isResolved: true })).toBe(false);
});
});
describe("hasMarkdownFilePrimaryAction", () => {
it("keeps the chip interactive when an editor or browser can open it", () => {
expect(
hasMarkdownFilePrimaryAction({
canOpenInEditor: true,
canOpenInBrowser: false,
}),
).toBe(true);
expect(
hasMarkdownFilePrimaryAction({
canOpenInEditor: false,
canOpenInBrowser: true,
}),
).toBe(true);
});
it("removes the link affordance when no primary action can open the file", () => {
expect(
hasMarkdownFilePrimaryAction({
canOpenInEditor: false,
canOpenInBrowser: false,
}),
).toBe(false);
});
});
describe("shouldUseMarkdownFileBrowserPrimaryAction", () => {
it("uses the browser when it is the only available primary action", () => {
expect(
shouldUseMarkdownFileBrowserPrimaryAction({
iconPath: "/tmp/report.html",
canOpenInEditor: false,
canOpenInBrowser: true,
}),
).toBe(true);
});
it("prefers the editor for HTML files when one is available", () => {
expect(
shouldUseMarkdownFileBrowserPrimaryAction({
iconPath: "/tmp/report.html",
canOpenInEditor: true,
canOpenInBrowser: true,
}),
).toBe(false);
});
it("continues to open PDF files in the browser by default", () => {
expect(
shouldUseMarkdownFileBrowserPrimaryAction({
iconPath: "/tmp/report.pdf",
canOpenInEditor: true,
canOpenInBrowser: true,
}),
).toBe(true);
});
});