@@ -223,18 +223,14 @@ test("failed dependencies block downstream tasks unless a repair supersedes them
223223} ) ;
224224
225225test ( "worker execution dispatches claimed parallel tasks and completes only from evidence reports" , ( ) => {
226- const graph = {
227- tasks : [
228- { id : "branch-a" , status : "ready" as const , dependencies : [ ] } ,
229- { id : "branch-b" , status : "ready" as const , dependencies : [ ] } ,
230- ] ,
231- } ;
226+ const graph = { tasks : [ { id : "branch-a" , status : "ready" as const , dependencies : [ ] } , { id : "branch-b" , status : "ready" as const , dependencies : [ ] } ] } ;
232227 const claimedA = claimTask ( graph , { taskId : "branch-a" , workerId : "w1" , token : "tok-a" , now : "2026-01-01T00:00:00.000Z" , leaseExpiresAt : "2026-01-01T00:20:00.000Z" } ) ;
233228 const claimed = claimTask ( claimedA , { taskId : "branch-b" , workerId : "w2" , token : "tok-b" , now : "2026-01-01T00:00:00.000Z" , leaseExpiresAt : "2026-01-01T00:20:00.000Z" } ) ;
234229 const workers = recordWorkerReady ( recordWorkerReady ( [ ] , { workerId : "w1" , now : "2026-01-01T00:00:01.000Z" , readinessNonce : "n1" } ) , { workerId : "w2" , now : "2026-01-01T00:00:01.000Z" , readinessNonce : "n2" } ) ;
235230 let state : WorkerExecutionState = { graph : claimed , workers, dispatches : [ ] , reports : [ ] } ;
236231
237232 assert . throws ( ( ) => dispatchClaimedTask ( state , { taskId : "branch-a" , workerId : "w1" , claimToken : "tok-a" , now : "2026-01-01T00:00:02.000Z" , readinessNonce : "wrong" } ) , / n o n c e / ) ;
233+ assert . throws ( ( ) => dispatchClaimedTask ( state , { taskId : "branch-a" , workerId : "w1" , claimToken : "tok-a" , now : "2026-01-01T00:00:02.000Z" } ) , / n o n c e / ) ;
238234 state = dispatchClaimedTask ( state , { taskId : "branch-a" , workerId : "w1" , claimToken : "tok-a" , now : "2026-01-01T00:00:02.000Z" , readinessNonce : "n1" } ) ;
239235 state = dispatchClaimedTask ( state , { taskId : "branch-b" , workerId : "w2" , claimToken : "tok-b" , now : "2026-01-01T00:00:02.000Z" , readinessNonce : "n2" } ) ;
240236 assert . deepEqual ( state . graph . tasks . map ( ( task ) => task . status ) , [ "in_progress" , "in_progress" ] ) ;
@@ -258,6 +254,24 @@ test("worker execution dispatches claimed parallel tasks and completes only from
258254 assert . equal ( stale . find ( ( worker ) => worker . id === "w2" ) ?. state , "unhealthy" ) ;
259255} ) ;
260256
257+ test ( "stale worker reports cannot mutate expired or recovered claims" , ( ) => {
258+ const state : WorkerExecutionState = {
259+ graph : { tasks : [ { id : "build" , status : "in_progress" as const , dependencies : [ ] , assignedWorker : "w1" , claim : { token : "old" , workerId : "w1" , claimedAt : "2026-01-01T00:00:00.000Z" , expiresAt : "2026-01-01T00:10:00.000Z" } } ] } ,
260+ workers : [ { id : "w1" , state : "busy" , lastHeartbeatAt : "2026-01-01T00:01:00.000Z" } ] ,
261+ dispatches : [ { taskId : "build" , workerId : "w1" , claimToken : "old" , dispatchedAt : "2026-01-01T00:01:00.000Z" } ] ,
262+ reports : [ ] ,
263+ } ;
264+ const report = { taskId : "build" , workerId : "w1" , claimToken : "old" , status : "completed" as const , summary : "late" , evidenceRefs : [ "verify.md#late" ] , reportedAt : "2026-01-01T00:11:00.000Z" } ;
265+
266+ assert . throws ( ( ) => captureWorkerReport ( state , report ) , / e x p i r e d / ) ;
267+ assert . equal ( state . graph . tasks [ 0 ] ?. status , "in_progress" ) ;
268+ assert . equal ( state . workers [ 0 ] ?. state , "busy" ) ;
269+ assert . deepEqual ( state . reports , [ ] ) ;
270+
271+ const recovered = recoverExpiredClaim ( state . graph , { taskId : "build" , workerId : "w2" , token : "new" , now : "2026-01-01T00:11:00.000Z" , leaseExpiresAt : "2026-01-01T00:20:00.000Z" } ) ;
272+ assert . throws ( ( ) => captureWorkerReport ( { ...state , graph : recovered } , { ...report , reportedAt : "2026-01-01T00:12:00.000Z" } ) , / m a t c h i n g c l a i m t o k e n / ) ;
273+ } ) ;
274+
261275test ( "worker heartbeat stale detection and terminal retention are modeled" , ( ) => {
262276 const workers = [
263277 { id : "fresh" , state : "busy" as const , lastHeartbeatAt : "2026-01-01T00:04:30.000Z" } ,
0 commit comments