Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(ci): refuse admin/dist hydration only on an unreadable tracked file (#6756)

garrytan6b9c848b51c8
diff --git a/docs/architecture/key-files/entrypoints-and-docs.md b/docs/architecture/key-files/entrypoints-and-docs.md
index 0f8baadeb1..c1e13c70bc 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`; #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`.
+- `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 only when a file `git ls-files admin/dist` tracks cannot be read from the worktree (the message names the file and `bun run build:admin`); 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.sh
index f7730c2264..c426228473 100755
--- a/scripts/ci-hydrate-admin-dist.sh
+++ b/scripts/ci-hydrate-admin-dist.sh
@@ -6,14 +6,24 @@
# 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>
+# build removed. It refuses only when a file git tracks under admin/dist
+# cannot be read from the worktree, naming the file and the admin build.
+# Run from the repository root (the tracked list comes from git ls-files).
+# 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
+tracked=$(git ls-files admin/dist)
+if [ -z "$tracked" ]; then
+ echo "[runner] ERROR: git tracks no files under admin/dist, so there is nothing to hydrate the admin/dist volume from. Build it with bun run build:admin, or restore it with git checkout -- admin/dist, and rerun ci:local." >&2
exit 1
fi
+while IFS= read -r path; do
+ if [ ! -r "$src/${path#admin/dist/}" ]; then
+ echo "[runner] ERROR: $path is tracked but cannot be read from the worktree ($src/${path#admin/dist/}), so the admin/dist volume was not hydrated. Restore it with git checkout -- $path, or rebuild the bundle with bun run build:admin, and rerun ci:local." >&2
+ exit 1
+ fi
+done <<< "$tracked"
mkdir -p "$dest"
find "$dest" -mindepth 1 -delete
cp -R "$src/." "$dest/"
diff --git a/test/scripts/ci-hydrate-admin-dist.test.ts b/test/scripts/ci-hydrate-admin-dist.test.ts
index d647d05adf..a804524147 100644
--- a/test/scripts/ci-hydrate-admin-dist.test.ts
+++ b/test/scripts/ci-hydrate-admin-dist.test.ts
@@ -4,7 +4,8 @@
* `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.
+ * the current worktree bytes, stale hashed files removed. It refuses only
+ * when a tracked admin/dist file cannot be read, naming it and the admin build.
*/
import { afterAll, describe, expect, test } from 'bun:test';
import { spawnSync } from 'node:child_process';
@@ -17,9 +18,7 @@ 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);
+function write(dir: string, files: Record<string, string>): string {
for (const [rel, body] of Object.entries(files)) {
mkdirSync(join(dir, rel, '..'), { recursive: true });
writeFileSync(join(dir, rel), body);
@@ -27,6 +26,22 @@ function tree(files: Record<string, string>): string {
return dir;
}
+function tree(files: Record<string, string>): string {
+ const dir = mkdtempSync(join(tmpdir(), 'gbrain-admin-dist-'));
+ homes.push(dir);
+ return write(dir, files);
+}
+
+/** A checkout whose admin/dist holds `files`, all tracked by git (index only). */
+function checkout(files: Record<string, string>): string {
+ const repo = tree({});
+ write(join(repo, 'admin', 'dist'), files);
+ const git = (...args: string[]) => spawnSync('git', ['-C', repo, ...args], { encoding: 'utf8' });
+ expect(git('init', '-q').status).toBe(0);
+ expect(git('add', 'admin/dist').status).toBe(0);
+ return repo;
+}
+
function listing(dir: string): Record<string, string> {
const out: Record<string, string> = {};
const walk = (rel: string) => {
@@ -39,44 +54,54 @@ function listing(dir: string): Record<string, string> {
return out;
}
-const hydrate = (src: string, dest: string) => spawnSync('bash', [SCRIPT, src, dest], { encoding: 'utf8' });
+const hydrate = (repo: string, dest: string) => spawnSync('bash', [SCRIPT, join(repo, 'admin', 'dist'), dest], { cwd: repo, 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);
+ const repo = checkout(WORKTREE), dest = join(tree({}), 'dist');
+ const r = hydrate(repo, 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);
+ const repo = checkout(WORKTREE), dest = tree(WORKTREE);
+ expect(hydrate(repo, 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('changed bundle: uncommitted worktree bytes win over the volume', () => {
+ const repo = checkout(WORKTREE), dest = tree(WORKTREE);
+ writeFileSync(join(repo, 'admin', 'dist', 'assets', 'logo.svg'), '<svg edited/>');
+ expect(hydrate(repo, dest).status).toBe(0);
+ expect(listing(dest)).toEqual({ ...WORKTREE, 'assets/logo.svg': '<svg edited/>' });
});
test('deleted bundle: stale hashed files from an older build are removed', () => {
- const src = tree(WORKTREE);
+ const repo = checkout(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(hydrate(repo, 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);
+ test('a tracked file missing from the worktree refuses, naming the file and the admin build, and leaves the volume alone', () => {
+ const repo = checkout(WORKTREE), dest = tree({ 'index.html': 'kept' });
+ rmSync(join(repo, 'admin', 'dist', 'assets', 'index-NEW.js'));
+ const r = hydrate(repo, dest);
expect(r.status).toBe(1);
- expect(r.stderr).toContain('git checkout -- admin/dist');
+ expect(r.stderr).toContain('admin/dist/assets/index-NEW.js is tracked but cannot be read');
+ expect(r.stderr).toContain('bun run build:admin');
expect(listing(dest)).toEqual({ 'index.html': 'kept' });
});
+ test('an untracked file in the worktree is copied too; only tracked files gate the refusal', () => {
+ const repo = checkout(WORKTREE), dest = tree({});
+ writeFileSync(join(repo, 'admin', 'dist', 'local-only.txt'), 'untracked');
+ expect(hydrate(repo, dest).status).toBe(0);
+ expect(listing(dest)).toEqual({ ...WORKTREE, 'local-only.txt': 'untracked' });
+ });
+
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');