"""Offscreen smoke tests for the command bar's reference attachment + match.""" import os import pytest os.environ.setdefault("QT_QPA_PLATFORM", "offscreen") pytest.importorskip("PySide6") from PySide6.QtCore import QThreadPool # noqa: E402 from PySide6.QtWidgets import QApplication # noqa: E402 from woodshop.gui.command_bar import CommandBar # noqa: E402 from woodshop.gui.controller import Controller # noqa: E402 _app = QApplication.instance() or QApplication([]) def test_attach_accumulates_and_clears(tmp_path): c = Controller(str(tmp_path / "s.json")) bar = CommandBar(c, QThreadPool.globalInstance()) a = tmp_path / "front.png"; a.write_bytes(b"x") b = tmp_path / "side.png"; b.write_bytes(b"x") bar._add_ref(str(a)) assert bar._pending == [str(a)] and "front.png" in bar.image_chip.text() bar._add_ref(str(b)) assert bar._pending == [str(a), str(b)] and "2 references" in bar.image_chip.text() bar._clear_refs() assert bar._pending == [] and bar.image_chip.text() == "" def test_attach_sets_default_text(tmp_path): c = Controller(str(tmp_path / "s.json")) bar = CommandBar(c, QThreadPool.globalInstance()) bar._add_ref(str(tmp_path / "x.png")) assert bar.input.text() == "build something like this" def test_match_button_enabled_only_with_reference(tmp_path): c = Controller(str(tmp_path / "s.json")) bar = CommandBar(c, QThreadPool.globalInstance()) assert not bar.match.isEnabled() # nothing attached yet bar._last_reference = (["/ref/a.png"], None) bar._busy(False) # re-evaluates the match button assert bar.match.isEnabled()