package com.nanri.aiimage.config; import org.junit.jupiter.api.Test; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; /** * 架构文档 §6 现状描述核对(任务 56,验证型)。 * 断言 java-architecture-optimization-plan.md §6 已反映本轮实现现状: * multipart 直通、1MB 阈值、过滤器日志不读 body、未做项标注、spec 引用、 * 与 00-overview 实施记录一致、无过时默认值/占位符残留。 */ class ArchitecturePlanSection6DocTest { private static final Path DOC = Paths.get("src", "main", "resources", "..", "..", "..", "docs", "java-architecture-optimization-plan.md").normalize(); private static final Path OVERVIEW = Paths.get("src", "main", "resources", "..", "..", "..", "docs", "plans", "00-plan-overview.md").normalize(); private static String read(Path path) throws IOException { return new String(Files.readAllBytes(path), StandardCharsets.UTF_8); } private static String section6() throws IOException { String doc = read(DOC); int start = doc.indexOf("## 6. "); int end = doc.indexOf("## 7. ", start); assertTrue(start >= 0, "文档存在 §6 章节"); return end > start ? doc.substring(start, end) : doc.substring(start); } private static List section6Lines() throws IOException { return List.of(section6().split("\r?\n")); } private static int docLineNumberOf(String section, String needle) { List lines = List.of(section.split("\r?\n")); for (int i = 0; i < lines.size(); i++) { if (lines.get(i).contains(needle)) { return i + 1; } } return -1; } @Test void noObsoleteDefaultRemains() throws IOException { for (String line : section6Lines()) { assertFalse(line.contains("104857600"), "§6 无过时默认值 104857600 残留:" + line); } } @Test void multipartPassthroughStated() throws IOException { String section = section6(); assertTrue(section.contains("multipart"), "§6 记录 multipart 处理"); assertTrue(section.contains("直通") || section.contains("跳过缓存"), "§6 记录 multipart 直通现状"); } @Test void threshold1MbStated() throws IOException { String section = section6(); assertTrue(section.contains("1MB") || section.contains("1 MiB") || section.contains("1048576"), "§6 记录 1MB 阈值现状"); assertTrue(section.contains("1048576"), "§6 记录阈值具体值 1048576"); } @Test void notReadingBodyStated() throws IOException { String section = section6(); assertTrue(section.contains("不读 body") || (section.contains("日志") && section.contains("body")), "§6 记录过滤器日志不读 body"); } @Test void deferredItemsListed() throws IOException { String section = section6(); assertTrue(section.contains("未做") || section.contains("不做") || section.contains("后续批次"), "§6 标注本轮未做项"); } @Test void spec03Referenced() throws IOException { String section = section6(); assertTrue(section.contains("specs/03-request-trace-filter.md") || section.contains("03-request-trace-filter.md"), "§6 引用 03 spec"); } @Test void consistentWithOverview() throws IOException { String section = section6(); String overview = read(OVERVIEW); for (String key : List.of("49", "50", "51", "52", "53", "54", "55", "56")) { assertTrue(overview.contains("| " + key + " |"), "00-overview 实施记录含任务 " + key); } assertTrue(overview.contains("multipart 直通"), "00-overview 记录 multipart 直通"); assertEquals(1, overview.split("multipart 直通", -1).length - 1, "00-overview 实施记录恰好一条 multipart 直通条目(与 §6 现状一致)"); } @Test void noTodoLeft() throws IOException { String section = section6(); assertTrue(docLineNumberOf(section, "### 现状") > 0 || section.contains("已实现"), "§6 有现状或已实现描述"); assertFalse(section.contains("TBD"), "§6 无 TBD 残留"); assertFalse(section.contains("TODO"), "§6 无 TODO 残留"); assertFalse(section.contains("待确认"), "§6 无待确认残留"); } }