feat: 接入 iOSGuard LLVM 混淆工具链与 IPA 加固门禁,按分支策略兼容旧版本打包
- 新增 toolchain_manager:构建前自愈校验 LLVM opt 工具链,按 Xcode 版本与渠道隔离 obj_cache - readoor31/readoor31OtherPay Archive 透传 IG_DIST_CHANNEL/IG_OBF_MODE/IG_ALL_GUARD_OFF/IG_RELEASE_SEED - Archive 前核对分发渠道编译条件:上架包缺失 IG_APPSTORE_DISTRIBUTION 即阻断,非上架包带该条件仅告警,未接入 anti_tamper 的分支跳过 - 导出后执行 IPA 加固门禁审计,失败阻断上传;持久化 dSYM、混淆映射、诊断事件码与审计报告 - 混淆是否执行改由分支 AutoPacking/build_policy.json 声明:force_obfuscation=true 强制,否则按任务勾选,兼容旧分支/旧 Tag;恢复打包页混淆勾选框 - 分支未自带混淆脚本时回退服务端脚本并告警;同步更新服务端 L1 混淆脚本 - .gitignore 忽略 iosguard_cache 与 artifacts 运行时目录;README 补充分支打包策略说明
This commit is contained in:
@@ -710,3 +710,354 @@ def test_mark_superseded_tasks_for_same_oss_url():
|
||||
assert db.get(Task, "old").superseded_at is not None
|
||||
assert db.get(Task, "latest").superseded_at is None
|
||||
db.close()
|
||||
|
||||
|
||||
async def test_build_project_iosguard_require_obf_and_persistent_cache(tmp_path, monkeypatch):
|
||||
"""开启 IR 混淆时调用自愈工具链校验,按版本与分发渠道隔离 obj_cache,并注入 IG_DIST_CHANNEL。"""
|
||||
from backend.services.build_service import _prepare_iosguard_build_env
|
||||
|
||||
build_dir = tmp_path / "build_snap"
|
||||
resolver = build_dir / "iOSGuardIntegration" / "toolchain" / "tools" / "llvm_obf" / "ig_toolchain_resolver.py"
|
||||
resolver.parent.mkdir(parents=True)
|
||||
resolver.write_text("# resolver stub\n", encoding="utf-8")
|
||||
|
||||
cache_root = tmp_path / "ig_cache"
|
||||
tc_cache_root = cache_root / "toolchains"
|
||||
stale_obj_dir = cache_root / "obj_cache" / "26A100-old1"
|
||||
stale_obj_dir.mkdir(parents=True)
|
||||
os.utime(stale_obj_dir, (1_600_000_000, 1_600_000_000))
|
||||
for i, old_name in enumerate(("26B200-old2", "26C300-old3", "26D400-old4")):
|
||||
d = cache_root / "obj_cache" / old_name
|
||||
d.mkdir(parents=True)
|
||||
os.utime(d, (1_700_000_000 + i * 10, 1_700_000_000 + i * 10))
|
||||
monkeypatch.delenv("IG_OBF_MODE", raising=False)
|
||||
monkeypatch.delenv("IG_ALL_GUARD_OFF", raising=False)
|
||||
monkeypatch.delenv("IG_RELEASE_SEED", raising=False)
|
||||
monkeypatch.delenv("IG_OBF_OBJ_CACHE_DIR", raising=False)
|
||||
monkeypatch.delenv("IG_SDK_CACHE_DIR", raising=False)
|
||||
|
||||
mock_tc = {
|
||||
"opt_path": "/opt/bin/opt",
|
||||
"source_mode": "cached",
|
||||
"xcode": {"xcode_build": "27A9275"},
|
||||
"passes_hash": "b3a4000211223344",
|
||||
}
|
||||
with patch("backend.services.build_service.IG_CACHE_DIR", cache_root), \
|
||||
patch("backend.services.build_service.IG_TOOLCHAIN_CACHE_DIR", tc_cache_root), \
|
||||
patch("backend.services.build_service.ensure_toolchain", new_callable=AsyncMock, return_value=mock_tc) as mock_ensure:
|
||||
env = await _prepare_iosguard_build_env(
|
||||
"task-m3-1",
|
||||
{"BUILD_VERSION": "3.1.0.5", "BUILD_TYPE": "App_Store"},
|
||||
build_dir,
|
||||
)
|
||||
|
||||
assert env["IG_REQUIRE_LLVM_OBF"] == "1"
|
||||
assert env["IG_OBF_MODE"] == "full"
|
||||
assert env["IG_DIST_CHANNEL"] == "appstore"
|
||||
assert env["IG_RELEASE_SEED"] == "task-m3-1_3.1.0.5"
|
||||
assert env["IG_TOOLCHAIN_CACHE_DIR"] == str(tc_cache_root)
|
||||
assert env["IG_OBF_OBJ_CACHE_DIR"] == str(cache_root / "obj_cache" / "27A9275-b3a40002" / "appstore")
|
||||
assert env["IG_SDK_CACHE_DIR"] == str(cache_root / "sdk_cache")
|
||||
assert Path(env["IG_OBF_OBJ_CACHE_DIR"]).is_dir()
|
||||
assert Path(env["IG_SDK_CACHE_DIR"]).is_dir()
|
||||
assert mock_ensure.call_args.args == (resolver,)
|
||||
# 超过 keep=3 的最旧 obj_cache 目录被自动清理
|
||||
assert not stale_obj_dir.exists()
|
||||
|
||||
with patch("backend.services.build_service.IG_CACHE_DIR", cache_root), \
|
||||
patch("backend.services.build_service.IG_TOOLCHAIN_CACHE_DIR", tc_cache_root), \
|
||||
patch("backend.services.build_service.ensure_toolchain", new_callable=AsyncMock, side_effect=RuntimeError("hash mismatch")):
|
||||
with pytest.raises(BuildError, match="LLVM IR 混淆工具链校验失败"):
|
||||
await _prepare_iosguard_build_env("task-m3-1", {"BUILD_VERSION": "3.1.0.5"}, build_dir)
|
||||
|
||||
# IG_OBF_MODE=off 与 IG_ALL_GUARD_OFF=1 跳过 opt 校验
|
||||
for extra_env in ({"IG_OBF_MODE": "off"}, {"IG_ALL_GUARD_OFF": "1"}):
|
||||
for k, v in extra_env.items():
|
||||
monkeypatch.setenv(k, v)
|
||||
with patch("backend.services.build_service.IG_CACHE_DIR", cache_root), \
|
||||
patch("backend.services.build_service.IG_TOOLCHAIN_CACHE_DIR", tc_cache_root), \
|
||||
patch("backend.services.build_service.ensure_toolchain", new_callable=AsyncMock) as should_not_run:
|
||||
off_env = await _prepare_iosguard_build_env("task-m3-off", {"BUILD_VERSION": "3.1.0.5"}, build_dir)
|
||||
assert should_not_run.call_count == 0
|
||||
assert off_env["IG_OBF_MODE"] == "off"
|
||||
assert "IG_REQUIRE_LLVM_OBF" not in off_env
|
||||
for k in extra_env:
|
||||
monkeypatch.delenv(k, raising=False)
|
||||
|
||||
|
||||
async def test_run_obfuscation_prefers_branch_scripts_and_falls_back(tmp_path, log_streamer):
|
||||
"""L1 优先执行分支内的 AutoPacking/obfuscation,旧分支缺少时回退到服务端 AUTOMATION_DIR。"""
|
||||
from backend.services.build_service import run_obfuscation
|
||||
|
||||
build_dir = tmp_path / "snap"
|
||||
branch_obf = build_dir / "AutoPacking" / "obfuscation"
|
||||
(branch_obf / "scripts").mkdir(parents=True)
|
||||
branch_check = branch_obf / "scripts" / "obfuscation_self_check.sh"
|
||||
branch_obf_py = branch_obf / "obfuscate_symbols.py"
|
||||
branch_check.write_text("#!/bin/sh\nexit 0\n", encoding="utf-8")
|
||||
branch_obf_py.write_text("# branch obf\n", encoding="utf-8")
|
||||
|
||||
fallback_root = tmp_path / "server_auto"
|
||||
(fallback_root / "obfuscation" / "scripts").mkdir(parents=True)
|
||||
fb_check = fallback_root / "obfuscation" / "scripts" / "obfuscation_self_check.sh"
|
||||
fb_py = fallback_root / "obfuscation" / "obfuscate_symbols.py"
|
||||
fb_check.write_text("#!/bin/sh\nexit 0\n", encoding="utf-8")
|
||||
fb_py.write_text("# fallback obf\n", encoding="utf-8")
|
||||
|
||||
with patch("backend.services.build_service.AUTOMATION_DIR", fallback_root), \
|
||||
patch("asyncio.create_subprocess_exec", return_value=_make_mock_process()) as mock_exec:
|
||||
await run_obfuscation("t-branch", MagicMock(), {"SCHEME": "readoor31OtherPay", "BUILD_VERSION": "1.0.0.1"}, build_dir)
|
||||
assert mock_exec.call_args_list[0].args[1] == str(branch_check)
|
||||
assert mock_exec.call_args_list[1].args[1] == str(branch_obf_py)
|
||||
|
||||
# 移除分支脚本后回退到服务端脚本
|
||||
branch_obf_py.unlink()
|
||||
with patch("backend.services.build_service.AUTOMATION_DIR", fallback_root), \
|
||||
patch("asyncio.create_subprocess_exec", return_value=_make_mock_process()) as mock_exec_fb:
|
||||
await run_obfuscation("t-fb", MagicMock(), {"SCHEME": "readoor31OtherPay", "BUILD_VERSION": "1.0.0.1"}, build_dir)
|
||||
assert mock_exec_fb.call_args_list[0].args[1] == str(fb_check)
|
||||
assert mock_exec_fb.call_args_list[1].args[1] == str(fb_py)
|
||||
|
||||
|
||||
async def test_build_project_passes_dist_channel_and_blocks_on_audit_failure(tmp_path, log_streamer):
|
||||
"""App_Store 向 xcodebuild archive 透传 IG_DIST_CHANNEL=appstore,并在导出审计失败时阻断上传。"""
|
||||
build_dir = tmp_path / "snap"
|
||||
(build_dir / "readoor.xcworkspace").mkdir(parents=True)
|
||||
(build_dir / "exportOptions.plist").write_text("<plist/>", encoding="utf-8")
|
||||
audit_script = build_dir / "iOSGuardIntegration" / "toolchain" / "tools" / "xcode_archive" / "audit_exported_ipa.py"
|
||||
audit_script.parent.mkdir(parents=True)
|
||||
audit_script.write_text("# audit stub\n", encoding="utf-8")
|
||||
|
||||
out_dir = build_dir / "build"
|
||||
out_dir.mkdir(parents=True)
|
||||
(out_dir / "readoor31OtherPay.ipa").write_bytes(b"PK")
|
||||
|
||||
mock_audit_fail = _make_mock_process(returncode=1, output=b"StaticHygieneGate FAILED\n")
|
||||
mock_audit_fail.wait = AsyncMock(return_value=1)
|
||||
|
||||
calls = []
|
||||
|
||||
async def exec_side_effect(*args, **kwargs):
|
||||
calls.append(args)
|
||||
if len(args) > 1 and str(audit_script) in args:
|
||||
return mock_audit_fail
|
||||
return _make_mock_process(0)
|
||||
|
||||
tc_info = {"opt_path": "/opt/bin/opt", "source_mode": "cached", "xcode": {"xcode_build": "27A9275"}, "passes_hash": "abc"}
|
||||
with patch("backend.services.build_service.IG_CACHE_DIR", tmp_path / "cache"), \
|
||||
patch("backend.services.build_service.IG_TOOLCHAIN_CACHE_DIR", tmp_path / "cache" / "toolchains"), \
|
||||
patch("backend.services.build_service.ensure_toolchain", new_callable=AsyncMock, return_value=tc_info), \
|
||||
patch("asyncio.create_subprocess_exec", side_effect=exec_side_effect):
|
||||
with pytest.raises(BuildError, match="IPA 加固门禁审计失败"):
|
||||
await build_project(
|
||||
"t-appstore",
|
||||
MagicMock(),
|
||||
{"SCHEME": "readoor31OtherPay", "BUILD_TYPE": "App_Store", "BUILD_VERSION": "3.1.0.1", "BUNDLE_ID": "com.test.app"},
|
||||
build_dir,
|
||||
{"workspace": "readoor.xcworkspace"},
|
||||
)
|
||||
|
||||
archive_cmd = next(c for c in calls if len(c) > 1 and c[0] == "xcodebuild" and c[1] == "archive")
|
||||
assert "IG_DIST_CHANNEL=appstore" in archive_cmd
|
||||
audit_cmd = next(c for c in calls if str(audit_script) in c)
|
||||
assert "--archive" in audit_cmd and "--bundle-id" in audit_cmd and "--report-out" in audit_cmd
|
||||
|
||||
|
||||
def _dist_channel_snapshot(tmp_path):
|
||||
"""构造接入了 anti_tamper 的源码快照(pbxproj 引用 IGAntiTamper.c)。"""
|
||||
build_dir = tmp_path / "snap"
|
||||
(build_dir / "readoor.xcworkspace").mkdir(parents=True)
|
||||
(build_dir / "readoor.xcodeproj").mkdir()
|
||||
(build_dir / "readoor.xcodeproj" / "project.pbxproj").write_text(
|
||||
"/* IGAntiTamper.c in Sources */", encoding="utf-8"
|
||||
)
|
||||
(build_dir / "exportOptions.plist").write_text("<plist/>", encoding="utf-8")
|
||||
return build_dir
|
||||
|
||||
|
||||
def _dist_env(channel):
|
||||
return {"IG_DIST_CHANNEL": channel, "IG_OBF_MODE": "full", "IG_ALL_GUARD_OFF": "0", "IG_RELEASE_SEED": "s"}
|
||||
|
||||
|
||||
def _dist_exec(calls, settings_output):
|
||||
async def exec_side_effect(*args, **kwargs):
|
||||
calls.append(args)
|
||||
if len(args) > 1 and args[1] == "-showBuildSettings":
|
||||
return _make_mock_process(0, settings_output)
|
||||
return _make_mock_process(0)
|
||||
return exec_side_effect
|
||||
|
||||
|
||||
async def test_appstore_build_blocked_when_dist_flag_missing(tmp_path):
|
||||
"""上架包 showBuildSettings 中没有 IG_APPSTORE_DISTRIBUTION 时,Archive 前阻断。"""
|
||||
build_dir = _dist_channel_snapshot(tmp_path)
|
||||
calls = []
|
||||
output = b" OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS -D TARGETTYPE_7\n"
|
||||
with patch("asyncio.create_subprocess_exec", side_effect=_dist_exec(calls, output)):
|
||||
with pytest.raises(BuildError, match="未注入 IG_APPSTORE_DISTRIBUTION"):
|
||||
await build_project(
|
||||
"t-miss", MagicMock(),
|
||||
{"SCHEME": "readoor31", "BUILD_TYPE": "App_Store"},
|
||||
build_dir, {"workspace": "readoor.xcworkspace"}, prepared_env=_dist_env("appstore"),
|
||||
)
|
||||
settings_cmd = next(c for c in calls if c[1] == "-showBuildSettings")
|
||||
assert "IG_DIST_CHANNEL=appstore" in settings_cmd and "Release" in settings_cmd
|
||||
assert not any(c[1] == "archive" for c in calls)
|
||||
|
||||
|
||||
async def test_appstore_build_passes_when_dist_flag_present(tmp_path):
|
||||
"""上架包已注入 -DIG_APPSTORE_DISTRIBUTION 时正常进入 Archive。"""
|
||||
build_dir = _dist_channel_snapshot(tmp_path)
|
||||
calls = []
|
||||
output = b" OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS -DIG_APPSTORE_DISTRIBUTION\n"
|
||||
with patch("asyncio.create_subprocess_exec", side_effect=_dist_exec(calls, output)):
|
||||
with pytest.raises(Exception, match="未找到 IPA 文件"):
|
||||
await build_project(
|
||||
"t-ok", MagicMock(),
|
||||
{"SCHEME": "readoor31OtherPay", "BUILD_TYPE": "App_Store"},
|
||||
build_dir, {"workspace": "readoor.xcworkspace"}, prepared_env=_dist_env("appstore"),
|
||||
)
|
||||
assert any(c[1] == "archive" for c in calls)
|
||||
|
||||
|
||||
async def test_adhoc_build_warns_when_dist_flag_hardcoded(tmp_path):
|
||||
"""非上架包仍带写死的分发条件时只告警、不阻断。"""
|
||||
build_dir = _dist_channel_snapshot(tmp_path)
|
||||
calls = []
|
||||
output = b" SWIFT_ACTIVE_COMPILATION_CONDITIONS = TARGETTYPE_7 IG_APPSTORE_DISTRIBUTION\n"
|
||||
with patch("asyncio.create_subprocess_exec", side_effect=_dist_exec(calls, output)), \
|
||||
patch("backend.services.build_service.log_streamer", new=AsyncMock()) as mock_ls:
|
||||
with pytest.raises(Exception, match="未找到 IPA 文件"):
|
||||
await build_project(
|
||||
"t-adhoc", MagicMock(),
|
||||
{"SCHEME": "readoor31", "BUILD_TYPE": "Ad_Hoc"},
|
||||
build_dir, {"workspace": "readoor.xcworkspace"}, prepared_env=_dist_env("dev"),
|
||||
)
|
||||
assert any(c[1] == "archive" for c in calls)
|
||||
warning_text = " ".join(str(call.args[1]) for call in mock_ls.emit_warning.call_args_list)
|
||||
assert "IG_APPSTORE_DISTRIBUTION" in warning_text
|
||||
|
||||
|
||||
async def test_dist_flag_check_skipped_without_anti_tamper(tmp_path):
|
||||
"""未接入 anti_tamper 的历史分支不做渠道核对。"""
|
||||
build_dir = _dist_channel_snapshot(tmp_path)
|
||||
(build_dir / "readoor.xcodeproj" / "project.pbxproj").write_text("/* legacy */", encoding="utf-8")
|
||||
calls = []
|
||||
with patch("asyncio.create_subprocess_exec", side_effect=_dist_exec(calls, b"")):
|
||||
with pytest.raises(Exception, match="未找到 IPA 文件"):
|
||||
await build_project(
|
||||
"t-legacy", MagicMock(),
|
||||
{"SCHEME": "readoor31", "BUILD_TYPE": "App_Store"},
|
||||
build_dir, {"workspace": "readoor.xcworkspace"}, prepared_env=_dist_env("appstore"),
|
||||
)
|
||||
assert not any(c[1] == "-showBuildSettings" for c in calls)
|
||||
|
||||
|
||||
def test_persist_task_artifacts_survives_build_dir_cleanup(tmp_path):
|
||||
"""_cleanup_build_dir 销毁 build_dir 后,dSYM(含 IGArchiveGuard)、映射表、事件码与混淆审计仍保留在 ARTIFACTS_DIR。"""
|
||||
from backend.services.build_service import persist_task_artifacts, _cleanup_build_dir
|
||||
|
||||
build_dir = tmp_path / "build_snap"
|
||||
artifacts_root = tmp_path / "artifacts"
|
||||
|
||||
dsym_app = build_dir / "build" / "readoor31.xcarchive" / "dSYMs" / "readoor31.app.dSYM" / "Contents" / "Resources" / "DWARF"
|
||||
dsym_fw = build_dir / "build" / "readoor31.xcarchive" / "dSYMs" / "IGArchiveGuard.framework.dSYM" / "Contents" / "Resources" / "DWARF"
|
||||
dsym_app.mkdir(parents=True)
|
||||
dsym_fw.mkdir(parents=True)
|
||||
(dsym_app / "readoor31").write_bytes(b"app-dwarf")
|
||||
(dsym_fw / "IGArchiveGuard").write_bytes(b"fw-dwarf")
|
||||
|
||||
maps_src = build_dir / "obfuscation_maps"
|
||||
maps_src.mkdir(parents=True)
|
||||
(maps_src / "symbol_map_readoor31_20261119.json").write_text('{"schema_version": 2}', encoding="utf-8")
|
||||
(maps_src / "method_map_readoor31_20261119.json").write_text('{"schema_version": 2}', encoding="utf-8")
|
||||
|
||||
cfg_dir = build_dir / "iOSGuardIntegration" / "toolchain" / "config"
|
||||
cfg_dir.mkdir(parents=True)
|
||||
(cfg_dir / "ig_diag_events.json").write_text('{"events": []}', encoding="utf-8")
|
||||
|
||||
audit_path = build_dir / "build" / "derived_data" / "Intermediates.noindex" / "readoor31.build" / "ig-route2-audit" / "ig_obfuscation_audit.json"
|
||||
audit_path.parent.mkdir(parents=True)
|
||||
audit_path.write_text('{"total_flattened": 65}', encoding="utf-8")
|
||||
|
||||
ipa_report = build_dir / "build" / "ipa_audit_report.json"
|
||||
ipa_report.write_text('{"passed": true}', encoding="utf-8")
|
||||
|
||||
with patch("backend.services.build_service.ARTIFACTS_DIR", artifacts_root):
|
||||
p_dsym, p_maps = persist_task_artifacts("task-persist-1", build_dir, "readoor31")
|
||||
|
||||
_cleanup_build_dir(build_dir)
|
||||
assert not build_dir.exists()
|
||||
assert p_dsym is not None and p_dsym.is_dir()
|
||||
assert (p_dsym / "readoor31.app.dSYM" / "Contents" / "Resources" / "DWARF" / "readoor31").is_file()
|
||||
assert (p_dsym / "IGArchiveGuard.framework.dSYM" / "Contents" / "Resources" / "DWARF" / "IGArchiveGuard").is_file()
|
||||
assert p_maps is not None and p_maps.is_dir()
|
||||
assert (p_maps / "symbol_map_readoor31_20261119.json").is_file()
|
||||
assert (p_maps / "method_map_readoor31_20261119.json").is_file()
|
||||
assert (p_maps / "ig_diag_events.json").is_file()
|
||||
assert (p_maps / "ig_obfuscation_audit.json").is_file()
|
||||
assert (p_maps / "ipa_audit_report.json").is_file()
|
||||
|
||||
|
||||
def test_get_definition_backfills_iosguard_integration_copy_items():
|
||||
from backend.projects import get_definition
|
||||
|
||||
defn = get_definition("readoor", {"patcher": "readoor", "copy_items": ["readoor", "readoor.xcodeproj"]})
|
||||
assert "iOSGuardIntegration" in defn["copy_items"]
|
||||
|
||||
|
||||
# ---- 分支打包策略:是否混淆 ----
|
||||
|
||||
def _policy_snapshot(tmp_path, policy_text=None, with_scripts=False):
|
||||
build_dir = tmp_path / "snap"
|
||||
build_dir.mkdir(parents=True)
|
||||
if with_scripts:
|
||||
obf = build_dir / "AutoPacking" / "obfuscation"
|
||||
(obf / "scripts").mkdir(parents=True)
|
||||
(obf / "obfuscate_symbols.py").write_text("# obf", encoding="utf-8")
|
||||
(obf / "scripts" / "obfuscation_self_check.sh").write_text("exit 0", encoding="utf-8")
|
||||
if policy_text is not None:
|
||||
(build_dir / "AutoPacking").mkdir(exist_ok=True)
|
||||
(build_dir / "AutoPacking" / "build_policy.json").write_text(policy_text, encoding="utf-8")
|
||||
return build_dir
|
||||
|
||||
|
||||
@pytest.mark.parametrize("task_obf", [True, False])
|
||||
def test_obfuscation_forced_when_branch_policy_declares(tmp_path, task_obf):
|
||||
"""分支 build_policy.json 声明 force_obfuscation=true 时,无视任务勾选强制混淆。"""
|
||||
from backend.services.build_service import _resolve_obfuscation_decision
|
||||
build_dir = _policy_snapshot(tmp_path, '{"force_obfuscation": true}', with_scripts=True)
|
||||
run, reason = _resolve_obfuscation_decision(build_dir, {"obfuscation": True}, MagicMock(obfuscation=task_obf))
|
||||
assert run is True
|
||||
assert "声明强制混淆" in reason
|
||||
|
||||
|
||||
@pytest.mark.parametrize("task_obf", [True, False])
|
||||
def test_old_tag_with_scripts_but_no_policy_follows_task_choice(tmp_path, task_obf):
|
||||
"""2.195.0 起的旧 Tag 带混淆脚本但无策略文件:按任务勾选,不因脚本存在而强制。"""
|
||||
from backend.services.build_service import _resolve_obfuscation_decision
|
||||
build_dir = _policy_snapshot(tmp_path, None, with_scripts=True)
|
||||
run, reason = _resolve_obfuscation_decision(build_dir, {"obfuscation": True}, MagicMock(obfuscation=task_obf))
|
||||
assert run is task_obf
|
||||
assert "按任务勾选" in reason
|
||||
|
||||
|
||||
@pytest.mark.parametrize("policy_text", [
|
||||
'{"force_obfuscation": false}',
|
||||
'{"force_obfuscation": "true"}', # 非布尔 true 不算声明
|
||||
"{broken json",
|
||||
"[true]",
|
||||
])
|
||||
def test_non_forcing_or_invalid_policy_follows_task_choice(tmp_path, policy_text):
|
||||
from backend.services.build_service import _resolve_obfuscation_decision
|
||||
build_dir = _policy_snapshot(tmp_path, policy_text)
|
||||
run, _ = _resolve_obfuscation_decision(build_dir, {"obfuscation": True}, MagicMock(obfuscation=False))
|
||||
assert run is False
|
||||
|
||||
|
||||
def test_unsupported_project_never_obfuscates_even_if_policy_forces(tmp_path):
|
||||
from backend.services.build_service import _resolve_obfuscation_decision
|
||||
build_dir = _policy_snapshot(tmp_path, '{"force_obfuscation": true}')
|
||||
run, reason = _resolve_obfuscation_decision(build_dir, {"obfuscation": False}, MagicMock(obfuscation=True))
|
||||
assert run is False
|
||||
assert "不支持" in reason
|
||||
|
||||
Reference in New Issue
Block a user