@@ -957,6 +957,8 @@ describe("buildStatusReply subagent summary", () => {
957957 OPENAI_API_KEY : undefined ,
958958 OPENAI_OAUTH_TOKEN : undefined ,
959959 } ,
960+ skipSessionCleanup : true ,
961+ skipHomeCleanup : true ,
960962 } ,
961963 ) ;
962964 } ) ;
@@ -1042,6 +1044,8 @@ describe("buildStatusReply subagent summary", () => {
10421044 OPENAI_API_KEY : undefined ,
10431045 OPENAI_OAUTH_TOKEN : undefined ,
10441046 } ,
1047+ skipSessionCleanup : true ,
1048+ skipHomeCleanup : true ,
10451049 } ,
10461050 ) ;
10471051 } ) ;
@@ -1066,66 +1070,69 @@ describe("buildStatusReply subagent summary", () => {
10661070 ] ,
10671071 } ) ;
10681072
1069- await withTempHome ( async ( dir ) => {
1070- saveStatusTestAuthProfile ( { dir, profileId : "work" , provider : "openai" } ) ;
1073+ await withTempHome (
1074+ async ( dir ) => {
1075+ saveStatusTestAuthProfile ( { dir, profileId : "work" , provider : "openai" } ) ;
10711076
1072- const text = await buildStatusText ( {
1073- cfg : {
1074- ...baseCfg ,
1075- agents : {
1076- defaults : {
1077- agentRuntime : { id : "codex" } ,
1077+ const text = await buildStatusText ( {
1078+ cfg : {
1079+ ...baseCfg ,
1080+ agents : {
1081+ defaults : {
1082+ agentRuntime : { id : "codex" } ,
1083+ } ,
10781084 } ,
10791085 } ,
1080- } ,
1081- sessionEntry : {
1082- sessionId : "sess-status-codex-synthetic-usage" ,
1083- updatedAt : 0 ,
1084- authProfileOverride : "work" ,
1085- } ,
1086- sessionKey : "agent:main:main" ,
1087- parentSessionKey : "agent:main:main" ,
1088- sessionScope : "per-sender" ,
1089- statusChannel : "mobilechat" ,
1090- provider : "openai" ,
1091- model : "gpt-5.5" ,
1092- contextTokens : 32_000 ,
1093- resolvedFastMode : false ,
1094- resolvedVerboseLevel : "off" ,
1095- resolvedReasoningLevel : "off" ,
1096- resolveDefaultThinkingLevel : async ( ) => undefined ,
1097- isGroup : false ,
1098- defaultGroupActivation : ( ) => "mention" ,
1099- modelAuthOverride : "oauth" ,
1100- activeModelAuthOverride : "oauth" ,
1101- } ) ;
1102-
1103- const normalized = normalizeTestText ( text ) ;
1104- expect ( normalized ) . toContain ( "Model: openai/gpt-5.5" ) ;
1105- expect ( normalized ) . toContain ( "Runtime: OpenAI Codex" ) ;
1106- expect ( normalized ) . toContain ( "Usage: 5h 91% left" ) ;
1107- const providerUsageCall = providerUsageMock . loadProviderUsageSummary . mock . calls . find (
1108- ( [ params ] ) => params ?. providers ?. includes ( "openai" ) ,
1109- ) ;
1110- if ( ! providerUsageCall ) {
1111- throw new Error ( "expected provider usage summary call for synthetic Codex auth" ) ;
1112- }
1113- expect ( providerUsageCall [ 0 ] ) . toMatchObject ( {
1114- timeoutMs : 8000 ,
1115- providers : [ "openai" ] ,
1116- auth : [
1117- {
1118- ...expectedCodexRuntimeUsageAuth [ 0 ] ,
1119- authProfileId : "work" ,
1086+ sessionEntry : {
1087+ sessionId : "sess-status-codex-synthetic-usage" ,
1088+ updatedAt : 0 ,
1089+ authProfileOverride : "work" ,
11201090 } ,
1121- ] ,
1122- config : expect . objectContaining ( {
1123- agents : expect . objectContaining ( {
1124- defaults : expect . objectContaining ( { agentRuntime : { id : "codex" } } ) ,
1091+ sessionKey : "agent:main:main" ,
1092+ parentSessionKey : "agent:main:main" ,
1093+ sessionScope : "per-sender" ,
1094+ statusChannel : "mobilechat" ,
1095+ provider : "openai" ,
1096+ model : "gpt-5.5" ,
1097+ contextTokens : 32_000 ,
1098+ resolvedFastMode : false ,
1099+ resolvedVerboseLevel : "off" ,
1100+ resolvedReasoningLevel : "off" ,
1101+ resolveDefaultThinkingLevel : async ( ) => undefined ,
1102+ isGroup : false ,
1103+ defaultGroupActivation : ( ) => "mention" ,
1104+ modelAuthOverride : "oauth" ,
1105+ activeModelAuthOverride : "oauth" ,
1106+ } ) ;
1107+
1108+ const normalized = normalizeTestText ( text ) ;
1109+ expect ( normalized ) . toContain ( "Model: openai/gpt-5.5" ) ;
1110+ expect ( normalized ) . toContain ( "Runtime: OpenAI Codex" ) ;
1111+ expect ( normalized ) . toContain ( "Usage: 5h 91% left" ) ;
1112+ const providerUsageCall = providerUsageMock . loadProviderUsageSummary . mock . calls . find (
1113+ ( [ params ] ) => params ?. providers ?. includes ( "openai" ) ,
1114+ ) ;
1115+ if ( ! providerUsageCall ) {
1116+ throw new Error ( "expected provider usage summary call for synthetic Codex auth" ) ;
1117+ }
1118+ expect ( providerUsageCall [ 0 ] ) . toMatchObject ( {
1119+ timeoutMs : 8000 ,
1120+ providers : [ "openai" ] ,
1121+ auth : [
1122+ {
1123+ ...expectedCodexRuntimeUsageAuth [ 0 ] ,
1124+ authProfileId : "work" ,
1125+ } ,
1126+ ] ,
1127+ config : expect . objectContaining ( {
1128+ agents : expect . objectContaining ( {
1129+ defaults : expect . objectContaining ( { agentRuntime : { id : "codex" } } ) ,
1130+ } ) ,
11251131 } ) ,
1126- } ) ,
1127- } ) ;
1128- } ) ;
1132+ } ) ;
1133+ } ,
1134+ { skipSessionCleanup : true , skipHomeCleanup : true } ,
1135+ ) ;
11291136 } ) ;
11301137
11311138 it ( "forwards legacy Codex profile providers to Codex synthetic usage" , async ( ) => {
@@ -1141,14 +1148,74 @@ describe("buildStatusReply subagent summary", () => {
11411148 ] ,
11421149 } ) ;
11431150
1144- await withTempHome ( async ( dir ) => {
1145- saveStatusTestAuthProfile ( {
1146- dir,
1147- profileId : "openai-codex:legacy" ,
1148- provider : "openai-codex" ,
1149- } ) ;
1151+ await withTempHome (
1152+ async ( dir ) => {
1153+ saveStatusTestAuthProfile ( {
1154+ dir,
1155+ profileId : "openai-codex:legacy" ,
1156+ provider : "openai-codex" ,
1157+ } ) ;
11501158
1151- await buildStatusText ( {
1159+ await buildStatusText ( {
1160+ cfg : {
1161+ ...baseCfg ,
1162+ agents : {
1163+ defaults : {
1164+ agentRuntime : { id : "codex" } ,
1165+ } ,
1166+ } ,
1167+ } ,
1168+ sessionEntry : {
1169+ sessionId : "sess-status-codex-legacy-profile" ,
1170+ updatedAt : 0 ,
1171+ authProfileOverride : "openai-codex:legacy" ,
1172+ } ,
1173+ sessionKey : "agent:main:main" ,
1174+ parentSessionKey : "agent:main:main" ,
1175+ sessionScope : "per-sender" ,
1176+ statusChannel : "mobilechat" ,
1177+ provider : "openai" ,
1178+ model : "gpt-5.5" ,
1179+ contextTokens : 32_000 ,
1180+ resolvedFastMode : false ,
1181+ resolvedVerboseLevel : "off" ,
1182+ resolvedReasoningLevel : "off" ,
1183+ resolveDefaultThinkingLevel : async ( ) => undefined ,
1184+ isGroup : false ,
1185+ defaultGroupActivation : ( ) => "mention" ,
1186+ modelAuthOverride : "oauth" ,
1187+ activeModelAuthOverride : "oauth" ,
1188+ } ) ;
1189+
1190+ const providerUsageCall = providerUsageMock . loadProviderUsageSummary . mock . calls . find (
1191+ ( [ params ] ) => params ?. providers ?. includes ( "openai" ) ,
1192+ ) ;
1193+ expect ( providerUsageCall ?. [ 0 ] ?. auth ) . toEqual ( [
1194+ {
1195+ ...expectedCodexRuntimeUsageAuth [ 0 ] ,
1196+ authProfileId : "openai-codex:legacy" ,
1197+ } ,
1198+ ] ) ;
1199+ } ,
1200+ { skipSessionCleanup : true , skipHomeCleanup : true } ,
1201+ ) ;
1202+ } ) ;
1203+
1204+ it ( "loads Codex synthetic usage when no local OpenAI profile label exists" , async ( ) => {
1205+ registerStatusCodexHarness ( ) ;
1206+ providerUsageMock . loadProviderUsageSummary . mockResolvedValue ( {
1207+ updatedAt : Date . now ( ) ,
1208+ providers : [
1209+ {
1210+ provider : "openai" ,
1211+ displayName : "OpenAI" ,
1212+ windows : [ { label : "5h" , usedPercent : 16 } ] ,
1213+ } ,
1214+ ] ,
1215+ } ) ;
1216+
1217+ await withTempHome ( async ( ) => {
1218+ const text = await buildStatusText ( {
11521219 cfg : {
11531220 ...baseCfg ,
11541221 agents : {
@@ -1158,9 +1225,8 @@ describe("buildStatusReply subagent summary", () => {
11581225 } ,
11591226 } ,
11601227 sessionEntry : {
1161- sessionId : "sess-status-codex-legacy -profile" ,
1228+ sessionId : "sess-status-codex-no -profile" ,
11621229 updatedAt : 0 ,
1163- authProfileOverride : "openai-codex:legacy" ,
11641230 } ,
11651231 sessionKey : "agent:main:main" ,
11661232 parentSessionKey : "agent:main:main" ,
@@ -1175,19 +1241,13 @@ describe("buildStatusReply subagent summary", () => {
11751241 resolveDefaultThinkingLevel : async ( ) => undefined ,
11761242 isGroup : false ,
11771243 defaultGroupActivation : ( ) => "mention" ,
1178- modelAuthOverride : "oauth" ,
1179- activeModelAuthOverride : "oauth" ,
11801244 } ) ;
11811245
1246+ expect ( normalizeTestText ( text ) ) . toContain ( "Usage: 5h 84% left" ) ;
11821247 const providerUsageCall = providerUsageMock . loadProviderUsageSummary . mock . calls . find (
11831248 ( [ params ] ) => params ?. providers ?. includes ( "openai" ) ,
11841249 ) ;
1185- expect ( providerUsageCall ?. [ 0 ] ?. auth ) . toEqual ( [
1186- {
1187- ...expectedCodexRuntimeUsageAuth [ 0 ] ,
1188- authProfileId : "openai-codex:legacy" ,
1189- } ,
1190- ] ) ;
1250+ expect ( providerUsageCall ?. [ 0 ] ?. auth ) . toEqual ( expectedCodexRuntimeUsageAuth ) ;
11911251 } ) ;
11921252 } ) ;
11931253
@@ -1204,49 +1264,52 @@ describe("buildStatusReply subagent summary", () => {
12041264 ] ,
12051265 } ) ;
12061266
1207- await withTempHome ( async ( dir ) => {
1208- saveStatusTestAuthProfiles ( {
1209- dir,
1210- profiles : [
1211- { profileId : "openai:status" , provider : "openai" } ,
1212- { profileId : "anthropic:work" , provider : "anthropic" } ,
1213- ] ,
1214- } ) ;
1267+ await withTempHome (
1268+ async ( dir ) => {
1269+ saveStatusTestAuthProfiles ( {
1270+ dir,
1271+ profiles : [
1272+ { profileId : "openai:status" , provider : "openai" } ,
1273+ { profileId : "anthropic:work" , provider : "anthropic" } ,
1274+ ] ,
1275+ } ) ;
12151276
1216- await buildStatusText ( {
1217- cfg : {
1218- ...baseCfg ,
1219- agents : {
1220- defaults : {
1221- agentRuntime : { id : "codex" } ,
1277+ await buildStatusText ( {
1278+ cfg : {
1279+ ...baseCfg ,
1280+ agents : {
1281+ defaults : {
1282+ agentRuntime : { id : "codex" } ,
1283+ } ,
12221284 } ,
12231285 } ,
1224- } ,
1225- sessionEntry : {
1226- sessionId : "sess-status-codex-stale-profile" ,
1227- updatedAt : 0 ,
1228- authProfileOverride : "anthropic:work" ,
1229- } ,
1230- sessionKey : "agent:main:main" ,
1231- parentSessionKey : "agent:main:main" ,
1232- sessionScope : "per-sender" ,
1233- statusChannel : "mobilechat" ,
1234- provider : "openai" ,
1235- model : "gpt-5.5" ,
1236- contextTokens : 32_000 ,
1237- resolvedFastMode : false ,
1238- resolvedVerboseLevel : "off" ,
1239- resolvedReasoningLevel : "off" ,
1240- resolveDefaultThinkingLevel : async ( ) => undefined ,
1241- isGroup : false ,
1242- defaultGroupActivation : ( ) => "mention" ,
1243- } ) ;
1286+ sessionEntry : {
1287+ sessionId : "sess-status-codex-stale-profile" ,
1288+ updatedAt : 0 ,
1289+ authProfileOverride : "anthropic:work" ,
1290+ } ,
1291+ sessionKey : "agent:main:main" ,
1292+ parentSessionKey : "agent:main:main" ,
1293+ sessionScope : "per-sender" ,
1294+ statusChannel : "mobilechat" ,
1295+ provider : "openai" ,
1296+ model : "gpt-5.5" ,
1297+ contextTokens : 32_000 ,
1298+ resolvedFastMode : false ,
1299+ resolvedVerboseLevel : "off" ,
1300+ resolvedReasoningLevel : "off" ,
1301+ resolveDefaultThinkingLevel : async ( ) => undefined ,
1302+ isGroup : false ,
1303+ defaultGroupActivation : ( ) => "mention" ,
1304+ } ) ;
12441305
1245- const providerUsageCall = providerUsageMock . loadProviderUsageSummary . mock . calls . find (
1246- ( [ params ] ) => params ?. providers ?. includes ( "openai" ) ,
1247- ) ;
1248- expect ( providerUsageCall ?. [ 0 ] ?. auth ) . toEqual ( expectedCodexRuntimeUsageAuth ) ;
1249- } ) ;
1306+ const providerUsageCall = providerUsageMock . loadProviderUsageSummary . mock . calls . find (
1307+ ( [ params ] ) => params ?. providers ?. includes ( "openai" ) ,
1308+ ) ;
1309+ expect ( providerUsageCall ?. [ 0 ] ?. auth ) . toEqual ( expectedCodexRuntimeUsageAuth ) ;
1310+ } ,
1311+ { skipSessionCleanup : true , skipHomeCleanup : true } ,
1312+ ) ;
12501313 } ) ;
12511314
12521315 it ( "uses active fallback provider usage for legacy fallback notices" , async ( ) => {
@@ -1751,7 +1814,7 @@ describe("buildStatusReply subagent summary", () => {
17511814 expect ( normalized ) . toContain ( "oauth (openai:status)" ) ;
17521815 expect ( normalized ) . not . toContain ( "api-key (openai:backup)" ) ;
17531816 } ,
1754- { env : { OPENAI_API_KEY : undefined } } ,
1817+ { env : { OPENAI_API_KEY : undefined } , skipSessionCleanup : true , skipHomeCleanup : true } ,
17551818 ) ;
17561819 } ) ;
17571820
0 commit comments