test(fls): e-mail account files against Swift's reader
The Swift oracle reads the 43 account files Java read (--email-files, with TopologyRuntimeEmailStorage.decodeJavaServer and decodeJavaClient). The accounts the model takes match Swift's except where Swift checks names, hosts and addresses and fails the whole file on one it rejects, or reads the format otherwise (the first client line instead of the last, exactly nine fields, a required messages field). Every departure is named with its reason; Java's reading is right in each, none is a Java error Swift fixes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -38,6 +38,10 @@ Sortierung, Base64 — und die ganzen Mengen `whitespacesAndNewlines` und
|
||||
unter Linux; ihre Steuerzeichen-Tabelle hat in Ebene 14 einen Fehler, den
|
||||
der Port nicht übernimmt.
|
||||
|
||||
`--email-files server|client` liest die Kontodateien
|
||||
(`packages/fls/test/email-*.cases.txt`) mit Swifts
|
||||
`TopologyRuntimeEmailStorage.decodeJavaServer`/`decodeJavaClient`.
|
||||
|
||||
`--dns-hosts` liest dieselben `/dns/hosts`-Fälle wie das Java-Orakel
|
||||
(`packages/fls/test/dns-hosts.cases.txt`) mit Swifts
|
||||
`TopologyDNSHostsFileCodec`; unter `state` stehen die DNS-Einträge jedes
|
||||
|
||||
@@ -666,7 +666,7 @@ func dnsRecordJSON(_ record: TopologyDNSResourceRecord) -> [Any] {
|
||||
[record.name.rawValue, record.type.rawValue, Int(record.ttlSeconds), record.target]
|
||||
}
|
||||
|
||||
/// One case per line: a whole hosts file, ASCII with Java-style unicode
|
||||
/// One case per line: a whole file (hosts, e-mail accounts), ASCII with Java-style unicode
|
||||
/// escapes (backslash, u, four hex digits) — the file the Java oracle reads.
|
||||
func readDNSHostsCases(_ url: URL) throws -> [(line: String, text: String)] {
|
||||
let lines = try String(contentsOf: url, encoding: .ascii).components(separatedBy: "\n")
|
||||
@@ -722,6 +722,37 @@ if CommandLine.arguments.count == 4, CommandLine.arguments[1] == "--dns-hosts" {
|
||||
exit(0)
|
||||
}
|
||||
|
||||
if CommandLine.arguments.count == 5, CommandLine.arguments[1] == "--email-files" {
|
||||
let server = CommandLine.arguments[2] == "server"
|
||||
let cases = try readDNSHostsCases(URL(fileURLWithPath: CommandLine.arguments[3]))
|
||||
let output: [[Any]] = cases.map { item in
|
||||
do {
|
||||
if server {
|
||||
let configuration = try TopologyRuntimeEmailStorage.decodeJavaServer(item.text)
|
||||
return [item.line, configuration.accounts.map { account in
|
||||
[
|
||||
"username": account.username, "password": account.password, "name": account.name,
|
||||
"mailbox": account.mailbox.map(emailMessageJSON),
|
||||
] as JSON
|
||||
}]
|
||||
}
|
||||
let client = try TopologyRuntimeEmailStorage.decodeJavaClient(item.text)
|
||||
return [item.line, [
|
||||
"pop3Host": client.pop3Host, "pop3Port": client.pop3Port,
|
||||
"smtpHost": client.smtpHost, "smtpPort": client.smtpPort,
|
||||
"username": client.username, "password": client.password,
|
||||
"name": client.name, "email": client.email,
|
||||
] as JSON]
|
||||
} catch {
|
||||
return [item.line, "!\(error)"]
|
||||
}
|
||||
}
|
||||
let data = try JSONSerialization.data(withJSONObject: output, options: [.prettyPrinted, .sortedKeys])
|
||||
try (data + Data("\n".utf8)).write(to: URL(fileURLWithPath: CommandLine.arguments[4]))
|
||||
print("email \(CommandLine.arguments[2]) files: \(cases.count) cases")
|
||||
exit(0)
|
||||
}
|
||||
|
||||
if CommandLine.arguments.count == 4, CommandLine.arguments[1] == "--corpus" {
|
||||
let summary = try readCorpus(root: URL(fileURLWithPath: CommandLine.arguments[2]))
|
||||
let data = try JSONSerialization.data(withJSONObject: summary, options: [.prettyPrinted, .sortedKeys])
|
||||
|
||||
@@ -15,4 +15,6 @@ docker run --rm -v "$root:/work" -w /work/tools/swift-oracle swift:6.1-jammy sh
|
||||
.build/debug/Oracle --vfs /work/packages/core/test/vfs.cases.json /work/packages/core/test/vfs.swift.json
|
||||
.build/debug/Oracle --strings /work/packages/core/test/strings.cases.json /work/packages/core/test/strings.swift.json
|
||||
.build/debug/Oracle --path-folding /work/packages/fls/test/path-folding.cases.json /work/packages/fls/test/path-folding.swift.json
|
||||
.build/debug/Oracle --dns-hosts /work/packages/fls/test/dns-hosts.cases.txt /work/packages/fls/test/dns-hosts.swift.json'
|
||||
.build/debug/Oracle --dns-hosts /work/packages/fls/test/dns-hosts.cases.txt /work/packages/fls/test/dns-hosts.swift.json
|
||||
.build/debug/Oracle --email-files server /work/packages/fls/test/email-server.cases.txt /work/packages/fls/test/email-server.swift.json
|
||||
.build/debug/Oracle --email-files client /work/packages/fls/test/email-client.cases.txt /work/packages/fls/test/email-client.swift.json'
|
||||
|
||||
Reference in New Issue
Block a user