Skip to content

Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.

test(packaging): restore package state after the import-surface probe

Soohong Kim9e40e1f96cc1
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cb1c565..006bddc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@ All notable public changes to `sprite-gen` are recorded here. Versions track the
- New `video-extend` (`POST /v1/videos/extensions`) continues a 2–15 s clip by 2–10 s and new `video-edit` (`POST /v1/videos/edits`) changes a clip of at most 8.7 s with a prompt. Both force the classic `grok-imagine-video` model (the 1.5 model refuses both endpoints), take no resolution / aspect / model flags because the output inherits the input's, check the input with ffprobe before uploading, and `video-extend` refuses a result shorter than its input.
- Local pre-checks refuse, before any call: no input at all, more than 7 references, `<IMAGE_n>` tags outside the given references (or with none), 1080p with references, and `last_frame` / `image`+`reference` on the classic model.
- The `sprite-gen-video-report` carries `mode` (`image-to-video`, `first-last`, `last-frame`, `reference`, `extend`, `edit`), `inputs` (local paths by role) and, for extend / edit, `input_duration`; every existing field stays.
+- Test isolation: the packaging import-surface probe now restores the parent package attribute and `sys.modules` entry it touched, so importing the retired `sprite_gen.gen.generate_image` shim no longer replaces the `generate_image()` function for later `tests/gen` runs. `pytest tests/packaging tests/gen` is green in any order.
- The expired-login prescription for Grok video and images no longer names a bare prompt (`grok -p ok`): on the grok CLI that starts the coding agent in the current directory, which can read, write and spend on its own. The prescription is now a non-agent round-trip (`grok models`) run from an empty directory, with `grok login` as the fallback, and the message says so. A test pins the prescription to a non-agent command.
## v2.2.0 - Independent asset tools and optional scenes
diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md
index 8e88af2..ba33df4 100644
--- a/docs/troubleshooting.md
+++ b/docs/troubleshooting.md
@@ -55,6 +55,23 @@
500(`ffmpeg not found`)을 준다. GIF 는 ffmpeg 없이 동작.
- **대처**: 서버 머신에 ffmpeg 설치 (`brew install ffmpeg` 등).
+## 테스트 스위트가 순서에 따라 깨짐 (`pytest tests/packaging tests/gen` 만 빨강)
+
+- **증상**: `pytest tests/gen` 과 `pytest tests/packaging` 은 각각 초록인데 한 세션에서
+ packaging → gen 순으로 돌리면 `tests/gen` 이 `TypeError: 'module' object is not
+ callable` 로 수십 건 실패.
+- **원인**: 패키징 import-surface 테스트가 `sprite_gen.gen.generate_image` (은퇴한 shim
+ 모듈)를 import 한다. 파이썬은 서브모듈을 import 하면 부모 패키지에 같은 이름의
+ 속성으로 바인딩하는데, `sprite_gen.gen` 은 이미 같은 이름의 함수
+ `generate_image()` 를 export 하므로 함수가 모듈로 덮여 세션 끝까지 남는다.
+ `gen.run()` 은 그 이름을 호출하니 이후 gen 테스트 전부가 죽는다.
+- **격리 방식**: `tests/packaging/test_package_surface.py` 의 `import_probe` 픽스처가
+ import 전에 부모 속성과 `sys.modules` 항목을 기록하고 테스트 뒤 되돌린다. 프로덕트
+ 코드는 그대로다 — 함수와 shim 모듈의 이름 충돌 자체는 남아 있으니, 런타임에서
+ `import sprite_gen.gen.generate_image` 를 실행하는 코드는 같은 덮어쓰기를 일으킨다.
+- **확인**: `pytest tests/packaging tests/gen`, `pytest tests/gen tests/packaging`,
+ `pytest tests/` 가 모두 같은 결과여야 한다.
+
## Related
- [docs/README.md](README.md) — documentation index
diff --git a/tests/packaging/test_package_surface.py b/tests/packaging/test_package_surface.py
index f208c8e..2003a39 100644
--- a/tests/packaging/test_package_surface.py
+++ b/tests/packaging/test_package_surface.py
@@ -59,10 +59,50 @@ def _read_skill_version() -> str:
return match.group(1)
+def import_probe():
+ """Import a module for inspection and leave the process as it was.
+
+ Importing a submodule binds it as an attribute on its parent package. When the
+ submodule shares its name with a function the package already exports
+ (`sprite_gen.gen.generate_image` is a retired shim next to the live
+ `sprite_gen.gen.generate_image()` function), that binding replaces the function
+ for the rest of the session and every later `gen.run()` dies with
+ `'module' object is not callable`. The probe records the parent attribute and the
+ `sys.modules` entry before importing and restores both afterwards, so this test
+ observes the package without rewriting it for tests that run after it.
+ """
+ restores: list[tuple[object, str, object]] = []
+ fresh_modules: list[str] = []
+ missing = object()
+
+ def probe(module_path: str):
+ parent_path, _, child = module_path.rpartition(".")
+ parent = sys.modules.get(parent_path) if parent_path else None
+ was_loaded = module_path in sys.modules
+ if parent is not None:
+ restores.append((parent, child, getattr(parent, child, missing)))
+ module = importlib.import_module(module_path)
+ if not was_loaded:
+ fresh_modules.append(module_path)
+ return module
+
+ yield probe
+
+ for parent, child, prior in reversed(restores):
+ if prior is missing:
+ if hasattr(parent, child):
+ delattr(parent, child)
+ else:
+ setattr(parent, child, prior)
+ for module_path in fresh_modules:
+ sys.modules.pop(module_path, None)
+
+
@pytest.mark.parametrize("module_name", PACKAGE_RUN_MODULES)
-def test_mcp_import_surface_modules_expose_callable_run(module_name: str) -> None:
+def test_mcp_import_surface_modules_expose_callable_run(module_name: str, import_probe) -> None:
module_path = "sprite_gen.gen" if module_name == "gen" else qualified(module_name)
- module = importlib.import_module(module_path)
+ module = import_probe(module_path)
assert callable(getattr(module, "run", None)), f"{module_path}.run must be callable"