scratch_edit is now scratch_replace, and takes a regex mode and a per-entry count — omit it to require exactly one match as before, 0 for every occurrence, n for the first n. scratch_copy and scratch_move move a staged file or subtree without its bytes passing through the transcript, which is what duplicating a file before a risky change used to cost. The app-side changes are the ones the rename and the two new tools reach: ActionKind.copy in both the English and Chinese verb tables, the pull → copy → replace → push recipe in the built-in config-edit skill, and the same wording in the system prompt and the plan contract. The legacy tables are deliberately untouched: legacyToolNames and legacyMetadata describe cards written before presenter IDs were persisted, and scratch_edit belongs in both. AgentKit keeps builtin.scratch_edit registered as an alias, so a transcript from before the rename still draws its diff rather than falling back to generic fields — which aCardWrittenAsScratchEditStillFindsItsProjection now pins. AppLanguageTests no longer requires %lld results. That plural moved to AgentKit with web_search's card, which is what db8796c removed from this catalog; the test's list had been left behind and was failing. AGENTS.md said AgentKit was referenced as a local SPM package. It is a versioned remote dependency, so an uncommitted change in ../AgentKit is invisible to the app and a change spanning both sides needs a tagged release in between. Said so, because working the other way wastes a build cycle before the mistake shows. Verified: AgentKit 0.3.0 builds and passes its 112 tests, and the six suites this touches pass here. The five failures in the full run — ColorSystemTests, two ChatComposerStateTests, FileURLDropTargetTests and WindowStateTests — all reproduce on a clean worktree at HEAD and are unrelated.
118 lines
5.2 KiB
Swift
118 lines
5.2 KiB
Swift
import Foundation
|
|
import Testing
|
|
|
|
@testable import Termind
|
|
|
|
struct AppLanguageTests {
|
|
@Test
|
|
func missingAndUnknownPreferencesFollowSystem() throws {
|
|
let defaults = try makeDefaults()
|
|
#expect(AppLanguage.stored(in: defaults) == .system)
|
|
|
|
defaults.set("unsupported", forKey: SettingsKey.appLanguage)
|
|
#expect(AppLanguage.stored(in: defaults) == .system)
|
|
}
|
|
|
|
@Test
|
|
func explicitLanguagesWriteFullAppleLanguageTags() throws {
|
|
let defaults = try makeDefaults()
|
|
|
|
AppLanguage.store(.english, in: defaults)
|
|
#expect(AppLanguage.stored(in: defaults) == .english)
|
|
#expect(defaults.stringArray(forKey: "AppleLanguages") == ["en"])
|
|
|
|
AppLanguage.store(.simplifiedChineseChina, in: defaults)
|
|
#expect(AppLanguage.stored(in: defaults) == .simplifiedChineseChina)
|
|
#expect(defaults.stringArray(forKey: "AppleLanguages") == ["zh-Hans-CN"])
|
|
#expect(AppLanguage.simplifiedChineseChina.locale.identifier == "zh-Hans-CN")
|
|
}
|
|
|
|
@Test
|
|
func followSystemRemovesAppleLanguageOverride() throws {
|
|
let suiteName = "AppLanguageTests.\(UUID().uuidString)"
|
|
let defaults = try #require(UserDefaults(suiteName: suiteName))
|
|
defaults.removePersistentDomain(forName: suiteName)
|
|
defaults.set(["zh-Hans-SG"], forKey: "AppleLanguages")
|
|
|
|
AppLanguage.store(.system, in: defaults)
|
|
|
|
#expect(AppLanguage.stored(in: defaults) == .system)
|
|
#expect(defaults.persistentDomain(forName: suiteName)?["AppleLanguages"] == nil)
|
|
}
|
|
|
|
@Test
|
|
func everyCatalogEntryHasSimplifiedChinese() throws {
|
|
let repository = URL(fileURLWithPath: #filePath)
|
|
.deletingLastPathComponent().deletingLastPathComponent()
|
|
for name in ["Localizable", "InfoPlist"] {
|
|
let url = repository.appending(path: "Termind/Resources/\(name).xcstrings")
|
|
let root = try #require(
|
|
JSONSerialization.jsonObject(with: Data(contentsOf: url))
|
|
as? [String: Any]
|
|
)
|
|
let strings = try #require(root["strings"] as? [String: Any])
|
|
for (key, value) in strings {
|
|
let entry = try #require(value as? [String: Any])
|
|
if entry["shouldTranslate"] as? Bool == false { continue }
|
|
let localizations = try #require(entry["localizations"] as? [String: Any])
|
|
let chinese = try #require(localizations["zh-Hans"] as? [String: Any])
|
|
let units = localizedUnits(in: chinese)
|
|
#expect(!units.isEmpty, "No translated values: \(key)")
|
|
for unit in units {
|
|
#expect(unit["state"] as? String == "translated", "Incomplete: \(key)")
|
|
#expect(!(unit["value"] as? String ?? "").isEmpty || key.isEmpty)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@Test
|
|
func countedToolResourcesUseCatalogPluralRules() throws {
|
|
let repository = URL(fileURLWithPath: #filePath)
|
|
.deletingLastPathComponent().deletingLastPathComponent()
|
|
let url = repository.appending(path: "Termind/Resources/Localizable.xcstrings")
|
|
let root = try #require(
|
|
JSONSerialization.jsonObject(with: Data(contentsOf: url)) as? [String: Any]
|
|
)
|
|
let strings = try #require(root["strings"] as? [String: Any])
|
|
|
|
for key in [
|
|
// `%lld results` is not here: `web_search`'s card moved to AgentKit
|
|
// with the runtime, and so did the plural resource behind it.
|
|
"%lld hosts", "%lld items", "%lld questions",
|
|
"%lld tool calls", "%@ — %lld tools",
|
|
] {
|
|
let entry = try #require(strings[key] as? [String: Any])
|
|
let localizations = try #require(entry["localizations"] as? [String: Any])
|
|
let english = try #require(localizations["en"] as? [String: Any])
|
|
let chinese = try #require(localizations["zh-Hans"] as? [String: Any])
|
|
#expect(pluralForms(in: english).keys.sorted() == ["one", "other"])
|
|
#expect(pluralForms(in: chinese).keys.sorted() == ["other"])
|
|
}
|
|
}
|
|
|
|
private func localizedUnits(in value: [String: Any]) -> [[String: Any]] {
|
|
if let unit = value["stringUnit"] as? [String: Any] { return [unit] }
|
|
guard let variations = value["variations"] as? [String: Any] else { return [] }
|
|
return variations.values.flatMap { variation -> [[String: Any]] in
|
|
guard let forms = variation as? [String: Any] else { return [] }
|
|
return forms.values.flatMap { form -> [[String: Any]] in
|
|
guard let form = form as? [String: Any] else { return [] }
|
|
return localizedUnits(in: form)
|
|
}
|
|
}
|
|
}
|
|
|
|
private func pluralForms(in localization: [String: Any]) -> [String: Any] {
|
|
let variations = localization["variations"] as? [String: Any]
|
|
return variations?["plural"] as? [String: Any] ?? [:]
|
|
}
|
|
|
|
private func makeDefaults() throws -> UserDefaults {
|
|
let suiteName = "AppLanguageTests.\(UUID().uuidString)"
|
|
let defaults = try #require(UserDefaults(suiteName: suiteName))
|
|
defaults.removePersistentDomain(forName: suiteName)
|
|
return defaults
|
|
}
|
|
}
|