@@ -54,6 +54,35 @@ describe("buildCostSummary", () => {
5454 expect ( summary . costHiddenReason ) . toBe ( "coding-plan" ) ;
5555 } ) ;
5656
57+ it ( "hides cost for a live coding-plan identity even when baseURL is still metered" , ( ) => {
58+ const summary = buildCostSummary ( {
59+ ...baseInput ,
60+ providerName : "zai" ,
61+ baseURL : "https://api.openai.com/v1" ,
62+ } ) ;
63+ expect ( summary . costHiddenReason ) . toBe ( "coding-plan" ) ;
64+ } ) ;
65+
66+ it ( "shows cost for a live metered identity even when baseURL is still a coding-plan endpoint" , ( ) => {
67+ const summary = buildCostSummary ( {
68+ ...baseInput ,
69+ modelId : "glm-5.1" ,
70+ providerName : "openai" ,
71+ baseURL : "https://api.z.ai/api/coding/paas/v4" ,
72+ } ) ;
73+ expect ( summary . costHiddenReason ) . toBeNull ( ) ;
74+ } ) ;
75+
76+ it ( "hides cost for a Codex ChatGPT subscription identity" , ( ) => {
77+ const summary = buildCostSummary ( {
78+ ...baseInput ,
79+ modelId : "gpt-5.6-luna" ,
80+ providerName : "codex/default" ,
81+ baseURL : "https://api.openai.com/v1" ,
82+ } ) ;
83+ expect ( summary . costHiddenReason ) . toBe ( "chatgpt-subscription" ) ;
84+ } ) ;
85+
5786 it ( "hides cost for a provider marked free" , ( ) => {
5887 const summary = buildCostSummary ( { ...baseInput , providerFree : true } ) ;
5988 expect ( summary . costHiddenReason ) . toBe ( "provider-free" ) ;
@@ -102,6 +131,47 @@ describe("formatStatusBarSegments", () => {
102131 } ) ;
103132 } ) ;
104133
134+ it ( "omits dollar cost for a Codex ChatGPT subscription session" , ( ) => {
135+ const summary = buildCostSummary ( {
136+ ...baseInput ,
137+ modelId : "gpt-5.6-luna" ,
138+ providerName : "codex/default" ,
139+ baseURL : "https://api.openai.com/v1" ,
140+ totalCost : 1.1897 ,
141+ formattedCost : "$1.1897" ,
142+ } ) ;
143+ expect ( formatStatusBarSegments ( summary ) ) . toEqual ( {
144+ contextLabel : "Ctx 16%" ,
145+ contextPercentUsed : 16 ,
146+ } ) ;
147+ } ) ;
148+
149+ it ( "omits prompt $ on a mixed session while the live identity is Codex" , ( ) => {
150+ const summary = buildCostSummary ( {
151+ ...baseInput ,
152+ modelId : "gpt-5.6-luna" ,
153+ providerName : "codex/default" ,
154+ formattedCost : "$0.0070" ,
155+ totalCost : 0.007 ,
156+ sessionBillingMix : "mixed" ,
157+ sessionHiddenReason : "chatgpt-subscription" ,
158+ } ) ;
159+ expect ( formatStatusBarSegments ( summary ) . costLabel ) . toBeUndefined ( ) ;
160+ } ) ;
161+
162+ it ( "shows the metered-accumulated $ on a mixed session while the live identity is metered" , ( ) => {
163+ const summary = buildCostSummary ( {
164+ ...baseInput ,
165+ modelId : "glm-5.1" ,
166+ providerName : "openai" ,
167+ formattedCost : "$0.0070" ,
168+ totalCost : 0.007 ,
169+ sessionBillingMix : "mixed" ,
170+ sessionHiddenReason : "chatgpt-subscription" ,
171+ } ) ;
172+ expect ( formatStatusBarSegments ( summary ) . costLabel ) . toBe ( "$0.0070" ) ;
173+ } ) ;
174+
105175 it ( "renders an unknown context window as --% rather than 0%" , ( ) => {
106176 setModelContextWindows ( { "test-model" : 0 } ) ;
107177 const summary = buildCostSummary ( baseInput ) ;
@@ -142,6 +212,23 @@ describe("formatCostCommandOutput", () => {
142212 expect ( formatCostCommandOutput ( summary ) ) . toContain ( "Cost: hidden (coding-plan endpoint)" ) ;
143213 } ) ;
144214
215+ it ( "reports ChatGPT subscription coverage instead of a hidden dollar figure" , ( ) => {
216+ const summary = buildCostSummary ( {
217+ ...baseInput ,
218+ modelId : "gpt-5.6-luna" ,
219+ providerName : "codex/default" ,
220+ baseURL : "https://api.openai.com/v1" ,
221+ } ) ;
222+ expect ( formatCostCommandOutput ( summary ) ) . toBe (
223+ [
224+ "Model: gpt-5.6-luna" ,
225+ "Cost: covered by ChatGPT subscription (not billed per token)" ,
226+ "Tokens: 1000 in / 500 out / 200 cache-read" ,
227+ "Context: 64000/400000 (16%)" ,
228+ ] . join ( "\n" ) ,
229+ ) ;
230+ } ) ;
231+
145232 it ( "reports the reason cost is hidden for a provider marked free" , ( ) => {
146233 const summary = buildCostSummary ( { ...baseInput , providerFree : true } ) ;
147234 expect ( formatCostCommandOutput ( summary ) ) . toContain ( "Cost: hidden (provider marked free)" ) ;
@@ -157,4 +244,49 @@ describe("formatCostCommandOutput", () => {
157244 const summary = buildCostSummary ( { ...baseInput , contextIsEstimate : true } ) ;
158245 expect ( formatCostCommandOutput ( summary ) ) . toContain ( "(~50%)" ) ;
159246 } ) ;
247+
248+ it ( "prints mixed /cost as the metered portion, not a whole-session subscription" , ( ) => {
249+ const summary = buildCostSummary ( {
250+ ...baseInput ,
251+ modelId : "gpt-5.6-luna" ,
252+ providerName : "codex/default" ,
253+ formattedCost : "$0.0070" ,
254+ totalCost : 0.007 ,
255+ sessionBillingMix : "mixed" ,
256+ sessionHiddenReason : "chatgpt-subscription" ,
257+ } ) ;
258+ const output = formatCostCommandOutput ( summary ) ;
259+ expect ( output ) . toContain (
260+ "Cost: $0.0070 (metered portion only; session mixed billed and hidden usage)" ,
261+ ) ;
262+ expect ( output ) . not . toContain ( "covered by ChatGPT subscription" ) ;
263+ } ) ;
264+
265+ it ( "prints mixed /cost as the metered portion after switching onto a public-rate model" , ( ) => {
266+ const summary = buildCostSummary ( {
267+ ...baseInput ,
268+ modelId : "glm-5.1" ,
269+ providerName : "openai" ,
270+ formattedCost : "$0.0070" ,
271+ totalCost : 0.007 ,
272+ sessionBillingMix : "mixed" ,
273+ sessionHiddenReason : "chatgpt-subscription" ,
274+ } ) ;
275+ expect ( formatCostCommandOutput ( summary ) ) . toContain (
276+ "Cost: $0.0070 (metered portion only; session mixed billed and hidden usage)" ,
277+ ) ;
278+ } ) ;
279+
280+ it ( "keeps hidden-only Codex /cost on the subscription copy" , ( ) => {
281+ const summary = buildCostSummary ( {
282+ ...baseInput ,
283+ modelId : "gpt-5.6-luna" ,
284+ providerName : "codex/default" ,
285+ sessionBillingMix : "hidden-only" ,
286+ sessionHiddenReason : "chatgpt-subscription" ,
287+ } ) ;
288+ expect ( formatCostCommandOutput ( summary ) ) . toContain (
289+ "Cost: covered by ChatGPT subscription (not billed per token)" ,
290+ ) ;
291+ } ) ;
160292} ) ;
0 commit comments