@@ -2231,6 +2231,10 @@ describe("PiAdapterV2", () => {
22312231 yield * fake . emit ( { type : "response" , command : "prompt" , success : true } ) ;
22322232 yield * fake . emit ( { type : "agent_start" } ) ;
22332233 yield * fake . emit ( { type : "agent_settled" } ) ;
2234+ yield * takeEvent (
2235+ ( event ) =>
2236+ event . type === "provider_turn.updated" && event . providerTurn . status === "completed" ,
2237+ ) ;
22342238 const thread = yield * takeEvent (
22352239 ( event ) =>
22362240 event . type === "provider_thread.updated" && event . providerThread . status === "idle" ,
@@ -2241,6 +2245,56 @@ describe("PiAdapterV2", () => {
22412245 } ) . pipe ( Effect . scoped , Effect . provide ( layerTest ) ) ,
22422246 ) ;
22432247
2248+ it . effect . each ( [ "missing parent" , "invalid parent" , "duplicate id" ] as const ) (
2249+ "does not reconcile malformed session entries: %s" ,
2250+ ( malformed ) =>
2251+ Effect . gen ( function * ( ) {
2252+ const fake = yield * makeFakePi ;
2253+ const { runtime, takeEvent } = yield * openRuntime ( fake ) ;
2254+ const root = { type : "model_change" , id : "root" , parentId : null } ;
2255+ fake . queueEntries ( { entries : [ root ] , leafId : "root" } ) ;
2256+ const providerThread = yield * runtime . ensureThread ( {
2257+ threadId : THREAD_ID ,
2258+ modelSelection : modelSelection ( "default" ) ,
2259+ runtimePolicy,
2260+ } ) ;
2261+ yield * startTurn ( runtime , providerThread ) ;
2262+ yield * fake . takeRequest ( "prompt" ) ;
2263+ const entry = {
2264+ type : "message" ,
2265+ id : "x" ,
2266+ message : { role : "user" , content : [ ] } ,
2267+ ...( malformed === "missing parent"
2268+ ? { }
2269+ : { parentId : malformed === "invalid parent" ? 42 : null } ) ,
2270+ } ;
2271+ fake . queueEntries ( { entries : [ ] , leafId : "x" } ) ;
2272+ fake . queueEntries ( {
2273+ entries : [
2274+ root ,
2275+ entry ,
2276+ ...( malformed === "duplicate id" ? [ { ...entry , parentId : "root" } ] : [ ] ) ,
2277+ ] ,
2278+ leafId : "x" ,
2279+ } ) ;
2280+ yield * fake . emit ( { type : "response" , command : "prompt" , success : true } ) ;
2281+ yield * fake . emit ( { type : "agent_start" } ) ;
2282+ yield * fake . emit ( { type : "agent_settled" } ) ;
2283+ yield * takeEvent (
2284+ ( event ) =>
2285+ event . type === "provider_turn.updated" && event . providerTurn . status === "completed" ,
2286+ ) ;
2287+ const thread = yield * takeEvent (
2288+ ( event ) =>
2289+ event . type === "provider_thread.updated" && event . providerThread . status === "idle" ,
2290+ ) ;
2291+ assert . isUndefined (
2292+ thread . type === "provider_thread.updated" ? thread . retainedNativeTurnIds : null ,
2293+ ) ;
2294+ yield * takeEvent ( ( event ) => event . type === "turn.terminal" ) ;
2295+ } ) . pipe ( Effect . scoped , Effect . provide ( layerTest ) ) ,
2296+ ) ;
2297+
22442298 it . effect ( "does not reconcile a replacement session tree as a native rewind" , ( ) =>
22452299 Effect . gen ( function * ( ) {
22462300 const fake = yield * makeFakePi ;
0 commit comments