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:
@@ -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])
|
||||
|
||||
Reference in New Issue
Block a user