229 lines
25 KiB
TypeScript
229 lines
25 KiB
TypeScript
import assert from "node:assert/strict"
|
|
import { projectServerPollApprovalContext } from "./server-poll-approval-context.js"
|
|
import { createHmac,randomUUID } from "node:crypto"
|
|
import { createServerPollExecution,ServerPollExecutionError,type ServerPollDependencies,type ServerPollReceipt } from "./server-poll-execution.js"
|
|
import { planServerPollMaintenance,projectServerPollEffect,ServerPollProblem,type ServerPollContext,type ServerPollEffect,type PollRow } from "./server-poll-execution-model.js"
|
|
|
|
// All boundaries below are inert memory functions. No DB pool, native client,
|
|
// filesystem key material, scheduler, notifications or network is imported.
|
|
const around="2026-10-25T12:00:00.000Z",epoch="11111111-2222-3333-4444-555555555555"
|
|
const initial=():ServerPollContext=>({
|
|
servers:[{id:1,name:"before",host:"192.0.2.1",enabled:false,password:"NEVER_POLL_ENDPOINT",routingEndpointEpoch:epoch,updatedAt:"2026-10-24T12:00:00.000Z",opaque:"NEVER_POLL_SERVER"},{id:2,name:"foreign",enabled:true,password:"NEVER_FOREIGN",routingEndpointEpoch:epoch}],
|
|
settings:{traffic:{retentionDays:14,opaque:"NEVER_TRAFFIC"},uptime:{retentionDays:14},internetPath:{retentionDays:14}},
|
|
partitions:[{namespace:"public",parent:"server_snapshots",name:"server_snapshots_w_20000103",from:"2000-01-03T00:00:00.000Z",to:"2000-01-10T00:00:00.000Z",storage:{},opaque:"NEVER_OLD_PARTITION"}],
|
|
snapshots:[{id:1,serverId:1,polledAt:"2026-10-24T12:00:00.000Z",rawInterfaces:[{name:"old",opaque:"NEVER_RAW"}],rawIpAddresses:[],opaque:"NEVER_HISTORY"}],protections:[{kind:"database",id:"all",protection:"approval"}],
|
|
})
|
|
function canonical(value:unknown):unknown{if(Array.isArray(value))return value.map(canonical);if(value&&typeof value==="object")return Object.fromEntries(Object.entries(value).sort(([a],[b])=>a.localeCompare(b)).map(([k,v])=>[k,canonical(v)]));return value}
|
|
const proof=async(value:unknown)=>createHmac("sha256","inert-private-fixture-only").update(JSON.stringify(canonical(value))).digest("hex")
|
|
let state:ServerPollContext=initial(),mode="normal",clock=Date.parse(around),global=true,allowed:number[]=[1,2],authority="a".repeat(64),nativeCalls:string[]=[],effects:ServerPollEffect[]=[],intents:unknown[]=[],acks:unknown[]=[],completed:ServerPollReceipt|undefined,claimed:{bindingProof:string;receipt?:ServerPollReceipt}|undefined,reads=0
|
|
let afterIntent:(()=>void)|undefined,afterEffect:(()=>void)|undefined
|
|
function reset(){state=initial();mode="normal";clock=Date.parse(around);global=true;allowed=[1,2];authority="a".repeat(64);nativeCalls=[];effects=[];intents=[];acks=[];completed=undefined;claimed=undefined;reads=0;afterIntent=undefined;afterEffect=undefined}
|
|
reset()
|
|
const deps:ServerPollDependencies={
|
|
now:()=>clock,
|
|
authorize:async(_request,_ids,signal)=>{signal?.throwIfAborted();if(mode==="revoked")throw new ServerPollProblem("PERMISSION_DENIED","inert revoke");return {global,serverIds:allowed,authorityProof:authority}},
|
|
readContext:async(_request,check,permitted)=>{await check();reads++;assert.ok(permitted.includes(1));const value=structuredClone(state);await check();return value},
|
|
proof,withGlobalLock:async work=>work(),
|
|
native:async(read,_server,options)=>{await options.beforeDispatch();if(mode==="duplicate-native")await options.beforeDispatch();nativeCalls.push(read);if(mode==="native-failed"&&read==="resource")throw Error("NEVER_PROVIDER_PAYLOAD");if(mode==="native-oversize"&&read==="identity")return{name:"x".repeat(1048577)};if(read==="identity")return{name:mode==="secret-reflection"?"router-NEVER_POLL_ENDPOINT":"after"};if(read==="resource")return{"cpu-load":"5","free-memory":"1024","total-memory":"2048",version:"7.24.5","board-name":"CHR",uptime:"1d"};if(read==="interfaces")return[{".id":"*a",name:"ether1",opaque:"NEVER_NATIVE_RAW"}];return[{".id":"*b",interface:"ether1",address:"192.0.2.1/24"}]},
|
|
effect:async(effect,options)=>{
|
|
await options.beforeDispatch();if(mode==="duplicate-effect")await options.beforeDispatch();effects.push(structuredClone(effect))
|
|
let row:PollRow|undefined
|
|
if(effect.kind==="snapshot.insert")row={id:2,...effect.snapshot,opaque:"NEVER_NEW_DEFAULT"}
|
|
if(effect.kind==="partition.ensure")row={namespace:"public",parent:effect.parent,name:effect.name,from:effect.from,to:effect.to,storage:{},opaque:"NEVER_PARTITION_DEFAULT"}
|
|
const ack={row};state=projectServerPollEffect(state,effect,ack)
|
|
if(mode==="lost")throw Error("NEVER_LOST_ACK")
|
|
if(mode==="collateral")state.servers[1].password="NEVER_CHANGED_FOREIGN"
|
|
if(afterEffect){const hook=afterEffect;afterEffect=undefined;hook()}
|
|
return ack
|
|
},
|
|
intent:async value=>{intents.push(structuredClone(value));if(afterIntent){const hook=afterIntent;afterIntent=undefined;hook()}},
|
|
acknowledge:async value=>{if(mode==="ack-failed")throw Error("NEVER_JOURNAL_FAILURE");acks.push(structuredClone(value))},
|
|
claim:async(_request,bindingProof)=>{if(claimed)return claimed.receipt?{state:"known",bindingProof:claimed.bindingProof,receipt:claimed.receipt}:{state:"unresolved",bindingProof:claimed.bindingProof};claimed={bindingProof};return{state:"new"}},
|
|
complete:async(receipt,bindingProof)=>{assert.equal(claimed?.bindingProof,bindingProof);if(mode==="receipt-failed")throw Error("NEVER_RECEIPT_FAILURE");completed=structuredClone(receipt);claimed!.receipt=structuredClone(receipt)},
|
|
}
|
|
const executor=createServerPollExecution(deps),request=()=>({serverId:1,receiptId:randomUUID()})
|
|
let plan=await executor.prepare(request())
|
|
assert.equal(plan.requiresHuman,true);assert.equal(plan.scope,"global");assert.deepEqual(plan.affectedServerIds,[1,2]);assert.ok(!JSON.stringify(plan).includes("NEVER_"));assert.ok(plan.maintenance.some(effect=>effect.kind==="partition.drop"));assert.ok(plan.maintenance.some(effect=>effect.kind==="partition.storage"))
|
|
const before=structuredClone(state),receipt=await executor.execute(plan)
|
|
assert.deepEqual(nativeCalls.sort(),["addresses","identity","interfaces","resource"])
|
|
assert.equal(receipt.nativeReads,4);assert.equal(receipt.complete,true);assert.equal(receipt.maintenanceComplete,true);assert.equal(receipt.observation,"online");assert.equal(receipt.snapshot.identityName,"after");assert.ok(!JSON.stringify(receipt).includes("NEVER_"))
|
|
assert.equal(state.servers[0].name,"after");assert.equal(state.servers[0].enabled,false,"Existing REST poll permits a disabled target; source identity is still sealed")
|
|
assert.deepEqual(state.servers[1],before.servers[1]);assert.deepEqual(state.settings,before.settings);assert.deepEqual(state.protections,before.protections);assert.equal(state.snapshots[0].rawInterfaces,null);assert.equal(state.snapshots[0].opaque,"NEVER_HISTORY")
|
|
assert.deepEqual(effects.slice(0,4).map(effect=>effect.kind),["server.name","flow-cache.invalidate","snapshot.insert","snapshot.raw.clear"])
|
|
assert.equal(effects.length,plan.maintenance.length+4);assert.equal(intents.length,effects.length+4);assert.equal(acks.length,intents.length);assert.equal(completed?.completedPublications,effects.length)
|
|
const nativeBefore=nativeCalls.length,effectsBefore=effects.length;assert.deepEqual(await executor.execute(plan),receipt);assert.equal(nativeCalls.length,nativeBefore);assert.equal(effects.length,effectsBefore,"Known durable receipt cannot replay poll or maintenance")
|
|
state.servers[1].name="later";assert.equal((await executor.execute(plan)).configurationVerified,false,"Historical receipt does not assert current state after later drift")
|
|
|
|
for(const mutate of [()=>{global=false},()=>{allowed=[1]},()=>{state.settings.traffic!.retentionDays=30},()=>{state.servers[0].routingEndpointEpoch=randomUUID()},()=>{state.partitions[0].opaque="changed"},()=>{authority="b".repeat(64)}]){
|
|
reset();plan=await executor.prepare(request());mutate();await assert.rejects(executor.execute(plan));assert.equal(nativeCalls.length,0);assert.equal(effects.length,0)
|
|
}
|
|
reset();global=false;await assert.rejects(executor.prepare(request()));assert.equal(reads,0,"Global refusal precedes private context reads")
|
|
reset();plan=await executor.prepare(request());afterIntent=()=>{mode="revoked"};await assert.rejects(executor.execute(plan));assert.equal(nativeCalls.length,0);assert.equal(effects.length,0,"Revocation after durable read intent prevents native dispatch")
|
|
reset();plan=await executor.prepare(request());mode="native-failed";const offline=await executor.execute(plan);assert.equal(offline.observation,"offline");assert.equal(offline.maintenanceComplete,true);assert.ok(!effects.some(effect=>effect.kind==="server.name"));assert.ok(effects.some(effect=>effect.kind==="snapshot.insert"));assert.ok(effects.some(effect=>effect.kind==="partition.drop"));assert.equal(state.servers[0].name,"before")
|
|
for(const fault of ["lost","collateral","receipt-failed"]){
|
|
reset();plan=await executor.prepare(request());mode=fault
|
|
await assert.rejects(executor.execute(plan),(error:unknown)=>error instanceof ServerPollExecutionError&&error.code===(fault==="collateral"?"VERIFICATION_FAILED":"MUTATION_OUTCOME_UNKNOWN"))
|
|
const count:number=effects.length;await assert.rejects(executor.execute(plan));assert.equal(effects.length,count,"Unknown/partial run never starts a second dispatch sequence")
|
|
if(fault!=="receipt-failed")assert.equal(count,1)
|
|
}
|
|
reset();plan=await executor.prepare(request());afterEffect=()=>{mode="revoked"};await assert.rejects(executor.execute(plan),ServerPollExecutionError);assert.equal(effects.length,1)
|
|
reset();plan=await executor.prepare(request());mode="native-oversize";await assert.rejects(executor.execute(plan));assert.equal(effects.length,0)
|
|
reset();plan=await executor.prepare(request());mode="secret-reflection";assert.ok(!JSON.stringify(await executor.execute(plan)).includes("NEVER_POLL_ENDPOINT"),"Known private values reflected by a native public-looking field remain private")
|
|
reset();plan=await executor.prepare(request());clock+=60000;assert.equal((await executor.execute(plan)).snapshot.polledAt,new Date(clock).toISOString(),"Sample time is execution time, not approval time")
|
|
reset();plan=await executor.prepare(request());clock+=86400000;await assert.rejects(executor.execute(plan));assert.equal(nativeCalls.length,0,"Changed UTC partition window requires a fresh manifest")
|
|
reset();plan=await executor.prepare(request());mode="duplicate-native";await assert.rejects(executor.execute(plan));assert.equal(nativeCalls.length,0);assert.equal(effects.length,0)
|
|
reset();plan=await executor.prepare(request());mode="duplicate-effect";await assert.rejects(executor.execute(plan),ServerPollExecutionError);assert.equal(effects.length,0)
|
|
reset();let sawFullCatalog=false;await assert.rejects(createServerPollExecution({...deps,authorize:async(_request,ids)=>{if(ids.length===2)sawFullCatalog=true;return {global:true,serverIds:[1,2],authorityProof:ids.length===2?"b".repeat(64):"a".repeat(64)}}}).prepare(request()));assert.equal(sawFullCatalog,true,"Drift specifically at authorize(all) is rejected")
|
|
reset();plan=await executor.prepare(request());const cancel=new AbortController();cancel.abort();await assert.rejects(executor.execute(plan,cancel.signal));assert.equal(nativeCalls.length,0);assert.equal(effects.length,0)
|
|
reset();plan=await executor.prepare(request());afterEffect=()=>{clock+=121000};assert.equal((await executor.execute(plan)).complete,true,"Bounded metadata/DDL reserve allows a full poll beyond the old 120s envelope")
|
|
reset();plan=await executor.prepare(request());afterEffect=()=>{clock+=180001};await assert.rejects(executor.execute(plan),ServerPollExecutionError);assert.equal(effects.length,1,"Hard total budget still prevents any next publication")
|
|
reset();const originalExpiry=clock+90000,expiring=createServerPollExecution({...deps,authorize:async(...args)=>{if(clock>=originalExpiry)throw new ServerPollProblem("PERMISSION_DENIED","Original actor expired");return deps.authorize(...args)}});plan=await expiring.prepare(request());afterEffect=()=>{clock+=90001};await assert.rejects(expiring.execute(plan),ServerPollExecutionError);assert.equal(effects.length,1,"Metadata reserve never extends original authority expiry")
|
|
reset();const missing=structuredClone(state);delete (missing.settings as Partial<ServerPollContext["settings"]>).traffic;await assert.rejects(createServerPollExecution({...deps,readContext:async()=>missing}).prepare(request()))
|
|
assert.throws(()=>planServerPollMaintenance({...initial(),settings:{traffic:{retentionDays:99999},uptime:null,internetPath:null}},around))
|
|
// V1/V2 planner compatibility below uses the existing inert authenticated
|
|
// fixture only. It does not manufacture a production journal or terminal.
|
|
const populateWarmPartitions=()=>{
|
|
const planned=planServerPollMaintenance(state,new Date(clock).toISOString())
|
|
for(const effect of planned){
|
|
const row=effect.kind==="partition.ensure"?{namespace:"public",parent:effect.parent,name:effect.name,from:effect.from,to:effect.to,storage:{},opaque:"NEVER_PARTITION_DEFAULT"}:undefined
|
|
state=projectServerPollEffect(state,effect,{row})
|
|
}
|
|
}
|
|
|
|
reset();populateWarmPartitions();const warmBefore=structuredClone(state);plan=await executor.prepare(request())
|
|
assert.equal(plan.version,2,"New plans explicitly seal the differential maintenance version")
|
|
assert.deepEqual(state,warmBefore,"Planning must not mutate original full catalogue or opaque fields")
|
|
const warmLegacy=planServerPollMaintenance(warmBefore,new Date(clock).toISOString())
|
|
assert(plan.maintenance.length<warmLegacy.length)
|
|
const warmPlanBefore=structuredClone(plan),warmReceipt=await executor.execute(plan)
|
|
assert.equal(warmReceipt.complete,true);assert.deepEqual(plan,warmPlanBefore)
|
|
assert.deepEqual(effects.slice(4),plan.maintenance,"V2 dispatches exactly its sealed remaining effects, without fake no-op ACKs")
|
|
assert.equal(intents.length,effects.length+4);assert.equal(acks.length,intents.length)
|
|
let warmExpected=structuredClone(warmBefore)
|
|
for(const effect of warmLegacy){const row=effect.kind==="partition.ensure"?{namespace:"public",parent:effect.parent,name:effect.name,from:effect.from,to:effect.to,storage:{},opaque:"NEVER_PARTITION_DEFAULT"}:undefined;warmExpected=projectServerPollEffect(warmExpected,effect,{row})}
|
|
const sortedPartitions=(value:ServerPollContext)=>[...value.partitions].sort((a,b)=>String(a.name).localeCompare(String(b.name)))
|
|
assert.deepEqual(sortedPartitions(state),sortedPartitions(warmExpected),"V2 reaches the exact V1 required final partition catalogue")
|
|
|
|
reset();populateWarmPartitions();const legacySeed=await executor.prepare(request())
|
|
const {bindingProof:discardNewBinding,...legacySeedCore}=legacySeed
|
|
void discardNewBinding
|
|
const originalV1Maintenance=planServerPollMaintenance(state,new Date(clock).toISOString())
|
|
const originalV1Core={...legacySeedCore,version:1 as const,maintenance:originalV1Maintenance,mutationCost:originalV1Maintenance.length+8}
|
|
const originalV1Plan={...originalV1Core,bindingProof:await proof(originalV1Core)},originalV1Copy=structuredClone(originalV1Plan)
|
|
const legacyReceipt=await executor.execute(originalV1Plan)
|
|
assert.equal(legacyReceipt.complete,true);assert.deepEqual(originalV1Plan,originalV1Copy)
|
|
assert.deepEqual(effects.slice(4),originalV1Maintenance,"A sealed historical V1 manifest executes legacy semantics, even on a warm catalogue")
|
|
assert(effects.length>warmPlanBefore.maintenance.length+4,"V1 is not silently upgraded to V2")
|
|
|
|
for(const change of ["catalogue","required-storage","missing-leaf"]as const){
|
|
reset();populateWarmPartitions();plan=await executor.prepare(request())
|
|
const dispatchedNames=new Set(plan.maintenance.flatMap(effect=>"name"in effect?[effect.name]:[]))
|
|
const omitted=state.partitions.find(row=>row.parent==="flow_hour_facts"&&!dispatchedNames.has(String(row.name)))!
|
|
assert(omitted,"Test must target a leaf whose CREATE/ALTER were elided")
|
|
if(change==="catalogue")omitted.opaque="changed-after-approval"
|
|
if(change==="required-storage")(omitted.storage as Record<string,string>).fillfactor="80"
|
|
if(change==="missing-leaf")state.partitions=state.partitions.filter(row=>row.name!==omitted.name)
|
|
await assert.rejects(executor.execute(plan));assert.equal(nativeCalls.length,0);assert.equal(effects.length,0,"Elided leaves remain covered by the full fresh source proof")
|
|
}
|
|
|
|
for(const badVersion of [1,3]){
|
|
reset();populateWarmPartitions();plan=await executor.prepare(request())
|
|
const tampered={...plan,version:badVersion}as typeof plan
|
|
await assert.rejects(executor.execute(tampered));assert.equal(nativeCalls.length,0);assert.equal(effects.length,0);assert.equal(claimed,undefined,"Changing only the inner sealed version is rejected before claim")
|
|
}
|
|
reset();populateWarmPartitions()
|
|
await assert.rejects(executor.execute({...originalV1Plan,version:2}))
|
|
assert.equal(nativeCalls.length,0);assert.equal(effects.length,0);assert.equal(claimed,undefined,"A stored V1 proof cannot be upgraded by changing its inner version")
|
|
reset();populateWarmPartitions();const wrongPlannerSeed=await executor.prepare(request())
|
|
const {bindingProof:discardWrongBinding,...wrongPlannerCore}=wrongPlannerSeed
|
|
void discardWrongBinding
|
|
const wrongMaintenance=planServerPollMaintenance(state,new Date(clock).toISOString())
|
|
const wronglySealedCore={...wrongPlannerCore,maintenance:wrongMaintenance,mutationCost:wrongMaintenance.length+8}
|
|
await assert.rejects(executor.execute({...wronglySealedCore,bindingProof:await proof(wronglySealedCore)}))
|
|
assert.equal(nativeCalls.length,0);assert.equal(effects.length,0,"Even a fixture-authenticated V2 plan must match the current V2 planner, not legacy recomputation")
|
|
|
|
// Version3 fixtures explicitly supply a trusted approval reader. No JSON flag
|
|
// or omitted capability can activate the relaxed waiting-time comparison.
|
|
const v3 = createServerPollExecution({...deps,approvalProof:async context=>proof(projectServerPollApprovalContext(context,1))})
|
|
function version3State(){reset();populateWarmPartitions();for(const row of Object.values(state.settings))if(row)row.pollConfigurationEpoch=randomUUID()}
|
|
version3State();const delayed=await v3.prepare(request());assert.equal(delayed.version,3)
|
|
const delayedSource=delayed.beforeProof
|
|
state.settings.uptime!.lastCollectedAt="2026-10-25T12:00:20.000Z";state.settings.uptime!.lastError="collector finished";state.settings.uptime!.updatedAt="2026-10-25T12:00:20.000Z";clock+=20000
|
|
let actualStart:Parameters<ServerPollDependencies["claim"]>[2]
|
|
const delayedExecutor=createServerPollExecution({...deps,approvalProof:async context=>proof(projectServerPollApprovalContext(context,1)),claim:async(...args)=>{actualStart=args[2];return deps.claim(...args)}})
|
|
const delayedReceipt=await delayedExecutor.execute(delayed)
|
|
assert.equal(delayedReceipt.complete,true);assert.equal(nativeCalls.length,4)
|
|
assert(actualStart);assert.notEqual(actualStart.fullProof,delayedSource);assert.equal(actualStart.approvalProof,delayed.approvalProof)
|
|
for(const change of ["configuration","aba","server","catalog"]){
|
|
version3State();const prepared=await v3.prepare(request())
|
|
if(change==="configuration")state.settings.uptime!.retentionDays=15
|
|
if(change==="aba"){state.settings.uptime!.retentionDays=15;state.settings.uptime!.pollConfigurationEpoch=randomUUID();state.settings.uptime!.retentionDays=14;state.settings.uptime!.pollConfigurationEpoch=randomUUID()}
|
|
if(change==="server")state.servers[0].name="external change"
|
|
if(change==="catalog")state.protections.push({kind:"database",id:"new"})
|
|
await assert.rejects(v3.execute(prepared));assert.equal(claimed,undefined,change+" refuses before admission");assert.equal(nativeCalls.length,0)
|
|
}
|
|
version3State();const beforeRace=await v3.prepare(request())
|
|
afterIntent=()=>{state.settings.uptime!.lastError="changed during execution"}
|
|
await assert.rejects(v3.execute(beforeRace));assert.equal(nativeCalls.length,0,"Runtime drift after the anchored start is still rejected by the exact full proof")
|
|
version3State();const unsupported=await v3.prepare(request())
|
|
await assert.rejects(executor.execute(unsupported));assert.equal(claimed,undefined)
|
|
|
|
console.log("Server poll inert foundations: four native reads, online/offline snapshots, name/cache/raw cleanup, complete global partition maintenance, full private proofs, intent/ACK fences, scope/revoke/deadline/unknown no replay passed")
|
|
|
|
// Candidate-only in-memory transaction model. Genuine SQL evidence is separate.
|
|
let atomicFault="",groupSends=0,groupCommits=0,precommitChecks=0
|
|
const coldV4=()=>{reset();for(const row of Object.values(state.settings))if(row)row.pollConfigurationEpoch=randomUUID();atomicFault="";groupSends=0;groupCommits=0;precommitChecks=0}
|
|
const atomicDeps:ServerPollDependencies={...deps,approvalProof:async context=>proof(projectServerPollApprovalContext(context,1)),maintenanceGroup:async(group,options)=>{
|
|
const originalPartitions=structuredClone(state.partitions),members:{row?:PollRow}[]=[]
|
|
if(atomicFault==="skip-dispatch"){await options.verifyBeforeCommit({effects:[]});throw Error("Unreachable skipped dispatch")}
|
|
await options.beforeDispatch();groupSends++
|
|
try{
|
|
for(const effect of group.effects){
|
|
const row=effect.kind==="partition.ensure"?{namespace:"public",parent:effect.parent,name:effect.name,from:effect.from,to:effect.to,storage:{},opaque:"NEVER_ATOMIC_DEFAULT"}:undefined
|
|
const ack=row?{row}:{};members.push(ack);state=projectServerPollEffect(state,effect,ack)
|
|
}
|
|
if(atomicFault==="configuration-drift")state.settings.uptime!.retentionDays=37
|
|
if(atomicFault==="runtime-drift")state.settings.uptime!.lastError="changed in group"
|
|
if(atomicFault==="foreign-drift")state.servers[1].password="changed in group"
|
|
if(atomicFault==="revoked")mode="revoked"
|
|
if(atomicFault==="expired")clock+=180001
|
|
if(atomicFault!=="skip-precommit"){
|
|
await options.verifyBeforeCommit({effects:members});precommitChecks++
|
|
if(atomicFault==="double-precommit")await options.verifyBeforeCommit({effects:members})
|
|
}
|
|
groupCommits++
|
|
}catch(error){state.partitions=originalPartitions;throw error}
|
|
if(atomicFault==="lost-commit-ack")throw Error("Inert lost ack; genuine wire fault is tested separately")
|
|
return {effects:members}
|
|
}}
|
|
const atomicExecutor=createServerPollExecution(atomicDeps)
|
|
coldV4();const atomicPlan=await atomicExecutor.prepare(request()),atomicBefore=structuredClone(state)
|
|
assert.equal(atomicPlan.version,4);assert.equal(atomicPlan.maintenanceGroupSize,8)
|
|
assert.equal(atomicPlan.mutationCost,atomicPlan.maintenance.length+8)
|
|
const atomicReceipt=await atomicExecutor.execute(atomicPlan)
|
|
assert(atomicReceipt.complete&&atomicReceipt.maintenanceComplete)
|
|
assert.equal(nativeCalls.length,4);assert.equal(effects.length,4)
|
|
assert.equal(groupSends,Math.ceil(atomicPlan.maintenance.length/8));assert.equal(groupCommits,groupSends);assert.equal(precommitChecks,groupSends)
|
|
assert.equal(atomicReceipt.confirmedPublications,groupSends+4)
|
|
assert.equal(intents.length,groupSends+8);assert.equal(acks.length,intents.length)
|
|
assert.deepEqual(state.settings,atomicBefore.settings);assert.deepEqual(state.servers[1],atomicBefore.servers[1]);assert.deepEqual(state.protections,atomicBefore.protections)
|
|
assert(!JSON.stringify(atomicReceipt).includes("NEVER_"))
|
|
for(const fault of ["configuration-drift","runtime-drift","foreign-drift","revoked","expired","double-precommit"]){
|
|
coldV4();const prepared=await atomicExecutor.prepare(request());const partitions=structuredClone(state.partitions);atomicFault=fault
|
|
await assert.rejects(atomicExecutor.execute(prepared),ServerPollExecutionError)
|
|
assert.equal(groupSends,1);assert.equal(groupCommits,0);assert.deepEqual(state.partitions,partitions)
|
|
assert.equal(completed,undefined);assert.equal(acks.length,8,"No grouped ACK is published before successful commit")
|
|
const previousSends=groupSends;await assert.rejects(atomicExecutor.execute(prepared));assert.equal(groupSends,previousSends)
|
|
}
|
|
for(const fault of ["skip-precommit","lost-commit-ack","skip-dispatch"]){
|
|
coldV4();const prepared=await atomicExecutor.prepare(request());atomicFault=fault
|
|
await assert.rejects(atomicExecutor.execute(prepared),ServerPollExecutionError)
|
|
assert.equal(groupSends,fault==="skip-dispatch"?0:1);assert.equal(completed,undefined);assert.equal(acks.length,8)
|
|
const previousSends=groupSends;await assert.rejects(atomicExecutor.execute(prepared));assert.equal(groupSends,previousSends)
|
|
}
|
|
coldV4();const onlyV3=await v3.prepare(request());assert.equal(onlyV3.version,3)
|
|
await atomicExecutor.execute(onlyV3);assert.equal(groupSends,0);assert.equal(effects.length,onlyV3.maintenance.length+4,"Legacy v3 stays ungrouped even on a group-capable executor")
|
|
coldV4();const unsupportedAtomic=await atomicExecutor.prepare(request())
|
|
await assert.rejects(v3.execute(unsupportedAtomic));assert.equal(claimed,undefined);assert.equal(nativeCalls.length,0)
|
|
console.log("Atomic engine components: all original V1/V2/V3 cases plus V4 complete cold manifest, unchanged logical quota, original four native reads, mandatory precommit full proof, runtime/config/foreign drift, revoke, expiry, missing/double check, lost ACK and no replay PASS; no SQL, registration or public admission")
|