refactor(租户): 站点超管判定收成唯一静态出口,看板补第四道门

"super_admin 才算平台超管"这句判断此前在 src/main 里被手抄过 19 遍,2026-10-07 定的
「company_super_admin 在业务数据面同权、只在管理动作收窄」要落地就得一次改到每一处,
漏一处的表现是某一页静默 403 或静默多放行,两边都不报错。现在口径只在
DeviceSessionPolicy.isSuper 比一次:

- 出口做成静态谓词而不是 AdminAuthSupport 实例方法——那 18 支测试里 mock 的是
  AdminAuthSupport,新增实例方法不会被桩到,默认 false 会把范围静默改窄;
- 12 个文件的 15 处调用点改为 DeviceSessionPolicy.isSuper(currentRole(...)),
  DataReadScope/AdminAuthSupport 只留一个委托包装;
- 「客户端任务管理」五个 handler 的成员集计算折进 DataReadScope.superAdminScopedUserIds,
  并在 CompanyIdParamGoesThroughReadScopeTest 里补成第四道门(正反探针各一,
  判据不会因"抽进私有方法"而失明);
- 护栏 SuperAdminPredicateSingleOutletTest 双向钉:出口定义==1、包装==1、调用点==16,
  且 banned 掉实例方法形状(自检断言保证它真能红)。

今天口径仍只认 super_admin,这一层是接缝不是开关。Java 全量在本批收口后的那棵树实测 4032 例
0 红 7 skip(7 支是要本地凭据/夹具的回放与实况探测类,历来 skip)。

一并落在这支的文件(同一文件只能进一次提交,故与同批的归属收口混装):ImageVideo/InvalidAsin/
AdminDeviceLog/AdminTaskCenter/DedupeTotalData/AdminShopDataCrawlTasks/AdminShopDataDuplicateCheck/
QueryAsin/ShopManage/SkipPriceAsin 这 10 支控制器的请求身份改走会话出口见 cp-item7 的说明;
PermissionMenuService 还删掉了 create/update/delete 三个"operator 传 null 即跳过归属闸门"的
无操作者写重载(src/main 无人调用),判据在 MenuWriteOutletOperatorTest。
This commit is contained in:
2026-10-07 20:01:30 +08:00
parent 7c7a7f2665
commit de2bf05ab7
21 changed files with 487 additions and 137 deletions
@@ -0,0 +1,267 @@
package com.nanri.aiimage.common.security;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import com.nanri.aiimage.testutil.SourceScan;
import org.junit.jupiter.api.Test;
/**
* 「谁是站点超管」只剩一处定义的绊线(2026-10-07 多公司改造三期)。
*
* <p>改之前的形状:这句判定在 {@code src/main} 里被重抄了 <b>19</b> 遍 —— 16 处
* {@code "super_admin".equals(adminAuthSupport.currentRole(x))}(含 4 个 {@code isSuper} 私有副本),
* 外加 3 处连「role 为空 + is_admin=1 + created_by_id 为空」的老数据推断一起手抄的副本
* ({@code DedupeTotalDataService} / {@code TaskCenterScopeService} / {@code PermissionMenuService})。</p>
*
* <p>重复本身不是缺陷,<b>改不动</b>才是:2026-10-07 定案「{@code company_super_admin} 在业务数据面与
* {@code super_admin} 同权、只在管理动作上收窄」要落地,就得一次改到这 19 处里的每一处。漏一处的表现是
* 某一页静默 403 或静默多放行,两边都不报错、不红。所以现在把口径钉成:</p>
*
* <ol>
* <li>角色比较只允许发生在 {@link DeviceSessionPolicy#isSuper(String)} 这一处,调用方一律写成
* {@code DeviceSessionPolicy.isSuper(adminAuthSupport.currentRole(x))};</li>
* <li>出口<b>不许多挂一个名字</b>:上一轮把它做成 {@code AdminAuthSupport} 的实例方法,
* 18 支护栏/业务用例打桩的是 {@code currentRole} 这把既有接缝,同一个 mock 上的新方法桩不到,
* 表现是 31 failures + 17 errors 全是"静默少放行"那一形(见 {@link #outletIsNotAMethodOnTheAuthSupportMock});</li>
* <li>老数据推断只允许存在于定义处 {@link DeviceSessionPolicy};</li>
* <li>公司 tab 的收窄三元式收成 {@code DataReadScope#superAdminScopedUserIds},
* {@code AdminTaskCenterController} 那 5 处逐字重复不再存在。</li>
* </ol>
*
* <p>每支都带"切片非空"自检:负向断言的同一把正则必须能抓到老形状,否则恒绿等于没护栏。</p>
*/
class SuperAdminPredicateSingleOutletTest {
/** 老形状:解析完角色之后又自己比字面量(字面量或私有常量两种写法都算)。 */
private static final Pattern ROLE_LITERAL = Pattern.compile(
"(?:\"super_admin\"|SUPER_ADMIN)\\.equals\\(\\s*adminAuthSupport\\.currentRole\\(");
/** 老形状:私有方法里把「role 为空 + is_admin=1 + created_by_id 为空」的推断整段手抄。 */
private static final Pattern PRIVATE_SUPERADMIN_COPY = Pattern.compile(
"private\\s+boolean\\s+isSuperAdmin\\s*\\([^)]*\\)\\s*\\{[^}]*\"super_admin\"",
Pattern.DOTALL);
@Test
void nobodyRewritesTheSuperAdminLiteralAfterResolvingRole() {
List<String> hits = new ArrayList<>();
for (Path file : mainSources()) {
String text = read(file);
var m = ROLE_LITERAL.matcher(text);
while (m.find()) {
hits.add(file.getFileName() + ": " + m.group());
}
}
assertThat(hits)
.as("src/main 里自己比较 super_admin 字面量的位置(应全部改走 DeviceSessionPolicy#isSuper)")
.isEmpty();
}
@Test
void theLiteralPatternIsNotVacuous() {
// 自检:上一支的正则必须真能抓到老形状,否则「0 命中」与「没扫到」同形。
// 两个样本就是本轮删掉的真实代码(16 处里的两种写法)。
assertThat(ROLE_LITERAL.matcher(
"if (\"super_admin\".equals(adminAuthSupport.currentRole(operator))) {").find()).isTrue();
assertThat(ROLE_LITERAL.matcher(
"return SUPER_ADMIN.equals(adminAuthSupport.currentRole(operator)) ? null : own;").find()).isTrue();
assertThat(ROLE_LITERAL.matcher(
"boolean superAdmin = DeviceSessionPolicy.isSuper(adminAuthSupport.currentRole(operator));").find())
.as("改走出口之后不得再被当成命中").isFalse();
}
@Test
void legacyRoleInferenceIsNotHandCopiedInPrivateMethods() {
List<String> copiers = new ArrayList<>();
for (Path file : mainSources()) {
String text = read(file);
var m = PRIVATE_SUPERADMIN_COPY.matcher(text);
while (m.find()) {
copiers.add(file.getFileName() + " 仍在自己比 role/is_admin");
}
}
assertThat(copiers)
.as("手抄「role 为空 + is_admin=1 + created_by_id 为空」推断的私有方法,一条都不许剩")
.isEmpty();
// 同一把尺子必须抓得到本轮删掉的真实副本,否则上一支恒绿
assertThat(PRIVATE_SUPERADMIN_COPY.matcher("""
private boolean isSuperAdmin(AdminUserEntity user) {
String role = user.getRole() == null ? "" : user.getRole().trim();
return "super_admin".equals(role);
}
""").find()).isTrue();
}
@Test
void superAdminOutletIsOneStaticPredicateAndSixteenCallSites() {
int definitions = 0;
int callSites = 0;
int wrappers = 0;
for (Path file : mainSources()) {
String text = read(file);
definitions += count(text, "public static boolean isSuper(");
callSites += count(text, "DeviceSessionPolicy.isSuper(adminAuthSupport.currentRole(");
wrappers += count(text, "public boolean isPlatformSuperAdmin(");
}
// 比字符串的那一处只有一份,它在 DeviceSessionPolicy;第三个定义点就是分叉的开始
assertThat(definitions)
.as("超管比较口径的定义处(DeviceSessionPolicy#isSuper)")
.isEqualTo(1);
assertThat(wrappers)
.as("业务层包装 isPlatformSuperAdmin 的定义处(只允许 DataReadScope 一个)")
.isEqualTo(1);
assertThat(callSites)
.as("走出口的调用点数:15 个业务调用方 + DataReadScope 包装体(新增调用要一起改这个数字,别改回字面量)")
.isEqualTo(16);
// 自检:这三把尺子的锚点必须真落在预期的文件里,否则"恰好也是 N"可能是扫错地方凑出来的
assertThat(read(mainRoot().resolve("common/security/DeviceSessionPolicy.java")))
.contains("public static boolean isSuper(String resolvedRole)");
assertThat(read(mainRoot().resolve("common/service/DataReadScope.java")))
.contains("public boolean isPlatformSuperAdmin(AdminUserEntity operator)");
}
/**
* 出口不得再做成 {@code AdminAuthSupport} 的实例方法。
*
* <p>这一支钉的是上一轮真实踩到的坑:把 19 处调用改成 {@code adminAuthSupport.isPlatformSuperAdmin(x)}
* 之后,测试里 {@code @Mock AdminAuthSupport} 的该方法是<b>未被打桩</b>的,Mockito 默认返回 false,
* 于是"超管放行"的分支在测试与线上同时静默变窄 —— 31 failures + 17 errors。
* 口径本身没错,错在把接缝挂到一把已有桩覆盖不到的方法上。改回来只需要动定义处,调用方不动。</p>
*/
@Test
void outletIsNotAMethodOnTheAuthSupportMock() {
String banned = "adminAuthSupport.isPlatformSuperAdmin(";
List<String> hits = new ArrayList<>();
for (Path file : mainSources()) {
String text = read(file);
for (int i = text.indexOf(banned); i >= 0; i = text.indexOf(banned, i + banned.length())) {
hits.add(file.getFileName() + ": " + text.substring(i, i + banned.length()));
}
}
assertThat(hits)
.as("超管出口不得挂在 AdminAuthSupport 实例方法上(护栏用例打桩的是 currentRole)")
.isEmpty();
}
@Test
void taskCenterTabsUseTheSingleScopedOutletInsteadOfFiveCopies() {
String controller = read(mainRoot().resolve(
"modules/taskcenter/controller/AdminTaskCenterController.java"));
assertThat(count(controller, "dataReadScope.superAdminScopedUserIds(operator, companyId)"))
.as("看板 5 个端点都走同一个收窄出口")
.isEqualTo(5);
assertThat(controller)
.as("逐字重复的三元式与私有 isSuper 副本不得回流")
.doesNotContain("superAdmin ? dataReadScope.readScope(")
.doesNotContain("isSuper(");
}
@Test
void theThreeLegacyCopiesNowDelegate() {
for (String rel : List.of("modules/dedupe/service/DedupeTotalDataService.java",
"modules/taskcenter/service/TaskCenterScopeService.java",
"modules/permission/service/PermissionMenuService.java")) {
String text = read(mainRoot().resolve(rel));
assertThat(text)
.as(rel + " 必须转调 DeviceSessionPolicy,而不是自己比字面量")
.contains("DeviceSessionPolicy.isSuperAdmin(user.getRole(), user.getIsAdmin(), user.getCreatedById())");
}
}
private static int count(String text, String needle) {
int n = 0;
for (int i = text.indexOf(needle); i >= 0; i = text.indexOf(needle, i + needle.length())) {
n++;
}
return n;
}
private static List<Path> mainSources() {
Path root = mainRoot();
try (Stream<Path> walk = Files.walk(root)) {
List<Path> files = walk.filter(p -> p.toString().endsWith(".java")).toList();
// 扫描本身失效的形态是"目录在但一个文件都没扫到",那会让上面几支全部恒绿
assertThat(files).as("src/main 扫到的 .java 数").hasSizeGreaterThan(400);
return files;
} catch (IOException e) {
throw new IllegalStateException("扫描失败: " + root, e);
}
}
private static Path mainRoot() {
Path here = Path.of("").toAbsolutePath();
Path direct = here.resolve("src/main/java/com/nanri/aiimage");
if (Files.isDirectory(direct)) {
return direct;
}
Path nested = here.resolve("backend-java").resolve("src/main/java/com/nanri/aiimage");
if (Files.isDirectory(nested)) {
return nested;
}
throw new IllegalStateException("无法定位 backend-java 源码目录(cwd=" + here + ")");
}
private static String read(Path file) {
if (!Files.isRegularFile(file)) {
fail("找不到 " + file + " —— 用例依赖以 backend-java 为工作目录运行,别让扫描静默通过");
}
try {
// 判据一律打在「剥掉注释的代码」上:本类的 ROLE_LITERAL / PRIVATE_SUPERADMIN_COPY 是
// "必须不存在"那一形(注释里提一句就假红),而 superAdminOutletIsOneStaticPredicate…
// 与 theThreeLegacyCopiesNowDelegate 是"必须存在/次数等于 N"那一形(javadoc 里提一句
// 就喂饱 ⇒ 假绿,等于护栏没写)。两个方向一起吃原文,留哪个都是雷。
return SourceScan.withoutComments(Files.readString(file, StandardCharsets.UTF_8));
} catch (IOException e) {
throw new IllegalStateException("读取失败: " + file, e);
}
}
/**
* 负对照:剥注释这件事本身必须能红能绿。
*
* <p>上一轮就栽在"前提被自己的注释喂饱"上(护栏 javadoc 里抄了被扫的字面量,
* 于是"必须存在"的断言恒真)。这里把两种形状都过一遍:字面量只在注释里 ⇒ 0 命中;
* 落到真代码上 ⇒ 1 命中。少了后一半,剥注释写错成"整行都删"也能一路绿。</p>
*/
@Test
void commentTextFeedsNeitherShape() {
String proseOnly = """
class C {
/** 老形状别再写: "super_admin".equals(adminAuthSupport.currentRole(operator)) */
// private boolean isSuperAdmin(AdminUserEntity u) { return "super_admin".equals(r); }
void h() {
boolean b = DeviceSessionPolicy.isSuper(adminAuthSupport.currentRole(operator));
}
}
""";
String code = SourceScan.withoutComments(proseOnly);
assertThat(ROLE_LITERAL.matcher(code).find())
.as("注释里的字面量不得算命中(否则「必须不存在」那一形会假红)").isFalse();
assertThat(PRIVATE_SUPERADMIN_COPY.matcher(code).find()).isFalse();
assertThat(count(code, "DeviceSessionPolicy.isSuper(adminAuthSupport.currentRole("))
.as("注释被剥掉之后真代码必须还剩下来(否则计数恒 0,护栏假绿)").isEqualTo(1);
String realCode = """
class C {
void h() {
if ("super_admin".equals(adminAuthSupport.currentRole(operator))) { }
}
}
""";
assertThat(ROLE_LITERAL.matcher(SourceScan.withoutComments(realCode)).find())
.as("同一把正则必须抓得到真代码").isTrue();
// 字符串字面量里的 // 不是注释:口径写坏了会把整行吃掉,这里钉住
assertThat(SourceScan.withoutComments("String u = \"https://a\"; // tail").contains("https://a"))
.isTrue();
}
}
@@ -14,6 +14,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.nanri.aiimage.testutil.SourceScan;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@@ -112,16 +113,20 @@ import org.junit.jupiter.api.Test;
* D 的代价与射程一并交代:非 {@code Long} 型公司参数取不到绑定名,判红并报形状;而"handler 之外的私有
* 收口方法里把公司参数硬写成 {@code null}"这一族 D 看不见——块边界止于该 handler 自己的闭括号
* (第 7 条),{@code AdminImageVideoTaskController.scopeOf} 正是它,那一处是<b>故意</b>传 null 的。</li>
* <li><b>几条正门,一套判据</b>(批次 2/3 新增;10-06 复验后加第二道,批次 6 加第三道)。出口现在有三个:
* <li><b>几条正门,一套判据</b>(批次 2/3 新增;10-06 复验后加第二道,批次 6 加第三道,10-07 三期加第四道)。
* 出口现在有四个:
* {@code readScope(} 按账号集合给范围(去重库、查询 ASIN、最低价 ASIN、历史、视频),
* {@code readCompanyIdOrOwn(} 给"归属物化成 {@code company_id} 列、可见集又不靠账号/分组"的表
* (今天只有店铺密钥,V150 起每公司一套),{@code resolveScopeCompanyId(} 给菜单字典那一棵树一套
* (V149 起,读写共用同一判据,见 {@link #RESOLVE_MENU_SCOPE_CALL} 的理由)。
* 三道门共用 A/B/C/D 四条判据:
* (V149 起,读写共用同一判据,见 {@link #RESOLVE_MENU_SCOPE_CALL} 的理由),
* {@code superAdminScopedUserIds(} 给看板那一族"只在站点超管身上收窄"的形状
* (见 {@link #SUPER_SCOPED_USER_IDS_CALL} 的理由)。
* 四道门共用 A/B/C/D 四条判据:
* {@link #SCOPE_DOORS} 供 A 与 C 逐条跑,{@link #SCOPE_CALLEE_NAMES} 供 D 认被调名,
* <b>名单只写一次</b>(红因消息与自检断言咬的是拼出来的同一个标签,两处各写一遍会随哈希顺序漂红)。
* 每条门各自带能红/能绿两向探针(全局约束 15 那把尺子):只在 {@code readScope} 上验过,
* 等于第二道门上的返回值与入参没人看守;第三道门(菜单字典)的三枚 {@code MENU_SCOPE_*} 探针同理。
* 等于第二道门上的返回值与入参没人看守;第三道门(菜单字典)的三枚 {@code MENU_SCOPE_*} 探针同理,
* 第四道门的三枚 {@code SUPER_SCOPED_*} 也是照这一条补的。
* <p>批次 2 时这里还有<b>中间</b>那道 {@code readCompanyId(},服务品牌库 {@code biz_invalid_asin_data}
* 与商品类目 {@code biz_product_category} 两张物化列表。10-06 控制方把这两页定成全平台共享,
* 方法随之删除 ⇒ 门也从名单一起摘掉:名单里留一门没有实现者的门,等于给"把公司开关再接回那两张表"
@@ -240,8 +245,20 @@ class CompanyIdParamGoesThroughReadScopeTest {
* 公司(菜单字典没有"混着两家的树一起列"这种视图),非超管<b>传别家</b>时抛 403 而不是静默改成本公司。</p>
*/
private static final String RESOLVE_MENU_SCOPE_CALL = "resolveScopeCompanyId(";
/**
* 第四道正门(10-07 三期收口补):{@code superAdminScopedUserIds}。它补的是
* {@code AdminTaskCenterController} 那一族「看板五个 tab 只在站点超管身上收窄」的形状 ——
* 此前那五个 handler 体内各写一遍 {@code superAdmin ? readScope(user, companyId).userIdsOr(null) : null},
* 三元式与 {@code userIdsOr(null)} 都在页里;收成一个方法之后判据整体搬进了
* {@code DataReadScope},所以 handler 体内不再有 {@code readScope(}。
*
* <p>这道门开在 {@code DataReadScope} 上、不是 controller 里的 if,前提与第二、三门同一条。
* 不加它的话 A 会把这五支合规 handler 判红;只加名字不配探针的话,这道门上的返回值与入参没人看守
* (全局约束 15),所以正/负两向证据在下面各给一遍。</p>
*/
private static final String SUPER_SCOPED_USER_IDS_CALL = "superAdminScopedUserIds(";
private static final List<String> SCOPE_DOORS =
List.of(READ_SCOPE_CALL, READ_OWN_COMPANY_ID_CALL, RESOLVE_MENU_SCOPE_CALL);
List.of(READ_SCOPE_CALL, READ_OWN_COMPANY_ID_CALL, RESOLVE_MENU_SCOPE_CALL, SUPER_SCOPED_USER_IDS_CALL);
private static final String EXPLICIT_PARAM_NAME = "name = \"company_id\"";
private static final String SNAKE_PARAM = "company_id";
private static final String CAMEL_PARAM = "companyId";
@@ -284,11 +301,13 @@ class CompanyIdParamGoesThroughReadScopeTest {
"if", "for", "while", "switch", "do", "catch", "synchronized", "return", "throw", "else", "try");
/**
* 断言 D 认的四个被调名:{@code readScope} 是按账号集合给范围的唯一出口,
* 断言 D 认的五个被调名:{@code readScope} 是按账号集合给范围的唯一出口,
* {@code resolveScope} 是 Task 11 模板鼓励的"controller 里的私有收口方法"那一形(它内部再去
* readScope),{@code readCompanyIdOrOwn} 是"归属物化成 {@code company_id} 列、可见集不靠账号/分组"
* 那一族表(今天只有店铺密钥)的正门(见 {@link #READ_OWN_COMPANY_ID_CALL} 的理由),
* {@code resolveScopeCompanyId} 是菜单字典那一棵树一套的归属判据(见 {@link #RESOLVE_MENU_SCOPE_CALL} 的理由)。
* {@code resolveScopeCompanyId} 是菜单字典那一棵树一套的归属判据(见 {@link #RESOLVE_MENU_SCOPE_CALL} 的理由),
* {@code superAdminScopedUserIds} 是看板那一族"只在站点超管身上收窄"的正门
* (见 {@link #SUPER_SCOPED_USER_IDS_CALL} 的理由)。
* 除此之外的调用都不算"把公司参数交给了出口"——尤其 {@code readScope(operator, null)} 里那个 {@code null}。
*/
private static final String RESOLVE_SCOPE_CALL = "resolveScope(";
@@ -298,7 +317,8 @@ class CompanyIdParamGoesThroughReadScopeTest {
* 那就等于一条会自己漂红的用例。
*/
private static final List<String> SCOPE_CALLEE_NAMES =
List.of("readScope", "resolveScope", "readCompanyIdOrOwn", "resolveScopeCompanyId");
List.of("readScope", "resolveScope", "readCompanyIdOrOwn", "resolveScopeCompanyId",
"superAdminScopedUserIds");
private static final Set<String> SCOPE_CALLEES = Set.copyOf(SCOPE_CALLEE_NAMES);
private static final String SCOPE_CALLEE_LABEL = String.join("/", SCOPE_CALLEE_NAMES);
@@ -523,10 +543,42 @@ class CompanyIdParamGoesThroughReadScopeTest {
}
""";
/**
* 第四道正门的<b>正探针</b>(形状逐字抄现网 {@code AdminTaskCenterController.overview}):
* 结果接进变量、又作为实参交给 {@code resolveScope(…)},公司参数本身进了门 ⇒ C 与 D 都必须判绿。
*/
private static final String SUPER_SCOPED_CAUGHT_PROBE = """
@GetMapping("/probe")
public String superScopedDoor(@RequestParam(name = "company_id", required = false) Long companyId) {
AdminUserEntity operator = session.operator();
List<Long> companyUserIds = dataReadScope.superAdminScopedUserIds(operator, companyId);
return String.valueOf(taskCenterScopeService.resolve(resolveScope(operatorId, companyUserIds)));
}
""";
/** 第四道正门的<b>裸语句探针</b>(C 在该门上的"能红"证据):门调了,收窄集当场丢掉。 */
private static final String SUPER_SCOPED_DISCARD_PROBE = """
@GetMapping("/probe")
public String superScopedDoorDiscard(@RequestParam(name = "company_id", required = false) Long companyId) {
dataReadScope.superAdminScopedUserIds(operator, companyId);
return "ok";
}
""";
/** 第四道正门的<b>负探针</b>(D 在该门上的存在理由):切了 tab,传进门里的还是 {@code null}。 */
private static final String SUPER_SCOPED_PASSED_NULL_PROBE = """
@GetMapping("/probe")
public String superScopedDoorNull(@RequestParam(name = "company_id", required = false) Long companyId) {
AdminUserEntity operator = session.operator();
List<Long> companyUserIds = dataReadScope.superAdminScopedUserIds(operator, null);
return String.valueOf(taskCenterScopeService.resolve(resolveScope(operatorId, companyUserIds)));
}
""";
/**
* 已摘掉那道门的<b>正样本探针</b>(形状抄退回前的 {@code InvalidAsinDataController.page}:
* 收 {@code company_id} 参数、体内调 {@code readCompanyId})。它现在应当被 A/C/D 三条同时判红——
* 红因必须落在"三条正门都没走"上,而不是"这段源码没被切成 handler"。
* 红因必须落在"一条正门都没走"上,而不是"这段源码没被切成 handler"。
*/
private static final String RETIRED_DOOR_WIRED_PROBE = """
@GetMapping("/probe")
@@ -711,6 +763,30 @@ class CompanyIdParamGoesThroughReadScopeTest {
.isNotNull()
.contains("没进任何 " + SCOPE_CALLEE_LABEL + " 的实参列表");
// 第四道门(看板超管收窄集)也两向取证:它今天有五个真实消费者(AdminTaskCenterController 的
// overview / shop-options / tasks / tasks-detail / variant-tasks)。只把名字加进 SCOPE_DOORS
// 而不验返回值与入参,这道门就是"名单里有、没人守"——上一轮 A 之所以红,正是因为名单先到、
// 探针没到,这道门上的 companyUserIds 哪天被丢掉或传成 null,C 与 D 都不求值。
assertThat(scopeProbeReason(SUPER_SCOPED_CAUGHT_PROBE, "SUPER_SCOPED_CAUGHT_PROBE"))
.as("断言 C 自检(第四道门·正样本):List<Long> companyUserIds = superAdminScopedUserIds(operator, companyId) "
+ "且它进了 resolveScope(…) 的实参 ⇒ 判红就是护栏假红")
.isNull();
assertThat(companyIdArgProbeReason(SUPER_SCOPED_CAUGHT_PROBE, "SUPER_SCOPED_CAUGHT_PROBE", CAMEL_PARAM))
.as("断言 D 自检(第四道门·正样本):companyId 真进了 superAdminScopedUserIds 的实参表 ⇒ 不许红")
.isNull();
assertThat(scopeProbeReason(SUPER_SCOPED_DISCARD_PROBE, "SUPER_SCOPED_DISCARD_PROBE"))
.as("断言 C 自检(第四道门·负样本):superAdminScopedUserIds( 写成裸语句、收窄集当场丢掉 ⇒ 必须判红")
.isNotNull()
.contains("范围算了但没接住");
assertThat(scopeProbeReason(SUPER_SCOPED_PASSED_NULL_PROBE, "SUPER_SCOPED_PASSED_NULL_PROBE"))
.as("断言 D(第四道门)负样本的前提(断言 C):结果接进 companyUserIds 又喂给了 resolveScope ⇒ C 判它绿")
.isNull();
assertThat(companyIdArgProbeReason(
SUPER_SCOPED_PASSED_NULL_PROBE, "SUPER_SCOPED_PASSED_NULL_PROBE", CAMEL_PARAM))
.as("断言 D 自检(第四道门·负样本):superAdminScopedUserIds(operator, null) ⇒ 必须判红")
.isNotNull()
.contains("没进任何 " + SCOPE_CALLEE_LABEL + " 的实参列表");
// 已摘掉的那道门不许再接回(全局约束 15 的"能红"方向)。这一族 handler(品牌库、商品类目)现在定案
// 全平台共享、不再收公司参数 ⇒ 它们已不进 A/C/D 的样本,"哪天有人把 ?company_id= 接回这两张表"
// 只剩这条探针还在求值,而今天真正拦它的是断言 A:C 与 D 在主循环里都以"体内有正门调用"为前提
@@ -1643,7 +1719,9 @@ class CompanyIdParamGoesThroughReadScopeTest {
private static String read(Path path) {
try {
return new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
// 尾随注释也要剥:{@link #sourceLines} 只丢整行注释,`service.list(…); // readScope( 已接`
// 这种一行里"代码 + 注释"的形状会同时喂 A/C(注释里的门名让 A 判绿=假绿)。
return SourceScan.withoutComments(new String(Files.readAllBytes(path), StandardCharsets.UTF_8));
} catch (IOException e) {
throw new IllegalStateException("读不到 " + path, e);
}