feat(pixel-perfect): expose standalone local tool API - #496
Conversation
The application needs a minimal boundary for local grid detection and reconstruction. Add immutable result types and stable input, busy, and unavailable error classes. Later adapters can compose the native modules without importing business services.
The tool API must invoke fixed local binaries without unbounded subprocess resources. Add six-field detector parsing, explicit reconstructor arguments, output limits, timeouts, and exit classification. Native failures now map to controlled tool errors instead of leaking process behavior.
Automatic and manual modes need one application boundary that remains outside generation. Compose detection and explicit reconstruction with finite parameters, bounded concurrency, and PNG validation. The tool can run independently while rejecting unsupported sub-three-pixel auto results.
Browsers need an explicit endpoint that never touches storage or generation workflows. Add streamed request limits, local-tool error mapping, PNG metadata headers, and composition-root registration. The authenticated endpoint now returns the rebuilt image directly with bounded upload concurrency.
The app package inspects upload and reconstruction dimensions at its own boundary. Declare Pillow directly and update only the corresponding workspace lock metadata. Runtime dependency ownership no longer relies on the unrelated AI engine package.
The new tool must remain separate from existing generation and infrastructure modules. Add bidirectional forbidden-import contracts for the tool, orchestrator, generation API, and worker. Future coupling attempts now fail the existing architecture gate.
Production needs both standalone Rust modules without shipping a Rust runtime or source tree. Build each locked crate in a separate stage and copy only binaries plus MIT licenses into the image. The Python runtime can invoke fixed local tools through explicit environment paths.
The explicit API needs regression evidence for composition, resources, and failure mapping. Cover uploads, manual bypass, sub-three-pixel rejection, native limits, concurrency, CORS, and OpenAPI. Tool regressions now fail without exercising storage, generation, databases, or external services.
The repository OpenAPI artifact must match the newly registered multipart endpoint. Export the PNG success response, business-error JSON, form parameters, and validation schema. Clients and CI now see the same explicit tool contract as the running application.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Review conclusion
The standalone API boundary, subprocess adapter, packaging changes, OpenAPI export, and architecture contracts were reviewed against the fixed SHA range. The targeted 20-test suite, Ruff checks, formatting check, and all four import-linter contracts pass. One integration-level upload-limit path does not preserve the API's documented business-error envelope, as detailed inline.
| if message["type"] == "http.request": | ||
| received += len(message.get("body", b"")) | ||
| if received > self.max_body_bytes: | ||
| raise _BodyTooLarge |
There was a problem hiding this comment.
[P2] 让超限上传走统一业务错误响应
这里从 receive 抛出的 _BodyTooLarge 会被 FastAPI/Starlette 的 multipart 解析器先捕获并转换成框架级 400,因此外层的 except _BodyTooLarge 实际不会执行。用完整应用上传 12 MiB 文件时,响应是 HTTP 400 {'detail':'There was an error parsing the body'},而不是项目约定的 HTTP 200 + code=400 业务包络;这也违背了本端点对资源超限提供稳定 API 错误的契约。请在 multipart 解析器之外完成超限响应或拦截其解析失败结果,并增加一个通过 TestClient 发送超过 11 MiB multipart 的集成测试;当前直接调用中间件的测试无法覆盖这一行为。
新增独立完美像素工具 API,只在这一层组合网格检测器与显式重建器;浏览器直传图片并直接接收 PNG,现有生成管线、媒体服务、数据库和对象存储均不参与。
Why
检测与重建模块需要一个最小的后端调用入口,但这个入口不能扩散进现有生成或工作流系统,也不能让本地 CPU 工具形成无界的上传、子进程或并发资源风险。
Changes
POST /tools/pixel-perfect,支持 PNG/JPEG、自动检测和手动pixel_size。<3px的自动结果不继续处理,要求调用方提供手动尺寸。Implementation
windup_app.server.pixel_perfect;它只依赖 Pillow 与 Python 标准库,不导入windup_ai_engine、windup_framework、媒体或 orchestrator。Verification
ruff format --check与ruff check:通过。pytest -q tests/test_pixel_perfect_api.py --no-cov:20 项通过,0 项失败。lint-imports:4 个架构契约通过,0 个破坏。git diff --check:通过。cargo、rustc、/app/native或/build。Scope
<3px自动识别优化另行处理。Development Context
Related Issues
Closes #492
Refs #489