Files
make-cad/test/test_failure_evidence.py
NiJingzhe d941cda14b fix: second-round review findings (failure pictures, use() owners, refused posts, front end)
- A face or edge query that matches nothing draws the plain solid again (it returned no picture).
- use() memo: a key kept again under another graph id, and eviction, no longer leave a stale owner.
- A refused preview post names what the server said; a picture that cannot be drawn is said on stderr.
- Editor: a client that left while a frame was sent is not registered again; the damaged-model message is accurate.
- Front end: a kept part is a copy, not a view that pins the frame it came in; a dropped frame is warned.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-29 03:50:36 +08:00

51 lines
1.9 KiB
Python

"""The failure pictures, and what a refused preview post tells the person."""
from __future__ import annotations
import io
import urllib.error
from pathlib import Path
import pytest
import simplecadapi as scad
@pytest.fixture(autouse=True)
def drawing(tmp_path, monkeypatch):
from simplecadapi._cpp import evidence
monkeypatch.delenv("SCA_NO_DIAGNOSTIC_RENDER", raising=False)
monkeypatch.chdir(tmp_path)
evidence._RENDER_DEDUP.clear()
def test_a_query_that_matches_nothing_still_draws_the_solid() -> None:
"""2.2.6 drew the plain solid when a face query matched nothing (the common ``exactly(1)`` found 0)."""
box = scad.make_box_rsolid(10, 10, 10)
with pytest.raises(scad.SimpleCADError) as raised:
scad.ql.faces().where(scad.ql.surface_type("TORUS")).exactly(1).resolve(box)
evidence = raised.value.to_dict()["evidence"]
assert len(evidence) == 1 and evidence[0]["kind"] == "render"
assert Path(evidence[0]["path"]).stat().st_size > 10_000
def test_a_picture_that_cannot_be_drawn_is_said_on_stderr(capsys, monkeypatch) -> None:
from simplecadapi._cpp import evidence
def broken(*args, **kwargs):
raise RuntimeError("no plot")
monkeypatch.setattr(evidence, "_wire_plan", broken)
assert evidence.provide("wire_plan_render", "loft", "plan", "caption", "key", [], {}) is None
assert "could not be drawn (RuntimeError: no plot)" in capsys.readouterr().err
def test_a_refused_preview_post_reports_what_the_server_said() -> None:
from simplecadapi.runtime.live import _server_words
refused = urllib.error.HTTPError("http://x", 400, "Bad Request", {}, io.BytesIO(b'{"ok": false, "error": "damaged preview: KeyError: key"}'))
assert _server_words(refused) == "HTTP 400: damaged preview: KeyError: key"
bare = urllib.error.HTTPError("http://x", 500, "Server Error", {}, io.BytesIO(b"<html>"))
assert "500" in _server_words(bare)