import ArgumentParser import Foundation import ParcelConfig import Synchronization import Testing @testable import prcl @Suite struct SchemaCommandTests { @Test func parsesAsALocalCommand() throws { #expect(try CLIParsing.parse(["schema"]) == .schema) #expect(CLIInvocation.schema.request == nil) } @Test func printsOnlySchemaWithoutConnecting() async throws { let output = Mutex("") try await CLIRunner.execute(.schema, socketPath: "not-an-absolute-path") { text in output.withLock { $0 += text } } #expect(output.withLock { $0 } == ConfigJSONSchema.string + "\n") } @Test func reportsOutputFailures() async { enum WriteFailure: Error { case rejected } await #expect(throws: WriteFailure.self) { try await CLIRunner.execute(.schema, socketPath: "not-an-absolute-path") { _ in throw WriteFailure.rejected } } } @Test(arguments: [["schema", "extra"], ["schema", "--json"], ["schema", "--unknown"]]) func rejectsExtraArguments(arguments: [String]) { #expect(throws: (any Error).self) { try CLIParsing.parse(arguments) } } @Test func helpListsSchema() { #expect(ParcelCLI.helpMessage().contains("schema")) #expect(SchemaCommand.helpMessage().contains("without connecting")) do { _ = try CLIParsing.parse(["schema", "--help"]) Issue.record("Expected an informational exit") } catch { #expect(ParcelCLI.exitCode(for: error).rawValue == 0) #expect(ParcelCLI.fullMessage(for: error).contains("schema")) } } }