清设计痕迹(卖源码): 删 84 项跟踪文档/spec/plan/prompt+5 支纯文档用例+4 支没人接进闸门的审计工具,9 支混合用例只摘读 docs 的那几段
V143–V152 的迁移契约用例逐支过:87 例 0 红(mvn -o test 实跑)。混合类里钉"迁移文件本体"的断言全部保留, 只删/只切按路径读 docs 的方法;两支 scannedSignaturesAreActuallyPresent 是防恒绿的自检, 它自检的对象(回滚补丁)已随文档出仓,那几行留在类里就变成给空断言背书,所以一并摘掉。 删除面 241 个唯一副本的归档在 D:\archive\design-scrub-2026-10-11\,逐个 sha256 回读。
This commit is contained in:
-121
@@ -1,121 +0,0 @@
|
||||
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<String> section6Lines() throws IOException {
|
||||
return List.of(section6().split("\r?\n"));
|
||||
}
|
||||
|
||||
private static int docLineNumberOf(String section, String needle) {
|
||||
List<String> 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 无待确认残留");
|
||||
}
|
||||
}
|
||||
@@ -90,9 +90,6 @@ class CompanyDefaultDropV152Test {
|
||||
return normalize(stripComments(rawMigration()));
|
||||
}
|
||||
|
||||
private static Path rollbackPatch() {
|
||||
return ROOT.resolve("docs/rollback-V152-columns-shop-key-default.sql");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------ SQL 预处理
|
||||
// 与 CompanyMigrationV144Test / ShopKeyMigrationV150Test 逐字同实现,理由见类注释。
|
||||
@@ -270,29 +267,6 @@ class CompanyDefaultDropV152Test {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 回滚补丁的默认档就是"两条 SET DEFAULT 1"——与 rollback-V150 的"空档"相反:
|
||||
* 本笔被动过的只有默认值属性,装回它既是完整回滚、又是纯元数据、可逆无损。
|
||||
* 破坏点:写成 MODIFY(重建表)或忘了删 flyway_schema_history 行(半套回滚,
|
||||
* 会让"重装 V152 时跳过执行"与"库里 DEFAULT 已被装回"长期互相矛盾)。
|
||||
*/
|
||||
@Test
|
||||
void rollbackPatchRestoresTheDefaultAndDeletesHistoryRow() throws IOException {
|
||||
Path doc = rollbackPatch();
|
||||
assertTrue(Files.isRegularFile(doc), "V152 的人工回滚补丁必须存在:" + doc);
|
||||
String whole = raw(doc);
|
||||
assertTrue(whole.contains("flyway_schema_history"), "回滚必须写明删 version='152' 的历史行");
|
||||
assertTrue(whole.contains("'152'"), "回滚补丁要点名本版本号,后来人才知道删的是哪一行");
|
||||
String executable = normalize(stripComments(whole));
|
||||
assertTrue(!executable.isEmpty(), "本笔回滚是可逆的元数据操作,默认档必须直接可执行(不学 V150 的空档)");
|
||||
assertEquals(2, count(executable, "SET DEFAULT 1"),
|
||||
"默认档应把两列的 DEFAULT 都装回去(各恰一次),实际可执行段:" + executable);
|
||||
assertTrue(executable.contains("ALTER TABLE `columns` ALTER COLUMN company_id SET DEFAULT 1;")
|
||||
&& executable.contains("ALTER TABLE `biz_shop_key` ALTER COLUMN company_id SET DEFAULT 1;"),
|
||||
"装回语句应逐字用 ALTER COLUMN ... SET DEFAULT 1:" + executable);
|
||||
assertFalse(executable.toUpperCase().contains("MODIFY"),
|
||||
"禁 MODIFY:重建表对这两张表的历史行归属没有意义且徒增风险");
|
||||
}
|
||||
|
||||
/**
|
||||
* 摘掉 DEFAULT 之后哨兵对这两张表本应静默,但清单要留着——它是"被装回"(dump 重建、
|
||||
@@ -312,15 +286,6 @@ class CompanyDefaultDropV152Test {
|
||||
}
|
||||
|
||||
/** 破坏点:盘点文档没跟着 V152 改 ⇒ 下一个人按"取号起点"取号就撞号,或按"最新版本"漏掉本文件。 */
|
||||
@Test
|
||||
void inventoryDocTracksV152() throws IOException {
|
||||
Path doc = ROOT.resolve("docs/migration-inventory.md");
|
||||
String text = raw(doc);
|
||||
assertTrue(text.contains(migration().getFileName().toString()),
|
||||
"盘点文档应逐字保留本迁移文件名:" + migration().getFileName());
|
||||
assertTrue(text.contains("V150__shop_key_company_scope.sql"),
|
||||
"盘点文档应同时保留更早的文件名:只钉最新一条会重演「推进概览时把旧条目挤掉」那一次回归");
|
||||
}
|
||||
|
||||
/** 自检:本用例集扫的是真文件,且 normalize 后仍能命中关键串(0 命中的断言是恒绿的)。 */
|
||||
@Test
|
||||
@@ -330,8 +295,5 @@ class CompanyDefaultDropV152Test {
|
||||
assertTrue(count(sql, "ALTER COLUMN") == 2,
|
||||
"关键签名命中数应为 2(恰好两条),实际 " + count(sql, "ALTER COLUMN")
|
||||
+ ":预处理或文件路径坏了,本类的断言全部不可信");
|
||||
String rollbackExecutable = normalize(stripComments(raw(rollbackPatch())));
|
||||
assertTrue(count(rollbackExecutable, "ALTER COLUMN") == 2,
|
||||
"回滚补丁可执行段的 ALTER COLUMN 也应为 2(否则上面「装回两次」的断言进了恒绿分支)");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ class CompanyMigrationV143Test {
|
||||
private static final Path ROOT = Path.of(System.getProperty("user.dir"));
|
||||
private static final Path DB_DIR = ROOT.resolve("src/main/resources/db");
|
||||
private static final Pattern VERSION_FILE = Pattern.compile("^V(\\d+)(?:_(\\d+))?__.*\\.sql$");
|
||||
private static final String ROLLBACK_RELATIVE = "docs/rollback-V143-company.sql";
|
||||
|
||||
// ---------------------------------------------------------------- 取文件
|
||||
|
||||
@@ -374,23 +373,6 @@ class CompanyMigrationV143Test {
|
||||
*/
|
||||
@Test
|
||||
void rollbackLivesOutsideFlywayScanPath() throws IOException {
|
||||
Path rollback = ROOT.resolve(ROLLBACK_RELATIVE);
|
||||
assertTrue(Files.isRegularFile(rollback),
|
||||
"回滚脚本应存在于 " + ROLLBACK_RELATIVE + "(Flyway 扫描路径之外),否则事故时无从回退");
|
||||
|
||||
String rb = normalize(stripComments(Files.readString(rollback, StandardCharsets.UTF_8)));
|
||||
assertMatches(rb, "ALTER TABLE `users`\\s+DROP INDEX `idx_users_company_id`", "回滚应删掉索引");
|
||||
assertMatches(rb, "DROP COLUMN `company_id`", "回滚应删掉 users.company_id");
|
||||
assertMatches(rb, "DROP TABLE (IF EXISTS )?`company`", "回滚应删掉 company 表");
|
||||
assertTrue(rb.contains("flyway_schema_history") && rb.contains("143"),
|
||||
"回滚必须清掉 flyway_schema_history 里 V143 的记录,否则重装 jar 时 Flyway 认为已应用而跳过");
|
||||
assertTrue(rb.contains("admin_companies"), "回滚应删掉后台「公司管理」菜单行");
|
||||
|
||||
assertTrue(rawMigration().contains(ROLLBACK_RELATIVE),
|
||||
"V143 头注释的「回滚步骤」必须点名该脚本,否则值班的人找不到它");
|
||||
assertFalse(rawMigration().contains("db/V144"),
|
||||
"回滚不得写成版本化迁移 V144:Flyway 会在下次启动时自动执行它,静默撤销 V143");
|
||||
|
||||
for (Path f : versionFiles()) {
|
||||
String name = f.getFileName().toString().toLowerCase();
|
||||
assertFalse(name.contains("rollback"), "Flyway 扫描路径内不得出现回滚迁移: " + f.getFileName());
|
||||
@@ -402,35 +384,4 @@ class CompanyMigrationV143Test {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 破坏点:docs/migration-inventory.md 的数字没跟着改。
|
||||
* 下一个人按文档里的"取号起点"取号就会撞号(Flyway 启动失败),或以为 V143 还没被占用。
|
||||
*/
|
||||
@Test
|
||||
void inventoryDocTracksTheNewMigration() throws IOException {
|
||||
Path doc = ROOT.resolve("docs/migration-inventory.md");
|
||||
assertTrue(Files.isRegularFile(doc), "盘点文档应存在");
|
||||
String text = Files.readString(doc, StandardCharsets.UTF_8);
|
||||
|
||||
List<Path> files = versionFiles();
|
||||
int maxOnDisk = files.stream().mapToInt(CompanyMigrationV143Test::versionOf).max().orElse(0);
|
||||
|
||||
assertTrue(text.contains(migration().getFileName().toString()),
|
||||
"盘点文档应记录最新迁移文件名 " + migration().getFileName());
|
||||
|
||||
Matcher count = Pattern.compile("版本化迁移文件数:\\*\\*(\\d+)\\*\\*").matcher(text);
|
||||
assertTrue(count.find(), "盘点文档应给出版本化迁移文件数");
|
||||
assertEquals(files.size(), Integer.parseInt(count.group(1)),
|
||||
"文档记录的迁移文件数与磁盘不符");
|
||||
|
||||
Matcher range = Pattern.compile("整数版本范围:\\*\\*V1\\.\\.V(\\d+)\\*\\*").matcher(text);
|
||||
assertTrue(range.find(), "盘点文档应给出整数版本范围");
|
||||
assertEquals(maxOnDisk, Integer.parseInt(range.group(1)),
|
||||
"文档记录的整数版本上界与磁盘不符");
|
||||
|
||||
Matcher next = Pattern.compile("从 \\*\\*V(\\d+)\\*\\* 起取号").matcher(text);
|
||||
assertTrue(next.find(), "盘点文档应给出取号起点");
|
||||
assertEquals(maxOnDisk + 1, Integer.parseInt(next.group(1)),
|
||||
"取号起点必须 = 磁盘最大版本 + 1,否则会撞号或留洞");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,14 +278,4 @@ class CompanyMigrationV144Test {
|
||||
}
|
||||
|
||||
/** 破坏点:盘点文档没跟着 V144 改,下一个人按"取号起点"取号就撞号。 */
|
||||
@Test
|
||||
void inventoryDocTracksV144() throws IOException {
|
||||
Path doc = ROOT.resolve("docs/migration-inventory.md");
|
||||
assertTrue(Files.isRegularFile(doc), "盘点文档应存在");
|
||||
String text = Files.readString(doc, StandardCharsets.UTF_8);
|
||||
assertTrue(text.contains(migration().getFileName().toString()),
|
||||
"盘点文档应记录 V144 文件名 " + migration().getFileName());
|
||||
assertTrue(text.contains("1539570901"),
|
||||
"盘点文档应记下 V143 的生产存量校验和,作为「不许原地改」的证据");
|
||||
}
|
||||
}
|
||||
|
||||
-21
@@ -312,17 +312,6 @@ class CompanyScopeMigrationV145Test {
|
||||
assertFalse(writesHistoryTable.matcher(executable).find(),
|
||||
"回滚不许编成版本化迁移:" + file.getFileName() + " 的执行段写了 flyway_schema_history");
|
||||
}
|
||||
Path rollback = ROOT.resolve("docs/rollback-V145-company-scope.sql");
|
||||
assertTrue(Files.isRegularFile(rollback), "回滚人工补丁必须存在:" + rollback);
|
||||
String whole = raw(rollback);
|
||||
assertTrue(whole.contains("flyway_schema_history"), "回滚必须删本版本历史行");
|
||||
String executable = normalize(stripComments(whole));
|
||||
assertTrue(executable.contains("ADD UNIQUE KEY `uk_data_value_brand` (`data_value`, `brand`(191))"),
|
||||
"回滚要把品牌库的全局唯一键加回来");
|
||||
assertTrue(executable.contains("ADD UNIQUE KEY `uk_data_value` (`data_value`)"),
|
||||
"回滚要去把去重库的全局唯一键加回来");
|
||||
assertFalse(executable.contains("DROP COLUMN"),
|
||||
"DROP COLUMN 是丢归属信息的动作,必须留在注释里由人工解开(第 2 家已开通,删了就无法再分清)");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -379,16 +368,6 @@ class CompanyScopeMigrationV145Test {
|
||||
}
|
||||
|
||||
/** 破坏点:盘点文档没跟着改,下一个人按"取号起点"取号就撞号。 */
|
||||
@Test
|
||||
void inventoryDocTracksV145() throws IOException {
|
||||
Path doc = ROOT.resolve("docs/migration-inventory.md");
|
||||
String text = raw(doc);
|
||||
assertTrue(text.contains(migration().getFileName().toString()), "盘点文档应记录 V145 文件名");
|
||||
// 取号起点不在这里钉:原先写死 contains("V146"),而 V146 真落地后它只因文档里还留着
|
||||
// 那个文件名而巧合为真。派生尺子=MigrationInventoryTest#inventoryDocNumberingStartIsMaxPlusOne。
|
||||
assertTrue(text.contains("1833593804"), "盘点文档应记下 V144 的生产存量校验和");
|
||||
assertTrue(text.contains("1539570901"), "盘点文档应保留 V143 的生产存量校验和");
|
||||
}
|
||||
|
||||
/** 自检:本用例集扫的是真文件,且 normalize 后仍能命中关键串(0 命中的断言是恒绿的)。 */
|
||||
@Test
|
||||
|
||||
@@ -1,131 +0,0 @@
|
||||
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.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* 任务 115:高频查询 EXPLAIN 索引审计(文档产出验证)。
|
||||
* 审计文档必须覆盖 history/progress/dashboard 三类高频查询的执行计划结论、
|
||||
* 候选索引清单(表/列/类型/收益/风险)、全表扫描标记、可重复执行步骤,
|
||||
* 且本任务明确不做 DDL(只审计,不加索引)。
|
||||
*/
|
||||
class ExplainIndexAuditDocTest {
|
||||
|
||||
private static final Path AUDIT = Paths.get("src", "main", "resources", "..", "..", "..",
|
||||
"docs", "explain-index-audit.md").normalize();
|
||||
private static final Path FLYWAY_SPEC = Paths.get("src", "main", "resources", "..", "..", "..",
|
||||
"docs", "specs", "12-flyway-and-inspection.md").normalize();
|
||||
|
||||
private static String read(Path path) throws IOException {
|
||||
return new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private static List<String> linesOf(Path path) throws IOException {
|
||||
return List.of(read(path).split("\r?\n"));
|
||||
}
|
||||
|
||||
private static String lineContaining(String content, String needle) {
|
||||
for (String line : content.split("\r?\n")) {
|
||||
if (line.contains(needle)) {
|
||||
return line;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_explain_history_plan() throws Exception {
|
||||
String doc = read(AUDIT);
|
||||
assertTrue(doc.contains("history"), "审计文档覆盖 history 查询");
|
||||
assertTrue(doc.contains("EXPLAIN"), "审计文档包含 EXPLAIN 执行计划记录");
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_explain_progress_plan() throws Exception {
|
||||
String doc = read(AUDIT);
|
||||
assertTrue(doc.contains("progress"), "审计文档覆盖 progress 查询");
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_explain_dashboard_plan() throws Exception {
|
||||
String doc = read(AUDIT);
|
||||
assertTrue(doc.contains("dashboard"), "审计文档覆盖 dashboard 查询");
|
||||
assertTrue(doc.contains("GROUP BY"), "dashboard 聚合查询计划已记录");
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_full_scan_detected() throws Exception {
|
||||
String doc = read(AUDIT);
|
||||
assertTrue(doc.contains("type=ALL") || doc.contains("全表扫描") || doc.contains("ALL")
|
||||
|| doc.contains("possible_keys") || doc.contains("扫描"),
|
||||
"审计文档记录执行计划扫描类型(full scan 标记)");
|
||||
String line = lineContaining(doc, "idx_file_job_task");
|
||||
assertTrue(line != null && line.contains("task_id"),
|
||||
"审计文档指出 task_id 前缀索引对 (module_type, job_type, task_id IN) 的局限");
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_index_candidates_listed() throws Exception {
|
||||
String doc = read(AUDIT);
|
||||
assertTrue(doc.contains("idx_file_job_module_type_task")
|
||||
|| doc.contains("module_type") && doc.contains("job_type") && doc.contains("task_id"),
|
||||
"候选索引清单含 (module_type, job_type, task_id) 组合");
|
||||
assertTrue(doc.contains("收益") && doc.contains("风险"),
|
||||
"候选索引清单含收益与风险说明");
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_plan_documented() throws Exception {
|
||||
String doc = read(AUDIT);
|
||||
assertTrue(doc.contains("biz_task_file_job"), "审计文档引用目标表");
|
||||
assertTrue(doc.contains("biz_file_task") || doc.contains("biz_file_result"),
|
||||
"审计文档引用业务任务/结果表");
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_plan_repeatable() throws Exception {
|
||||
String doc = read(AUDIT);
|
||||
assertTrue(doc.contains("EXPLAIN SELECT") || doc.contains("EXPLAIN")
|
||||
&& doc.contains("手工执行") || doc.contains("执行"),
|
||||
"审计文档包含可重复执行的 EXPLAIN SQL 步骤");
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_no_ddl_this_task() throws Exception {
|
||||
String audit = read(AUDIT);
|
||||
String spec = read(FLYWAY_SPEC);
|
||||
assertTrue(audit.contains("不做 DDL") || audit.contains("本任务无 DDL")
|
||||
|| audit.contains("不新增索引") || audit.contains("只审计"),
|
||||
"审计文档明确本任务不做 DDL");
|
||||
// 任务 116 落地 V101 索引后,审计文档会把 ALTER TABLE 作为候选索引的
|
||||
// 回滚说明引用。审计任务自身依然不执行 DDL——判定口径改为「ALTER TABLE
|
||||
// 只能出现在候选/回滚等说明性上下文」,而不是文档里不得出现该字符串。
|
||||
for (String line : audit.split("\r?\n")) {
|
||||
if (!line.contains("ALTER TABLE")) {
|
||||
continue;
|
||||
}
|
||||
assertTrue(line.contains("回滚") || line.contains("候选") || line.contains("建议")
|
||||
|| line.contains("风险") || line.trim().startsWith(">"),
|
||||
"审计文档中的 ALTER TABLE 必须是候选/回滚说明,实际行:" + line);
|
||||
}
|
||||
assertTrue(spec.contains("只读") || spec.contains("巡检"),
|
||||
"12 spec 巡检报表模式与审计文档对应");
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_audit_reflects_batch_loading_queries() throws Exception {
|
||||
String doc = read(AUDIT);
|
||||
assertTrue(doc.contains("findAssembleJobsByTaskIds"), "审计覆盖轻量进度 Job 批量查询");
|
||||
assertTrue(doc.contains("findAssembleJobsByResultIds"), "审计覆盖结果列表 Job 批量查询");
|
||||
assertTrue(doc.contains("selectMaps") || doc.contains("GROUP BY"), "审计覆盖 dashboard 聚合查询");
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
package com.nanri.aiimage.config;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* task-201:迁移演练 runbook 契约。
|
||||
* docs/flyway-migration-drill.md 固化演练步骤:干净迁移/validate/验证 SQL/回滚/锁窗口/校验和/
|
||||
* 幂等重跑/不动历史;on-DB 步骤由运维在副本库按 runbook 执行(本环境无库)。
|
||||
*/
|
||||
class FlywayMigrationDrillDocTest {
|
||||
|
||||
private static final String DOC = "docs/flyway-migration-drill.md";
|
||||
|
||||
private String doc() throws IOException {
|
||||
return Files.readString(Path.of(System.getProperty("user.dir"), DOC));
|
||||
}
|
||||
|
||||
@Test
|
||||
void drillDocExists() {
|
||||
assertTrue(Files.exists(Path.of(System.getProperty("user.dir"), DOC)), "演练 runbook 应存在");
|
||||
}
|
||||
|
||||
@Test
|
||||
void cleanMigrateStepDescribed() throws IOException {
|
||||
assertTrue(doc().contains("migrate"), "应描述干净迁移步骤");
|
||||
}
|
||||
|
||||
@Test
|
||||
void validateStepDescribed() throws IOException {
|
||||
assertTrue(doc().contains("validate"), "应包含 validate 校验历史 checksum 步骤");
|
||||
}
|
||||
|
||||
@Test
|
||||
void validationSqlStepDescribed() throws IOException {
|
||||
assertTrue(doc().contains("验证 SQL"), "应包含验证 SQL 步骤");
|
||||
}
|
||||
|
||||
@Test
|
||||
void rollbackStepDescribed() throws IOException {
|
||||
assertTrue(doc().contains("回滚"), "应包含回滚验证步骤");
|
||||
}
|
||||
|
||||
@Test
|
||||
void lockWindowEstimatedStepDescribed() throws IOException {
|
||||
assertTrue(doc().contains("锁窗口"), "应包含锁窗口估算步骤");
|
||||
}
|
||||
|
||||
@Test
|
||||
void checksumAndIdempotentRerunDescribed() throws IOException {
|
||||
String text = doc();
|
||||
assertTrue(text.contains("checksum") || text.contains("校验和"), "应包含校验和检查");
|
||||
assertTrue(text.contains("幂等重跑") || text.contains("idempotent"), "应包含幂等重跑");
|
||||
}
|
||||
|
||||
@Test
|
||||
void noLegacyTouchGuarded() throws IOException {
|
||||
assertTrue(doc().contains("历史") && (doc().contains("未被动") || doc().contains("未被改动")),
|
||||
"应明确演练不动历史迁移");
|
||||
}
|
||||
}
|
||||
-76
@@ -1,76 +0,0 @@
|
||||
package com.nanri.aiimage.config;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* task-192:迁移规范模板契约。
|
||||
* docs/flyway-migration-template.md 存在且六项必填(目的/影响表与数据量/锁表风险/验证 SQL/
|
||||
* 回滚步骤/上线窗口)齐全,含示例 SQL,可被新迁移文件头注释引用。
|
||||
*/
|
||||
class FlywayMigrationTemplateDocTest {
|
||||
|
||||
private static final String DOC = "docs/flyway-migration-template.md";
|
||||
|
||||
private String doc() throws IOException {
|
||||
return Files.readString(Path.of(System.getProperty("user.dir"), DOC));
|
||||
}
|
||||
|
||||
@Test
|
||||
void templateExists() throws IOException {
|
||||
assertTrue(Files.exists(Path.of(System.getProperty("user.dir"), DOC)), "模板文件应存在");
|
||||
}
|
||||
|
||||
@Test
|
||||
void sixMandatoryFieldsPresent() throws IOException {
|
||||
String text = doc();
|
||||
for (int i = 1; i <= 6; i++) {
|
||||
assertTrue(text.contains(i + ". "), "头注释应含第 " + i + " 项必填");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void fieldNamesListed() throws IOException {
|
||||
String text = doc();
|
||||
assertTrue(text.contains("变更目的"));
|
||||
assertTrue(text.contains("影响表与数据量"));
|
||||
assertTrue(text.contains("锁表风险"));
|
||||
assertTrue(text.contains("验证 SQL"));
|
||||
assertTrue(text.contains("回滚步骤"));
|
||||
assertTrue(text.contains("上线窗口"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasCopyableHeaderComment() throws IOException {
|
||||
assertTrue(doc().contains("复制以下头注释"), "模板应提供可复制头注释");
|
||||
assertTrue(doc().contains("V{N+1}__"), "头注释示例应含占位版本号");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasValidationSqlExample() throws IOException {
|
||||
assertTrue(doc().contains("SELECT COUNT(*)"), "应含验证 SQL 示例");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasRollbackField() throws IOException {
|
||||
assertTrue(doc().contains("回滚步骤"), "应含回滚步骤说明");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasUpgradeWindowField() throws IOException {
|
||||
assertTrue(doc().contains("上线窗口"), "应含上线窗口说明");
|
||||
}
|
||||
|
||||
@Test
|
||||
void templateUsableByNewMigrations() throws IOException {
|
||||
String text = doc();
|
||||
assertTrue(text.contains("src/main/resources/db/"), "应说明迁移文件目录");
|
||||
assertTrue(text.contains("只追加"), "应强调只追加不改历史");
|
||||
assertTrue(text.contains("V109") || text.contains("最大现有版本"), "应说明版本号取最大现有版本+1");
|
||||
}
|
||||
}
|
||||
@@ -22,8 +22,6 @@ class IndexMigrationV101Test {
|
||||
|
||||
private static final Path DB_DIR = Paths.get("src", "main", "resources", "db");
|
||||
private static final Path MIGRATION = DB_DIR.resolve("V101__task_file_job_module_type_task_index.sql");
|
||||
private static final Path AUDIT = Paths.get("src", "main", "resources", "..", "..", "..",
|
||||
"docs", "explain-index-audit.md").normalize();
|
||||
|
||||
private static String read(Path path) throws IOException {
|
||||
return new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
|
||||
@@ -78,18 +76,8 @@ class IndexMigrationV101Test {
|
||||
void test_migration_validated() throws Exception {
|
||||
String sql = read(MIGRATION);
|
||||
assertTrue(sql.contains("SELECT 1"), "验证 SQL(幂等分支)");
|
||||
String audit = read(AUDIT);
|
||||
assertTrue(audit.contains("idx_file_job_module_type_task"), "审计清单已列出该索引");
|
||||
assertTrue(audit.contains("收益") && audit.contains("风险"), "审计清单含收益/风险");
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_explain_improved() throws Exception {
|
||||
String audit = read(AUDIT);
|
||||
assertTrue(audit.contains("findAssembleJobsByTaskIds"), "审计覆盖 progress/light Job 查询");
|
||||
assertTrue(audit.contains("执行后重跑") || audit.contains("前后计划")
|
||||
|| audit.contains("对比"), "审计含迁移前后 EXPLAIN 对比步骤");
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_migration_no_alter_legacy() throws Exception {
|
||||
@@ -109,9 +97,6 @@ class IndexMigrationV101Test {
|
||||
String sql = read(MIGRATION);
|
||||
assertTrue(sql.contains("DROP INDEX") || sql.contains("drop index"),
|
||||
"迁移文件含回滚语句(DROP INDEX idx_file_job_module_type_task)");
|
||||
String audit = read(AUDIT);
|
||||
assertTrue(audit.contains("回滚") || audit.contains("DROP"),
|
||||
"审计文档含回滚步骤说明");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
-46
@@ -376,45 +376,6 @@ class MenuTreeCompanyMigrationV149Test {
|
||||
assertTrue(raw.contains("information_schema.STATISTICS"), "验证 SQL 要复验两条旧键已摘、两条新键在");
|
||||
}
|
||||
|
||||
/**
|
||||
* 破坏点:回滚被编成版本化迁移(Flyway 扫描路径里的 V*.sql 会在下次启动自动执行),
|
||||
* 或者回滚把"删副本"排在"重指授权"之前。
|
||||
*
|
||||
* <p>后者是这一版独有的陷阱:{@code user_column_permission} 的外键是 ON DELETE CASCADE,
|
||||
* 先删副本会把它名下授权一起删光——而 V149 之后账号名下"本来就该"挂的是副本行。
|
||||
* 写反的读数不是报错,是 133 只账号的菜单被清空。</p>
|
||||
*/
|
||||
@Test
|
||||
void rollbackRepointsGrantsBeforeDeletingTheCopiesAndStaysUnversioned() throws IOException {
|
||||
Pattern writesHistoryTable = Pattern.compile(
|
||||
"\\b(DELETE|UPDATE|INSERT|TRUNCATE|ALTER|DROP)\\b[^;]*\\bflyway_schema_history\\b",
|
||||
Pattern.CASE_INSENSITIVE);
|
||||
for (Path file : versionFiles()) {
|
||||
String executable = normalize(stripComments(raw(file)));
|
||||
assertFalse(writesHistoryTable.matcher(executable).find(),
|
||||
"回滚不许编成版本化迁移:" + file.getFileName() + " 的执行段写了 flyway_schema_history");
|
||||
}
|
||||
Path rollback = ROOT.resolve("docs/rollback-V149-permission-menu-company.sql");
|
||||
assertTrue(Files.isRegularFile(rollback), "回滚人工补丁必须存在:" + rollback);
|
||||
String whole = raw(rollback);
|
||||
assertTrue(whole.contains("flyway_schema_history"), "回滚必须删本版本历史行(漏掉=重装时 Flyway 跳过 V149)");
|
||||
String executable = normalize(stripComments(whole));
|
||||
assertTrue(executable.contains("SET g.column_id = src.id"), "回滚要先把授权指针挪回公司 1 的源行");
|
||||
assertTrue(executable.contains("DELETE FROM `columns` WHERE company_id <> 1"), "再删副本");
|
||||
assertTrue(executable.indexOf("SET g.column_id = src.id") < executable.indexOf("DELETE FROM `columns`"),
|
||||
"顺序不能反:FK 是 ON DELETE CASCADE,先删副本等于清空 133 只账号的菜单");
|
||||
assertTrue(whole.contains("ON DELETE CASCADE"), "注释要写明为什么这个顺序是陷阱");
|
||||
assertTrue(executable.contains("ADD UNIQUE KEY `uk_column_key` (`column_key`)"), "回滚要把两条全平台旧键加回来");
|
||||
assertTrue(executable.contains("ADD UNIQUE KEY `uk_menu_type_route_path` (`menu_type`, `route_path`)"));
|
||||
assertTrue(executable.contains("DROP INDEX `uk_company_column_key`"), "并摘掉两条按公司的新键");
|
||||
assertTrue(executable.contains("DROP INDEX `uk_company_menu_type_route_path`"));
|
||||
assertTrue(executable.indexOf("ADD UNIQUE KEY `uk_column_key`") < executable.indexOf("DROP INDEX `uk_company_column_key`"),
|
||||
"回滚同样是先 ADD 后 DROP:中间态必须还剩一个唯一键");
|
||||
assertTrue(executable.contains("CREATE TEMPORARY TABLE `_v149_rb_gate`"),
|
||||
"重指与删除之间要有闸门:漏一行就会被 CASCADE 静默吞掉");
|
||||
assertTrue(executable.contains("CREATE TABLE IF NOT EXISTS `columns_bak_v149_rollback`"),
|
||||
"删副本前必须整表留底");
|
||||
}
|
||||
|
||||
/**
|
||||
* 破坏点:头注释喊了哨兵,哨兵却没探这一列 ⇒ "有人盯着摘 DEFAULT"这件事是假的。
|
||||
@@ -533,13 +494,6 @@ class MenuTreeCompanyMigrationV149Test {
|
||||
}
|
||||
|
||||
/** 破坏点:盘点文档没跟着改,下一个人按"取号起点"取号就撞号。 */
|
||||
@Test
|
||||
void inventoryDocTracksV149() throws IOException {
|
||||
String text = raw(ROOT.resolve("docs/migration-inventory.md"));
|
||||
assertTrue(text.contains(migration().getFileName().toString()), "盘点文档应记录 V149 文件名");
|
||||
assertTrue(text.contains("V152"), "盘点文档应记下新的取号起点(V150/V151 已被同批占用)");
|
||||
// 取号起点是否真等于"当前最大值 + 1"由 MigrationInventoryTest 派生判定,这里不重复钉死字面号。
|
||||
}
|
||||
|
||||
/** 自检:本用例集扫的是真文件,且 normalize 后仍能命中关键串(0 命中的断言是恒绿的)。 */
|
||||
@Test
|
||||
|
||||
@@ -138,49 +138,7 @@ class MigrationInventoryTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void inventoryDocCommittedAndConsistent() throws IOException {
|
||||
Path doc = Path.of(System.getProperty("user.dir"), "docs/migration-inventory.md");
|
||||
assertTrue(Files.exists(doc), "盘点文档应存在并随仓库提交");
|
||||
String text = Files.readString(doc);
|
||||
int maxMajor = parseAll(versionFiles()).stream().filter(Migration::isInteger)
|
||||
.mapToInt(Migration::major).max().orElse(0);
|
||||
assertTrue(text.contains("V" + maxMajor), "文档应记录最新版本 V" + maxMajor);
|
||||
assertTrue(text.contains("25_1") || text.contains("V25_1"), "文档应记录历史小版本");
|
||||
for (int hole : RETIRED_HOLES) {
|
||||
assertTrue(text.contains(String.valueOf(hole)),
|
||||
"文档应记录退役空号 V" + hole + " 的来历,否则后来人会试图回填该号");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 盘点文档的「起取号」必须是目录当前最大值 + 1 —— 派生式,不写死数字。
|
||||
*
|
||||
* <p>破坏点两条:加了 V148 却没改文档 ⇒ 后来人照文档取号撞上刚落地的 V148(改已应用版本=两台都起不来);
|
||||
* 文档把号位改超前 ⇒ 1..max 留洞,{@link #integerVersionsSequentialFromOne} 会红。
|
||||
* 各迁移自己的审计类原先把「起点推到 V14x」写死在 assertTrue 里,那种断言在 V14x 真落地那天就
|
||||
* 只因文档里还留着同名文件而恒为真(基线自己过期)。尺子挪到这里、只对「本轮目录」求值,
|
||||
* 才不需要每加一版都有人记得回来改一个数字。</p>
|
||||
*/
|
||||
@Test
|
||||
void inventoryDocNumberingStartIsMaxPlusOne() throws IOException {
|
||||
String text = Files.readString(Path.of(System.getProperty("user.dir"), "docs/migration-inventory.md"));
|
||||
String marker = "从 **V";
|
||||
int hits = 0, cursor = -1;
|
||||
while ((cursor = text.indexOf(marker, cursor + 1)) >= 0) hits++;
|
||||
assertEquals(1, hits, "「从 **V<号>** 起取号」应只有一条可解析的取号规则," + hits + " 条=后来人不知道按哪条取号");
|
||||
|
||||
int digitsFrom = text.indexOf(marker) + marker.length();
|
||||
int digitsTo = digitsFrom;
|
||||
while (digitsTo < text.length() && Character.isDigit(text.charAt(digitsTo))) digitsTo++;
|
||||
assertTrue(digitsTo > digitsFrom, "取号规则里 V 之后必须是数字(解析不出=本用例恒绿)");
|
||||
int stated = Integer.parseInt(text.substring(digitsFrom, digitsTo));
|
||||
|
||||
int maxMajor = parseAll(versionFiles()).stream().filter(Migration::isInteger)
|
||||
.mapToInt(Migration::major).max().orElse(0);
|
||||
assertEquals(maxMajor + 1, stated,
|
||||
"取号起点应是目录最大值 V" + maxMajor + " 的下一号,实际文档写 V" + stated);
|
||||
}
|
||||
|
||||
@Test
|
||||
void checksumStableAcrossReads() throws IOException {
|
||||
|
||||
-45
@@ -203,33 +203,6 @@ class ProductCategoryMigrationV147Test {
|
||||
"三段条件 DDL 都必须走 PREPARE/EXECUTE(MySQL 不能在 IF 里直接写 DDL)");
|
||||
}
|
||||
|
||||
/**
|
||||
* 破坏点:回滚脚本没跟着写 ⇒ 出问题只能手工现编 SQL,而"漏删 flyway_schema_history 的 147 行"
|
||||
* 这一手会让重装带 V147 的 jar 时 Flyway 判定已应用直接跳过——列和键都不重建,
|
||||
* 而 Java 侧实体照常读写 company_id,运行期报 Unknown column。
|
||||
*
|
||||
* <p>与 V145 那份同形:{@code DROP COLUMN} 必须留在注释里由人工解开(这张表没有账号列,
|
||||
* 删了就再也分不出哪一家),而"回滚不得版本化"由 {@link CompanyScopeMigrationV145Test
|
||||
* #rollbackStaysOutOfFlywayScanAndCoversTheHistoryRow} 那支按全目录扫,本类不重复实现,
|
||||
* 只在下面那支按文件名把本迁移钉进盘点文档(号位起点由 {@link MigrationInventoryTest
|
||||
* #inventoryDocNumberingStartIsMaxPlusOne} 派生式盯着)。</p>
|
||||
*/
|
||||
@Test
|
||||
void rollbackIsAHumanPatchOutsideTheFlywayScanPath() throws IOException {
|
||||
Path doc = ROOT.resolve("docs/rollback-V147-product-category-company.sql");
|
||||
assertTrue(Files.isRegularFile(doc), "V147 的人工回滚补丁必须存在:" + doc);
|
||||
String whole = raw(doc);
|
||||
assertTrue(whole.contains("flyway_schema_history"), "回滚必须写明删 version='147' 的历史行");
|
||||
String executable = normalize(stripComments(whole));
|
||||
assertTrue(executable.contains("ADD UNIQUE KEY `" + OLD_KEY + "` (`category_key`)"),
|
||||
"回滚要把全平台唯一键加回来(新键是旧键的严格放宽,回填那一刻必然不撞)");
|
||||
assertTrue(executable.contains("DROP INDEX `" + NEW_KEY + "`"), "回滚要摘掉按公司的新唯一键");
|
||||
assertTrue(executable.indexOf("ADD UNIQUE KEY") < executable.indexOf("DROP INDEX"),
|
||||
"回滚也必须先加旧键后删新键,理由与迁移同一半:中间时刻不许没有唯一键");
|
||||
assertFalse(executable.contains("DROP COLUMN"),
|
||||
"DROP COLUMN 是丢归属信息的动作,必须留在注释里由人工解开");
|
||||
assertFalse(executable.contains("MODIFY COLUMN"), "同上:任何时候不要写 MODIFY COLUMN");
|
||||
}
|
||||
|
||||
/**
|
||||
* 破坏点(2026-10-06 起方向相反):类目表随「商品类目做成所有公司共享」的定案<b>退出</b>了启动期
|
||||
@@ -297,24 +270,6 @@ class ProductCategoryMigrationV147Test {
|
||||
return hits.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 破坏点:盘点文档没跟着改 ⇒ 下一个人按"取号起点"取号就撞号,或者按"最新版本"漏掉本文件。
|
||||
* 这里把 V145/V146/V147 三个文件名同时钉住:只钉最新一条会重演
|
||||
* 「推进第 11 行时把 V145 挤掉」那一次回归(本轮真实发生过)。
|
||||
* 号位起点不写在这里——写死 "V148" 到 V148 落地那天就自己过期,改由
|
||||
* {@link MigrationInventoryTest#inventoryDocNumberingStartIsMaxPlusOne} 按「本轮目录最大值 + 1」求值。
|
||||
*/
|
||||
@Test
|
||||
void inventoryDocTracksV147AndTheEarlierFilenamesTogether() throws IOException {
|
||||
Path doc = ROOT.resolve("docs/migration-inventory.md");
|
||||
String text = raw(doc);
|
||||
for (String keep : List.of("V145__brand_dedupe_company_scope.sql",
|
||||
"V146__users_expires_at_admin_expiry.sql",
|
||||
migration().getFileName().toString())) {
|
||||
assertTrue(text.contains(keep), "盘点文档应逐字保留文件名:" + keep);
|
||||
}
|
||||
assertTrue(text.contains("1833593804"), "盘点文档应记下 V144 的生产存量校验和");
|
||||
}
|
||||
|
||||
/** 自检:本用例集扫的是真文件,且 normalize 后仍能命中关键串(0 命中的断言是恒绿的)。 */
|
||||
@Test
|
||||
|
||||
@@ -223,27 +223,6 @@ class ShopKeyMigrationV150Test {
|
||||
assertTrue(whole.contains("没有实查") || whole.contains("未实查"), "行数没查过这件事必须写在文件里,不许读成已知");
|
||||
}
|
||||
|
||||
/**
|
||||
* 回滚是人工补丁,且在 Flyway 扫描路径之外。
|
||||
*
|
||||
* <p>本迁移的回滚默认档<b>一条 SQL 都不执行</b>:这张表没有账号列,删列就删掉了唯一的归属依据,
|
||||
* 所以 {@code DROP COLUMN} 留在注释里由人工解开,止损走"保留新列、只回 jar"那一档
|
||||
* (新列对旧 jar 是惰性的,{@code DEFAULT 1} 正好把旧 jar 插入的行接住)。
|
||||
* {@link CompanyScopeMigrationV145Test#rollbackStaysOutOfFlywayScanAndCoversTheHistoryRow} 按全目录
|
||||
* 钉"回滚不得版本化",本类只钉本迁移这一支的内容。</p>
|
||||
*/
|
||||
@Test
|
||||
void rollbackIsAHumanPatchThatDefaultsToKeepingTheColumn() throws IOException {
|
||||
Path doc = ROOT.resolve("docs/rollback-V150-shop-key-company.sql");
|
||||
assertTrue(Files.isRegularFile(doc), "V150 的人工回滚补丁必须存在:" + doc);
|
||||
String whole = raw(doc);
|
||||
assertTrue(whole.contains("flyway_schema_history"), "回滚必须写明删 version='150' 的历史行");
|
||||
assertTrue(whole.contains("'150'"), "回滚补丁要点名本版本号,后来人才知道删的是哪一行");
|
||||
String executable = normalize(stripComments(whole));
|
||||
assertTrue(executable.isEmpty(),
|
||||
"默认档不执行任何 SQL(删列是不可逆动作,必须留在注释里由人工解开),实际可执行段:" + executable);
|
||||
assertTrue(whole.contains("DROP COLUMN"), "删列那一步要在文件里,只是不许默认可执行");
|
||||
}
|
||||
|
||||
/**
|
||||
* 破坏点:V150 的 DEFAULT 1 没进启动期哨兵清单 ⇒ "下一次记得摘"这件事没人喊,
|
||||
@@ -262,15 +241,6 @@ class ShopKeyMigrationV150Test {
|
||||
}
|
||||
|
||||
/** 破坏点:盘点文档没跟着改 ⇒ 下一个人按"取号起点"取号就撞号,或按"最新版本"漏掉本文件。 */
|
||||
@Test
|
||||
void inventoryDocTracksTheShopKeyFile() throws IOException {
|
||||
Path doc = ROOT.resolve("docs/migration-inventory.md");
|
||||
String text = raw(doc);
|
||||
assertTrue(text.contains(migration().getFileName().toString()),
|
||||
"盘点文档应逐字保留本迁移文件名:" + migration().getFileName());
|
||||
assertTrue(text.contains("V147__product_category_company_scope.sql"),
|
||||
"盘点文档应同时保留更早的文件名:只钉最新一条会重演「推进概览时把旧条目挤掉」那一次回归");
|
||||
}
|
||||
|
||||
/** 自检:本用例集扫的是真文件,且 normalize 后仍能命中关键串(0 命中的断言是恒绿的)。 */
|
||||
@Test
|
||||
@@ -279,10 +249,6 @@ class ShopKeyMigrationV150Test {
|
||||
assertTrue(sql.length() > 120, "剥注释后的 SQL 太短,说明预处理把内容吃掉了:" + sql.length());
|
||||
assertTrue(count(sql, "ALTER TABLE") >= 1 && count(sql, "information_schema") > 0,
|
||||
"关键签名 0 命中=预处理或文件路径坏了,本类的断言全部不可信");
|
||||
String rollbackExecutable = normalize(stripComments(raw(ROOT.resolve("docs/rollback-V150-shop-key-company.sql"))));
|
||||
assertTrue(raw(ROOT.resolve("docs/rollback-V150-shop-key-company.sql")).contains("--"),
|
||||
"回滚补丁若一条注释都没有,上面那条「可执行段为空」就成了恒真断言");
|
||||
assertTrue(rollbackExecutable.isEmpty(), "回滚补丁的可执行段应当确实为空");
|
||||
}
|
||||
|
||||
private static int count(String haystack, String needle) {
|
||||
|
||||
Reference in New Issue
Block a user