fix(外观专利): 整批品牌查询失败的文案按真因分档(BK B95-02)

现网 16890 侧成片刷「解密失败: Malformed UTF-8 data」,交付表却一律写
「品牌库上游整体不可用」——上游其实有应答,坏的是应答体解密,
运维照「上游挂了」去查永远查不到东西。

- 新增 AppearancePatentBrandFailureText:批内 reason 全同形才分档
  (全解密→解密链路故障、全不可达→服务不可达、混形/空→通用文案),
  三条文案都保留「商标查询失败」前缀(状态列与 isBrandQueryFailed 靠它判失败)。
- AppearancePatentLlmClient 的 brandAggregateFailure 收成一行委派;
  删掉只被测试调用的 boolean buildTitleRisk 重载(String 版保留兼容)。
- 用例 +5:整批解密/整批不可达/混形与空 reason/三条文案互不相同且同前缀。
This commit is contained in:
2026-11-11 20:01:36 +08:00
parent 691b29da7e
commit a17d8edc9e
3 changed files with 176 additions and 29 deletions
@@ -106,10 +106,11 @@ class AppearancePatentLlmClientTest {
BrandCheckClient.BrandCheckBatchResult failed =
new BrandCheckClient.BrandCheckBatchResult(List.of("nike"), List.of(), List.of("nike"), "");
assertThat(client.buildTitleRisk("nike air", failed, true))
assertThat(client.buildTitleRisk("nike air", failed,
AppearancePatentBrandFailureText.UPSTREAM_UNAVAILABLE))
.isEqualTo(AppearancePatentLlmClient.BRAND_UPSTREAM_UNAVAILABLE);
// 只有它自己查失败时维持原文案:不许把个例升级成整批口径
assertThat(client.buildTitleRisk("nike air", failed, false)).isEqualTo("商标查询失败");
assertThat(client.buildTitleRisk("nike air", failed, (String) null)).isEqualTo("商标查询失败");
}
/** 整批不可用不许盖掉真实命中——这一行只要拿到过侵权结论就先给结论。 */
@@ -118,7 +119,8 @@ class AppearancePatentLlmClientTest {
BrandCheckClient.BrandCheckBatchResult hit =
new BrandCheckClient.BrandCheckBatchResult(List.of("阿凡达"), List.of("阿凡达"), List.of(), "");
assertThat(client.buildTitleRisk("阿凡达 联名", hit, true)).isEqualTo("侵权");
assertThat(client.buildTitleRisk("阿凡达 联名", hit,
AppearancePatentBrandFailureText.UPSTREAM_UNAVAILABLE)).isEqualTo("侵权");
}
/** 长文案要一路传到结论列;旧输入逐字不变由上一个用例守住。 */
@@ -129,6 +131,74 @@ class AppearancePatentLlmClientTest {
.isEqualTo(AppearancePatentLlmClient.BRAND_UPSTREAM_UNAVAILABLE);
}
/**
* 2026-11-11 现网(BACKLOG B95-02):16890 侧 `解密失败: Malformed UTF-8 data` 成片刷,
* 交付表却一律写「品牌库上游整体不可用」——上游其实有应答,坏的是应答体解密,
* 运维照着「上游挂了」去查永远查不到东西。真因必须写进标题列。
*/
@Test
void 整批解密失败要写成解密而不是上游整体不可用() throws Exception {
String decryptReason = "查询或解密失败: 解密失败: Malformed UTF-8 data";
BrandCheckClient brandCheckClient = mock(BrandCheckClient.class);
when(brandCheckClient.checkTitleTexts(anyList(), eq("Terms"), any())).thenReturn(List.of(
new BrandCheckClient.BrandCheckBatchResult(List.of("nike"), List.of(), List.of("nike"),
decryptReason),
new BrandCheckClient.BrandCheckBatchResult(List.of("puma"), List.of(), List.of("puma"),
decryptReason)));
String dataText = """
{"data":[{"row_id":"1","title":"nike","title_reason":"nike","appearance":"外观识别异常","result":""},
{"row_id":"2","title":"puma","title_reason":"puma","appearance":"外观识别异常","result":""}]}
""";
List<AppearancePatentResultRowDto> merged = clientWith(brandCheckClient)
.mergeRowsFromDataText(List.of(newRow("1"), newRow("2")), dataText);
assertThat(merged).hasSize(2);
assertThat(merged).allSatisfy(r -> {
assertThat(r.getTitleRisk()).isEqualTo(AppearancePatentBrandFailureText.DECRYPT_BROKEN);
// 前缀不能变:状态列与 isBrandQueryFailed 都靠它判失败
assertThat(r.getTitleRisk()).startsWith("商标查询失败");
assertThat(r.getTitleRisk()).doesNotContain("上游整体不可用");
});
}
/** 整批全失败且原因是「连接没建立」时,文案要指向服务不可达,而不是解密或通用文案。 */
@Test
void 整批连接不上要写成服务不可达() {
String unreachable = "品牌检测服务不可达(连接未建立,非本行数据问题)";
BrandCheckClient.BrandCheckBatchResult failed =
new BrandCheckClient.BrandCheckBatchResult(List.of("nike"), List.of(), List.of("nike"),
unreachable);
assertThat(client.buildTitleRisk("nike air", failed,
AppearancePatentBrandFailureText.classify(List.of(unreachable))))
.isEqualTo(AppearancePatentBrandFailureText.SERVICE_UNREACHABLE);
}
/**
* 判据保守:reason 混形、或有行没给 reason 时一律落回通用文案,不猜真因——
* 猜错的运维文案比笼统的更贵。
*/
@Test
void reason混形或不给原因时维持通用文案() {
assertThat(AppearancePatentBrandFailureText.classify(
List.of("查询或解密失败: 解密失败: x", "品牌检测服务不可达(连接未建立)")))
.isEqualTo(AppearancePatentLlmClient.BRAND_UPSTREAM_UNAVAILABLE);
assertThat(AppearancePatentBrandFailureText.classify(List.of("", "")))
.isEqualTo(AppearancePatentLlmClient.BRAND_UPSTREAM_UNAVAILABLE);
}
/** 三条文案都必须以「商标查询失败」开头且彼此不同,否则分档就会把状态列或归因搅乱。 */
@Test
void 三种整批文案都保留商标查询失败前缀且互不相同() {
List<String> texts = List.of(
AppearancePatentLlmClient.BRAND_UPSTREAM_UNAVAILABLE,
AppearancePatentBrandFailureText.DECRYPT_BROKEN,
AppearancePatentBrandFailureText.SERVICE_UNREACHABLE);
assertThat(texts).allSatisfy(t -> assertThat(t).startsWith("商标查询失败"));
assertThat(texts).doesNotHaveDuplicates();
}
@Test
void spacedNoInfringementAppearanceDoesNotLeakIntoConclusion() throws Exception {
BrandCheckClient brandCheckClient = mock(BrandCheckClient.class);