// PEP-230: the platform image is built from a git archive (no .git), so the web build must take // its commit from the PEPPA_COMMIT build-arg — otherwise /api/health reports `commit: null` and // scripts/platform-deploy.sh rolls every deploy back. import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import { describe, test } from "node:test"; import { claudeConfigFor } from "@peppa/runner"; const read = (p: string) => readFileSync(new URL(`../../../${p}`, import.meta.url), "utf8"); describe("PEP-230: образ платформы знает свой коммит", () => { test("Сценарий: сборка без .git — коммит приходит в next build из build-arg", () => { const dockerfile = read("infra/platform/Dockerfile"); const build = dockerfile.slice(0, dockerfile.lastIndexOf("\nFROM ")); const env = build.indexOf("ENV PEPPA_COMMIT=${PEPPA_COMMIT}"); assert.ok(build.includes("ARG PEPPA_COMMIT"), "build stage must declare ARG PEPPA_COMMIT"); assert.ok(env > 0 && env < build.indexOf("next build"), "PEPPA_COMMIT must be set before `next build`"); }); test("Сценарий: git недоступен — NEXT_PUBLIC_PEPPA_COMMIT берётся из PEPPA_COMMIT", () => { const config = read("apps/web/next.config.ts"); assert.match(config, /NEXT_PUBLIC_PEPPA_COMMIT: git\([^)]*\) \|\| buildCommit/); assert.match(config, /NEXT_PUBLIC_PEPPA_COMMIT_FULL: git\([^)]*\) \|\| buildCommit/); assert.match(config, /process\.env\.PEPPA_COMMIT/); }); test("Сценарий: аналитик и ревьюер работают в контейнере платформы — CLI Claude и Codex есть в образе", () => { const dockerfile = read("infra/platform/Dockerfile"); const runtime = dockerfile.slice(dockerfile.lastIndexOf("\nFROM ")); assert.match(runtime, /npm install -g[^\n]*@anthropic-ai\/claude-code/); assert.match(runtime, /@openai\/codex/); }); test("Сценарий: Linux-сервер — сервисы не от root, общий tmux, агент видит веб по имени контейнера", () => { const compose = read("infra/docker-compose.yml"); assert.match(compose, /user: "\$\{PEPPA_UID:-0\}:\$\{PEPPA_GID:-0\}"/); assert.match(compose, /TMUX_TMPDIR: \$\{PEPPA_HOME\}\/tmux/); assert.match(compose, /PEPPA_WORKSPACES: \$\{PEPPA_HOME\}\/workspaces/); assert.match(compose, /PEPPA_AGENT_URL: \$\{PEPPA_AGENT_URL:-http:\/\/peppa-web:3100\}/); assert.match(compose, /group_add: \["\$\{PEPPA_DOCKER_GID:-0\}"\]/); const deploy = read("scripts/platform-deploy.sh"); assert.match(deploy, /PEPPA_UID=.*id -u/); assert.match(deploy, /docker run --rm --user/); }); test("Сценарий: новый агент в контейнере не ждёт нажатия на экране «Bypass Permissions mode»", () => { const cfg = JSON.parse(claudeConfigFor(null, "/w/p")); assert.equal(cfg.bypassPermissionsModeAccepted, true); assert.equal(cfg.projects["/w/p"].hasTrustDialogAccepted, true); assert.equal(JSON.parse(claudeConfigFor(JSON.stringify({ keep: 1 }), "/w/p")).keep, 1); }); });