From fcc7863b314463ef3dd73a316af7b42077893ee9 Mon Sep 17 00:00:00 2001 From: saas-backend-agent Date: Mon, 7 Sep 2026 22:35:49 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20#1765=20generate=5Fpixel=5Fperturbat?= =?UTF-8?q?ion=20=E6=94=AF=E6=8C=81=20int=20seed=20=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 与 get_rhythm_template(seed) 接口保持一致:传入 int 时自动构造 random.Random(seed),保证基于 variantSeed 可复现;Random 对象和 None 调用方式不变。 --- packages/domain/variant_plan_selector.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/domain/variant_plan_selector.py b/packages/domain/variant_plan_selector.py index 1bd09cde7..d40fd6267 100644 --- a/packages/domain/variant_plan_selector.py +++ b/packages/domain/variant_plan_selector.py @@ -129,7 +129,10 @@ def reselect_clips_for_variant( Raises: ValueError: 源片段为空 / 素材池为空 / 素材时长全为 0(无法差异化选片)。 """ - rng = rng or random.Random() + if rng is None: + rng = random.Random() + elif isinstance(rng, int): + rng = random.Random(rng) if not source_clips: raise ValueError("源 plan 无片段,无法为变体重新选片") if not candidate_asset_ids: @@ -312,7 +315,10 @@ def generate_visual_perturbation(rng: random.Random | None = None) -> dict: - speed_factor: 0.95~1.05 速度微调(±5%,肉眼不太敏感但时间轴不同) - brightness_shift: -10~+10 亮度偏移(eq=brightness,画面明暗差异) """ - rng = rng or random.Random() + if rng is None: + rng = random.Random() + elif isinstance(rng, int): + rng = random.Random(rng) return { "hflip": rng.random() < 0.3, "zoom_ratio": round(1.0 + rng.uniform(0, 0.08), 4), @@ -321,7 +327,7 @@ def generate_visual_perturbation(rng: random.Random | None = None) -> dict: } -def generate_pixel_perturbation(rng: random.Random | None = None) -> dict: +def generate_pixel_perturbation(rng: random.Random | int | None = None) -> dict: """为一个变体生成像素级扰动滤镜参数(Issue #1765)。 在现有视觉扰动(hflip/zoom/brightness)基础上,额外叠加 2-3 种 @@ -336,7 +342,10 @@ def generate_pixel_perturbation(rng: random.Random | None = None) -> dict: 返回 dict,可直接存入 plan.config["pixel_perturbation"]。 渲染侧读取后追加到 ffmpeg filter chain。 """ - rng = rng or random.Random() + if rng is None: + rng = random.Random() + elif isinstance(rng, int): + rng = random.Random(rng) # 可用滤镜池 filter_options = ["noise", "unsharp", "curves", "color_balance"] -- 2.54.0 From cd6d8615e67521b2812bce24dc4990d38f05e591 Mon Sep 17 00:00:00 2001 From: saas-backend-agent Date: Mon, 7 Sep 2026 22:47:22 +0800 Subject: [PATCH 2/2] =?UTF-8?q?test:=20#1765=20=E8=A1=A5=E5=85=85=20int=20?= =?UTF-8?q?seed=20=E5=88=86=E6=94=AF=E6=B5=8B=E8=AF=95=EF=BC=8Cdiff=20cove?= =?UTF-8?q?rage=20=E8=BE=BE=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增 5 个测试覆盖 int seed 入参分支(reproducible/与 Random 对象 等价/None 默认),满足 diff coverage ≥60% 要求。 --- tests/unit/test_pixel_perturbation.py | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/unit/test_pixel_perturbation.py b/tests/unit/test_pixel_perturbation.py index 0ba311d94..38422baa9 100644 --- a/tests/unit/test_pixel_perturbation.py +++ b/tests/unit/test_pixel_perturbation.py @@ -110,3 +110,32 @@ class TestPixelPerturbationAcceptance: # 至少 2 种不同组合 unique = len(set(results)) assert unique >= 2, f"Expected >= 2 unique filter combos, got {unique}: {results}" + + +class TestIntSeedSupport: + """int seed 入参支持(与 get_rhythm_template(seed) 接口一致)。""" + + def test_int_seed_returns_dict(self): + """int seed 正常返回 dict。""" + result = generate_pixel_perturbation(42) + assert isinstance(result, dict) + assert "filters" in result + + def test_int_seed_reproducible(self): + """相同 int seed 结果一致。""" + assert generate_pixel_perturbation(42) == generate_pixel_perturbation(42) + + def test_int_seed_differs_across_seeds(self): + """不同 int seed 大概率不同(遍历确认至少 2 种组合)。""" + results = {tuple(generate_pixel_perturbation(s)["filters"]) for s in range(30)} + assert len(results) >= 2 + + def test_int_seed_matches_random_obj(self): + """int seed 与等价 random.Random(seed) 结果一致。""" + assert generate_pixel_perturbation(7) == generate_pixel_perturbation(random.Random(7)) + + def test_none_seed_works(self): + """None 入参(默认随机)正常返回。""" + result = generate_pixel_perturbation(None) + assert isinstance(result, dict) + assert len(result["filters"]) in [2, 3] -- 2.54.0