ktg-plugin-marketplace/docs/marketplace-polyrepo-migration/migration/10-extract.test.mjs

44 lines
2.2 KiB
JavaScript

// Step 3 integration test — runs the extraction driver against the live monorepo (via the mirror)
// and asserts F1 (renamed-plugin history retained), F5 (single clean re-tag), root-level contents,
// and origin removal. Pattern: plugins/voyage/tests/integration/*.test.mjs.
import test from 'node:test';
import assert from 'node:assert/strict';
import { spawnSync } from 'node:child_process';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const here = path.dirname(fileURLToPath(import.meta.url));
const SCRIPT = path.join(here, '10-extract.sh');
const WORK = process.env.WORK || '/tmp/polyrepo-migration';
const EXTRACT = path.join(WORK, 'voyage');
const git = (args) => spawnSync('git', ['-C', EXTRACT, ...args], { encoding: 'utf8' });
// Reuse the extract if the verify already produced it (tagged v5.1.1); otherwise build it.
(function ensureExtract() {
const tag = git(['tag']);
if (tag.status === 0 && tag.stdout.trim() === 'v5.1.1') return;
const r = spawnSync('bash', [SCRIPT, 'voyage'], { encoding: 'utf8', env: { ...process.env, WORK } });
if (r.status !== 0) throw new Error(`extract failed (status ${r.status}):\n${r.stdout}\n${r.stderr}`);
})();
test('voyage extract retains pre-rename (ultraplan-local) history — F1', () => {
const n = parseInt(git(['rev-list', '--count', 'HEAD']).stdout.trim(), 10);
assert.ok(n >= 150, `expected >=150 commits (voyage + ultraplan-local), got ${n}`);
});
test('voyage extract carries exactly one tag: v5.1.1 (F5)', () => {
const tags = git(['tag']).stdout.trim().split('\n').filter(Boolean).sort();
assert.deepEqual(tags, ['v5.1.1']);
});
test('voyage extract has no plugins/ prefix — contents at repo root', () => {
const files = git(['ls-files']).stdout.trim().split('\n').filter(Boolean);
assert.ok(files.length > 0, 'extract should have tracked files');
assert.ok(!files.some((f) => f.startsWith('plugins/')), 'no tracked path should start with plugins/');
assert.ok(files.includes('.claude-plugin/plugin.json'), 'voyage plugin.json should be at repo root');
});
test('origin remote is removed post-filter', () => {
assert.equal(git(['remote']).stdout.trim(), '', 'filter-repo should remove the origin remote');
});