CoDEVX / lib /composer-autocomplete.test.ts
CodexMacTiger
feat: live package-scoped chat and thinking logs
837e3ac
import { describe, expect, it } from "vitest";
import seedWorkPackages from "../agentic_pm_demo_codex_plans/data/work-packages.seed.json";
import {
applyComposerSuggestion,
getComposerSuggestions,
} from "./composer-autocomplete";
import { parseCommand } from "./command-parser";
import type { WorkPackage } from "./work-package-types";
const workPackages = seedWorkPackages as WorkPackage[];
const selectedWorkPackage = workPackages.find((wp) => wp.shortName === "SRS");
describe("composer autocomplete", () => {
it("returns work package suggestions for @ queries", () => {
const suggestions = getComposerSuggestions("@sr", workPackages);
expect(suggestions.some((suggestion) => suggestion.kind === "package")).toBe(
true,
);
expect(
suggestions.find(
(suggestion) =>
suggestion.kind === "package" && suggestion.shortName === "SRS",
),
).toBeTruthy();
});
it("returns all command suggestions for slash queries", () => {
const suggestions = getComposerSuggestions("/", workPackages);
expect(suggestions).toHaveLength(4);
expect(suggestions.map((suggestion) => suggestion.kind)).toEqual([
"command",
"command",
"command",
"command",
]);
expect(
suggestions.map((suggestion) =>
suggestion.kind === "command" ? suggestion.mode : null,
),
).toEqual(["ask", "plan", "change", "execute"]);
});
it("applies slash suggestions by expanding into an @ command", () => {
const suggestion = getComposerSuggestions("/pl", workPackages).find(
(item) => item.kind === "command" && item.mode === "plan",
);
expect(suggestion).toBeTruthy();
const nextDraft = applyComposerSuggestion({
draft: "/pl",
suggestion: suggestion!,
selectedWorkPackage,
});
expect(nextDraft).toBe("@SRS plan ");
expect(parseCommand(nextDraft, workPackages).parsed.mode).toBe("plan");
});
});