File size: 1,949 Bytes
837e3ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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");
  });
});