126 lines
6.0 KiB
JavaScript
126 lines
6.0 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('node:assert/strict');
|
|
const test = require('node:test');
|
|
const {
|
|
authorizeControl,
|
|
authorizeReference,
|
|
createA8ExperimentLedger,
|
|
recordExperimentRun,
|
|
} = require('../../src/services/ps5-fpkg-a8-experiment-ledger');
|
|
const { qualifyA8ControlEvidence } = require('../../src/services/ps5-fpkg-a8-control-qualification');
|
|
|
|
const PROFILE = Object.freeze({
|
|
profileDigest: '1'.repeat(64), runtimeFingerprint: '2'.repeat(64),
|
|
workingTreeDigest: '3'.repeat(64), payloadSha256: '4'.repeat(64),
|
|
loaderSha256: '5'.repeat(64), readerSha256: '6'.repeat(64),
|
|
observabilityPatchSha256: '7'.repeat(64),
|
|
});
|
|
|
|
function ledger() {
|
|
const controlQualification = qualifyA8ControlEvidence({
|
|
titleId: 'PPSA01234', packageClass: 'fpkg', sourceEvidenceSha256: '8'.repeat(64),
|
|
route: '/api/ps5/app/launch',
|
|
preflight: { observedAtMs: 1_000, coverageComplete: true, truncated: false, exactTitleAbsent: true },
|
|
request: {
|
|
observedAtMs: 2_000, operationId: 'prior-qualified-control', titleId: 'PPSA01234',
|
|
clientRequests: 1, retryPerformed: false,
|
|
},
|
|
processSamples: [
|
|
{ observedAtMs: 2_100, coverageComplete: true, truncated: false, titleId: 'PPSA01234', kind: 'app', pid: 42 },
|
|
{ observedAtMs: 12_100, coverageComplete: true, truncated: false, titleId: 'PPSA01234', kind: 'app', pid: 42 },
|
|
],
|
|
packageEvidence: { fakePackage: true, artifactSha256: '9'.repeat(64), installedEvidenceSha256: 'a'.repeat(64) },
|
|
});
|
|
return createA8ExperimentLedger({
|
|
profile: PROFILE,
|
|
controlTitleId: 'PPSA01234',
|
|
referenceTitleId: 'FAKE00000',
|
|
controlQualification,
|
|
priorA7: { referenceRuns: 1, retryPerformed: false, ledgerConsumed: true },
|
|
});
|
|
}
|
|
|
|
function controlAuthorized() {
|
|
return authorizeControl(ledger(), 'LAUNCH CHIMERA P15 A8 CONTROL PPSA01234');
|
|
}
|
|
|
|
test('A8 host ledger freezes exact identities but grants no live action', () => {
|
|
const value = ledger();
|
|
assert.equal(value.status, 'host_qualified_control_pending');
|
|
assert.equal(value.liveAuthorization.control, false);
|
|
assert.equal(value.liveAuthorization.reference, false);
|
|
assert.equal(value.budget.control.used, 0);
|
|
assert.equal(value.budget.reference.used, 0);
|
|
assert.equal(value.priorA7.reusable, false);
|
|
assert.ok(Object.isFrozen(value));
|
|
});
|
|
|
|
test('A8 ledger rejects a ShellUI-only signed retail qualification', () => {
|
|
const controlQualification = qualifyA8ControlEvidence({
|
|
titleId: 'PPSA01234', packageClass: 'signed_retail', sourceEvidenceSha256: '8'.repeat(64),
|
|
route: '/api/ps5/app/launch',
|
|
preflight: { observedAtMs: 1_000, coverageComplete: true, truncated: false, exactTitleAbsent: true },
|
|
request: { observedAtMs: 2_000, operationId: 'retail-control', titleId: 'PPSA01234', clientRequests: 1, retryPerformed: false },
|
|
processSamples: [
|
|
{ observedAtMs: 2_100, coverageComplete: true, truncated: false, titleId: 'PPSA01234', kind: 'app', pid: 42 },
|
|
{ observedAtMs: 12_100, coverageComplete: true, truncated: false, titleId: 'PPSA01234', kind: 'app', pid: 42 },
|
|
],
|
|
packageEvidence: { fakePackage: false, artifactSha256: '9'.repeat(64), installedEvidenceSha256: 'a'.repeat(64) },
|
|
});
|
|
assert.throws(() => createA8ExperimentLedger({
|
|
profile: PROFILE, controlTitleId: 'PPSA01234', referenceTitleId: 'FAKE00000',
|
|
controlQualification,
|
|
priorA7: { referenceRuns: 1, retryPerformed: false, ledgerConsumed: true },
|
|
}), error => error.code === 'P15_A8_CONTROL_SCOPE_INSUFFICIENT');
|
|
});
|
|
|
|
test('A8 refuses reference-before-control, profile drift and retries', () => {
|
|
const value = ledger();
|
|
assert.throws(() => recordExperimentRun(value, {
|
|
role: 'reference', titleId: 'FAKE00000', profile: PROFILE, launchRequests: 1,
|
|
}), error => error.code === 'P15_A8_REFERENCE_NOT_AUTHORIZED');
|
|
assert.throws(
|
|
() => authorizeControl(value, 'LAUNCH VERIFY PPSA01234'),
|
|
error => error.code === 'P15_A8_CONTROL_CONFIRMATION_REQUIRED',
|
|
);
|
|
const authorized = controlAuthorized();
|
|
assert.throws(() => recordExperimentRun(authorized, {
|
|
role: 'control', titleId: 'PPSA01234', profile: { ...PROFILE, readerSha256: '8'.repeat(64) }, launchRequests: 1,
|
|
}), error => error.code === 'P15_A8_EXPERIMENT_PROFILE_DRIFT');
|
|
assert.throws(() => recordExperimentRun(authorized, {
|
|
role: 'control', titleId: 'PPSA01234', profile: PROFILE, launchRequests: 2,
|
|
}), error => error.code === 'P15_A8_EXPERIMENT_LEDGER_INVALID');
|
|
});
|
|
|
|
test('A8 permits a separately confirmed reference only after stable exact-title control', () => {
|
|
const afterControl = recordExperimentRun(controlAuthorized(), {
|
|
role: 'control', titleId: 'PPSA01234', profile: PROFILE, launchRequests: 1,
|
|
retryPerformed: false, stableExactTitleProcess: true, outcome: 'process_observed',
|
|
});
|
|
assert.equal(afterControl.status, 'control_passed_reference_confirmation_required');
|
|
assert.equal(afterControl.liveAuthorization.reference, false);
|
|
assert.throws(
|
|
() => authorizeReference(afterControl, 'LAUNCH VERIFY FAKE00000'),
|
|
error => error.code === 'P15_A8_REFERENCE_CONFIRMATION_REQUIRED',
|
|
);
|
|
const authorized = authorizeReference(afterControl, 'LAUNCH CHIMERA P15 A8 REFERENCE FAKE00000');
|
|
assert.equal(authorized.status, 'reference_authorized');
|
|
assert.equal(authorized.liveAuthorization.reference, true);
|
|
});
|
|
|
|
test('A8 does not authorize reference after an inconclusive control and never reuses a run', () => {
|
|
const afterControl = recordExperimentRun(controlAuthorized(), {
|
|
role: 'control', titleId: 'PPSA01234', profile: PROFILE, launchRequests: 1,
|
|
retryPerformed: false, stableExactTitleProcess: false, outcome: 'outcome_unknown',
|
|
});
|
|
assert.equal(afterControl.status, 'control_failed_or_inconclusive');
|
|
assert.throws(
|
|
() => authorizeReference(afterControl, 'LAUNCH CHIMERA P15 A8 REFERENCE FAKE00000'),
|
|
error => error.code === 'P15_A8_CONTROL_NOT_QUALIFIED',
|
|
);
|
|
assert.throws(() => recordExperimentRun(afterControl, {
|
|
role: 'control', titleId: 'PPSA01234', profile: PROFILE, launchRequests: 1,
|
|
}), error => error.code === 'P15_A8_EXPERIMENT_BUDGET_CONSUMED');
|
|
});
|