fix(appearance-patent): 外观维把「没跑」写成「外观识别异常」且原因列空白(B96-09)

34061 交付件实测:1000 行里 987 行外观维=外观识别异常、外观原因/专利原因只有 21 行有字,而零行真的跑过外观。根因是 LLM 上游 01:01-01:06 全程 403 欠费(用户[155933] 剩 0.0305 < 单次 0.0324)→ 标题维先失败 → 跳过外观那一步,跳过分支把标签写死成外观识别异常、原因留空。

改:新增 APPEARANCE_NOT_RUN(未执行外观检测)+ 两条原因文案(无标题/无图、商标维先失败带原话),专利原因同步;APPEARANCE_ANOMALY 只留给发了请求没答上的行。顺带修原因 sheet 每行自增两次(1000 ASIN 占 2000 行)。

门禁:外观专利包 364 例全绿;后端整量 mvn -o test 5435 例/0 失败/0 错误/19 skip/BUILD SUCCESS(7:50)。
This commit is contained in:
2026-11-12 15:53:35 +08:00
parent ad33b7d54c
commit f5f40cd2ea
5 changed files with 127 additions and 9 deletions
@@ -164,7 +164,7 @@ class AppearancePatentBrandBatchTest {
.containsExactly("阿凡达 玩具 手办 正版", "小米 充电宝 20000mAh 快充");
assertThat(rows).hasSize(2);
for (AppearancePatentResultRowDto row : rows) {
assertThat(row.getAppearanceRisk()).isEqualTo("外观识别异常");
assertThat(row.getAppearanceRisk()).isEqualTo("未执行外观检测");
}
assertThat(rows.get(0).getTitleRisk()).isEqualTo("侵权");
assertThat(rows.get(1).getTitleRisk()).as("回退行的归因同样停在行").isEqualTo("无侵权");
@@ -173,6 +173,51 @@ class AppearancePatentBrandBatchTest {
}
}
/**
* 商标维先失败的行,外观那一步**根本没发出请求**,原因列必须这么写。
*
* <p>2026-11-12 任务 34061 的交付件就是反面样本:1000 行里 987 行外观维写着「外观识别异常」,
* 而「外观原因」整列只有 21 行有字——真实的 403 欠费原因在标题原因里,用户只能把那一格读成
* 「图片识别没认出来」。标签「外观识别异常」保持不变(它本来就是"没有外观结论"的口径),
* 但原因必须把「没跑」写出来,并带上商标维的原话。
*/
@Test
void skippedAppearanceRowsSayTheImageStepNeverRan() throws Exception {
when(brandCheckClient.checkTitleTexts(anyList(), eq("Terms"), any())).thenAnswer(invocation -> {
List<String> titles = invocation.getArgument(0);
List<BrandCheckClient.BrandCheckBatchResult> results = new ArrayList<>();
for (String title : titles) {
results.add(new BrandCheckClient.BrandCheckBatchResult(List.of(title), List.of(), List.of(), ""));
}
return results;
});
HttpServer llmDown = startUnusableLlm();
try {
AppearancePatentProperties properties = new AppearancePatentProperties();
properties.setLlmHost("http://127.0.0.1:" + llmDown.getAddress().getPort());
properties.setLlmRetryTimes(1);
properties.setLlmReadTimeoutMillis(5_000);
AppearancePatentLlmClient inspectClient = new AppearancePatentLlmClient(
properties, new ObjectMapper(), null, brandCheckClient,
mock(UserSecretUsageService.class), new UnreachableCooldown());
List<AppearancePatentResultRowDto> rows = inspectClient.inspectRows(
List.of(source("1", "阿凡达 玩具 手办 正版")), null, "test-key");
assertThat(rows).hasSize(1);
AppearancePatentResultRowDto row = rows.get(0);
assertThat(row.getAppearanceRisk()).isEqualTo("未执行外观检测");
assertThat(row.getAppearanceReason())
.as("外观原因要说清「没跑」,不能空着让用户以为是图片识别失败")
.startsWith("未执行外观检测:商标维先失败")
.contains("502");
assertThat(row.getPatentReason()).isEqualTo("未执行专利检测:外观维未执行");
assertThat(row.getTitleReason()).as("商标维自己的原话照旧留在标题原因里").contains("502");
} finally {
llmDown.stop(0);
}
}
/** LLM 一律回 502:让每一行都落到回退分支,只观察品牌校验的调用形状。 */
private HttpServer startUnusableLlm() throws IOException {
HttpServer server = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
@@ -415,13 +415,15 @@ class AppearancePatentLlmClientHttpTest {
}
@Test
void missingUrlFallsBackToAppearanceAnomalyWithoutLlmCall() {
void missingUrlFallsBackToAppearanceNotRunWithoutLlmCall() {
AppearancePatentResultRowDto row = row("4", "B004", "测试商品", "", "");
List<AppearancePatentResultRowDto> rows = client.inspectRows(List.of(row), null, "test-key");
AppearancePatentResultRowDto result = rows.get(0);
assertThat(result.getAppearanceRisk()).isEqualTo("外观识别异常");
assertThat(result.getAppearanceRisk()).isEqualTo("未执行外观检测");
assertThat(result.getAppearanceReason())
.isEqualTo("未执行外观检测:本行没有标题或图片链接,未发出图片识别请求");
assertThat(callCounts.get("deepseek-v4-flash")).isNull();
assertThat(callCounts.get("gemini-3.1-flash-lite-preview-thinking-medium")).isNull();
}
@@ -465,7 +467,8 @@ class AppearancePatentLlmClientHttpTest {
List<AppearancePatentResultRowDto> rows = singleAttemptClient.inspectRows(
List.of(row("7", "B007", "任意标题", "", "https://img.example.com/7.jpg")), null, "test-key");
assertThat(rows.get(0).getAppearanceRisk()).isEqualTo("外观识别异常");
assertThat(rows.get(0).getAppearanceRisk()).isEqualTo("未执行外观检测");
assertThat(rows.get(0).getAppearanceReason()).startsWith("未执行外观检测:商标维先失败");
assertThat(capturedBodies).noneMatch(b -> b.contains("\"type\":\"image_url\""));
assertThat(textRequestCount.get()).isEqualTo(1);
}
@@ -578,7 +581,7 @@ class AppearancePatentLlmClientHttpTest {
assertThat(textRequestCount.get()).isEqualTo(1);
assertThat(result).hasSize(5);
for (AppearancePatentResultRowDto item : result) {
assertThat(item.getAppearanceRisk()).isEqualTo("外观识别异常");
assertThat(item.getAppearanceRisk()).isEqualTo("未执行外观检测");
}
assertThat(capturedBodies).noneMatch(b -> b.contains("\"type\":\"image_url\""));
}
@@ -10,11 +10,13 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -242,6 +244,32 @@ class AppearancePatentSheetBuilderTest {
}
}
/**
* 原因 sheet 一行一个 ASIN,不许留空行:2026-11-12 任务 34061 的交付件里 1000 个 ASIN 占了 2000 行
* (写一行自增两次),Excel 里看着就是隔行空白。
*/
@Test
void test_sheet_builder_reason_sheet_has_no_blank_rows() throws Exception {
try (Workbook wb = new XSSFWorkbook()) {
List<AppearancePatentParsedRowVo> parsed = new ArrayList<>();
Map<String, AppearancePatentResultRowDto> byKey = new LinkedHashMap<>();
for (String asin : List.of("B01A", "B01B", "B01C")) {
AppearancePatentParsedRowVo p = parsedRow("2_" + asin, asin, "US", "t", "", "");
AppearancePatentResultRowDto r = resultRow("2_" + asin, asin, "US");
parsed.add(p);
byKey.put(AppearancePatentSheetBuilder.rowKey(r), r);
}
AppearancePatentSheetBuilder.buildResultSheet(wb, parsed, byKey);
Sheet reason = wb.getSheet("原因");
for (int i = 1; i <= 3; i++) {
assertNotNull(reason.getRow(i), "第 " + i + " 行不许是空行");
}
assertNull(reason.getRow(4), "三个 ASIN 只占三行");
assertEquals(3, reason.getLastRowNum(), "行数=ASIN 数,不许夹空行");
}
}
@Test
void test_sheet_builder_writable_output_stream() throws Exception {
try (Workbook wb = new XSSFWorkbook()) {