|
| 1 | +import { test } from 'node:test'; |
| 2 | +import assert from 'node:assert/strict'; |
| 3 | +import { mkdtempSync, mkdirSync } from 'node:fs'; |
| 4 | +import { join } from 'node:path'; |
| 5 | +import { tmpdir } from 'node:os'; |
| 6 | +import { ownedPathsToDiscard } from '../src/steps/harness.js'; |
| 7 | +import { HARNESS } from '../src/config.js'; |
| 8 | + |
| 9 | +const SKILLS = ['frontend-profissional', 'design-system', 'security', 'backend-profissional']; |
| 10 | + |
| 11 | +function tmpProject() { |
| 12 | + return mkdtempSync(join(tmpdir(), 'harness-merge-')); |
| 13 | +} |
| 14 | + |
| 15 | +test('template without .cursor/: no .cursor/skills/* path is discarded', () => { |
| 16 | + const dest = tmpProject(); |
| 17 | + // Template shipped only the Claude side of the four skills. |
| 18 | + for (const skill of SKILLS) { |
| 19 | + mkdirSync(join(dest, '.claude', 'skills', skill), { recursive: true }); |
| 20 | + } |
| 21 | + const discard = ownedPathsToDiscard(HARNESS.templateOwnedPaths, dest); |
| 22 | + assert.deepEqual( |
| 23 | + discard.sort(), |
| 24 | + SKILLS.map((s) => `.claude/skills/${s}`).sort(), |
| 25 | + ); |
| 26 | + assert.ok(!discard.some((rel) => rel.startsWith('.cursor/')), 'harness must still cover Cursor'); |
| 27 | +}); |
| 28 | + |
| 29 | +test('template with only .claude/skills/security: only that path is discarded', () => { |
| 30 | + const dest = tmpProject(); |
| 31 | + mkdirSync(join(dest, '.claude', 'skills', 'security'), { recursive: true }); |
| 32 | + assert.deepEqual(ownedPathsToDiscard(HARNESS.templateOwnedPaths, dest), ['.claude/skills/security']); |
| 33 | +}); |
| 34 | + |
| 35 | +test('template with all shared paths: the 8 are discarded', () => { |
| 36 | + const dest = tmpProject(); |
| 37 | + for (const rel of HARNESS.templateOwnedPaths) { |
| 38 | + mkdirSync(join(dest, rel), { recursive: true }); |
| 39 | + } |
| 40 | + const discard = ownedPathsToDiscard(HARNESS.templateOwnedPaths, dest); |
| 41 | + assert.equal(discard.length, 8); |
| 42 | + assert.deepEqual(discard.sort(), [...HARNESS.templateOwnedPaths].sort()); |
| 43 | +}); |
| 44 | + |
| 45 | +test('nonexistent destDir: nothing is discarded', () => { |
| 46 | + const dest = join(tmpProject(), 'does-not-exist'); |
| 47 | + assert.deepEqual(ownedPathsToDiscard(HARNESS.templateOwnedPaths, dest), []); |
| 48 | +}); |
| 49 | + |
| 50 | +test('empty/undefined templateOwnedPaths: nothing is discarded', () => { |
| 51 | + const dest = tmpProject(); |
| 52 | + assert.deepEqual(ownedPathsToDiscard(undefined, dest), []); |
| 53 | + assert.deepEqual(ownedPathsToDiscard([], dest), []); |
| 54 | +}); |
| 55 | + |
| 56 | +test('injectable exists: decision is pure and follows the predicate', () => { |
| 57 | + const seen = []; |
| 58 | + const exists = (p) => { |
| 59 | + seen.push(p); |
| 60 | + return p.endsWith(join('.cursor', 'skills', 'design-system')); |
| 61 | + }; |
| 62 | + const discard = ownedPathsToDiscard(HARNESS.templateOwnedPaths, '/virtual/project', exists); |
| 63 | + assert.deepEqual(discard, ['.cursor/skills/design-system']); |
| 64 | + assert.equal(seen.length, HARNESS.templateOwnedPaths.length); |
| 65 | +}); |
0 commit comments