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
13 changes: 8 additions & 5 deletions Sources/CLI/main/Dependencies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ struct Dependencies: Sendable {
)
let httpCache: URLCache?
let httpDataTransport: URLSession
let documentationRepository: DefaultAppleDocumentationRepository<DefaultAppleDocumentationClient<URLSession>>

// Commands resolve the repository after logging is bootstrapped.
var documentationRepository: DefaultAppleDocumentationRepository<DefaultAppleDocumentationClient<URLSession>> {
DefaultAppleDocumentationRepository(
logger: Logger(label: "com.techprimate.apple-docs.repository"),
dependencies: DefaultAppleDocumentationClient(
logger: Logger(label: "com.techprimate.apple-docs.client"), dependencies: httpDataTransport))
}

init() {
if let cachesDirectory = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first {
Expand All @@ -39,10 +46,6 @@ struct Dependencies: Sendable {
configuration.urlCache = httpCache
}
httpDataTransport = URLSession(configuration: configuration)
documentationRepository = DefaultAppleDocumentationRepository(
logger: Logger(label: "com.techprimate.apple-docs.repository"),
dependencies: DefaultAppleDocumentationClient(
logger: Logger(label: "com.techprimate.apple-docs.client"), dependencies: httpDataTransport))
}

var documentationCache: URLCache? {
Expand Down
22 changes: 22 additions & 0 deletions Tests/CLIIntegrationTests/AppleDocsCommandIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,28 @@ struct AppleDocsCommandIntegrationTests {
#expect(!output.contains("\u{1B}"))
}

@Test("startup routes documentation logs only to verbose stderr", arguments: [false, true])
func routesDocumentationLogs(verbose: Bool) throws {
// -- Arrange --
var arguments = ["types", "view", "environmentvalues/linelimit", "--technology", "SwiftUI", "--agent"]
if verbose { arguments.append("--verbose") }
var diagnostics = ""

// -- Act --
let output = try runAppleDocs(arguments, captureStandardError: { diagnostics = $0 })

// -- Assert --
#expect(output.hasPrefix("# lineLimit\n"))
#expect(!output.contains("Fetched type documentation"))
#expect(!output.contains("Requesting documentation data"))
if verbose {
#expect(diagnostics.contains("Fetched type documentation"))
#expect(diagnostics.contains("Requesting documentation data"))
} else {
#expect(diagnostics.isEmpty)
}
}

@Test("agent JSON includes navigation without verbose diagnostics on stdout")
func rendersAgentJSON() throws {
// -- Arrange --
Expand Down
Loading