Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

1.5 KB
Raw Blame
import { describe, expect, it } from "vitest";
import {
  formatAskToolOutput,
  isAskToolQuestionWithinLimit,
  MAX_ASK_TOOL_QUESTION_CHARS,
  type AskToolQuestion,
} from "./types.js";

describe("asktool output", () => {
  const questions: AskToolQuestion[] = [
    { question: "Preferred color?", options: ["Blue", "Green"] },
    {
      question: "Which platforms?",
      options: [
        { label: "**Web**", description: "Runs in a browser." },
        { label: "Desktop", description: "Installs on the user's computer." },
      ],
      multiSelect: true,
    },
  ];

  it("serializes each question with selected answers and a stable separator", () => {
    expect(formatAskToolOutput(questions, [["Blue"], ["**Web**", "Desktop"]])).toBe(
      "Preferred color?:Blue\n---\nWhich platforms?:**Web**、Desktop",
    );
  });

  it("keeps skipped answers as empty placeholders", () => {
    expect(formatAskToolOutput(questions, [null, ["Desktop"]])).toBe(
      "Preferred color?:\n---\nWhich platforms?:Desktop",
    );
  });

  it("limits questions to 300 Unicode characters", () => {
    expect(isAskToolQuestionWithinLimit("q".repeat(MAX_ASK_TOOL_QUESTION_CHARS))).toBe(true);
    expect(isAskToolQuestionWithinLimit("q".repeat(MAX_ASK_TOOL_QUESTION_CHARS + 1))).toBe(false);
    expect(isAskToolQuestionWithinLimit("🧭".repeat(MAX_ASK_TOOL_QUESTION_CHARS))).toBe(true);
    expect(isAskToolQuestionWithinLimit("🧭".repeat(MAX_ASK_TOOL_QUESTION_CHARS + 1))).toBe(false);
  });
});