Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

test: prove the autofixer verify sandbox in the Linux containment job (#12487)

[._.]/ Adam Eivya9e25cd11ce0
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index c910ae519a..de853d92bb 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -1217,7 +1217,7 @@ jobs:
PORTOS_REQUIRE_LINUX_CONTAINMENT: '1'
# Keep this list equal to the impact planner's LINUX_CONTAINMENT_TESTS:
# the job is gated on those files' import closure.
- run: npm test --prefix server -- --run lib/codeAnimationContainment.test.js routes/codeAnimationExecution.test.js services/codeAnimation/containedWorker.test.js
+ run: npm test --prefix server -- --run ../autofixer/sandbox.verify.test.js lib/codeAnimationContainment.test.js routes/codeAnimationExecution.test.js services/codeAnimation/containedWorker.test.js
gate:
name: CI Gate
diff --git a/autofixer/sandbox.js b/autofixer/sandbox.js
index 01491a3e0b..72f4eef60e 100644
--- a/autofixer/sandbox.js
+++ b/autofixer/sandbox.js
@@ -29,7 +29,7 @@
import { spawn } from 'child_process';
import { waitForChild, COMMAND_TIMEOUT_MS } from './childProcess.js';
-import { writeFile, rm, mkdir, mkdtemp, readdir, realpath, stat, access } from 'fs/promises';
+import { writeFile, rm, mkdir, mkdtemp, readdir, realpath, lstat, access } from 'fs/promises';
import { constants as fsConstants } from 'fs';
import { join, isAbsolute, normalize, resolve, dirname } from 'path';
import { homedir, tmpdir } from 'os';
@@ -480,7 +480,7 @@ export async function probeVerifyContainment() {
return codeAnimationContainmentMechanism('linux', false, { reason: 'install bubblewrap (/usr/bin/bwrap) to verify autofixes' });
}
const child = spawn(CODE_ANIMATION_BUBBLEWRAP, ['--unshare-all', '--die-with-parent', '--ro-bind', '/', '/', '--', '/bin/true'], {
- cwd: '/', env: {}, stdio: ['ignore', 'ignore', 'ignore'],
+ cwd: '/', env: {}, windowsHide: true, stdio: ['ignore', 'ignore', 'ignore'],
});
const { code } = await waitForChild(child, { timeoutMs: 5000, capture: false });
return codeAnimationContainmentMechanism('linux', false, {
@@ -571,11 +571,14 @@ export async function runVerifyCommand(command, cwd, { dataDir = null, homeDir =
launch = [CODE_ANIMATION_SEATBELT, ['-p', autofixVerifySeatbeltProfile({ worktree, scratch, protectedPaths }), ...shell]];
} else {
seccomp = autofixVerifySeccompFilter(process.arch);
- const present = await Promise.all(protectedPaths.map(async (path) => [path, await stat(path).catch(() => null)]));
+ // bwrap mounts over each path, so a symlink is skipped: its resolved
+ // target is already listed and is what the mount must cover.
+ const present = (await Promise.all(protectedPaths.map(async (path) => [path, await lstat(path).catch(() => null)])))
+ .filter(([, info]) => info && !info.isSymbolicLink());
const bwrapArgs = autofixVerifyBubblewrapArgs({
worktree, scratch, env,
protectedDirs: present.filter(([, info]) => info?.isDirectory()).map(([path]) => path),
- protectedFiles: present.filter(([, info]) => info && !info.isDirectory()).map(([path]) => path),
+ protectedFiles: present.filter(([, info]) => !info.isDirectory()).map(([path]) => path),
});
launch = [CODE_ANIMATION_BUBBLEWRAP, [...bwrapArgs, ...shell]];
}
diff --git a/autofixer/sandbox.verify.test.js b/autofixer/sandbox.verify.test.js
index 3d10ad121c..d807b457e1 100644
--- a/autofixer/sandbox.verify.test.js
+++ b/autofixer/sandbox.verify.test.js
@@ -7,6 +7,9 @@ import { probeVerifyContainment, runVerifyCommand } from './sandbox.js';
// The real OS boundary an agent-written test file or npm lifecycle script meets.
const mechanism = await probeVerifyContainment();
+if (process.env.PORTOS_REQUIRE_LINUX_CONTAINMENT === '1' && mechanism.id !== 'linux-bubblewrap') {
+ throw new Error(`Real Linux containment is required by this test job: ${mechanism.reason}`);
+}
describe.skipIf(!mechanism.supported)(`runVerifyCommand under ${mechanism.id || 'no containment'}`, () => {
let root;
diff --git a/scripts/ci-test-plan.js b/scripts/ci-test-plan.js
index e7c1281d60..55f89c604c 100644
--- a/scripts/ci-test-plan.js
+++ b/scripts/ci-test-plan.js
@@ -610,6 +610,7 @@ export const PROMPT_HISTORY_GUARD = 'scripts/migrations/check-shipped-prompt-his
export const PROMPT_HISTORY_PATH_RE = /^(?:scripts\/migrations\/|data\.reference\/prompts\/|server\/services\/taskPromptDefaults(?:\/|\.js$)|scripts\/regen-prompt-integrity-snapshot(?:\.test)?\.js$|\.github\/workflows\/ci\.yml$)/;
// The files the `linux-containment` job passes to `npm test --prefix server`.
export const LINUX_CONTAINMENT_TESTS = [
+ 'autofixer/sandbox.verify.test.js',
'server/lib/codeAnimationContainment.test.js',
'server/routes/codeAnimationExecution.test.js',
'server/services/codeAnimation/containedWorker.test.js',
diff --git a/scripts/ci-test-plan.test.js b/scripts/ci-test-plan.test.js
index ea2e0f9e28..0697c87f34 100644
--- a/scripts/ci-test-plan.test.js
+++ b/scripts/ci-test-plan.test.js
@@ -2,7 +2,7 @@ import { describe, expect, it, vi } from 'vitest';
import { execFileSync } from 'node:child_process';
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
-import { dirname, join } from 'node:path';
+import { dirname, join, posix } from 'node:path';
import { fileURLToPath } from 'node:url';
import { resolveDbTestFiles } from './lib/dbTestFiles.js';
import { staticImportClosure } from '../server/lib/staticImportGraph.js';
@@ -1979,7 +1979,7 @@ describe('path-gated single-purpose jobs', () => {
expect(jobs['linux-containment']).toContain("if: needs.impact.outputs.linux_containment == 'true'");
// The gate walks LINUX_CONTAINMENT_TESTS, so the job must run exactly those.
const run = jobs['linux-containment'].match(/run: npm test --prefix server -- --run (.*)/)[1];
- expect(run.split(' ').map((path) => `server/${path}`)).toEqual(LINUX_CONTAINMENT_TESTS);
+ expect(run.split(' ').map((path) => posix.join('server', path))).toEqual(LINUX_CONTAINMENT_TESTS);
// A skipped gated job still reports to CI Gate, which treats skipped as passing.
expect(jobs.gate).toContain('CI_GATE_RESULT_PROMPT_HISTORY: ${{ needs.prompt-history.result }}');
expect(jobs.gate).toContain('CI_GATE_RESULT_LINUX_CONTAINMENT: ${{ needs.linux-containment.result }}');