diff --git a/.github/workflows/pm-stack-tests.yml b/.github/workflows/pm-stack-tests.yml new file mode 100644 index 0000000000..afde698519 --- /dev/null +++ b/.github/workflows/pm-stack-tests.yml @@ -0,0 +1,47 @@ +name: pm-stack tests + +on: + push: + branches: [main] + paths: + - "pm-stack/**" + - ".github/workflows/pm-stack-tests.yml" + pull_request: + paths: + - "pm-stack/**" + - ".github/workflows/pm-stack-tests.yml" + workflow_dispatch: + +permissions: + contents: read + +jobs: + test: + name: aggregator + projector + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@v7 + + - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0 + + - name: Install aggregator dependencies + working-directory: pm-stack/aggregator + run: bun install --frozen-lockfile + + - name: Test aggregator + working-directory: pm-stack/aggregator + run: bun test + + - name: Install projector dependencies + working-directory: pm-stack/projector + run: bun install --frozen-lockfile + + - name: Test projector + working-directory: pm-stack/projector + run: bun test + + - name: Test seed and deploy/install scripts + run: | + bash pm-stack/scripts/seed-smoke.test.sh + bash pm-stack/scripts/deploy-install-smoke.test.sh diff --git a/pm-stack/aggregator/src/sources/fixtures.ts b/pm-stack/aggregator/src/sources/fixtures.ts index 80b7addc28..470e5b825c 100644 --- a/pm-stack/aggregator/src/sources/fixtures.ts +++ b/pm-stack/aggregator/src/sources/fixtures.ts @@ -1317,7 +1317,7 @@ export const FIXTURE_USAGE: UsageView = { value: 12, unit: "pct", limit: 100, - resetsAt: "2026-10-31T00:00:00Z", + resetsAt: `${daysAgo(-1)}T00:00:00Z`, // future-dated: a fixed past reset collapses the pace window (windowStartIndex) and the detail view loses Pace projections source: "manual", observedBy: "fixtures", }, @@ -1328,7 +1328,7 @@ export const FIXTURE_USAGE: UsageView = { value: 38, unit: "pct", limit: 100, - resetsAt: "2026-10-31T00:00:00Z", + resetsAt: `${daysAgo(-1)}T00:00:00Z`, source: "manual", observedBy: "fixtures", }, @@ -1339,7 +1339,7 @@ export const FIXTURE_USAGE: UsageView = { value: 82, unit: "pct", limit: 100, - resetsAt: "2026-10-31T00:00:00Z", + resetsAt: `${daysAgo(-1)}T00:00:00Z`, source: "manual", observedBy: "fixtures", }, diff --git a/pm-stack/aggregator/test/grist-live.test.ts b/pm-stack/aggregator/test/grist-live.test.ts new file mode 100644 index 0000000000..332206660b --- /dev/null +++ b/pm-stack/aggregator/test/grist-live.test.ts @@ -0,0 +1,122 @@ +import { describe, expect, test } from "bun:test"; +import { mkdtemp, writeFile } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { loadConfig } from "../src/config.ts"; +import { FIXTURE_ROADMAP } from "../src/sources/fixtures.ts"; +import { liveSource } from "../src/sources/live.ts"; + +async function testConfig() { + const dir = await mkdtemp(join(tmpdir(), "pm-grist-live-")); + const feedFile = join(dir, "fleet-feed.json"); + await writeFile( + feedFile, + JSON.stringify({ + version: 1, + generatedAt: new Date().toISOString(), + quota: { pools: [], burn: [], choices: { hasHeadroom: [], burnBeforeReset: [], doNotStart: [] } }, + attention: [], + }), + ); + return loadConfig({ + ...Bun.env, + PM_AGG_SOURCE: "live", + PM_AGG_FEED_FILE: feedFile, + PM_PROJECTOR_URL: "off", + GRIST_URL: "http://grist.test", + GRIST_ROADMAP_DOC: "test-roadmap-doc", + GRIST_API_KEY: "test-grist-api-key", + }); +} + +describe("live Grist roadmap reader (#1213)", () => { + test("reads the records endpoint with bearer auth and maps roadmap fields and references", async () => { + const cfg = await testConfig(); + const requests: { url: string; authorization: string | null }[] = []; + const realFetch = globalThis.fetch; + globalThis.fetch = (async (input: unknown, init?: RequestInit) => { + requests.push({ + url: String(input), + authorization: new Headers(init?.headers).get("authorization"), + }); + return new Response( + JSON.stringify({ + records: [ + { + id: 1213, + fields: { + Title: "Live roadmap row", + Area: "Aggregator", + Status: "In progress", + Horizon: "Q4 2026", + Source: "Issue: https://github.com/developing-today/code/issues/1213", + Notes: "Related PR: https://github.com/developing-today/code/pull/2435", + }, + }, + ], + }), + { status: 200, headers: { "Content-Type": "application/json" } }, + ); + }) as typeof fetch; + + try { + const src = liveSource(cfg); + const rows = await src.roadmap(); + + expect(requests).toEqual([ + { + url: "http://grist.test/api/docs/test-roadmap-doc/tables/Roadmap/records", + authorization: "Bearer test-grist-api-key", + }, + ]); + expect(rows).toEqual([ + { + id: 1213, + subject: "grist:test-roadmap-doc/Roadmap/1213", + title: "Live roadmap row", + area: "Aggregator", + status: "In progress", + horizon: "Q4 2026", + source: "Issue: https://github.com/developing-today/code/issues/1213", + notes: "Related PR: https://github.com/developing-today/code/pull/2435", + links: [ + { ref: "developing-today/code#1213", relation: "tracks" }, + { ref: "developing-today/code#2435", relation: "tracks" }, + ], + gristUrl: "http://amd-6.raptor-pumpkinseed.ts.net:8484/doc/test-roadmap-doc", + }, + ]); + expect(src.provenance().roadmap).toBe("live (Grist)"); + } finally { + globalThis.fetch = realFetch; + } + }); + + test("falls back to fixture rows and reports the Grist read failure", async () => { + const cfg = await testConfig(); + const requests: { url: string; authorization: string | null }[] = []; + const realFetch = globalThis.fetch; + globalThis.fetch = (async (input: unknown, init?: RequestInit) => { + requests.push({ + url: String(input), + authorization: new Headers(init?.headers).get("authorization"), + }); + return new Response("Grist unavailable", { status: 503 }); + }) as typeof fetch; + + try { + const src = liveSource(cfg); + + expect(await src.roadmap()).toEqual(FIXTURE_ROADMAP); + expect(src.provenance().roadmap).toBe("fixtures (grist unreachable: grist roadmap read failed)"); + expect(requests).toEqual([ + { + url: "http://grist.test/api/docs/test-roadmap-doc/tables/Roadmap/records", + authorization: "Bearer test-grist-api-key", + }, + ]); + } finally { + globalThis.fetch = realFetch; + } + }); +}); diff --git a/pm-stack/aggregator/test/slice3.test.ts b/pm-stack/aggregator/test/slice3.test.ts index 394199e494..c53a01bfac 100644 --- a/pm-stack/aggregator/test/slice3.test.ts +++ b/pm-stack/aggregator/test/slice3.test.ts @@ -531,7 +531,8 @@ describe("slice-3 routes", () => { expect(dnsJson.totalAnnualListUsd).toBe(595.62); const sessions = await (await fetch(`http://127.0.0.1:${port}/sessions`)).text(); expect(sessions).toContain("identity registry"); - const registry = (await (await fetch(`http://127.0.0.1:${port}/api/registry.json`)).json()) as { + // window=all: fixture last-activity is a fixed date; the default 7-day window ages it out and fails this test on later run dates. + const registry = (await (await fetch(`http://127.0.0.1:${port}/api/registry.json?window=all`)).json()) as { records: { source: string }[]; identities: { kind: string }[]; }; diff --git a/pm-stack/projector/bun.lock b/pm-stack/projector/bun.lock new file mode 100644 index 0000000000..78a8063d93 --- /dev/null +++ b/pm-stack/projector/bun.lock @@ -0,0 +1,57 @@ +{ + "lockfileVersion": 2, + "configVersion": 1, + "workspaces": { + "": { + "name": "pm-projector", + "dependencies": { + "@libsql/client": "0.18.0", + }, + }, + }, + "packages": { + "@libsql/client": ["@libsql/client@0.18.0", "https://registry.npmmirror.com/@libsql/client/-/client-0.18.0.tgz", { "dependencies": { "@libsql/core": "^0.18.0", "@libsql/hrana-client": "^0.10.0", "js-base64": "^3.7.5", "libsql": "^0.5.28", "promise-limit": "^2.7.0" } }, "sha512-zMCCo58vv7w27j7+cnt/GW+X6/Rih6cHZ86PKi0AxCMOqMfrVgG9OZ5lW2bDMJhSeOjsv2szH2nJF3A9l36UmA=="], + + "@libsql/core": ["@libsql/core@0.18.0", "https://registry.npmmirror.com/@libsql/core/-/core-0.18.0.tgz", { "dependencies": { "js-base64": "^3.7.5" } }, "sha512-N8RR2CIpcgtbKZnXs2KVpw2lJQfinUj3I56e7qRDRpK18Hty0Rr8nr00VmFb4R/DsqOanPB/TaP3+QAQLZeXMg=="], + + "@libsql/darwin-arm64": ["@libsql/darwin-arm64@0.5.29", "https://registry.npmmirror.com/@libsql/darwin-arm64/-/darwin-arm64-0.5.29.tgz", { "os": "darwin", "cpu": "arm64" }, "sha512-K+2RIB1OGFPYQbfay48GakLhqf3ArcbHqPFu7EZiaUcRgFcdw8RoltsMyvbj5ix2fY0HV3Q3Ioa/ByvQdaSM0A=="], + + "@libsql/darwin-x64": ["@libsql/darwin-x64@0.5.29", "https://registry.npmmirror.com/@libsql/darwin-x64/-/darwin-x64-0.5.29.tgz", { "os": "darwin", "cpu": "x64" }, "sha512-OtT+KFHsKFy1R5FVadr8FJ2Bb1mghtXTyJkxv0trocq7NuHntSki1eUbxpO5ezJesDvBlqFjnWaYYY516QNLhQ=="], + + "@libsql/hrana-client": ["@libsql/hrana-client@0.10.0", "https://registry.npmmirror.com/@libsql/hrana-client/-/hrana-client-0.10.0.tgz", { "dependencies": { "@libsql/isomorphic-ws": "^0.1.5", "js-base64": "^3.7.5" } }, "sha512-OoA4EMqRAC7kn7V2P6EQqRcpZf2W+AjsNIyCizBg339Tq/aMC7sRnzs3SklderhmQWAqEzvv8A2vhxVmWpkVvw=="], + + "@libsql/isomorphic-ws": ["@libsql/isomorphic-ws@0.1.5", "https://registry.npmmirror.com/@libsql/isomorphic-ws/-/isomorphic-ws-0.1.5.tgz", { "dependencies": { "@types/ws": "^8.5.4", "ws": "^8.13.0" } }, "sha512-DtLWIH29onUYR00i0GlQ3UdcTRC6EP4u9w/h9LxpUZJWRMARk6dQwZ6Jkd+QdwVpuAOrdxt18v0K2uIYR3fwFg=="], + + "@libsql/linux-arm-gnueabihf": ["@libsql/linux-arm-gnueabihf@0.5.29", "https://registry.npmmirror.com/@libsql/linux-arm-gnueabihf/-/linux-arm-gnueabihf-0.5.29.tgz", { "os": "linux", "cpu": "arm" }, "sha512-CD4n4zj7SJTHso4nf5cuMoWoMSS7asn5hHygsDuhRl8jjjCTT3yE+xdUvI4J7zsyb53VO5ISh4cwwOtf6k2UhQ=="], + + "@libsql/linux-arm-musleabihf": ["@libsql/linux-arm-musleabihf@0.5.29", "https://registry.npmmirror.com/@libsql/linux-arm-musleabihf/-/linux-arm-musleabihf-0.5.29.tgz", { "os": "linux", "cpu": "arm" }, "sha512-2Z9qBVpEJV7OeflzIR3+l5yAd4uTOLxklScYTwpZnkm2vDSGlC1PRlueLaufc4EFITkLKXK2MWBpexuNJfMVcg=="], + + "@libsql/linux-arm64-gnu": ["@libsql/linux-arm64-gnu@0.5.29", "https://registry.npmmirror.com/@libsql/linux-arm64-gnu/-/linux-arm64-gnu-0.5.29.tgz", { "os": "linux", "cpu": "arm64" }, "sha512-gURBqaiXIGGwFNEaUj8Ldk7Hps4STtG+31aEidCk5evMMdtsdfL3HPCpvys+ZF/tkOs2MWlRWoSq7SOuCE9k3w=="], + + "@libsql/linux-arm64-musl": ["@libsql/linux-arm64-musl@0.5.29", "https://registry.npmmirror.com/@libsql/linux-arm64-musl/-/linux-arm64-musl-0.5.29.tgz", { "os": "linux", "cpu": "arm64" }, "sha512-fwgYZ0H8mUkyVqXZHF3mT/92iIh1N94Owi/f66cPVNsk9BdGKq5gVpoKO+7UxaNzuEH1roJp2QEwsCZMvBLpqg=="], + + "@libsql/linux-x64-gnu": ["@libsql/linux-x64-gnu@0.5.29", "https://registry.npmmirror.com/@libsql/linux-x64-gnu/-/linux-x64-gnu-0.5.29.tgz", { "os": "linux", "cpu": "x64" }, "sha512-y14V0vY0nmMC6G0pHeJcEarcnGU2H6cm21ZceRkacWHvQAEhAG0latQkCtoS2njFOXiYIg+JYPfAoWKbi82rkg=="], + + "@libsql/linux-x64-musl": ["@libsql/linux-x64-musl@0.5.29", "https://registry.npmmirror.com/@libsql/linux-x64-musl/-/linux-x64-musl-0.5.29.tgz", { "os": "linux", "cpu": "x64" }, "sha512-gquqwA/39tH4pFl+J9n3SOMSymjX+6kZ3kWgY3b94nXFTwac9bnFNMffIomgvlFaC4ArVqMnOZD3nuJ3H3VO1w=="], + + "@libsql/win32-x64-msvc": ["@libsql/win32-x64-msvc@0.5.29", "https://registry.npmmirror.com/@libsql/win32-x64-msvc/-/win32-x64-msvc-0.5.29.tgz", { "os": "win32", "cpu": "x64" }, "sha512-4/0CvEdhi6+KjMxMaVbFM2n2Z44escBRoEYpR+gZg64DdetzGnYm8mcNLcoySaDJZNaBd6wz5DNdgRmcI4hXcg=="], + + "@neon-rs/load": ["@neon-rs/load@0.0.4", "https://registry.npmmirror.com/@neon-rs/load/-/load-0.0.4.tgz", {}, "sha512-kTPhdZyTQxB+2wpiRcFWrDcejc4JI6tkPuS7UZCG4l6Zvc5kU/gGQ/ozvHTh1XR5tS+UlfAfGuPajjzQjCiHCw=="], + + "@types/node": ["@types/node@26.6.6", "https://registry.npmmirror.com/@types/node/-/node-26.6.6.tgz", { "dependencies": { "undici-types": "~8.9.0" } }, "sha512-MzQj+8Kx3XI40OmUAE6Qoh58ZMNstNNMwn2nfd3qWsfe7nDNSqJNzes4njhz6AHwrSHOffSLwXU6yb474Q4aog=="], + + "@types/ws": ["@types/ws@8.18.2", "https://registry.npmmirror.com/@types/ws/-/ws-8.18.2.tgz", { "dependencies": { "@types/node": "*" } }, "sha512-67MQl+fpWKVTT1NYdnmo3U4sc/xPo/zQBncVnI74qmQa0z/b+1g6iYqNmGCPbxO+zz2aklb08a0oHfegiVd0/w=="], + + "detect-libc": ["detect-libc@2.0.2", "https://registry.npmmirror.com/detect-libc/-/detect-libc-2.0.2.tgz", {}, "sha512-UX6sGumvvqSaXgdKGUsgZWqcUyIXZ/vZTrlRT/iobiKhGL0zL4d3osHj3uqllWJK+i+sixDS/3COVEOFbupFyw=="], + + "js-base64": ["js-base64@3.9.6", "https://registry.npmmirror.com/js-base64/-/js-base64-3.9.6.tgz", {}, "sha512-LjkzbLtU6Lx6fjXMYGEACEB7rdtqZtxkBe9aS1ZpDNUyWgUivw3yBEIhQ37OVygJYRt+C+9e9fVT8PpFzH2Hww=="], + + "libsql": ["libsql@0.5.29", "https://registry.npmmirror.com/libsql/-/libsql-0.5.29.tgz", { "dependencies": { "@neon-rs/load": "^0.0.4", "detect-libc": "2.0.2" }, "optionalDependencies": { "@libsql/darwin-arm64": "0.5.29", "@libsql/darwin-x64": "0.5.29", "@libsql/linux-arm-gnueabihf": "0.5.29", "@libsql/linux-arm-musleabihf": "0.5.29", "@libsql/linux-arm64-gnu": "0.5.29", "@libsql/linux-arm64-musl": "0.5.29", "@libsql/linux-x64-gnu": "0.5.29", "@libsql/linux-x64-musl": "0.5.29", "@libsql/win32-x64-msvc": "0.5.29" }, "os": [ "linux", "win32", "darwin", ], "cpu": [ "arm", "x64", "arm64", ] }, "sha512-8lMP8iMgiBzzoNbAPQ59qdVcj6UaE/Vnm+fiwX4doX4Narook0a4GPKWBEv+CR8a1OwbfkgL18uBfBjWdF0Fzg=="], + + "promise-limit": ["promise-limit@2.7.0", "https://registry.npmmirror.com/promise-limit/-/promise-limit-2.7.0.tgz", {}, "sha512-7nJ6v5lnJsXwGprnGXga4wx6d1POjvi5Qmf1ivTRxTjH4Z/9Czja/UCMLVmB9N93GeWOU93XaFaEt6jbuoagNw=="], + + "undici-types": ["undici-types@8.9.0", "https://registry.npmmirror.com/undici-types/-/undici-types-8.9.0.tgz", {}, "sha512-KTDyRTYX8sWmKXAikPHHSyc63CRPETMctyjKFupcC6OBLXT3xsN0e9aF7m+mIXutFWpUXuedtowG7iLOzp0kQg=="], + + "ws": ["ws@8.22.1", "https://registry.npmmirror.com/ws/-/ws-8.22.1.tgz", { "peerDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": ">=5.0.2" }, "optionalPeers": ["bufferutil", "utf-8-validate"] }, "sha512-oyL6OPYme/CmiFvNuGzeoxCJ4nOrZE2O1FwM9MWM1AsGri6nLXB2pg+lNA8aLeXMSav0J6eIVS1j6vUPzUtK9g=="], + } +} diff --git a/pm-stack/scripts/deploy-install-smoke.test.sh b/pm-stack/scripts/deploy-install-smoke.test.sh new file mode 100755 index 0000000000..42a80a64be --- /dev/null +++ b/pm-stack/scripts/deploy-install-smoke.test.sh @@ -0,0 +1,379 @@ +#!/usr/bin/env bash +# Safely smoke render/install shell paths using temporary copies, isolated +# HOME directories, fake SOPS input and guarded command stubs. +# Run from anywhere: bash pm-stack/scripts/deploy-install-smoke.test.sh +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PM_STACK_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" +BASH_BIN="${BASH:-$(command -v bash)}" +REAL_RM="$(command -v rm)" +REAL_INSTALL="$(command -v install)" +REAL_CP="$(command -v cp)" +SYSTEM_PATH="/run/current-system/sw/bin:/usr/bin:/bin" +export PATH="$SYSTEM_PATH" +export PM_TEST_REAL_RM="$REAL_RM" PM_TEST_REAL_INSTALL="$REAL_INSTALL" PM_TEST_REAL_CP="$REAL_CP" + +for command_name in jq chmod cp mkdir; do + if ! command -v "$command_name" >/dev/null 2>&1; then + echo "FAIL - required command not found: $command_name" + exit 1 + fi +done + +TMP_BASE="${TMPDIR:-/tmp/opencode}" +mkdir -p "$TMP_BASE" +TMP="$(mktemp -d "$TMP_BASE/deploy-install-smoke.XXXXXX")" +trap 'rm -rf "$TMP"' EXIT +STUB_BIN="$TMP/stubs" +mkdir -p "$STUB_BIN" +FAILURES=0 +pass() { printf 'ok - %s\n' "$1"; } +fail() { printf 'FAIL - %s\n' "$1"; FAILURES=$((FAILURES + 1)); } +contains() { grep -Fq -- "$2" "$1"; } + +cat >"$STUB_BIN/sops" <<'STUB' +#!/usr/bin/env bash +set -euo pipefail +mode=decrypt +key='' +input='' +while (($#)); do + case "$1" in + --decrypt) mode=decrypt ;; + -d) mode=extract ;; + --extract) key="$2"; shift ;; + *) input="$1" ;; + esac + shift +done +if [[ ! -f "$input" || ! "$input" -ef "${PM_TEST_SECRETS:?}" ]]; then + echo "refusing non-fixture SOPS input: $input" >&2 + exit 91 +fi +if [[ -n ${PM_TEST_SOPS_LOG:-} ]]; then printf '%s %s\n' "$mode" "${key:-all}" >>"$PM_TEST_SOPS_LOG"; fi +if [[ $mode == extract ]]; then + case "$key" in + *kaneo_admin_email*) printf '%s\n' 'smoke-admin@example.invalid' ;; + *kaneo_admin_password*) printf '%s\n' 'fake-kaneo-password' ;; + *grist_api_key*) printf '%s\n' 'fake-grist-key' ;; + *) echo "unexpected extract key: $key" >&2; exit 92 ;; + esac +else + cat <<'YAML' +postgres_password: fake-postgres-password +auth_secret: fake-auth-secret +notification_secret_encryption_key: fake-notification-key +github_app_id: 12345 +github_app_name: smoke-app +github_webhook_secret: fake-webhook-secret +github_private_key_base64: ZmFrZS1wcml2YXRlLWtleQ== +cloudflare_tunnel_token: fake-tunnel-token +pad_api_token: fake-pad-token +grist_session_secret: fake-grist-session +grist_default_email: smoke-grist@example.invalid +YAML +fi +STUB + +cat >"$STUB_BIN/curl" <<'STUB' +#!/usr/bin/env bash +set -euo pipefail +url='' +for arg in "$@"; do + case "$arg" in http://*|https://*) url="$arg" ;; esac +done +printf 'curl %s\n' "$url" >>"${PM_TEST_COMMAND_LOG:?}" +case "$url" in + http://127.0.0.1:4870/api/health|http://100.64.20.21:4870/api/health) + printf '{"version":"%s"}\n' "${PM_TEST_BUILD_VERSION:-smoke-build-v1}" + ;; + http://127.0.0.1:6056/) + printf 'fake ready-for-agent UI\n' + ;; + *) echo "blocked unexpected curl URL: $url" >&2; exit 93 ;; +esac +STUB + +cat >"$STUB_BIN/docker" <<'STUB' +#!/usr/bin/env bash +printf 'docker %s\n' "$*" >>"${PM_TEST_COMMAND_LOG:?}" +echo 'docker command is blocked in smoke tests' >&2 +exit 94 +STUB + +cat >"$STUB_BIN/systemctl" <<'STUB' +#!/usr/bin/env bash +set -euo pipefail +printf 'systemctl %s\n' "$*" >>"${PM_TEST_COMMAND_LOG:?}" +# Model ExecMainStartTimestampMonotonic: a value that changes on restart, +# so installers that prove a fresh process start (ready-for-agent) can pass. +start_ts_file="${PM_TEST_ROOT:?}/.systemctl-start-ts" +case " $* " in + *' restart '*) + cur=1000 + if [[ -f "$start_ts_file" ]]; then cur="$(cat "$start_ts_file")"; fi + printf '%s\n' "$((cur + 1000))" >"$start_ts_file" + ;; + *' show '*ExecMainStartTimestampMonotonic*) + if [[ -f "$start_ts_file" ]]; then cat "$start_ts_file"; else printf '1000\n'; fi + ;; + *' is-active '*|*' status '*) printf 'active\n' ;; +esac +exit 0 +STUB + +cat >"$STUB_BIN/bun" <<'STUB' +#!/usr/bin/env bash +set -euo pipefail +printf 'bun %s\n' "$*" >>"${PM_TEST_COMMAND_LOG:?}" +if [[ ${1:-} == install ]]; then + # Package changes are explicitly prohibited by this smoke test. + exit 0 +fi +if [[ ${1:-} == -e ]]; then + # Return the deterministic version corresponding to the fake health API. + cat >/dev/null + printf '%s\n' "${PM_TEST_BUILD_VERSION:-smoke-build-v1}" + exit 0 +fi +echo "blocked unexpected bun invocation: $*" >&2 +exit 95 +STUB + +cat >"$STUB_BIN/npm" <<'STUB' +#!/usr/bin/env bash +printf 'npm %s\n' "$*" >>"${PM_TEST_COMMAND_LOG:?}" +echo 'npm package changes are blocked in smoke tests' >&2 +exit 96 +STUB + +cat >"$STUB_BIN/git" <<'STUB' +#!/usr/bin/env bash +printf 'git %s\n' "$*" >>"${PM_TEST_COMMAND_LOG:?}" +if [[ ${*: -2} == 'rev-parse HEAD' ]]; then + printf '%s\n' "${PM_TEST_BUILD_VERSION:-smoke-build-v1}" + exit 0 +fi +echo "blocked unexpected git invocation: $*" >&2 +exit 97 +STUB + +cat >"$STUB_BIN/tailscale" <<'STUB' +#!/usr/bin/env bash +printf 'tailscale %s\n' "$*" >>"${PM_TEST_COMMAND_LOG:?}" +printf '100.64.20.21\n' +STUB + +cat >"$STUB_BIN/sleep" <<'STUB' +#!/usr/bin/env bash +printf 'sleep %s\n' "$*" >>"${PM_TEST_COMMAND_LOG:?}" +exit 0 +STUB + +cat >"$STUB_BIN/rm" <<'STUB' +#!/usr/bin/env bash +set -euo pipefail +for arg in "$@"; do + case "$arg" in + -*) ;; + "$HOME"/*|"${PM_TEST_ROOT:?}"/*) ;; + *) echo "blocked rm outside isolated HOME/temp root: $arg" >&2; exit 98 ;; + esac +done +exec "${PM_TEST_REAL_RM:?}" "$@" +STUB + +cat >"$STUB_BIN/install" <<'STUB' +#!/usr/bin/env bash +set -euo pipefail +target='' +for arg in "$@"; do [[ $arg == -* ]] || target="$arg"; done +case "$target" in + "$HOME"/*) ;; + *) echo "blocked install outside isolated HOME: $target" >&2; exit 99 ;; +esac +exec "${PM_TEST_REAL_INSTALL:?}" "$@" +STUB + +cat >"$STUB_BIN/cp" <<'STUB' +#!/usr/bin/env bash +set -euo pipefail +target='' +for arg in "$@"; do [[ $arg == -* ]] || target="$arg"; done +case "$target" in + "$HOME"/*) ;; + *) echo "blocked cp outside isolated HOME: $target" >&2; exit 100 ;; +esac +exec "${PM_TEST_REAL_CP:?}" "$@" +STUB +chmod +x "$STUB_BIN"/* + +COMMAND_LOG="$TMP/commands.log" +: >"$COMMAND_LOG" + +# Render modes run from copied layouts, with one fake SOPS file shared by +# the three scripts. Docker/curl remain blocked as a safety backstop. +RENDER_ROOT="$TMP/render" +RENDER_SECRETS="$RENDER_ROOT/secrets/pm-stack.sops.yaml" +mkdir -p "$RENDER_ROOT/pm-stack/pad" "$RENDER_ROOT/pm-stack/grist" "$RENDER_ROOT/secrets" +printf '%s\n' 'fake encrypted render fixture' >"$RENDER_SECRETS" +cp "$PM_STACK_DIR/deploy.sh" "$RENDER_ROOT/pm-stack/deploy.sh" +cp "$PM_STACK_DIR/pad/deploy.sh" "$RENDER_ROOT/pm-stack/pad/deploy.sh" +cp "$PM_STACK_DIR/grist/deploy.sh" "$RENDER_ROOT/pm-stack/grist/deploy.sh" + +run_render() { + local script="$1" home="$2" log="$3" + mkdir -p "$home" + env HOME="$home" PATH="$STUB_BIN:$SYSTEM_PATH" \ + PM_TEST_ROOT="$TMP" PM_TEST_SECRETS="$RENDER_SECRETS" \ + PM_TEST_COMMAND_LOG="$COMMAND_LOG" PM_TEST_SOPS_LOG="$log" \ + PM_STACK_TAILNET_IP=100.64.20.21 \ + "$BASH_BIN" "$script" render >"$log.out" 2>&1 +} + +if run_render "$RENDER_ROOT/pm-stack/deploy.sh" "$TMP/render-home-pm" "$TMP/pm-sops.log"; then + pass 'pm-stack deploy render mode runs in a temporary copy' +else + cat "$TMP/pm-sops.log.out" 2>/dev/null || true + fail 'pm-stack deploy render mode runs in a temporary copy' +fi +if contains "$RENDER_ROOT/pm-stack/.env" 'POSTGRES_PASSWORD=fake-postgres-password' && + contains "$RENDER_ROOT/pm-stack/.env" 'DISABLE_REGISTRATION=true' && + contains "$RENDER_ROOT/pm-stack/tunnel.env" 'TUNNEL_TOKEN=fake-tunnel-token'; then + pass 'pm-stack render emits expected fake values' +else + fail 'pm-stack render emits expected fake values' +fi +if [[ $(stat -c '%a' "$RENDER_ROOT/pm-stack/.env") == 600 && + $(stat -c '%a' "$RENDER_ROOT/pm-stack/tunnel.env") == 600 ]]; then + pass 'pm-stack render files have mode 600' +else + fail 'pm-stack render files have mode 600' +fi + +if run_render "$RENDER_ROOT/pm-stack/pad/deploy.sh" "$TMP/render-home-pad" "$TMP/pad-sops.log"; then + pass 'Pad deploy render mode runs in a temporary copy' +else + cat "$TMP/pad-sops.log.out" 2>/dev/null || true + fail 'Pad deploy render mode runs in a temporary copy' +fi +if contains "$RENDER_ROOT/pm-stack/pad/.env" 'PM_STACK_TAILNET_IP=100.64.20.21' && + contains "$RENDER_ROOT/pm-stack/pad/.env" 'Pad needs no server-env secrets'; then + pass 'Pad render emits expected temporary configuration' +else + fail 'Pad render emits expected temporary configuration' +fi +if [[ $(stat -c '%a' "$RENDER_ROOT/pm-stack/pad/.env") == 600 ]]; then pass 'Pad render file has mode 600'; else fail 'Pad render file has mode 600'; fi + +if run_render "$RENDER_ROOT/pm-stack/grist/deploy.sh" "$TMP/render-home-grist" "$TMP/grist-sops.log"; then + pass 'Grist deploy render mode runs in a temporary copy' +else + cat "$TMP/grist-sops.log.out" 2>/dev/null || true + fail 'Grist deploy render mode runs in a temporary copy' +fi +if contains "$RENDER_ROOT/pm-stack/grist/.env" 'GRIST_SESSION_SECRET=fake-grist-session' && + contains "$RENDER_ROOT/pm-stack/grist/.env" 'GRIST_DEFAULT_EMAIL=smoke-grist@example.invalid' && + contains "$RENDER_ROOT/pm-stack/grist/.env" 'PM_STACK_TAILNET_IP=100.64.20.21'; then + pass 'Grist render emits expected fake values' +else + fail 'Grist render emits expected fake values' +fi +if [[ $(stat -c '%a' "$RENDER_ROOT/pm-stack/grist/.env") == 600 ]]; then pass 'Grist render file has mode 600'; else fail 'Grist render file has mode 600'; fi +if ! grep -Fq 'docker ' "$COMMAND_LOG"; then pass 'render modes invoke no Docker commands'; else fail 'render modes invoke no Docker commands'; fi + +# Syntax-check originals without executing them in the checkout/host. +AGG_INSTALL="$PM_STACK_DIR/aggregator/install.sh" +READY_INSTALL="$PM_STACK_DIR/ready-for-agent/install.sh" +if "$BASH_BIN" -n "$AGG_INSTALL"; then pass 'aggregator/install.sh syntax check'; else fail 'aggregator/install.sh syntax check'; fi +if "$BASH_BIN" -n "$READY_INSTALL"; then pass 'ready-for-agent/install.sh syntax check'; else fail 'ready-for-agent/install.sh syntax check'; fi + +# Build a minimal aggregator package copy so install.sh's hash/copy logic +# runs entirely inside a disposable HOME. Side-effecting tools are stubbed. +AGG_SRC="$TMP/aggregator-src" +AGG_HOME="$TMP/aggregator-home" +mkdir -p "$AGG_SRC" "$AGG_HOME/secrets" "$AGG_HOME/pm-stack/systemd" +cp "$AGG_INSTALL" "$AGG_SRC/install.sh" +printf '%s\n' '{"name":"smoke-aggregator","version":"1.0.0"}' >"$AGG_SRC/package.json" +printf '%s\n' 'fake lockfile' >"$AGG_SRC/bun.lock" +printf '%s\n' '{"compilerOptions":{}}' >"$AGG_SRC/tsconfig.json" +printf '%s\n' '{"projects":[]}' >"$AGG_SRC/fleet-feed.json" +mkdir -p "$AGG_SRC/src" "$AGG_SRC/test" "$AGG_SRC/scripts" "$AGG_SRC/opencode-tools" "$AGG_SRC/systemd" +printf '%s\n' '// fixture' >"$AGG_SRC/src/smoke.ts" +printf '%s\n' '// fixture' >"$AGG_SRC/test/smoke.test.ts" +printf '%s\n' '# fixture' >"$AGG_SRC/scripts/smoke.sh" +printf '%s\n' '// fixture' >"$AGG_SRC/opencode-tools/smoke.ts" +printf '%s\n' '[Service]' >"$AGG_SRC/systemd/quota-gatherer.service" +printf '%s\n' '[Timer]' >"$AGG_SRC/systemd/quota-gatherer.timer" +printf '%s\n' '[Service]' >"$AGG_HOME/pm-stack/systemd/pm-aggregator.service" +printf '%s\n' 'fake encrypted aggregator fixture' >"$AGG_HOME/secrets/pm-stack.sops.yaml" +AGG_SOPS_LOG="$TMP/aggregator-sops.log" +AGG_OUTPUT="$TMP/aggregator-install.out" +if env HOME="$AGG_HOME" PATH="$STUB_BIN:$SYSTEM_PATH" \ + PM_TEST_ROOT="$TMP" PM_TEST_SECRETS="$AGG_HOME/secrets/pm-stack.sops.yaml" \ + PM_TEST_COMMAND_LOG="$COMMAND_LOG" PM_TEST_SOPS_LOG="$AGG_SOPS_LOG" \ + PM_TEST_BUILD_VERSION=smoke-build-v1 TAILNET_IP=100.64.20.21 \ + "$BASH_BIN" "$AGG_SRC/install.sh" >"$AGG_OUTPUT" 2>&1; then + pass 'aggregator install smoke completes using temporary HOME and stubs' +else + cat "$AGG_OUTPUT" + fail 'aggregator install smoke completes using temporary HOME and stubs' +fi +if contains "$AGG_HOME/pm-stack/aggregator/.env" 'KANEO_ADMIN_EMAIL=smoke-admin@example.invalid' && + contains "$AGG_HOME/pm-stack/aggregator/.env" 'GRIST_API_KEY=fake-grist-key' && + contains "$AGG_HOME/pm-stack/aggregator/.env" 'PM_AGG_BUILD_VERSION=smoke-build-v1'; then + pass 'aggregator renders environment from stubbed SOPS fields' +else + fail 'aggregator renders environment from stubbed SOPS fields' +fi +if [[ -f "$AGG_HOME/.config/systemd/user/pm-aggregator.service" && + -f "$AGG_HOME/.config/systemd/user/quota-gatherer.service" && + -f "$AGG_HOME/pm-stack/aggregator/.deploy-tree-hash" ]]; then + pass 'aggregator copies package and unit files only under temporary HOME' +else + fail 'aggregator copies package and unit files only under temporary HOME' +fi +if contains "$AGG_OUTPUT" 'health version verified: smoke-build-v1'; then + pass 'aggregator health-version gate accepts the stubbed matching version' +else + fail 'aggregator health-version gate accepts the stubbed matching version' +fi + +# Pre-seed a fake pinned executable, avoiding npm. The npm stub fails +# closed if the installer ever attempts a package change. +READY_ROOT="$TMP/ready-src" +READY_HOME="$TMP/ready-home" +mkdir -p "$READY_ROOT/systemd" "$READY_HOME/.local/bin" +cp "$READY_INSTALL" "$READY_ROOT/install.sh" +printf '%s\n' '[Service]' >"$READY_ROOT/systemd/ready-for-agent.service" +cat >"$READY_HOME/.local/bin/ready-for-agent" <<'FAKE' +#!/usr/bin/env bash +printf 'ready-for-agent 1.1.0\n' +FAKE +chmod +x "$READY_HOME/.local/bin/ready-for-agent" +READY_OUTPUT="$TMP/ready-install.out" +if env HOME="$READY_HOME" PATH="$STUB_BIN:$SYSTEM_PATH" \ + PM_TEST_ROOT="$TMP" PM_TEST_COMMAND_LOG="$COMMAND_LOG" \ + "$BASH_BIN" "$READY_ROOT/install.sh" >"$READY_OUTPUT" 2>&1; then + pass 'ready-for-agent install smoke completes using temporary HOME and stubs' +else + cat "$READY_OUTPUT" + fail 'ready-for-agent install smoke completes using temporary HOME and stubs' +fi +if [[ -f "$READY_HOME/.config/systemd/user/ready-for-agent.service" ]] && + contains "$READY_OUTPUT" 'is running after restart'; then + pass 'ready-for-agent copies its unit and passes the fake UI health check' +else + fail 'ready-for-agent copies its unit and passes the fake UI health check' +fi +if ! grep -Fq 'npm ' "$COMMAND_LOG"; then pass 'ready-for-agent smoke makes no package-manager call'; else fail 'ready-for-agent smoke makes no package-manager call'; fi + +if ((FAILURES)); then + echo 'LIMITATION: HTTP, SOPS, systemd, git, Bun execution/package install, Docker and npm are stubbed; no live service, host unit, network, or package state is exercised.' + echo 'LIMITATION: ready-for-agent clone mode is intentionally not run because it is network-heavy.' + printf 'deploy-install-smoke.test.sh: %d check(s) failed\n' "$FAILURES" + exit 1 +fi +echo 'LIMITATION: HTTP, SOPS, systemd, git, Bun execution/package install, Docker and npm are stubbed; no live service, host unit, network, or package state is exercised.' +echo 'LIMITATION: ready-for-agent clone mode is intentionally not run because it is network-heavy; only the non-clone install path is smoke-tested.' +echo 'deploy-install-smoke.test.sh: all checks passed' diff --git a/pm-stack/scripts/seed-smoke.test.sh b/pm-stack/scripts/seed-smoke.test.sh new file mode 100755 index 0000000000..d0f7035d95 --- /dev/null +++ b/pm-stack/scripts/seed-smoke.test.sh @@ -0,0 +1,244 @@ +#!/usr/bin/env bash +# Safe, stateful smoke tests for the Grist and Pad seed scripts. +# Run from anywhere: bash pm-stack/scripts/seed-smoke.test.sh +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PM_STACK_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" +BASH_BIN="${BASH:-$(command -v bash)}" +SYSTEM_PATH="/run/current-system/sw/bin:/usr/bin:/bin" +export PATH="$SYSTEM_PATH" + +if ! command -v jq >/dev/null 2>&1; then + echo 'FAIL - jq is required by the seed scripts but was not found in PATH' + exit 1 +fi + +TMP_BASE="${TMPDIR:-/tmp/opencode}" +mkdir -p "$TMP_BASE" +TMP="$(mktemp -d "$TMP_BASE/seed-smoke.XXXXXX")" +trap 'rm -rf "$TMP"' EXIT +STUB_BIN="$TMP/bin" +HOME_DIR="$TMP/home" +SECRETS_FILE="$TMP/secrets/fake.sops.yaml" +mkdir -p "$STUB_BIN" "$HOME_DIR/.config/sops/age" "$(dirname "$SECRETS_FILE")" +printf '%s\n' 'test fixture only; never decrypted by real sops' >"$SECRETS_FILE" +printf '%s\n' 'fake age key location' >"$HOME_DIR/.config/sops/age/keys.txt" + +FAILURES=0 +pass() { printf 'ok - %s\n' "$1"; } +fail() { printf 'FAIL - %s\n' "$1"; FAILURES=$((FAILURES + 1)); } +contains() { grep -Fq -- "$2" "$1"; } + +cat >"$STUB_BIN/sops" <<'STUB' +#!/usr/bin/env bash +set -euo pipefail +input='' +mode=decrypt +key='' +while (($#)); do + case "$1" in + --decrypt) mode=decrypt ;; + -d) mode=extract ;; + --extract) key="$2"; shift ;; + *) input="$1" ;; + esac + shift +done +if [[ "$input" != "${PM_TEST_SECRETS:?}" || ! -f "$input" ]]; then + echo "refusing non-fixture SOPS input: $input" >&2 + exit 91 +fi +if [[ $mode == extract ]]; then + echo 'unexpected extract request in seed test' >&2 + exit 92 +fi +cat <<'YAML' +grist_api_key: fake-grist-key +pad_api_token: fake-pad-token +YAML +STUB + +cat >"$STUB_BIN/curl-grist" <<'STUB' +#!/usr/bin/env bash +set -euo pipefail +method=GET +url='' +body='' +while (($#)); do + case "$1" in + -X) method="$2"; shift ;; + -H) shift ;; + -d) + if [[ "$2" == @- ]]; then body="$(cat)"; else body="$2"; fi + shift + ;; + --fail|--silent) ;; + http://*) url="$1" ;; + esac + shift +done +case "$url" in + http://127.0.0.1:8484*) path="${url#http://127.0.0.1:8484}" ;; + *) echo "blocked unexpected Grist URL: $url" >&2; exit 93 ;; +esac +log="${SMOKE_CURL_LOG:?}" +state="${SMOKE_STATE:?}" +phase="${SMOKE_PHASE:-unknown}" +event='' +if [[ $method == POST && $path == /api/docs/42/apply ]]; then + action="$(printf '%s' "$body" | jq -r '.[0][0]')" + event="action=$action" + case "$action" in + AddTable) : >"$state/table" ;; + BulkAddRecord) : >"$state/rows" ;; + *) echo "unexpected Grist apply action: $action" >&2; exit 94 ;; + esac +fi +printf 'phase=%s method=%s path=%s %s\n' "$phase" "$method" "$path" "$event" >>"$log" +if [[ $method == POST ]]; then + case "$path" in + /api/orgs/1/workspaces) : >"$state/workspace"; printf '11\n' ;; + /api/workspaces/11/docs) : >"$state/document"; printf '42\n' ;; + /api/docs/42/apply) printf '{}\n' ;; + *) echo "blocked unexpected Grist POST: $path" >&2; exit 95 ;; + esac + exit 0 +fi +case "$path" in + /api/orgs) printf '[{"id":1}]\n' ;; + /api/orgs/1/workspaces) + if [[ -f "$state/workspace" ]]; then + if [[ -f "$state/document" ]]; then + printf '[{"id":11,"name":"Roadmap & registers","docs":[{"id":42,"name":"Program roadmap"}]}]\n' + else + printf '[{"id":11,"name":"Roadmap & registers","docs":[]}]\n' + fi + else + printf '[]\n' + fi + ;; + /api/docs/42/tables) + if [[ -f "$state/table" ]]; then printf '{"tables":[{"id":"Roadmap"}]}\n'; else printf '{"tables":[]}\n'; fi + ;; + /api/docs/42/tables/Roadmap/records) + if [[ -f "$state/rows" ]]; then printf '{"records":[{"id":1}]}\n'; else printf '{"records":[]}\n'; fi + ;; + *) echo "blocked unexpected Grist GET: $path" >&2; exit 96 ;; +esac +STUB + +cat >"$STUB_BIN/curl-pad" <<'STUB' +#!/usr/bin/env bash +set -euo pipefail +method=GET +url='' +body='' +while (($#)); do + case "$1" in + -X) method="$2"; shift ;; + -H) shift ;; + -d) + if [[ "$2" == @- ]]; then body="$(cat)"; else body="$2"; fi + shift + ;; + --fail|--silent) ;; + http://*) url="$1" ;; + esac + shift +done +case "$url" in + http://127.0.0.1:7777/api/v1/workspaces/developing-today/collections/*/items) path="${url#http://127.0.0.1:7777/api/v1/workspaces/developing-today}" ;; + *) echo "blocked unexpected Pad URL: $url" >&2; exit 97 ;; +esac +log="${SMOKE_CURL_LOG:?}" +state="${SMOKE_STATE:?}" +phase="${SMOKE_PHASE:-unknown}" +titles="$state/titles" +mkdir -p "$state" +if [[ $method == POST ]]; then + title="$(printf '%s' "$body" | jq -r '.title')" + printf '%s\n' "$title" >>"$titles" + printf 'phase=%s method=POST path=%s title=%s\n' "$phase" "$path" "$title" >>"$log" + printf '{}\n' +else + printf 'phase=%s method=GET path=%s\n' "$phase" "$path" >>"$log" + if [[ -f "$titles" ]]; then + jq -Rsc 'split("\n") | map(select(length > 0) | {title: .})' "$titles" + else + printf '[]\n' + fi +fi +STUB +chmod +x "$STUB_BIN/sops" "$STUB_BIN/curl-grist" "$STUB_BIN/curl-pad" + +GRIST_STATE="$TMP/grist-state" +PAD_STATE="$TMP/pad-state" +GRIST_LOG="$TMP/grist-curl.log" +PAD_LOG="$TMP/pad-curl.log" +mkdir -p "$TMP/grist-bin" "$TMP/pad-bin" "$GRIST_STATE" "$PAD_STATE" +ln -s "$STUB_BIN/curl-grist" "$TMP/grist-bin/curl" +ln -s "$STUB_BIN/curl-pad" "$TMP/pad-bin/curl" +: >"$GRIST_LOG" +: >"$PAD_LOG" + +run_grist() { + local phase="$1" output="$2" + env HOME="$HOME_DIR" PATH="$TMP/grist-bin:$STUB_BIN:$SYSTEM_PATH" \ + PM_STACK_SECRETS="$SECRETS_FILE" PM_TEST_SECRETS="$SECRETS_FILE" \ + SOPS_AGE_KEY_FILE="$HOME_DIR/.config/sops/age/keys.txt" \ + SMOKE_PHASE="$phase" SMOKE_STATE="$GRIST_STATE" SMOKE_CURL_LOG="$GRIST_LOG" \ + "$BASH_BIN" "$PM_STACK_DIR/grist/seed.sh" >"$output" 2>&1 +} +run_pad() { + local phase="$1" output="$2" + env HOME="$HOME_DIR" PATH="$TMP/pad-bin:$STUB_BIN:$SYSTEM_PATH" \ + PM_STACK_SECRETS="$SECRETS_FILE" PM_TEST_SECRETS="$SECRETS_FILE" \ + SOPS_AGE_KEY_FILE="$HOME_DIR/.config/sops/age/keys.txt" \ + SMOKE_PHASE="$phase" SMOKE_STATE="$PAD_STATE" SMOKE_CURL_LOG="$PAD_LOG" \ + "$BASH_BIN" "$PM_STACK_DIR/pad/seed.sh" >"$output" 2>&1 +} + +if run_grist first "$TMP/grist-first.out"; then pass 'Grist first seed run completes'; else cat "$TMP/grist-first.out"; fail 'Grist first seed run completes'; fi +if run_grist second "$TMP/grist-second.out"; then pass 'Grist second seed run completes'; else cat "$TMP/grist-second.out"; fail 'Grist second seed run completes'; fi +if contains "$TMP/grist-first.out" 'seeded '; then pass 'Grist first run seeds the initially empty Roadmap'; else fail 'Grist first run seeds the initially empty Roadmap'; fi +if contains "$TMP/grist-second.out" 'skip: Roadmap already has '; then pass 'Grist second run reports existing rows'; else fail 'Grist second run reports existing rows'; fi +if contains "$GRIST_LOG" 'phase=first method=POST path=/api/docs/42/apply action=AddTable' && + contains "$GRIST_LOG" 'phase=first method=POST path=/api/docs/42/apply action=BulkAddRecord'; then + pass 'Grist first run creates the table and writes rows in fake API state' +else + fail 'Grist first run creates the table and writes rows in fake API state' +fi +if ! grep -Fq 'phase=second method=POST' "$GRIST_LOG"; then + pass 'Grist second run performs no creates or row writes' +else + fail 'Grist second run performs no creates or row writes' +fi + +if run_pad first "$TMP/pad-first.out"; then pass 'Pad first seed run completes'; else cat "$TMP/pad-first.out"; fail 'Pad first seed run completes'; fi +if run_pad second "$TMP/pad-second.out"; then pass 'Pad second seed run completes'; else cat "$TMP/pad-second.out"; fail 'Pad second seed run completes'; fi +PAD_TITLES=( + 'Project-management stack — design & phase plan' + 'Phase 1 — as-built (Kaneo execution board)' + 'Phase 2 — plan (dispatch, planning, roadmap layers)' +) +for title in "${PAD_TITLES[@]}"; do + if contains "$TMP/pad-second.out" "skip (exists): [plans] $title"; then + pass "Pad second run skips: $title" + else + fail "Pad second run skips: $title" + fi +done +if [[ $(grep -Fc 'phase=first method=POST' "$PAD_LOG" || true) -eq 3 ]] && + ! grep -Fq 'phase=second method=POST' "$PAD_LOG"; then + pass 'Pad second run performs no creates; all three first-run titles persist' +else + fail 'Pad second run performs no creates; all three first-run titles persist' +fi + +if ((FAILURES)); then + printf 'seed-smoke.test.sh: %d check(s) failed\n' "$FAILURES" + exit 1 +fi +echo 'LIMITATION: SOPS and HTTP are simulated; these checks verify idempotence against fake API state, not a live Grist/Pad deployment.' +echo 'seed-smoke.test.sh: all checks passed'