"""Unit tests for the /printer proxy rewrites (pure, no live app). The fixtures are verbatim slices of what the ELEGOO Centauri Carbon (firmware V1.4.49) actually serves -- the index shell, main.js's websocket URL, the 25..js video binding + file-host template literals, and the SDCP video-URL frame -- so a firmware bump that changes a shape shows up here before it silently breaks the page.""" import os import sys import pytest sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "api")) from printer_proxy import ( # noqa: E402 FRAME_CSS, REWRITE_VERSION, client_response_headers, not_modified, proxy_etag, rewrite_html, rewrite_js, rewrite_kind, rewrite_ws_text, upstream_request_headers, ) INDEX = ( '' '' '' '' '' '' ) # ── html ────────────────────────────────────────────────────────────────────── def test_html_base_href_moves_under_prefix(): assert '' in rewrite_html(INDEX) def test_html_absolute_asset_paths_move_under_prefix(): assert 'href="/printer/assets/iconfont/iconfont.css"' in rewrite_html(INDEX) def test_html_relative_paths_untouched(): out = rewrite_html(INDEX) assert 'href="favicon.ico"' in out assert 'href="styles.948ae391de6d85346226.css"' in out assert 'src="runtime.d8e385257819bb9e3f4a.js"' in out def test_html_injects_frame_overrides_once_unrerooted(): # Against FRAME_CSS itself, not a copy of its text: the ?v= is bumped # whenever the override sheet changes, and a literal here turns every one of # those bumps into a red suite for no defect. out = rewrite_html(INDEX) assert out.count(FRAME_CSS + "") == 1 assert 'href="/printer/printer-frame.css' not in out # injected after the re-root pass def test_html_protocol_relative_untouched(): assert rewrite_html('