46 lines
1.8 KiB
JavaScript
46 lines
1.8 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('fs');
|
|
const os = require('os');
|
|
const path = require('path');
|
|
const test = require('node:test');
|
|
const { classifyRoot, createSourceClassificationService } = require('../../src/services/source-classification-service');
|
|
|
|
test('source classifier recognizes PS4 and PS5 roots without changing settings', () => {
|
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'chimera-source-classification-'));
|
|
const ps4 = path.join(root, 'PS4');
|
|
const ps5 = path.join(root, 'PS5');
|
|
fs.mkdirSync(path.join(ps4, 'CUSA12345 Example'), { recursive: true });
|
|
fs.mkdirSync(path.join(ps5, 'PPSA54321 Example'), { recursive: true });
|
|
const writes = [];
|
|
try {
|
|
assert.equal(classifyRoot(ps4).classification, 'ps4');
|
|
assert.equal(classifyRoot(ps5).classification, 'ps5');
|
|
const service = createSourceClassificationService({
|
|
roots: () => [ps4, ps5],
|
|
settings: { get: (_key, fallback) => fallback, set: (...args) => writes.push(args) },
|
|
});
|
|
const result = service.analyze();
|
|
assert.equal(result.automaticChangesApplied, 0);
|
|
assert.equal(result.recommendations.length, 2);
|
|
assert.deepEqual(writes, []);
|
|
} finally {
|
|
fs.rmSync(root, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
test('source classifier leaves ambiguous and missing roots as review evidence', () => {
|
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'chimera-source-ambiguous-'));
|
|
try {
|
|
fs.writeFileSync(path.join(root, 'readme.txt'), 'unknown');
|
|
const ambiguous = classifyRoot(root);
|
|
const missing = classifyRoot(path.join(root, 'missing'));
|
|
assert.equal(ambiguous.classification, 'unknown');
|
|
assert.equal(ambiguous.confidence, 'low');
|
|
assert.equal(missing.exists, false);
|
|
} finally {
|
|
fs.rmSync(root, { recursive: true, force: true });
|
|
}
|
|
});
|