Files
ruflo/plugins/ruflo-console/tests/plugin-catalog.spec.ts
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

146 lines
8.2 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it } from 'vitest'
import { readCatalog, readDoc, visible, type CatalogPlugin } from '../hooks/data/plugin-catalog'
import type { ReaderFs } from '../hooks/data/files'
const ROOT = '/h/.claude/plugins/marketplaces/ruflo'
const CACHE = '/h/.claude/plugins/cache/ruflo'
const GIT = { source: 'git-subdir', url: 'https://example.com/qe.git', path: 'plugins/qe', ref: 'v2.0.0', sha: 'a'.repeat(40) }
const files: Record<string, string> = {
[`${ROOT}/.claude-plugin/marketplace.json`]: JSON.stringify({
plugins: [
{ name: 'a-plugin', source: './plugins/a-plugin', description: 'Does A things' },
{ name: 'b-mod', source: './plugins/b-mod', description: 'A mod' },
{ name: 'evil', source: './../../etc', description: 'climbs out' },
{ name: 'bad name!', source: './plugins/x', description: 'not a word' },
{ name: 'ext-installed', source: GIT, description: 'An external plugin, installed' },
{ name: 'ext-missing', source: { ...GIT, path: 'plugins/other' }, description: 'An external plugin, not installed' },
{ name: 'ext-odd', source: { source: 'npm', package: 'x' }, description: 'a source kind it does not read' },
],
}),
[`${ROOT}/plugins/a-plugin/.claude-plugin/plugin.json`]: '{"version":"1.2.3"}',
[`${ROOT}/plugins/a-plugin/skills/alpha/SKILL.md`]: '---\nname: alpha\ndescription: "Alpha does a"\n---\nbody\n',
[`${ROOT}/plugins/a-plugin/agents/helper.md`]: 'x',
[`${ROOT}/plugins/a-plugin/commands/go.md`]: 'x',
[`${ROOT}/plugins/a-plugin/.mcp.json`]: '{}',
[`${ROOT}/plugins/b-mod/hooks/register.ts`]: 'x',
[`${CACHE}/ext-installed/2.0.0/.claude-plugin/plugin.json`]: '{"version":"2.0.0","userConfig":{"guardMode":{}}}',
[`${CACHE}/ext-installed/2.0.0/commands/qe-go.md`]: '---\ndescription: Go\n---\n',
[`${CACHE}/ext-installed/2.0.0/.mcp.json`]: '{}',
[`${CACHE}/ext-installed/2.0.0/hooks/register.ts`]: 'x',
}
const fs: ReaderFs = {
read: async path => {
if (!(path in files)) throw new Error('ENOENT')
return files[path] as string
},
stat: async path => (path in files ? { size: (files[path] as string).length } : undefined),
list: async path => {
const below = Object.keys(files).filter(file => file.startsWith(`${path}/`)).map(file => file.slice(path.length + 1))
if (below.length === 0) throw new Error('ENOENT')
return [...new Set(below.map(name => name.split('/')[0] as string))].map(name => ({ name, kind: below.some(file => file === name) ? 'file' : 'dir' }))
},
}
describe('plugin catalog reader', () => {
it('lists each plugin with what it ships, skipping a climbing source, a non-word name and a source kind it does not read', async () => {
const plugins = (await readCatalog(fs, ROOT)) as CatalogPlugin[]
expect(plugins.map(plugin => plugin.name)).toEqual(['a-plugin', 'b-mod', 'ext-installed', 'ext-missing'])
expect(plugins[0]).toMatchObject({ version: '1.2.3', skills: ['alpha'], agents: ['helper'], commands: ['go'], hasMcp: true, isMod: false })
expect(plugins[0]?.external).toBeUndefined()
expect(plugins[1]).toMatchObject({ isMod: true, skills: [] })
})
it('reads an external plugin from its install path, and lists one that is not installed by its entry alone', async () => {
const plugins = (await readCatalog(fs, ROOT, new Map([['ext-installed', `${CACHE}/ext-installed/2.0.0`]]))) as CatalogPlugin[]
const installed = plugins.find(plugin => plugin.name === 'ext-installed') as CatalogPlugin
const missing = plugins.find(plugin => plugin.name === 'ext-missing') as CatalogPlugin
expect(installed).toMatchObject({ dir: `${CACHE}/ext-installed/2.0.0`, version: '2.0.0', commands: ['qe-go'], options: ['guardMode'], hasMcp: true, isMod: true, external: 'https://example.com/qe.git plugins/qe @ v2.0.0' })
expect((await readDoc(fs, installed, 'command', 'qe-go'))?.description).toBe('Go')
expect(missing).toMatchObject({ dir: '', version: null, skills: [], agents: [], commands: [], hasMcp: false, isMod: false, external: 'https://example.com/qe.git plugins/other @ v2.0.0' })
expect(await readDoc(fs, missing, 'command', 'qe-go')).toBeNull()
})
it('refuses a location with .. or a relative one, and a missing manifest', async () => {
expect(await readCatalog(fs, '/h/../etc')).toBeNull()
expect(await readCatalog(fs, 'relative/clone')).toBeNull()
expect(await readCatalog(fs, '/nowhere')).toBeNull()
})
it('reads a skill’s description from its frontmatter and bounds the lines', async () => {
const [plugin] = (await readCatalog(fs, ROOT)) as CatalogPlugin[]
const doc = await readDoc(fs, plugin as CatalogPlugin, 'skill', 'alpha')
expect(doc?.description).toBe('Alpha does a')
expect(doc?.lines.length).toBeLessThanOrEqual(40)
expect(await readDoc(fs, plugin as CatalogPlugin, 'skill', '../escape')).toBeNull()
})
it('filters by mode and by a word found in a name, description, or skill name', async () => {
const plugins = (await readCatalog(fs, ROOT)) as CatalogPlugin[]
const installed = new Set(['a-plugin'])
expect(visible(plugins, installed, 'installed', '').map(plugin => plugin.name)).toEqual(['a-plugin'])
expect(visible(plugins, installed, 'missing', '').map(plugin => plugin.name)).toEqual(['b-mod', 'ext-installed', 'ext-missing'])
expect(visible(plugins, installed, 'mods', '').map(plugin => plugin.name)).toEqual(['b-mod'])
expect(visible(plugins, installed, 'all', 'alpha').map(plugin => plugin.name)).toEqual(['a-plugin'])
expect(visible(plugins, installed, 'skills', '').map(plugin => plugin.name)).toEqual(['a-plugin'])
expect(visible(plugins, installed, 'all', 'nothing-like-this')).toEqual([])
})
})
describe('plugin catalog reader: hostile text from an external plugin', () => {
// ESC/CSI colour, an OSC 8 hyperlink and an OSC title, and the bidi embeddings, overrides and isolates (U+202A–202E, U+2066–2069),
// written as \u escapes so no control character sits in this source.
const ESC = '\u001b'
const BIDI = ['‪', '‫', '‬', '‭', '‮', '⁦', '⁧', '⁨', '⁩']
const hostile = `${ESC}[31mred${ESC}[0m ${ESC}]8;;https://evil.example${ESC}\\link${ESC}]8;;${ESC}\\ ${ESC}]0;title\u0007${BIDI.join('')}txt.exe`
const dir = `${CACHE}/ext-hostile/1.0.0`
const hostileFiles: Record<string, string> = {
[`${ROOT}/.claude-plugin/marketplace.json`]: JSON.stringify({ plugins: [{ name: 'ext-hostile', source: { ...GIT, url: `https://github.com/o/r${ESC}[2J` } }] }),
[`${dir}/.claude-plugin/plugin.json`]: JSON.stringify({ name: 'ext-hostile', version: `1.0.0${ESC}[2J${BIDI[4]}`, description: hostile }),
[`${dir}/commands/go.md`]: `---\ndescription: ${hostile}\n---\n${hostile}\n`,
[`${dir}/commands/${ESC}[2Jbad.md`]: 'x',
}
const hostileFs: ReaderFs = {
read: async path => {
if (!(path in hostileFiles)) throw new Error('ENOENT')
return hostileFiles[path] as string
},
stat: async path => (path in hostileFiles ? { size: (hostileFiles[path] as string).length } : undefined),
list: async path => {
const below = Object.keys(hostileFiles).filter(file => file.startsWith(`${path}/`)).map(file => file.slice(path.length + 1))
if (below.length === 0) throw new Error('ENOENT')
return [...new Set(below.map(name => name.split('/')[0] as string))].map(name => ({ name, kind: below.some(file => file === name) ? 'file' : 'dir' }))
},
}
const clean = (text: string) => {
expect(text).not.toMatch(/[\u0000-\u001f\u007f-\u009f]/)
for (const mark of BIDI) expect(text.includes(mark), `U+${mark.charCodeAt(0).toString(16)}`).toBe(false)
expect(text).not.toMatch(/\]8;;|\[31m|\[2J|\]0;/)
}
it('strips escape sequences and bidi controls from its description, version, source line and docs, and drops a hostile file name', async () => {
const [plugin] = (await readCatalog(hostileFs, ROOT, new Map([['ext-hostile', dir]]))) as CatalogPlugin[]
expect(plugin?.name).toBe('ext-hostile')
for (const text of [plugin?.description ?? '', plugin?.version ?? '', plugin?.external ?? '']) clean(text)
expect(plugin?.description).toBe('red link txt.exe')
expect(plugin?.commands).toEqual(['go'])
const doc = await readDoc(hostileFs, plugin as CatalogPlugin, 'command', 'go')
clean(doc?.description ?? 'missing')
for (const line of doc?.lines ?? []) clean(line)
})
})