@@ -24,6 +24,7 @@ function deferred<T>() {
2424}
2525
2626const state = vi . hoisted ( ( ) => ( {
27+ serverConfig : { shellThreadFamilies : false } ,
2728 scopes : new Map < string , Set < string > > ( ) ,
2829 threads : [ ] as {
2930 environmentId : EnvironmentId ;
@@ -35,6 +36,10 @@ const state = vi.hoisted(() => ({
3536 session : { status : "ready" | "stopped" } | null ;
3637 latestTurn : null ;
3738 } [ ] ,
39+ familyThreads : [ ] as {
40+ id : ThreadId ;
41+ lineage : { parentThreadId : ThreadId | null ; sideChat ?: boolean } ;
42+ } [ ] ,
3843 requests : [ ] as { action : string ; environmentId : string ; input : { threadId ?: string } } [ ] ,
3944 localEffects : [ ] as string [ ] ,
4045 confirm : vi . fn < ( message : string ) => Promise < boolean > > ( ) ,
@@ -71,15 +76,28 @@ vi.mock("../state/use-atom-command", () => ({
7176 } ,
7277} ) ) ;
7378vi . mock ( "../state/use-atom-query-runner" , ( ) => ( {
74- useAtomQueryRunner : ( ) => async ( environmentId : string ) =>
75- state . sessionLookupFails
76- ? AsyncResult . failure ( Cause . fail ( new Error ( "Session lookup failed" ) ) )
77- : AsyncResult . success ( {
78- authenticated : true ,
79- scopes : [ ...( state . scopes . get ( environmentId ) ?? [ ] ) ] ,
80- auth : { serverUpdateScope : "environment:maintain" } ,
81- } ) ,
79+ useAtomQueryRunner : ( family : unknown ) => async ( environmentId : string ) =>
80+ family === "threadFamily"
81+ ? AsyncResult . success ( { threads : state . familyThreads } )
82+ : state . sessionLookupFails
83+ ? AsyncResult . failure ( Cause . fail ( new Error ( "Session lookup failed" ) ) )
84+ : AsyncResult . success ( {
85+ authenticated : true ,
86+ scopes : [ ...( state . scopes . get ( environmentId ) ?? [ ] ) ] ,
87+ auth : { serverUpdateScope : "environment:maintain" } ,
88+ } ) ,
89+ } ) ) ;
90+ vi . mock ( "../state/orchestration" , ( ) => ( {
91+ orchestrationEnvironment : { threadFamily : "threadFamily" } ,
8292} ) ) ;
93+ vi . mock ( "../state/server" , async ( importOriginal ) => {
94+ const actual = await importOriginal < typeof import ( "../state/server" ) > ( ) ;
95+ const { Atom } = await import ( "effect/reactivity" ) ;
96+ return {
97+ ...actual ,
98+ environmentServerConfigsAtom : Atom . make ( new Map ( [ [ "secondary" , state . serverConfig ] ] ) ) ,
99+ } ;
100+ } ) ;
83101vi . mock ( "../state/threads" , ( ) => ( {
84102 threadEnvironment : Object . fromEntries (
85103 [
@@ -230,6 +248,8 @@ const operations = [
230248] as const ;
231249
232250beforeEach ( ( ) => {
251+ state . serverConfig . shellThreadFamilies = false ;
252+ state . familyThreads = [ ] ;
233253 state . scopes = new Map ( [
234254 [ primary , new Set ( [ AuthOrchestrationOperateScope ] ) ] ,
235255 [ secondary , new Set < string > ( ) ] ,
@@ -312,6 +332,18 @@ describe("thread action permissions", () => {
312332 ) ;
313333
314334 it ( "deletes an archived thread only with its own environment's grant" , async ( ) => {
335+ state . serverConfig . shellThreadFamilies = true ;
336+ state . familyThreads = [
337+ {
338+ id : ThreadId . make ( "side-chat" ) ,
339+ lineage : { parentThreadId : target . threadId , sideChat : true } ,
340+ } ,
341+ { id : ThreadId . make ( "fork" ) , lineage : { parentThreadId : target . threadId } } ,
342+ {
343+ id : ThreadId . make ( "other-side-chat" ) ,
344+ lineage : { parentThreadId : ThreadId . make ( "other-parent" ) , sideChat : true } ,
345+ } ,
346+ ] ;
315347 state . threads = [ ] ;
316348 seedThreadPanelState ( target ) ;
317349 const actions = useThreadActions ( ) ;
@@ -324,6 +356,16 @@ describe("thread action permissions", () => {
324356 expect . objectContaining ( { action : "delete" , environmentId : secondary } ) ,
325357 ] ) ;
326358 expect ( threadPanelStatePresence ( target ) ) . toEqual ( panelStateCleared ) ;
359+ expect ( state . localEffects ) . toEqual (
360+ expect . arrayContaining ( [
361+ "release-uploads:thread" ,
362+ "clear-draft:thread" ,
363+ "release-uploads:side-chat" ,
364+ "clear-draft:side-chat" ,
365+ ] ) ,
366+ ) ;
367+ expect ( state . localEffects ) . not . toContain ( "clear-draft:fork" ) ;
368+ expect ( state . localEffects ) . not . toContain ( "clear-draft:other-side-chat" ) ;
327369 } ) ;
328370
329371 it ( "stops before delete and local cleanup when permission is revoked during session stop" , async ( ) => {
0 commit comments