Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(ci): hydrate the admin/dist volume from the worktree in ci:local (#6756)
garrytan7d555b5c57d1
diff --git a/docker-compose.ci.yml b/docker-compose.ci.ymlindex a082478fd9..dfd114a9c3 100644--- a/docker-compose.ci.yml+++ b/docker-compose.ci.yml@@ -156,6 +156,9 @@ services:- gbrain-ci-node-modules:/app/node_modules- gbrain-ci-admin-node-modules:/app/admin/node_modules- gbrain-ci-admin-dist:/app/admin/dist+ # #6756: the worktree's admin/dist, read-only, outside /app; the runner+ # copies it into the volume above before building (scripts/ci-hydrate-admin-dist.sh).+ - ./admin/dist:/ci-src/admin-dist:ro# Compiled CLI tests must execute a Linux binary, never a host Mac build.- gbrain-ci-bin:/app/bin# Warm install cache across runs.diff --git a/docs/architecture/key-files/entrypoints-and-docs.md b/docs/architecture/key-files/entrypoints-and-docs.mdindex 6a210feea6..0f8baadeb1 100644--- a/docs/architecture/key-files/entrypoints-and-docs.md+++ b/docs/architecture/key-files/entrypoints-and-docs.md@@ -13,7 +13,7 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL- `admin/` — React 19 + Vite + TypeScript admin SPA embedded in the binary via `admin/dist/` served by `serve-http.ts`. Views: Login (bootstrap token or single-use link → session cookie, preserving pending OAuth consent), Dashboard (metrics + SSE feed + token health), Agents (client table + registration), Register (machine/public PKCE/confidential PKCE with permission preview), Client Setup (method-aware instructions + explicit recoverable private download), Request Log (filterable paginated), Agent Detail drawer (setup, permission review, request activity, and token invalidation/revocation/deletion). Design tokens: `#0a0a0f` bg, Inter for UI, JetBrains Mono for data, 4-32px spacing scale, rounded pill badges. HTTP-only SameSite=Strict cookie auth. About 79KiB gzip for JS/CSS assets. Build: `cd admin && bun install && bun run build`; output at `admin/dist/` is committed for self-contained binaries.-- `docker-compose.ci.yml` + `scripts/ci-local.sh` — Local CI gate. `bun run ci:local` spins up four `pgvector/pgvector:pg16` services (postgres-1..4) + `oven/bun:${GBRAIN_CI_BUN_TAG:-1.4.2}` with named volumes (`gbrain-ci-pg-data-{1..4}`, `gbrain-ci-node-modules`, `gbrain-ci-admin-node-modules`, `gbrain-ci-admin-dist`, `gbrain-ci-bun-cache`), runs gitleaks on host, smoke-tests `scripts/run-e2e.sh` argv handling, runs the authoritative `bun run verify` once plus the explicit Bun test-timeout guard, then the complete serial and slow lanes before 4-shard parallel unit + E2E (`xargs -P4`, one Postgres per shard; unit phase keeps `DATABASE_URL` unset). `--no-shard` runs unit/E2E sequentially (debug aid); `--diff` narrows E2E selection without changing the chosen shard mode. The doc-only `--diff` fast path runs only the host secrets scans. Also runs a `pgbouncer` service (`edoburu/pgbouncer`, `POOL_MODE: transaction`, `AUTH_TYPE: plain` — pg16 stores SCRAM verifiers, so the userlist must hold the plaintext password; `IGNORE_STARTUP_PARAMETERS` whitelists gbrain's `statement_timeout`/`idle_in_transaction_session_timeout` startup params the way the Supabase pooler does) fronting postgres-1 on host port `GBRAIN_CI_PGBOUNCER_PORT` (default 6543); every E2E invocation exports `GBRAIN_PGBOUNCER_URL` (pooled; dedicated `gbrain_pgbouncer_test` database so it never races the `gbrain_test` TRUNCATE fixtures) + `GBRAIN_PGBOUNCER_DIRECT_URL`, consumed by `test/e2e/pgbouncer-teardown.test.ts` — which reproduces the transaction-mode teardown failure in the local gate. `--no-pull` skips upstream pulls; `--clean` nukes named volumes. Postgres host port defaults to 5434; override with `GBRAIN_CI_PG_PORT=NNNN`. Full persistence and native runtime matrices run separately; see `docs/TESTING.md`.+- `docker-compose.ci.yml` + `scripts/ci-local.sh` — Local CI gate. `bun run ci:local` spins up four `pgvector/pgvector:pg16` services (postgres-1..4) + `oven/bun:${GBRAIN_CI_BUN_TAG:-1.4.2}` with named volumes (`gbrain-ci-pg-data-{1..4}`, `gbrain-ci-node-modules`, `gbrain-ci-admin-node-modules`, `gbrain-ci-admin-dist`, `gbrain-ci-bun-cache`; #6756: the runner mounts the worktree's `admin/dist` read-only at `/ci-src/admin-dist` and `scripts/ci-hydrate-admin-dist.sh` makes the `gbrain-ci-admin-dist` volume an exact copy of it, stale hashed files removed, before `bun run build`, refusing with the restore command when `admin/dist/index.html` is missing; pinned by `test/scripts/ci-hydrate-admin-dist.test.ts`), runs gitleaks on host, smoke-tests `scripts/run-e2e.sh` argv handling, runs the authoritative `bun run verify` once plus the explicit Bun test-timeout guard, then the complete serial and slow lanes before 4-shard parallel unit + E2E (`xargs -P4`, one Postgres per shard; unit phase keeps `DATABASE_URL` unset). `--no-shard` runs unit/E2E sequentially (debug aid); `--diff` narrows E2E selection without changing the chosen shard mode. The doc-only `--diff` fast path runs only the host secrets scans. Also runs a `pgbouncer` service (`edoburu/pgbouncer`, `POOL_MODE: transaction`, `AUTH_TYPE: plain` — pg16 stores SCRAM verifiers, so the userlist must hold the plaintext password; `IGNORE_STARTUP_PARAMETERS` whitelists gbrain's `statement_timeout`/`idle_in_transaction_session_timeout` startup params the way the Supabase pooler does) fronting postgres-1 on host port `GBRAIN_CI_PGBOUNCER_PORT` (default 6543); every E2E invocation exports `GBRAIN_PGBOUNCER_URL` (pooled; dedicated `gbrain_pgbouncer_test` database so it never races the `gbrain_test` TRUNCATE fixtures) + `GBRAIN_PGBOUNCER_DIRECT_URL`, consumed by `test/e2e/pgbouncer-teardown.test.ts` — which reproduces the transaction-mode teardown failure in the local gate. `--no-pull` skips upstream pulls; `--clean` nukes named volumes. Postgres host port defaults to 5434; override with `GBRAIN_CI_PG_PORT=NNNN`. Full persistence and native runtime matrices run separately; see `docs/TESTING.md`.- `docs/UPGRADING_DOWNSTREAM_AGENTS.md` — Patches for downstream agent skill forks to apply when upgrading. Each release appends a new section; includes diffs for brain-ops, meeting-ingestion, signal-detector, enrich.diff --git a/scripts/ci-hydrate-admin-dist.sh b/scripts/ci-hydrate-admin-dist.shnew file mode 100755index 0000000000..f7730c2264--- /dev/null+++ b/scripts/ci-hydrate-admin-dist.sh@@ -0,0 +1,20 @@+#!/usr/bin/env bash+# #6756: ci:local mounts the named volume gbrain-ci-admin-dist over+# /app/admin/dist (so the container's builds never write the host checkout),+# and a new named volume starts empty: a fresh checkout's `bun run build` then+# failed on the hashed bundles src/admin-embedded.ts imports. The runner calls+# this before the build to make the volume an exact copy of the worktree's+# admin/dist (mounted read-only at /ci-src/admin-dist): the current worktree+# bytes, uncommitted changes included, with stale hashed files from an older+# build removed. Usage: ci-hydrate-admin-dist.sh <worktree admin/dist> <volume admin/dist>+set -euo pipefail+src="${1:?usage: ci-hydrate-admin-dist.sh <worktree admin/dist> <volume admin/dist>}"+dest="${2:?usage: ci-hydrate-admin-dist.sh <worktree admin/dist> <volume admin/dist>}"+if [ ! -f "$src/index.html" ]; then+ echo "[runner] ERROR: $src/index.html is missing, so the worktree's committed admin/dist is absent and the CLI build cannot embed it. Restore it with git checkout -- admin/dist (or rebuild it with bun run build:admin) and rerun ci:local." >&2+ exit 1+fi+mkdir -p "$dest"+find "$dest" -mindepth 1 -delete+cp -R "$src/." "$dest/"+echo "[runner] admin/dist hydrated from the worktree ($(find "$dest" -type f | wc -l | tr -d ' ') files)"diff --git a/scripts/ci-local.sh b/scripts/ci-local.shindex 504f38858a..e7a0cb36fa 100755--- a/scripts/ci-local.sh+++ b/scripts/ci-local.sh@@ -286,6 +286,8 @@ fi# Container runs as root (uid 0) against a host-uid bind-mount; mark repo +# any worktree gitdir as safe so `git status` etc. don't refuse.git config --global --add safe.directory '*' || true+# #6756: the admin/dist volume starts empty on a fresh checkout; make it the worktree's bytes.+bash scripts/ci-hydrate-admin-dist.sh /ci-src/admin-dist admin/dist# Revalidate even a warm dependency volume against this checkout's lockfile.echo "[runner] bun install --frozen-lockfile"bun install --frozen-lockfilediff --git a/test/scripts/ci-hydrate-admin-dist.test.ts b/test/scripts/ci-hydrate-admin-dist.test.tsnew file mode 100644index 0000000000..d647d05adf--- /dev/null+++ b/test/scripts/ci-hydrate-admin-dist.test.ts@@ -0,0 +1,91 @@+/**+ * #6756: ci:local mounts the named volume gbrain-ci-admin-dist over+ * /app/admin/dist, and a new named volume starts empty, so a fresh checkout's+ * `bun run build` failed on the hashed admin bundles src/admin-embedded.ts+ * imports. The runner now copies the worktree's admin/dist (mounted read-only+ * at /ci-src/admin-dist) into the volume before the build: an exact copy of+ * the current worktree bytes, stale hashed files removed.+ */+import { afterAll, describe, expect, test } from 'bun:test';+import { spawnSync } from 'node:child_process';+import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';++const ROOT = join(import.meta.dir, '../..');+const SCRIPT = join(ROOT, 'scripts/ci-hydrate-admin-dist.sh');+const homes: string[] = [];+afterAll(() => { for (const h of homes) rmSync(h, { recursive: true, force: true }); });++function tree(files: Record<string, string>): string {+ const dir = mkdtempSync(join(tmpdir(), 'gbrain-admin-dist-'));+ homes.push(dir);+ for (const [rel, body] of Object.entries(files)) {+ mkdirSync(join(dir, rel, '..'), { recursive: true });+ writeFileSync(join(dir, rel), body);+ }+ return dir;+}++function listing(dir: string): Record<string, string> {+ const out: Record<string, string> = {};+ const walk = (rel: string) => {+ for (const e of readdirSync(join(dir, rel), { withFileTypes: true })) {+ const r = rel ? `${rel}/${e.name}` : e.name;+ if (e.isDirectory()) walk(r); else out[r] = readFileSync(join(dir, r), 'utf8');+ }+ };+ walk('');+ return out;+}++const hydrate = (src: string, dest: string) => spawnSync('bash', [SCRIPT, src, dest], { encoding: 'utf8' });+const WORKTREE = { 'index.html': '<script src="/assets/index-NEW.js">', 'assets/index-NEW.js': 'new bundle', 'assets/logo.svg': '<svg/>' };++describe('#6756 ci:local hydrates the admin/dist volume from the worktree', () => {+ test('cold: an empty volume gets the worktree bytes', () => {+ const src = tree(WORKTREE), dest = join(tree({}), 'dist');+ const r = hydrate(src, dest);+ expect(r.status, r.stderr).toBe(0);+ expect(listing(dest)).toEqual(WORKTREE);+ });++ test('warm: a volume already matching stays identical', () => {+ const src = tree(WORKTREE), dest = tree(WORKTREE);+ expect(hydrate(src, dest).status).toBe(0);+ expect(listing(dest)).toEqual(WORKTREE);+ });++ test('changed bundle: a file whose bytes changed in the worktree is replaced', () => {+ const src = tree(WORKTREE), dest = tree({ ...WORKTREE, 'assets/logo.svg': '<svg old/>' });+ expect(hydrate(src, dest).status).toBe(0);+ expect(listing(dest)).toEqual(WORKTREE);+ });++ test('deleted bundle: stale hashed files from an older build are removed', () => {+ const src = tree(WORKTREE);+ const dest = tree({ 'index.html': '<script src="/assets/index-OLD.js">', 'assets/index-OLD.js': 'old bundle', '.vite/manifest.json': '{}' });+ expect(hydrate(src, dest).status).toBe(0);+ expect(listing(dest)).toEqual(WORKTREE);+ });++ test('a worktree without admin/dist/index.html refuses with the remedy and leaves the volume alone', () => {+ const src = tree({}), dest = tree({ 'index.html': 'kept' });+ const r = hydrate(src, dest);+ expect(r.status).toBe(1);+ expect(r.stderr).toContain('git checkout -- admin/dist');+ expect(listing(dest)).toEqual({ 'index.html': 'kept' });+ });++ test('the runner mounts the worktree admin/dist read-only and hydrates after git setup, before the build', () => {+ const compose = Bun.YAML.parse(readFileSync(join(ROOT, 'docker-compose.ci.yml'), 'utf8')) as { services: { runner: { volumes: string[] } } };+ expect(compose.services.runner.volumes).toContain('./admin/dist:/ci-src/admin-dist:ro');+ expect(compose.services.runner.volumes).toContain('gbrain-ci-admin-dist:/app/admin/dist');+ const source = readFileSync(join(ROOT, 'scripts/ci-local.sh'), 'utf8');+ const template = source.slice(source.indexOf("INNER_CMD=$(cat <<'EOF'"), source.indexOf('__RUN_PHASES__'));+ const hydrateAt = template.indexOf('bash scripts/ci-hydrate-admin-dist.sh /ci-src/admin-dist admin/dist');+ expect(hydrateAt).toBeGreaterThan(template.indexOf('safe.directory'));+ expect(hydrateAt).toBeLessThan(template.indexOf('bun run build'));+ expect(existsSync(SCRIPT)).toBe(true);+ });+});diff --git a/test/scripts/ci-local-rendering.test.ts b/test/scripts/ci-local-rendering.test.tsindex 813903d346..b2ef68c0f8 100644--- a/test/scripts/ci-local-rendering.test.ts+++ b/test/scripts/ci-local-rendering.test.ts@@ -55,6 +55,8 @@ describe('ci-local command rendering', () => {writeFileSync(join(bin, name), '#!/bin/sh\nexit 0\n', { mode: 0o755 });}writeFileSync(join(bin, 'apt-get'), '#!/bin/sh\nprintf "%s\\n" "$*" >> "$INSTALL_LOG"\n', { mode: 0o755 });+ mkdirSync(join(home, 'scripts'));+ writeFileSync(join(home, 'scripts', 'ci-hydrate-admin-dist.sh'), 'exit 0\n');const phaseLog = join(home, 'phase.log');const installLog = join(home, 'install.log');const phases = [@@ -106,6 +108,7 @@ function runPhases(noShard: boolean, diff: boolean, failStage = '') {const trace = join(home, 'trace');const put = (path: string, body: string) => writeFileSync(join(home, path), `#!/bin/bash\n${body}\n`, { mode: 0o755 });for (const name of ['git', 'python3', 'ps', 'psql', 'apt-get']) put(`bin/${name}`, 'exit 0');+ put('scripts/ci-hydrate-admin-dist.sh', 'exit 0');put('bin/bun', `case "$*" in"scripts/lib/ensure-e2e-database.ts "*)