package com.baiyue.warehouse.schema; import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import static org.assertj.core.api.Assertions.assertThat; class WarehousePalletBatchContractTest { @Test void baselineAndUnifiedIncrementalContainBatchTablesAndCommandHashes() throws Exception { String baseline = read(Path.of("src", "main", "resources", "db", "warehouse.sql")); String incremental = read(Path.of("..", "scripts", "db", "incremental.sql")); String unified = read(Path.of("..", "deploy", "sql", "海外区域统一增量-MySQL8.sql")); for (String sql : new String[] {baseline, incremental, unified}) { assertThat(sql).contains("CREATE TABLE IF NOT EXISTS wh_pallet_batch (") .contains("CREATE TABLE IF NOT EXISTS wh_pallet_batch_item (") .contains("confirm_command_hash CHAR(64)") .contains("compensate_command_hash CHAR(64)") .contains("business_key VARCHAR(100)") .contains("pallet_code VARCHAR(64)"); } } @Test void internalOpenApiFreezesEnvelopeAndLengthContract() throws Exception { String yaml = read(Path.of("src", "main", "resources", "openapi", "warehouse-pallet-batch-internal-v1.yaml")); assertThat(yaml).contains("/internal/v1/warehouse-pallet-batches/ensure-reserved:") .contains("/internal/v1/warehouse-pallet-batches/confirm:") .contains("/internal/v1/warehouse-pallet-batches/compensate:") .contains("业务冲突仍为HTTP 200且响应体code=A0409") .contains("commandKey幂等作用域为(warehouseId,batchKey,commandKey),无需全局唯一") .contains("资源锁保持ACTIVE供后续真实履约release或scrap") .contains("businessKey: { type: string, minLength: 1, maxLength: 100 }") .contains("palletCode: { type: string, maxLength: 64 }") .doesNotContain("'409':"); } private static String read(Path path) throws Exception { return Files.readString(path, StandardCharsets.UTF_8); } }