mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-04-02 07:03:28 +08:00
feat: orchestration harness, selective install, observer improvements
This commit is contained in:
139
tests/lib/install-state.test.js
Normal file
139
tests/lib/install-state.test.js
Normal file
@@ -0,0 +1,139 @@
|
||||
/**
|
||||
* Tests for scripts/lib/install-state.js
|
||||
*/
|
||||
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
|
||||
const {
|
||||
createInstallState,
|
||||
readInstallState,
|
||||
writeInstallState,
|
||||
} = require('../../scripts/lib/install-state');
|
||||
|
||||
function test(name, fn) {
|
||||
try {
|
||||
fn();
|
||||
console.log(` \u2713 ${name}`);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.log(` \u2717 ${name}`);
|
||||
console.log(` Error: ${error.message}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function createTestDir() {
|
||||
return fs.mkdtempSync(path.join(os.tmpdir(), 'install-state-'));
|
||||
}
|
||||
|
||||
function cleanupTestDir(dirPath) {
|
||||
fs.rmSync(dirPath, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
function runTests() {
|
||||
console.log('\n=== Testing install-state.js ===\n');
|
||||
|
||||
let passed = 0;
|
||||
let failed = 0;
|
||||
|
||||
if (test('creates a valid install-state payload', () => {
|
||||
const state = createInstallState({
|
||||
adapter: { id: 'cursor-project' },
|
||||
targetRoot: '/repo/.cursor',
|
||||
installStatePath: '/repo/.cursor/ecc-install-state.json',
|
||||
request: {
|
||||
profile: 'developer',
|
||||
modules: ['orchestration'],
|
||||
legacyLanguages: ['typescript'],
|
||||
legacyMode: true,
|
||||
},
|
||||
resolution: {
|
||||
selectedModules: ['rules-core', 'orchestration'],
|
||||
skippedModules: [],
|
||||
},
|
||||
operations: [
|
||||
{
|
||||
kind: 'copy-path',
|
||||
moduleId: 'rules-core',
|
||||
sourceRelativePath: 'rules',
|
||||
destinationPath: '/repo/.cursor/rules',
|
||||
strategy: 'preserve-relative-path',
|
||||
ownership: 'managed',
|
||||
scaffoldOnly: true,
|
||||
},
|
||||
],
|
||||
source: {
|
||||
repoVersion: '1.9.0',
|
||||
repoCommit: 'abc123',
|
||||
manifestVersion: 1,
|
||||
},
|
||||
installedAt: '2026-03-13T00:00:00Z',
|
||||
});
|
||||
|
||||
assert.strictEqual(state.schemaVersion, 'ecc.install.v1');
|
||||
assert.strictEqual(state.target.id, 'cursor-project');
|
||||
assert.strictEqual(state.request.profile, 'developer');
|
||||
assert.strictEqual(state.operations.length, 1);
|
||||
})) passed++; else failed++;
|
||||
|
||||
if (test('writes and reads install-state from disk', () => {
|
||||
const testDir = createTestDir();
|
||||
const statePath = path.join(testDir, 'ecc-install-state.json');
|
||||
|
||||
try {
|
||||
const state = createInstallState({
|
||||
adapter: { id: 'claude-home' },
|
||||
targetRoot: path.join(testDir, '.claude'),
|
||||
installStatePath: statePath,
|
||||
request: {
|
||||
profile: 'core',
|
||||
modules: [],
|
||||
legacyLanguages: [],
|
||||
legacyMode: false,
|
||||
},
|
||||
resolution: {
|
||||
selectedModules: ['rules-core'],
|
||||
skippedModules: [],
|
||||
},
|
||||
operations: [],
|
||||
source: {
|
||||
repoVersion: '1.9.0',
|
||||
repoCommit: 'abc123',
|
||||
manifestVersion: 1,
|
||||
},
|
||||
});
|
||||
|
||||
writeInstallState(statePath, state);
|
||||
const loaded = readInstallState(statePath);
|
||||
|
||||
assert.strictEqual(loaded.target.id, 'claude-home');
|
||||
assert.strictEqual(loaded.request.profile, 'core');
|
||||
assert.deepStrictEqual(loaded.resolution.selectedModules, ['rules-core']);
|
||||
} finally {
|
||||
cleanupTestDir(testDir);
|
||||
}
|
||||
})) passed++; else failed++;
|
||||
|
||||
if (test('rejects invalid install-state payloads on read', () => {
|
||||
const testDir = createTestDir();
|
||||
const statePath = path.join(testDir, 'ecc-install-state.json');
|
||||
|
||||
try {
|
||||
fs.writeFileSync(statePath, JSON.stringify({ schemaVersion: 'ecc.install.v1' }, null, 2));
|
||||
assert.throws(
|
||||
() => readInstallState(statePath),
|
||||
/Invalid install-state/
|
||||
);
|
||||
} finally {
|
||||
cleanupTestDir(testDir);
|
||||
}
|
||||
})) passed++; else failed++;
|
||||
|
||||
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
|
||||
process.exit(failed > 0 ? 1 : 0);
|
||||
}
|
||||
|
||||
runTests();
|
||||
Reference in New Issue
Block a user