mirror of
https://github.com/Yuyi-Oak/BlueArchiveToolkit.git
synced 2026-09-18 10:54:55 +08:00
fix(tm):建立 Trusted 唯一性与 Supersede 治理
This commit is contained in:
@@ -756,14 +756,15 @@ func TestTranslationMemoryTypedContract(t *testing.T) {
|
||||
Data: map[string]any{
|
||||
"available": true,
|
||||
"path": "/var/lib/bat/translation-memory.sqlite",
|
||||
"schema_version": 1,
|
||||
"schema_version": 2,
|
||||
"summary": map[string]any{
|
||||
"schema_version": 1,
|
||||
"record_count": 3,
|
||||
"trusted_count": 1,
|
||||
"candidate_count": 1,
|
||||
"superseded_count": 1,
|
||||
"rejected_count": 0,
|
||||
"schema_version": 2,
|
||||
"record_count": 3,
|
||||
"trusted_count": 1,
|
||||
"candidate_count": 1,
|
||||
"superseded_count": 1,
|
||||
"rejected_count": 0,
|
||||
"current_trusted_count": 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -859,6 +860,50 @@ func TestTranslationMemoryTypedContract(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
case "translation.memory.conflicts":
|
||||
var params TranslationMemoryConflictsParams
|
||||
if err := json.Unmarshal(req.Params, ¶ms); err != nil {
|
||||
t.Fatalf("decode conflicts params: %v", err)
|
||||
}
|
||||
if params.TranslationMemoryPath != "/var/lib/bat/translation-memory.sqlite" ||
|
||||
params.Limit == nil || *params.Limit != limit {
|
||||
t.Fatalf("conflicts params=%#v", params)
|
||||
}
|
||||
return testResponse{
|
||||
Result: testEnvelope{
|
||||
OK: true, Status: "ok", RequestID: "req-tm-conflicts",
|
||||
Data: map[string]any{
|
||||
"available": true,
|
||||
"path": "/var/lib/bat/translation-memory.sqlite",
|
||||
"conflicts": []any{},
|
||||
},
|
||||
},
|
||||
}
|
||||
case "translation.memory.resolve_conflict":
|
||||
var params TranslationMemoryResolveConflictParams
|
||||
if err := json.Unmarshal(req.Params, ¶ms); err != nil {
|
||||
t.Fatalf("decode resolve params: %v", err)
|
||||
}
|
||||
if params.WinnerRecordID != "tm-record-1" ||
|
||||
len(params.ExpectedTrustedRecordIDs) != 2 ||
|
||||
params.ExpectedTrustedRecordIDs[1] != "tm-record-2" ||
|
||||
params.Reviewer != "reviewer" ||
|
||||
params.Reason != "selected" {
|
||||
t.Fatalf("resolve params=%#v", params)
|
||||
}
|
||||
return testResponse{
|
||||
Result: testEnvelope{
|
||||
OK: true, Status: "ok", RequestID: "req-tm-resolve",
|
||||
Data: map[string]any{
|
||||
"available": true,
|
||||
"path": "/var/lib/bat/translation-memory.sqlite",
|
||||
"entry": map[string]any{
|
||||
"record_id": "tm-record-1",
|
||||
"trust_status": "trusted",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
default:
|
||||
t.Fatalf("unexpected method %q", req.Method)
|
||||
return testResponse{}
|
||||
@@ -915,6 +960,32 @@ func TestTranslationMemoryTypedContract(t *testing.T) {
|
||||
confirmed.Entry.RecordID != "tm-record-1" {
|
||||
t.Fatalf("confirmed=%#v", confirmed)
|
||||
}
|
||||
|
||||
conflicts, err := client.TranslationMemoryConflicts(context.Background(), TranslationMemoryConflictsParams{
|
||||
TranslationMemoryPath: "/var/lib/bat/translation-memory.sqlite",
|
||||
Limit: &limit,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("TranslationMemoryConflicts error: %v", err)
|
||||
}
|
||||
if !conflicts.Available || len(conflicts.Conflicts) != 0 {
|
||||
t.Fatalf("conflicts=%#v", conflicts)
|
||||
}
|
||||
|
||||
resolved, err := client.TranslationMemoryResolveConflict(context.Background(), TranslationMemoryResolveConflictParams{
|
||||
TranslationMemoryPath: "/var/lib/bat/translation-memory.sqlite",
|
||||
WinnerRecordID: "tm-record-1",
|
||||
ExpectedTrustedRecordIDs: []string{"tm-record-1", "tm-record-2"},
|
||||
Reviewer: "reviewer",
|
||||
Reason: "selected",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("TranslationMemoryResolveConflict error: %v", err)
|
||||
}
|
||||
if !resolved.Available || resolved.Entry.RecordID != "tm-record-1" ||
|
||||
resolved.Entry.TrustStatus != TranslationMemoryStatusTrusted {
|
||||
t.Fatalf("resolved=%#v", resolved)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTranslationProofreadUsesRustMethod(t *testing.T) {
|
||||
@@ -1064,9 +1135,9 @@ func TestGlossaryTypedContract(t *testing.T) {
|
||||
Data: map[string]any{
|
||||
"available": true,
|
||||
"path": "/var/lib/bat/glossary.sqlite",
|
||||
"schema_version": 1,
|
||||
"schema_version": 2,
|
||||
"summary": map[string]any{
|
||||
"schema_version": 1,
|
||||
"schema_version": 2,
|
||||
"term_count": 2,
|
||||
"approved_count": 1,
|
||||
"draft_count": 1,
|
||||
|
||||
Reference in New Issue
Block a user