@@ -2,6 +2,7 @@ import { describe, expect, test } from "bun:test"
22import { Instance } from "../../src/project/instance"
33import { Session } from "../../src/session"
44import { SessionPrompt } from "../../src/session/prompt"
5+ import { Agent } from "../../src/agent/agent"
56import { tmpdir } from "../fixture/fixture"
67
78describe ( "session.prompt agent variant" , ( ) => {
@@ -84,4 +85,99 @@ describe("session.prompt agent variant", () => {
8485 } ,
8586 } )
8687 } )
88+
89+ test ( "subagent inherits variant from parent session user message" , async ( ) => {
90+ await using tmp = await tmpdir ( {
91+ git : true ,
92+ config : { } ,
93+ } )
94+
95+ await Instance . provide ( {
96+ directory : tmp . path ,
97+ fn : async ( ) => {
98+ // 1. Create a parent session and send a user message with variant
99+ const parent = await Session . create ( { } )
100+ const parentMsg = await SessionPrompt . prompt ( {
101+ sessionID : parent . id ,
102+ variant : "high" ,
103+ noReply : true ,
104+ parts : [ { type : "text" , text : "use @general to explore the codebase" } ] ,
105+ } )
106+ if ( parentMsg . info . role !== "user" ) throw new Error ( "expected user message" )
107+ expect ( parentMsg . info . variant ) . toBe ( "high" )
108+
109+ // 2. Simulate what task.ts does: read back the parent user message
110+ // and compute the inherited variant for the subagent
111+ const agent = await Agent . get ( "general" )
112+ const resolved = ! agent . variant && parentMsg . info . role === "user" ? parentMsg . info . variant : undefined
113+ expect ( resolved ) . toBe ( "high" )
114+
115+ // 3. Create a child session (like task.ts does) and prompt with inherited variant
116+ const child = await Session . create ( { parentID : parent . id } )
117+ const childMsg = await SessionPrompt . prompt ( {
118+ sessionID : child . id ,
119+ agent : "general" ,
120+ variant : resolved ,
121+ noReply : true ,
122+ parts : [ { type : "text" , text : "explore the project structure" } ] ,
123+ } )
124+ if ( childMsg . info . role !== "user" ) throw new Error ( "expected user message" )
125+ expect ( childMsg . info . variant ) . toBe ( "high" )
126+
127+ await Session . remove ( child . id )
128+ await Session . remove ( parent . id )
129+ } ,
130+ } )
131+ } )
132+
133+ test ( "subagent does not inherit variant when agent has own variant" , async ( ) => {
134+ await using tmp = await tmpdir ( {
135+ git : true ,
136+ config : {
137+ agent : {
138+ build : {
139+ model : "openai/gpt-5.2" ,
140+ variant : "xhigh" ,
141+ } ,
142+ } ,
143+ } ,
144+ } )
145+
146+ await Instance . provide ( {
147+ directory : tmp . path ,
148+ fn : async ( ) => {
149+ // 1. Parent message with variant="high"
150+ const parent = await Session . create ( { } )
151+ const parentMsg = await SessionPrompt . prompt ( {
152+ sessionID : parent . id ,
153+ variant : "high" ,
154+ noReply : true ,
155+ parts : [ { type : "text" , text : "use @build to compile" } ] ,
156+ } )
157+ if ( parentMsg . info . role !== "user" ) throw new Error ( "expected user message" )
158+ expect ( parentMsg . info . variant ) . toBe ( "high" )
159+
160+ // 2. Agent "build" has its own variant="xhigh", so inheritance should NOT happen
161+ const agent = await Agent . get ( "build" )
162+ const resolved = ! agent . variant && parentMsg . info . role === "user" ? parentMsg . info . variant : undefined
163+ expect ( resolved ) . toBeUndefined ( )
164+
165+ // 3. When variant=undefined, the child session uses agent's own variant via prompt.ts
166+ const child = await Session . create ( { parentID : parent . id } )
167+ const childMsg = await SessionPrompt . prompt ( {
168+ sessionID : child . id ,
169+ agent : "build" ,
170+ variant : resolved ,
171+ noReply : true ,
172+ parts : [ { type : "text" , text : "compile the project" } ] ,
173+ } )
174+ if ( childMsg . info . role !== "user" ) throw new Error ( "expected user message" )
175+ // agent.variant="xhigh" is applied by prompt.ts since we're using the agent's model
176+ expect ( childMsg . info . variant ) . toBe ( "xhigh" )
177+
178+ await Session . remove ( child . id )
179+ await Session . remove ( parent . id )
180+ } ,
181+ } )
182+ } )
87183} )
0 commit comments