Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.
fix(gen): a Bearer value after _ or - is masked like a key after them
Soohong Kim19c999fe74be
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 38e8064..2c05597 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -5,7 +5,7 @@ All notable public changes to `sprite-gen` are recorded here. Versions track the## Unreleased (v2.12.0) - A refusal names the provider's code, and says when it was the content policy- A provider refusal line now carries the provider's own code after the status: `openai-gen: image request failed (HTTP 400) code=invalid_value; no retry or provider fallback`. The code is `error.code` (or, for xAI's synchronous errors, a top-level `code`) and is printed only when it matches `^[A-Za-z0-9_.:-]{1,64}$`. The video verbs read the code out of a failed poll's `error` object too.-- The image paths now print the provider's error body too, as received, at the end of the line: `openai-gen: image request failed (HTTP 400) code=invalid_value; no retry or provider fallback: {"error": {...}}` (JSON on one line, other text with its line breaks as `\n`, nothing for an empty body; this includes 401/403). Before, the body was dropped and a failure was hard to diagnose. Two things are masked with `[redacted]`: strings shaped like an API key (`sk-…`, `xai-…`, a `Bearer` value, the credential the request carried; a key the provider already masked is left alone) and URL query strings, where signatures live. The video verbs, which already printed what xAI said, now go through the same mask, applied before their 300-character cut so a key the cut would split is still masked. A key right after `_` or `-` (`api_key_sk-…`) is masked too; only a letter or digit in front makes `sk-`/`xai-` part of a word. The body can repeat the prompt: a product that shows sprite-gen's stderr to its own users decides what to keep. Everything in front of the body is unchanged.+- The image paths now print the provider's error body too, as received, at the end of the line: `openai-gen: image request failed (HTTP 400) code=invalid_value; no retry or provider fallback: {"error": {...}}` (JSON on one line, other text with its line breaks as `\n`, nothing for an empty body; this includes 401/403). Before, the body was dropped and a failure was hard to diagnose. Two things are masked with `[redacted]`: strings shaped like an API key (`sk-…`, `xai-…`, a `Bearer` value, the credential the request carried; a key the provider already masked is left alone) and URL query strings, where signatures live. The video verbs, which already printed what xAI said, now go through the same mask, applied before their 300-character cut so a key the cut would split is still masked. A key or a `Bearer` value right after `_` or `-` (`api_key_sk-…`, `x_Bearer …`) is masked too; only a letter or digit in front makes `sk-`/`xai-`/`bearer` part of a word. The body can repeat the prompt: a product that shows sprite-gen's stderr to its own users decides what to keep. Everything in front of the body is unchanged.- A code the provider documents as a content-policy block turns the line into `<verb>: refused by the provider's content policy (HTTP <n>) code=<code>; no retry or provider fallback`, so a caller can tell "change the request" from an auth, quota or parameter error by one fixed phrase. OpenAI's `moderation_blocked` is the only such code (the image guide calls `error.code` the stable discriminator); its `moderation_details.moderation_stage` follows as `moderation_stage=input|output|unknown`. xAI's `invalid_argument` is not one: it covers moderation and parameter errors alike.- An xAI clip that finishes with `video.respect_moderation: false` is now `<verb>: generation <id> refused by the provider's content policy (HTTP 200) respect_moderation=false; nothing was written` instead of "done but reported no video url". The xAI REST image answer has no moderation field, so a grok image refusal carries its code only.- `(HTTP <n>)` is unchanged, and the body comes after it and everything else, so anything that finds the status with `\(HTTP (\d{3})\)` reads these lines as before, whatever the body says. The policy table is `sprite_gen/gen/refusal.py` `POLICY_CODES`. Line shape: [docs/gen.md](docs/gen.md).diff --git a/sprite_gen/gen/refusal.py b/sprite_gen/gen/refusal.pyindex cf5504a..9d03540 100644--- a/sprite_gen/gen/refusal.py+++ b/sprite_gen/gen/refusal.py@@ -37,7 +37,7 @@ CONTENT_POLICY = "refused by the provider's content policy"# `_` or `-` (`api_key_sk-…`) the key starts there._KEY = re.compile(r"(?<![A-Za-z0-9])(sk|xai)-([A-Za-z0-9_*-]+)")_KEY_MIN_LENGTH = 16-_BEARER = re.compile(r"(?i)\b(bearer\s+)[A-Za-z0-9._~+/=-]{16,}")+_BEARER = re.compile(r"(?i)(?<![A-Za-z0-9])(bearer\s+)[A-Za-z0-9._~+/=-]{16,}")_URL_QUERY = re.compile(r"(?i)\b(https?://[^\s?#\"'<>\\]+)\?[^\s#\"'<>\\]*")REDACTED = "[redacted]"diff --git a/tests/gen/test_video.py b/tests/gen/test_video.pyindex 6b88b33..a392a32 100644--- a/tests/gen/test_video.py+++ b/tests/gen/test_video.py@@ -514,6 +514,16 @@ def test_a_key_after_an_underscore_or_hyphen_is_masked_and_a_word_ending_in_sk_iassert 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"])+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}"++@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: "),