repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

extensions/ui/__tests__/composer.test.ts

Raw
File outline
import { describe, expect, it } from "vitest";
import { parseComposerInput } from "../composer";

describe("ui composer parser", () => {
	it("parses plain prompts", () => {
		expect(parseComposerInput("hello pi")).toEqual({
			kind: "prompt",
			text: "hello pi",
			refs: [],
		});
	});

	it("parses slash commands and arguments", () => {
		expect(parseComposerInput("/mode terse now")).toEqual({
			kind: "slash",
			command: "mode",
			args: "terse now",
			text: "/mode terse now",
			refs: [],
		});
	});

	it("parses skill commands", () => {
		expect(parseComposerInput("/skill:brutal make it short")).toEqual({
			kind: "slash",
			command: "skill:brutal",
			args: "make it short",
			text: "/skill:brutal make it short",
			refs: [],
		});
	});

	it("extracts at-references from prompts", () => {
		expect(
			parseComposerInput("read @README.md and @docs/spec.md please"),
		).toEqual({
			kind: "prompt",
			text: "read @README.md and @docs/spec.md please",
			refs: ["README.md", "docs/spec.md"],
		});
	});

	it("parses single-bang bash", () => {
		expect(parseComposerInput("!git status --short")).toEqual({
			kind: "bash",
			command: "git status --short",
			excludeFromContext: false,
			refs: [],
		});
	});

	it("parses double-bang bash as excluded from context", () => {
		expect(parseComposerInput("!!node --version")).toEqual({
			kind: "bash",
			command: "node --version",
			excludeFromContext: true,
			refs: [],
		});
	});
});