`` | end';
+ cell.evidence = ['validated-test:test\\source.ts::handles | values'];
+ const page = render(fixture);
+ const section = page.split('### dual-root-remote-mode\n')[1]!;
+ const row = section.split('\n').find((line) => line.startsWith('| `opencode` |'))!;
+ const html = new MarkdownIt({ html: true }).render([
+ '| Host | Capability | Validation | Mechanism | Evidence |',
+ '| --- | --- | --- | --- | --- |',
+ row,
+ ].join('\n'));
+ expect(html.match(//g)).toHaveLength(5);
+ expect(html).toContain('..\\base');
+ expect(html).toContain('quoted ` ..\\root');
+ expect(html).toContain('a\\|*bold* [link](url) `tick` & <tag>');
+ expect(html).toContain('validated-test:test\\source.ts::handles | values');
+ });
+
+ it('preserves Markdown escapes while keeping plain pipes in the same table cell', async () => {
+ const { render } = (await import(RENDERER)) as { render: (m: unknown) => string };
+ const fixture = structuredClone(matrix);
+ const feature = fixture.features.find((f) => f.id === 'dual-root-remote-mode')!;
+ feature.cells['opencode']!.mechanism = String.raw`before \*literal\* a\|b c\\|d e\\\|f`;
+ const section = render(fixture).split('### dual-root-remote-mode\n')[1]!;
+ const row = section.split('\n').find((line) => line.startsWith('| `opencode` |'))!;
+ const html = new MarkdownIt().render([
+ '| Host | Capability | Validation | Mechanism | Evidence |',
+ '| --- | --- | --- | --- | --- |',
+ row,
+ ].join('\n'));
+
+ expect(html.match(/ | /g)).toHaveLength(5);
+ expect(html).toContain(String.raw`before *literal* a|b c\|d e\|f`);
+ expect(html).not.toContain('literal');
+ });
});
// โโโ 2. bridge scenarios (deterministic; no CLI, no model) โโโโโโโโโโโโโโโโโโ
diff --git a/test/squad-20-preview-tarball-matrix.test.ts b/test/squad-20-preview-tarball-matrix.test.ts
index 8e32213e0..9a3a65ffd 100644
--- a/test/squad-20-preview-tarball-matrix.test.ts
+++ b/test/squad-20-preview-tarball-matrix.test.ts
@@ -339,6 +339,12 @@ describe('upgrade-matrix.json integrity', () => {
// โโโ harness guards (always on) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
describe('upgrade-matrix harness guards', () => {
+ it('passes metacharacters in npm arguments literally', async () => {
+ const prefix = path.join(ROOT, 'matrix test & literal');
+ const result = await npmCmd(['config', 'get', 'prefix', '--prefix', prefix], ROOT, process.env);
+ expect(result.code, result.stderr).toBe(0);
+ expect(result.stdout.trim()).toBe(prefix);
+ });
const fakeSpec = (over: Partial = {}): ProducerSpec => ({
version: '0.0.0-guard', source: 'github-release', why: 'guard test', supports: { stateBackend: true, dryRun: true },
artifacts: { release: { repository: 'bradygaster/squad', tag: 'v0.0.0-guard', assets: {} } },
@@ -686,12 +692,10 @@ async function fetchBuffer(url: string, headers: Record = {}): P
}
async function npmCmd(args: string[], cwd: string, env: NodeJS.ProcessEnv): Promise {
- const npm = PLATFORM === 'win32' ? 'npm.cmd' : 'npm';
- // Absolute tarball paths: a bare `dir/file.tgz` would be read by npm as a GitHub `owner/repo` shorthand.
- const quoted = args.map((a) => (/\s/.test(a) ? `"${a}"` : a));
- return PLATFORM === 'win32'
- ? run(process.env['ComSpec'] ?? 'cmd.exe', ['/d', '/s', '/c', `${npm} ${quoted.join(' ')}`], { cwd, env, timeout: 600_000 })
- : run(npm, args, { cwd, env, timeout: 600_000 });
+ if (PLATFORM !== 'win32') return run('npm', args, { cwd, env, timeout: 600_000 });
+ const npmCli = path.join(path.dirname(process.execPath), 'node_modules', 'npm', 'bin', 'npm-cli.js');
+ if (!fs.existsSync(npmCli)) throw new Error(`npm CLI not found beside Node: ${npmCli}`);
+ return run(process.execPath, [npmCli, ...args], { cwd, env, timeout: 600_000 });
}
/**
diff --git a/test/squad-20-upgrade-matrix.test.ts b/test/squad-20-upgrade-matrix.test.ts
index 30e5caa28..207ee093c 100644
--- a/test/squad-20-upgrade-matrix.test.ts
+++ b/test/squad-20-upgrade-matrix.test.ts
@@ -29,7 +29,7 @@
* `node scripts/render-upgrade-matrix.mjs --merge `.
*/
-import { afterAll, beforeAll, describe, expect, it } from 'vitest';
+import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';
import { execFile, execFileSync } from 'node:child_process';
import http from 'node:http';
import type { AddressInfo } from 'node:net';
@@ -96,6 +96,7 @@ interface Matrix {
inapplicable: Inapplicable[];
expectedFailures: ExpectedFailure[];
findings: Finding[];
+ historicalRuns?: Run[];
runs: Run[];
}
@@ -274,6 +275,15 @@ describe('upgrade-matrix.json integrity', () => {
}
});
+ it('retains previous runs with their original attribution', () => {
+ for (const run of matrix.historicalRuns ?? []) {
+ expect(run.targetSha).toMatch(/^[0-9a-f]{40}$/);
+ expect(run.harnessHash).toMatch(/^[0-9a-f]{64}$/);
+ expect(run.runUrl).toMatch(/^https:\/\/github\.com\/github\/squad\/actions\/runs\/\d+$/);
+ expect(run.results.length).toBeGreaterThan(0);
+ }
+ });
+
it('the "Tested upgrade paths" section of upgrading.md is up to date with the JSON', async () => {
const { renderSection, extractSection } = (await import(RENDERER)) as {
renderSection: (m: unknown) => string;
@@ -288,6 +298,84 @@ describe('upgrade-matrix.json integrity', () => {
// โโโ harness guards (always on) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
describe('upgrade-matrix harness guards', () => {
+ it('scrubs inherited Node settings but preserves explicit scenario instrumentation', () => {
+ vi.stubEnv('NODE_OPTIONS', '--require inherited-hook.cjs');
+ vi.stubEnv('NODE_PATH', 'inherited-path');
+ vi.stubEnv('SQUAD_CLI', 'inherited-cli');
+ try {
+ const clean = isolatedEnv('isolated-home');
+ expect(clean.HOME).toBe('isolated-home');
+ expect(clean.USERPROFILE).toBe('isolated-home');
+ expect(clean.NODE_OPTIONS).toContain('profile-fs-guard.cjs');
+ expect(clean.NODE_OPTIONS).not.toContain('inherited-hook.cjs');
+ expect(clean.NODE_PATH).toBeUndefined();
+ expect(clean.SQUAD_CLI).toBeUndefined();
+ const instrumented = isolatedEnv('isolated-home', {
+ NODE_OPTIONS: '--require scenario-hook.cjs',
+ NODE_PATH: 'scenario-path',
+ SQUAD_CLI: 'scenario-cli',
+ });
+ expect(instrumented.NODE_OPTIONS).toContain('profile-fs-guard.cjs');
+ expect(instrumented.NODE_OPTIONS).toContain('--require scenario-hook.cjs');
+ expect(instrumented.NODE_PATH).toBe('scenario-path');
+ expect(instrumented.SQUAD_CLI).toBe('scenario-cli');
+ } finally {
+ vi.unstubAllEnvs();
+ }
+ });
+
+ it('records profile probes without breaking native realpath', async () => {
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'squad-matrix-fs-watch-'));
+ try {
+ const profile = path.join(dir, 'profile');
+ const log = path.join(dir, 'access.log');
+ fs.mkdirSync(profile);
+ const script = [
+ "const fs = require('node:fs');",
+ "const path = require('node:path');",
+ "fs.realpathSync.native(process.env.SQUAD_MATRIX_FS_WATCH_ROOT);",
+ "fs.existsSync(path.join(process.env.SQUAD_MATRIX_FS_WATCH_ROOT, 'missing'));",
+ ].join('\n');
+ const result = await run(process.execPath, ['-e', script], {
+ cwd: dir,
+ env: {
+ ...process.env,
+ NODE_OPTIONS: `--require ${JSON.stringify(FS_HOOK)}`,
+ SQUAD_MATRIX_FS_WATCH_ROOT: profile,
+ SQUAD_MATRIX_FS_WATCH_LOG: log,
+ },
+ });
+ expect(result.code, result.stderr).toBe(0);
+ const recorded = fs.readFileSync(log, 'utf8');
+ expect(recorded).toContain('fs.realpathSync.native');
+ expect(recorded).toContain('fs.existsSync');
+ } finally {
+ fs.rmSync(dir, { recursive: true, force: true });
+ }
+ });
+
+ it('passes metacharacters in npm arguments literally', async () => {
+ const prefix = path.join(ROOT, 'matrix test & literal');
+ const result = await npmCmd(['config', 'get', 'prefix', '--prefix', prefix], ROOT, process.env);
+ expect(result.code, result.stderr).toBe(0);
+ expect(result.stdout.trim()).toBe(prefix);
+ });
+
+ it('packs a local package into a destination containing shell metacharacters', async () => {
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'squad-matrix- & '));
+ try {
+ const dest = path.join(dir, 'packed files & literal');
+ fs.mkdirSync(dest);
+ fs.writeFileSync(path.join(dir, 'package.json'), JSON.stringify({ name: 'squad-matrix-test', version: '1.0.0' }));
+ const result = await npmCmd(['pack', '--quiet', '--ignore-scripts', '--pack-destination', dest], dir, process.env);
+ expect(result.code, result.stderr).toBe(0);
+ const tarball = result.stdout.trim().split(/\r?\n/).pop()!;
+ expect(fs.existsSync(path.join(dest, tarball))).toBe(true);
+ } finally {
+ fs.rmSync(dir, { recursive: true, force: true });
+ }
+ });
+
const fakeSpec = (over: Partial = {}): ProducerSpec => ({
version: '0.0.0-guard', source: 'github-release', why: 'guard test', supports: { stateBackend: true, dryRun: true },
artifacts: { release: { repository: 'bradygaster/squad', tag: 'v0.0.0-guard', assets: {} } },
@@ -456,16 +544,18 @@ function isolatedEnv(configHome: string, extra: NodeJS.ProcessEnv = {}): NodeJS.
const env: NodeJS.ProcessEnv = {
...process.env, ...GIT_ENV,
CI: '1', SQUAD_NONINTERACTIVE: '1', NO_COLOR: '1', FORCE_COLOR: '0', SQUAD_INIT_NO_COLOR: '1', TERM: 'dumb',
+ HOME: configHome, USERPROFILE: configHome,
APPDATA: configHome, LOCALAPPDATA: configHome, XDG_CONFIG_HOME: configHome,
SQUAD_HOME_DIR_OVERRIDE: path.join(configHome, 'squad-home'),
- ...extra,
};
- if (PLATFORM === 'darwin') env['HOME'] = configHome;
delete env['NODE_PATH'];
delete env['NODE_OPTIONS'];
+ delete env['SQUAD_CLI'];
delete env['SQUAD_TEAM_ROOT'];
for (const k of Object.keys(env)) if (k.startsWith('npm_')) delete env[k];
- return env;
+ const guard = path.join(ROOT, 'test', 'setup', 'profile-fs-guard.cjs').replace(/\\/g, '/');
+ const nodeOptions = [`--require "${guard}"`, extra.NODE_OPTIONS].filter(Boolean).join(' ');
+ return { ...env, ...extra, NODE_OPTIONS: nodeOptions };
}
// โโโ scenario bookkeeping โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
@@ -593,12 +683,10 @@ async function fetchBuffer(url: string, headers: Record = {}): P
}
async function npmCmd(args: string[], cwd: string, env: NodeJS.ProcessEnv): Promise {
- const npm = PLATFORM === 'win32' ? 'npm.cmd' : 'npm';
- // Absolute tarball paths: a bare `dir/file.tgz` would be read by npm as a GitHub `owner/repo` shorthand.
- const quoted = args.map((a) => (/\s/.test(a) ? `"${a}"` : a));
- return PLATFORM === 'win32'
- ? run(process.env['ComSpec'] ?? 'cmd.exe', ['/d', '/s', '/c', `${npm} ${quoted.join(' ')}`], { cwd, env, timeout: 600_000 })
- : run(npm, args, { cwd, env, timeout: 600_000 });
+ if (PLATFORM !== 'win32') return run('npm', args, { cwd, env, timeout: 600_000 });
+ const npmCli = path.join(path.dirname(process.execPath), 'node_modules', 'npm', 'bin', 'npm-cli.js');
+ if (!fs.existsSync(npmCli)) throw new Error(`npm CLI not found beside Node: ${npmCli}`);
+ return run(process.execPath, [npmCli, ...args], { cwd, env, timeout: 600_000 });
}
/**
@@ -721,17 +809,23 @@ describe.skipIf(!ENABLED)('old-version ร OS ร state-shape upgrade matrix (SQUA
const sdkDir = path.join(ROOT, 'packages', 'squad-sdk');
const cliDir = path.join(ROOT, 'packages', 'squad-cli');
const buildEnv = { ...process.env, SKIP_BUILD_BUMP: '1', NO_COLOR: '1', FORCE_COLOR: '0' };
- const npmShell = PLATFORM === 'win32';
- if (!fs.existsSync(path.join(sdkDir, 'dist', 'index.js'))) execFileSync('npm', ['run', 'build'], { cwd: sdkDir, stdio: 'inherit', env: buildEnv, shell: npmShell });
- if (!fs.existsSync(path.join(cliDir, 'dist', 'cli-entry.js'))) execFileSync('npm', ['run', 'build'], { cwd: cliDir, stdio: 'inherit', env: buildEnv, shell: npmShell });
+ const runNpm = async (args: string[], cwd: string): Promise => {
+ const result = await npmCmd(args, cwd, buildEnv);
+ if (result.code !== 0) throw new Error(`npm ${args[0]} failed in ${cwd} (exit ${result.code}): ${result.stderr || result.stdout}`);
+ return result.stdout.trim();
+ };
+ if (!fs.existsSync(path.join(sdkDir, 'dist', 'index.js'))) await runNpm(['run', 'build'], sdkDir);
+ if (!fs.existsSync(path.join(cliDir, 'dist', 'cli-entry.js'))) await runNpm(['run', 'build'], cliDir);
fs.mkdirSync(CACHE_ROOT, { recursive: true });
staging = fs.mkdtempSync(path.join(CACHE_ROOT, 'staging-'));
const tarballs = path.join(staging, 'tarballs');
fs.mkdirSync(tarballs);
- const pack = (pkgDir: string): string => {
- const out = execFileSync('npm', ['pack', '--quiet', '--ignore-scripts', '--pack-destination', tarballs], { cwd: pkgDir, encoding: 'utf8', shell: npmShell, env: buildEnv }).trim();
- return path.join(tarballs, out.split(/\r?\n/).filter(Boolean).pop()!.trim());
+ const pack = async (pkgDir: string): Promise => {
+ const out = await runNpm(['pack', '--quiet', '--ignore-scripts', '--pack-destination', tarballs], pkgDir);
+ const filename = out.split(/\r?\n/).filter(Boolean).pop()?.trim();
+ if (!filename) throw new Error(`npm pack produced no tarball name for ${pkgDir}`);
+ return path.join(tarballs, filename);
};
const unpack = (tarball: string, dest: string) => {
const tmp = fs.mkdtempSync(path.join(tarballs, 'x-'));
@@ -740,8 +834,8 @@ describe.skipIf(!ENABLED)('old-version ร OS ร state-shape upgrade matrix (SQUA
fs.renameSync(path.join(tmp, 'package'), dest);
rmrf(tmp);
};
- unpack(pack(sdkDir), path.join(staging, 'node_modules', '@bradygaster', 'squad-sdk'));
- unpack(pack(cliDir), path.join(staging, 'node_modules', '@bradygaster', 'squad-cli'));
+ unpack(await pack(sdkDir), path.join(staging, 'node_modules', '@bradygaster', 'squad-sdk'));
+ unpack(await pack(cliDir), path.join(staging, 'node_modules', '@bradygaster', 'squad-cli'));
fs.writeFileSync(path.join(staging, 'package.json'), JSON.stringify({ name: 'squad-upgrade-matrix-consumer', private: true, type: 'module' }, null, 2) + '\n');
newVersion = (readJson<{ version: string }>(path.join(staging, 'node_modules', '@bradygaster', 'squad-cli', 'package.json')))!.version;
newCli = {
@@ -998,6 +1092,7 @@ describe.skipIf(!ENABLED)('old-version ร OS ร state-shape upgrade matrix (SQUA
// pointed at the retired profile tree: zero reads, probes or writes may land there.
const newEnv = isolatedEnv(configHome, {
...newCli.env,
+ SQUAD_CLI: newCli.args[0],
NODE_OPTIONS: `--require ${JSON.stringify(FS_HOOK)}`,
SQUAD_MATRIX_FS_WATCH_ROOT: profileRoot,
SQUAD_MATRIX_FS_WATCH_LOG: fsLog,
diff --git a/test/standalone-release-workflow.test.ts b/test/standalone-release-workflow.test.ts
index ae3a3915a..cc7b5d149 100644
--- a/test/standalone-release-workflow.test.ts
+++ b/test/standalone-release-workflow.test.ts
@@ -331,17 +331,19 @@ describe('standalone release handoff', () => {
expect(standaloneWorkflow.on?.release).toBeUndefined();
});
- it('pins every standalone checkout and cross-job artifact to source_sha', () => {
+ it('checks out the trusted dispatch SHA and binds it and cross-job artifacts to source_sha', () => {
for (const [jobName, job] of Object.entries(standaloneWorkflow.jobs)) {
const steps = job.steps ?? [];
for (const [index, step] of steps.entries()) {
if (!step.uses?.startsWith('actions/checkout@')) continue;
- expect(step.with?.ref, `${jobName} checkout ref`).toBe('${{ inputs.source_sha }}');
+ expect(step.with?.ref, `${jobName} checkout ref`).toBe('${{ github.sha }}');
const verify = steps[index + 1];
if (jobName === 'guard') {
const validate = stepNamed(job, 'Validate inputs').run ?? '';
expect(validate).toContain('head_sha="$(git rev-parse HEAD)"');
expect(validate).toContain('test "$head_sha" = "$SOURCE_SHA"');
+ expect(validate).toContain('test "$DISPATCH_SHA" = "$SOURCE_SHA"');
+ expect(validate).toContain('test "$WORKFLOW_SHA" = "$SOURCE_SHA"');
expect(validate).toContain('echo "Verified checkout HEAD: ${head_sha}"');
} else {
expect(verify?.name, `${jobName} checkout verification`).toBe(
@@ -919,7 +921,7 @@ describe('automated package publication', () => {
const checkout = standaloneWorkflow.jobs[jobName].steps?.find((step) =>
step.uses?.startsWith('actions/checkout@'),
);
- expect(checkout?.with?.ref, jobName).toBe('${{ inputs.source_sha }}');
+ expect(checkout?.with?.ref, jobName).toBe('${{ github.sha }}');
}
});
diff --git a/workflows/shared/squad-command-contract.mjs b/workflows/shared/squad-command-contract.mjs
index 7688b71e6..8581e2ed4 100644
--- a/workflows/shared/squad-command-contract.mjs
+++ b/workflows/shared/squad-command-contract.mjs
@@ -441,6 +441,30 @@ export function enforceSquadRouterOutputs(agentOutputPath) {
}
}
+function withoutCommentsForInspection(body) {
+ const parts = [];
+ let cursor = 0;
+ while (cursor < body.length) {
+ const open = body.indexOf('', close)) { close += 3; break; }
+ if (body.startsWith('--!>', close)) {
+ throw new Error('Unsupported HTML comment terminator in agent output; refusing ambiguous authority.');
+ }
+ close++;
+ }
+ if (close === -1) throw new Error('Unclosed HTML comment in agent output; refusing ambiguous authority.');
+ cursor = close;
+ }
+ parts.push(body.slice(cursor));
+ const normalized = parts.join('');
+ if (normalized.includes('/g, '')];
+ const bodies = [rawBody, withoutCommentsForInspection(rawBody)];
if (activationArtifacts.has(item.data?.squad_artifact) ||
bodies.some(body => /Activation (?:bindings|reconciliation):/i.test(body) ||
/squad-activation-(?:pending|finalization)\/v1/.test(body) ||
diff --git a/workflows/squad-workflows.manifest.json b/workflows/squad-workflows.manifest.json
index 67773a410..d3f5c2f77 100644
--- a/workflows/squad-workflows.manifest.json
+++ b/workflows/squad-workflows.manifest.json
@@ -177,7 +177,7 @@
"package_destination": ".github/workflows/shared/squad-command-contract.mjs",
"destination": ".github/workflows/shared/squad-command-contract.mjs",
"ownership": "manifest",
- "sha256": "9f044d9ab402d893f58eb0477e3d3620540f0b992056ed3a61d090daa50aea4a"
+ "sha256": "295d4f828094b2b71bbb947007d125471ef80f22b503bfb7775e1e6a366485b5"
},
{
"path": "shared/squad-evidence-provider.mjs",
|