@@ -9,9 +9,11 @@ import {
99 ProviderTurnId ,
1010 RunAttemptId ,
1111 RunId ,
12+ RuntimeRequestId ,
1213 ThreadId ,
1314 type OrchestrationV2ExecutionNode ,
1415 type OrchestrationV2RunStatus ,
16+ type OrchestrationV2RuntimeRequest ,
1517} from "@t3tools/contracts" ;
1618import * as DateTime from "effect/DateTime" ;
1719import { createModelCapabilities , createModelSelection } from "@t3tools/shared/model" ;
@@ -20,6 +22,7 @@ import { describe, expect, it } from "vite-plus/test";
2022
2123import { v2Projection } from "./orchestrationV2TestFixtures.ts" ;
2224import {
25+ canResumeThread ,
2326 deriveReportedModelSelection ,
2427 deriveLatestThreadRun ,
2528 deriveProviderSubagentStatus ,
@@ -38,6 +41,23 @@ import {
3841
3942const now = DateTime . makeUnsafe ( "2026-07-28T10:00:00.000Z" ) ;
4043
44+ function request (
45+ id : string ,
46+ status : OrchestrationV2RuntimeRequest [ "status" ] ,
47+ ) : OrchestrationV2RuntimeRequest {
48+ return {
49+ id : RuntimeRequestId . make ( id ) ,
50+ nodeId : NodeId . make ( `node-${ id } ` ) ,
51+ providerTurnId : null ,
52+ nativeRequestRef : null ,
53+ kind : "command" ,
54+ status,
55+ responseCapability : { type : "not_resumable" , reason : "Session ended." } ,
56+ createdAt : now ,
57+ resolvedAt : status === "pending" ? null : now ,
58+ } ;
59+ }
60+
4161function run ( id : string , ordinal : number , status : OrchestrationV2RunStatus ) {
4262 return {
4363 id : RunId . make ( id ) ,
@@ -369,6 +389,47 @@ describe("thread execution presentation", () => {
369389 expect ( deriveThreadRuntime ( onlyHeld ) ) . toBeNull ( ) ;
370390 } ) ;
371391
392+ it . each ( [
393+ { name : "no requests" , requests : [ ] , runId : "run-stopped" , held : false , expected : true } ,
394+ {
395+ name : "a pending request" ,
396+ requests : [ request ( "approval" , "pending" ) ] ,
397+ runId : "run-stopped" ,
398+ held : false ,
399+ expected : false ,
400+ } ,
401+ {
402+ name : "only a resolved request" ,
403+ requests : [ request ( "approval" , "resolved" ) ] ,
404+ runId : "run-stopped" ,
405+ held : false ,
406+ expected : true ,
407+ } ,
408+ {
409+ name : "a held queue behind a blocked continuation" ,
410+ requests : [ request ( "approval" , "pending" ) ] ,
411+ runId : "run-stopped" ,
412+ held : true ,
413+ expected : false ,
414+ } ,
415+ {
416+ name : "a held queue with no run to continue" ,
417+ requests : [ request ( "approval" , "pending" ) ] ,
418+ runId : null ,
419+ held : true ,
420+ expected : true ,
421+ } ,
422+ { name : "nothing to resume" , requests : [ ] , runId : null , held : false , expected : false } ,
423+ ] ) ( "decides whether Resume can start with $name" , ( { requests, runId, held, expected } ) => {
424+ expect (
425+ canResumeThread (
426+ { runtimeRequests : requests } ,
427+ runId === null ? null : RunId . make ( runId ) ,
428+ held ,
429+ ) ,
430+ ) . toBe ( expected ) ;
431+ } ) ;
432+
372433 it ( "does not expose a queued-only run as interruptible" , ( ) => {
373434 const queuedRun = run ( "run-queued" , 1 , "queued" ) ;
374435 const projection = { ...v2Projection , runs : [ queuedRun ] , updatedAt : now } ;
0 commit comments