Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.
test(gen): drop the tests and grid rows that check the same code path as a kept test
Soohong Kimecc243da641d
diff --git a/tests/gen/test_anthropic_api.py b/tests/gen/test_anthropic_api.pyindex 3a63012..03017fe 100644--- a/tests/gen/test_anthropic_api.py+++ b/tests/gen/test_anthropic_api.py@@ -122,9 +122,8 @@ def test_refusals_past_the_retries_end_the_call(server):assert waits == [8.0, 16.0]+# Which statuses are asked again is tests/gen/test_retry.py's table; the spend cap shows the body reaches it.@pytest.mark.parametrize(("status", "error"), [- (502, {}), (503, {}),- (504, {"type": "timeout_error"}), # "The request timed out while processing": it was worked on(429, {"type": "rate_limit_error", "details": {"error_code": "enforced_spend_limit_reached"}}), # the spend cap])def test_a_refusal_anthropic_does_not_document_as_not_taken_is_not_asked_again(server, status, error):@@ -136,13 +135,6 @@ def test_a_refusal_anthropic_does_not_document_as_not_taken_is_not_asked_again(sassert caught.value.status == status and len(server.asked) == 1-def test_a_retry_after_longer_than_the_run_waits_is_not_waited_out_early(server):- server.script.append(("json", 429, {"retry-after": "600"}, {"type": "error", "error": {"type": "rate_limit_error"}}))- with pytest.raises(api.ApiError, match=r"\(HTTP 429\)"):- api.stream_message(KEY, body(), sleep=lambda s: pytest.fail("never asked again sooner than it said"))- assert len(server.asked) == 1--def test_a_batch_read_refused_on_the_providers_side_is_read_again(server):"""A GET buys nothing: a 502 on a batch's status is asked again, where the same answer to a POST is not."""server.script += [("json", 502, {}, b"<html>bad gateway</html>"), ("json", 200, {}, {"id": "msgbatch_1"})]diff --git a/tests/gen/test_body_plan_sheets.py b/tests/gen/test_body_plan_sheets.pyindex 0e2364f..6bb5c57 100644--- a/tests/gen/test_body_plan_sheets.py+++ b/tests/gen/test_body_plan_sheets.py@@ -85,21 +85,6 @@ def test_no_clip_prompt_of_any_state_names_a_part_the_body_lacks(body) -> None:assert not {name: words for name, words in named.items() if words}-def test_without_a_body_plan_the_v2_32_rows_and_attack_did_name_a_persons_parts() -> None:- """What the report was about, as 2.32.0 said it to every body."""- frozen = table.read(FIXTURE)- assert "body, arm, leg, hair" in frozen["every-state/base/walk.txt"]- assert "alternating leg, arm, shoulder" in frozen["every-state/base/frontwalk.txt"]- assert "alternating leg, arm, shoulder" in frozen["every-state/base/45_frontwalk.txt"]- assert "hand tilted" in frozen["every-state/base/wave.txt"]- assert "friendly hand wave gesture" in frozen["default-states/base/wave.txt"]- assert "arm counter-swing" in frozen["every-state/base/jump.txt"]- assert "shoulder overlap, hand/foot placement" in frozen["every-state/base/running-front-right.txt"]- attack = batch.build_prompt("side", "attack", "A brown horse")- assert "bare hands only if it holds nothing" in attack and "one hand stays one hand" in attack- assert "one hand stays one hand" in batch.build_prompt("side", "attack", "A brown horse", motion="It bites.")--def test_a_horse_attacks_with_what_it_holds_or_its_own_body() -> None:horse = bp.parse_all(["quadruped"])assert batch.build_prompt("side", "attack", "A brown horse", body_plan=horse) == (@@ -166,9 +151,9 @@ def test_the_sheet_cli_takes_records_and_carries_the_body_plan(tmp_path) -> Noneassert "body_plan" not in json.loads((plain / "sprite-request.json").read_text())+# each `body_plan.parse_all` error is tested in-process (tests/video/test_body_plan.py): one of them is enough here@pytest.mark.parametrize("args, match", [(["--body-plan", "horse"], "expected"),- (["--body-plan", "quadruped", "--body-plan", "the man=biped"], "names each figure"),(["--request-json", json.dumps({"body_plan": "quadruped"})], "must be a list"),])def test_a_sheet_body_plan_is_refused_before_the_run_dir_is_written(tmp_path, args, match) -> None:diff --git a/tests/gen/test_chroma_extraction.py b/tests/gen/test_chroma_extraction.pyindex 70c8145..b49b37e 100644--- a/tests/gen/test_chroma_extraction.py+++ b/tests/gen/test_chroma_extraction.py@@ -12,7 +12,8 @@ colors:2. ``choose_chroma_key`` ranked candidates by the 1st-percentile distance tosubject pixels, which discards sub-1% features (eyes, gems, ear lamps): theauto key could look safe while its nearest subject pixel was still inside the- extraction erase radius and would be deleted.+ extraction erase radius and would be deleted. Its guards are in+ ``test_chroma_key_auto.py``, beside the function.3. The old fringe cut erased every pixel inside the fringe color band *anywherein the image* — hot pink (~129 from magenta) and purple (~153) subjects fellin the band and were bleached wholesale. Soft-alpha unmix now treats boundary@@ -42,7 +43,6 @@ def _load(name: str):extract = _load("extract_sprite_row_frames")-prepare = _load("prepare_sprite_run")MAGENTA = (255, 0, 255)# extract_sprite_row_frames.py main() defaults@@ -220,10 +220,6 @@ def test_despill_preserves_far_subject_colors() -> None:assert _key(pixel) == (*pixel, 255), f"{pixel} was mangled by despill"-def test_exact_key_is_removed_everywhere() -> None:- assert _key(MAGENTA)[3] == 0--FRINGE = (147, 90, 157) # magenta blended with a green subject edge@@ -292,32 +288,6 @@ def _trap_band_subject(subject: tuple[int, int, int], size: int = 100, margin: ireturn canvas-def _subject_band_survival(image: Image.Image) -> float:- """Survival ratio of fringe-band subject pixels after cleanup."""- source = image.load()- band = []- for y in range(image.height):- for x in range(image.width):- color = source[x, y][:3]- distance = extract.color_distance(color, MAGENTA)- if KEY_THRESHOLD < distance <= FRINGE_THRESHOLD and extract.key_tint_score(color, MAGENTA) >= FRINGE_DELTA:- band.append((x, y))- assert band, "generated subject has no fringe-band pixels; generator is wrong"- out = _clean(image).load()- survived = sum(1 for x, y in band if out[x, y][3] != 0)- return survived / len(band)---def test_key_tinted_subject_material_survives() -> None:- # Hot-pink and purple subjects sit inside the magenta key's fringe trap. The- # old position-blind cut erased ~100% of them; boundary-limited despill must- # keep nearly all — only genuine key-blend edge pixels (the outer despill- # layers of the block) may go.- for subject in (HOT_PINK, PURPLE):- ratio = _subject_band_survival(_trap_band_subject(subject))- assert ratio >= 0.90, f"{subject}: only {ratio:.1%} of key-tinted subject pixels survived"--def test_key_tinted_subject_opaque_pixels_do_not_regress() -> None:# A 100x100 in-band subject block is ~10k opaque pixels; interior is# untouchable and only the outer despill layers may go, so the vast majority@@ -326,76 +296,3 @@ def test_key_tinted_subject_opaque_pixels_do_not_regress() -> None:out = _clean(_trap_band_subject(subject))opaque = out.getchannel("A").histogram()[255]assert opaque >= 9000, f"{subject}: opaque subject pixels regressed to {opaque}"---# A small, cyan-leaning teal feature: ~55 from the cyan key, so cyan would erase-# it, yet it is far enough from magenta/green/blue for those to keep it.-EYE = (0, 250, 200)---def _reference_image(path: Path) -> None:- # 128px so PIL never downscales the sample (deterministic across platforms).- image = Image.new("RGBA", (128, 128), (0, 0, 0, 0))- pixels = image.load()- for y in range(128):- for x in range(128):- if (x - 64) ** 2 + (y - 64) ** 2 < 58 ** 2:- pixels[x, y] = (196, 54, 38, 255) # red-orange body (the bulk hue)- # Two tiny eyes: well under 1% of the subject, so the 1st-percentile ranking- # ignores them and a naive selector happily picks the cyan key that erases them.- for cx, cy in ((50, 52), (78, 52)):- for dy in range(-1, 2):- for dx in range(-2, 3):- pixels[cx + dx, cy + dy] = (*EYE, 255)- image.save(path)---def test_auto_key_avoids_erasing_small_feature(tmp_path: Path) -> None:- ref = tmp_path / "base.png"- _reference_image(ref)-- opaque = eyes = 0- with Image.open(ref) as opened:- data = opened.convert("RGBA").load()- for y in range(128):- for x in range(128):- r, g, b, a = data[x, y]- if a <= 16:- continue- opaque += 1- if (r, g, b) == EYE:- eyes += 1- assert opaque and eyes / opaque < 0.01 # the eyes are a sub-1% feature-- pixels = prepare.sampled_reference_pixels(ref)- cyan = prepare.parse_hex_color("#00FFFF")- cyan_min = min(prepare.color_distance(cyan, pixel) for pixel in pixels)- # cyan would win the raw 1st-percentile ranking yet erase the eyes: that is- # exactly the trap the guard exists for.- assert cyan_min <= prepare.MIN_SUBJECT_KEY_DISTANCE-- result = prepare.choose_chroma_key(ref, "auto")- assert result["selection"] == "auto"- assert result["name"] != "cyan"- # The chosen key clears every subject pixel, including the tiny eyes.- assert result["min_subject_distance"] > prepare.MIN_SUBJECT_KEY_DISTANCE- assert "warning" not in result---def test_auto_key_warns_when_no_candidate_is_safe(tmp_path: Path) -> None:- # A subject that parks saturated pixels next to every candidate key: no safe- # choice exists, so the selector falls back to the ranking *and* warns.- ref = tmp_path / "rainbow.png"- image = Image.new("RGBA", (32, 32), (0, 0, 0, 0))- pixels = image.load()- near_keys = [(235, 30, 235), (30, 235, 30), (30, 235, 235), (20, 80, 235)]- for index, color in enumerate(near_keys):- for x in range(index * 8, index * 8 + 8):- for y in range(32):- pixels[x, y] = (*color, 255)- image.save(ref)-- result = prepare.choose_chroma_key(ref, "auto")- assert result["selection"] == "auto"- assert result["min_subject_distance"] <= prepare.MIN_SUBJECT_KEY_DISTANCE- assert "warning" in resultdiff --git a/tests/gen/test_chroma_key_auto.py b/tests/gen/test_chroma_key_auto.pyindex c084e89..5384d68 100644--- a/tests/gen/test_chroma_key_auto.py+++ b/tests/gen/test_chroma_key_auto.py@@ -61,22 +61,6 @@ def _candidate(result: dict, name: str) -> dict:return next(entry for entry in result["candidates"] if entry["name"] == name)-def test_flat_background_is_excluded_from_subject_pixels(tmp_path: Path) -> None:- ref = tmp_path / "base.png"- _base_on_background(ref)-- result = prepare.choose_chroma_key(ref, "auto")- assert result["background"]["mode"] == "flat"- assert result["background"]["hex"] == "#FF00FF"-- # No sampled subject pixel is the background, so the key the base was drawn- # against is scored against the body -- not against itself.- for pixel in prepare.sampled_reference_pixels(ref):- assert prepare.color_distance(pixel, MAGENTA) > prepare.BACKGROUND_TOLERANCE- assert _candidate(result, "magenta")["min_subject_distance"] > prepare.MIN_SUBJECT_KEY_DISTANCE- assert "warning" not in result--def test_auto_can_reselect_the_key_the_base_was_drawn_against(tmp_path: Path) -> None:# Subject material sits inside the erase radius of green, cyan and blue, so# magenta is the only safe key -- and magenta is also the base's background.diff --git a/tests/gen/test_chroma_rcb_byte_identity.py b/tests/gen/test_chroma_rcb_byte_identity.pyindex 46d8275..ca46f8c 100644--- a/tests/gen/test_chroma_rcb_byte_identity.py+++ b/tests/gen/test_chroma_rcb_byte_identity.py@@ -1211,14 +1211,6 @@ def test_key_tint_score_matches_frozen_scalar_reference():assert checked == len(_KEYS) * len(_SWEEP) ** 3-def test_key_tint_score_returns_zero_for_degenerate_keys():- """축퇴 키(키 채널 없음 / 언키 채널 없음)는 0.0 — 이 값이- `remove_chroma_background` 의 unmix·spill 패스 전체를 끄는 스위치다."""- for key in _DEGENERATE_KEYS:- assert extract.key_tint_score((10, 200, 30), key) == 0.0- assert _ref_key_tint_score((10, 200, 30), key) == 0.0--def test_despill_and_unmix_match_frozen_scalar_reference():"""despill/unmix 는 벡터화 대상 안쪽의 산수라 별도로 고정한다."""key = GREEN@@ -1346,29 +1338,16 @@ def test_key_tint_field_matches_frozen_scalar_reference():# --- remove_chroma_background: 바이트 동일 ---------------------------------[email protected]("case", CASES, ids=[case[0] for case in CASES])-def test_remove_chroma_background_byte_identical_to_frozen_reference(case):- got = _run_production(case)- ref = _run_reference(case)- assert got.size == ref.size- assert got.mode == ref.mode == "RGBA"- assert got.tobytes() == ref.tobytes(), f"{case[0]}: {_sha256(got)} != {_sha256(ref)}"--@pytest.mark.parametrize("case", CASES, ids=[case[0] for case in CASES])def test_remove_chroma_background_matches_pinned_output_hash(case):- """절대 잠금 — 프로덕션과 동결 참조를 같이 고쳐도 여기서 걸린다."""+ """절대 잠금 — 프로덕션과 동결 참조를 같이 고쳐도 여기서 걸린다. 두 해시가 같은 리터럴이니+ 프로덕션 == 동결 참조 바이트 동일도 여기서 성립한다. 같은 참조 실행으로 픽스처가 어떤 분기를+ 실제로 밟는지도 고정한다 — 통과만 하는 단정을 막는다."""expected = EXPECTED_OUTPUT_SHA256[case[0]]assert expected != "PENDING", "고정 해시가 비어 있다 — 게이트가 아니다"assert _sha256(_run_production(case)) == expected- assert _sha256(_run_reference(case)) == expected--[email protected]("case", CASES, ids=[case[0] for case in CASES])-def test_case_branch_coverage_is_pinned(case):- """픽스처가 어떤 분기를 실제로 밟는지 고정 — 통과만 하는 단정을 막는다."""counters = {}- _run_reference(case, counters=counters)+ assert _sha256(_run_reference(case, counters=counters)) == expectedassert counters == EXPECTED_COVERAGE[case[0]], f"{case[0]}: {counters}"diff --git a/tests/gen/test_chroma_soft_alpha.py b/tests/gen/test_chroma_soft_alpha.pyindex b31f9be..4a44eac 100644--- a/tests/gen/test_chroma_soft_alpha.py+++ b/tests/gen/test_chroma_soft_alpha.py@@ -21,10 +21,12 @@ The fixtures are 1/8-size NEAREST copies of the repro raws (1024x1536 ->Source raws: moe-test ``raw-green.png`` (magenta key) / ``raw-red.png``(green key), generated at cell 1024x1536, idle single frame.-The third test pins the v1.10.1 guardrail from the other side: on these+Partial alpha on both keys is pinned on the sibling moe fixtures+(``test_chroma_extraction.py::test_moe_fixtures_keep_meaningful_mid_alpha_edges``).+The second test pins the v1.10.1 guardrail from the other side: on thesefixtures, pixels deeper than any plausible fringe peel must come outbyte-identical. The one sanctioned interior treatment is the trapped-spill-despill (fourth test): a *small* cluster with a strongly key-tinted pixel,+despill (third test): a *small* cluster with a strongly key-tinted pixel,buried inside the subject, is generator spill and gets its color correctedin place (alpha kept — no pinholes); marginally warm subject colors (skin)and large key-tinted material regions are never touched.@@ -128,16 +130,6 @@ def _keyed_distance_map(image: Image.Image, chroma_key: tuple[int, int, int]) ->return distance[email protected]("name, chroma_key", CASES)-def test_boundary_blend_pixels_get_partial_alpha(name: str, chroma_key) -> None:- # ① Antialiased edges must survive as partial alpha. A hard binary cut- # leaves zero mid-alpha pixels and the silhouette staircases.- out = _clean(_open(name), chroma_key)- histogram = out.getchannel("A").histogram()- mid_alpha = sum(histogram[1:255])- assert mid_alpha > 0, f"{name}: no partial alpha anywhere — edges are a binary cut"--@pytest.mark.parametrize("name, chroma_key", CASES)def test_no_key_tint_residue_survives_cleanup(name: str, chroma_key) -> None:# ② Key/subject blends trapped between hair strands must not survive asdiff --git a/tests/gen/test_chroma_ycbcr.py b/tests/gen/test_chroma_ycbcr.pyindex ae344bc..c85fa49 100644--- a/tests/gen/test_chroma_ycbcr.py+++ b/tests/gen/test_chroma_ycbcr.py@@ -206,10 +206,3 @@ def test_extract_cli_ycbcr_mode_end_to_end(fixture_run_dir: Path):assert _opaque_count(opened.convert("RGBA")) > 0-def test_default_mode_stays_rgb(fixture_run_dir: Path):- from conftest import run_script-- result = run_script("extract_sprite_row_frames.py", "--run-dir", str(fixture_run_dir))- assert result.returncode == 0, result.stderr- request = json.loads((fixture_run_dir / "sprite-request.json").read_text())- assert request["chroma"]["mode"] == "rgb"diff --git a/tests/gen/test_claude_login.py b/tests/gen/test_claude_login.pyindex 1b6e533..50f4071 100644--- a/tests/gen/test_claude_login.py+++ b/tests/gen/test_claude_login.py@@ -51,13 +51,13 @@ def test_the_child_runs_without_a_key_and_without_the_calling_session():"CLAUDE_CODE_USE_VERTEX": "1"}+# `method not in SUBSCRIPTION_METHODS` is one check: each method it lets in, one it keeps out.@pytest.mark.parametrize("answer, expected", [(SIGNED_IN, claude_login.Login("claude.ai", "max")),(status(0, {"loggedIn": True, "authMethod": "oauth_token", "subscriptionType": "team"}),claude_login.Login("oauth_token", "team")),(SIGNED_OUT, None),(status(0, {"loggedIn": True, "authMethod": "api_key"}), None),- (status(0, {"loggedIn": True, "authMethod": "third_party"}), None),(FileNotFoundError("claude"), None),])def test_the_login_is_a_subscription_or_none(answer, expected):@@ -68,8 +68,9 @@ def test_the_login_is_a_subscription_or_none(answer, expected):assert "ANTHROPIC_API_KEY" not in call["env"] # the status of the login the child would use+# A timeout and an OSError share one `except`.@pytest.mark.parametrize("answer", [status(0, "not json"), status(2, {"loggedIn": False}),- subprocess.TimeoutExpired(["claude"], 30), PermissionError("denied")])+ subprocess.TimeoutExpired(["claude"], 30)])def test_an_unreadable_status_is_refused_not_read_as_no_login(answer):with pytest.raises(SystemExit, match="refusing to guess whether your Claude subscription is signed in"):claude_login.login({}, run=Run(answer))diff --git a/tests/gen/test_codex_rollout_resolution.py b/tests/gen/test_codex_rollout_resolution.pyindex 1673dd5..8a73de3 100644--- a/tests/gen/test_codex_rollout_resolution.py+++ b/tests/gen/test_codex_rollout_resolution.py@@ -49,21 +49,6 @@ def _write_rollout(codex_home: Path, session_id: str, *, branch: str = "03") ->return rollout-def test_codex_home_env_is_the_only_state_root(tmp_path: Path, monkeypatch) -> None:- configured = tmp_path / "account-codex-home"- configured.mkdir()- monkeypatch.setenv("CODEX_HOME", str(configured))-- assert codex_provider._resolve_codex_home() == configured.resolve()---def test_codex_home_unset_uses_codex_default_root(tmp_path: Path, monkeypatch) -> None:- monkeypatch.delenv("CODEX_HOME", raising=False)- monkeypatch.setattr(codex_provider.Path, "home", classmethod(lambda cls: tmp_path / "user"))-- assert codex_provider._resolve_codex_home() == tmp_path / "user" / ".codex"--def test_codex_home_set_empty_fails_instead_of_falling_back(monkeypatch) -> None:monkeypatch.setenv("CODEX_HOME", " ")diff --git a/tests/gen/test_facing.py b/tests/gen/test_facing.pyindex 5659250..b87f3bd 100644--- a/tests/gen/test_facing.py+++ b/tests/gen/test_facing.py@@ -73,10 +73,10 @@ def test_left_request_mirrors_right_and_preserves_alpha_and_preview(tmp_path, moassert result.extra["facing"]["final_direction"] == "left"[email protected]("options", [{}, {"facing_fix": "none"}])-def test_default_and_none_preserve_bytes_despite_wrong_observation(tmp_path, monkeypatch, options):+def test_default_and_none_preserve_bytes_despite_wrong_observation(tmp_path, monkeypatch):+ # the default is `none`, so an explicit `facing_fix="none"` runs the same codebackend = Backend("left", image_direction="right")- result = generate(tmp_path, monkeypatch, backend, **options)+ result = generate(tmp_path, monkeypatch, backend)assert result.out.read_bytes() == result.raw.read_bytes() == (FIXTURES / "right.png").read_bytes()report = result.extra["facing"]assert report["fix"] == "none" and report["action"] == "none"@@ -232,14 +232,14 @@ def test_codex_vision_reads_new_answer_and_scrubs_identity(monkeypatch, tmp_pathassert not list(tmp_path.iterdir())[email protected]("options", [[], ["--facing-fix", "none"]])-def test_cli_options_reach_report(tmp_path, monkeypatch, options):+def test_cli_options_reach_report(tmp_path, monkeypatch):+ # `--facing-fix` defaults to `none`, so passing it runs the same codebackend = Backend("right")monkeypatch.setattr(gen, "_make_provider", lambda *a, **kw: backend)report = tmp_path / "report.json"assert gen.main(["--provider", "openai", "--prompt", "robot", "--ref", str(FIXTURES / "right.png"),"--out", str(tmp_path / "out.png"), "--report", str(report),- "--facing", "left", *options]) == 0+ "--facing", "left"]) == 0facing_report = json.loads(report.read_text())["extra"]["facing"]assert facing_report["requested"] == "left" and facing_report["action"] == "none"assert facing_report["fix"] == "none"diff --git a/tests/gen/test_gen.py b/tests/gen/test_gen.pyindex 20dc4e7..33f65fb 100644--- a/tests/gen/test_gen.py+++ b/tests/gen/test_gen.py@@ -94,73 +94,6 @@ def test_provider_binary_resolves_windows_style_path_shims(monkeypatch) -> None:assert gen_base.provider_binary("codex") == "codex"-def test_provider_run_uses_scrubbed_env(tmp_path: Path, monkeypatch) -> None:- # Codex remains the subprocess provider; Grok now calls the API directly.-- monkeypatch.setenv("CODEX_HOME", str(tmp_path))- seen: dict[str, dict | None] = {}-- class _Completed:- returncode = 0- stdout = '{"type":"thread.started","thread_id":"aaaa-bbbb"}\n'- stderr = ""-- def _fake_codex_run(cmd, **kwargs):- seen["codex"] = kwargs.get("env")- seen["codex_cmd"] = cmd- seen["codex_encoding"] = kwargs.get("encoding")- return _Completed()-- # Short-circuit codex's post-run rollout parsing — we only assert the env.- monkeypatch.setattr(codex_provider.subprocess, "run", _fake_codex_run)- monkeypatch.setattr(codex_provider, "codex_login", lambda: codex_provider.CodexLogin(codex_provider.AUTH_SOURCE_LOGIN))- monkeypatch.setattr(- codex_provider,- "_resolve_rollout",- lambda sid, sessions_root, *, preexisting: tmp_path / "x.jsonl",- )- b64 = base64.b64encode(_png_bytes()).decode()- monkeypatch.setattr(- codex_provider, "_collect_inline_results", lambda rollout: [codex_provider.InlineResult(b64)]- )- monkeypatch.setenv("ORCHESTRATOR_RUNTIME_ENDPOINT_ID", "synthetic-endpoint")- codex_provider.CodexProvider(keep_session=True).generate(- GenRequest(prompt="a mushroom", raw=tmp_path / "raw.png"), tmp_path- )- assert seen["codex"] is not None- assert "ORCHESTRATOR_RUNTIME_ENDPOINT_ID" not in seen["codex"]- assert seen["codex_encoding"] == "utf-8"---def test_provider_commands_use_the_single_resolved_binary(tmp_path: Path, monkeypatch) -> None:- monkeypatch.setenv("CODEX_HOME", str(tmp_path))- seen: dict[str, list[str]] = {}- monkeypatch.setattr(codex_provider, "provider_binary", lambda _name: "C:/bin/codex.CMD")-- class _CodexCompleted:- returncode = 0- stdout = '{"type":"thread.started","thread_id":"aaaa-bbbb"}\n'- stderr = ""-- def fake_codex(cmd, **_kwargs):- seen["codex"] = cmd- return _CodexCompleted()-- monkeypatch.setattr(codex_provider.subprocess, "run", fake_codex)- monkeypatch.setattr(codex_provider, "codex_login", lambda: codex_provider.CodexLogin(codex_provider.AUTH_SOURCE_LOGIN))- monkeypatch.setattr(codex_provider, "_resolve_rollout", lambda *_args, **_kwargs: tmp_path / "rollout.jsonl")- monkeypatch.setattr(- codex_provider,- "_collect_inline_results",- lambda _path: [codex_provider.InlineResult(base64.b64encode(_png_bytes()).decode())],- )- codex_provider.CodexProvider(keep_session=True).generate(- GenRequest(prompt="도구", raw=tmp_path / "codex.png"), tmp_path- )-- assert seen["codex"][0] == "C:/bin/codex.CMD"--def test_json_report_writes_utf8_bytes_without_reconfiguring_stdout(monkeypatch) -> None:import ioimport sys@@ -290,32 +223,6 @@ def test_codex_parse_session_id_json_and_legacy() -> None:assert codex_provider._parse_session_id("no id here") is None-def test_codex_prompt_carries_official_imagegen_skill_trigger() -> None:- # Image generation lives in codex's bundled `imagegen` system skill, and the- # official way to invoke a skill explicitly is the `$<skill>` prompt mention- # (skills/.system/imagegen/agents/openai.yaml ships `default_prompt: "Use- # $imagegen to make or edit an image for this project."`). This locks the- # transport prompt to that contract; if the implicit prose phrasing comes- # back, this goes red.- #- # Scope note: the trigger is a contract alignment, not a tool-exposure fix.- # Built-in image generation is an account capability of the active Codex state- # root — see codex_provider._no_image_records_message. Do not let this test's- # name imply that the trigger is what makes image_gen available.- user_prompt = "a mushroom sprite row on a #00FF00 background"- prompt = codex_provider._build_prompt(user_prompt)-- assert codex_provider._SKILL_TRIGGER == "$imagegen"- assert "$imagegen" in prompt, "the official skill trigger must be in the transport prompt"- # It must lead the instruction, not trail the user's prompt as an aside.- assert prompt.startswith("$imagegen "), prompt- # The caller's sprite-request prompt is the SSoT — passed through verbatim.- assert user_prompt in prompt- # The rest of the transport contract survives the trigger.- assert "정확히 1번" in prompt- assert "금지" in prompt--def test_codex_empty_rollout_fails_loud_on_tool_non_exposure(tmp_path: Path, monkeypatch) -> None:# An empty rollout is the tool-non-exposure signature. It must fail loudly, name# the account capability behind the active Codex state root as the thing that is@@ -360,7 +267,9 @@ def test_codex_prompt_reaches_the_child_process(tmp_path: Path, monkeypatch) -># The trigger is only real if it survives into codex exec's stdin — assert the# transport prompt is what the child actually receives, not just what we build.monkeypatch.setenv("CODEX_HOME", str(tmp_path))- seen: dict[str, str] = {}+ monkeypatch.setenv("ORCHESTRATOR_RUNTIME_ENDPOINT_ID", "synthetic-endpoint")+ monkeypatch.setattr(codex_provider, "provider_binary", lambda _name: "C:/bin/codex.CMD")+ seen: dict = {}class _Completed:returncode = 0@@ -368,6 +277,9 @@ def test_codex_prompt_reaches_the_child_process(tmp_path: Path, monkeypatch) ->stderr = ""def _fake_run(cmd, **kwargs):+ seen["cmd"] = cmd+ seen["env"] = kwargs.get("env")+ seen["encoding"] = kwargs.get("encoding")seen["input"] = kwargs.get("input", "")return _Completed()@@ -387,6 +299,10 @@ def test_codex_prompt_reaches_the_child_process(tmp_path: Path, monkeypatch) ->GenRequest(prompt="a mushroom", raw=tmp_path / "raw.png"), tmp_path)+ assert seen["cmd"][0] == "C:/bin/codex.CMD"+ assert seen["env"] is not None+ assert "ORCHESTRATOR_RUNTIME_ENDPOINT_ID" not in seen["env"]+ assert seen["encoding"] == "utf-8"assert seen["input"].startswith("$imagegen ")assert "a mushroom" in seen["input"]@@ -451,29 +367,10 @@ def test_chroma_key_transparent_removes_textured_gradient_background(assert keyed.getpixel((48, 32))[3] == 255-def test_chroma_key_transparent_rejects_zero_percent_alpha(- tmp_path: Path,- monkeypatch,-) -> None:- src = tmp_path / "src.png"- Image.new("RGBA", (512, 512), (20, 30, 40, 255)).save(src)-- def ineffective_matte(image, chroma_key, warnings):- result = image.convert("RGBA")- result.putpixel((0, 0), (0, 0, 0, 0))- return result-- monkeypatch.setattr(chroma_mod, "remove_chroma_background_ycbcr", ineffective_matte)-- out = tmp_path / "out.png"- with pytest.raises(SystemExit, match=r"0\.0% transparent pixels"):- chroma_mod.key_transparent(src, out, key="magenta")- assert not out.exists()--class _FakeProvider:name = "fake"transparency = gen_base.TRANSPARENCY_CHROMA+ size = (8, 8)def __init__(self) -> None:self.calls = 0@@ -482,7 +379,7 @@ class _FakeProvider:def generate(self, request: GenRequest, workdir: Path):self.calls += 1self.requests.append(request)- Image.new("RGBA", (8, 8), (255, 0, 255, 255)).save(request.raw)+ Image.new("RGBA", self.size, (255, 0, 255, 255)).save(request.raw)return gen_base.ProviderRun(provider=self.name, elapsed_seconds=1.23, model=request.model)@@ -565,21 +462,6 @@ def test_native_strategy_publishes_measured_alpha_and_asks_provider_for_it(assert payload["chroma"] is None # no chroma key ran-def test_chroma_strategy_reports_itself_under_alpha_too(tmp_path: Path, monkeypatch) -> None:- fake = _FakeProvider()- monkeypatch.setattr(gen, "_make_provider", lambda name, *, keep_session: fake)- out = tmp_path / "asset.png"- report = tmp_path / "report.json"-- assert gen.run(**_gen_kwargs(out, report)) == 0-- assert fake.requests[0].native_alpha is False- payload = json.loads(report.read_text(encoding="utf-8"))- assert payload["alpha"]["strategy"] == "chroma"- assert payload["alpha"]["method"] == "ycbcr"- assert payload["chroma"]["method"] == "ycbcr"--@pytest.mark.parametrize(("image", "expected_message"),[@@ -628,26 +510,6 @@ def test_alpha_mode_chroma_forces_keying_on_a_native_provider(tmp_path: Path, moassert payload["chroma"]["key"] == "magenta"-def test_auto_steps_down_to_chroma_when_refs_are_attached(tmp_path: Path, monkeypatch, capsys) -> None:- # 2026-09-08 실측: codex native alpha with --ref drew checkerboards 5/6, chroma 6/6.- # `auto` therefore keys a ref run instead of gambling on native — decided before- # the model call, printed, and recorded in the report.- fake = _FakeNativeProvider(Image.new("RGBA", (8, 8), (255, 0, 255, 255)))- monkeypatch.setattr(gen, "_make_provider", lambda name, *, keep_session: fake)- ref = tmp_path / "ref.png"- ref.write_bytes(_png_bytes())- out = tmp_path / "asset.png"- report = tmp_path / "report.json"-- assert gen.run(**_gen_kwargs(out, report, ref=[ref])) == 0-- assert fake.requests[0].native_alpha is False- payload = json.loads(report.read_text(encoding="utf-8"))- assert payload["alpha"]["strategy"] == "chroma"- assert payload["alpha"]["strategy_source"] == "refs-attached"- assert "reference image(s) attached" in capsys.readouterr().err--def test_explicit_native_still_runs_with_refs(tmp_path: Path, monkeypatch) -> None:fake = _FakeNativeProvider()monkeypatch.setattr(gen, "_make_provider", lambda name, *, keep_session: fake)@@ -664,8 +526,9 @@ def test_explicit_native_still_runs_with_refs(tmp_path: Path, monkeypatch) -> Noassert payload["alpha"]["strategy_source"] == "explicit"-# Three raws a ref run can come back with (2026-10-04): a real cut-out (a transparent-# --ref is answered with alpha), a drawn checkerboard and a painted key background.+# Raws a ref run can come back with (2026-10-04): a real cut-out (a transparent+# --ref is answered with alpha) and a painted key background; a drawn checkerboard is+# refused in tests/gen/test_painted_checkerboard.py.# The figure is a dark outline around an orange body with a cream belly — the two# colours a second key took off the real cut-out._OUTLINE, _BODY, _CREAM = (20, 20, 20), (240, 140, 40), (245, 230, 200)@@ -687,14 +550,6 @@ def _real_alpha_raw() -> Image.Image:return _outlined_figure(Image.new("RGBA", (64, 64), (0, 0, 0, 0)))-def _checkerboard_raw() -> Image.Image:- board = Image.new("RGB", (64, 64))- for y in range(64):- for x in range(64):- board.putpixel((x, y), (204, 204, 204) if (x // 8 + y // 8) % 2 else (255, 255, 255))- return _outlined_figure(board)--def _key_background_raw() -> Image.Image:return _outlined_figure(Image.new("RGB", (64, 64), (255, 0, 255)))@@ -731,7 +586,7 @@ def test_ref_run_publishes_a_real_alpha_raw_without_keying_its_outline(assert "publishing its own alpha" in capsys.readouterr().err-def test_ref_run_still_keys_a_raw_with_no_alpha(tmp_path: Path, monkeypatch) -> None:+def test_ref_run_still_keys_a_raw_with_no_alpha(tmp_path: Path, monkeypatch, capsys) -> None:fake, rc, out, report = _ref_run(tmp_path, monkeypatch, _key_background_raw())assert rc == 0@@ -745,21 +600,7 @@ def test_ref_run_still_keys_a_raw_with_no_alpha(tmp_path: Path, monkeypatch) ->}assert payload["chroma"]["key"] == "magenta"assert Image.open(out).getpixel((0, 0)) == (0, 0, 0, 0) # the background was keyed out---def test_ref_run_refuses_a_drawn_checkerboard_instead_of_keying_it(tmp_path: Path, monkeypatch) -> None:- # a drawn checkerboard is no alpha either, so it is not published on its own alpha; and it is not the key- # the run asked for, so it is refused before keying (tests/gen/test_painted_checkerboard.py)- with pytest.raises(SystemExit, match=r"^chroma: the background is a painted transparency checkerboard \(8 px"):- _ref_run(tmp_path, monkeypatch, _checkerboard_raw())- assert not (tmp_path / "asset.png").exists() and not (tmp_path / "report.json").exists()---def test_key_background_ref_run_keeps_its_outline(tmp_path: Path, monkeypatch) -> None:- _, _, out, _ = _ref_run(tmp_path, monkeypatch, _key_background_raw())- published = Image.open(out)- assert published.getpixel(_OUTLINE_PX) == _OUTLINE + (255,)- assert published.getpixel(_CREAM_PX) == _CREAM + (255,)+ assert "reference image(s) attached" in capsys.readouterr().errdef test_ref_run_keys_an_ambiguous_raw_and_warns(tmp_path: Path, monkeypatch, capsys) -> None:@@ -939,20 +780,6 @@ def test_classify_raw_alpha_reads_the_alpha_band(tmp_path: Path, image: Image.Imassert chroma_mod.classify_raw_alpha(path)["verdict"] == verdict-def test_classify_raw_alpha_needs_a_transparent_border(tmp_path: Path) -> None:- # Plenty of alpha 0, all of it inside an opaque frame: not a transparent background.- image = Image.new("RGBA", (20, 20), (255, 0, 255, 255))- for y in range(4, 16):- for x in range(4, 16):- image.putpixel((x, y), (0, 0, 0, 0))- path = tmp_path / "raw.png"- image.save(path)- stats = chroma_mod.classify_raw_alpha(path)- assert stats["alpha_zero_pct"] == 36.0- assert stats["border_alpha_zero_pct"] == 0.0- assert stats["verdict"] == "ambiguous"--def test_classify_raw_alpha_judges_before_rounding(tmp_path: Path) -> None:# One alpha-0 pixel in 200 x 200 is 0.0025 %, reported as 0.0 but not "no alpha".image = Image.new("RGBA", (200, 200), (255, 0, 255, 255))@@ -1094,12 +921,15 @@ def test_generate_image_zero_percent_alpha_fails_without_success_report(monkeypatch,) -> None:fake = _FakeProvider()+ fake.size = (150, 150)monkeypatch.setattr(gen, "_make_provider", lambda name, *, keep_session: fake)- monkeypatch.setattr(- chroma_mod,- "remove_chroma_background_ycbcr",- lambda image, chroma_key, warnings: image.convert("RGBA"),- )++ def ineffective_matte(image, chroma_key, warnings):+ result = image.convert("RGBA")+ result.putpixel((0, 0), (0, 0, 0, 0))+ return result++ monkeypatch.setattr(chroma_mod, "remove_chroma_background_ycbcr", ineffective_matte)out = tmp_path / "asset.png"report = tmp_path / "report.json"@@ -1147,11 +977,14 @@ def test_generate_image_orchestrates_report_and_raw_keep(tmp_path: Path, monkeyp)assert rc == 0assert fake.calls == 1+ assert fake.requests[0].native_alpha is Falseassert out.is_file()assert (tmp_path / "asset.png.raw.png").is_file() # pre-chroma raw preservedpayload = json.loads(report.read_text(encoding="utf-8"))assert payload["provider"] == "fake"assert payload["transparent"] is True+ assert payload["alpha"]["strategy"] == "chroma"+ assert payload["alpha"]["method"] == "ycbcr"assert payload["chroma"]["method"] == "ycbcr"assert payload["chroma"]["stale_transparent_rgb_pixels"] == 0assert payload["elapsed_seconds"] == 1.23@@ -1170,12 +1003,6 @@ def test_unknown_provider_fails_loud(tmp_path: Path) -> None:# ── Default-provider policy (maintainer 2026-07-17): default = codex, observable grok# fallback when codex is unavailable, SPRITE_GEN_DEFAULT_PROVIDER override. ──────-def test_resolve_default_provider_hard_default_is_codex(monkeypatch) -> None:- monkeypatch.delenv(gen.DEFAULT_PROVIDER_ENV, raising=False)- monkeypatch.setattr(gen, "_codex_available", lambda: (True, ""))- assert gen.resolve_default_provider() == ("codex", None)--def test_resolve_default_provider_env_override(monkeypatch) -> None:monkeypatch.setenv(gen.DEFAULT_PROVIDER_ENV, "grok")# codex probe must not even run when the env pins a non-codex default.@@ -1189,19 +1016,6 @@ def test_resolve_default_provider_invalid_env_fails_loud(monkeypatch) -> None:gen.resolve_default_provider()-def test_resolve_default_provider_codex_unavailable_falls_back_observably(monkeypatch) -> None:- monkeypatch.delenv(gen.DEFAULT_PROVIDER_ENV, raising=False)- monkeypatch.setattr(gen, "_codex_available", lambda: (False, "codex not logged in (test)"))- provider, fallback = gen.resolve_default_provider()- assert provider == "grok"- assert fallback == {- "from": "codex",- "to": "grok",- "reason": "codex not logged in (test)",- "default_source": "hard-default",- }--def test_resolve_default_provider_env_codex_still_falls_back(monkeypatch) -> None:# An env that pins codex still gets the availability fallback (default_source=env).monkeypatch.setenv(gen.DEFAULT_PROVIDER_ENV, "codex")diff --git a/tests/gen/test_grok_provider.py b/tests/gen/test_grok_provider.pyindex b3a9642..46ee98a 100644--- a/tests/gen/test_grok_provider.py+++ b/tests/gen/test_grok_provider.py@@ -74,7 +74,8 @@ def test_generation_decodes_jpeg_to_png_without_agent(tmp_path, api):assert "synthetic-secret" not in json.dumps(report)[email protected]("count", [1, 2, 5])+# `count == 1` sends `image`, more send `images`.[email protected]("count", [1, 5])def test_reference_edit_preserves_order_and_model(tmp_path, api, count):refs = []for i in range(count):@@ -104,7 +105,8 @@ def test_direct_output_keeps_chroma_pipeline(tmp_path, api):assert image.getpixel((6, 4))[3] == 255[email protected]("status", [400, 401, 403, 500, 503])+# Two branches: 401/403 the credential, the rest a refusal; which are sent again is tests/gen/test_retry.py's.[email protected]("status", [401, 503])def test_api_failure_keeps_existing_output_and_does_not_retry(tmp_path, api, status):api.update(status=status, body={"error": "synthetic-secret https://signed.invalid/private?sig=abc"})out = tmp_path / "existing.png"@@ -136,7 +138,7 @@ def test_a_rate_limit_still_there_after_two_more_sends_ends_the_call(tmp_path, aassert len(api["calls"]) == 3 and api["slept"] == [8.0, 16.0][email protected]("body", [{}, {"data": []}, {"data": [None]}, {"data": [{}, {}]},[email protected]("body", [{}, {"data": [None]}, {"data": [{}, {}]},{"data": [{"b64_json": "???"}]},{"data": [{"b64_json": base64.b64encode(b"invalid image").decode()}]},{"data": [{"url": "https://signed.invalid/private"}]}])@@ -202,7 +204,8 @@ def _subscription_login(tmp_path, monkeypatch):"key": "subscription-token", "expires_at": "2100-01-01T00:00:00Z"}}))[email protected]("status", [200, 403, 503])+# 403 and 503 both end on the first call, on the subscription token.[email protected]("status", [200, 403])def test_images_use_subscription_even_with_api_key(tmp_path, api, monkeypatch, status):_subscription_login(tmp_path, monkeypatch)api["status"] = status@@ -236,8 +239,8 @@ def _sent(api, index=0):return json.loads(api["calls"][index][0].data)[email protected]("resolution", grok.SUPPORTED_RESOLUTIONS)[email protected]("quality", grok.SUPPORTED_QUALITIES)+# A level is checked against the declared subset, then passed on with no branch on its value.[email protected](("quality", "resolution"), [("auto", "1k")])def test_every_priced_level_reaches_the_request_and_the_report(tmp_path, api, quality, resolution):"""The two knobs Imagine prices on arrive verbatim — no normalising, no default."""result = gen.generate_image("grok", "x", tmp_path / f"{quality}-{resolution}.png",@@ -256,14 +259,10 @@ def test_asking_for_neither_leaves_the_request_and_report_as_they_were(tmp_path,assert "quality" not in result.extra and "resolution" not in result.extra+# One `not in` per knob.@pytest.mark.parametrize("options, expected", [({"quality": "high"}, "openai"),- ({"quality": "xhigh"}, "openai"),- ({"quality": "max"}, "openai"),- ({"quality": "bogus"}, "openai"),({"resolution": "4k"}, "1.5k"),- ({"resolution": "1024"}, "1.5k"),- ({"resolution": "1K"}, "1.5k"),])def test_a_level_grok_cannot_serve_fails_before_upload(tmp_path, api, options, expected):with pytest.raises(SystemExit) as error:diff --git a/tests/gen/test_handedness.py b/tests/gen/test_handedness.pyindex 3bb4f78..8ac41ec 100644--- a/tests/gen/test_handedness.py+++ b/tests/gen/test_handedness.py@@ -207,16 +207,6 @@ def test_two_items_do_not_call_a_wrist_bare_that_the_other_is_on() -> None:assert "has none," in h.text([watch], "side", "right") and "none of it" not in h.text([watch, bracelet], "side", "right")-def test_the_clip_prompt_ends_with_the_handedness_sentence() -> None:- items = [h.parse(WATCH)]- plain = batch_mod.build_prompt("front_diagonal", "walk", None, facing="left")- with_item = batch_mod.build_prompt("front_diagonal", "walk", None, facing="left", handed=items)- assert with_item == plain + " " + h.text(items, "front_diagonal", "left", clip=True)- front = batch_mod.build_prompt("front", "walk", None, facing="right", handed=items, motion="It strolls.")- assert front.endswith(h.text(items, "front", None, clip=True))- assert batch_mod.build_prompt("side", "walk", None, handed=None) == batch_mod.build_prompt("side", "walk", None)--def test_video_prompt_carries_handedness_and_turns_a_left_diagonal_loop_left() -> None:record = clip_prompt.plan_prompt(direction="back_diagonal", state="walk", facing="left", last_frame=False,unpinned=True, handed=[h.parse(WATCH)])diff --git a/tests/gen/test_openai_provider.py b/tests/gen/test_openai_provider.pyindex 10c3865..e8404a8 100644--- a/tests/gen/test_openai_provider.py+++ b/tests/gen/test_openai_provider.py@@ -20,7 +20,7 @@ from PIL import Imagefrom sprite_gen import genfrom sprite_gen.gen import grok_provider as grokfrom sprite_gen.gen import openai_provider as openai-from sprite_gen.gen import retry, xai+from sprite_gen.gen import retryfrom sprite_gen.gen.base import GenRequestfrom sprite_gen.workflow import accessfrom sprite_gen.workflow.catalog import FIELDS, GUIDED_PROVIDERS, PROVIDER_LABELS, validate_choices@@ -42,24 +42,6 @@ def encoded_image(fmt="PNG", *, alpha=False, key=False):return base64.b64encode(buf.getvalue()).decode()-class _GrokResponse:- """Minimal 200 answer for the xai transport (a PNG, so chroma stays untouched)."""-- def __init__(self, request, api):- api["calls"].append((request, None))-- def __enter__(self):- return self-- def __exit__(self, *args):- pass-- status = 200-- def read(self):- return json.dumps({"data": [{"b64_json": encoded_image()}]}).encode()--@pytest.fixturedef api(monkeypatch):monkeypatch.setenv("OPENAI_API_KEY", KEY)@@ -144,24 +126,17 @@ def test_a_response_without_rate_limit_headers_reports_that_none_came(tmp_path,assert gen.generate_image("openai", "x", tmp_path / "out.png").to_dict()["extra"]["rate_limit"] == {}[email protected]("quality", openai.SUPPORTED_QUALITIES)-def test_every_quality_level_reaches_the_request_verbatim(tmp_path, api, quality):- gen.generate_image("openai", "x", tmp_path / f"{quality}.png", quality=quality)- assert _body(api["calls"][0][0])["quality"] == quality--[email protected]("ratio,size", sorted(openai.SIZES.items()))-def test_aspect_ratio_maps_to_a_legal_gpt_image_size(tmp_path, api, ratio, size):- gen.generate_image("openai", "x", tmp_path / "out.png", aspect_ratio=ratio)- assert _body(api["calls"][0][0])["size"] == size- if size == "auto":- return- width, height = (int(side) for side in size.split("x"))- # The documented custom-size constraints, checked on the table itself.- assert width % 16 == 0 and height % 16 == 0- assert max(width, height) <= 3840- assert 1 / 3 <= width / height <= 3- assert 655_360 <= width * height <= 8_294_400+def test_aspect_ratio_maps_to_a_legal_gpt_image_size():+ # The lookup is one `SIZES[ratio]` (sent end to end in test_cli_accepts_provider_and_quality).+ for ratio, size in sorted(openai.SIZES.items()):+ if size == "auto":+ continue+ width, height = (int(side) for side in size.split("x"))+ # The documented custom-size constraints, checked on the table itself.+ assert width % 16 == 0 and height % 16 == 0, ratio+ assert max(width, height) <= 3840, ratio+ assert 1 / 3 <= width / height <= 3, ratio+ assert 655_360 <= width * height <= 8_294_400, ratiodef test_model_and_quality_overrides_are_not_second_guessed(tmp_path, api):@@ -200,7 +175,8 @@ def test_reference_edit_posts_multipart_images_in_order(tmp_path, api):assert positions == sorted(positions), "reference images are read positionally; order must survive"[email protected]("status", [400, 401, 403, 500, 502])+# Two branches: 401/403 the credential, the rest a refusal; which are sent again is tests/gen/test_retry.py's.[email protected]("status", [401, 500])def test_api_failure_keeps_existing_output_and_does_not_retry(tmp_path, api, status):api.update(status=status, body={"error": {"message": f"{KEY} https://signed.invalid/private?sig=abc"}})out = tmp_path / "existing.png"@@ -216,9 +192,8 @@ def test_api_failure_keeps_existing_output_and_does_not_retry(tmp_path, api, sta@pytest.mark.parametrize(("refused", "slept"), [((429, {"error": {"type": "rate_limit_error", "code": "rate_limit_exceeded"}}, {"retry-after": "2"}), [2.0]),- ((429, {"error": {"type": "rate_limit_error", "code": "slow_down"}}, {}), [8.0]),((503, {"error": {"type": "service_unavailable_error", "code": "server_is_overloaded"}}, {}), [8.0]),-], ids=["rate-limit", "slow-down", "overloaded"])+], ids=["rate-limit", "overloaded"])def test_a_refusal_openai_documents_as_not_taken_is_sent_again(tmp_path, api, capsys, refused, slept):"""429 (a rate limit) and 503 (overloaded) are the two the error-codes guide and the SDKs retry(gen.retry, read 2026-10-13): the image is asked for again after the answer's retry-after or the@@ -230,8 +205,8 @@ def test_a_refusal_openai_documents_as_not_taken_is_sent_again(tmp_path, api, caassert f"[gen] openai refused the request ({refused[0]} {refused[1]['error']['code']}); nothing was made" in capsys.readouterr().err[email protected]("code", ["credit_balance_exhausted", "organization_spend_limit_exceeded",- "project_spend_limit_exceeded", "organization_usage_limit_exceeded", "insufficient_quota"])+# Which billing codes are not sent again is tests/gen/test_retry.py's table; the line is the same for each.[email protected]("code", ["insufficient_quota"])def test_a_billing_429_asks_the_caller_to_act_and_is_not_sent_again(tmp_path, api, code):api.update(status=429, body={"error": {"type": "insufficient_quota", "code": code}})with pytest.raises(SystemExit, match=f"HTTP 429.*code={code}; no retry or provider fallback"):@@ -247,7 +222,7 @@ def test_a_refusal_still_there_after_two_more_sends_ends_the_call(tmp_path, api)assert len(api["calls"]) == 3 and api["slept"] == [8.0, 16.0][email protected]("body", [{}, {"data": []}, {"data": [None]}, {"data": [{}, {}]},[email protected]("body", [{}, {"data": [None]}, {"data": [{}, {}]},{"data": [{"b64_json": "???"}]},{"data": [{"b64_json": base64.b64encode(b"invalid image").decode()}]},{"data": [{"url": "https://signed.invalid/private"}]}])@@ -326,7 +301,8 @@ def test_provider_is_registered_everywhere_a_provider_must_be(api):# --- 구독 우선 불변식 (수홍 2026-09-20) --------------------------------------# sprite-gen runs on subscriptions people already pay for. The API-key backend is# for servers and SaaS and is billed per call, so nothing may route to it on its-# own. These three tests are the guard rails for invariants 1, 2 and 3.+# own. These two tests are the guard rails for invariants 1 and 2; invariant 3 (the+# Grok login wins over XAI_API_KEY) is tests/gen/test_grok_provider.py's.def test_openai_is_explicit_only_and_never_a_default(monkeypatch, api):@@ -362,21 +338,6 @@ def test_an_api_key_in_the_environment_reroutes_nothing(monkeypatch, api, configassert api["calls"] == []-def test_grok_login_still_outranks_its_api_key(tmp_path, api, monkeypatch, capsys):- """불변식 3: the Grok subscription login wins over XAI_API_KEY."""- monkeypatch.setenv("XAI_API_KEY", "xai-api-secret")- monkeypatch.setenv("GROK_HOME", str(tmp_path))- (tmp_path / "auth.json").write_text(json.dumps({"account": {- "key": "subscription-token", "expires_at": "2100-01-01T00:00:00Z"}}))- assert xai.resolve_credential().source == xai.AUTH_SOURCE_GROK_LOGIN- monkeypatch.setattr(xai.urllib.request, "urlopen",- lambda request, *, timeout: _GrokResponse(request, api))- result = gen.generate_image("grok", "x", tmp_path / "grok.png")- assert result.extra["auth_source"] == xai.AUTH_SOURCE_GROK_LOGIN- # A subscription call says nothing about API billing; only the key route does.- assert "per-call API charge" not in capsys.readouterr().err--def test_every_api_key_call_announces_the_charge_before_it_leaves(tmp_path, api, capsys):"""불변식 5: one stderr line, before the request, naming the billing route."""gen.generate_image("openai", "x", tmp_path / "out.png", quality="low")@@ -385,16 +346,6 @@ def test_every_api_key_call_announces_the_charge_before_it_leaves(tmp_path, api,assert "OPENAI_API_KEY" in notice[0] and "quality=low" in notice[0]-def test_grok_on_an_api_key_announces_the_charge_too(tmp_path, api, monkeypatch, capsys):- monkeypatch.setenv("XAI_API_KEY", "xai-api-secret")- monkeypatch.setenv("GROK_HOME", str(tmp_path / "no-login"))- monkeypatch.setattr(xai.urllib.request, "urlopen",- lambda request, *, timeout: _GrokResponse(request, api))- gen.generate_image("grok", "x", tmp_path / "grok.png")- notice = [line for line in capsys.readouterr().err.splitlines() if "per-call API charge" in line]- assert len(notice) == 1 and "XAI_API_KEY" in notice[0]--def test_cli_accepts_provider_and_quality(tmp_path, api):report = tmp_path / "report.json"assert gen.main(["--provider", "openai", "--prompt", "x", "--out", str(tmp_path / "cli.png"),@@ -432,12 +383,10 @@ def _refused(tmp_path, api, status, error):return message[: -len(body)]+# Three branches: a documented stage, no moderation object, a stage outside MODERATION_STAGES.@pytest.mark.parametrize("details, stage", [({"moderation_details": {"moderation_stage": "output", "categories": ["other"]}}, " moderation_stage=output"),- ({"moderation_details": {"moderation_stage": "input"}}, " moderation_stage=input"),- ({"moderation_details": {"moderation_stage": "unknown"}}, " moderation_stage=unknown"),({}, ""),- ({"moderation_details": None}, ""),({"moderation_details": {"moderation_stage": "a sentence the body made up"}}, ""),])def test_a_content_policy_block_says_so_with_its_code(tmp_path, api, details, stage):@@ -454,8 +403,8 @@ def test_another_code_keeps_the_plain_failure_and_names_the_code(tmp_path, api):)[email protected]("error", [{}, {"code": None}, {"code": 400}, {"code": "has a space"},- {"code": "x" * 65}, {"code": ""}, {"code": "quote'd"}])+# `refusal.identifier`: no code, a code that is not a str, a str outside CODE_PATTERN.[email protected]("error", [{}, {"code": 400}, {"code": "has a space"}, {"code": "x" * 65}])def test_no_code_or_a_code_outside_the_format_leaves_the_line_as_it_was(tmp_path, api, error):assert _refused(tmp_path, api, 400, error) == ("openai-gen: image request failed (HTTP 400); no retry or provider fallback"diff --git a/tests/gen/test_painted_checkerboard.py b/tests/gen/test_painted_checkerboard.pyindex e8ea78a..c3d583b 100644--- a/tests/gen/test_painted_checkerboard.py+++ b/tests/gen/test_painted_checkerboard.py@@ -12,7 +12,6 @@ not a painted checkerboard. Every sheet here is synthetic.from __future__ import annotations-import jsonfrom pathlib import Pathimport numpy as np@@ -70,8 +69,8 @@ def test_an_element_across_two_edges_leaves_the_checkerboard_recognised():@pytest.mark.parametrize("background", [+ # a flat key leaves at the grey-share test whatever its hue: one key stands for bothpytest.param(lambda: np.full((384, 256, 3), MAGENTA, dtype=np.uint8), id="magenta key"),- pytest.param(lambda: np.full((384, 256, 3), (0, 255, 0), dtype=np.uint8), id="green key"),pytest.param(lambda: np.full((384, 256, 3), 240, dtype=np.uint8), id="plain light grey"),pytest.param(lambda: np.repeat(np.linspace(200, 255, 256).astype(np.uint8)[None, :, None], 384, 0).repeat(3, -1), id="grey gradient"),@@ -135,18 +134,3 @@ def test_a_ui_kit_generation_that_comes_back_on_a_checkerboard_is_refused(tmp_pagen.run(provider="fake", prompt="A game UI kit in brass and walnut.", out=out, report=report,transparent=True, layout_guide="ui-kit", aspect_ratio="2:3")assert not out.exists() and not report.exists()---def test_a_ui_kit_generation_on_a_key_background_is_keyed_as_before(tmp_path, monkeypatch):- class _KeyProvider(_CheckerboardProvider):- def generate(self, request, workdir):- image(with_elements(np.full((384, 256, 3), MAGENTA, dtype=np.uint8))).save(request.raw)- return gen_base.ProviderRun(provider=self.name, elapsed_seconds=0.1, model=request.model)-- monkeypatch.setattr(gen, "_make_provider", lambda name, *, keep_session: _KeyProvider())- out, report = tmp_path / "uikit.png", tmp_path / "report.json"- assert gen.run(provider="fake", prompt="A game UI kit in brass and walnut.", out=out, report=report,- transparent=True, layout_guide="ui-kit", aspect_ratio="2:3") == 0- alpha = json.loads(report.read_text(encoding="utf-8"))["alpha"]- assert alpha["strategy"] == "chroma" and alpha["strategy_source"] == "refs-attached"- assert 50 < alpha["alpha_zero_pct"] < 90diff --git a/tests/gen/test_pixel_draw.py b/tests/gen/test_pixel_draw.pyindex 300698b..f3bf1cf 100644--- a/tests/gen/test_pixel_draw.py+++ b/tests/gen/test_pixel_draw.py@@ -446,7 +446,6 @@ def test_a_used_folder_is_refused(tmp_path, claude):@pytest.mark.parametrize("args,message", [(["--size", "7"], "--size is 8..48 pixels, got 7"),(["--size", "49"], "--size is 8..48 pixels, got 49"),- (["--frames", ",".join(f"f{i}" for i in range(65))], "at most 64 frames, got 65"),(["--frames", "a,b", "--duration-ms", "5"], "--duration-ms is at least 10, got 5"),(["--style", " "], "--style is a sentence of words, got ' '"),(["--motion", "a spin"], "--motion is two or more frames"),@@ -516,22 +515,6 @@ def test_a_walk_cycle_is_one_call_of_four_frames(tmp_path, claude):assert preview.size == (4 * 256 + 3 * 16, 256)-def test_prompts_say_the_kind_and_the_format():- def request(**changes):- base = dict(subject="grass", size=32, kind="tile", frames=("tile",), walk_cycle=False,- palette=pg.palette_rule("free:8"), candidates=1, effort="high", answer_format="chargrid",- batch=False, max_tokens=32000, pick="vision")- return pixel_draw.PixelRequest(**{**base, **changes})- tile = pixel_draw.generation_prompt(request())- assert "This is a tile: fill every pixel (no transparency) and make it repeat seamlessly" in tile- assert "Palette: at most 8 colors plus transparent." in tile and "Background: transparent" not in tile- assert "```pixels\nPALETTE\n. transparent" in tile and "exactly 32 lines of exactly 32 characters" in tile- sprite = pixel_draw.generation_prompt(request(kind="sprite", frames=("down", "up"), subject="a knight"))- assert "stand on row 29 in every frame." in sprite and "goes below it" not in sprite- assert "Background: transparent." in sprite- assert "Frames in this order: down, up." in sprite--def test_an_edited_grid_is_checked_and_rendered_without_a_call(tmp_path, claude, monkeypatch):claude({"c1-gen1": reply(SPRITE16)})first = tmp_path / "first"@@ -631,25 +614,6 @@ def pixel_request(**changes) -> pixel_draw.PixelRequest:return pixel_draw.PixelRequest(**{**base, **changes})[email protected]("size,margin,inner,first,last", [(16, 1, 14, 2, 15), (24, 2, 20, 3, 22), (32, 3, 26, 4, 29),- (48, 4, 40, 5, 44)])-def test_the_prompt_says_the_safe_area_in_pixels(size, margin, inner, first, last):- """The engine's safe area (prepare's 9.4% margin, floored), in numbers the model can count - a- target for the body's size that a pose may go past, as the image path keeps it (frames/extract.py)."""- sprite = pixel_draw.generation_prompt(pixel_request(size=size))- assert "fill most of the canvas" not in sprite and "1-2 pixel margin" not in sprite- assert (f"Safe area: draw the subject's body about the size of the central {inner}x{inner} pixels - rows "- f"{first}-{last} and columns {first}-{last}, counting rows and columns from 1 - inside a {margin}-pixel "- "margin on every side. That is a target for its average size, not a wall: when a pose or a detail needs "- "the room (a raised weapon, a long blade, an effect, a wide stance), it may reach past the safe area "- "into the margin, up to the canvas edge. Keep the four corner pixels transparent.") in sprite- assert (f"Floor: row {last}, the bottom row of the safe area, is the ground: the feet (or the lowest point the "- f"subject rests on) stand on row {last}.") in sprite- for absolute in ("outermost rows and columns", "stay transparent", "Only a thin detail", "nothing reaches past",- "goes below it", "keep a"):- assert absolute not in sprite, absolute--def test_the_prompt_keeps_every_frame_on_the_floor_row_and_icons_off_it():walk = pixel_draw.generation_prompt(pixel_request(frames=("walk1", "walk2", "walk3", "walk4"), walk_cycle=True))assert "stand on row 29 in every frame." in walk@@ -713,12 +677,11 @@ def staff_answer() -> str:return "```pixels\nPALETTE\n. transparent\na #2a1f2e\nb #8a5a30\nFRAME sprite\n" + "\n".join(rows) + "\nEND\n```"+# The knight's two warnings reach the report in test_an_edited_grid_goes_through_the_safe_area_check.@pytest.mark.parametrize("answer,size,frame,warnings,info", [(staff_answer(), "32", "sprite", [],["G8: frames exceed the safe area 26x26 but fit within the margin zone (informational, no action): sprite:17x29"]),- (FULL16, "16", "front", ["G8: frames exceed the physical cap 16x15 (reroll candidates): front:14x16",- "G8 the feet are not on the floor row (the safe area's bottom row): front 1 px below it"], []),-], ids=["staff-to-the-edge", "knight-on-the-edge-rows"])+], ids=["staff-to-the-edge"])def test_one_candidate_past_the_safe_area_is_the_pick(tmp_path, claude, answer, size, frame, warnings, info):"""One candidate, as a caller that buys one drawing asks: a staff on the canvas edge, or a knightfrom helmet to boots on its edge rows, passes - its info lines and warnings in the report."""diff --git a/tests/gen/test_pixel_draw_frames.py b/tests/gen/test_pixel_draw_frames.pyindex 46d1450..7b1ece9 100644--- a/tests/gen/test_pixel_draw_frames.py+++ b/tests/gen/test_pixel_draw_frames.py@@ -155,8 +155,8 @@ def test_batches_draw_each_part_in_its_own_round(tmp_path, claude):assert "Frames already drawn" in fake.submitted[1][1][0][1]["messages"][0]["content"]+# The 64-frame limit is checked after the spec/flag split, as for --frames (tests/gen/test_pixel_effect.py).@pytest.mark.parametrize("frames,message", [- ([f"f{i}" for i in range(65)], "at most 64 frames, got 65"),([{"name": "a", "pose": ""}, "b"], "a frame is a name or {\"name\": ..., \"pose\": ...}"),([{"name": "a", "pose": "up", "hold": 2}, "b"], "a frame is a name or {\"name\": ..., \"pose\": ...}"),])@@ -181,7 +181,8 @@ def test_sixty_four_frames_are_sixteen_calls():STYLE = "no outline: selective outlining only where a shape meets its own colour, hue-shifted shadows"[email protected]("kind,frames", [("sprite", ("sprite",)), ("icon", ("icon",)), ("tile", ("tile",)),+# An icon shares the sprite's branch of `generation_prompt`.[email protected]("kind,frames", [("sprite", ("sprite",)), ("tile", ("tile",)),("effect", ("birth", "peak", "decay", "gone"))])def test_a_style_replaces_the_kinds_style_sentence_and_keeps_its_structure(kind, frames):default = pixel_draw.generation_prompt(pixel_request(kind=kind, frames=frames))@@ -291,14 +292,6 @@ def test_the_default_prompts_are_byte_for_byte_what_they_were():# ----------------------------------------------------------------------------- --motion and --duration-ms-def test_motion_is_two_or_more_frames_and_no_effect(tmp_path, claude):- claude({})- with pytest.raises(SystemExit, match="--motion is two or more frames"):- draw(tmp_path / "a", "--subject", "x", "--motion", "a spin")- with pytest.raises(SystemExit, match="--motion does not apply to an effect"):- draw(tmp_path / "b", "--subject", "x", "--kind", "effect", "--motion", "a spin")--def test_the_motion_sentence_follows_the_frames_line():prompt = pixel_draw.generation_prompt(pixel_request(frames=("a", "b"), motion="a bow"))lines = prompt.splitlines()diff --git a/tests/gen/test_pixel_gates.py b/tests/gen/test_pixel_gates.pyindex 8897d4e..366d0cd 100644--- a/tests/gen/test_pixel_gates.py+++ b/tests/gen/test_pixel_gates.py@@ -24,7 +24,7 @@ WALK = ("walk1", "walk2", "walk3", "walk4")FOURDIR = ("down", "up", "left", "right")FREE16 = pg.palette_rule("free")-INK, SKIN, GRASS, MOSS = (40, 30, 46, 255), (240, 192, 152, 255), (78, 144, 56, 255), (92, 158, 66, 255)+INK, SKIN, GRASS = (40, 30, 46, 255), (240, 192, 152, 255), (78, 144, 56, 255)CLEAR = (0, 0, 0, 0)@@ -70,48 +70,16 @@ def test_g2_counts_colours_against_the_limit_and_the_fixed_set():assert evaluate(frames, kind="sprite", rule=exact, walk_cycle=False)["G2"]["ok"]+# The opaque border and the tile's hole are `alpha_verdict`'s, tested in tests/gen/test_alpha_verdict.py.@pytest.mark.parametrize("frame,kind", [([[INK] + [CLEAR] * 7] + [[CLEAR] * 8 for _ in range(7)], "sprite"), # an opaque corner- ([[INK] * 8 for _ in range(3)] + blob()[3:], "icon"), # border mostly opaque([[CLEAR] * 8 for _ in range(8)], "sprite"), # nothing drawn- ([[GRASS] * 8 for _ in range(7)] + [[GRASS] * 7 + [CLEAR]], "tile"), # one hole in a tile])def test_g3_alpha_failures(frame, kind):gates = evaluate({"f": frame}, kind=kind, rule=FREE16, walk_cycle=False)assert not gates["ok"] and "G3" in gates["failed"]-def test_g4_seam_only_warns():- striped = [[GRASS if x < 2 or x >= 6 else MOSS for x in range(8)] for _ in range(8)] # wraps cleanly- seam = [[GRASS if x < 7 else INK for x in range(8)] for _ in range(8)]- clean = evaluate({"tile": striped}, kind="tile", rule=FREE16, walk_cycle=False)- assert clean["ok"] and not clean["G4"]["warn"] and clean["warnings"] == []- gates = evaluate({"tile": seam}, kind="tile", rule=FREE16, walk_cycle=False)- assert gates["G4"]["warn"] and gates["G4"]["needs_review"] == ["tile x"]- assert gates["ok"] and any(w.startswith("G4 tile seam") for w in gates["warnings"])---def test_g5_stray_pixels_only_warn():- frame = blob()- frame[7][7] = CLEAR- frame[0][4] = INK # a speck above the block, touching nothing- gates = evaluate({"f": frame}, kind="icon", rule=FREE16, walk_cycle=False) # an icon has no floor row- assert gates["G5"]["isolated_pixels"] == 1 and gates["ok"]- assert gates["warnings"] == ["G5 1 stray pixel(s) with no opaque neighbour"]---def test_g5_a_one_pixel_diagonal_stroke_is_not_stray():- """Each pixel of a diagonal stroke touches the next at a corner: joined, as a staff or a blade drawn- at 45 degrees is. Only the speck that touches nothing is stray."""- frame = [[INK if 6 <= y <= 11 and 6 <= x <= 11 else CLEAR for x in range(16)] for y in range(16)]- for step in (3, 4, 5):- frame[step][step] = INK- frame[2][12] = INK- gates = evaluate({"f": frame}, kind="icon", rule=FREE16, walk_cycle=False)- assert gates["G5"]["isolated_pixels"] == 1 and gates["G5"]["frames"] == {"f": 1}- assert gates["warnings"] == ["G5 1 stray pixel(s) with no opaque neighbour"]--def test_recorded_four_directions_stand_on_one_line():gates = evaluate(frames_of("fourdir-16-pass.txt", 16, FOURDIR), kind="sprite", rule=FREE16, walk_cycle=False)assert gates["G6"]["ok"] and gates["G6"]["identical_pairs"] == []@@ -128,6 +96,7 @@ def test_recorded_walk_passes_with_the_weak_leg_warning():gates = evaluate(frames_of("walk-32-safe-area-pass.txt", 32, WALK), kind="sprite", rule=FREE16, walk_cycle=True)g6 = gates["G6"]assert gates["ok"] and g6["ok"] and g6["height_spread"] == 1 # the passing pose is a pixel higher+ assert g6["rule"] == "motion" # a walk cycle is a motionassert g6["walk"]["warn"] and g6["walk"]["ratio"] < 0.4assert [w[:30] for w in gates["warnings"]] == ["G6 weak leg alternation: the c"] and gates["info"] == []assert set(g6["baselines"].values()) == {gates["G8"]["floor_row"]} == {28} # row 29 of 32, counted from 1@@ -165,7 +134,8 @@ def figure(size: int = 32):return paint(canvas(size), size // 4, m, size - 1 - size // 4, size - 1 - m)[email protected]("size,margin,inner", [(8, 0, 8), (16, 1, 14), (24, 2, 20), (32, 3, 26), (48, 4, 40)])+# `normalize_cell` is `int(width * RATIO)` with no branch on the size; the 0 px margin is its own test below.[email protected]("size,margin,inner", [(32, 3, 26)])def test_the_safe_area_is_the_engines(size, margin, inner):area = pixel_gates.safe_area(size, size)cell = prepare.normalize_cell({"width": size, "height": size}, size, None)@@ -191,11 +161,9 @@ def test_g8_passes_a_body_inside_the_safe_area():assert g8["frames"]["f"] == {"bbox": [8, 3, 23, 28], "size": [16, 26], "body_box": [8, 3, 23, 28]}+# The side blades take the thin-tip path and the bottom tail the floor path, each tested below.@pytest.mark.parametrize("stroke,info", [- ((24, 15, 31, 15), []), # a blade to the right edge: 24 columns, within the safe area's width- ((0, 20, 7, 20), []), # an arm to the left edge((15, 0, 15, 2), ["f:16x29"]), # a staff to the top edge: 29 rows, past the safe area, within the cap- ((12, 29, 12, 31), ["f:16x29"]), # a tail to the bottom edge, the feet still on the floor row])def test_g8_never_fails_a_pose_that_reaches_the_canvas_edge(stroke, info):"""The safe area is a target for the body's size, not a wall: a pose may reach the canvas edge."""@@ -214,40 +182,17 @@ def test_g8_lets_a_thin_tip_into_the_margin():assert measure["bbox"] == [8, 3, 30, 28] and measure["body_box"] == [8, 3, 23, 28]-def test_g8_notes_a_frame_past_the_safe_area_within_the_physical_cap():- """Size, not place: what the image path judges is how big the frame is against the cell."""- for inside in (paint(canvas(), 3, 3, 28, 28), paint(canvas(), 1, 3, 20, 28)): # 26x26, and 20x26 off-centre- gates = evaluate({"f": inside}, kind="sprite", rule=FREE16, walk_cycle=False)- assert gates["ok"] and gates["warnings"] == [] and gates["info"] == []- wide = paint(canvas(), 3, 3, 29, 28) # 27 columns- whole = paint(canvas(), 0, 3, 31, 28) # the canvas's width, edge to edge- staff = paint(figure(), 20, 0, 20, 2) # a staff to the top edge: 29 rows, the cap- gates = evaluate({"a": wide, "b": whole, "c": staff}, kind="icon", rule=FREE16, walk_cycle=False)- assert gates["ok"] and gates["failed"] == [] and gates["warnings"] == [] and not gates["G8"]["warn"]- assert gates["G8"]["past_safe_area"] == ["a", "b", "c"]- assert gates["info"] == ["G8: frames exceed the safe area 26x26 but fit within the margin zone (informational, "- "no action): a:27x26, b:32x26, c:16x29"]--def test_g8_warns_a_frame_past_the_physical_cap():"""The cap is the canvas's width and its height less the margin under the floor row: 32x29 at 32 px."""over = paint(figure(), 20, 0, 20, 29) # a staff from the top edge to a row under the floor row: 30 rowsfor kind in ("sprite", "icon"): # the same judgment for bothgates = evaluate({"f": over}, kind=kind, rule=FREE16, walk_cycle=False)assert gates["ok"] and gates["failed"] == [] and gates["G8"]["warn"] and gates["info"] == []+ assert "ok" not in gates["G8"]assert gates["G8"]["over_cap"] == ["f"] and gates["G8"]["frames"]["f"]["body_box"][3] == 28assert gates["warnings"] == ["G8: frames exceed the physical cap 32x29 (reroll candidates): f:16x30"]-def test_g8_never_fails_a_candidate():- """A plus across the whole canvas: past the cap and off the floor row - two warnings, and it passes."""- plus = paint(paint(canvas(), 15, 0, 16, 31), 0, 15, 31, 16)- gates = evaluate({"f": plus}, kind="sprite", rule=FREE16, walk_cycle=False)- assert gates["ok"] and gates["failed"] == [] and "ok" not in gates["G8"] and gates["info"] == []- assert gates["warnings"] == ["G8: frames exceed the physical cap 32x29 (reroll candidates): f:32x32",- "G8 the feet are not on the floor row (the safe area's bottom row): f 12 px above it"]--def test_g8_warns_a_sprite_off_the_floor_row():floating = paint(canvas(), 8, 3, 23, 26)gates = evaluate({"a": floating, "b": paint(canvas(), 9, 3, 23, 26)}, kind="sprite", rule=FREE16, walk_cycle=False)@@ -313,15 +258,6 @@ def test_a_recorded_staff_and_spark_in_the_margin_pass():assert [m["bbox"][1] for m in gates["G8"]["frames"].values()] == [3, 1, 2, 3]-def test_recorded_answers_from_the_full_canvas_prompt_pass_g8_with_warnings():- """Drawn when the prompt asked to fill the canvas: the knight's helmet is on row 1 and its boots- on row 16, the 16 px canvas's own edge rows - 16 rows, where 15 stand above the bottom margin."""- gates = evaluate(frames_of("sprite-16-pass.txt", 16, ("front",)), kind="sprite", rule=FREE16, walk_cycle=False)- assert gates["ok"] and gates["failed"] == [] and gates["info"] == []- assert gates["warnings"] == ["G8: frames exceed the physical cap 16x15 (reroll candidates): front:14x16",- "G8 the feet are not on the floor row (the safe area's bottom row): front 1 px below it"]--def test_g8_reads_a_frames_opaque_box_off_the_image_paths_judgment(monkeypatch):"""The opaque box G8 sizes a frame by is `frames.extract.solid_alpha_bbox` (alpha at least 128), thebox the image path crops a sprite to — one measure, not a second count of opaque rows here."""@@ -386,7 +322,3 @@ def test_g6_of_a_motion_warns_a_body_drawn_larger():"G6 the body changes size, not only its pose - its height, mass and breadth all grow or shrink by more ""than a pixel: b +29% against a"]--def test_a_walk_cycle_is_a_motion():- gates = evaluate(frames_of("walk-32-safe-area-pass.txt", 32, WALK), kind="sprite", rule=FREE16, walk_cycle=True)- assert gates["G6"]["rule"] == "motion" and gates["G6"]["walk"]["warn"]diff --git a/tests/gen/test_pixel_grid.py b/tests/gen/test_pixel_grid.pyindex fadc8ab..7a5f6b0 100644--- a/tests/gen/test_pixel_grid.py+++ b/tests/gen/test_pixel_grid.py@@ -32,17 +32,13 @@ def codes(issues):return sorted({i.code for i in issues})+# The other recorded answers (tile-16, fourdir-16, sprite-16-safe-area, walk-32-safe-area, attack-32-safe-area,+# attack-32-margin-detail) are parsed whole by the recorded tests of tests/gen/test_pixel_gates.py.PASSING = [("sprite-16-pass.txt", "chargrid", 16, ("front",)),("icon-32-pass.txt", "chargrid", 32, ("icon",)),- ("tile-16-pass.txt", "chargrid", 16, ("tile",)),("walk-16-pass.txt", "chargrid", 16, WALK),- ("fourdir-16-pass.txt", "chargrid", 16, FOURDIR),("icon-16-json-pass.txt", "json", 16, ("icon",)),- ("sprite-16-safe-area-pass.txt", "chargrid", 16, ("sprite",)),- ("walk-32-safe-area-pass.txt", "chargrid", 32, WALK),- ("attack-32-safe-area-pass.txt", "chargrid", 32, ("attack1", "attack2", "attack3", "attack4")),- ("attack-32-margin-detail.txt", "chargrid", 32, ("attack1", "attack2", "attack3", "attack4")),]@@ -226,15 +222,6 @@ def test_png_bytes_are_a_function_of_the_pixels_alone():assert image.mode == "RGBA" and list(image.get_flattened_data()) == [p for row in pixels for p in row]-def test_a_frame_png_decodes_to_the_grid_and_repeats_byte_for_byte():- grid, _ = pg.parse_answer(fixture("icon-32-pass.txt"), "chargrid", 32, 32, ("icon",))- pixels = pg.frame_pixels(grid, "icon")- first, second = pg.png_bytes(pixels), pg.png_bytes(pg.frame_pixels(grid, "icon"))- assert first == second- with Image.open(io.BytesIO(first)) as image:- assert image.size == (32, 32) and list(image.get_flattened_data()) == [p for row in pixels for p in row]--def test_palette_rules(tmp_path):assert pg.palette_rule("free") == pg.PaletteRule("free:16", 16)assert pg.palette_rule("free:8") == pg.PaletteRule("free:8", 8)diff --git a/tests/gen/test_prompt_assembly.py b/tests/gen/test_prompt_assembly.pyindex 0658a3a..1723b66 100644--- a/tests/gen/test_prompt_assembly.py+++ b/tests/gen/test_prompt_assembly.py@@ -22,7 +22,7 @@ import reimport pytestfrom sprite_gen import gen-from sprite_gen.gen import chroma, facing as facing_mod, handedness as h, prompt_parts+from sprite_gen.gen import chroma, handedness as h, prompt_partsfrom sprite_gen.gen import video as video_modfrom sprite_gen.video import batch, clip_prompt@@ -41,19 +41,17 @@ SUBJECT = "A small fox adventurer, 2D game sprite, full body"USER_TEXT = {"plain": {"text": f"{SUBJECT}."},"names-key": {"text": f"{SUBJECT}, magenta chroma-key background.", "key": "magenta"},- "names-key-hex": {"text": f"{SUBJECT} on a flat #FF00FF background.", "key": "magenta"},"says-turn": {"text": f"{SUBJECT}, facing right.", "turn": "right"},"says-item-side": {"text": f"{SUBJECT}, wearing a black smartwatch on its left wrist.", "item": "left"},"says-other-item-side": {"text": f"{SUBJECT}, wearing a black smartwatch on its right wrist.", "item": "right"},}# --character: words the motion paragraphs below never use, so a clip that names the character got them from hereCHARACTER = "A small fox adventurer in a green cloak"-STATES = ("idle", "walk", "run", "jump", "attack", "cheer")+STATES = ("idle", "walk", "run", "jump", "attack")MODELS = {"pro": "grok-imagine-video-1.5", "lite": "grok-imagine-video-1.5-lite"}-# --motion: the built-in sentence, the caller's own, one that quotes an engine rule, one that walks the other way+# --motion: the built-in sentence, the caller's own that quotes an engine rule, one that walks the other wayMOTION = {"built-in": {"text": None},- "own": {"text": "The fox walks with a cheerful bounce, swinging both arms."},"quotes-engine": {"text": "The fox walks with a cheerful bounce. Camera completely locked, no zoom, no pan, no reframing."},"says-turn": {"text": "The fox walks to the right with a cheerful bounce.", "turn": "right"},}@@ -83,7 +81,8 @@ def _still_rows():def _clip_rows():for (view, facing), handed, state, model, motion in itertools.product(_views(), HANDED, STATES, MODELS, MOTION):- if MOTION[motion]["text"] and state != "walk":+ # Lite adds its text to a walk only (`batch._lite_text`): another state's Lite prompt is the Pro one+ if state != "walk" and (MOTION[motion]["text"] or model == "lite"):continuemake = lambda items, v=view, s=state, f=facing or "right", m=MOTION[motion]["text"], mo=MODELS[model]: (batch.clip_prompt_parts(v, s, CHARACTER, facing=f, motion=m, model=mo, handed=items))@@ -91,7 +90,8 @@ def _clip_rows():row = {"user": None, "motion": motion, "facing": facing, "handed": handed, "state": state, "character": CHARACTER,"plain": make(None).text}yield f"clip/{view}@{facing}/{state}/{model}/{motion}/{handed}", parts, row- if view == "side": # handed on to `sprite-gen video --direction side`+ # handed on to `sprite-gen video --direction side`, whose hold sentence is appended whatever the clip says+ if view == "side" and (state, model, motion) == ("walk", "pro", "built-in"):yield (f"clip+video/{view}@{facing}/{state}/{model}/{motion}/{handed}",video_mod.side_view_prompt(parts.text, facing), {**row, "clip": parts})@@ -109,6 +109,13 @@ def _start_still_rows():ROWS = [*_still_rows(), *_clip_rows(), *_start_still_rows()]_HANDED_ROWS = [r for r in ROWS if r[2]["handed"] != "none"]+# without --handed a row's prompt and its plain one are the same call: one such row per kind, and every side hold+_FIRST_PLAIN = {name.split("/")[0]: name for name, _, row in reversed(ROWS) if row["handed"] == "none"}+_ASSEMBLY_ROWS = [r for r in ROWS+ if r[2]["handed"] != "none" or r[0].startswith("clip+video/") or r[0] in _FIRST_PLAIN.values()]+# the engine's own words handed on carry no handed piece of their own, and their notes are the first verb's+_NOTED_ROWS = [r for r in ROWS if not r[0].startswith(("clip+video/", "start-still"))]+_TWICE_ROWS = [r for r in _HANDED_ROWS if not r[0].startswith(("clip+video/", "start-still/"))]# -- the checks ------------------------------------------------------------------------------------@@ -138,10 +145,10 @@ def _without_handed(parts: prompt_parts.Prompt) -> str:def test_the_table_covers_every_place_a_prompt_is_put_together() -> None:kinds = {name.split("/")[0] for name, _, _ in ROWS}assert kinds == {"still", "clip", "clip+video", "start-still", "start-still+gen"}- assert len(_HANDED_ROWS) > 1000+ assert len(_HANDED_ROWS) > 600[email protected]("name,parts,row", ROWS, ids=[name for name, _, _ in ROWS])[email protected]("name,parts,row", _ASSEMBLY_ROWS, ids=[name for name, _, _ in _ASSEMBLY_ROWS])def test_handed_puts_in_its_piece_and_changes_nothing_else(name, parts, row) -> None:"""With --handed the prompt is the one without it (2.22.0's) and the handed piece; without it, there is none."""if name.startswith("clip+video"):@@ -156,20 +163,18 @@ def test_handed_puts_in_its_piece_and_changes_nothing_else(name, parts, row) ->assert parts.piece("handed") is None and parts.text == row["plain"][email protected]("name,parts,row", _HANDED_ROWS, ids=[name for name, _, _ in _HANDED_ROWS])[email protected]("name,parts,row", _TWICE_ROWS, ids=[name for name, _, _ in _TWICE_ROWS])def test_no_handed_sentence_is_said_twice(name, parts, row) -> None:said = _sentences(parts.text)for sentence in _sentences(_handed_text(parts)):assert said.count(sentence) == 1, (sentence, parts.text)[email protected]("name,parts,row", ROWS, ids=[name for name, _, _ in ROWS])[email protected]("name,parts,row", _NOTED_ROWS, ids=[name for name, _, _ in _NOTED_ROWS])def test_the_notes_say_where_the_callers_words_turn_or_place_the_item_the_other_way(name, parts, row) -> None:caller = {**USER_TEXT.get(row["user"] or "", {}), **MOTION.get(row.get("motion") or "", {})}facing = row["facing"]conflicts = {note["about"] for note in parts.notes if note["kind"] == "conflict"}- if name.startswith("clip+video") or name.startswith("start-still"):- return # the engine's own words handed on: the notes are the first verb'sif caller.get("turn") not in (None, facing):# the caller's own words turn another way than the view: they are left as written, and the notes say soassert "facing" in conflicts, name@@ -287,16 +292,3 @@ def test_gen_reports_what_the_callers_text_says_against_the_options(tmp_path, moassert '[gen] warning: the text says "facing left" and the engine\'s sentence says right' in errquiet = gen.generate_image("fake", "a fox", tmp_path / "quiet.png", view="side", facing="right")assert "prompt_notes" not in quiet.extra---def test_video_prompt_names_the_character_in_every_view_of_a_callers_walk() -> None:- for view, state in itertools.product(h.VIEWS, batch.GAIT_STATES):- record = clip_prompt.plan_prompt(direction=view, state=state, character=CHARACTER, facing="right",- motion=MOTION["own"]["text"])- assert record["prompt"].count(CHARACTER) == 1, record["prompt"]---def test_the_facing_correction_is_said_after_the_prompt_as_2_22_0_did() -> None:- """`--facing-fix regen` sends the first prompt and the correction after it (`facing.prepare_correction`)."""- assert facing_mod.prompt_suffix("left", retry=True).startswith("CORRECTION REQUIRED: redraw the subject's orientation. "- "The subject must be facing left")diff --git a/tests/gen/test_prompt_freeze.py b/tests/gen/test_prompt_freeze.pyindex 77ae6ab..cc659e7 100644--- a/tests/gen/test_prompt_freeze.py+++ b/tests/gen/test_prompt_freeze.py@@ -125,20 +125,6 @@ def test_only_the_diagonal_still_sentences_moved(frozen, drawn) -> None:assert f"not a {angle} view with only the head turned" in drawn[name]-def test_the_default_walk_keeps_its_treadmill_and_screen_sentences(frozen, drawn) -> None:- """The built-in walk and run paragraphs are frozen with everything else: "as if on a treadmill" (kept in- place for a body without legs to read, a slime's bounce included), "without moving across the screen" in- the gait sentence as well as the frame sentence, and the view sentence after the gait sentence."""- for name, prompt in frozen.items():- if name.startswith("clip/") and name.split("/")[2] in ("walk", "run") and "/built-in/" in name:- assert "as if on a treadmill" in prompt and drawn[name] == prompt, name- side = drawn["clip/side@right/walk/built-in/default/pinned=None/no-character"]- assert "walks naturally in place, as if on a treadmill, without moving across the screen." in side- assert "The character is seen from the exact side, facing right." in side- front = drawn["clip/front@right/walk/built-in/default/pinned=None/no-character"]- assert "The character is seen from the front" in front--PREPARE_FIXTURE = Path(__file__).resolve().parents[1] / "fixtures" / "prepare-rows-v2.32.0.json.gz"diff --git a/tests/gen/test_refusal.py b/tests/gen/test_refusal.pyindex 388e056..a804fe8 100644--- a/tests/gen/test_refusal.py+++ b/tests/gen/test_refusal.py@@ -23,19 +23,15 @@ TOKENS = {"secret": (SECRET, SECRET),}-# What stands right in front of the token in the provider's text. JSON, `repr`-# and the raw-body line join write most of these as an escape (`\n`, `\t`,-# `\x0b`, `→`), which a mask on the finished line read as a letter or digit.+# What stands right in front of the token in the provider's text: one of each class the mask's one lookbehind,+# `(?<![A-Za-z0-9])`, tells apart. JSON, `repr` and the raw-body line join write some of these as an escape+# (`\n`, `→`), which a mask on the finished line read as a letter or digit.SEPARATORS = {- "start": "", "space": " ", "colon": ":", "equals": "=", "paren": "(", "dquote": '"', "squote": "'",- "backslash": "\\", "underscore": "_", "hyphen": "-",- "LF": "\n", "CRLF": "\r\n", "CR": "\r", "TAB": "\t", "VT": "\x0b", "FF": "\x0c", "BS": "\x08",- "SOH": "\x01", "DEL": "\x7f", "NEL": "\x85", "NBSP": "\xa0", "ZWSP": "", "LSEP": " ",- "arrow": "→", "e-acute": "é", "hangul": "한", "emoji": "\U0001f600",+ "start": "", "space": " ", "underscore": "_", "hyphen": "-", "LF": "\n", "arrow": "→", "hangul": "한",# A letter or digit in front: a key or Bearer value is part of a word."letter": "x", "digit": "2",# The provider's own encoding: its text has a letter or digit in front, so the same.- "provider-backslash-n": "\\n", "provider-percent-0A": "%0A",+ "provider-backslash-n": "\\n",}# path -> how the provider's string reaches the printed line@@ -54,11 +50,16 @@ def _masked_by_rule(sep: str, kind: str) -> bool:return kind in ("url", "secret") or not (before.isascii() and before.isalnum())+# a URL query or the credential is masked whatever stands in front: the start and an escaped LF are enough+CELLS = [(sep, kind) for sep in SEPARATORS for kind in TOKENS+ if kind not in ("url", "secret") or sep in ("start", "LF")]++@pytest.mark.parametrize("path", PATHS)[email protected]("kind", TOKENS)[email protected]("sep", SEPARATORS)[email protected](("sep", "kind"), CELLS, ids=[f"{sep}-{kind}" for sep, kind in CELLS])def test_masked_whatever_stands_in_front_unless_a_letter_or_digit_makes_it_a_word(sep, kind, path) -> None:- """31 separators x 5 kinds x 6 paths: 858 cells masked, 72 left as a word."""+ """10 separators x 3 kinds and 2 x 2 for a URL query and the credential, x 6 paths: 150 cells masked, 54 left+ as a word."""token, hidden = TOKENS[kind]printed = PATHS[path](("x" + SEPARATORS[sep] if SEPARATORS[sep] else "") + token)if _masked_by_rule(SEPARATORS[sep], kind):@@ -69,42 +70,14 @@ def test_masked_whatever_stands_in_front_unless_a_letter_or_digit_makes_it_a_worassert "[redacted]" not in printed-def test_a_key_after_a_line_break_in_json() -> None:- assert refusal.said({"error": {"message": "x\nsk-" + "A" * 40}}) == ': {"error": {"message": "x\\nsk-[redacted]"}}'---def test_a_bearer_value_after_a_line_break_in_a_raw_body() -> None:- assert refusal.said(refusal.RawBody("x\nBearer " + "t" * 32)) == ": x\\nBearer [redacted]"---def test_a_bearer_value_after_a_line_break_on_the_video_lines() -> None:- assert video._error_detail({"message": "x\nBearer " + "t" * 32}) == "message='x\\nBearer [redacted]'"---def test_a_bearer_value_after_a_tab_in_json() -> None:- assert refusal.said({"error": {"message": "x\tBearer " + "t" * 32}}) == ': {"error": {"message": "x\\tBearer [redacted]"}}'---def test_a_key_after_a_non_ascii_character_on_the_video_json_fallback() -> None:- assert video._error_detail({"x": ["→sk-" + "A" * 40]}) == '{"x": ["\\u2192sk-[redacted]"]}'--[email protected](("said", "printed"), [- ("see\nhttps://files.example.invalid/o.png?X-Signature=0a1b",- ': {"error": {"message": "see\\nhttps://files.example.invalid/o.png?[redacted]"}}'),- ("see_https://files.example.invalid/o.png?X-Signature=0a1b",- ': {"error": {"message": "see_https://files.example.invalid/o.png?[redacted]"}}'),- ("seehttps://files.example.invalid/o.png?X-Signature=0a1b",- ': {"error": {"message": "seehttps://files.example.invalid/o.png?[redacted]"}}'),- ("한https://files.example.invalid/o.png?X-Signature=0a1b",- ': {"error": {"message": "한https://files.example.invalid/o.png?[redacted]"}}'),-], ids=["line-break", "underscore", "letter", "hangul"])-def test_a_url_query_is_masked_wherever_the_url_starts(said, printed) -> None:- assert refusal.said({"error": {"message": said}}) == printed+def test_a_url_query_is_masked_wherever_the_url_starts() -> None:+ # the URL query has no lookbehind: a letter in front, which leaves a key a word, still masks it+ assert (refusal.said({"error": {"message": "seehttps://files.example.invalid/o.png?X-Signature=0a1b"}})+ == ': {"error": {"message": "seehttps://files.example.invalid/o.png?[redacted]"}}')@pytest.mark.parametrize("path", PATHS)[email protected]("gap", ["\t", "\n", "\r\n", "\xa0"], ids=["TAB", "LF", "CRLF", "NBSP"])[email protected]("gap", ["\n", "\xa0"], ids=["LF", "NBSP"]) # one `\s+`: an escaped one and a Unicode onedef test_a_bearer_value_after_any_whitespace(gap, path) -> None:assert "synthetic.token" not in PATHS[path]("x Bearer" + gap + "synthetic.token.value-0123456789")diff --git a/tests/gen/test_video.py b/tests/gen/test_video.pyindex 16dc2f7..af1567d 100644--- a/tests/gen/test_video.py+++ b/tests/gen/test_video.py@@ -96,11 +96,13 @@ def clock(monkeypatch) -> _Clock:# --- credential resolution -------------------------------------------------[email protected]("api_key", ["xai-console", "", " "])+# A login file is read before the env is (`xai.resolve_credential`), so any key value, or none, takes one path.[email protected]("api_key", ["xai-console", " "])def test_grok_login_wins_over_api_key_env(tmp_path: Path, monkeypatch, api_key) -> None:monkeypatch.setenv("GROK_HOME", str(_login_file(tmp_path)))cred = video.resolve_credential(env={"XAI_API_KEY": api_key}, now=NOW)assert cred.token == "tok" and cred.source == video.AUTH_SOURCE_GROK_LOGIN+ assert cred.expires_at == "2026-09-08T18:00:00.000000Z"def test_api_key_is_used_only_without_a_login_file(tmp_path: Path, monkeypatch) -> None:@@ -109,24 +111,6 @@ def test_api_key_is_used_only_without_a_login_file(tmp_path: Path, monkeypatch)assert cred == video.Credential(token="xai-console", source=video.AUTH_SOURCE_API_KEY)-def test_grok_login_is_used_when_no_api_key(tmp_path: Path, monkeypatch) -> None:- monkeypatch.setenv("GROK_HOME", str(_login_file(tmp_path, key="oidc-token")))- cred = video.resolve_credential(env={}, now=NOW)- assert cred.source == video.AUTH_SOURCE_GROK_LOGIN- assert cred.token == "oidc-token"- assert cred.expires_at == "2026-09-08T18:00:00.000000Z"---def test_expired_grok_login_fails_before_upload_with_refresh_prescription(tmp_path: Path, monkeypatch) -> None:- monkeypatch.setenv("GROK_HOME", str(_login_file(tmp_path, expires_at="2026-09-08T10:56:34.899829Z")))- with pytest.raises(SystemExit, match="expired at 2026-09-08T10:56:34") as excinfo:- video.resolve_credential(env={}, now=NOW)- message = str(excinfo.value)- assert video.GROK_REFRESH_COMMAND in message- assert video.GROK_LOGIN_COMMAND in message- assert "never rewrites" in message--def test_missing_login_and_key_prescribes_both_setups(tmp_path: Path, monkeypatch) -> None:monkeypatch.setenv("GROK_HOME", str(tmp_path / "nowhere"))with pytest.raises(SystemExit, match="no xAI credential") as excinfo:@@ -140,14 +124,6 @@ def test_empty_api_key_env_is_refused_not_ignored(tmp_path: Path, monkeypatch) -video.resolve_credential(env={"XAI_API_KEY": " "}, now=NOW)-def test_login_file_with_two_accounts_is_refused(tmp_path: Path, monkeypatch) -> None:- home = _login_file(tmp_path)- (home / "auth.json").write_text(json.dumps({"a": {"key": "1"}, "b": {"key": "2"}}), encoding="utf-8")- monkeypatch.setenv("GROK_HOME", str(home))- with pytest.raises(SystemExit, match="holds 2 account entries"):- video.resolve_credential(env={}, now=NOW)--def test_login_without_expiry_is_accepted(tmp_path: Path, monkeypatch) -> None:monkeypatch.setenv("GROK_HOME", str(_login_file(tmp_path, expires_at=None)))assert video.resolve_credential(env={}, now=NOW).expires_at is None@@ -190,22 +166,13 @@ def test_generate_video_posts_data_url_polls_and_publishes_verified_mp4(tmp_pathassert "tok" not in dumped.replace("token", "") and "vidgen.x.ai/v/1.mp4" not in dumped-def test_audio_default_is_left_to_the_api(tmp_path: Path) -> None:- api = _FakeApi()- video.generate_video(_request(tmp_path), credential=video.Credential("t", "XAI_API_KEY"), call=api.call, download=api.download, sleep=lambda s: None)- assert "generate_audio" not in api.calls[0][3] and "aspect_ratio" not in api.calls[0][3]--+# A refused POST, a failed poll, a poll refused for good and a done poll naming no url each have their own test below.@pytest.mark.parametrize(("post", "polls", "expected"),[((200, {"error": "quota"}), None, "generation request refused"),- ((400, {"code": "invalid-argument", "error": "Zero Data Retention teams must provide output.upload_url"}), None, "refused \\(HTTP 400\\)"),((403, {"code": "unauthenticated:bad-credentials", "error": "The OAuth2 access token could not be validated."}), None, "rejected the credential \\(grok-login\\) with HTTP 403"),- ((200, {"request_id": "r"}), [(200, {"status": "failed", "error": "nsfw"})], "status='failed'"),((200, {"request_id": "r"}), [(200, {"status": "expired"})], "status='expired'"),- ((200, {"request_id": "r"}), [(404, {"raw": "boom"})], "HTTP 404"),- ((200, {"request_id": "r"}), [(200, {"status": "done", "video": {}})], "poll named no video url to download"),],)def test_api_failures_are_named_and_write_nothing(tmp_path: Path, post, polls, expected) -> None:@@ -225,14 +192,6 @@ def test_bad_credential_prescribes_refresh_for_login_and_check_for_key(tmp_path:video.generate_video(_request(tmp_path), credential=video.Credential("t", video.AUTH_SOURCE_API_KEY), call=api.call, download=api.download, sleep=lambda s: None)-def test_poll_timeout_fails_loud(tmp_path: Path, clock) -> None:- api = _FakeApi(polls=[(200, {"status": "pending"})])- request = _request(tmp_path)- with pytest.raises(SystemExit, match="poll timeout"):- video.generate_video(request, credential=video.Credential("t", "XAI_API_KEY"), call=api.call, download=api.download, sleep=clock.sleep, poll_timeout=10)- assert not request.out.exists()--@pytest.mark.parametrize(("overrides", "expected"),[@@ -329,7 +288,8 @@ def test_uninspectable_login_never_permits_api_credit(tmp_path, monkeypatch):video.resolve_credential(env={"XAI_API_KEY": "console-key"}, now=NOW)[email protected]("status", [200, 403, 503])+# 403 and 503 both end on the first call, on the subscription token.[email protected]("status", [200, 403])def test_video_uses_subscription_with_api_key_present(tmp_path, monkeypatch, status):monkeypatch.setenv("GROK_HOME", str(_login_file(tmp_path, key="subscription-token", expires_at="2100-01-01T00:00:00Z")))monkeypatch.setenv("XAI_API_KEY", "console-key")@@ -353,9 +313,12 @@ def test_refresh_prescription_is_a_non_agent_command_run_outside_the_repo(tmp_paassert " -p " not in f" {video.GROK_REFRESH_COMMAND} " and "--single" not in video.GROK_REFRESH_COMMANDassert "empty directory" in video.GROK_REFRESH_WHEREmonkeypatch.setenv("GROK_HOME", str(_login_file(tmp_path, expires_at="2026-09-08T10:56:34.899829Z")))- with pytest.raises(SystemExit) as excinfo:+ with pytest.raises(SystemExit, match="expired at 2026-09-08T10:56:34") as excinfo:video.resolve_credential(env={}, now=NOW)message = str(excinfo.value)+ assert video.GROK_REFRESH_COMMAND in message+ assert video.GROK_LOGIN_COMMAND in message+ assert "never rewrites" in messageassert video.GROK_REFRESH_WHERE in messageassert "grok -p ok" not in message.replace("`grok -p …`", "")assert "coding agent" in message@@ -406,7 +369,8 @@ def test_every_verb_announces_the_charge_before_the_request_leaves(tmp_path: Patassert f"`{video.GROK_LOGIN_COMMAND}` signs your Grok subscription in." in notice[0][email protected]("verb", ["video", "video-extend", "video-edit"])+# One `if credential.source == AUTH_SOURCE_API_KEY` for every verb.[email protected]("verb", ["video"])def test_the_subscription_route_stays_silent_about_billing(tmp_path: Path, capsys, verb) -> None:api = _FakeApi()_billed_run(verb, tmp_path, credential=video.Credential("tok", video.AUTH_SOURCE_GROK_LOGIN),@@ -467,18 +431,6 @@ def test_a_moderated_clip_is_a_content_policy_refusal(tmp_path: Path) -> None:assert HTTP_STATUS.search(message).group(1) == "200"-def test_a_moderated_clip_is_refused_even_if_a_url_came_back(tmp_path: Path) -> None:- api = _FakeApi(polls=[(200, {"status": "done", "video": {"url": "https://vidgen.x.ai/v/1.mp4", "respect_moderation": False}})])- assert "refused by the provider's content policy" in _refused(tmp_path, api)[0]---def test_a_clip_that_respects_moderation_publishes(tmp_path: Path) -> None:- api = _FakeApi(polls=[(200, {"status": "done", "video": {"url": "https://vidgen.x.ai/v/1.mp4", "duration": 6.0, "respect_moderation": True}})])- request = _request(tmp_path)- video.generate_video(request, credential=video.Credential("t", video.AUTH_SOURCE_GROK_LOGIN), call=api.call, download=api.download, sleep=lambda s: None)- assert request.out.read_bytes() == MP4--def test_a_failed_poll_names_the_code_inside_its_error_object(tmp_path: Path) -> None:"""`invalid_argument` covers moderation and bad parameters alike, so it is a code, not a policy verdict."""api = _FakeApi(polls=[(200, {"status": "failed", "error": {"code": "invalid_argument", "message": "synthetic"}})])@@ -520,31 +472,19 @@ def test_a_key_the_300_character_cut_would_split_is_masked_before_the_cut(body)assert "xai-[redacted]" in detail and len(detail) <= 300+# The separators and the word case are cells of tests/gen/test_refusal.py's masking grid (`video:repr`);+# this lowercase row is the one that reaches `_BEARER`'s `(?i)`.@pytest.mark.parametrize(("said", "masked"), [- ("api_key_sk-" + "Synthetic0Key1For2Tests" * 2, "api_key_sk-[redacted]"),- ("token-xai-" + "Synthetic0Key1For2Tests" * 2, "token-xai-[redacted]"),- ("task-" + "Synthetic0Key1For2Tests" * 2, "task-" + "Synthetic0Key1For2Tests" * 2),-], ids=["underscore", "hyphen", "word"])-def test_a_key_after_an_underscore_or_hyphen_is_masked_and_a_word_ending_in_sk_is_not(said, masked) -> None:- assert video._error_detail({"message": said}) == f"message={masked!r}"--[email protected](("said", "masked"), [- ("Authorization: Bearer " + "synthetic.token.value-0123456789", "Authorization: Bearer [redacted]"),- ("x_Bearer " + "synthetic.token.value-0123456789", "x_Bearer [redacted]"),("x-bearer " + "synthetic.token.value-0123456789", "x-bearer [redacted]"),- ("xbearer " + "synthetic.token.value-0123456789", "xbearer " + "synthetic.token.value-0123456789"),-], ids=["header", "underscore", "hyphen", "word"])+], ids=["hyphen"])def test_a_bearer_value_after_an_underscore_or_hyphen_is_masked_and_a_word_ending_in_bearer_is_not(said, masked) -> None:assert video._error_detail({"message": said}) == f"message={masked!r}"+# One code read and one left off; refusal.read's other cases are the provider grids'.@pytest.mark.parametrize(("post", "prefix"), [((400, {"code": "invalid-argument", "error": "synthetic"}), "video: generation request refused (HTTP 400) code=invalid-argument: "),- ((400, {"error": {"code": "invalid_argument", "message": "synthetic"}}), "video: generation request refused (HTTP 400) code=invalid_argument: "),- ((400, {"error": "synthetic"}), "video: generation request refused (HTTP 400): "),((400, {"code": "not a code", "error": "synthetic"}), "video: generation request refused (HTTP 400): "),- ((429, {"error": {"code": "x" * 65}}), "video: generation request refused (HTTP 429): "),])def test_a_refused_request_names_a_well_formed_code(tmp_path: Path, post, prefix) -> None:message, _ = _refused(tmp_path, _FakeApi(post=post))@@ -561,7 +501,8 @@ def test_a_refused_request_names_a_well_formed_code(tmp_path: Path, post, prefixDONE = (200, {"status": "done", "video": {"url": "https://vidgen.x.ai/v/1.mp4", "duration": 6.0}, "model": "grok-imagine-video-1.5"})[email protected]("status", [429, 500, 502, 503, 504])+# One branch, `http in retry.GET_AGAIN`; the set itself is tests/gen/test_retry.py's.[email protected]("status", [429, 503])def test_a_throttled_poll_asks_the_same_request_again_and_publishes(tmp_path: Path, status) -> None:api = _FakeApi(polls=[(status, {"code": "synthetic", "error": "slow down"}), (status, {"error": "slow down"}),(200, {"status": "pending"}), DONE])@@ -577,11 +518,13 @@ def test_a_throttled_poll_asks_the_same_request_again_and_publishes(tmp_path: Paassert payload["request_id"] == "req-1" and payload["polls"] == 4 and payload["polls_refused"] == 2-def test_a_clip_whose_polls_were_never_refused_reports_no_retry(tmp_path: Path) -> None:+def test_a_clip_answered_at_once_reports_no_retry_none_unanswered_and_one_download(tmp_path: Path) -> None:api = _FakeApi()payload = video.generate_video(_request(tmp_path), credential=video.Credential("t", "XAI_API_KEY"),call=api.call, download=api.download, sleep=lambda s: None).to_dict()assert payload["polls"] == 1 and payload["polls_refused"] == 0+ assert payload["polls_unanswered"] == 0+ assert payload["downloads"] == 1def test_polls_refused_until_the_poll_timeout_end_naming_the_request_to_ask_again(tmp_path: Path, clock, capsys) -> None:@@ -610,16 +553,19 @@ def test_polls_refused_until_the_poll_timeout_end_naming_the_request_to_ask_agaidef test_a_poll_timeout_while_pending_names_the_request_to_ask_again(tmp_path: Path, clock) -> None:api = _FakeApi(polls=[(200, {"status": "pending"})])+ request = _request(tmp_path)with pytest.raises(video.GenerationUnfinished) as unfinished:- video.generate_video(_request(tmp_path), credential=video.Credential("t", "XAI_API_KEY"),+ video.generate_video(request, credential=video.Credential("t", "XAI_API_KEY"),call=api.call, download=api.download, sleep=clock.sleep, poll_timeout=10)message = str(unfinished.value)assert message.startswith("video: generation req-1 still 'pending' after 3 polls — poll timeout; ")assert "request_id=req-1" in message and HTTP_STATUS.search(message) is Noneassert (unfinished.value.request_id, unfinished.value.last_http, unfinished.value.last_status) == ("req-1", 200, "pending")+ assert not request.out.exists()[email protected]("status", [400, 404])+# One branch for any status past GET_AGAIN and 401/403; 404 is the resume test's.[email protected]("status", [400])def test_a_poll_refused_for_good_ends_at_once_with_its_status(tmp_path: Path, status) -> None:api = _FakeApi(polls=[(status, {"error": "synthetic"})])message, _ = _refused(tmp_path, api)@@ -627,7 +573,8 @@ def test_a_poll_refused_for_good_ends_at_once_with_its_status(tmp_path: Path, stassert HTTP_STATUS.search(message).group(1) == str(status)[email protected]("status", [400, 500, 503])+# Every status but 429 fails `retry.again_after("xai")`; the table is tests/gen/test_retry.py's.[email protected]("status", [503])def test_a_refused_submission_is_never_sent_again(tmp_path: Path, status) -> None:"""A POST is sent again only on an answer xAI documents as a request not taken, 429 (gen.retry):any other refusal may have been worked on, and it keeps `(HTTP n)` for the caller."""@@ -710,13 +657,12 @@ class _LossyApi(_FakeApi):return reply+# `xai.no_answer_reason`: a URLError unwrapped, an empty message named by its type, a plain OSError.@pytest.mark.parametrize(("raised", "reason"), [- (urllib.error.URLError("[Errno 8] nodename nor servname provided"), "[Errno 8] nodename nor servname provided"),(urllib.error.URLError(TimeoutError("timed out")), "timed out"),- (TimeoutError("timed out"), "timed out"),(TimeoutError(), "TimeoutError"),(ConnectionResetError(54, "Connection reset by peer"), "[Errno 54] Connection reset by peer"),-], ids=["dns", "url-timeout", "timeout", "bare-timeout", "reset"])+], ids=["url-timeout", "bare-timeout", "reset"])def test_http_json_names_a_request_that_got_no_answer(monkeypatch, raised, reason) -> None:"""Still the SystemExit and line it always was; the type lets a caller that may ask again catch it."""def urlopen(request, *, timeout):@@ -745,13 +691,6 @@ def test_a_poll_that_gets_no_answer_is_asked_again_and_publishes(tmp_path: Path,assert "[video] poll 1 of generation req-1 got no answer (timed out); asking again in 8s" in capsys.readouterr().err-def test_a_clip_whose_polls_were_all_answered_reports_none_unanswered(tmp_path: Path) -> None:- api = _FakeApi()- payload = video.generate_video(_request(tmp_path), credential=video.Credential("t", "XAI_API_KEY"),- call=api.call, download=api.download, sleep=lambda s: None).to_dict()- assert payload["polls_unanswered"] == 0--def test_polls_that_get_no_answer_until_the_poll_timeout_end_unfinished_naming_the_request(tmp_path: Path, clock) -> None:api = _LossyApi(polls=[LOST])request = _request(tmp_path)@@ -787,12 +726,12 @@ def test_a_submission_that_gets_no_answer_is_not_unfinished_and_is_never_sent_agassert calls == ["POST"] and "no automatic retry" in str(failed.value)[email protected]("status", [401, 403])[email protected](("source", "fix"), [- (video.AUTH_SOURCE_GROK_LOGIN, f"refresh the login with `{video.GROK_REFRESH_COMMAND}` run {video.GROK_REFRESH_WHERE} "- f"or `{video.GROK_LOGIN_COMMAND}`"),- (video.AUTH_SOURCE_API_KEY, f"check the {video.AUTH_ENV} value"),-], ids=["grok-login", "api-key"])+# `http in (401, 403)` is one branch; the source picks only the fix text.[email protected](("status", "source", "fix"), [+ (401, video.AUTH_SOURCE_GROK_LOGIN, f"refresh the login with `{video.GROK_REFRESH_COMMAND}` run {video.GROK_REFRESH_WHERE} "+ f"or `{video.GROK_LOGIN_COMMAND}`"),+ (403, video.AUTH_SOURCE_API_KEY, f"check the {video.AUTH_ENV} value"),+], ids=["401-grok-login", "403-api-key"])def test_a_poll_whose_credential_is_rejected_ends_unfinished_at_once(tmp_path: Path, status, source, fix) -> None:api = _FakeApi(polls=[(200, {"status": "pending"}), (status, {"error": "token expired"})])request = _request(tmp_path)@@ -838,10 +777,9 @@ def test_resume_polls_the_request_without_a_submission_and_publishes(tmp_path: Passert "per-call API charge" not in capsys.readouterr().err[email protected]("scripted", ["refused", "lost", "pending"])-def test_a_resume_cut_short_again_is_unfinished_on_the_same_request(tmp_path: Path, clock, scripted) -> None:- poll = {"refused": (429, {"error": "slow down"}), "lost": LOST, "pending": (200, {"status": "pending"})}[scripted]- api = _LossyApi(polls=[poll])+def test_a_resume_cut_short_again_is_unfinished_on_the_same_request(tmp_path: Path, clock) -> None:+ # The polls' stop reasons (refused, lost, pending) are `_poll_publish`'s, tested on the generate path.+ api = _LossyApi(polls=[LOST])with pytest.raises(video.GenerationUnfinished) as unfinished:_resume(tmp_path, api, sleep=clock.sleep, poll_timeout=30)assert "POST" not in [call[0] for call in api.calls]@@ -855,16 +793,6 @@ def test_a_resume_cut_short_again_is_unfinished_on_the_same_request(tmp_path: Paassert not (tmp_path / "clip.mp4").exists()[email protected]("status", [401, 403])-def test_a_resume_whose_credential_is_rejected_is_unfinished_on_the_same_request(tmp_path: Path, status) -> None:- api = _FakeApi(polls=[(status, {"error": "token expired"})])- with pytest.raises(video.GenerationUnfinished) as unfinished:- _resume(tmp_path, api)- assert [call[0] for call in api.calls] == ["GET"]- assert str(unfinished.value).startswith(- f"video-resume: generation req-7 was accepted, but xAI rejected the credential (grok-login) on poll 1 (answer {status}); ")--def test_a_resume_of_a_request_xai_does_not_know_ends_with_its_status(tmp_path: Path) -> None:api = _FakeApi(polls=[(404, {"error": "not found"})])with pytest.raises(SystemExit) as refused:@@ -1078,13 +1006,16 @@ def _on_wire(method, url, token, body, **deadline):return xai.http_json(method, url, token, body, timeout=5, **deadline)[email protected](("answer", "line", "reason"), [- (CUT, xai.TRANSPORT_FAILED, CUT_SAID),- (CUT_REFUSAL, xai.TRANSPORT_FAILED, "IncompleteRead(9 bytes read, 191 more expected)"),- (GARBLED, xai.TRANSPORT_FAILED, "BadStatusLine('garbage\\r\\n')"),- (NOT_JSON, "xai: response was not valid JSON", "response was not valid JSON"),-], ids=["cut", "cut-refusal", "garbled", "not-json"])[email protected]("bounded", [False, True], ids=["no-deadline", "deadline"])+# A body cut short reads differently with and without a deadline; a garbled status line fails inside urlopen+# and a whole body that is not JSON fails in json.loads, the same on either read.[email protected](("answer", "line", "reason", "bounded"), [+ (CUT, xai.TRANSPORT_FAILED, CUT_SAID, False),+ (CUT, xai.TRANSPORT_FAILED, CUT_SAID, True),+ (CUT_REFUSAL, xai.TRANSPORT_FAILED, "IncompleteRead(9 bytes read, 191 more expected)", False),+ (CUT_REFUSAL, xai.TRANSPORT_FAILED, "IncompleteRead(9 bytes read, 191 more expected)", True),+ (GARBLED, xai.TRANSPORT_FAILED, "BadStatusLine('garbage\\r\\n')", False),+ (NOT_JSON, "xai: response was not valid JSON", "response was not valid JSON", False),+], ids=["cut-no-deadline", "cut-deadline", "cut-refusal-no-deadline", "cut-refusal-deadline", "garbled", "not-json"])def test_http_json_reads_an_answer_it_cannot_read_whole_as_no_answer(wire, clock, answer, line, reason, bounded) -> None:"""The line each always had — the transport's, or the not-JSON one — on the type a poll asks again on,whether or not a deadline bounds the read (a body read a chunk at a time still knows it was cut short)."""@@ -1111,15 +1042,6 @@ def test_a_poll_cut_short_garbled_or_not_json_is_asked_again_and_publishes(tmp_passert "[video] poll 3 of generation req-1 got no answer (response was not valid JSON); asking again in 32s" in err-def test_a_resume_whose_poll_is_cut_short_asks_the_same_request_again(tmp_path: Path, wire) -> None:- """The validator's counterexample: a resumed poll cut 10 bytes into its 200-byte body."""- server = wire(CUT, DONE_ON_WIRE)- result = video.resume_video(video.ResumeRequest(request_id="req-1", out=tmp_path / "clip.mp4"), credential=RESUMED,- call=_on_wire, download=lambda url, token, **_: MP4, sleep=lambda s: None)- assert server.seen == [("GET", "/v1/videos/req-1")] * 2- assert result.out.read_bytes() == MP4 and result.to_dict()["polls_unanswered"] == 1--def test_polls_cut_short_until_the_poll_timeout_leave_an_unfinished_report_naming_the_request(tmp_path: Path, wire, clock, monkeypatch, capsys) -> None:server = wire(ACCEPTED, CUT)@@ -1268,13 +1190,6 @@ def test_a_download_cut_short_or_refused_is_downloaded_again_and_publishes(tmp_passert "[video] download 2 of generation req-1 was refused (503); downloading again in 16s" in err-def test_a_clip_downloaded_whole_at_once_reports_one_download(tmp_path: Path) -> None:- api = _FakeApi()- payload = video.generate_video(_request(tmp_path), credential=video.Credential("t", "XAI_API_KEY"),- call=api.call, download=api.download, sleep=lambda s: None).to_dict()- assert payload["downloads"] == 1--@pytest.mark.parametrize(("answer", "downloads", "said", "status"), [(CLIP_REFUSED, 3, "was refused (last answer 503) after 3 attempts", 503),(CLIP_GONE, 1, "was refused (answer 404)", 404),@@ -1503,14 +1418,12 @@ def _done_naming(named) -> bytes:return _answer("200 OK", json.dumps({"status": "done", "video": named, "model": video.DEFAULT_MODEL}).encode("utf-8"))+# The branches: `video` not an object, its url not a str, a str with no scheme.@pytest.mark.parametrize("named", [{"duration": 6.0},- {"url": "", "duration": 6.0},- {"url": None},- {"url": 7},{"url": "vidgen.x.ai/v/1.mp4"},"a clip",-], ids=["no-url", "empty-url", "null-url", "a-number", "no-scheme", "not-an-object"])+], ids=["no-url", "no-scheme", "not-an-object"])def test_a_done_poll_that_names_no_url_leaves_an_unfinished_report_naming_the_request(tmp_path: Path, wire, monkeypatch, capsys, named) -> None:"""The second counterexample: xAI says done — the clip is made and may be billed — and names nothing the@@ -1542,15 +1455,3 @@ def test_a_done_poll_that_names_no_url_leaves_an_unfinished_report_naming_the_re"elapsed_seconds": 0.0,}assert capsys.readouterr().out == "" and not out.exists() and not list(tmp_path.glob("*.part"))---def test_a_resume_whose_done_poll_names_no_url_is_unfinished_on_the_same_request(tmp_path: Path, wire) -> None:- server = wire(_done_naming({"duration": 6.0}))- with pytest.raises(video.GenerationUnfinished) as unfinished:- video.resume_video(video.ResumeRequest(request_id="req-1", out=tmp_path / "clip.mp4"), credential=RESUMED,- call=_on_wire, sleep=lambda s: None)- assert server.seen == [("GET", "/v1/videos/req-1")]- assert str(unfinished.value).startswith(- "video-resume: generation req-1 is done, but its poll named no video url to download; ")- assert (unfinished.value.verb, unfinished.value.request_id) == ("video-resume", "req-1")- assert not (tmp_path / "clip.mp4").exists()diff --git a/tests/gen/test_video_facing.py b/tests/gen/test_video_facing.pyindex 7215f15..5181ef0 100644--- a/tests/gen/test_video_facing.py+++ b/tests/gen/test_video_facing.py@@ -31,8 +31,10 @@ class Api:return 200, {"status": "done", "video": {"url": "https://vidgen.x.ai/test.mp4", "duration": 3}}[email protected]("fix", ["mirror", "none"])[email protected]("observed", ["left", "right", "front", "unknown"])+# `fix` is read only when the still faces the other way, so the other observations are asked once, with `none`[email protected](("observed", "fix"), [+ ("left", "mirror"), ("right", "none"), ("front", "none"), ("unknown", "none"),+])def test_side_input_is_inspected_once_before_upload(tmp_path, fix, observed):api = Api(observed)original = FIXTURE.read_bytes()@@ -57,10 +59,10 @@ def test_side_input_is_inspected_once_before_upload(tmp_path, fix, observed):assert uploaded.tobytes() == expected.tobytes()[email protected]("direction", [None, "front", "back"])-def test_non_side_video_keeps_prompt_and_has_no_inspection(tmp_path, direction):+def test_non_side_video_keeps_prompt_and_has_no_inspection(tmp_path):+ # only `direction == "side"` branches: one named view that is not side stands for the rest and for noneapi = Api()- result = video.generate_video(video.VideoRequest(FIXTURE, "original prompt", tmp_path / "out.mp4", direction=direction),+ result = video.generate_video(video.VideoRequest(FIXTURE, "original prompt", tmp_path / "out.mp4", direction="front"),credential=video.Credential("synthetic", "grok-login"), call=api.call, download=lambda *a, **kw: MP4)assert len(api.calls) == 2assert result.prompt == "original prompt" and "facing" not in result.to_dict()@@ -84,15 +86,15 @@ def test_side_multi_input_refused_before_vision_or_video(tmp_path):assert not api.calls[email protected]("options", [[], ["--facing-fix", "none"]])-def test_video_cli_passes_side_policy(tmp_path, monkeypatch, options):+def test_video_cli_passes_side_policy(tmp_path, monkeypatch):+ # `--facing-fix` defaults to `none`, so passing it runs the same codeapi = Api()monkeypatch.setattr(video, "resolve_credential", lambda: video.Credential("synthetic", "grok-login"))monkeypatch.setattr(video, "http_json", api.call)monkeypatch.setattr(video, "http_download", lambda *a, **kw: MP4)report = tmp_path / "report.json"assert video.main(["--image", str(FIXTURE), "--prompt", "idle", "--out", str(tmp_path / "out.mp4"),- "--direction", "side", "--facing", "right", *options, "--report", str(report)]) == 0+ "--direction", "side", "--facing", "right", "--report", str(report)]) == 0data = json.loads(report.read_text())assert data["facing"]["requested"] == "right" and "facing right" in data["prompt"]assert data["facing"]["fix"] == "none" and data["facing"]["action"] == "none"diff --git a/tests/gen/test_video_modes.py b/tests/gen/test_video_modes.pyindex 3ccc76c..28cbf7b 100644--- a/tests/gen/test_video_modes.py+++ b/tests/gen/test_video_modes.py@@ -159,7 +159,6 @@ def test_reference_with_image_keeps_both(tmp_path: Path) -> None:(lambda t: _gen(t, reference_images=[_still(t), _still(t, "b.png")], prompt="<IMAGE_0> and <IMAGE_2>"), "<IMAGE_2> but only 2 --reference"),(lambda t: _gen(t, image=_still(t), prompt="<IMAGE_0> walks"), "<IMAGE_0> but no --reference"),(lambda t: _gen(t, image=_still(t), last_frame=_still(t, "l.png"), model=video.CLASSIC_MODEL), "classic grok-imagine-video rejects last_frame"),- (lambda t: _gen(t, last_frame=_still(t, "l.png"), model=video.CLASSIC_MODEL), "classic grok-imagine-video rejects last_frame"),(lambda t: _gen(t, image=_still(t), reference_images=[_still(t, "r.png")], model=video.CLASSIC_MODEL), "rejects --image combined with --reference"),],)@@ -207,13 +206,6 @@ def test_extend_posts_classic_model_to_extensions_and_inherits_the_rest(tmp_pathassert result.out.read_bytes() == MP4-def test_extend_accepts_the_frame_padded_fifteen_second_clip(tmp_path: Path) -> None:- # probe m4c: a 15.04 s container went through and came back 20.04 s.- api = _FakeApi(done={"status": "done", "video": {"url": "https://vidgen.x.ai/v/2.mp4", "duration": 20.04}, "model": "grok-imagine-video"})- video.extend_video(_ext(tmp_path, duration=5), probe=_probe(15.04, 20.04), **api.kw())- assert api.body["duration"] == 5--def test_extend_refuses_a_result_shorter_than_the_input_measured_from_bytes(tmp_path: Path) -> None:# The poll claims 17 s; the downloaded bytes are 5 s. Bytes win, nothing is published.api = _FakeApi(done={"status": "done", "video": {"url": "https://vidgen.x.ai/v/2.mp4", "duration": 17.0}, "model": "grok-imagine-video"})@@ -268,7 +260,6 @@ def test_edit_posts_classic_model_to_edits_without_duration(tmp_path: Path) -> N("build", "seconds", "expected"),[(lambda t: _edit(t), 8.71, "at most 8.7s"),- (lambda t: _edit(t), 15.04, "at most 8.7s"),(lambda t: _edit(t, video=_clip(t, "in.webm")), 5.0, "must be an .mp4"),(lambda t: _edit(t, model=video.DEFAULT_MODEL), 5.0, "only the classic grok-imagine-video supports editing"),(lambda t: _edit(t, prompt=""), 5.0, "empty prompt"),