Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Generated by Scripts/regenerate-codex-parser-hash.sh. Do not edit by hand.

enum CodexParserHash {
static let value = "8050a4faf4fddb96"
static let value = "6293f505c4cbbce8"
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,14 @@ public struct CostUsageCustomPricing: Sendable, Equatable {
if keys.contains(where: { ProcessInfo.processInfo.environment[$0] != nil }) {
return true
}
#if os(macOS)
return Bundle.allBundles.contains { $0.bundlePath.hasSuffix(".xctest") }
#else
// Bundle.allBundles crashes on Linux (swift-corelibs-foundation). SwiftPM
// builds test executables with a `.xctest` suffix, so detect the test
// process from the main executable instead of enumerating bundles.
return Bundle.main.executableURL?.path.hasSuffix(".xctest") ?? false
#endif
}

public static func parse(_ data: Data) -> CostUsageCustomPricing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ public enum OpenCodexUsageLog {
if NSClassFromString("XCTestCase") != nil {
return true
}
#if os(macOS)
return Bundle.allBundles.contains { $0.bundlePath.hasSuffix(".xctest") }
#else
// Bundle.allBundles crashes on Linux (swift-corelibs-foundation). SwiftPM
// builds test executables with a `.xctest` suffix, so detect the test
// process from the main executable instead of enumerating bundles.
return Bundle.main.executableURL?.path.hasSuffix(".xctest") ?? false
#endif
}
}
23 changes: 23 additions & 0 deletions TestsLinux/PlatformGatingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,29 @@ struct PlatformGatingTests {
#expect(Bool(true))
#endif
}

@Test
func `custom pricing test detector is safe on Linux without test markers`() {
#if os(Linux)
let pricing = CostUsageCustomPricing.load(environment: [:])
#expect(pricing.fingerprint == "none" || !pricing.fingerprint.isEmpty)
#else
#expect(Bool(true))
#endif
}

@Test
func `OpenCodex usage log URL resolution is safe on Linux without test markers`() {
#if os(Linux)
// Under test runner, ProcessInfo has test markers, so isRunningTests returns true safely and returns nil without crashing
let logURL = OpenCodexUsageLog.usageLogURL(environment: [:])
#expect(logURL == nil)
let overriddenURL = OpenCodexUsageLog.usageLogURL(environment: ["OPENCODEX_HOME": "/tmp/test"])
#expect(overriddenURL?.path == "/tmp/test/usage.jsonl")
#else
#expect(Bool(true))
#endif
}
private func makeClaudeAutoContext(env: [String: String] = [:]) -> ProviderFetchContext {
self.makeClaudeContext(sourceMode: .auto, env: env)
}
Expand Down