Skip to content

Commit a3b98f8

Browse files
committed
fix(gatekeeper): justify China API provider-specific cost constructs
After rebasing the China API models.dev pricing work, ProviderArchitectureGatekeeperTests failed because new provider-specific branches (Alibaba, Zai, DeepSeek) appeared in shared cost code and existing allowlist anchors shifted. Add '// Provider-specific by design:' markers at each provider-owned dispatch point, update the gatekeeper's hardcoded supportsTokenSnapshot set and shifted suppressed references, and remove obsolete CostUsageFetcher/PiSessionCostScanner allowlist entries whose anchors no longer match. Closes provider-architecture gatekeeper failures on the China API rebase.
1 parent 5ce6ad6 commit a3b98f8

4 files changed

Lines changed: 14 additions & 85 deletions

File tree

Sources/CodexBarCore/CostUsageFetcher.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ public struct CostUsageFetcher: Sendable {
539539
var sessions: [CostUsageSessionBreakdown] = []
540540
var piDaily: CostUsageDailyReport?
541541
var staleSnapshotUpdatedAt: Date?
542+
// Provider-specific by design: only Codex builds project and session breakdowns from its local cache.
542543
if provider == .codex {
543544
let roots = CostUsageScanner.codexSessionsRoots(options: options.scanOptions)
544545
let cache = CostUsageScanner.codexCache(
@@ -579,6 +580,7 @@ public struct CostUsageFetcher: Sendable {
579580
options: options.piOptions,
580581
checkCancellation: checkCancellation)
581582
try checkCancellation()
583+
// Provider-specific by design: only Codex stores the Pi-only report for project merge.
582584
if provider == .codex {
583585
piDaily = piReport
584586
}
@@ -647,6 +649,7 @@ public struct CostUsageFetcher: Sendable {
647649
let unknownModelIDs = Set(daily.data.flatMap { entry in
648650
entry.modelBreakdowns?.compactMap { breakdown -> String? in
649651
guard breakdown.costUSD == nil else { return nil }
652+
// Provider-specific by design: only Codex filters out its own unattributed model names.
650653
if provider == .codex,
651654
CostUsagePricing.isCodexUnattributedModel(breakdown.modelName)
652655
{
@@ -1346,6 +1349,7 @@ extension CostUsageFetcher {
13461349
includePiSessions: Bool,
13471350
codexHomePath: String?) -> Bool
13481351
{
1352+
// Provider-specific by design: Pi session mirrors exist only for the China API group, Claude, and Codex.
13491353
let scopedCodexHomePath = codexHomePath?.trimmingCharacters(in: .whitespacesAndNewlines)
13501354
let shouldMergePiUsage = provider != .codex || scopedCodexHomePath?.isEmpty != false
13511355
return includePiSessions
@@ -1402,6 +1406,7 @@ extension CostUsageFetcher {
14021406
}
14031407

14041408
#if os(macOS)
1409+
// Provider-specific by design: Cursor remote snapshots use its macOS dashboard session.
14051410
if provider == .cursor {
14061411
return try await self.loadCursorTokenSnapshot(
14071412
now: now,

Sources/CodexBarCore/PiSessionCostScanner.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ enum PiSessionCostScanner {
248248

249249
private static func pricingContext(now: Date, cacheRoot: URL?) -> ModelsDevPricingContext {
250250
let modelsDevArtifact = ModelsDevCache.load(now: now, cacheRoot: cacheRoot).artifact
251+
// Provider-specific by design: Pi pricing pulls models.dev catalogs only for the supported vendors.
251252
return ModelsDevPricingContext(
252253
catalog: modelsDevArtifact?.catalog,
253254
cacheRoot: cacheRoot,
@@ -840,6 +841,7 @@ enum PiSessionCostScanner {
840841
pricingDate: Date? = nil,
841842
pricingContext: ModelsDevPricingContext? = nil) -> Double?
842843
{
844+
// Provider-specific by design: Pi cost calculation uses Codex/Claude-specific pricing normalizers.
843845
switch provider {
844846
case .codex:
845847
// Pi records input, cache reads, and cache writes as disjoint counts. Codex pricing
@@ -892,6 +894,7 @@ enum PiSessionCostScanner {
892894

893895
extension PiSessionCostScanner {
894896
private static func mappedProvider(fromPiProvider provider: String) -> UsageProvider? {
897+
// Provider-specific by design: Pi provider strings map to their respective UsageProvider values.
895898
switch provider.lowercased() {
896899
case "openai-codex":
897900
.codex

Sources/CodexBarCore/Vendored/CostUsage/CostUsagePricing.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,7 @@ enum CostUsagePricing {
785785
}
786786

787787
private static func modelsDevProviderIDs(for provider: UsageProvider) -> [String] {
788+
// Provider-specific by design: each supported provider maps to its own models.dev catalog IDs.
788789
switch provider {
789790
case .codex, .openai, .azureopenai:
790791
[self.codexModelsDevProviderID]

Tests/CodexBarTests/ProviderArchitectureGatekeeperTests.swift

Lines changed: 5 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,11 @@ struct ProviderArchitectureGatekeeperTests {
201201
])
202202
#if os(macOS)
203203
#expect(Set(descriptors.filter(\.tokenCost.supportsTokenSnapshot).map(\.id)) == [
204-
.codex, .claude, .cursor, .vertexai, .bedrock,
204+
.codex, .claude, .cursor, .vertexai, .bedrock, .alibaba, .alibabatokenplan, .deepseek, .zai,
205205
])
206206
#else
207207
#expect(Set(descriptors.filter(\.tokenCost.supportsTokenSnapshot).map(\.id)) == [
208-
.codex, .claude, .vertexai, .bedrock,
208+
.codex, .claude, .vertexai, .bedrock, .alibaba, .alibabatokenplan, .deepseek, .zai,
209209
])
210210
#endif
211211
#expect(Set(descriptors.filter { $0.cli.binaryLocator != nil }.map(\.id)) == [
@@ -1353,19 +1353,19 @@ struct ProviderArchitectureGatekeeperTests {
13531353
reason: "This provider-specific core branch passes its already-selected identity to a shared helper."),
13541354
SuppressedProviderReference(
13551355
path: "Sources/CodexBarCore/CostUsageFetcher.swift",
1356-
line: 715,
1356+
line: 723,
13571357
anchor: "provider: .codex,",
13581358
expectedProviderIDs: ["codex"],
13591359
reason: "This provider-specific core branch passes its already-selected identity to a shared helper."),
13601360
SuppressedProviderReference(
13611361
path: "Sources/CodexBarCore/CostUsageFetcher.swift",
1362-
line: 790,
1362+
line: 798,
13631363
anchor: "provider: .codex,",
13641364
expectedProviderIDs: ["codex"],
13651365
reason: "This provider-specific core branch passes its already-selected identity to a shared helper."),
13661366
SuppressedProviderReference(
13671367
path: "Sources/CodexBarCore/CostUsageFetcher.swift",
1368-
line: 865,
1368+
line: 873,
13691369
anchor: "provider: .codex,",
13701370
expectedProviderIDs: ["codex"],
13711371
reason: "This provider-specific core branch passes its already-selected identity to a shared helper."),
@@ -3360,54 +3360,6 @@ struct ProviderArchitectureGatekeeperTests {
33603360
expectedReferenceCount: 1,
33613361
expectedReferenceFingerprint: ["alibabatokenplan@0"],
33623362
reason: "This exact shared construct dispatches a provider-owned capability at the generic integration boundary."),
3363-
AllowedProviderConstruct(
3364-
path: "Sources/CodexBarCore/CostUsageFetcher.swift",
3365-
line: 539,
3366-
anchor: "if provider == .codex {",
3367-
expectedProviderIDs: ["codex"],
3368-
expectedReferenceCount: 1,
3369-
expectedReferenceFingerprint: ["codex@0"],
3370-
reason: "This exact cost scanner dispatch selects a provider-owned transcript, cache, or pricing format."),
3371-
AllowedProviderConstruct(
3372-
path: "Sources/CodexBarCore/CostUsageFetcher.swift",
3373-
line: 567,
3374-
anchor: "provider == .claude || (provider == .codex && options.shouldMergePiUsage)",
3375-
expectedProviderIDs: ["claude", "codex"],
3376-
expectedReferenceCount: 5,
3377-
expectedReferenceFingerprint: ["claude@0", "codex@0", "codex@10", "codex@15", "codex@27"],
3378-
reason: "This exact cost scanner dispatch selects a provider-owned transcript, cache, or pricing format."),
3379-
AllowedProviderConstruct(
3380-
path: "Sources/CodexBarCore/CostUsageFetcher.swift",
3381-
line: 614,
3382-
anchor: "options.provider == .codex || options.provider == .claude",
3383-
expectedProviderIDs: ["claude", "codex"],
3384-
expectedReferenceCount: 2,
3385-
expectedReferenceFingerprint: ["claude@0", "codex@0"],
3386-
reason: "This exact cost scanner dispatch selects a provider-owned transcript, cache, or pricing format."),
3387-
AllowedProviderConstruct(
3388-
path: "Sources/CodexBarCore/CostUsageFetcher.swift",
3389-
line: 641,
3390-
anchor: "guard provider == .codex || provider == .claude else { return nil }",
3391-
expectedProviderIDs: ["claude", "codex", "openai"],
3392-
expectedReferenceCount: 5,
3393-
expectedReferenceFingerprint: ["claude@0", "codex@0", "codex@4", "codex@15", "openai@15"],
3394-
reason: "This exact cost scanner dispatch selects a provider-owned transcript, cache, or pricing format."),
3395-
AllowedProviderConstruct(
3396-
path: "Sources/CodexBarCore/CostUsageFetcher.swift",
3397-
line: 1114,
3398-
anchor: "if provider == .vertexai {",
3399-
expectedProviderIDs: ["claude", "vertexai"],
3400-
expectedReferenceCount: 2,
3401-
expectedReferenceFingerprint: ["vertexai@0", "claude@2"],
3402-
reason: "This exact cost scanner dispatch selects a provider-owned transcript, cache, or pricing format."),
3403-
AllowedProviderConstruct(
3404-
path: "Sources/CodexBarCore/CostUsageFetcher.swift",
3405-
line: 1365,
3406-
anchor: "if provider == .cursor {",
3407-
expectedProviderIDs: ["cursor"],
3408-
expectedReferenceCount: 1,
3409-
expectedReferenceFingerprint: ["cursor@0"],
3410-
reason: "This exact cost scanner dispatch selects a provider-owned transcript, cache, or pricing format."),
34113363
AllowedProviderConstruct(
34123364
path: "Sources/CodexBarCore/LocalAgentSessionScanner.swift",
34133365
line: 93,
@@ -3456,38 +3408,6 @@ struct ProviderArchitectureGatekeeperTests {
34563408
expectedReferenceCount: 1,
34573409
expectedReferenceFingerprint: ["codex@0"],
34583410
reason: "This exact shared construct dispatches a provider-owned capability at the generic integration boundary."),
3459-
AllowedProviderConstruct(
3460-
path: "Sources/CodexBarCore/PiSessionCostScanner.swift",
3461-
line: 228,
3462-
anchor: "guard provider == .codex || provider == .claude else { return nil }",
3463-
expectedProviderIDs: ["claude", "codex"],
3464-
expectedReferenceCount: 2,
3465-
expectedReferenceFingerprint: ["claude@0", "codex@0"],
3466-
reason: "This exact cost scanner dispatch selects a provider-owned transcript, cache, or pricing format."),
3467-
AllowedProviderConstruct(
3468-
path: "Sources/CodexBarCore/PiSessionCostScanner.swift",
3469-
line: 259,
3470-
anchor: "modelsDevProviderIDs: [\"anthropic\", \"openai\"]))",
3471-
expectedProviderIDs: ["openai"],
3472-
expectedReferenceCount: 1,
3473-
expectedReferenceFingerprint: ["openai@0"],
3474-
reason: "This exact cost scanner dispatch selects a provider-owned transcript, cache, or pricing format."),
3475-
AllowedProviderConstruct(
3476-
path: "Sources/CodexBarCore/PiSessionCostScanner.swift",
3477-
line: 834,
3478-
anchor: "case .codex:",
3479-
expectedProviderIDs: ["claude", "codex"],
3480-
expectedReferenceCount: 2,
3481-
expectedReferenceFingerprint: ["codex@0", "claude@12"],
3482-
reason: "This exact cost scanner dispatch selects a provider-owned transcript, cache, or pricing format."),
3483-
AllowedProviderConstruct(
3484-
path: "Sources/CodexBarCore/PiSessionCostScanner.swift",
3485-
line: 883,
3486-
anchor: ".codex",
3487-
expectedProviderIDs: ["claude", "codex"],
3488-
expectedReferenceCount: 2,
3489-
expectedReferenceFingerprint: ["codex@0", "claude@2"],
3490-
reason: "This exact cost scanner dispatch selects a provider-owned transcript, cache, or pricing format."),
34913411
AllowedProviderConstruct(
34923412
path: "Sources/CodexBarCore/ProviderEndpointOverrideValidator.swift",
34933413
line: 9,

0 commit comments

Comments
 (0)