feat(公司tab): 批次 2/3/4 再接 8 页,注册表收到 16 页——用户页回流 company_id 按新边界改写反向钉
「切 tab 数据还一样」的根因一直是分母小于现实:批次 1 只登记 8 页,本轮按控制方 三次点名扩到 16 页(company-scope.ts 是唯一清单,routes.ts 的 companyScoped 逐页对平)。 批次 2(五页 ASIN 中心):去重总数据 / 不符合ASIN / 查询ASIN / 最低价ASIN / 商品类目。 批次 3(两页店铺中心):撞款监控、店铺数据记录。这两页没有归属列可筛,归属口径是 「本公司账号名下的店铺」——后端由 DataReadScope 推公司 → 成员账号 → biz_shop_manage. created_by_id,前端只把 activeId 当 company_id 送下去。空成员集必须交空集合,绝不能 退化成 null(null 在这里=全量,那样第二家会看到全部数据)。 批次 4(用户管理):后端早就认 company_id(只对站点超管生效,公司超管恒锁本公司), 断的是前端——UserListQuery 里连这个字段都没有,三家 tab 看的是同一份全量列表。 三处口径改动,逐条说明: 1)company-user-list.test.ts 的反向钉被改写。2026-10-04 定案把公司维度从用户页整体摘掉, 那条钉的原文是「列表查询/筛选/行渲染不允许出现公司维度」。控制方 2026-10-05 明确要 用户管理区分公司 tab,所以钉的边界收窄成两半:渲染层(行级公司列、「所属公司」标签、 筛选状态、顶栏公司名)仍不得回流;请求层的 company_id 是这次加回来的,尺子换成 「取值口唯一」——页面每处 companyId 都必须等于 companyTab.requestCompanyId,且 normalizeUserPageParams/toUserListQuery 两只白名单构造器体内不许出现公司值。 新增一支行为钉:往归一化里传 companyId 必须被丢掉,这是 users.ts 读原始入参的全部理由 (写成 normalized.companyId 时 TS 照样绿、运行时恒 undefined)。 2)align-dup-console 那条 watch 看守的 token 扩到含 reload。变异自证里「删掉 void loadConsole()」当场全绿:体里的清筛选项守住了,重新取数那半没人守。批次 3/4 三对 token 一起写到 reload 为止(批次 1/2 的老条目不动)。 3)公司管理页补正/反向两把尺子:company-config-entry-super-only 新增「吃公司 tab 的页面 集合恰好等于 COMPANY_SCOPED_PAGES 的 pageFiles」——按代码真值比,不按清单比,所以 清单不改一字而往 CompaniesPage.vue 里塞 store 也会红。谓词带括号,否则 import 行也算消费者。 菜单权限(admin_columns)本轮不动:MenusPage 只消费 /api/admin/permission-menus 这一份全局 菜单字典,切 tab 一样是数据本身全局,不是筛选坏了。真问题在写侧——PermissionMenuService create/update/delete 只有 ensureAdminOperatorIfPresent(isAdmin 即放行),公司管理员改的是 全平台的菜单行。收窄为仅站点超管 vs 给 permission_menu 加归属列,两种改法代价差一个量级, 留给控制方定档。 护栏:G1 发送口 22 个 / 页面分组 17、watch 体看守 10 对、operation-guide 的 tab 文案 15 页 (撞款监控是显式豁免,另有一条自检盯「豁免落空」)。 变异自证 12/12 全杀(前端 10 + 公司管理反向钉 2),分母钉死在 27 例。 门禁:后端全量 3823 例 / 0 失败 / 0 错误 / 7 skipped,BUILD SUCCESS;admin-frontend-vue 1741 例 / 0 红;vue-tsc rc=0。首轮后端 4 红是另一路 task_partial 改动与本轮编译抢跑, 单跑 13 例已绿,本笔不含他们的任何文件。 未上线:jar 与 admin-vue 都没出包,V147 未在生产执行。
This commit is contained in:
+91
-19
@@ -19,6 +19,8 @@ import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
@@ -34,8 +36,10 @@ import static org.mockito.Mockito.when;
|
||||
* 还没摘,此后每个没显式传公司的写入都会被静默塞进默认那家——不报错、不丢数据,只在后台列表里
|
||||
* 表现成"这条数据怎么在别家公司"。所以必须用代码在启动期喊出来,而不是写在注释里等人记得。</p>
|
||||
*
|
||||
* <p>V145 之后盯的是【三张表】(users + 两张规则库),不是一列:漏登记的那张表等于没人盯,
|
||||
* 所以"探不到列"也要出声(见 {@link #unwatchedTableIsAnnouncedInsteadOfLookingClean})。</p>
|
||||
* <p>V145 之后盯的是【一张清单】(users + 两张规则库 + V147 的 biz_product_category),不是一列:
|
||||
* 漏登记的那张表等于没人盯,所以"探不到列"也要出声(见
|
||||
* {@link #unwatchedTableIsAnnouncedInsteadOfLookingClean})。清单与探针 SQL 的 IN 列表双向同源由
|
||||
* {@link #watchedTablesMatchTheProbeSql} 钉住。</p>
|
||||
*/
|
||||
class CompanyDefaultGuardTest {
|
||||
|
||||
@@ -66,20 +70,49 @@ class CompanyDefaultGuardTest {
|
||||
when(companyMapper.selectCount(null)).thenReturn(count);
|
||||
}
|
||||
|
||||
/** 一条探针结果都没有=这些表在 information_schema 里查不到 company_id。 */
|
||||
/**
|
||||
* 一条探针结果都没有=这些表在 information_schema 里查不到 company_id。
|
||||
*
|
||||
* <p>未被点名的表按"已摘掉"自动补齐:清单哪天加第五条,本文件那几支"一声不响"的用例不会
|
||||
* 因为漏了一张而红在 {@link #unwatchedTableIsAnnouncedInsteadOfLookingClean} 的同一条 WARN 上——
|
||||
* 那种红会把人引去改哨兵,而哨兵是对的。要演"探不到"那一族,用 {@link #probeReturnsOnly}。</p>
|
||||
*/
|
||||
private void probeReturns(String... tableAndDefault) {
|
||||
Map<String, String> given = new LinkedHashMap<>();
|
||||
for (String entry : tableAndDefault) {
|
||||
int split = entry.indexOf('=');
|
||||
given.put(entry.substring(0, split), split + 1 >= entry.length() ? null : entry.substring(split + 1));
|
||||
}
|
||||
List<Map<String, Object>> rows = new ArrayList<>();
|
||||
for (String table : CompanyDefaultGuard.WATCHED_TABLES) {
|
||||
if (!given.containsKey(table)) {
|
||||
rows.add(row(table, null));
|
||||
} else {
|
||||
rows.add(row(table, given.get(table)));
|
||||
}
|
||||
}
|
||||
when(jdbcTemplate.queryForList(anyString())).thenReturn(rows);
|
||||
}
|
||||
|
||||
/** 只给这几条结果,不补清单:用来演"某一列在 information_schema 里查不到"。 */
|
||||
private void probeReturnsOnly(String... tableAndDefault) {
|
||||
List<Map<String, Object>> rows = new ArrayList<>();
|
||||
for (String entry : tableAndDefault) {
|
||||
int split = entry.indexOf('=');
|
||||
Map<String, Object> row = new LinkedHashMap<>();
|
||||
row.put("TABLE_NAME", entry.substring(0, split));
|
||||
row.put("COLUMN_DEFAULT", split + 1 >= entry.length() || "null".equals(entry.substring(split + 1))
|
||||
? null : entry.substring(split + 1));
|
||||
rows.add(row);
|
||||
rows.add(row(entry.substring(0, split),
|
||||
split + 1 >= entry.length() || "null".equals(entry.substring(split + 1))
|
||||
? null : entry.substring(split + 1)));
|
||||
}
|
||||
when(jdbcTemplate.queryForList(anyString())).thenReturn(rows);
|
||||
}
|
||||
|
||||
private static Map<String, Object> row(String table, String columnDefault) {
|
||||
Map<String, Object> row = new LinkedHashMap<>();
|
||||
row.put("TABLE_NAME", table);
|
||||
row.put("COLUMN_DEFAULT", "null".equals(columnDefault) ? null : columnDefault);
|
||||
return row;
|
||||
}
|
||||
|
||||
private String messageAt(Level level) {
|
||||
return appender.list.stream()
|
||||
.filter(e -> e.getLevel() == level)
|
||||
@@ -194,19 +227,39 @@ class CompanyDefaultGuardTest {
|
||||
@DisplayName("盯不到的那张表要出声,不能装作检查过了")
|
||||
void unwatchedTableIsAnnouncedInsteadOfLookingClean() {
|
||||
companies(2);
|
||||
probeReturns("users=null");
|
||||
probeReturnsOnly("users=null");
|
||||
|
||||
guard.check();
|
||||
|
||||
assertThat(messageAt(Level.ERROR)).isEmpty();
|
||||
assertThat(messageAt(Level.WARN))
|
||||
.contains(CompanyDefaultGuard.PROBE_FAILED)
|
||||
.contains("biz_invalid_asin_data")
|
||||
.contains("biz_dedupe_total_data");
|
||||
String warn = messageAt(Level.WARN);
|
||||
assertThat(warn).contains(CompanyDefaultGuard.PROBE_FAILED);
|
||||
// 逐条点名而不是挑两条写死:清单里每一条都必须出现在"探不到"的名单里,
|
||||
// 新登记表漏进 SQL 之外的任何一侧都会在这一支红。
|
||||
for (String table : CompanyDefaultGuard.WATCHED_TABLES) {
|
||||
if (!"users".equals(table)) {
|
||||
assertThat(warn).contains(table);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("探的是这三张表的 company_id 列,表名列名写错就等于没探")
|
||||
@DisplayName("V147 的 biz_product_category 也在盯的清单里:摘 DEFAULT 那一步不许把它落下")
|
||||
void productCategoryTableIsWatchedToo() {
|
||||
companies(2);
|
||||
probeReturns("biz_product_category=1");
|
||||
|
||||
guard.check();
|
||||
|
||||
assertThat(messageAt(Level.ERROR))
|
||||
.contains(CompanyDefaultGuard.ALARM)
|
||||
.contains("biz_product_category.company_id DEFAULT=1")
|
||||
.contains("ALTER TABLE biz_product_category ALTER COLUMN company_id DROP DEFAULT")
|
||||
.doesNotContain("MODIFY");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("探的是清单里这几张表的 company_id 列,表名列名写错就等于没探")
|
||||
void probeReadsTheRightColumns() {
|
||||
companies(2);
|
||||
probeReturns("users=null", "biz_invalid_asin_data=null", "biz_dedupe_total_data=null");
|
||||
@@ -218,19 +271,38 @@ class CompanyDefaultGuardTest {
|
||||
assertThat(sql.getValue())
|
||||
.contains("information_schema.COLUMNS")
|
||||
.contains("DATABASE()")
|
||||
.contains("'company_id'")
|
||||
.contains("'users'")
|
||||
.contains("'biz_invalid_asin_data'")
|
||||
.contains("'biz_dedupe_total_data'");
|
||||
.contains("'company_id'");
|
||||
for (String table : CompanyDefaultGuard.WATCHED_TABLES) {
|
||||
assertThat(sql.getValue()).contains("'" + table + "'");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 双向钉同源。只钉"清单里的都在 SQL 里"会漏掉另一侧:有人往 SQL 的 IN 列表加了一张表、
|
||||
* 却没加进 {@code WATCHED_TABLES},那么 {@link #check} 的逐表循环根本不会走到它——
|
||||
* 探针查得到、判定查不到,Outcome 是"这张表没人盯"而一声不响,正是本哨兵要消灭的那个形状。
|
||||
*/
|
||||
@Test
|
||||
@DisplayName("清单与探针 SQL 的 IN 列表必须同源:漏一条就是那张表没人盯")
|
||||
@DisplayName("清单与探针 SQL 的 IN 列表必须同源:两个方向都钉,漏一条就是那张表没人盯")
|
||||
void watchedTablesMatchTheProbeSql() {
|
||||
String probeSql = probeSqlText();
|
||||
for (String table : CompanyDefaultGuard.WATCHED_TABLES) {
|
||||
assertThat(probeSql).contains("'" + table + "'");
|
||||
}
|
||||
assertThat(inListTables(probeSql)).containsExactlyInAnyOrder(
|
||||
CompanyDefaultGuard.WATCHED_TABLES.toArray(new String[0]));
|
||||
}
|
||||
|
||||
/** 取 {@code TABLE_NAME IN ('a', 'b')} 里那批单引号表名(只认 IN 那一段,别把 'company_id' 也算进来)。 */
|
||||
private static List<String> inListTables(String probeSql) {
|
||||
Matcher inList = Pattern.compile("TABLE_NAME\\s+IN\\s*\\(([^)]*)\\)").matcher(probeSql);
|
||||
assertThat(inList.find()).as("探针 SQL 里没有 TABLE_NAME IN (…) 这一段,取不到清单").isTrue();
|
||||
List<String> tables = new ArrayList<>();
|
||||
Matcher quoted = Pattern.compile("'([^']+)'").matcher(inList.group(1));
|
||||
while (quoted.find()) {
|
||||
tables.add(quoted.group(1));
|
||||
}
|
||||
return tables;
|
||||
}
|
||||
|
||||
private String probeSqlText() {
|
||||
|
||||
Reference in New Issue
Block a user