fix(外观专利): 批量正文读不出来改走单行补检,不再按传输失败整批记死

上游回了 200 但正文不是批量协议(纯文本、或缺 items 数组)时,原来和「请求根本没通」
落进同一个分支:整批 5 行一起记失败、外观请求也不再发出,报表里就是一批没有结论的行
(10-05 21:00-21:32 生产 23 次,约 115 行)。现按异常类型分成内容失败与传输失败两类,
由代码判定而非调用方猜文案:内容失败交给既有单行补检一轮,传输失败仍整批收口、绝不逐行
放大成本。顺带接受「条目齐全但没有 items 信封」的顶层数组形状(生产实见 2 例)。

护栏:HttpTest 加 4 条用例(批内乱码补检、全量乱码只补一轮、顶层数组照读、商标批乱码);
变异 5/5 KILLED,其中 M5 是反向护栏——把分类写死成内容失败也会被既有 3 条用例杀。
货源 SimilarAsinLlmService 逐条核过:批量分类解析失败即走单行回退,无同形状缺陷,不改。
This commit is contained in:
2026-10-06 00:49:32 +08:00
parent 764ac21d30
commit e5e36aa713
2 changed files with 162 additions and 18 deletions
@@ -43,6 +43,16 @@ class AppearancePatentLlmClientHttpTest {
private volatile boolean crossAssignFirstTitleItem = false;
private volatile boolean reverseTitleItems = false;
private volatile boolean dropLastAppearanceItem = false;
/**
* 正文形状钩子:模拟「HTTP 200 但正文按批量协议读不出来」的上游形状。
* garbled_batch 只污染多行请求(补检的单行请求照常成功),garbled_all 连单行也污染,
* top_level_array 是 2026-10-05 21:09 生产实测到的形状——条目自带 i,只是没包在 items 里。
*/
private volatile String appearanceBodyShape = "normal";
private volatile String titleBodyShape = "normal";
/** 没有任何 JSON 结构的正文:readBatchRoot 两次解析都会抛,等同生产那 23 次失败。 */
private static final String GARBLED_BODY = "外观判定结论:第一件商品无侵权,第二件商品无侵权。以上为纯文本描述。";
private AppearancePatentLlmClient client;
@@ -155,6 +165,9 @@ class AppearancePatentLlmClientHttpTest {
List<String> texts = new ArrayList<>();
parseIndexedLines(userTextOf(request), indexes, texts);
boolean batch = indexes.size() > 1;
if (isGarbledBody(titleBodyShape, indexes.size())) {
return GARBLED_BODY;
}
List<Map<String, Object>> items = new ArrayList<>();
for (int i = 0; i < indexes.size(); i++) {
if (batch && dropLastTitleItem && i == indexes.size() - 1) {
@@ -180,6 +193,9 @@ class AppearancePatentLlmClientHttpTest {
List<Integer> indexes = new ArrayList<>();
List<String> texts = new ArrayList<>();
parseIndexedLines(appearanceUserTextOf(request), indexes, texts);
if (isGarbledBody(appearanceBodyShape, indexes.size())) {
return GARBLED_BODY;
}
List<Map<String, Object>> items = new ArrayList<>();
for (int i = 0; i < indexes.size(); i++) {
if (indexes.size() > 1 && dropLastAppearanceItem && i == indexes.size() - 1) {
@@ -189,11 +205,19 @@ class AppearancePatentLlmClientHttpTest {
"appearance_status", texts.get(i).contains("原创个性杯") ? "侵权" : "无侵权",
"appearance_reason", appearanceReasonFor(texts.get(i))));
}
if ("top_level_array".equals(appearanceBodyShape)) {
return objectMapper.writeValueAsString(items);
}
String json = objectMapper.writeValueAsString(Map.of("items", items));
boolean dirtySingle = indexes.size() <= 1 && !texts.isEmpty() && texts.get(0).contains("原创个性杯");
return dirtySingle ? "```json\n" + json + "\n```" : json;
}
/** 污染范围按请求行数决定:只污染批量才能验证「整批读不出来时改为逐行补检」。 */
private static boolean isGarbledBody(String shape, int requestedRows) {
return "garbled_all".equals(shape) || ("garbled_batch".equals(shape) && requestedRows > 1);
}
private String appearanceReasonFor(String text) {
return text.contains("原创个性杯")
? "【视觉拆解】:特殊造型\n【判定依据】:高度相似知名设计"
@@ -555,6 +579,80 @@ class AppearancePatentLlmClientHttpTest {
}
}
/**
* 外观批量正文读不出来(HTTP 200)=和漏行同一类失真:必须逐行补检把结论拿回来,
* 不允许一次上游抖动把整批行直接打成「外观识别异常」——那正是报表里「有行没结论」的来源,
* 而且外层会把这批行标成已检测,用户重发任务也捞不回来。
*/
@Test
void appearanceBatchGarbledBodyRedoesRowsIndividually() {
appearanceBodyShape = "garbled_batch";
List<AppearancePatentResultRowDto> rows = List.of(
row("1", "F001", "普通直筒杯A", "", "https://img.example.com/f1.jpg"),
row("2", "F002", "普通直筒杯B", "", "https://img.example.com/f2.jpg"),
row("3", "F003", "原创个性杯", "", "https://img.example.com/f3.jpg"));
List<AppearancePatentResultRowDto> result = client.inspectRows(rows, null, "test-key");
assertThat(imageRequestCount.get()).isEqualTo(4);
assertThat(result.get(0).getAppearanceRisk()).isEqualTo("无侵权");
assertThat(result.get(1).getAppearanceRisk()).isEqualTo("无侵权");
assertThat(result.get(2).getAppearanceRisk()).isEqualTo("侵权");
}
/** 补检有上界:单行补检也读不出来时,每行只做一次补检就落回退,绝不套娃重发。 */
@Test
void appearanceBatchGarbledBodyRedoIsBoundedToOnePass() {
appearanceBodyShape = "garbled_all";
List<AppearancePatentResultRowDto> rows = new ArrayList<>();
for (int i = 1; i <= 3; i++) {
rows.add(row(String.valueOf(i), "G00" + i, "普通直筒杯" + i, "", "https://img.example.com/g" + i + ".jpg"));
}
List<AppearancePatentResultRowDto> result = client.inspectRows(rows, null, "test-key");
assertThat(imageRequestCount.get()).isEqualTo(4);
for (AppearancePatentResultRowDto item : result) {
assertThat(item.getAppearanceRisk()).isEqualTo("外观识别异常");
}
}
/**
* 顶层数组正文(生产实测 2026-10-05 21:09):条目自带 i,只是没包在 items 里,
* 按既有整串解包口径(parseResults)同样收下,不许白扔一整批。
*/
@Test
void appearanceBatchTopLevelArrayBodyIsRead() {
appearanceBodyShape = "top_level_array";
List<AppearancePatentResultRowDto> rows = List.of(
row("1", "H001", "普通直筒杯A", "", "https://img.example.com/h1.jpg"),
row("2", "H002", "原创个性杯", "", "https://img.example.com/h2.jpg"));
List<AppearancePatentResultRowDto> result = client.inspectRows(rows, null, "test-key");
assertThat(imageRequestCount.get()).isEqualTo(1);
assertThat(result.get(0).getAppearanceRisk()).isEqualTo("无侵权");
assertThat(result.get(1).getAppearanceRisk()).isEqualTo("侵权");
assertThat(result.get(1).getConclusion()).isEqualTo("侵权");
}
/** 商标提取那一路共用同一套批次调度:整批正文读不出来时同样逐行补检。 */
@Test
void titleBatchGarbledBodyRedoesRowsIndividually() {
titleBodyShape = "garbled_batch";
List<AppearancePatentResultRowDto> rows = List.of(
row("1", "I001", "Apple Magic Case", "", "https://img.example.com/i1.jpg"),
row("2", "I002", "Nike Air 鞋", "", "https://img.example.com/i2.jpg"));
List<AppearancePatentResultRowDto> result = client.inspectRows(rows, null, "test-key");
assertThat(textRequestCount.get()).isEqualTo(3);
assertThat(result.get(0).getTitleReason()).isEqualTo("Apple");
assertThat(result.get(1).getTitleReason()).isEqualTo("Nike");
assertThat(result.get(0).getAppearanceRisk()).isEqualTo("无侵权");
assertThat(result.get(1).getAppearanceRisk()).isEqualTo("无侵权");
}
private static int countOccurrences(String haystack, String needle) {
int count = 0;
for (int i = haystack.indexOf(needle); i >= 0; i = haystack.indexOf(needle, i + needle.length())) {