Repository Public License
1// ORIX Convert — Packages/ConvertKit/Tests/ConvertKitTests/ChainFixtureTests.swift2// Description: The sweep's chained plans: fixtures that can satisfy a chain (SVG with text, NetCDF grid with lat / lon),3// the classification of content-dependent refusals, and the engine notes read by the matrix.4// Author: Simon-Pierre Boucher — contact@spboucher.ai5import Foundation6import Testing7import ConvertCore8import ConvertKit9@testable import ConvertCLI1011@Suite struct ChainFixtureTests {12 @Test func contentRefusalsAreRecognisedByKindAndSentence() {13 let coordinates = "A setting is not valid. No coordinate columns were recognised in the CSV file. Columns: time, x, temperature."14 #expect(ContentRefusal.reason(kind: "invalidOption", message: coordinates) == "no coordinate columns")15 #expect(ContentRefusal.reason(kind: "internalError", message: "This PDF has no text layer (it looks like a scanned document), so there is no text to rebuild.") == "no text layer")16 #expect(ContentRefusal.reason(kind: "internalError", message: "No text was found in this PDF, even with text recognition.") == "no text")17 // The same sentence under another kind, or any other error, is a real failure.18 #expect(ContentRefusal.reason(kind: "toolFailed", message: coordinates) == nil)19 #expect(ContentRefusal.reason(kind: "invalidOption", message: "A setting is not valid. The quality must be between 1 and 100.") == nil)20 #expect(ContentRefusal.reason(kind: "outputInvalid", message: "The converted file failed verification.") == nil)21 #expect(ContentRefusal.reason(kind: nil, message: coordinates) == nil)22 #expect(ContentRefusal.reason(kind: "invalidOption", message: nil) == nil)23 }2425 @Test func refusedChainsAreCountedApartFromFailures() {26 var totals = SweepReport.Totals()27 func result(_ status: String) -> SweepResult {28 SweepResult(id: "chain:a>b>c", kind: "chain", source: "a", destination: "c", operation: nil, engines: [], status: status, seconds: nil, error: nil,29 errorKind: nil, failedCheck: nil, detectedAs: nil, explicitSourceFormat: false, fixtureOrigin: nil, fixtureVariant: nil,30 primaryFixtureError: nil, primaryFixtureOrigin: nil, primaryErrorKind: nil, variantsTried: nil, crashedWith: nil, options: [:], checks: 0,31 warnings: [], outputs: 0, outputBytes: nil, note: nil, refusalReason: nil)32 }33 for status in ["pass", "refused", "refused", "fail"] { Sweep.add(result(status), to: &totals) }34 #expect(totals.total == 4 && totals.pass == 1 && totals.refusedContent == 2 && totals.fail == 1 && totals.cancelled == 0)35 }3637 @Test func theGridNetCDFChainsToAGeospatialFormat() async throws {38 let scratch = Scratch()39 let grid = scratch.file("grid.nc")40 try Seeds.netcdfClassic(grid: true).write(to: grid)41 let table = try await convert([grid.path, "--to", "csv", "--output-dir", scratch.file("csv").path], scratch: scratch)42 #expect(table.code == .success, "\(table.report.jobs.first?.error ?? "")")43 let csv = try #require(try FileManager.default.contentsOfDirectory(at: scratch.file("csv"), includingPropertiesForKeys: nil).first)44 let header = try String(contentsOf: csv, encoding: .utf8).split(separator: "\n").first.map(String.init) ?? ""45 #expect(header.contains("lat") && header.contains("lon") && header.contains("temperature"), "\(header)")46 // NetCDF → GeoJSON has no direct path: scientific engine to CSV, then the geo engine.47 let chained = try await convert([grid.path, "--to", "geojson", "--output-dir", scratch.file("geo").path], scratch: scratch)48 #expect(chained.code == .success, "\(chained.report.jobs.first?.error ?? "")")49 #expect(chained.report.jobs.first?.chained == true)50 let geo = try #require(try FileManager.default.contentsOfDirectory(at: scratch.file("geo"), includingPropertiesForKeys: nil).first)51 let object = try #require(try JSONSerialization.jsonObject(with: Data(contentsOf: geo)) as? [String: Any])52 #expect((object["features"] as? [Any])?.count == 12)53 // The plain seed has no coordinate columns: the same chain is refused, and the refusal is recognised.54 let plain = scratch.file("plain.nc")55 try Seeds.netcdfClassic().write(to: plain)56 let refused = try await convert([plain.path, "--to", "geojson", "--output-dir", scratch.file("geo2").path], scratch: scratch)57 #expect(refused.code != .success)58 let job = try #require(refused.report.jobs.first)59 #expect(ContentRefusal.reason(kind: job.errorKind, message: job.error) == "no coordinate columns", "\(job.errorKind ?? "") \(job.error ?? "")")60 }6162 @Test func theSVGWithTextChainsToAWordDocument() async throws {63 let scratch = Scratch()64 let drawing = try scratch.text("text.svg", Seeds.svgWithText)65 let chained = try await convert([drawing.path, "--to", "markdown", "--output-dir", scratch.file("md").path], scratch: scratch)66 #expect(chained.code == .success, "\(chained.report.jobs.first?.error ?? "")")67 let file = try #require(try FileManager.default.contentsOfDirectory(at: scratch.file("md"), includingPropertiesForKeys: nil).first)68 #expect(try String(contentsOf: file, encoding: .utf8).contains("ORIX Convert fixture"))69 let docx = try await convert([drawing.path, "--to", "docx", "--output-dir", scratch.file("docx").path], scratch: scratch)70 #expect(docx.code == .success, "\(docx.report.jobs.first?.error ?? "")")71 }7273 @Test func notesNameTestsInOperationCellsSourceListsAndSentences() {74 var notes = EngineNotes()75 let text = """76 ## Paths7778 Every ordered pair. Test for all of them: `PathTests.convertsCities(_:)` (30 cases).7980 | Source | Destination | Operation | Tests |81 |---|---|---|---|82 | png, jpeg, heic | pdf | — (multiple sources) | `ImagesIntoPDF/everySourceFormat` |83 | pdf | pdf | `pdf.merge` (multiple sources) | `PageOperations/merge` |84 | netcdf | netcdf | `netcdf.reformat` (Change NetCDF Variant) | `classicWriter` |85 | svg | png | – | `svgToBitmaps` |8687 ## KMZ as a source (2026-11-21)8889 Read through the bounded ZIP reader. Test: `KMZSourceTests`.90 """91 notes.parse(text, package: "EngineX", engines: ["x"])92 func path(_ s: FormatID, _ d: FormatID, _ op: String? = nil) -> ConversionPath { ConversionPath(s, d, engine: "x", operation: op, fidelity: .lossy) }93 #expect(notes.test(package: "EngineX", path: path(.jpeg, .pdf)) == "ImagesIntoPDF/everySourceFormat")94 #expect(notes.test(package: "EngineX", path: path(.heic, .pdf)) == "ImagesIntoPDF/everySourceFormat")95 #expect(notes.test(package: "EngineX", path: path(.pdf, .pdf, "pdf.merge")) == "PageOperations/merge")96 #expect(notes.test(package: "EngineX", path: path(.netcdf, .netcdf, "netcdf.reformat")) == "classicWriter")97 #expect(notes.test(package: "EngineX", path: path(.svg, .png)) == "svgToBitmaps")98 #expect(notes.test(package: "EngineX", path: path(.kmz, .geojson)) == "KMZSourceTests")99 #expect(notes.test(package: "EngineX", path: path(.geojson, .kml)) == "PathTests.convertsCities(_:)")100 // The sentence covers plain conversions only.101 #expect(notes.test(package: "EngineX", path: path(.geojson, .geojson, "geo.reproject")) == nil)102 #expect(notes.test(package: "EngineY", path: path(.geojson, .kml)) == nil)103 }104}105