// docker/demo.sh (demo epic D5), against a STUB `docker` on PATH that records // every call and, unless told to play along, fails any call that would change // something (up, build, pull, exec, down). No real docker, no network but a // loopback fake of the host's ollama, nothing outside a temp dir. // // Run with: pnpm test:scripts import assert from "node:assert/strict"; import test from "node:test"; import { spawn, spawnSync } from "node:child_process"; import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, statSync, symlinkSync, writeFileSync } from "node:fs"; import http from "node:http"; import os from "node:os"; import path from "node:path"; const SCRIPT = path.join(import.meta.dirname, "..", "docker", "demo.sh"); // The shell demo.sh runs under (DEMO_TEST_SHELL: dash, busybox — the review runs it under each). const SH = process.env.DEMO_TEST_SHELL || "/bin/sh"; const START = path.join(import.meta.dirname, "..", "docker", "ollama-start.sh"); const ROOT = mkdtempSync(path.join(os.tmpdir(), "demo-sh-")); test.after(() => rmSync(ROOT, { recursive: true, force: true })); // The stub. Read-only probes answer; anything else is FORBIDDEN (exit 99) // unless STUB_PERMISSIVE, when it is recorded and succeeds — `logs` and // `ollama list` answer as a running stack would. const BIN = path.join(ROOT, "bin"); mkdirSync(BIN); writeFileSync( path.join(BIN, "docker"), `#!/bin/sh printf '%s\\n' "$*" >> "$STUB_LOG" case "$*" in info) [ -n "\${STUB_DENIED:-}" ] && { echo "permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock" >&2; exit 1; }; [ -n "\${STUB_NO_DAEMON:-}" ] && exit 1; exit 0 ;; *" ps -aq") { [ -n "\${STUB_RUNNING:-}" ] || [ -n "\${STUB_EXISTS:-}" ]; } && echo c0ffee; exit 0 ;; "info --format {{.DockerRootDir}}") echo /var/lib/docker; exit 0 ;; "compose version --short") [ -n "\${STUB_NO_COMPOSE:-}" ] && exit 1; echo "\${STUB_COMPOSE:-2.29.1}"; exit 0 ;; "version --format {{.Server.Version}}") echo 27.3.1; exit 0 ;; *" ps -q caddy") [ -n "\${STUB_RUNNING:-}" ] && echo c0ffee; exit 0 ;; "image inspect "*) [ -n "\${STUB_IMAGES:-}" ] && exit 0; exit 1 ;; esac if [ -n "\${STUB_PERMISSIVE:-}" ]; then case "$*" in *" up -d") [ -n "\${STUB_ENV_DUMP:-}" ] && printf '%s %s %s %s\\n' "\${SITE_BIND-unset}" "\${EDITOR_BIND-unset}" "\${HOMEPAGE_BIND-unset}" "\${UMTOOL_BIND-unset}" > "\${STUB_ENV_DUMP}" ;; esac if [ -n "\${STUB_FAIL:-}" ]; then case "$*" in *"\${STUB_FAIL}"*) echo "Error: stub says no" >&2; exit 1 ;; esac fi case "$*" in *" logs "*) echo 'time=x level=INFO source=types.go:60 msg="inference compute" id=0 library=Vulkan name=Vulkan0 description="AMD Radeon RX 6600 XT (RADV NAVI23)" type=discrete total="8.0 GiB" available="7.0 GiB"' ;; *"exec -T ollama ollama list"*) printf 'NAME ID SIZE MODIFIED\\n%s abc 4.7GB now\\n' "\${STUB_HAS_MODEL:-none}" ;; *"exec -T editor test -x /usr/lib/ollama/llama-server"*) exit 1 ;; *"exec -T editor test -e"*) exit 1 ;; *"exec -T ollama printenv OLLAMA_NO_CLOUD"*) echo "\${STUB_NO_CLOUD:-1}" ;; esac exit 0 fi echo "FORBIDDEN $*" >> "$STUB_LOG" exit 99 `, ); chmodSync(path.join(BIN, "docker"), 0o755); let n = 0; function fixture({ ramGb = 16, freeGb = 80, dri = true } = {}) { const dir = path.join(ROOT, `case-${++n}`); mkdirSync(path.join(dir, "dri"), { recursive: true }); if (dri) writeFileSync(path.join(dir, "dri", "renderD128"), ""); writeFileSync(path.join(dir, "meminfo"), `MemTotal: ${ramGb * 1048576} kB\nMemFree: 1 kB\n`); return { dir, log: path.join(dir, "docker.log"), env: path.join(dir, ".env.demo"), freeKb: String(freeGb * 1048576) }; } // The tools the script needs, and NOT docker: a PATH for "docker is not installed". const TOOLS = path.join(ROOT, "tools"); mkdirSync(TOOLS); for (const t of ["sh", "dirname", "sed", "tail", "head", "grep", "awk", "cat", "tr", "od", "cut", "chmod", "mv", "curl"]) { const where = spawnSync("sh", ["-c", `command -v ${t}`], { encoding: "utf8" }).stdout.trim(); if (where) symlinkSync(where, path.join(TOOLS, t)); } function envOf(f, extra) { return { PATH: `${BIN}:${process.env.PATH}`, HOME: f.dir, STUB_LOG: f.log, DEMO_ENV_FILE: f.env, DEMO_TEST_DRI_DIR: path.join(f.dir, "dri"), DEMO_TEST_MEMINFO: path.join(f.dir, "meminfo"), DEMO_TEST_FREE_KB: f.freeKb, DEMO_TEST_BUSY_PORTS: "", // A closed port: no host ollama answers unless a test starts one. DEMO_HOST_OLLAMA_URL: "http://127.0.0.1:9", ...extra, }; } function callsOf(f) { return existsSync(f.log) ? readFileSync(f.log, "utf8").trim().split("\n").filter(Boolean) : []; } function demo(args, f, extra = {}) { rmSync(f.log, { force: true }); const res = spawnSync(SH, [SCRIPT, ...args], { encoding: "utf8", env: envOf(f, extra) }); return { code: res.status, out: res.stdout, err: res.stderr, calls: callsOf(f) }; } // The same, without blocking the event loop (a test's own server must answer). function demoAsync(args, f, extra = {}) { rmSync(f.log, { force: true }); return new Promise((resolve) => { const child = spawn(SH, [SCRIPT, ...args], { env: envOf(f, extra) }); let out = ""; let err = ""; child.stdout.on("data", (d) => (out += d)); child.stderr.on("data", (d) => (err += d)); child.on("close", (code) => resolve({ code, out, err, calls: callsOf(f) })); }); } const forbidden = (calls) => calls.filter((c) => c.startsWith("FORBIDDEN")); test("up --dry-run: the plan, in plain lines; nothing written, nothing changed", () => { const f = fixture(); const r = demo(["up", "--dry-run"], f); assert.equal(r.code, 0, r.err); assert.deepEqual(forbidden(r.calls), []); assert.equal(existsSync(f.env), false, "no .env.demo"); const lines = r.out.split("\n"); assert.equal(lines[0], "demo: dry run: only read-only probes — docker version and info, df, /proc/meminfo, /dev/dri, the listening ports, and GET http://127.0.0.1:9/api/ps (a host ollama, if one answers); nothing is written, built, pulled or started"); assert.match(lines[1], /^demo: docker 27\.3\.1, compose v2\.29\.1 · 16 GB RAM · 80 GB free · ok$/); assert.match(r.out, /demo: GPU: .*renderD128 found -> will ask ollama for Vulkan/); assert.match(r.out, /demo: model qwen2\.5:7b: pulled unless ollama already has it \(once, 4\.7 GB\)/); assert.match(r.out, /demo: archive https:\/\/jeralyzer\.pages\.dev · model qwen2\.5:7b · LOCAL ONLY \(the Claude API is refused\)/); assert.match(r.out, /would write .*\.env\.demo \(mode 600, a new WORKER_TOKEN\)/); const compose = "docker compose -p archilyzer-demo --env-file " + f.env + " -f docker-compose.yml -f docker-compose.demo.yml -f docker-compose.ollama-vulkan.yml --profile umtool --profile ollama"; for (const tail of ["build editor umtool", "up -d", "exec -T ollama ollama pull qwen2.5:7b", "exec -T editor pnpm --silent archilyzer gen preset local", "exec -T editor pnpm --silent archilyzer gen model local qwen2.5:7b", "exec -T editor pnpm --silent archilyzer gen model extractor qwen2.5:7b"]) { assert.ok(r.out.includes(` would run: ${compose} ${tail}\n`), `${tail}\n${r.out}`); } assert.doesNotMatch(r.out, /anthropic/, "the Claude API overlay is never part of it"); assert.match(r.out, /demo: dry run: nothing was written, built, pulled or started\n$/); }); test("up --dry-run with the flags: another archive and model, no GPU, images present, other ports", () => { const f = fixture({ dri: false }); const r = demo(["up", "--dry-run", "--archive", "https://example.org/corpus.json", "--model", "qwen3:8b", "--gpu", "none", "--editor-port", "18081", "--umtool-port", "18083"], f, { STUB_IMAGES: "1", DEMO_TEST_IMAGES_PRESENT: "1" }); assert.equal(r.code, 0, r.err); assert.deepEqual(forbidden(r.calls), []); assert.match(r.out, /archive https:\/\/example\.org · model qwen3:8b/); assert.match(r.out, /GPU: none -> ollama will run on the CPU/); assert.match(r.out, /model qwen3:8b: pulled unless ollama already has it \(once, 5\.2 GB\)/); assert.match(r.out, /images: archilyzer:demo and archilyzer:demo-umtool present/); assert.doesNotMatch(r.out, /build editor umtool/); assert.doesNotMatch(r.out, /ollama-vulkan|ollama-nvidia/); assert.match(r.out, /gen model local qwen3:8b/); }); test("each missing prerequisite: one sentence, exit 1, nothing changed", () => { const cases = [ [{ PATH: TOOLS }, /^demo: docker is not installed — install Docker Engine \(or Docker Desktop\) and run this again\.\n$/], [{ STUB_NO_DAEMON: "1" }, /^demo: the docker daemon is not answering — start it \(sudo systemctl start docker\) and run this again\.\n$/], [{ STUB_NO_COMPOSE: "1" }, /^demo: docker compose v2 is missing — install the compose plugin \(docker-compose v1 is not enough\) and run this again\.\n$/], [{ STUB_COMPOSE: "2.20.3" }, /^demo: docker compose 2\.20\.3 is too old — the demo needs compose v2\.24 or newer\.\n$/], [{ DEMO_TEST_BUSY_PORTS: "8083" }, /^demo: port 8083 is already taken on this machine — pick another with --umtool-port \.\n$/], ]; for (const [env, msg] of cases) { const f = fixture(); const r = demo(["up"], f, env); assert.equal(r.code, 1, `${JSON.stringify(env)}: ${r.out}${r.err}`); assert.match(r.err, msg); assert.deepEqual(forbidden(r.calls), []); assert.equal(existsSync(f.env), false); } const small = fixture({ ramGb: 8 }); const ram = demo(["up"], small); assert.equal(ram.code, 1); assert.match(ram.err, /^demo: this machine has 8 GB of RAM; the demo needs at least 12 GB \(a 7B model, the editor and a render\)\.\n$/); const full = fixture({ freeGb: 10 }); const disk = demo(["up"], full); assert.equal(disk.code, 1); assert.match(disk.err, /^demo: 10 GB is free where docker keeps its images; the demo needs 25 GB/); for (const [args, msg] of [ [["up", "--model", "gpt-oss:120b-cloud"], /an ollama CLOUD model — the demo runs local models only/], [["up", "--model", "claude-sonnet-5-5"], /a Claude model — the demo runs local models only/], [["up", "--gpu", "rocm"], /--gpu is auto, vulkan, nvidia or none/], [["up", "--editor-port", "80x"], /a port is a number/], [["up", "--archive", "ftp://x"], /--archive is not an http\(s\) URL/], [["down", "--model", "x"], /only up takes/], [["up", "--volumes"], /only down takes --volumes/], [["launch"], /unknown command "launch"/], [["up", "--fast"], /unknown flag "--fast"/], ]) { const f = fixture(); const r = demo(args, f); assert.equal(r.code, 1, args.join(" ")); assert.match(r.err, msg); assert.equal(r.err.trim().split("\n").length, 1, "one sentence"); } }); test("a host ollama with a model loaded is a WARNING, never a refusal (asked with GET /api/ps)", async () => { const asked = []; const server = http.createServer((req, res) => { asked.push(`${req.method} ${req.url}`); res.setHeader("content-type", "application/json"); res.end(JSON.stringify({ models: [{ name: "qwen3:8b", model: "qwen3:8b", size: 1 }] })); }); await new Promise((ok) => server.listen(0, "127.0.0.1", ok)); const url = `http://127.0.0.1:${server.address().port}`; try { const f = fixture(); const r = await demoAsync(["up", "--dry-run"], f, { DEMO_HOST_OLLAMA_URL: url }); assert.equal(r.code, 0, r.err); assert.match(r.out, new RegExp(`demo: WARNING: a host ollama at ${url} has qwen3:8b loaded — two servers would share the GPU`)); } finally { server.close(); } assert.deepEqual(asked, ["GET /api/ps"]); }); test("up for real (the stub plays along): .env.demo written once, mode 600; a re-run reuses the token and changes nothing", () => { const f = fixture(); const play = { STUB_PERMISSIVE: "1" }; const first = demo(["up"], f, play); assert.equal(first.code, 0, first.err + first.out); const env = readFileSync(f.env, "utf8"); assert.equal(statSync(f.env).mode & 0o777, 0o600); const token = /^WORKER_TOKEN=([0-9a-f]{48})$/m.exec(env)?.[1]; assert.ok(token, env); assert.ok(!first.out.includes(token) && !first.err.includes(token), "the token is never printed"); assert.match(env, /^DEMO_ARCHIVE=https:\/\/jeralyzer\.pages\.dev$/m); assert.match(env, /^ARCHILYZER_TAG=demo$/m); assert.match(env, /^DEMO_OLLAMA_MEM=6g$/m, "40% of 16 GB"); assert.match(first.out, /demo: ollama: GPU Vulkan, AMD Radeon RX 6600 XT \(RADV NAVI23\) 8\.0 GiB/); assert.match(first.out, /demo: voice: Orpheus is not available in this image \(it carries no llama-server\)/); assert.match(first.out, /demo: ready\. umtool http:\/\/localhost:8083\/research · editor http:\/\/localhost:8081/); const order = first.calls.map((c) => c.replace(/^compose -p archilyzer-demo --env-file \S+ -f docker-compose\.yml -f docker-compose\.demo\.yml -f docker-compose\.ollama-vulkan\.yml --profile umtool --profile ollama /, "C ")); const want = ["C build editor umtool", "C up -d", "C exec -T ollama ollama pull qwen2.5:7b", "C exec -T editor pnpm --silent archilyzer gen preset local", "C exec -T editor pnpm --silent archilyzer gen model local qwen2.5:7b"]; let at = 0; for (const w of want) { const i = order.indexOf(w, at); assert.ok(i >= at, `${w} after ${want[want.indexOf(w) - 1]}\n${order.join("\n")}`); at = i; } assert.ok(!first.calls.some((c) => / down/.test(c) || /-v\b/.test(c))); const again = demo(["up"], f, { ...play, STUB_RUNNING: "1", STUB_IMAGES: "1", STUB_HAS_MODEL: "qwen2.5:7b", DEMO_TEST_BUSY_PORTS: "8080 8081 8082 8083" }); assert.equal(again.code, 0, again.err); assert.match(again.out, /choices: .*\.env\.demo unchanged/); assert.match(again.out, /images: archilyzer:demo and archilyzer:demo-umtool present/); assert.match(again.out, /model qwen2\.5:7b: present/); assert.ok(!again.calls.some((c) => / build | pull /.test(c)), again.calls.join("\n")); assert.equal(readFileSync(f.env, "utf8"), env, "the same file, the same token"); // A flag changes its line, and only that. const model = demo(["up", "--model", "qwen3:8b"], f, { ...play, STUB_RUNNING: "1", STUB_IMAGES: "1" }); assert.equal(model.code, 0, model.err); assert.match(readFileSync(f.env, "utf8"), /^DEMO_MODEL=qwen3:8b$/m); assert.match(readFileSync(f.env, "utf8"), new RegExp(`^WORKER_TOKEN=${token}$`, "m")); }); test("down keeps the volumes unless --volumes; it stops the project with or without .env.demo; nothing there is nothing to stop", () => { const none = fixture(); const empty = demo(["down"], none); assert.equal(empty.code, 0); assert.match(empty.out, /nothing to stop: no archilyzer-demo containers on this machine/); assert.deepEqual(forbidden(empty.calls), []); const f = fixture(); writeFileSync(f.env, "WORKER_TOKEN=x\n"); const keep = demo(["down"], f, { STUB_PERMISSIVE: "1", STUB_EXISTS: "1" }); assert.equal(keep.code, 0, keep.err); assert.match(keep.out, /volumes kept; --volumes deletes them/); const downs = keep.calls.filter((c) => / down/.test(c)); assert.equal(downs.length, 1); assert.match(downs[0], / down$/); const wipe = demo(["down", "--volumes"], f, { STUB_PERMISSIVE: "1", STUB_EXISTS: "1" }); assert.match(wipe.out, /AND deleting its volumes/); assert.ok(wipe.calls.some((c) => / down -v$/.test(c))); const dry = demo(["down", "--volumes", "--dry-run"], f, { STUB_EXISTS: "1" }); assert.deepEqual(forbidden(dry.calls), []); assert.match(dry.out, /would run: docker compose .* down -v/); // .env.demo deleted while the stack runs (S8): it is still stopped, no --env-file. const lost = fixture(); const gone = demo(["down"], lost, { STUB_PERMISSIVE: "1", STUB_EXISTS: "1" }); assert.equal(gone.code, 0, gone.err); const d = gone.calls.filter((c) => / down$/.test(c)); assert.equal(d.length, 1); assert.ok(d[0].startsWith("compose -p archilyzer-demo -f docker-compose.yml"), d[0]); }); test("check: exit 1 when ollama runs without OLLAMA_NO_CLOUD; refused when the demo is not running", () => { const f = fixture(); writeFileSync(f.env, "WORKER_TOKEN=x\n"); const ok = demo(["check"], f, { STUB_PERMISSIVE: "1", STUB_RUNNING: "1" }); assert.equal(ok.code, 0, ok.err + ok.out); assert.match(ok.out, /LOCAL ONLY: yes/); assert.ok(ok.calls.some((c) => /exec -T editor pnpm --silent archilyzer gen local-check$/.test(c))); const bad = demo(["check"], f, { STUB_PERMISSIVE: "1", STUB_RUNNING: "1", STUB_NO_CLOUD: "0" }); assert.equal(bad.code, 1); assert.match(bad.out, /check: FAIL ollama runs without OLLAMA_NO_CLOUD=1/); assert.match(bad.err, /LOCAL ONLY: NOT proven/); const down = demo(["check"], f); assert.equal(down.code, 1); assert.match(down.err, /^demo: the demo is not running — start it with \.\/docker\/demo\.sh up first\.\n$/); }); test("voice: says plainly what is missing when the image has no llama-server", () => { const f = fixture(); writeFileSync(f.env, "WORKER_TOKEN=x\n"); const r = demo(["voice"], f, { STUB_PERMISSIVE: "1", STUB_RUNNING: "1" }); assert.equal(r.code, 1); assert.match(r.err, /^demo: Orpheus needs a llama-server inside the editor image, and this image has none \(\/usr\/lib\/ollama\/llama-server is missing\)/); assert.ok(!r.calls.some((c) => /tts setup --engine orpheus$/.test(c)), "nothing installed"); }); test("ollama-start.sh: one honest gpu line, then ollama serve", () => { const dri = path.join(ROOT, "start-dri"); mkdirSync(dri, { recursive: true }); const run = (env) => spawnSync("sh", [START], { encoding: "utf8", env: { PATH: process.env.PATH, OLLAMA_START_DRI_DIR: dri, OLLAMA_START_BIN: "echo", ...env } }); const none = run({}); assert.match(none.stdout, /\[ollama\] gpu: {8}NONE in this container — models run on the CPU/); assert.match(none.stdout, /\nserve\n$/, "execs ` serve`"); writeFileSync(path.join(dri, "renderD128"), ""); const off = run({}); assert.match(off.stdout, /renderD128 passed through, but OLLAMA_VULKAN is not 1/); const on = run({ OLLAMA_VULKAN: "1", OLLAMA_NO_CLOUD: "1", LLAMA_ARG_CACHE_RAM: "1024" }); assert.match(on.stdout, /renderD128 passed through, OLLAMA_VULKAN=1/); assert.match(on.stdout, /cloud: {6}OLLAMA_NO_CLOUD=1/); assert.match(on.stdout, /prompt cache 1024 MiB/); }); test("entrypoint: ARCHILYZER_LOCAL_ONLY read as localOnlyFlag reads it; a value it does not understand is an ERROR line, never silent (S7)", (t) => { // The entrypoint is bash (the app image's); an image without bash skips this. if (!spawnSync("sh", ["-c", "command -v bash"], { encoding: "utf8" }).stdout.trim()) return t.skip("no bash here"); const ENTRY = path.join(import.meta.dirname, "..", "docker", "entrypoint.sh"); const fn = readFileSync(ENTRY, "utf8").match(/^local_only_line\(\) \{[\s\S]*?^\}$/m)?.[0]; assert.ok(fn, "local_only_line is in the entrypoint"); const run = (v) => spawnSync("bash", ["-c", `log() { printf '[entrypoint] %s\\n' "$*"; }\n${fn}\nlocal_only_line`], { encoding: "utf8", env: { PATH: process.env.PATH, ARCHILYZER_LOCAL_ONLY: v } }); // The same table as common/lib/llm/localOnly.test.ts (localOnlyFlag). for (const v of ["1", " TRUE ", "yes", "On"]) { const r = run(v); assert.match(r.stdout, /models: {3}LOCAL ONLY/, v); assert.equal(r.stderr, "", v); } for (const v of ["", "0", "false", "NO", "off"]) { const r = run(v); assert.equal(r.stdout + r.stderr, "", JSON.stringify(v)); } for (const v of ["2", "y", "enabled", "local"]) { const r = run(v); assert.equal(r.stdout, ""); assert.equal(r.stderr, `[entrypoint] ERROR: ARCHILYZER_LOCAL_ONLY=${v} is not understood — the guard is OFF (1, true, yes or on turns it on)\n`, v); } }); // ─── review round 1 ─── test("M1: --archive cannot inject a line: a newline, a space, a quote, $, a backtick or # is refused in one line, nothing written", () => { for (const bad of ["https://x.example\nEDITOR_BIND=0.0.0.0", "https://x.example EDITOR_BIND=0.0.0.0", 'https://x.example"', "https://x.example/$HOME", "https://x.example/`id`", "https://x.example/#frag", "https://x.example/\r"]) { const f = fixture(); const r = demo(["up", "--archive", bad], f, { STUB_PERMISSIVE: "1" }); assert.equal(r.code, 1, JSON.stringify(bad)); assert.equal(r.err, "demo: --archive is not a single-line http(s) URL of URL characters (letters, digits and - . _ ~ : / ? = & % + @ ,).\n", JSON.stringify(bad)); assert.equal(existsSync(f.env), false); assert.deepEqual(r.calls.filter((c) => / up -d| build /.test(c)), []); } const ok = demo(["up", "--dry-run", "--archive", "https://archive.example/sub/path?x=1&y=2"], fixture()); assert.equal(ok.code, 0, ok.err); }); test("M1: a hand-edited .env.demo — a bind off loopback, a key demo.sh does not write, a bad value — is refused before compose reads it", () => { const cases = [ ["WORKER_TOKEN=tok\nEDITOR_BIND=0.0.0.0\n", /^demo: \S+\.env\.demo sets EDITOR_BIND to something other than 127\.0\.0\.1, which would publish a port beyond this machine — the demo binds 127\.0\.0\.1 only; remove that line\.\n$/], ["WORKER_TOKEN=tok\nUMTOOL_BIND=192.168.1.9\n", /sets UMTOOL_BIND to something other than 127\.0\.0\.1/], ["WORKER_TOKEN=tok\nUMTOOL_ALLOWED_HOSTS=evil.example\n", /^demo: line 2 of \S+ sets a key demo\.sh does not write — remove it, or delete \S+ to start again\.\n$/], ["WORKER_TOKEN=tok\nDEMO_ARCHIVE=https://x.example/$(id)\n", /line 2 of \S+ \(DEMO_ARCHIVE\) holds a character no demo value has/], ["garbage\n", /line 1 of \S+ is not KEY=value/], ]; for (const [text, msg] of cases) { for (const verb of ["up", "down", "status", "check"]) { const f = fixture(); writeFileSync(f.env, text); const r = demo([verb], f, { STUB_PERMISSIVE: "1", STUB_RUNNING: "1" }); assert.equal(r.code, 1, `${verb} ${JSON.stringify(text)}: ${r.out}`); assert.match(r.err, msg, verb); assert.deepEqual(r.calls.filter((c) => c.startsWith("compose")), [], `${verb}: compose never ran`); } } // A bind of 127.0.0.1 is allowed. const f = fixture(); writeFileSync(f.env, "WORKER_TOKEN=tok\nEDITOR_BIND=127.0.0.1\n"); assert.equal(demo(["up", "--dry-run"], f).code, 0); }); test("M1: a bind off loopback in this shell is refused; compose is always handed 127.0.0.1 for every bind", () => { const f = fixture(); const r = demo(["up"], f, { STUB_PERMISSIVE: "1", EDITOR_BIND: "0.0.0.0" }); assert.equal(r.code, 1); assert.equal(r.err, "demo: EDITOR_BIND is set in this shell to something other than 127.0.0.1, which would publish a port beyond this machine — unset it; the demo binds 127.0.0.1 only.\n"); // The stub sees the environment compose would: 127.0.0.1 for each bind, // even with none set (compose would otherwise read .env.demo, or nothing). const g = fixture(); const binds = path.join(g.dir, "binds"); const r2 = demo(["up"], g, { STUB_PERMISSIVE: "1", STUB_IMAGES: "1", STUB_ENV_DUMP: binds }); assert.equal(r2.code, 0, r2.err); assert.equal(readFileSync(binds, "utf8"), "127.0.0.1 127.0.0.1 127.0.0.1 127.0.0.1\n"); }); test("M1: the exposure guard in the caddy container sees the bind compose publishes on (docker compose config, when docker is here)", (t) => { const real = spawnSync("sh", ["-c", "command -v docker"], { encoding: "utf8" }).stdout.trim(); if (!real) return t.skip("no docker on this machine"); const dir = mkdtempSync(path.join(ROOT, "cfg-")); const env = path.join(dir, "bind.env"); writeFileSync(env, "WORKER_TOKEN=tok\nEDITOR_BIND=0.0.0.0\n"); const repo = path.join(import.meta.dirname, ".."); const r = spawnSync(real, ["compose", "-p", "archilyzer-demo-cfgtest", "--env-file", env, "-f", "docker-compose.yml", "-f", "docker-compose.demo.yml", "--profile", "umtool", "--profile", "ollama", "config", "--format", "json"], { cwd: repo, encoding: "utf8", env: { PATH: process.env.PATH, HOME: process.env.HOME } }); if (r.status !== 0) return t.skip(`docker compose config did not run: ${r.stderr.slice(0, 200)}`); const caddy = JSON.parse(r.stdout).services.caddy; assert.equal(caddy.environment.EDITOR_BIND, "0.0.0.0", "the guard is told what is published"); assert.equal(caddy.environment.UMTOOL_BIND, "127.0.0.1"); assert.ok(caddy.ports.some((p) => p.host_ip === "0.0.0.0")); }); test("S1: a failed step of up ends with ONE sentence — what failed, partly up, down stops it — and exit 1", () => { const steps = [ [" up -d", "demo: starting the stack (docker compose up) failed — the demo is partly up; ./docker/demo.sh down stops it.\n"], ["ollama pull", "demo: pulling llama3.2:3b failed — the demo is partly up; ./docker/demo.sh down stops it.\n"], ["gen preset local", "demo: setting the local preset (archilyzer gen preset local) failed — the demo is partly up; ./docker/demo.sh down stops it.\n"], ["gen model local", "demo: setting the local model (archilyzer gen model local) failed — the demo is partly up; ./docker/demo.sh down stops it.\n"], ["curl -fsS -o /dev/null", "demo: the editor did not answer within 4 minutes (docker compose -p archilyzer-demo logs editor says why) — the demo is partly up; ./docker/demo.sh down stops it.\n"], ]; for (const [fail, sentence] of steps) { const f = fixture(); const r = demo(["up", "--model", "llama3.2:3b"], f, { STUB_PERMISSIVE: "1", STUB_IMAGES: "1", STUB_FAIL: fail, DEMO_TEST_WAIT_TRIES: "2", DEMO_TEST_WAIT_SLEEP: "0" }); assert.equal(r.code, 1, fail); assert.ok(r.err.endsWith(sentence), `${fail}\n${r.err}`); assert.doesNotMatch(r.out, /demo: ready/); } const b = fixture(); const build = demo(["up"], b, { STUB_PERMISSIVE: "1", STUB_FAIL: " build editor umtool" }); assert.equal(build.code, 1); assert.ok(build.err.endsWith("demo: building the images failed (the build's output is above) — nothing was started; fix it and run ./docker/demo.sh up again.\n")); assert.ok(!build.calls.some((c) => / up -d/.test(c)), "nothing was started"); }); test("S8: permission denied on the socket has its own sentence; no coreutils on PATH still reaches 'docker is not installed'", () => { const f = fixture(); const r = demo(["up"], f, { STUB_DENIED: "1" }); assert.equal(r.code, 1); assert.equal(r.err, "demo: docker is installed, but this user may not use its socket (permission denied) — add yourself to the docker group (sudo usermod -aG docker $USER, then log in again) and run this again.\n"); const empty = mkdtempSync(path.join(ROOT, "nopath-")); const res = spawnSync(SH, [SCRIPT, "up"], { encoding: "utf8", env: { PATH: empty } }); assert.equal(res.status, 1); assert.equal(res.stderr, "demo: docker is not installed — install Docker Engine (or Docker Desktop) and run this again.\n"); }); test("S8: a tagless model is found as name:latest; a model of unknown size prints no size", () => { const f = fixture(); const have = demo(["up", "--model", "mistral"], f, { STUB_PERMISSIVE: "1", STUB_IMAGES: "1", STUB_HAS_MODEL: "mistral:latest" }); assert.equal(have.code, 0, have.err); assert.match(have.out, /model mistral: present/); assert.ok(!have.calls.some((c) => / pull /.test(c))); const g = fixture(); const pull = demo(["up", "--model", "gemma3:27b"], g, { STUB_PERMISSIVE: "1", STUB_IMAGES: "1" }); assert.match(pull.out, /demo: pulling gemma3:27b \(once\)\n/); });