Files
awesome-opencode/test/pr-checks.test.js
T
John SmithandClaude Opus 5.5 ef6357d8d1 feat(ci): required validate check with V2 probe, and pull_request_target triage
validate-pr.yml now runs on every PR (README-only PRs previously got no feedback), drops tj-actions/changed-files, runs unit tests, scripts/check-pr.js and a README/registry generation dry run, and supports workflow_dispatch so bot branches get the check. New plugin entries that are V1-only are blocked; declared compat must match what is detected. triage.yml labels PRs (ready, needs-v2, needs-metadata, needs-human, category) and keeps one results comment, using base-branch code only and reading PR files as data. The README workflow uses full history and Node 24.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-17 13:00:22 -04:00

65 lines
3.0 KiB
JavaScript

const test = require('node:test');
const assert = require('node:assert/strict');
const { analyzePullRequest } = require('../scripts/utils/pr-checks');
const { normalizeInput, parseIssueForm } = require('../scripts/utils/submission');
const good = [
'name: Thing',
'repo: https://github.com/someone/brand-new-thing',
'tagline: Does the thing',
'description: Does the thing well.',
'kind: plugin',
'topics:',
' - workflow',
'compat: v2',
''
].join('\n');
const existing = { category: 'plugins', id: 'old', file: 'data/plugins/old.yaml', data: { name: 'Old', repo: 'https://github.com/someone/old', tagline: 't', description: 'd', kind: 'plugin', topics: ['ui'], compat: 'v2' } };
test('a valid new entry is ready', async () => {
const r = await analyzePullRequest({ changes: [{ path: 'data/plugins/thing.yaml', status: 'added', content: good }], baseEntries: [existing], probe: false });
assert.deepEqual(r.errors, []);
assert.deepEqual(r.labels, ['ready']);
assert.deepEqual(r.categories, ['plugins']);
});
test('editing the generated README is rejected', async () => {
const r = await analyzePullRequest({ changes: [{ path: 'README.md', status: 'modified' }], baseEntries: [existing], probe: false });
assert.match(r.errors[0].message, /generated/);
assert.deepEqual(r.labels, ['needs-metadata']);
});
test('broken YAML and duplicates are reported against the PR file', async () => {
const broken = await analyzePullRequest({ changes: [{ path: 'data/plugins/x.yaml', status: 'added', content: 'tagline: A: B\nname: x' }], baseEntries: [], probe: false });
assert.match(broken.errors[0].message, /invalid YAML/);
const dup = await analyzePullRequest({
changes: [{ path: 'data/plugins/thing.yaml', status: 'added', content: good.replace('brand-new-thing', 'old') }],
baseEntries: [existing],
probe: false
});
assert.ok(dup.errors.some(e => /duplicate/.test(e.message)));
});
test('reusing a filename for another repo needs a human', async () => {
const r = await analyzePullRequest({
changes: [{ path: 'data/plugins/old.yaml', status: 'modified', content: good, baseContent: 'repo: https://github.com/someone/old\n' }],
baseEntries: [existing],
probe: false
});
assert.ok(r.warnings.some(w => /changes this entry's target/.test(w.message)));
assert.ok(r.labels.includes('needs-human'));
});
test('issue form parsing and normalization', () => {
const body = '### Name\n\nThing\n\n### Repository URL\n\nhttps://github.com/a/b/tree/main/packages/x\n\n### npm package\n\n_No response_\n\n### Category\n\nplugins\n\n### Topics\n\nmemory, context\n\n### Installation\n\n```markdown\nnpm i thing\n```';
const fields = parseIssueForm(body);
assert.equal(fields.name, 'Thing');
assert.equal(fields.npm, undefined);
assert.equal(fields.installation, 'npm i thing');
const { category, data } = normalizeInput(fields);
assert.equal(category, 'plugins');
assert.equal(data.repo, 'https://github.com/a/b');
assert.equal(data.path, 'packages/x');
assert.deepEqual(data.topics, ['memory', 'context']);
});