From 3c7d67fea660ede613530df5871f0499bb8c5ace Mon Sep 17 00:00:00 2001 From: Studio Date: Fri, 27 Nov 2026 13:29:09 -0500 Subject: [PATCH] T-6: Eliminate sandbox git-metadata deadlock for check gates --- AGENTS.md | 6 +++ scripts/test/audit-secrets-repo.test.ts | 53 +++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 scripts/test/audit-secrets-repo.test.ts diff --git a/AGENTS.md b/AGENTS.md index 452eafe9..e17d8648 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -6,6 +6,12 @@ - Typecheck: `bun run typecheck` - Tests: `bun test` (PostgreSQL safety tests require `PIPELINE_TEST_DATABASE_URL` pointing to a dedicated `stock_bot_safety*` database, configured via `/home/boki/.studio/test-env/stock-bot.env`). +### Check Gates & Sandbox Split +- **Why `bun run check` (`scripts/check.ts`) cannot pass end-to-end inside the agent sandbox**: worktree `.git` metadata lives outside the sandbox (breaking `audit:secrets` and the worktree-git tooling tests in `scripts/test/audit-secrets-repo.test.ts`, `strategy-packaging.test.ts`, `benchmark-research.test.ts`, `benchmark-replay.test.ts`, and `benchmark-sma.test.ts`), and sandbox network isolation blocks host PostgreSQL `127.0.0.1:5432` for `PIPELINE_TEST_DATABASE_URL` suites. +- **Sandbox-runnable gates (run locally before handoff)**: `bun run typecheck`, `bun run test:contracts`, `bun run lint:check`, `CARGO_BUILD_JOBS=2 bun run test:native`, `bun run test:utils`, `bun run test:calculations`, and targeted non-git/non-Postgres tests (e.g. `bun test scripts/test/security.test.ts`). +- **Studio unsandboxed verification (`bun run build` and `bun --env-file=/home/boki/.studio/test-env/stock-bot.env test`)**: authoritatively covers `build`, `audit:secrets` (via `scripts/test/audit-secrets-repo.test.ts`), `test:tooling` (including all worktree-git tests), `test:integration`, and PostgreSQL-backed tests. Sandbox-only `.git`/PostgreSQL failures are not a review deadlock when Studio's unsandboxed run is green, and agents must never skip or mock out those checks to make them pass inside the sandbox. +- **Full host verification outside a sandbox**: run `CARGO_BUILD_JOBS=2 bun run check`. + ## Environments (`dev` / `qa` / `prod`) | Environment | `NODE_ENV` | Compose File | PostgreSQL | MongoDB (Write) | MongoDB (Read / Pipeline) | Dragonfly | QuestDB | diff --git a/scripts/test/audit-secrets-repo.test.ts b/scripts/test/audit-secrets-repo.test.ts new file mode 100644 index 00000000..7f325f3b --- /dev/null +++ b/scripts/test/audit-secrets-repo.test.ts @@ -0,0 +1,53 @@ +import { mkdtempSync, rmSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { expect, test } from 'bun:test'; + +const repoRoot = fileURLToPath(new URL('../../', import.meta.url)); +const auditScript = fileURLToPath(new URL('../audit-secrets.ts', import.meta.url)); + +function isolatedGitEnv(baseEnv: NodeJS.ProcessEnv = process.env): Record { + const env: Record = {}; + for (const [key, value] of Object.entries(baseEnv)) { + if (value !== undefined && !key.startsWith('GIT_')) { + env[key] = value; + } + } + return env; +} + +function runAuditSecrets(cwd: string, baseEnv: NodeJS.ProcessEnv = process.env) { + const result = Bun.spawnSync([process.execPath, auditScript], { + cwd, + env: isolatedGitEnv(baseEnv), + stdout: 'pipe', + stderr: 'pipe', + }); + return { + exitCode: result.exitCode, + stdout: new TextDecoder().decode(result.stdout), + stderr: new TextDecoder().decode(result.stderr), + }; +} + +test('audit:secrets passes on the real repository', () => { + const result = runAuditSecrets(repoRoot); + + expect(result.exitCode, result.stderr).toBe(0); + expect(result.stderr).toBe(''); + expect(result.stdout).toContain('Secret audit passed'); +}); + +test('audit:secrets fails closed when git metadata is unavailable', () => { + const tempDir = mkdtempSync(join(tmpdir(), 'audit-secrets-no-git-')); + + try { + const result = runAuditSecrets(tempDir); + + expect(result.exitCode).not.toBe(0); + expect(result.stderr).toContain('Cannot inspect tracked files for the secret audit'); + } finally { + rmSync(tempDir, { recursive: true, force: true }); + } +});