From a0d08c81f0902bceef4f92cda1632a36df2b77be Mon Sep 17 00:00:00 2001 From: ozymandiashh <234437643+ozymandiashh@users.noreply.github.com> Date: Sat, 12 Sep 2026 20:29:35 +0300 Subject: [PATCH] fix(menubar): pick the second row's provider by its worst quota window MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The "quota remaining" row selected each provider's headline window, which is a billing horizon: weekly, else monthly, and only then the busiest window. That is the right number for the Capacity Dock rail and the wrong one for a row whose whole job is to name the provider nearest its limit. On a real machine it discarded Cursor's API window at 100% and Claude's 5-hour window at 18% in favour of Monthly 9.5% and Weekly 5%, so the row read as if nothing were near a limit — while the flame beside it was tinting off the worst window across every provider. The comment claiming the row followed the flame was wrong on both counts. Each provider now contributes its worst window, per-model rows included, which is exactly the rule aggregateQuotaStatus tints by, so the row and the flame agree and README, CHANGELOG and the Settings help become true as written. A provider in transientFailure keeps its last-known window instead of dropping out, matching the dock, which shows the same data dimmed during a backoff: the row no longer vanishes and resizes the status item for the length of a retry. Three smaller fixes from the same review: the row is capped at 24 characters — about the widest the single row gets at 13pt, since the second line renders at 9pt — shortening a long provider name rather than letting "GitHub Copilot 12% left · 6d 3h" more than double the item's width; the two-line title gets a VoiceOver label that reads as one phrase instead of a string with a newline in it; and the snapshot feeding the row is no longer built on refreshes where the feature is off. With the setting off the title is byte-for-byte the single-row composition it has always been. Closes #1310 --- CHANGELOG.md | 1 + mac/Sources/CodeBurnMenubar/AppStore.swift | 21 +- mac/Sources/CodeBurnMenubar/CodeBurnApp.swift | 21 +- .../CodeBurnMenubar/MenubarSecondRow.swift | 128 ++++++++++- .../MenubarSecondRowTests.swift | 200 ++++++++++++++++++ 5 files changed, 344 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c634d97..4c7e93e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - **The Capacity Dock gauge can report the short usage window instead of the weekly one, without expanding the dock.** The resting rail shows one number per provider, and that number was always the weekly (else monthly) billing window. Clicking the provider already resting in the rail now switches its gauge to the provider's short rolling window — Claude's 5-hour limit, Codex's 5-hour or daily window, any `Hourly`, `Daily` or session row an adapter reports — and clicking again switches back. The choice is stored per provider under `CodeBurnCapacityDockGlanceWindows`, so Claude can sit on its 5-hour window while Codex stays weekly, and it survives relaunch. A per-model row such as `Weekly · Opus` is never read as a short window, a provider that reports only one window keeps the plain click-to-pin behaviour, and a stored horizon the provider stops reporting falls back to the window it does report rather than blanking the gauge to `--`. The rail's geometry is untouched, VoiceOver and keyboard users get the switch as a named action on the provider cell with the window named in the cell's value, and Escape or a click outside still unpins the dock. (#1243) ### Fixed +- **The menubar second row's quota line now names the provider the flame is warning about.** "Quota remaining" picked each provider's *headline* window — weekly, else monthly, and only then the busiest one — which is the Capacity Dock's billing horizon, not a warning: on a machine with Cursor's API window at 100% and Claude's 5-hour window at 18%, the row reported Monthly 9.5% and Weekly 5% and read as if nothing were near a limit. Each provider now contributes its worst window, per-model rows included, which is exactly what the menu-bar flame already tints by, so the two surfaces agree. A provider backing off after a failed fetch keeps its last-known window instead of dropping out, so the row no longer vanishes — resizing the status item — for the length of a retry, matching what the dock shows dimmed. The row is also capped at 24 characters, shortening a long provider name ("GitHub Copilot 12% left · 6d 3h") rather than letting the second line more than double the item's width, and the two-line title now carries a VoiceOver label that reads as one phrase instead of a string with a newline in it. With the setting off nothing changed: the snapshot that feeds the row is no longer even built on a refresh, and the title is the single-row composition it has always been. (#1310) - **Copilot live quota works for GitHub Enterprise Cloud enterprises on a `*.ghe.com` host.** Both readers hardcoded `https://api.github.com/copilot_internal/user` and threw away the host their credential came from, so a data-residency enterprise signed in on `.ghe.com` could only ever report `available: false` with "Temporarily unavailable". A discovered credential now carries its host — `hosts.json` is keyed by host and newer `apps.json` files key by `:` — and the request follows it: `api.github.com` for `github.com` and for any rung that carries no host of its own (an app-name `apps.json` key, `COPILOT_GITHUB_TOKEN` / `GH_TOKEN` / `GITHUB_TOKEN`, `gh auth token`, a pasted token), and `https://api..ghe.com/copilot_internal/user` for an enterprise host. The token and the host always come from the same entry, with `github.com` preferred when several hosts are signed in and otherwise the first `.ghe.com` tenant in sorted order; a host neither rule can address, such as a self-hosted GitHub Enterprise Server install, fails with a message naming that host instead of sending the credential to dotcom, and unreachable-host and HTTP failures name the host that was tried. The macOS Settings connection row now says which host answered. (#1286) ## 0.9.24 - 2026-09-04 diff --git a/mac/Sources/CodeBurnMenubar/AppStore.swift b/mac/Sources/CodeBurnMenubar/AppStore.swift index 8ac119d5..7c769c6b 100644 --- a/mac/Sources/CodeBurnMenubar/AppStore.swift +++ b/mac/Sources/CodeBurnMenubar/AppStore.swift @@ -2047,27 +2047,24 @@ final class AppStore { return todayPayload?.current } - /// Connected providers that report a headline quota window, as plain values. - /// Bounded on purpose: the six adapters with a native quota path, plus the + /// Providers that report a quota window, as plain values. Bounded on + /// purpose: the six adapters with a native quota path, plus the /// CodeBurn-owned adapters whose summary has already been fetched. Nothing /// here starts a fetch, so the menu-bar title stays a pure read. + /// + /// Which window each provider contributes, and which connection states still + /// count, are `MenubarQuotaRowSelection`'s business — it takes the worst + /// window, the same one the flame tints by, and keeps a backing-off provider + /// on its last-known data the way the Capacity Dock does. var menubarQuotaCandidates: [MenubarQuotaCandidate] { var candidates: [MenubarQuotaCandidate] = [] var seen: Set = [] func append(label: String, summary: QuotaSummary?) { guard let summary, - summary.connection == .connected || summary.connection == .stale, - let window = summary.headlineWindow, - window.percent.isFinite, + let candidate = MenubarQuotaRowSelection.candidate(label: label, summary: summary), seen.insert(label).inserted else { return } - candidates.append( - MenubarQuotaCandidate( - label: label, - percentUsed: window.percent, - resetsAt: window.resetsAt - ) - ) + candidates.append(candidate) } for provider in CapacityDockPreferences.supportedProviders { diff --git a/mac/Sources/CodeBurnMenubar/CodeBurnApp.swift b/mac/Sources/CodeBurnMenubar/CodeBurnApp.swift index b21c1857..b8244e6b 100644 --- a/mac/Sources/CodeBurnMenubar/CodeBurnApp.swift +++ b/mac/Sources/CodeBurnMenubar/CodeBurnApp.swift @@ -1334,15 +1334,26 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSPopoverDelegate, NSM // nil whenever the setting is off or the chosen metric has no data, in // which case the title falls back to the single-row composition. - let secondRow = MenubarRowFormatter.secondRow( - settings: store.menubarRowSettings, - snapshot: store.menubarRowSnapshot - ) + // `menubarRowSnapshot` walks every provider's quota summary and reads + // the today block, so it is only built once the setting is on: with the + // row off a refresh costs no more than the bool it already reads. + let rowSettings = store.menubarRowSettings + let secondRow = rowSettings.isSecondRowEnabled + ? MenubarRowFormatter.secondRow(settings: rowSettings, snapshot: store.menubarRowSnapshot) + : nil applyTitleLineMode(to: button, multiline: secondRow != nil) - button.attributedTitle = composeStatusTitle( + let title = composeStatusTitle( style: secondRow == nil ? .singleRow : .twoRow, secondRow: secondRow ) + button.attributedTitle = title + // The two-line title is one string with a literal newline in it, which + // VoiceOver reads as a single run-on phrase. Spell it out instead. The + // single-row state sets nil, so turning the row off restores exactly the + // label AppKit derives from the title on its own. + button.setAccessibilityLabel( + secondRow == nil ? nil : MenubarRowFormatter.accessibilityLabel(title: title.string) + ) let menubarPeriod = store.menubarPeriod if let shortfall = store.menubarBadgeDeviceShortfall { diff --git a/mac/Sources/CodeBurnMenubar/MenubarSecondRow.swift b/mac/Sources/CodeBurnMenubar/MenubarSecondRow.swift index 37930396..57c734a8 100644 --- a/mac/Sources/CodeBurnMenubar/MenubarSecondRow.swift +++ b/mac/Sources/CodeBurnMenubar/MenubarSecondRow.swift @@ -89,9 +89,8 @@ struct MenubarQuotaCandidate: Equatable, Sendable { enum MenubarQuotaRowSelection { /// The "primary" connected provider for the second row: the one nearest its - /// limit, which is the same provider the menu-bar flame already tints for. - /// Ties break on label so the row does not flip between equal providers - /// from one refresh to the next. + /// limit. Ties break on label so the row does not flip between equal + /// providers from one refresh to the next. static func primary(from candidates: [MenubarQuotaCandidate]) -> MenubarQuotaCandidate? { candidates .sorted { lhs, rhs in @@ -100,6 +99,56 @@ enum MenubarQuotaRowSelection { } .first } + + /// One provider reduced to its row candidate, or nil when it has nothing the + /// row may report. + /// + /// The window is the provider's *worst* one, not `headlineWindow`. The + /// headline window is a billing horizon — weekly, else monthly, and only + /// then the busiest window — which is the right number for the Capacity Dock + /// rail but the wrong one here: it discards a Cursor API window sitting at + /// 100% in favour of a monthly window at 9.5%, so the row names a provider + /// that is nowhere near its limit. The worst window is also exactly what the + /// menu-bar flame tints by (`AppStore.aggregateQuotaStatus` takes the max + /// across every window a provider reports, per-model rows included), so the + /// two surfaces now agree about which provider is in trouble. + static func candidate(label: String, summary: QuotaSummary) -> MenubarQuotaCandidate? { + guard feedsRow(summary.connection), let window = worstWindow(summary) else { return nil } + return MenubarQuotaCandidate( + label: label, + percentUsed: window.percent, + resetsAt: window.resetsAt + ) + } + + /// Connection states whose last-known data still feeds the row. A provider + /// backing off (`transientFailure`) keeps its data in the Capacity Dock, + /// dimmed, so dropping it here made the row — and with it the status item's + /// width — flicker away for the length of a backoff. Only states with + /// nothing to show are excluded. + static func feedsRow(_ connection: QuotaSummary.Connection) -> Bool { + switch connection { + case .connected, .stale, .transientFailure: true + case .disconnected, .loading, .terminalFailure: false + } + } + + /// The window nearest exhaustion across everything the provider reports, + /// `primary` included. Ties break on label so the countdown does not swap + /// between two equally used windows from one refresh to the next. + static func worstWindow(_ summary: QuotaSummary) -> QuotaSummary.Window? { + var windows = summary.details + if let primary = summary.primary, !windows.contains(primary) { + windows.append(primary) + } + return windows + .filter { $0.percent.isFinite } + .sorted { lhs, rhs in + if lhs.percent != rhs.percent { return lhs.percent > rhs.percent } + return lhs.label < rhs.label + } + .first + } } /// Everything the second row can read, captured as plain values. A nil field @@ -155,35 +204,94 @@ enum MenubarRowFormatter { now: Date = Date() ) -> String? { guard settings.isSecondRowEnabled else { return nil } + let row: String? switch settings.secondRowMetric { case .quotaRemaining: - return quotaRow(snapshot.quota, now: now) + row = quotaRow(snapshot.quota, now: now) case .todayCost: guard let cost = snapshot.todayCost, cost.isFinite else { return nil } let converted = cost * snapshot.currencyRate - return String(format: "\(snapshot.currencySymbol)%.2f today", converted) + row = String(format: "\(snapshot.currencySymbol)%.2f today", converted) case .todayTokens: guard let tokens = snapshot.todayTotalTokens else { return nil } - return "\(compactTokens(Double(tokens))) tok today" + row = "\(compactTokens(Double(tokens))) tok today" case .activeSessions: guard let count = snapshot.activeSessionCount else { return nil } // Live sessions are identity-derived, so the exact phrasing applies. - return SessionCountLabel.compact(sessions: count, basis: "identity") + row = SessionCountLabel.compact(sessions: count, basis: "identity") } + // Last line of defence: whatever a metric produces, the row never gets + // to set the status item's width on its own. + return row.map { clampToRowBudget($0) } } /// "Claude 42% left · 3h 12m". The countdown is dropped when the provider /// reports no reset instant; the whole row is dropped when there is no /// usable percentage. + /// + /// The percentage and the countdown are bounded by their own shapes; the + /// provider label is not ("GitHub Copilot"), so it is the part that gives + /// way when the row would exceed `secondRowCharacterBudget`. Shortening the + /// name keeps both figures — the two things the row exists to say — rather + /// than clipping the countdown off the end. private static func quotaRow(_ quota: MenubarQuotaCandidate?, now: Date) -> String? { guard let quota, quota.percentUsed.isFinite else { return nil } let remaining = min(max(1 - quota.percentUsed, 0), 1) let percent = Int((remaining * 100).rounded()) - var row = quota.label.isEmpty ? "\(percent)% left" : "\(quota.label) \(percent)% left" + var figures = "\(percent)% left" if let countdown = resetCountdown(quota.resetsAt, now: now) { - row += " · \(countdown)" + figures += " · \(countdown)" } - return row + guard !quota.label.isEmpty else { return figures } + let label = abbreviate(quota.label, to: secondRowCharacterBudget - figures.count - 1) + return label.isEmpty ? figures : "\(label) \(figures)" + } + + /// How wide the second row may get, in characters. + /// + /// The status item is variable width, so the widest line wins; an unbounded + /// second row ("GitHub Copilot 12% left · 6d 3h") made the item more than + /// twice as wide as the figure above it. The single row bounds itself by + /// abbreviating (`Period.menubarSuffix(compact:)`, `asCompactCurrencyWhole`), + /// and at its widest — tokens, a period suffix and a device-shortfall marker + /// — it runs to roughly 24 characters at 13pt. The second row renders at 9pt + /// (`MenubarRowTypography.twoRowFontSize`), so the same character count there + /// is about two thirds of that width: turning the row on cannot push the item + /// past what the first row alone could already occupy. + static let secondRowCharacterBudget = 24 + + /// Shortens `text` to `limit` characters, marking the cut with an ellipsis. + /// Returns "" when there is no room for even one character plus the mark, so + /// the caller can drop the part entirely rather than render a bare "…". + static func abbreviate(_ text: String, to limit: Int) -> String { + guard text.count > limit else { return text } + guard limit >= 2 else { return "" } + var kept = String(text.prefix(limit - 1)) + while kept.last == " " { kept.removeLast() } + return kept.isEmpty ? "" : kept + "…" + } + + /// Applies `secondRowCharacterBudget` to an already-composed row. + static func clampToRowBudget(_ row: String) -> String { + abbreviate(row, to: secondRowCharacterBudget) + } + + /// What VoiceOver reads for the status item once the second row is on. + /// + /// The rendered title is one attributed string carrying a literal newline + /// between the rows, and the row separator is a middle dot; read verbatim + /// that is neither a sentence nor a pause. This spells the same information + /// as one comma-separated phrase, from the title as composed, so the label + /// cannot drift from what is on screen. + static func accessibilityLabel(title: String) -> String { + let parts = title + // U+FFFC is the inline flame attachment's placeholder character. + .replacingOccurrences(of: "\u{FFFC}", with: " ") + .split(whereSeparator: \.isNewline) + .flatMap { $0.split(separator: "·") } + .map { $0.trimmingCharacters(in: .whitespaces) } + .filter { !$0.isEmpty } + return (["CodeBurn"] + parts).joined(separator: ", ") } /// Same shape as the popover's quota rows (`QuotaSummary.Window.resetsInLabel`), diff --git a/mac/Tests/CodeBurnMenubarTests/MenubarSecondRowTests.swift b/mac/Tests/CodeBurnMenubarTests/MenubarSecondRowTests.swift index 006043ee..8bf67a68 100644 --- a/mac/Tests/CodeBurnMenubarTests/MenubarSecondRowTests.swift +++ b/mac/Tests/CodeBurnMenubarTests/MenubarSecondRowTests.swift @@ -245,6 +245,206 @@ struct MenubarSecondRowTests { #expect(MenubarQuotaRowSelection.primary(from: candidates.reversed())?.label == "Claude") } + // MARK: - Which window a provider contributes + + private func summary( + _ filter: ProviderFilter, + connection: QuotaSummary.Connection = .connected, + primary: QuotaSummary.Window? = nil, + details: [QuotaSummary.Window] + ) -> QuotaSummary { + QuotaSummary( + providerFilter: filter, + connection: connection, + primary: primary, + details: details, + planLabel: nil, + footerLines: [] + ) + } + + @Test("the row reports each provider's worst window, not its billing headline") + func candidateUsesWorstWindow() { + // The shape reported from a real machine in #1310: Cursor's API window is + // exhausted and Claude's 5-hour window is the busier of its two, while the + // headline rule answers Monthly 9.5% and Weekly 5% and so reports a + // machine that is nowhere near a limit. + let cursor = summary(.cursor, details: [ + QuotaSummary.Window(label: "API", percent: 1.0, resetsAt: nil), + QuotaSummary.Window(label: "Monthly", percent: 0.095, resetsAt: nil), + ]) + let weekly = QuotaSummary.Window(label: "Weekly", percent: 0.05, resetsAt: nil) + let claude = summary(.claude, primary: weekly, details: [ + QuotaSummary.Window(label: "Current session (5h)", percent: 0.18, resetsAt: nil), + weekly, + ]) + // What the headline rule answers, and what the row must no longer use. + #expect(cursor.headlineWindow?.percent == 0.095) + #expect(claude.headlineWindow?.percent == 0.05) + + let cursorCandidate = MenubarQuotaRowSelection.candidate(label: "Cursor", summary: cursor) + let claudeCandidate = MenubarQuotaRowSelection.candidate(label: "Claude", summary: claude) + #expect(cursorCandidate?.percentUsed == 1.0) + #expect(claudeCandidate?.percentUsed == 0.18) + + let chosen = MenubarQuotaRowSelection.primary( + from: [claudeCandidate, cursorCandidate].compactMap { $0 } + ) + #expect(chosen?.label == "Cursor") + #expect( + MenubarRowFormatter.secondRow( + settings: settings(true, .quotaRemaining), + snapshot: snapshot(quota: chosen), + now: now + ) == "Cursor 0% left" + ) + } + + @Test("a per-model window counts, the same way the flame counts it") + func candidateCountsPerModelWindows() { + let claude = summary(.claude, details: [ + QuotaSummary.Window(label: "Weekly", percent: 0.05, resetsAt: nil), + QuotaSummary.Window(label: "Weekly · Opus", percent: 0.87, resetsAt: nil), + ]) + #expect(MenubarQuotaRowSelection.candidate(label: "Claude", summary: claude)?.percentUsed == 0.87) + #expect(MenubarQuotaRowSelection.worstWindow(claude)?.label == "Weekly · Opus") + } + + @Test("the worst window carries its own reset instant") + func candidateKeepsWorstWindowReset() { + let reset = now.addingTimeInterval(5 * 3600) + let codex = summary(.codex, details: [ + QuotaSummary.Window(label: "Weekly", percent: 0.2, resetsAt: now.addingTimeInterval(86_400)), + QuotaSummary.Window(label: "5h", percent: 0.94, resetsAt: reset), + ]) + let candidate = MenubarQuotaRowSelection.candidate(label: "Codex", summary: codex) + #expect(candidate?.resetsAt == reset) + #expect( + MenubarRowFormatter.secondRow( + settings: settings(true, .quotaRemaining), + snapshot: snapshot(quota: candidate), + now: now + ) == "Codex 6% left · 5h 0m" + ) + } + + @Test("equally used windows break on label so the countdown does not swap") + func worstWindowTieBreak() { + let a = QuotaSummary.Window(label: "Alpha", percent: 0.5, resetsAt: nil) + let b = QuotaSummary.Window(label: "Beta", percent: 0.5, resetsAt: nil) + #expect(MenubarQuotaRowSelection.worstWindow(summary(.claude, details: [a, b]))?.label == "Alpha") + #expect(MenubarQuotaRowSelection.worstWindow(summary(.claude, details: [b, a]))?.label == "Alpha") + } + + @Test("a provider with no usable window contributes nothing") + func candidateWithoutWindows() { + #expect(MenubarQuotaRowSelection.candidate(label: "Claude", summary: summary(.claude, details: [])) == nil) + let broken = summary(.claude, details: [QuotaSummary.Window(label: "Weekly", percent: .nan, resetsAt: nil)]) + #expect(MenubarQuotaRowSelection.candidate(label: "Claude", summary: broken) == nil) + } + + @Test("a provider backing off keeps its last-known window, as the dock does") + func transientFailureStaysACandidate() { + let windows = [QuotaSummary.Window(label: "5h", percent: 0.62, resetsAt: nil)] + let feeding: [QuotaSummary.Connection] = [.connected, .stale, .transientFailure] + for connection in feeding { + #expect(MenubarQuotaRowSelection.feedsRow(connection)) + let quota = summary(.claude, connection: connection, details: windows) + #expect(MenubarQuotaRowSelection.candidate(label: "Claude", summary: quota)?.percentUsed == 0.62) + } + let silent: [QuotaSummary.Connection] = [.disconnected, .loading, .terminalFailure(reason: "expired")] + for connection in silent { + #expect(!MenubarQuotaRowSelection.feedsRow(connection)) + let quota = summary(.claude, connection: connection, details: windows) + #expect(MenubarQuotaRowSelection.candidate(label: "Claude", summary: quota) == nil) + } + } + + // MARK: - Width cap + + @Test("a long provider name is shortened instead of widening the status item") + func secondRowIsCapped() { + let row = MenubarRowFormatter.secondRow( + settings: settings(true, .quotaRemaining), + snapshot: snapshot( + quota: MenubarQuotaCandidate( + label: "GitHub Copilot", + percentUsed: 0.88, + resetsAt: now.addingTimeInterval(6 * 86_400 + 3 * 3600) + ) + ), + now: now + ) + // Both figures survive; the name is what gives way. + #expect(row == "GitHub… 12% left · 6d 3h") + #expect(row?.count == MenubarRowFormatter.secondRowCharacterBudget) + } + + @Test("no metric can produce a row past the budget") + func everyMetricRespectsTheBudget() { + let wide = snapshot( + quota: MenubarQuotaCandidate( + label: "Some Very Long Provider Name", + percentUsed: 0.015, + resetsAt: now.addingTimeInterval(3 * 86_400 + 14 * 3600) + ), + todayCost: 123_456.78, + todayTotalTokens: 987_654_321, + activeSessionCount: 4096, + currencySymbol: "CHF", + currencyRate: 1 + ) + for metric in MenubarSecondRowMetric.allCases { + let row = MenubarRowFormatter.secondRow(settings: settings(true, metric), snapshot: wide, now: now) + #expect(row != nil) + #expect((row?.count ?? 0) <= MenubarRowFormatter.secondRowCharacterBudget) + } + } + + @Test("rows inside the budget are left exactly as they were") + func shortRowsAreUntouched() { + #expect(MenubarRowFormatter.abbreviate("Claude", to: 24) == "Claude") + #expect(MenubarRowFormatter.abbreviate("Claude", to: 6) == "Claude") + #expect(MenubarRowFormatter.abbreviate("Claude", to: 5) == "Clau…") + // A cut that lands on a space drops it rather than leaving "GitHub …". + #expect(MenubarRowFormatter.abbreviate("GitHub Copilot", to: 8) == "GitHub…") + // No room for anything meaningful: the caller drops the part instead. + #expect(MenubarRowFormatter.abbreviate("Claude", to: 1) == "") + #expect(MenubarRowFormatter.abbreviate("Claude", to: 0) == "") + #expect(MenubarRowFormatter.abbreviate("Claude", to: -3) == "") + #expect(MenubarRowFormatter.clampToRowBudget("12 sess") == "12 sess") + } + + @Test("an unlabelled provider keeps the full figures") + func unlabelledQuotaRow() { + #expect( + MenubarRowFormatter.secondRow( + settings: settings(true, .quotaRemaining), + snapshot: snapshot(quota: MenubarQuotaCandidate(label: "", percentUsed: 0.5, resetsAt: nil)), + now: now + ) == "50% left" + ) + } + + // MARK: - Accessibility + + @Test("the two-line title reads as one phrase, without the raw newline") + func accessibilityLabelForTwoRows() { + // The composed title as the status item holds it: the flame attachment's + // placeholder character, the badge, a newline, then the second row. + let title = "\u{FFFC} $12.34\nClaude 42% left · 3h 12m" + let label = MenubarRowFormatter.accessibilityLabel(title: title) + #expect(label == "CodeBurn, $12.34, Claude 42% left, 3h 12m") + #expect(!label.contains("\n")) + #expect(!label.contains("·")) + #expect(!label.contains("\u{FFFC}")) + } + + @Test("an icon-only badge still names the second row") + func accessibilityLabelIconOnly() { + #expect(MenubarRowFormatter.accessibilityLabel(title: "\u{FFFC}\n12 sess") == "CodeBurn, 12 sess") + } + // MARK: - Preferences @Test("settings default to off and round-trip through UserDefaults")