Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
python tests/smoke_test_egress_failover.py
python tests/test_vision_client.py
python tests/test_restore_ui_playbook.py
python tests/test_trace.py

python-egress-windows:
runs-on: windows-latest
Expand All @@ -47,7 +48,9 @@ jobs:
- name: Compile proxy entry points
run: python -m py_compile vision_proxy.py vision_client.py tests/smoke_test_egress_failover.py
- name: Run Windows egress smoke test
run: python tests/smoke_test_egress_failover.py
run: |
python tests/smoke_test_egress_failover.py
python tests/test_trace.py

extensions:
runs-on: ubuntu-latest
Expand Down
10 changes: 8 additions & 2 deletions bin/trace
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ def truncate_decimals(svg, places=2):
return re.sub(r"-?\d+\.\d{3,}", lambda m: f"{float(m.group()):.{places}f}", svg)


def write_svg(path, svg):
"""Write the exact UTF-8 payload whose byte count is reported to callers."""
payload = svg.encode("utf-8")
return Path(path).expanduser().write_bytes(payload)


def prepare_input(path, region, scale):
"""Crop/upscale with Pillow when asked; return the path vtracer reads and the scale used.

Expand Down Expand Up @@ -113,8 +119,8 @@ def main():
"--color is a last resort: on an anti-aliased image it splits every gray "
"level into its own path.", file=sys.stderr)
if args.output:
Path(args.output).expanduser().write_text(svg)
print(f"wrote {args.output} ({len(svg)} bytes, {paths} paths, traced at {scale}x)")
bytes_written = write_svg(args.output, svg)
print(f"wrote {args.output} ({bytes_written} bytes, {paths} paths, traced at {scale}x)")
else:
print(svg)

Expand Down
12 changes: 12 additions & 0 deletions tests/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ def main():
assert "7.891011" not in truncated and "7.89" in truncated
print("PASS: background stripping and decimal truncation")

with tempfile.TemporaryDirectory() as raw:
out = os.path.join(raw, "multiline.svg")
multiline = "<svg>\n<title>几何</title>\n<path/>\n</svg>\n"
reported = mod.write_svg(out, multiline)
payload = multiline.encode("utf-8")
with open(out, "rb") as handle:
written = handle.read()
assert written == payload, "SVG output must preserve LF bytes on every platform"
assert reported == len(written), "reported bytes must equal the file size on disk"
assert reported > len(multiline), "the byte contract must not use Unicode character count"
print("PASS: multiline SVG output preserves exact UTF-8 bytes")

try:
import vtracer # noqa: F401
from PIL import Image
Expand Down
Loading