Files
ruflo/tests/external-plugins.test.mjs
T
1af3abedd7 feat(marketplace): install Agentic QE (agentic-qe-fleet) from the ruflo marketplace (#3950)
* feat(marketplace): list Agentic QE (agentic-qe-fleet) as an external, pinned plugin

The ruflo marketplace now lists agentic-qe-fleet by a git-subdir source pinned
to agentic-qe v3.15.0 (1363bc7d), so `/plugin install agentic-qe-fleet@ruflo`
installs the plugin from its own repository: 11 QE agents, 9 skills, 9 commands,
the agentic-qe MCP server pinned to 3.15.0, and the aqe-mod guard.

Tooling that assumed every entry is a local ./plugins folder now handles an
external one:
- validate-marketplace.yml checks an external entry (git-subdir, https url,
  path without .., full sha, description) instead of failing on it
- smoke-all-plugins checks out each external entry at its sha and runs its own
  scripts/smoke.sh (--skip-external to omit); the workflow also runs when
  marketplace.json changes
- ruflo-console 0.40.9: plugin-map line (Dev Tools), the coverage test requires
  a line for every external entry, and the Plugin Catalog reads an external
  plugin from its install path in installed_plugins.json (EXT badge)
- README and plugins/README rows; ADR-484 records the decision and evidence

* docs(adr-484): record what Claude Code before 2.1.69 does with the external entry, and main's existing floor

* fix(ci): fence the external-plugin smoke: github-only sources, realpath containment, scrubbed env and cwd, read-only token

Review findings 1 and 2 on #3950:
- scripts/external-plugins.mjs: sources must be https://github.com/<owner>/<repo>(.git);
  the plugin folder, its manifest and smoke.sh must stay inside the checkout after realpath;
  the external smoke.sh runs with only PATH, LANG, TERM and CI kept (no GITHUB_TOKEN,
  ACTIONS_*, *_TOKEN, *_KEY, *SECRET*), a temporary HOME, and its checkout (in a temp
  folder outside the workspace) as cwd; git fetch runs with the same env
- validate-marketplace.yml applies the same github-only allowlist and path rule
- all-plugins-smoke.yml: permissions contents: read, persist-credentials: false,
  runs tests/external-plugins.test.mjs
- tests/external-plugins.test.mjs: non-github host and lookalikes refused by both
  validators, symlink escapes refused, child env has no GITHUB_TOKEN and cwd is outside
  the workspace

* ci(all-plugins-smoke): raise the smoke-all timeout from 10 to 15 minutes

Review finding 4 on #3950: green runs on main take 9m40-9m50s, so the job sat on the
10-minute cap and was cancelled at 10m16s on this PR.

* test(console): an external plugin's description, version, source line and docs are stripped of escapes and bidi controls

Review finding 3 on #3950: the catalog reader already passes every external manifest
string through plain() (ESC/CSI/OSC sequences, C0/C1 controls, U+202A-202E and
U+2066-2069 removed); this test holds it to that.

* ci(test-ratchet): tests/external-plugins.test.mjs runs under node --test, not the root vitest

all-plugins-smoke.yml runs it with node --test; vitest reported "No test suite found".

* feat(marketplace): move the agentic-qe-fleet pin to v3.15.1 (4f0f8412)

agentic-qe v3.15.1 changes only the aqe-mod guard (#920: hardened, still tighten-only,
same engine API and events as 3.15.0) and pins agentic-qe@3.15.1 in .mcp.json.

* docs(adr-484): install evidence re-run at the v3.15.1 pin

* feat(marketplace): move the agentic-qe-fleet pin to v3.15.2 (9db36edf)

agentic-qe v3.15.2: aqe-mod reports its real version, keeps guard totals and the last
refusal across sessions (additive totals/lastRefusal in status.json), and never reads or
writes its status file through a symlink (adds $.fs.read and $.fs.stat); guard judging
unchanged. .mcp.json pins agentic-qe@3.15.2. ADR-484 evidence re-run at this pin.

* fix(marketplace): plain-name paths for external plugins, pin-review note, one marketplace for agentic-qe-fleet

- both validators (scripts/external-plugins.mjs, validate-marketplace.yml) require the
  plugin path to match ^[A-Za-z0-9._-]+(/[A-Za-z0-9._-]+)*$ with no . or .. segment:
  %2e%2e, a\..\b, a//b and a trailing slash are refused; tests cover both validators
- ADR-484: every pin bump needs a review of the pinned scripts/smoke.sh
- READMEs: install agentic-qe-fleet from the agentic-qe or the ruflo marketplace, not both

* feat(marketplace): move the agentic-qe-fleet pin to v3.15.3 (d7e5ffa7)

The plugin at v3.15.3 differs from v3.15.2 only in its version and its MCP
pin (agentic-qe@3.15.3). ADR-484's evidence records the install re-run at
the new pin.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* chore(plugins): pin agentic-qe to v3.15.4 (bec02b13)

The plugin at v3.15.4 differs from v3.15.3 only in its version and its MCP
pin (agentic-qe@3.15.4). ADR-484's evidence records the install re-run at
the new pin.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* chore(plugins): pin agentic-qe to v3.15.5 (d65ede14)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* chore(console): leave the console version bump to the maintainer at merge

The console version and CHANGELOG entry collided with every console release on
main (four rebases on 2026-10-12, each only plugins/ruflo-console/CHANGELOG.md).
plugin.json, hooks/version.ts, scripts/smoke.sh and CHANGELOG.md now match
main; ADR-484 and its index row say 'next console release'.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* chore(plugins): pin agentic-qe to v3.15.6 (0fa34d24)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* chore(plugins): pin agentic-qe to v3.15.7 (7f2d091d)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* chore(plugins): pin agentic-qe to v3.15.8 (d9ce98f7)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* chore(plugins): pin agentic-qe to v3.15.9 (d1c33d2b)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* chore(plugins): pin agentic-qe to v3.15.10 (e5814a2f)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: rUv <ruv@ruv.net>
2026-10-19 22:55:58 -04:00

157 lines
8.8 KiB
JavaScript

// node --test tests/external-plugins.test.mjs
// The external-plugin checks (ADR-484): the github-only source allowlist in scripts/external-plugins.mjs and in
// validate-marketplace.yml's inline validator, the realpath containment of the plugin folder, and the environment and working
// directory an external smoke.sh runs with.
import assert from 'node:assert/strict';
import { spawnSync } from 'node:child_process';
import { mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join, sep } from 'node:path';
import { test } from 'node:test';
import { fileURLToPath } from 'node:url';
import { externalSmokePlan, externalSourceProblem, isAllowedRepoUrl, makeWorkArea, realpathInside, scrubbedEnv } from '../scripts/external-plugins.mjs';
const REPO = fileURLToPath(new URL('..', import.meta.url));
const SHA = 'e5814a2f4f3d7995b87ebda9ad30e8a3d92cd555';
const source = (over) => ({ source: 'git-subdir', url: 'https://github.com/proffesor-for-testing/agentic-qe.git', path: 'plugins/agentic-qe-fleet', ref: 'v3.15.10', sha: SHA, ...over });
const REFUSED_URLS = [
'https://github.com.evil.io/owner/repo',
'https://evil.io/github.com/owner/repo',
'https://gitlab.com/owner/repo',
'http://github.com/owner/repo',
'https://user@github.com/owner/repo',
'https://github.com/owner/repo/extra',
'https://github.com/owner',
'https://github.com/../repo',
'https://github.com/owner/..',
'https://github.com/owner/repo?x=1',
'https://github.com/own er/repo',
'git@github.com:owner/repo.git',
'--upload-pack=x',
];
// Paths the plugin folder may not take: encoded or backslashed climbs, empty or trailing segments, absolute, . and .. segments.
const BAD_PATHS = ['%2e%2e', 'plugins/%2e%2e/x', 'a\\..\\b', 'a//b', 'plugins/p/', '/etc', '.', '..', 'a/./b', 'a/../b', '', 'a b', 'a/b?c'];
test('the allowlist takes https://github.com/<owner>/<repo>, with or without .git', () => {
assert.equal(isAllowedRepoUrl('https://github.com/proffesor-for-testing/agentic-qe.git'), true);
assert.equal(isAllowedRepoUrl('https://github.com/ruvnet/ruflo'), true);
});
test('the allowlist refuses other hosts, lookalikes and anything around the owner/repo pair', () => {
for (const url of REFUSED_URLS) assert.equal(isAllowedRepoUrl(url), false, url);
});
test('externalSourceProblem refuses a non-github host, a lookalike, a climbing path and a short sha', () => {
assert.equal(externalSourceProblem(source()), null);
assert.match(externalSourceProblem(source({ url: 'https://gitlab.com/owner/repo.git' })), /github/);
assert.match(externalSourceProblem(source({ url: 'https://github.com.evil.io/owner/repo' })), /github/);
assert.match(externalSourceProblem(source({ url: 'https://evil.io/github.com/owner/repo' })), /github/);
assert.match(externalSourceProblem(source({ path: 'plugins/../..' })), /path/);
assert.match(externalSourceProblem(source({ path: '/etc' })), /path/);
for (const path of BAD_PATHS) assert.match(externalSourceProblem(source({ path })) ?? 'accepted', /path/, path);
assert.equal(externalSourceProblem(source({ path: 'plugins/agentic-qe-fleet' })), null);
assert.equal(externalSourceProblem(source({ path: 'a.b/c_d-e' })), null);
assert.match(externalSourceProblem(source({ sha: SHA.slice(0, 12) })), /sha/);
assert.match(externalSourceProblem(source({ source: 'url' })), /git-subdir/);
});
/** Runs validate-marketplace.yml's inline validator (the `node -e "..."` block, through bash as CI does) on one entry. */
function runWorkflowValidator(entrySource) {
const yml = readFileSync(join(REPO, '.github', 'workflows', 'validate-marketplace.yml'), 'utf8');
const start = yml.indexOf('node -e "');
const end = yml.indexOf('\n "', start);
assert.ok(start > 0 && end > start, 'found the inline validator');
const dir = mkdtempSync(join(tmpdir(), 'validate-marketplace-'));
try {
mkdirSync(join(dir, '.claude-plugin'));
const entry = { name: 'ext', source: entrySource, description: 'an external plugin' };
writeFileSync(join(dir, '.claude-plugin', 'marketplace.json'), JSON.stringify({ name: 't', plugins: [entry] }));
return spawnSync('bash', ['-c', yml.slice(start, end + 12)], { cwd: dir, encoding: 'utf8' });
} finally {
rmSync(dir, { recursive: true, force: true });
}
}
test('validate-marketplace.yml accepts a pinned github git-subdir and refuses other hosts and lookalikes', () => {
assert.equal(runWorkflowValidator(source()).status, 0);
for (const url of ['https://gitlab.com/owner/repo.git', 'https://github.com.evil.io/owner/repo', 'https://evil.io/github.com/owner/repo', 'https://github.com/../repo']) {
const r = runWorkflowValidator(source({ url }));
assert.notEqual(r.status, 0, url);
assert.match(r.stderr, /github\.com/, url);
}
for (const path of [...BAD_PATHS, 'plugins/../x']) assert.notEqual(runWorkflowValidator(source({ path })).status, 0, path);
assert.equal(runWorkflowValidator(source({ path: 'a.b/c_d-e' })).status, 0);
assert.notEqual(runWorkflowValidator(source({ sha: 'abc' })).status, 0);
});
/** A fake external checkout: plugins/p with a manifest and a smoke.sh that records its env and cwd under $HOME. */
function fakeCheckout(area) {
const plugin = join(area.checkout, 'plugins', 'p');
mkdirSync(join(plugin, '.claude-plugin'), { recursive: true });
mkdirSync(join(plugin, 'scripts'));
writeFileSync(join(plugin, '.claude-plugin', 'plugin.json'), JSON.stringify({ name: 'p' }));
writeFileSync(join(plugin, 'scripts', 'smoke.sh'), 'env > "$HOME/env.txt"\npwd -P > "$HOME/cwd.txt"\nls -A > "$HOME/ls.txt"\n');
return plugin;
}
test('an external smoke runs with a scrubbed env (no GITHUB_TOKEN, no *_TOKEN/*_KEY/*SECRET*/ACTIONS_*) and its checkout as cwd, outside the workspace', () => {
const area = makeWorkArea();
try {
fakeCheckout(area);
const parent = { PATH: process.env.PATH, LANG: 'C.UTF-8', TERM: 'xterm', CI: 'true', GITHUB_TOKEN: 'ghs_x', ACTIONS_RUNTIME_TOKEN: 'y', NPM_TOKEN: 'z', ANTHROPIC_API_KEY: 'k', MY_SECRET_VALUE: 's', GITHUB_WORKSPACE: REPO, HOME: '/root' };
const plan = externalSmokePlan(area.checkout, area.home, 'plugins/p', 'p', parent);
assert.ok(plan.smoke, JSON.stringify(plan));
// Run it the way smoke-all-plugins' runSmoke does: bash <smoke> with exactly the plan's cwd and env.
const r = spawnSync('bash', [plan.smoke], { cwd: plan.cwd, env: plan.env, encoding: 'utf8' });
assert.equal(r.status, 0, r.stderr);
const seen = readFileSync(join(area.home, 'env.txt'), 'utf8');
for (const name of ['GITHUB_TOKEN', 'ACTIONS_RUNTIME_TOKEN', 'NPM_TOKEN', 'ANTHROPIC_API_KEY', 'MY_SECRET_VALUE', 'GITHUB_WORKSPACE']) {
assert.doesNotMatch(seen, new RegExp(`^${name}=`, 'm'), name);
}
assert.match(seen, new RegExp(`^HOME=${area.home.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}$`, 'm'));
const cwd = readFileSync(join(area.home, 'cwd.txt'), 'utf8').trim();
assert.equal(cwd, plan.cwd);
assert.ok(!(cwd + sep).startsWith(REPO), `cwd ${cwd} is outside the workspace ${REPO}`);
assert.deepEqual(readFileSync(join(area.home, 'ls.txt'), 'utf8').trim().split('\n'), ['plugins'], 'the cwd holds only the checkout');
assert.deepEqual(Object.keys(plan.env).sort(), ['CI', 'HOME', 'LANG', 'PATH', 'TERM']);
} finally {
rmSync(area.dir, { recursive: true, force: true });
}
});
test('a plugin folder that is a symlink out of the checkout is refused, and so is a smoke.sh that links out', () => {
const area = makeWorkArea();
const outside = mkdtempSync(join(tmpdir(), 'outside-'));
try {
mkdirSync(join(outside, '.claude-plugin'));
writeFileSync(join(outside, '.claude-plugin', 'plugin.json'), JSON.stringify({ name: 'p' }));
mkdirSync(join(area.checkout, 'plugins'));
symlinkSync(outside, join(area.checkout, 'plugins', 'p'));
assert.equal(realpathInside(area.checkout, join(area.checkout, 'plugins', 'p')), null);
assert.match(externalSmokePlan(area.checkout, area.home, 'plugins/p', 'p').problem, /outside the checkout/);
rmSync(join(area.checkout, 'plugins'), { recursive: true, force: true });
const plugin = fakeCheckout(area);
rmSync(join(plugin, 'scripts', 'smoke.sh'));
writeFileSync(join(outside, 'evil.sh'), 'exit 0\n');
symlinkSync(join(outside, 'evil.sh'), join(plugin, 'scripts', 'smoke.sh'));
assert.match(externalSmokePlan(area.checkout, area.home, 'plugins/p', 'p').problem, /smoke\.sh resolves outside/);
} finally {
rmSync(area.dir, { recursive: true, force: true });
rmSync(outside, { recursive: true, force: true });
}
});
test('a manifest that does not carry the listed name is refused', () => {
const area = makeWorkArea();
try {
fakeCheckout(area);
assert.match(externalSmokePlan(area.checkout, area.home, 'plugins/p', 'other').problem, /does not name other/);
} finally {
rmSync(area.dir, { recursive: true, force: true });
}
});