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.

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

const CORE = path.join(__dirname, "../scripts/install-core.sh");
const PHASES = ["cli.sh", "runtime-build.sh", "service.sh", "finalize.sh"].map((name) =>
  path.join(__dirname, "../scripts/install", name),
);
const README = fs.readFileSync(path.join(__dirname, "../README.md"), "utf8");
const INSTALL = fs.readFileSync(path.join(__dirname, "../docs/INSTALL.md"), "utf8");
const AGENTS = fs.readFileSync(path.join(__dirname, "../AGENTS.md"), "utf8");
const core = [CORE, ...PHASES].map((file) => fs.readFileSync(file, "utf8")).join("\n");
const help = execFileSync("bash", [CORE, "--help"], { encoding: "utf8" });

function publicFlags() {
  return help.split("\n")
    .filter((line) => /^  -/.test(line))
    .flatMap((line) => line.match(/--?[a-z][a-z-]*/g) ?? []);
}

function publicEnv() {
  return help.match(/^Env:\s+(.+)$/m)?.[1].match(/MSO_[A-Z0-9_]+/g) ?? [];
}

describe("installer documentation contract", () => {
  it("keeps full installer options in INSTALL.md and the overview linked", () => {
    expect(publicFlags().length).toBeGreaterThan(5);
    expect(publicEnv().length).toBeGreaterThan(3);
    for (const token of [...publicFlags(), ...publicEnv()]) {
      expect(INSTALL, `INSTALL.md missing ${token}`).toContain(token);
    }
    expect(README).toContain("./docs/INSTALL.md");
    expect(README.split("\n").length).toBeLessThanOrEqual(120);
  });

  it("documents one AI-agent path and the legacy-upgrade bridge", () => {
    for (const doc of [README, INSTALL, AGENTS]) {
      expect(doc).toContain("mso doctor");
      expect(doc).toContain("mso update");
      expect(doc).toContain("scripts/install.sh");
    }
    expect(README).toContain("Install or update MSO from this repo");
    expect(INSTALL).toContain("Upgrading an older MSO install");
  });

  it("keeps the installer backward-compatible with an existing service checkout", () => {
    const detect = core.indexOf('systemctl show -p WorkingDirectory --value "$SERVICE"');
    const fresh = core.indexOf('[ -d "$DIR/.git" ] || FRESH_INSTALL=1');
    const checkout = core.indexOf("INSTALL_PHASE=checkout");
    expect(detect).toBeGreaterThan(0);
    expect(detect).toBeLessThan(fresh);
    expect(detect).toBeLessThan(checkout);
    expect(core).toContain('info "found existing service → updating $DIR"');
    expect(core).toContain('if [ ! -f .env.local ]; then');
    expect(core).toContain('OS_LOGIN_PASSWORD=$GEN_PW');
    expect(core).toContain('OS_SESSION_SECRET=$SECRET');
    expect(core).toContain('OS_MCP_ENABLED=1');
    expect(core).toContain('OS_MCP_MAX_SCOPE=exec');
    expect(core).toContain('chmod 600 .env.local');
    expect(core).toContain('.env.local exists — left untouched (existing secrets preserved)');
  });

  it("documents the safe fresh-install MCP and stable-origin defaults", () => {
    expect(INSTALL).toContain("OS_MCP_ENABLED=1");
    expect(INSTALL).toContain("OS_MCP_MAX_SCOPE=exec");
    expect(INSTALL).toContain("mso gateway domain set https://mso.example.com");
    expect(INSTALL).toContain("http://127.0.0.1:4005");
    expect(INSTALL).toContain("cfargotunnel.com");
    expect(INSTALL).toContain("DNS-only");
    expect(INSTALL).not.toMatch(/OS_PUBLIC_ORIGIN=https:\/\/[A-Za-z0-9-]+\.trycloudflare\./);
  });

  it("prints modern update surfaces plus a legacy fallback after installation", () => {
    expect(core).toContain("Update:    mso update");
    expect(core).toContain("Settings → Update MSO");
    expect(core).toContain("Legacy:    re-run the official one-line installer");
    expect(core).toContain('ok "mso updated at $DIR"');
    const pairing = core.indexOf("Pair your first device after the API is running");
    const freshGuard = core.lastIndexOf('if [ "$FRESH_INSTALL" -eq 1 ]; then', pairing);
    expect(freshGuard).toBeGreaterThan(0);
  });
});