Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

5.2 KB
Raw Blame
import fs from "node:fs";
import path from "node:path";
import { describe, expect, it } from "vitest";

const root = path.resolve(__dirname, "..");
const cli = fs.readFileSync(path.join(root, "bin/mso"), "utf8");
const commandOwner = fs.readFileSync(path.join(root, "scripts/cli/commands.sh"), "utf8");
const agentCli = fs.readFileSync(
  path.join(__dirname, "mso-cli-agent.sh"),
  "utf8",
);
const providerCatalogCli = fs.readFileSync(
  path.join(root, "scripts/cli/ai-provider-catalog.sh"),
  "utf8",
);
const providerAuthCli = fs.readFileSync(
  path.join(root, "scripts/cli/ai-provider-auth.sh"),
  "utf8",
);
// The handler body moved to a colocated handler.ts when route.ts became a thin
// adapter (Phase 2). These two assertions are about the request-parsing logic, so
// they read the file that actually owns it; pointing them at route.ts would only
// ever match its import lines.
const configRoute = fs.readFileSync(
  path.join(root, "app/api/config/handler.ts"),
  "utf8",
);
const oauthRoute = fs.readFileSync(
  path.join(root, "app/api/oauth/[provider]/handler.ts"),
  "utf8",
);
const slash = fs.readFileSync(
  path.join(__dirname, "mso-agent-slash.mjs"),
  "utf8",
);
const picker = fs.readFileSync(
  path.join(__dirname, "mso-tui-select.mjs"),
  "utf8",
);

const all = [cli, commandOwner, agentCli, providerCatalogCli, providerAuthCli, configRoute, oauthRoute, slash, picker].join("\n");

describe("MSO model/provider/session CLI contract", () => {
  it("keeps provider auth (`models`) separate from active selection (`model`)", () => {
    expect(cli).toContain('VERSION="1.13.1"');
    expect(cli).toContain("models *             Configure AI providers/auth");
    expect(cli).toContain("model [ref]          Select active model");
    expect(agentCli).toContain("run_models()");
    expect(agentCli).toContain("run_model_setup()");
    expect(agentCli).toContain("provider_key_body_unselected");
    expect(agentCli).toContain("custom_provider_body_unselected");
    expect(providerAuthCli).toContain("configure_ai_provider()");
    expect(all).toContain("select:false");
    expect(configRoute).toContain("body.select !== false");
    expect(oauthRoute).toContain("body.select === true");
    expect(oauthRoute).not.toContain("body.select !== false");
    expect(slash).toMatch(/text:\s*"\/models"[\s\S]{0,120}meta:\s*"Configure AI providers and authentication"/);
    expect(slash).toMatch(/text:\s*"\/model"[\s\S]{0,120}meta:\s*"Select the active model from connected providers"/);
  });

  it("uses one native arrow-key picker instead of numeric provider/model prompts", () => {
    expect(agentCli).toContain('tui_select "Select AI provider"');
    expect(agentCli).toContain('tui_select "Select model · $provider"');
    expect(agentCli).toContain('tui_select "AI provider/auth manager"');
    expect(agentCli).not.toContain("Provider [1]:");
    expect(agentCli).not.toContain("Model [1]:");
    expect(agentCli).not.toContain("choose a provider number");
    expect(agentCli).not.toContain("choose a model number");
    expect(picker).toContain(
      "↑↓ navigate · type filter · Enter select · Esc cancel",
    );
    expect(picker).toContain("nextPickerIndex");
  });

  it("shares a dynamic free-provider catalog between connect and model discovery", () => {
    expect(providerCatalogCli).toContain('jget "/api/models/providers"');
    expect(agentCli).toContain('tui_select "Connect AI platform"');
    expect(agentCli).toContain('free) print_free_ai_options');
    expect(providerCatalogCli).toContain('FREE · ');
    expect(providerCatalogCli).toContain('provider account/key and rate limits may still apply');
  });

  it("adds providers hermes-style: non-interactive flags plus a status <provider> probe", () => {
    expect(providerAuthCli).toContain("usage_models_add()");
    expect(providerAuthCli).toContain("--api-key <key>");
    expect(providerAuthCli).toContain("--type api-key|oauth");
    expect(agentCli).toContain('case "$sub" in\n    -h|--help|help) usage_models_add');
    // Picker must not use fs.readFileSync(0): a non-blocking pipe throws EAGAIN.
    expect(picker).toContain("readStdinSync");
    expect(picker).not.toContain("readFileSync(0");
  });

  it("supports explicit and slash-containing model IDs without losing provider intent", () => {
    expect(agentCli).toContain("Model IDs themselves may contain slashes");
    expect(agentCli).toContain("mso model set <provider> <model>");
    expect(agentCli).toContain("any(.models[]?; .id==$id)");
    expect(agentCli).toContain('select_model_ref "$2/$3"');
  });

  it("makes durable session continuation a first-class CLI startup path", () => {
    expect(cli).toContain("--continue|-c");
    expect(cli).toContain("--resume|-r");
    expect(cli).toContain('AGENT_START_ARGS+=("--continue")');
    expect(cli).toContain('AGENT_START_ARGS+=("--resume" "$2")');
    expect(slash).toContain('text: "/resume"');
    expect(slash).toContain('text: "/status"');
  });

  it("accepts yolo as a global Agent startup flag instead of treating it as a command", () => {
    expect(cli).toContain('--yolo|-yolo) AGENT_START_ARGS+=("--yolo")');
    expect(commandOwner).toContain(
      "agent [--continue|-c|--resume|-r <latest|index|id|title>|--yolo|-yolo]",
    );
  });
});