Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2import { parsePiSessionCommand } from "./piSessionCommands.ts";
3
4describe("Pi session command parsing", () => {
5 it("recognizes standalone utilities and an export path with spaces", () => {
6 expect(parsePiSessionCommand(" /copy ")).toEqual({ command: "copy" });
7 expect(parsePiSessionCommand("/share")).toEqual({ command: "share" });
8 expect(parsePiSessionCommand("/export")).toEqual({ command: "export" });
9 expect(parsePiSessionCommand("/export reports/my session.html")).toEqual({
10 command: "export",
11 outputPath: "reports/my session.html",
12 });
13 });
14
15 it("rejects arguments to no-argument commands instead of treating them as prompts", () => {
16 expect(parsePiSessionCommand("/copy this")).toEqual({
17 error: "/copy does not accept arguments.",
18 });
19 expect(parsePiSessionCommand("/share this")).toEqual({
20 error: "/share does not accept arguments.",
21 });
22 expect(parsePiSessionCommand("/copy\nExplain this")).toEqual({
23 error: "/copy does not accept arguments.",
24 });
25 expect(parsePiSessionCommand("/export\nthen explain")).toEqual({
26 error: "/export accepts a path on a single line.",
27 });
28 });
29
30 it("leaves prose and unrecognized commands as prompts", () => {
31 for (const prompt of ["please /copy", "/exporter", "/copying"]) {
32 expect(parsePiSessionCommand(prompt)).toBeNull();
33 }
34 });
35});