'use strict'; const assert = require('node:assert/strict'); const crypto = require('node:crypto'); const fs = require('node:fs'); const path = require('node:path'); const test = require('node:test'); const ROOT = path.resolve(__dirname, '../..'); const PATCH = path.join(ROOT, 'tools', 'ps5-kstuff-diagnostics', 'completion-observability.patch'); const READER = path.join(ROOT, 'tools', 'ps5-kstuff-diagnostics', 'completion-reader.c'); const BUILD = path.join(ROOT, 'scripts', 'autonomous', 'p15-a8-build-completion.sh'); const EVIDENCE = path.join(ROOT, 'docs', 'autonomous', 'evidence', 'P15_A8_HOST_QUALIFICATION_2026-08-26.json'); const EXPERIMENT = path.join(ROOT, 'docs', 'autonomous', 'evidence', 'P15_A8_CONTROL_REFERENCE_HOST_PLAN_2026-08-26.json'); const CONTROL_ASSESSMENT = path.join(ROOT, 'docs', 'autonomous', 'evidence', 'P15_A8_CONTROL_CANDIDATE_ASSESSMENT_2026-08-26.json'); function sha256Text(file) { const canonical = fs.readFileSync(file, 'utf8').replace(/\r\n/g, '\n'); return crypto.createHash('sha256').update(canonical, 'utf8').digest('hex'); } test('A8 carries explicit nmount attribution from arm into the utils trap', () => { const source = fs.readFileSync(PATCH, 'utf8'); assert.match(source, /start_syscall_with_dbgregs_tagged/); assert.match(source, /KSTUFF_SYSCALL_NMOUNT/); assert.match(source, /KSTUFF_DBGREGS_TAGGED_TRAP/); assert.match(source, /observe_tagged_syscall_debug_register/); assert.match(source, /debug_register_tagged_finish_entries/); assert.match(source, /debug_register_tagged_finish_peek_failures/); const additions = source.split(/\r?\n/).filter(line => /^\+(?!\+\+)/.test(line)).join('\n'); for (const forbidden of ['key_data', 'crypt_seed', 'eekpfs', 'mailboxBuffer', 'requestPointer', 'registerValues']) { assert.doesNotMatch(additions, new RegExp(forbidden, 'i')); } }); test('A8 leaves authentication and package semantics untouched', () => { const source = fs.readFileSync(PATCH, 'utf8'); for (const forbiddenFile of ['pfs_crypto.c', 'fakekeys.c', 'mailbox.c', 'fself.c', 'npdrm.c']) { assert.doesNotMatch(source, new RegExp(`diff --git a/ps5-kstuff/uelf/${forbiddenFile.replace('.', '\\.')}`)); } assert.match(source, /diff --git a\/ps5-kstuff\/uelf\/fpkg\.c/); assert.match(source, /handle_fpkg_syscall\(uint64_t\* regs, enum kstuff_syscall_tag tag\)/); }); test('A8 reader emits only bounded semantic completion counters', () => { const source = fs.readFileSync(READER, 'utf8'); assert.match(source, /schema=chimera\.p15-a8-completion-metrics\.v1/); assert.match(source, /completion tag=nmount/); assert.match(source, /finish_entry=/); assert.match(source, /finish_peek_fail=/); assert.match(source, /volatile_scrub\(&snapshot, sizeof\(snapshot\)\)/); for (const forbidden of ['word_log', 'msg_log', 'ioctl_com_table', 'key_data', 'dr0', 'mailbox-capture']) { assert.doesNotMatch(source, new RegExp(forbidden, 'i')); } }); test('A8 build is an offline incremental build over the immutable A7 patch', () => { const source = fs.readFileSync(BUILD, 'utf8'); const a7 = source.indexOf('route-selection-observability.patch'); const a8 = source.indexOf('completion-observability.patch'); assert.ok(a7 >= 0 && a8 > a7); assert.match(source, /expected_revision=3b2ab4a16ba43c8ab38daf7ec83cc297014e0e47/); assert.match(source, /--network none/); assert.doesNotMatch(source, /curl|wget|releases\/latest/i); }); test('A8 host evidence binds exact sources and grants no live action', () => { const evidence = JSON.parse(fs.readFileSync(EVIDENCE, 'utf8')); const plan = JSON.parse(fs.readFileSync(EXPERIMENT, 'utf8')); for (const item of evidence.patchStack) assert.equal(sha256Text(path.join(ROOT, item.path)), item.sha256); assert.equal(sha256Text(path.join(ROOT, evidence.reader.source)), evidence.reader.sourceSha256); assert.equal(sha256Text(path.join(ROOT, evidence.reader.makefile)), evidence.reader.makefileSha256); assert.equal(sha256Text(path.join(ROOT, evidence.build.script)), evidence.build.scriptSha256); assert.equal(sha256Text(path.join(ROOT, 'src/services/ps5-fpkg-completion-trace.js')), evidence.hostContracts.completionTraceSourceSha256); assert.equal(sha256Text(path.join(ROOT, 'src/services/ps5-fpkg-a8-experiment-ledger.js')), evidence.hostContracts.experimentLedgerSourceSha256); assert.equal(sha256Text(path.join(ROOT, 'src/services/ps5-fpkg-a8-control-qualification.js')), evidence.hostContracts.controlQualificationSourceSha256); assert.equal(sha256Text(path.join(ROOT, 'src/services/ps5-fpkg-control-candidate-service.js')), evidence.hostContracts.controlCandidateServiceSourceSha256); assert.equal(sha256Text(path.join(ROOT, 'src/services/ps5-fpkg-compatibility-profile-service.js')), evidence.hostContracts.durableLedgerSourceSha256); assert.match(evidence.hostContracts.launchServiceSourceSha256, /^[a-f0-9]{64}$/); const currentLaunchService = fs.readFileSync(path.join(ROOT, 'src/services/ps5-native-package-install-service.js'), 'utf8'); assert.match(currentLaunchService, /operation\.status !== 'installed_observed'[\s\S]{0,300}PS5_FPKG_LAUNCH_STATE/); const durableReservation = currentLaunchService.indexOf("status: 'launch_test_pending'"); const providerLaunch = currentLaunchService.indexOf('await provider.launch', durableReservation); assert.ok(durableReservation >= 0 && providerLaunch > durableReservation); assert.match(currentLaunchService, /productionRestorable: operation\.productionRestorable === true/); assert.equal(evidence.build.runs, 2); assert.equal(evidence.build.exactByteMatch, true); assert.equal(Object.values(evidence.liveActions).some(Boolean), false); assert.equal(plan.grantsLiveAction, false); assert.equal(plan.control.titleId, null); assert.equal(plan.reference.a7Ledger.reusable, false); assert.equal(plan.reference.a8Authorization, false); const assessment = JSON.parse(fs.readFileSync(CONTROL_ASSESSMENT, 'utf8')); assert.equal(assessment.status, 'no-full-fpkg-control-qualified'); assert.equal(assessment.existingEvidencePromoted, false); assert.equal(assessment.grantsLiveAction, false); assert.equal(assessment.candidates.find(item => item.titleId === 'PPSA02774').state, 'rejected_as_existing_evidence'); }); test('A8 cached control discovery is a read-only command and never starts a scan', () => { const registry = fs.readFileSync(path.join(ROOT, 'src/server/create-registry.js'), 'utf8'); const service = fs.readFileSync(path.join(ROOT, 'src/services/ps5-fpkg-control-candidate-service.js'), 'utf8'); assert.match(registry, /name: 'ps5-native-packages:a8-control-candidates', classification: 'read-only'/); assert.match(service, /source: 'cached-only-no-console-scan'/); assert.match(service, /consoleContacted: false, scanStarted: false, grantsLiveAction: false/); assert.doesNotMatch(service, /runConsoleScan|preflightLaunch\(|\.launch\(|\.install\(|fetch\(/); });