mirror of
https://github.com/Yuyi-Oak/BlueArchiveToolkit.git
synced 2026-09-18 08:14:55 +08:00
feat(api): proxy Translation Memory over bat.sock
This commit is contained in:
@@ -110,3 +110,91 @@ func TestRustContractFixturesPreserveGoMirror(t *testing.T) {
|
||||
t.Fatalf("legacy game_main_config field unexpectedly present: %s", snapshot.LegacyGameMainConfig)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTranslationMemoryRustContractMirror(t *testing.T) {
|
||||
raw := []byte(`{
|
||||
"available": true,
|
||||
"path": "${TM_PATH}",
|
||||
"source_text": "${SOURCE_TEXT}",
|
||||
"source_context": {
|
||||
"destination": "${DESTINATION}",
|
||||
"field_path": "${FIELD_PATH}"
|
||||
},
|
||||
"matches": [{
|
||||
"entry": {
|
||||
"record_id": "${RECORD_ID}",
|
||||
"source_text": "${SOURCE_TEXT}",
|
||||
"source_hash": "${SOURCE_HASH}",
|
||||
"normalized_source_text": "${NORMALIZED_SOURCE_TEXT}",
|
||||
"source_context": {
|
||||
"destination": "${DESTINATION}",
|
||||
"field_path": "${FIELD_PATH}"
|
||||
},
|
||||
"source_context_hash": "${SOURCE_CONTEXT_HASH}",
|
||||
"translated_text": "${TRANSLATED_TEXT}",
|
||||
"translation_source_kind": "provider",
|
||||
"trust_status": "trusted",
|
||||
"official_release_id": "${OFFICIAL_RELEASE_ID}",
|
||||
"source_trace": {
|
||||
"official_release_id": "${OFFICIAL_RELEASE_ID}",
|
||||
"unit_id": "${UNIT_ID}",
|
||||
"task_id": "${TASK_ID}",
|
||||
"destination": "${DESTINATION}",
|
||||
"archive_entry": "${ARCHIVE_ENTRY}",
|
||||
"serialized_file": "${SERIALIZED_FILE}",
|
||||
"path_id": 42,
|
||||
"class_id": 114,
|
||||
"field_path": "${FIELD_PATH}",
|
||||
"format": "json",
|
||||
"asset_name": "${ASSET_NAME}",
|
||||
"text_source_kind": "text_asset"
|
||||
},
|
||||
"provider": "${PROVIDER}",
|
||||
"provider_run_id": "${PROVIDER_RUN_ID}",
|
||||
"created_unix_seconds": 100,
|
||||
"updated_unix_seconds": 200,
|
||||
"trusted_unix_seconds": 200,
|
||||
"trusted_by": "${REVIEWER}",
|
||||
"trusted_reason": "${TRUST_REASON}"
|
||||
},
|
||||
"match_kind": "strong_exact",
|
||||
"can_auto_reuse": true
|
||||
}]
|
||||
}`)
|
||||
if bytes.Contains(raw, []byte("/tmp/")) {
|
||||
t.Fatal("TM mirror contains a local temporary path")
|
||||
}
|
||||
|
||||
var report backendrpc.TranslationMemoryQueryReport
|
||||
if err := json.Unmarshal(raw, &report); err != nil {
|
||||
t.Fatalf("decode TM query mirror: %v", err)
|
||||
}
|
||||
if !report.Available || report.Path != "${TM_PATH}" ||
|
||||
report.SourceText != "${SOURCE_TEXT}" ||
|
||||
report.SourceContext["field_path"] != "${FIELD_PATH}" ||
|
||||
len(report.Matches) != 1 {
|
||||
t.Fatalf("TM report=%+v", report)
|
||||
}
|
||||
match := report.Matches[0]
|
||||
if match.MatchKind != "strong_exact" || !match.CanAutoReuse ||
|
||||
match.Entry.TrustStatus != "trusted" ||
|
||||
match.Entry.TranslationSourceKind != "provider" ||
|
||||
match.Entry.SourceTrace.PathID == nil || *match.Entry.SourceTrace.PathID != 42 ||
|
||||
match.Entry.SourceTrace.ClassID == nil || *match.Entry.SourceTrace.ClassID != 114 ||
|
||||
match.Entry.TrustedBy == nil || *match.Entry.TrustedBy != "${REVIEWER}" {
|
||||
t.Fatalf("TM match=%+v", match)
|
||||
}
|
||||
|
||||
var missing backendrpc.TranslationMemorySummaryReport
|
||||
if err := json.Unmarshal([]byte(`{
|
||||
"available": false,
|
||||
"path": "${TM_PATH}",
|
||||
"reason": "database_missing"
|
||||
}`), &missing); err != nil {
|
||||
t.Fatalf("decode missing TM summary mirror: %v", err)
|
||||
}
|
||||
if missing.Available || missing.Summary != nil || missing.SchemaVersion != nil ||
|
||||
missing.Reason != "database_missing" {
|
||||
t.Fatalf("missing TM summary=%+v", missing)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user