Initial curated chimera source from a8ae5b1db07fb49926c94585e2718e5130330974
This commit is contained in:
commit
c737a37f71
531 files changed
+119270
No files matched your search
@@ -0,0 +1,73 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('node:assert/strict');
|
||||
const test = require('node:test');
|
||||
const initSqlJs = require('sql.js');
|
||||
const migration = require('../../src/database/migrations/0011-create-compatibility-findings');
|
||||
const { createCompatibilityProviderService, createSqliteCompatibilityRepository } = require('../../src/services/compatibility-provider-service');
|
||||
|
||||
async function fixture(options = {}) {
|
||||
const SQL = await initSqlJs({ locateFile: file => require.resolve(`sql.js/dist/${file}`) });
|
||||
const db = new SQL.Database();
|
||||
db.run('PRAGMA foreign_keys = ON');
|
||||
migration.up(db);
|
||||
const repository = createSqliteCompatibilityRepository({ db });
|
||||
const service = createCompatibilityProviderService({ repository, providers: options.providers || [{ id: 'alpha', sourceUrl: 'https://compat.example.org/alpha.json' }], fetchDocument: options.fetchDocument, now: options.now, limits: options.limits });
|
||||
return { db, repository, service };
|
||||
}
|
||||
|
||||
const finding = overrides => ({ key: 'game-base', titleId: 'PPSA12345', version: { min: '1.00', max: '2.00' }, firmware: { min: '8.00', max: '10.01' }, loaders: ['etahen'], storage: ['usb'], formats: ['ffpkg'], state: 'compatible', severity: 'info', explanation: 'Validated data-only compatibility evidence.', confidence: 'high', ...overrides });
|
||||
|
||||
test('valid provider snapshots store bounded provenance and applicability', async t => {
|
||||
const payload = { schemaVersion: 1, revision: 'alpha-2026.07', findings: [finding()] };
|
||||
const f = await fixture({ fetchDocument: async () => Buffer.from(JSON.stringify(payload)), now: () => 1_721_600_000_000 });
|
||||
t.after(() => f.db.close());
|
||||
const snapshot = await f.service.refresh('alpha');
|
||||
assert.match(snapshot.evidenceSha256, /^[a-f0-9]{64}$/);
|
||||
assert.equal(snapshot.revision, 'alpha-2026.07');
|
||||
assert.equal(snapshot.sourceUrl, 'https://compat.example.org/alpha.json');
|
||||
assert.equal(snapshot.fetchedAt, 1_721_600_000_000);
|
||||
const merged = f.service.merge({ titleId: 'PPSA12345', version: '1.50', firmware: '9.60', loader: 'etaHEN', storage: 'usb', format: 'ffpkg' });
|
||||
assert.equal(merged.findings.length, 1);
|
||||
assert.equal(merged.findings[0].confidence, 'high');
|
||||
assert.equal(merged.findings[0].revision, 'alpha-2026.07');
|
||||
assert.equal(f.service.merge({ titleId: 'PPSA12345', version: '3.00', firmware: '9.60', loader: 'etaHEN', storage: 'usb', format: 'ffpkg' }).findings.length, 0);
|
||||
});
|
||||
|
||||
test('hostile providers, executable fields, private sources and limits fail closed', async t => {
|
||||
await assert.rejects(fixture({ providers: [{ id: 'lan', sourceUrl: 'https://192.168.1.5/findings.json' }] }), /public HTTPS/);
|
||||
const f = await fixture({ fetchDocument: async () => ({ schemaVersion: 1, revision: 'hostile', findings: [{ ...finding(), action: { command: 'run' } }] }) });
|
||||
t.after(() => f.db.close());
|
||||
await assert.rejects(f.service.refresh('alpha'), error => error.code === 'COMPATIBILITY_EXECUTABLE_FIELD');
|
||||
assert.equal(f.repository.latest('alpha'), null);
|
||||
const limited = await fixture({ fetchDocument: async () => ({ schemaVersion: 1, revision: 'large', findings: [finding(), finding({ key: 'second' })] }), limits: { findings: 1 } });
|
||||
t.after(() => limited.db.close());
|
||||
await assert.rejects(limited.service.refresh('alpha'), error => error.code === 'COMPATIBILITY_LIMIT');
|
||||
});
|
||||
|
||||
test('conflicting providers remain visible and offline refresh returns explicit stale cache', async t => {
|
||||
let clock = 1_721_600_000_000;
|
||||
let offline = false;
|
||||
const documents = {
|
||||
alpha: { schemaVersion: 1, revision: 'a1', findings: [finding()] },
|
||||
beta: { schemaVersion: 1, revision: 'b7', findings: [finding({ state: 'incompatible', severity: 'critical', explanation: 'Conflicting lab result.' })] },
|
||||
};
|
||||
const f = await fixture({
|
||||
providers: [{ id: 'alpha', sourceUrl: 'https://compat.example.org/alpha.json' }, { id: 'beta', sourceUrl: 'https://compat.example.net/beta.json' }],
|
||||
fetchDocument: async provider => { if (offline) throw new Error('network offline'); return documents[provider.id]; },
|
||||
now: () => clock, limits: { maxAgeMs: 1_000 },
|
||||
});
|
||||
t.after(() => f.db.close());
|
||||
await f.service.refresh('alpha');
|
||||
await f.service.refresh('beta');
|
||||
const merged = f.service.merge({ titleId: 'PPSA12345', version: '1.50', firmware: '9.60', loader: 'etaHEN', storage: 'usb', format: 'ffpkg' });
|
||||
assert.deepEqual(merged.conflicts[0].states, ['compatible', 'incompatible']);
|
||||
assert.equal(merged.findings.every(item => item.conflictGroup === merged.conflicts[0].conflictGroup), true);
|
||||
assert.equal(merged.resolvedAutomatically, false);
|
||||
clock += 2_000;
|
||||
offline = true;
|
||||
const cached = await f.service.refresh('alpha');
|
||||
assert.equal(cached.offline, true);
|
||||
assert.equal(cached.stale, true);
|
||||
assert.equal(cached.revision, 'a1');
|
||||
});
|
||||
Reference in new issue
Block a user