mirror of
https://github.com/bitbaum/printcraft.git
synced 2026-12-04 08:58:16 +01:00
`generate scene` printed a red "✗ Failed" and exited 0. `generate all-scenes` printed "0/2 scenes generated successfully" and exited 0. The generator was never at fault — it detects the rate limit, sets `error` and returns `success=False` correctly. The CLI took that report and threw it away at the process boundary, so every wrapper, `&&` chain, cron job and scrolled-past terminal read a half-finished round as a finished one. That is how round 010 of the Duschwand lost `chain_vv_van` and `chain_teal_kd` to a rate limit in April and sat unfinished for five months: 8 prompts, 7 outputs on disk, exit 0. This is the same defect class the web app has been swept for across #36–#47 — a failure that reports itself as success — found at the CLI boundary of the pipeline that actually produces the client deliverable. Both commands now exit 1 when any scene fails, and `all-scenes` names which ones. `--only-missing` re-runs just the scenes with no output, so recovering from a rate limit no longer means regenerating (and overwriting) the images that worked. The output filename pattern now has one definition — `output_path()` in grok.py, used both by `generate()` which writes the file and by the caller asking whether it already exists, so "is this scene done?" cannot drift from what is actually written. Also corrected the module docstring, which advertised a `generate mural` command that does not exist; the command is `all-scenes`. The Python half of this repo had no tests and no CI at all, which is why a bug this plain survived: `tests/` is new, with 6 tests over the fixed behaviour and a fake generator so no browser or network is touched. CI gets a "Python pipeline tests" step. Deliberately NOT folded into `pnpm run verify` — that gate has to work from a bare `pnpm install`, and pytest needs a Python env — so it is a separate, explicitly documented gate rather than a silent gap; `package.json`'s comment field and the CI step both say so. Verified: 6/6 new pytest pass; each half of the fix mutation-verified (dropping the scene exit, the round exit, or the --only-missing filter each fails a different named test). Root `pnpm run verify` still exits 0 (format + lint 0 errors/8 pre-existing warnings + tsc + 101 JS tests). Reproduced the original defect first — the same harness printed EXIT CODE: 0 before and prints EXIT CODE: 1 after. `printcraft project list-scenes` still loads the real duschwand-roli project. Does NOT retro-fix round 010: those prompts are `chain_*`, ad-hoc names that do not match project.yaml scene ids, so that round was not produced by `all-scenes` and cannot be resumed by it. Finishing it is still manual work. Claude-Session: https://claude.ai/code/session_01SZGjXtzLGk2q9zPUkA3vMf Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
94 lines
2.4 KiB
Python
94 lines
2.4 KiB
Python
"""Shared fixtures for the pipeline tests."""
|
|
from __future__ import annotations
|
|
|
|
import textwrap
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from printcraft.generators.grok import GenerationResult
|
|
|
|
|
|
PROJECT_YAML = textwrap.dedent(
|
|
"""
|
|
client: TestClient
|
|
title: Test Project
|
|
status: in-progress
|
|
surface:
|
|
name: test-surface
|
|
dpi: 150
|
|
panels:
|
|
- id: main
|
|
width_cm: 100
|
|
height_cm: 100
|
|
style:
|
|
name: test-style
|
|
prompt: A short style prompt.
|
|
scene:
|
|
setting: Somewhere
|
|
description: A scene.
|
|
characters: []
|
|
scenes:
|
|
- id: alpha
|
|
description: Scene alpha.
|
|
- id: beta
|
|
description: Scene beta.
|
|
- id: gamma
|
|
description: Scene gamma.
|
|
"""
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def project_dir(tmp_path: Path) -> Path:
|
|
"""A minimal but real project on disk — three scenes, no reference photos."""
|
|
(tmp_path / "project.yaml").write_text(PROJECT_YAML)
|
|
return tmp_path
|
|
|
|
|
|
class FakeGenerator:
|
|
"""Stands in for GrokGenerator so no browser or network is involved.
|
|
|
|
`fails` names the scene ids that should come back unsuccessful, which is how
|
|
a rate limit presents itself: the generator reports it correctly, and the
|
|
question under test is only what the CLI does with that report.
|
|
"""
|
|
|
|
fails: set[str] = set()
|
|
calls: list[str] = []
|
|
|
|
def __init__(self, config=None):
|
|
pass
|
|
|
|
def __enter__(self):
|
|
return self
|
|
|
|
def __exit__(self, *exc):
|
|
return False
|
|
|
|
def generate(self, scene_id, prompt, reference_photo=None, output_dir=None, file_prefix=None):
|
|
type(self).calls.append(scene_id)
|
|
result = GenerationResult(scene_id=scene_id, prompt=prompt)
|
|
if scene_id in type(self).fails:
|
|
result.error = "Rate limited — wait for reset and retry"
|
|
return result
|
|
from printcraft.generators.grok import output_path
|
|
|
|
path = output_path(output_dir, file_prefix or scene_id)
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
path.write_bytes(b"fake-jpeg")
|
|
result.outputs.append(path)
|
|
result.success = True
|
|
return result
|
|
|
|
|
|
@pytest.fixture
|
|
def fake_generator(monkeypatch):
|
|
"""Install FakeGenerator in place of the real one, with per-test failure control."""
|
|
import printcraft.cli as cli
|
|
|
|
FakeGenerator.fails = set()
|
|
FakeGenerator.calls = []
|
|
monkeypatch.setattr(cli, "GrokGenerator", FakeGenerator)
|
|
return FakeGenerator
|