deadbyte-mcp 0.15.64 → 0.15.66

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/MANIFEST.SHA256 +64 -22
  2. package/PROVENANCE.json +32 -7
  3. package/README.txt +31 -18
  4. package/RELEASE.json +40 -7
  5. package/SBOM.cdx.json +2 -2
  6. package/TEST-MATRIX.json +48 -2
  7. package/bridge/package.json +1 -1
  8. package/controller/deadbyte-process-policy.json +4 -4
  9. package/docs/R168-ACTIVATION-RECONCILIATION-BLOCKER-20261026.md +39 -0
  10. package/docs/R168-CRASH-JOURNAL-PROTECTED-PREFLIGHT-20261026.md +46 -0
  11. package/docs/R168-FIVE-PLANE-FENCE-20261026.md +41 -0
  12. package/docs/R168-NATIVE-EXCLUSION-TERMINAL-CONTRACT-20261026.md +53 -0
  13. package/docs/R168-NPX-REMOTE-SKEW-HOTFIX-20261026.md +41 -0
  14. package/docs/R168-READONLY-AUDIT-AND-RESUME-20261026.md +56 -0
  15. package/docs/R168-SIGNED-RECONCILIATION-PRECOMMIT-20261026.md +45 -0
  16. package/package.json +6 -3
  17. package/scripts/deploy-r48.mjs +37 -4
  18. package/scripts/gate-windows-r167.ps1 +75 -0
  19. package/scripts/gate-windows-r168.ps1 +75 -0
  20. package/scripts/npm-release-r48.mjs +33 -3
  21. package/scripts/npm-release-readiness-r167.mjs +70 -0
  22. package/scripts/npm-release-readiness-r168.mjs +70 -0
  23. package/scripts/r168-audit-readonly.mjs +32 -0
  24. package/scripts/r168-npm-registry-readonly.mjs +19 -0
  25. package/scripts/r168-protected-preflight.mjs +65 -0
  26. package/scripts/r168-release-scan.mjs +28 -0
  27. package/scripts/r168-source-full-test-runner.mjs +46 -0
  28. package/scripts/r168-subject-readonly.mjs +49 -0
  29. package/src/activation-path-r167.mjs +55 -0
  30. package/src/activation-reconciliation-audit-r168.mjs +200 -0
  31. package/src/activation-reconciliation-consent-r168.mjs +235 -0
  32. package/src/activation-reconciliation-fence-r168.mjs +87 -0
  33. package/src/activation-reconciliation-journal-r168.mjs +100 -0
  34. package/src/activation-reconciliation-receipt-store-r168.mjs +42 -0
  35. package/src/activation-reconciliation-terminal-r168.mjs +111 -0
  36. package/src/deadbyte-cli.mjs +20 -0
  37. package/src/npm-publication-resume-r168.mjs +25 -0
  38. package/src/remote-one-shot-coherence-r168.mjs +36 -0
  39. package/src/version.mjs +1 -1
  40. package/test/process-policy-refresh.test.mjs +8 -5
  41. package/test/r130-release-security-contract.test.mjs +7 -7
  42. package/test/r132-release-identity.test.mjs +7 -7
  43. package/test/r153-prepublish-identity.test.mjs +2 -2
  44. package/test/r160-release-contract.test.mjs +4 -12
  45. package/test/r163-isolated-slot-rollback-restore.test.mjs +2 -2
  46. package/test/r165-live-cli-skew.test.mjs +7 -7
  47. package/test/r167-activation-path.test.mjs +124 -0
  48. package/test/r167-release-contract.test.mjs +51 -0
  49. package/test/r167-release-readiness.test.mjs +27 -0
  50. package/test/r168-combined-targeted-runner.mjs +14 -0
  51. package/test/r168-crash-journal.test.mjs +149 -0
  52. package/test/r168-five-plane-fence-runner.mjs +11 -0
  53. package/test/r168-five-plane-fence.test.mjs +128 -0
  54. package/test/r168-focused-suite.test.mjs +4 -0
  55. package/test/r168-native-five-plane-runner.mjs +11 -0
  56. package/test/r168-native-five-plane-scratch.test.mjs +49 -0
  57. package/test/r168-native-r85-protected-scratch.test.mjs +44 -0
  58. package/test/r168-npm-resume-identity.test.mjs +49 -0
  59. package/test/r168-owner-reconciliation-contract.test.mjs +250 -0
  60. package/test/r168-protected-entrypoint.test.mjs +53 -0
  61. package/test/r168-reconciliation-audit.test.mjs +42 -0
  62. package/test/r168-release-contract.test.mjs +56 -0
  63. package/test/r168-remote-one-shot-coherence.test.mjs +65 -0
  64. package/test/r59-tool-surface-compat.test.mjs +1 -1
  65. package/test/r63-one-shot-coherence.test.mjs +10 -5
  66. package/node_modules/which/CHANGELOG.md +0 -166
@@ -0,0 +1,51 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import {readFile} from 'node:fs/promises';
4
+ import path from 'node:path';
5
+ import {fileURLToPath} from 'node:url';
6
+ import {DEADBYTE_VERSION} from '../src/version.mjs';
7
+
8
+ const root=path.resolve(fileURLToPath(new URL('..',import.meta.url)));
9
+ const read=async rel=>JSON.parse(await readFile(path.join(root,rel),'utf8'));
10
+ const readOptional=async rel=>{try{return await read(rel);}catch(error){if(error?.code==='ENOENT')return null;throw error;}};
11
+ const VERSION='0.15.66';
12
+ const R166_MANIFEST='ad3c091fbbe2bac6d234548724008b67305fd483ad6542f92d5aeb1aa84f5849';
13
+ const R166_TARBALL='3d22412c3cebabd66bfa92ca4dbaaf3ef49acba7f92436a16485d7e4cb18c653';
14
+
15
+ test('R168 package identity binds published R167 source separately from active R153 runtime',async()=>{
16
+ const [pkg,lock,bridge,release,provenance,matrix,bom]=await Promise.all([
17
+ read('package.json'),readOptional('package-lock.json'),read('bridge/package.json'),read('RELEASE.json'),
18
+ read('PROVENANCE.json'),read('TEST-MATRIX.json'),read('SBOM.cdx.json')]);
19
+ const versions=[pkg.version,bridge.version,release.version,
20
+ provenance.version,matrix.version,bom.metadata.component.version,DEADBYTE_VERSION];
21
+ if(lock)versions.push(lock.version,lock.packages[''].version);
22
+ for(const version of versions)assert.equal(version,VERSION);
23
+ assert.equal(release.train,'R168');
24
+ assert.equal(matrix.train,'R168');
25
+ assert.equal(bom.serialNumber,'urn:cdx:deadbyte-mcp:r168:0.15.66');
26
+ assert.deepEqual(release.runtime_predecessor,{
27
+ version:'0.15.61',release_id:'v0.15.61-055d1ff0aa99e60b',
28
+ manifest_sha256:'055d1ff0aa99e60bbf9e9f136b02ebd4fffb8391712560f7607cff30af94dcdf',
29
+ generation_manifest_sha256:'f940e794daac2dda097a66301c4b85c4b29a2df7c669e549503c05a2a55ff6c4'
30
+ });
31
+ assert.equal(release.source_predecessor.version,'0.15.65');
32
+ assert.equal(release.source_predecessor.train,'R167');
33
+ assert.equal(release.source_predecessor.tarball_sha256,'fc3ae5b1505e316bc9dfedf8d063cb00641754c8f5f1306a31f8cc4bb84c9484');
34
+ assert.equal(release.r167.source_predecessor_manifest_sha256,R166_MANIFEST);
35
+ assert.equal(provenance.source_predecessor_manifest_file_sha256,'3316654646cc870584a7c969c2032af6c795229ff8c65e5a8b794f97c2458c41');
36
+ assert.equal(provenance.source_predecessor_tarball_sha256,'fc3ae5b1505e316bc9dfedf8d063cb00641754c8f5f1306a31f8cc4bb84c9484');
37
+ assert.equal(release.r167.public_tool_delta,0);
38
+ assert.equal(release.r167.authority_scope_delta,0);
39
+ assert.equal(release.r167.production_activation,'NOT_RUN');
40
+ assert.equal(release.r167.npm_publish,'NOT_RUN');
41
+ });
42
+
43
+ test('R167 protected continuity remains pending until exact Windows fixture evidence exists',async()=>{
44
+ const [release,provenance,matrix]=await Promise.all([
45
+ read('RELEASE.json'),read('PROVENANCE.json'),read('TEST-MATRIX.json')]);
46
+ assert.equal(release.r167.protected_entrypoint_continuity,'PENDING_PROTECTED_WINDOWS_FIXTURE');
47
+ assert.equal(provenance.r167.final_manifest_evidence,'PENDING_PROTECTED_WINDOWS_FIXTURE');
48
+ assert.equal(matrix.r167.protected_epoch_continuity,'PENDING_PROTECTED_WINDOWS_FIXTURE');
49
+ assert.equal(matrix.r167.new_public_tools,0);
50
+ assert.equal(matrix.r167.new_authority_scopes,0);
51
+ });
@@ -0,0 +1,27 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import path from 'node:path';
4
+ import {fileURLToPath} from 'node:url';
5
+ import {readFile} from 'node:fs/promises';
6
+ import {assertR167NpmPublishReady,assertR167PackedIdentity} from '../scripts/npm-release-readiness-r167.mjs';
7
+
8
+ const root=path.resolve(fileURLToPath(new URL('..',import.meta.url)));
9
+
10
+ test('R167 publication refuses absent external exact-byte closure',async()=>{
11
+ const release=JSON.parse(await readFile(path.join(root,'RELEASE.json'),'utf8'));
12
+ const prior=process.env.DEADBYTE_R167_CLOSURE_ROOT;
13
+ try{
14
+ delete process.env.DEADBYTE_R167_CLOSURE_ROOT;
15
+ await assert.rejects(assertR167NpmPublishReady(release,{root}),/PUBLISH_BLOCKED R167/);
16
+ }finally{
17
+ if(prior===undefined)delete process.env.DEADBYTE_R167_CLOSURE_ROOT;
18
+ else process.env.DEADBYTE_R167_CLOSURE_ROOT=prior;
19
+ }
20
+ });
21
+
22
+ test('R167 publication rejects a repacked artifact that differs from verified closure bytes',()=>{
23
+ const expected={tarball_sha256:'a'.repeat(64),tarball_integrity:'sha512-expected',tarball_shasum:'b'.repeat(40)};
24
+ assert.throws(()=>assertR167PackedIdentity({
25
+ ...expected,observedSha256:'c'.repeat(64),observedIntegrity:'sha512-other',observedShasum:'d'.repeat(40)
26
+ }),/PUBLISH_BLOCKED R167.*tarball/i);
27
+ });
@@ -0,0 +1,14 @@
1
+ // R168 targeted test entrypoint. Does not invoke production authority.
2
+ import {spawnSync} from 'node:child_process';
3
+ import {fileURLToPath} from 'node:url';
4
+ import path from 'node:path';
5
+
6
+ const dir=path.dirname(fileURLToPath(import.meta.url));
7
+ const cases=['r168-five-plane-fence.test.mjs','r168-focused-suite.test.mjs','r168-crash-journal.test.mjs','r168-protected-entrypoint.test.mjs','r168-remote-one-shot-coherence.test.mjs'];
8
+ const result=spawnSync(process.execPath,['--test','--test-concurrency=1',...cases.map(x=>path.join(dir,x))],{
9
+ cwd:dir,encoding:'utf8',shell:false,windowsHide:true,timeout:120000,maxBuffer:3*1024*1024
10
+ });
11
+ if(result.stdout)process.stdout.write(result.stdout);
12
+ if(result.stderr)process.stderr.write(result.stderr);
13
+ if(result.error)throw result.error;
14
+ process.exitCode=result.status??1;
@@ -0,0 +1,149 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import path from 'node:path';
4
+ import os from 'node:os';
5
+ import {mkdtemp,mkdir,lstat,readFile,rm,readdir,writeFile} from 'node:fs/promises';
6
+ import {pathToFileURL} from 'node:url';
7
+ import {simulateR168FivePlaneEpochFence} from '../src/activation-reconciliation-fence-r168.mjs';
8
+ import {queryForegroundIdentity} from '../src/foreground-process-identity.mjs';
9
+ import {readPinnedEpochLockSnapshot,deletePinnedRemoteMarker} from '../src/foreground-marker-cas-win32.mjs';
10
+ import {createHash,generateKeyPairSync,sign} from 'node:crypto';
11
+ import {canonicalJson} from '../src/canonical-json.mjs';
12
+ import {createR168ReconciliationSubject,createR168SignedAuthorization,makeR168ConsentChallenge} from '../src/activation-reconciliation-consent-r168.mjs';
13
+ import {createR168TerminalResult} from '../src/activation-reconciliation-terminal-r168.mjs';
14
+ import {prepareR168TerminalIntent,classifyR168Recovery} from '../src/activation-reconciliation-journal-r168.mjs';
15
+
16
+ const digest=o=>createHash('sha256').update(typeof o==='string'?o:canonicalJson(o)).digest('hex');
17
+ const OWNER=generateKeyPairSync('ed25519'),MACHINE=generateKeyPairSync('ed25519');
18
+ const now='2026-10-26T08:00:00.000Z',later='2026-10-27T08:00:00.000Z';
19
+ function fixture({fileId='1234567890abcdef:1234567890abcdef1234567890abcdef'}={}){
20
+ const planes=['process','coding','autonomous','desktop','host'];
21
+ const counts=[27,29,24,28,26];
22
+ const history=Object.fromEntries(planes.map((p,i)=>[p,{status:'PASS',verified_events:counts[i],event_sha256:digest(p),head_action:p==='coding'?'grant':'user_revoke'}]));
23
+ const obs={schema:'deadbyte.r168-readonly-reconciliation-observation.v1',
24
+ status:'NO_MATCHING_TRANSACTION_OBSERVED',terminalization_authorized:false,
25
+ old_operation_id:'c84d7ffa4eee80a2f467acda3ddd9332',
26
+ old_continuity_update_id:'r65-ef42bc84451ce024c4dee736d4047b36',
27
+ old_claim_sha256:digest('claim'),old_outcome_sha256:digest('outcome'),predecessor_pointer_sha256:digest('pointer'),
28
+ coding_policy_sha256:digest('policy'),coding_grant_sha256:digest('grant'),
29
+ coding_epoch_sha256:history.coding.event_sha256,candidate_manifest_sha256:digest('candidate'),
30
+ epoch_history:history,signed_event_count:134,update_inventory_count:376};
31
+ const observation={...obs,observation_sha256:digest(obs)};
32
+ const subject=createR168ReconciliationSubject({observation,
33
+ claimSnapshot:{sha256:obs.old_claim_sha256,fileId},
34
+ stateRoot:'C:\\Users\\DEADBYTE\\.deadbyte-mcp'});
35
+ const body={schema:'deadbyte.r168-owner-approval.v1',action:'terminalize_unknown_without_replay',
36
+ subject_sha256:subject.subject_sha256,claim_operation_id:subject.claim_operation_id,
37
+ nonce:digest('nonce'),issued_at_utc:'2026-10-26T07:59:00.000Z',expires_at_utc:'2026-10-26T08:04:00.000Z'};
38
+ const signature=sign(null,Buffer.concat([Buffer.from('DEADBYTE-R168-OWNER-APPROVAL-V1\0'),Buffer.from(canonicalJson(body))]),OWNER.privateKey);
39
+ const approval={body,attestation:{algorithm:'ed25519',domain:'DEADBYTE-R168-OWNER-APPROVAL-V1',signature_base64:signature.toString('base64')}};
40
+ const prepared=createR168SignedAuthorization({subject,approval,ownerPublicKey:OWNER.publicKey,
41
+ machinePrivateKey:MACHINE.privateKey,now,typedConfirmation:makeR168ConsentChallenge(subject)});
42
+ const common={subject,approval,prepared,ownerPublicKey:OWNER.publicKey,machinePublicKey:MACHINE.publicKey};
43
+ return common;
44
+ }
45
+ async function isolated(fn){
46
+ const dir=await mkdtemp(path.join(os.tmpdir(),'r168-crash-journal-'));
47
+ try{return await fn(dir);}finally{await rm(dir,{recursive:true,force:true});}
48
+ }
49
+ test('R168 terminal intent is exclusive, durable-readback, and cannot be reused or overwritten',()=>isolated(async dir=>{
50
+ const common=fixture();
51
+ const result=await prepareR168TerminalIntent({evidenceDir:dir,...common,now});
52
+ assert.match(result.sha256,/^[0-9a-f]{64}$/);
53
+ const parsed=JSON.parse(await readFile(result.file,'utf8'));
54
+ assert.equal(parsed.body.phase,'INTENT_PREPARED_ONLY');
55
+ assert.equal(parsed.body.terminalization_committed,false);
56
+ assert.equal(parsed.body.activation_authorized,false);
57
+ assert.equal(parsed.body.claim_file_id,common.subject.claim_file_id);
58
+ await assert.rejects(prepareR168TerminalIntent({evidenceDir:dir,...common,now}),/exists|one-use|clobber/i);
59
+ assert.equal((await readdir(dir)).length,1);
60
+ }));
61
+ test('R168 interrupted operation with original claim still present remains blocked and does not replay CAS',()=>isolated(async dir=>{
62
+ const common=fixture();
63
+ const record=await prepareR168TerminalIntent({evidenceDir:dir,...common,now});
64
+ const observedClaim={state:'PRESENT',fileId:common.subject.claim_file_id,sha256:common.subject.claim_file_sha256};
65
+ const status=await classifyR168Recovery({...common,recordFile:record.file,observedClaim,now:later});
66
+ assert.equal(status.state,'PRECOMMIT_CLAIM_PRESENT_BLOCKED');
67
+ assert.equal(status.activation_authorized,false);
68
+ assert.equal(status.terminalization_committed,false);
69
+ }));
70
+ test('R168 interrupted operation with missing claim but absent terminal proof stays unknown and blocked',()=>isolated(async dir=>{
71
+ const common=fixture();
72
+ const record=await prepareR168TerminalIntent({evidenceDir:dir,...common,now});
73
+ const status=await classifyR168Recovery({...common,recordFile:record.file,observedClaim:{state:'ABSENT'},now:later});
74
+ assert.equal(status.state,'CAS_OUTCOME_UNKNOWN_BLOCKED');
75
+ assert.equal(status.activation_authorized,false);
76
+ }));
77
+ test('R168 claim replacement or tampered journal is never treated as successful reconciliation',()=>isolated(async dir=>{
78
+ const common=fixture(),record=await prepareR168TerminalIntent({evidenceDir:dir,...common,now});
79
+ const status=await classifyR168Recovery({...common,recordFile:record.file,
80
+ observedClaim:{state:'PRESENT',fileId:common.subject.claim_file_id,sha256:digest('new-claim')},now:later});
81
+ assert.equal(status.state,'CLAIM_CHANGED_BLOCKED');
82
+ const parsed=JSON.parse(await readFile(record.file,'utf8'));
83
+ parsed.body.activation_authorized=true;
84
+ await writeFile(record.file,JSON.stringify(parsed)+'\n');
85
+ await assert.rejects(classifyR168Recovery({...common,recordFile:record.file,
86
+ observedClaim:{state:'ABSENT'},now:later}),/journal|digest|tamper/i);
87
+ }));
88
+ test('R168 verified terminal result can be archived after owner approval expiry but never auto-activates',()=>isolated(async dir=>{
89
+ const common=fixture(),record=await prepareR168TerminalIntent({evidenceDir:dir,...common,now});
90
+ const after={native_cas_result:'REMOVED',claim_absent:true,
91
+ pointer_sha256:common.subject.predecessor_pointer_sha256,old_outcome_sha256:common.subject.old_outcome_sha256,
92
+ coding_policy_sha256:common.subject.coding_policy_sha256,coding_grant_sha256:common.subject.coding_grant_sha256,
93
+ coding_epoch_sha256:common.subject.coding_epoch_sha256,epoch_history:common.subject.epoch_history};
94
+ const terminal=createR168TerminalResult({...common,machinePrivateKey:MACHINE.privateKey,after,now});
95
+ const status=await classifyR168Recovery({...common,recordFile:record.file,
96
+ observedClaim:{state:'ABSENT'},terminal,after,now:later});
97
+ assert.equal(status.state,'TERMINAL_VERIFIED_ACTIVATION_SEPARATE');
98
+ assert.equal(status.terminalization_committed,true);
99
+ assert.equal(status.activation_authorized,false);
100
+ await assert.rejects(classifyR168Recovery({...common,recordFile:record.file,
101
+ observedClaim:{state:'PRESENT',fileId:common.subject.claim_file_id,sha256:common.subject.claim_file_sha256},
102
+ terminal,after,now:later}),/terminal|claim|ambiguous/i);
103
+ }));
104
+
105
+ test('R168 real R85 five-plane scratch fence + journal + FileId-bound native CAS + terminal proof',()=>isolated(async root=>{
106
+ if(process.platform!=='win32')return;
107
+ const protectedRoot='C:\\Program Files\\DEADBYTE-R167-Protected-0.15.65-3316654646cc8705-Fix6';
108
+ const originalManifest=await readFile(path.join(protectedRoot,'MANIFEST.SHA256'));
109
+ assert.equal(createHash('sha256').update(originalManifest).digest('hex'),'3316654646cc870584a7c969c2032af6c795229ff8c65e5a8b794f97c2458c41');
110
+ const {acquireHeldEpochLock}=await import(pathToFileURL(path.join(protectedRoot,'src','epoch-lock-r85.mjs')).href);
111
+ const planes=['process','coding','autonomous','desktop','host'];
112
+ for(const plane of planes)await mkdir(path.join(root,'runtime','authority-epochs',plane),{recursive:true});
113
+ const evid=path.join(root,'evidence');await mkdir(evid);
114
+ const claimPath=path.join(root,'r65-activation.lock');
115
+ await writeFile(claimPath,'claim');
116
+ const observed=readPinnedEpochLockSnapshot(claimPath);
117
+ assert.equal(observed.sha256,digest('claim'));
118
+ const common=fixture({fileId:observed.fileId});
119
+ const after={native_cas_result:'REMOVED',claim_absent:true,
120
+ pointer_sha256:common.subject.predecessor_pointer_sha256,old_outcome_sha256:common.subject.old_outcome_sha256,
121
+ coding_policy_sha256:common.subject.coding_policy_sha256,coding_grant_sha256:common.subject.coding_grant_sha256,
122
+ coding_epoch_sha256:common.subject.coding_epoch_sha256,epoch_history:common.subject.epoch_history};
123
+ const result=await simulateR168FivePlaneEpochFence({stateRoot:root,
124
+ testOwnerIdentity:queryForegroundIdentity(process.pid),testAcquire:acquireHeldEpochLock,
125
+ onHeld:async({assertHeld})=>{
126
+ assert.equal(assertHeld(),true);
127
+ const before=readPinnedEpochLockSnapshot(claimPath);
128
+ assert.equal(before.fileId,common.subject.claim_file_id);
129
+ const intent=await prepareR168TerminalIntent({evidenceDir:evid,...common,now});
130
+ const receiptBefore=await classifyR168Recovery({...common,recordFile:intent.file,
131
+ observedClaim:{state:'PRESENT',fileId:before.fileId,sha256:before.sha256},now:later});
132
+ assert.equal(receiptBefore.state,'PRECOMMIT_CLAIM_PRESENT_BLOCKED');
133
+ const status=deletePinnedRemoteMarker(claimPath,before.sha256,{expectedFileId:before.fileId});
134
+ assert.equal(status,'REMOVED');
135
+ assert.equal(readPinnedEpochLockSnapshot(claimPath),null);
136
+ const terminal=createR168TerminalResult({...common,machinePrivateKey:MACHINE.privateKey,after,now});
137
+ const final=await classifyR168Recovery({...common,recordFile:intent.file,
138
+ observedClaim:{state:'ABSENT'},terminal,after,now:later});
139
+ assert.equal(final.state,'TERMINAL_VERIFIED_ACTIVATION_SEPARATE');
140
+ assert.equal(final.activation_authorized,false);
141
+ return final.state;
142
+ }});
143
+ assert.equal(result,'TERMINAL_VERIFIED_ACTIVATION_SEPARATE');
144
+ await assert.rejects(lstat(claimPath),e=>e.code==='ENOENT');
145
+ for(const plane of planes){
146
+ await assert.rejects(lstat(path.join(root,'runtime','authority-epochs',plane,'.lock')),
147
+ e=>e.code==='ENOENT');
148
+ }
149
+ }));
@@ -0,0 +1,11 @@
1
+ // Explicit Node --test worker isolation for R168 native fence test adapters.
2
+ import {spawnSync} from 'node:child_process';
3
+ import {fileURLToPath} from 'node:url';
4
+ import path from 'node:path';
5
+ const file=fileURLToPath(new URL('./r168-five-plane-fence.test.mjs',import.meta.url));
6
+ const child=spawnSync(process.execPath,['--test',file],{cwd:path.dirname(file),
7
+ shell:false,encoding:'utf8',timeout:60000,windowsHide:true,maxBuffer:1024*1024});
8
+ process.stdout.write(child.stdout??'');
9
+ process.stderr.write(child.stderr??'');
10
+ if(child.error)throw child.error;
11
+ process.exitCode=child.status??1;
@@ -0,0 +1,128 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import {mkdtemp,mkdir,rm} from 'node:fs/promises';
4
+ import path from 'node:path';
5
+ import os from 'node:os';
6
+ import {simulateR168FivePlaneEpochFence,withR168FivePlaneEpochFence} from '../src/activation-reconciliation-fence-r168.mjs';
7
+
8
+ const planes=['process','coding','autonomous','desktop','host'];
9
+ async function fixture(run){
10
+ const root=await mkdtemp(path.join(os.tmpdir(),'deadbyte-r168-fence-'));
11
+ try{
12
+ for(const plane of planes)await mkdir(path.join(root,'runtime','authority-epochs',plane),{recursive:true});
13
+ return await run(root);
14
+ }finally{await rm(root,{recursive:true,force:true});}
15
+ }
16
+ const makeAcquire=(calls,{rejectPlane=null,releaseFailurePlane=null,observedLocks=null}={})=>
17
+ async(file,bytes)=>{
18
+ const plane=path.basename(path.dirname(file));
19
+ const owner=JSON.parse(bytes.toString('utf8'));
20
+ assert.equal(owner.schema,'deadbyte.authority-epoch-lock.r65.v1');
21
+ assert.equal(owner.pid,process.pid);
22
+ assert.match(owner.token,/^[a-f0-9]{32}$/);
23
+ calls.push('acquire:'+plane);
24
+ if(rejectPlane===plane)return null;
25
+ observedLocks?.add(plane);
26
+ let done=false;
27
+ return {async release(){
28
+ assert.equal(done,false);done=true;
29
+ calls.push('release:'+plane);
30
+ observedLocks?.delete(plane);
31
+ if(releaseFailurePlane===plane)throw new Error('release exploded:'+plane);
32
+ }};
33
+ };
34
+ async function gated(root,calls,work,options={}){
35
+ return simulateR168FivePlaneEpochFence({
36
+ stateRoot:root,onHeld:work,
37
+ testAcquire:makeAcquire(calls,options),
38
+ testOwnerIdentity:{schema:'deadbyte.foreground-process.v1',pid:process.pid,
39
+ parent_pid:0,creation_utc:'2026-10-26T00:00:00.000Z',executable_path:process.execPath,
40
+ command_line_sha256:'a'.repeat(64)}
41
+ });
42
+ }
43
+ test('R168 takes all five R85 epoch locks in deterministic order before final audit/CAS callback',()=>fixture(async root=>{
44
+ const calls=[],locks=new Set();
45
+ const result=await simulateR168FivePlaneEpochFence({stateRoot:root,
46
+ testAcquire:makeAcquire(calls,{observedLocks:locks}),
47
+ testOwnerIdentity:{schema:'deadbyte.foreground-process.v1',pid:process.pid,parent_pid:0,
48
+ creation_utc:'2026-10-26T00:00:00.000Z',executable_path:process.execPath,command_line_sha256:'a'.repeat(64)},
49
+ onHeld:async({planeOrder,assertHeld})=>{
50
+ assert.deepEqual(planeOrder,planes);
51
+ assert.deepEqual([...locks],planes);
52
+ assert.equal(assertHeld(),true);
53
+ calls.push('final-audit');
54
+ calls.push('expected-CAS-not-executed');
55
+ return 'R168_NO_MUTATION';
56
+ }
57
+ });
58
+ assert.equal(result,'R168_NO_MUTATION');
59
+ assert.deepEqual(calls,[
60
+ ...planes.map(p=>'acquire:'+p),'final-audit','expected-CAS-not-executed',
61
+ ...planes.toReversed().map(p=>'release:'+p)
62
+ ]);
63
+ assert.equal(locks.size,0);
64
+ }));
65
+ test('R168 partial native acquisition failure releases prior handles in reverse and never runs audit',()=>fixture(async root=>{
66
+ const calls=[];
67
+ await assert.rejects(gated(root,calls,async()=>{calls.push('UNEXPECTED_AUDIT');},{rejectPlane:'desktop'}),
68
+ /lock|held|busy/i);
69
+ assert.deepEqual(calls,['acquire:process','acquire:coding','acquire:autonomous','acquire:desktop',
70
+ 'release:autonomous','release:coding','release:process']);
71
+ }));
72
+ test('R168 work abort releases all native handles; error is not reported as terminal success',()=>fixture(async root=>{
73
+ const calls=[];
74
+ await assert.rejects(gated(root,calls,async()=>{calls.push('signed-audit');throw new Error('audit mismatch');}),/audit mismatch/);
75
+ assert.deepEqual(calls.slice(-5),planes.toReversed().map(p=>'release:'+p));
76
+ }));
77
+ test('R168 native release ambiguity cannot be suppressed by callback success',()=>fixture(async root=>{
78
+ const calls=[];
79
+ await assert.rejects(gated(root,calls,async()=>true,{releaseFailurePlane:'coding'}),
80
+ error=>error instanceof AggregateError&&/release ambiguous/i.test(error.message)&&
81
+ error.errors.some(e=>e.cause?.message==='release exploded:coding'));
82
+ assert.deepEqual(calls.slice(-5),planes.toReversed().map(p=>'release:'+p));
83
+ }));
84
+ test('R168 missing epoch-plane directory stops before any acquisition',()=>fixture(async root=>{
85
+ const calls=[];
86
+ await rm(path.join(root,'runtime','authority-epochs','host'),{recursive:true});
87
+ await assert.rejects(gated(root,calls,async()=>true),/directory|epoch/i);
88
+ assert.deepEqual(calls,[]);
89
+ }));
90
+
91
+ test('R168 holding five epoch locks excludes concurrent normal authority append on every plane',()=>fixture(async root=>{
92
+ const active=new Set(),calls=[];
93
+ const nativeLikeAcquire=async(file)=>{
94
+ const plane=path.basename(path.dirname(file));
95
+ calls.push('acquire:'+plane);
96
+ if(active.has(plane))return null;
97
+ active.add(plane);
98
+ return {async release(){active.delete(plane);}};
99
+ };
100
+ const result=await simulateR168FivePlaneEpochFence({stateRoot:root,
101
+ testAcquire:nativeLikeAcquire,
102
+ testOwnerIdentity:{schema:'deadbyte.foreground-process.v1',pid:process.pid,parent_pid:0,
103
+ creation_utc:'2026-10-26T00:00:00.000Z',executable_path:process.execPath,command_line_sha256:'a'.repeat(64)},
104
+ onHeld:async({assertHeld})=>{
105
+ assertHeld();
106
+ for(const plane of planes){
107
+ const normalAppend=await nativeLikeAcquire(path.join(root,'runtime','authority-epochs',plane,'.lock'));
108
+ assert.equal(normalAppend,null,'append must not acquire '+plane+' while R168 holds exclusion');
109
+ }
110
+ return 'NO_MUTATION';
111
+ }
112
+ });
113
+ assert.equal(result,'NO_MUTATION');
114
+ assert.deepEqual([...active],[]);
115
+ assert.equal(calls.length,10);
116
+ }));
117
+ test('R168 never attempts stale epoch-lock recovery when busy; fail closed',()=>fixture(async root=>{
118
+ const calls=[];
119
+ await assert.rejects(gated(root,calls,async()=>{throw new Error('should not audit')},
120
+ {rejectPlane:'coding'}),/native lock busy: coding/);
121
+ assert.deepEqual(calls,['acquire:process','acquire:coding','release:process']);
122
+ }));
123
+
124
+ test('R168 protected production API refuses injection even inside test worker',()=>fixture(async root=>{
125
+ const acquire=async()=>({release:async()=>{}});
126
+ await assert.rejects(withR168FivePlaneEpochFence({stateRoot:root,onHeld:async()=>true,
127
+ testAcquire:acquire}),/forbids injected/);
128
+ }));
@@ -0,0 +1,4 @@
1
+ // R168 integrated focused suite: live-free and without any production mutation.
2
+ import './r168-reconciliation-audit.test.mjs';
3
+ import './r168-owner-reconciliation-contract.test.mjs';
4
+ import './r168-npm-resume-identity.test.mjs';
@@ -0,0 +1,11 @@
1
+ import {spawnSync} from 'node:child_process';
2
+ import path from 'node:path';
3
+ import {fileURLToPath} from 'node:url';
4
+ const target=fileURLToPath(new URL('./r168-native-five-plane-scratch.test.mjs',import.meta.url));
5
+ const result=spawnSync(process.execPath,['--test',target],{
6
+ cwd:path.dirname(target),encoding:'utf8',windowsHide:true,shell:false,timeout:90000,maxBuffer:1024*1024
7
+ });
8
+ process.stdout.write(result.stdout??'');
9
+ process.stderr.write(result.stderr??'');
10
+ if(result.error)throw result.error;
11
+ process.exitCode=result.status??1;
@@ -0,0 +1,49 @@
1
+ // R168 five-plane real Win32 R85 lock test on disposable scratch ONLY.
2
+ // Runs inside Node --test and reuses R89-verified R167 protected native addon.
3
+ import test from 'node:test';
4
+ import assert from 'node:assert/strict';
5
+ import {createHash} from 'node:crypto';
6
+ import {readFile,mkdir,mkdtemp,rm,lstat} from 'node:fs/promises';
7
+ import path from 'node:path';
8
+ import os from 'node:os';
9
+ import {pathToFileURL} from 'node:url';
10
+ import {simulateR168FivePlaneEpochFence} from '../src/activation-reconciliation-fence-r168.mjs';
11
+ import {queryForegroundIdentity} from '../src/foreground-process-identity.mjs';
12
+
13
+ const C='C:\\Program Files\\DEADBYTE-R167-Protected-0.15.65-3316654646cc8705-Fix6';
14
+ const sha=createHash('sha256');
15
+ const expected='3316654646cc870584a7c969c2032af6c795229ff8c65e5a8b794f97c2458c41';
16
+ const planes=['process','coding','autonomous','desktop','host'];
17
+
18
+ test('R168 holds five real protected R85 native kernel locks together on isolated scratch',async()=>{
19
+ if(process.platform!=='win32')return;
20
+ const manifest=await readFile(path.join(C,'MANIFEST.SHA256'));
21
+ assert.equal(createHash('sha256').update(manifest).digest('hex'),expected);
22
+ const {acquireHeldEpochLock}=await import(pathToFileURL(path.join(C,'src','epoch-lock-r85.mjs')).href);
23
+ const stateRoot=await mkdtemp(path.join(os.tmpdir(),'r168-real-five-plane-'));
24
+ try{
25
+ for(const plane of planes)await mkdir(path.join(stateRoot,'runtime','authority-epochs',plane),{recursive:true});
26
+ const owner=queryForegroundIdentity(process.pid);
27
+ const result=await simulateR168FivePlaneEpochFence({
28
+ stateRoot,
29
+ testOwnerIdentity:owner,
30
+ testAcquire:acquireHeldEpochLock,
31
+ onHeld:async({planeOrder,assertHeld})=>{
32
+ assertHeld();
33
+ assert.deepEqual(planeOrder,planes);
34
+ for(const plane of planes){
35
+ const lock=path.join(stateRoot,'runtime','authority-epochs',plane,'.lock');
36
+ assert.ok((await lstat(lock)).isFile());
37
+ const competitor=await acquireHeldEpochLock(lock,Buffer.from('R168 scratch competitor'));
38
+ assert.equal(competitor,null,'native lock allowed duplicate owner for '+plane);
39
+ }
40
+ return 'REAL_NATIVE_FENCE_HELD';
41
+ }
42
+ });
43
+ assert.equal(result,'REAL_NATIVE_FENCE_HELD');
44
+ for(const plane of planes){
45
+ const lock=path.join(stateRoot,'runtime','authority-epochs',plane,'.lock');
46
+ await assert.rejects(lstat(lock),error=>error.code==='ENOENT');
47
+ }
48
+ }finally{await rm(stateRoot,{recursive:true,force:true});}
49
+ });
@@ -0,0 +1,44 @@
1
+ // R168 nonproduction integration smoke: real R85 addon from R167 R89-trusted
2
+ // Program Files install, applied ONLY to an isolated disposable scratch lock.
3
+ import test from 'node:test';
4
+ import assert from 'node:assert/strict';
5
+ import {createHash} from 'node:crypto';
6
+ import {readFile,mkdtemp,mkdir,rm,lstat} from 'node:fs/promises';
7
+ import os from 'node:os';
8
+ import path from 'node:path';
9
+ import {pathToFileURL} from 'node:url';
10
+
11
+ const protectedRoot='C:\\Program Files\\DEADBYTE-R167-Protected-0.15.65-3316654646cc8705-Fix6';
12
+ const manifestHash='3316654646cc870584a7c969c2032af6c795229ff8c65e5a8b794f97c2458c41';
13
+
14
+ test('R168 R85 protected addon enforces exclusive kernel handle on disposable local scratch',async()=>{
15
+ if(process.platform!=='win32'){test.skip('Windows only');return;}
16
+ const manifest=await readFile(path.join(protectedRoot,'MANIFEST.SHA256'));
17
+ assert.equal(createHash('sha256').update(manifest).digest('hex'),manifestHash);
18
+ const release=JSON.parse(await readFile(path.join(protectedRoot,'RELEASE.json'),'utf8'));
19
+ assert.equal(release.version,'0.15.65');
20
+ assert.equal(release.train,'R167');
21
+ // Loading the addon checks the protected code's own R89 ACL trust path.
22
+ const {acquireHeldEpochLock}=await import(pathToFileURL(path.join(protectedRoot,'src','epoch-lock-r85.mjs')).href);
23
+ const scratch=await mkdtemp(path.join(os.tmpdir(),'r168-real-r85-test-'));
24
+ const folder=path.join(scratch,'authority-epochs','coding');
25
+ await mkdir(folder,{recursive:true});
26
+ const lockFile=path.join(folder,'.lock');
27
+ const bytes=Buffer.from(JSON.stringify({schema:'deadbyte.r168-scratch-lock.v1',pid:process.pid,nonce:'scratch-only'}));
28
+ let first=null,second=null;
29
+ try{
30
+ first=await acquireHeldEpochLock(lockFile,bytes);
31
+ assert.ok(first,'protected R85 addon failed to acquire scratch lock');
32
+ assert.equal(await acquireHeldEpochLock(lockFile,bytes),null,'exclusive held lock accepted a competing acquisition');
33
+ await first.release();first=null;
34
+ await assert.rejects(lstat(lockFile),e=>e.code==='ENOENT');
35
+ second=await acquireHeldEpochLock(lockFile,bytes);
36
+ assert.ok(second,'R85 scratch lock cannot reacquire after verified release');
37
+ await second.release();second=null;
38
+ await assert.rejects(lstat(lockFile),e=>e.code==='ENOENT');
39
+ }finally{
40
+ if(second)await second.release();
41
+ if(first)await first.release();
42
+ await rm(scratch,{recursive:true,force:true});
43
+ }
44
+ });
@@ -0,0 +1,49 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import {createHash} from 'node:crypto';
4
+ import {resumePackRecord} from '../src/npm-publication-resume-r168.mjs';
5
+ import * as childProcess from 'node:child_process';
6
+ import * as nodeUrl from 'node:url';
7
+
8
+ const hash=(alg,x)=>createHash(alg).update(x).digest(alg==='sha512'?'base64':'hex');
9
+ const bytes=Buffer.from('R168 immutable artifact sample');
10
+ const manifest=hash('sha256',Buffer.from('manifest'));
11
+ const claim={schema:'deadbyte.npm-publication-claim.r65.v1',version:'0.15.65',
12
+ manifest_sha256:manifest,tarball_sha256:hash('sha256',bytes)};
13
+ const args={filename:'deadbyte-mcp-0.15.65.tgz',localBytes:bytes,claim,version:'0.15.65',manifestSha256:manifest};
14
+
15
+ test('R168 resume derives npm shasum and integrity from verified preserved tarball',()=>{
16
+ const record=resumePackRecord(args);
17
+ assert.equal(record.filename,args.filename);
18
+ assert.equal(record.shasum,hash('sha1',bytes));
19
+ assert.equal(record.integrity,'sha512-'+hash('sha512',bytes));
20
+ assert.equal(record.sha256,hash('sha256',bytes));
21
+ });
22
+ test('R168 resume rejects immutable claim version, schema or manifest drift',()=>{
23
+ assert.throws(()=>resumePackRecord({...args,claim:{...claim,version:'0.15.64'}}),/claim|version/);
24
+ assert.throws(()=>resumePackRecord({...args,claim:{...claim,schema:'unknown'}}),/claim|schema/);
25
+ assert.throws(()=>resumePackRecord({...args,manifestSha256:'f'.repeat(64)}),/claim|manifest/);
26
+ });
27
+ test('R168 resume rejects altered tarball bytes instead of reconciling or publishing',()=>{
28
+ assert.throws(()=>resumePackRecord({...args,localBytes:Buffer.from('altered')}),/tarball|digest|claim/);
29
+ assert.throws(()=>resumePackRecord({...args,localBytes:null}),/tarball|bytes/);
30
+ });
31
+
32
+ test('R168 publisher wires verified resume record to R167 exact-byte publication fence',async()=>{
33
+ const {readFile}=await import('node:fs/promises');
34
+ const src=await readFile(new URL('../scripts/npm-release-r48.mjs',import.meta.url),'utf8');
35
+ assert.match(src,/const preservedRecord=resuming\?resumePackRecord\(/);
36
+ assert.match(src,/const packRecord=resuming\?preservedRecord:/);
37
+ assert.match(src,/observedShasum:packRecord\.shasum/);
38
+ assert.match(src,/claimData\.manifest_sha256!==currentManifestSha256/);
39
+ assert.doesNotMatch(src,/resuming\?\{filename:path\.basename\(preservedTarball\)\}/);
40
+ });
41
+
42
+ test('R168 publisher parses without invoking npm publish',()=>{
43
+ const {spawnSync}=childProcess;
44
+ const {fileURLToPath}=nodeUrl;
45
+ const target=fileURLToPath(new URL('../scripts/npm-release-r48.mjs',import.meta.url));
46
+ const child=spawnSync(process.execPath,['--check',target],{
47
+ encoding:'utf8',shell:false,windowsHide:true,timeout:15000});
48
+ assert.equal(child.status,0,child.stderr);
49
+ });