Team Hoa, EPIC R08 (UI/Application Separation) - Team Hoa scope only
(R08-T11 -> T14; R08-T01->T10 belong to Team Duy/Team Nam).
- R08-T11: ui/schedule_task_tab.py (795 lines) -> presentation/scheduling/
{kanban_board_widget,calendar_view_widget,ai_task_creator_dialog,
ai_task_import_dialog,run_history_dialog}.py + schedule_task_tab.py
shell. Kanban CRUD/drag-drop now goes through
application/scheduling/task_application_service.py (R07-T04) instead of
~30 lines of inline if/elif per drag target.
- R08-T12: ui/folder_tab.py (1587 lines, the largest of the four) ->
presentation/folder/{workspace_file_tree,document_preview_manager,
code_editor,office_document_renderer,ai_file_editor_dialog,
ai_edit_model_resolver,ai_edit_pipeline}.py + folder_tab.py shell.
Closes the R06-T05 loop: FileWorkspaceService existed since R06 with
zero production call sites (confirmed by grep); every plain-text write
(save/create/write_content) now goes through it, gaining path
containment and a Python-syntax warning the original code never had.
Pure helpers (_read_text, _is_probably_text, _pptx_available,
_split_code_block, _parse_ai_output) moved to
application/workspaces/{file_preview_helpers,ai_edit_output}.py.
- R08-T13: ui/dashboard_tab.py (437 lines) -> presentation/dashboard/
{token_usage_card_widget,usage_chart_widget,habits_widget}.py +
dashboard_tab.py shell, backed by a new
application/monitoring/dashboard_query_service.py (pricing/period/
summary queries the three widgets used to each recompute separately).
Directory-ownership note left in the checklist for Team Nam.
- R08-T14: ui/structure_graph_view.py (1035 lines) ->
presentation/graph/{graph_scene_items,graph_renderer,
graph_messages_view,graph_qa_widget}.py + structure_graph_view.py
shell. Extraction helpers (_pdf_to_markdown, _extract_file_contents)
moved to application/workspaces/graph_index_service.py (pure Python).
Renderer and Q&A panel talk only through signals
(node_selected/graph_rendered/raw_json_ready/project_changed) - neither
imports the other.
- presentation/shared/web_engine_support.py: HAS_WEB_ENGINE, previously
duplicated (folder_tab imported it FROM structure_graph_view.py) - now
one shared flag instead of one screen importing another screen's module.
All four old ui/*.py files deleted; app.py and ui/workspace_tab.py updated
to the new import paths (each god-file only had 1-2 real construction
sites, so import sites were updated directly rather than kept as a
strangler-fig shim - unlike core/tools.py at R05, which had dozens).
pytest: 377 pass (+94 vs the R07 baseline of 328; same 4 pre-existing
failures as the R05/R06 baseline, unrelated to this work).
scripts/check_imports.py: PASS. python -c "import cowork_local.app": OK.
Every new file < 400 lines (largest: graph_renderer.py, 391).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
163 lines
5.8 KiB
Python
163 lines
5.8 KiB
Python
"""EPIC R08-T14: GraphRenderer / GraphQaWidget / StructureGraphView shell,
|
|
real Qt offscreen.
|
|
|
|
Scope note: a real directory SCAN (``GraphRenderer._scan``) runs on a
|
|
``core.worker.AgentWorker`` QThread and had no existing test before this
|
|
task either (grep confirms nothing under tests/ exercised
|
|
``ui/structure_graph_view.py``). These tests drive ``_render()`` directly
|
|
with a hand-built ``StructureGraph`` instead of a live scan — enough to
|
|
prove the renderer <-> Q&A wiring (the actual R08-T14 deliverable) without
|
|
needing a real codebase to walk.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
|
|
import pytest
|
|
|
|
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
|
|
|
from cowork_local.config import AppConfig # noqa: E402
|
|
from cowork_local.core.structure_graph import GEdge, GNode, StructureGraph # noqa: E402
|
|
from cowork_local.state import AppContext # noqa: E402
|
|
|
|
pytest.importorskip("PySide6", reason="Qt is required for the integration suite")
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def qt_app():
|
|
from PySide6.QtWidgets import QApplication
|
|
|
|
return QApplication.instance() or QApplication([])
|
|
|
|
|
|
@pytest.fixture
|
|
def ctx(qt_app, tmp_path):
|
|
return AppContext(AppConfig.load(tmp_path / "config.json"))
|
|
|
|
|
|
def _fake_graph(tmp_path):
|
|
f = tmp_path / "mod.py"
|
|
f.write_text("def hello():\n pass\n", encoding="utf-8")
|
|
nodes = [
|
|
GNode(id="n1", label="mod.py", kind="file", detail="a module", path=str(f)),
|
|
GNode(id="n2", label="hello", kind="function", detail="says hi", path=str(f)),
|
|
]
|
|
edges = [GEdge(source="n1", target="n2", type="defines")]
|
|
return StructureGraph(nodes=nodes, edges=edges)
|
|
|
|
|
|
def test_structure_graph_view_builds(ctx):
|
|
from cowork_local.presentation.graph.structure_graph_view import StructureGraphView
|
|
|
|
view = StructureGraphView(ctx)
|
|
assert view.renderer is not None
|
|
assert view.qa is not None
|
|
|
|
|
|
def test_render_populates_the_scene_and_emits_graph_rendered(ctx, tmp_path):
|
|
from cowork_local.presentation.graph.graph_renderer import GraphRenderer
|
|
|
|
renderer = GraphRenderer(ctx)
|
|
graph = _fake_graph(tmp_path)
|
|
seen = []
|
|
renderer.graph_rendered.connect(lambda: seen.append(1))
|
|
|
|
renderer._render({"graph": graph, "pos": {"n1": (0, 0), "n2": (100, 0)}, "seq": renderer._scan_seq})
|
|
|
|
assert renderer.graph is graph
|
|
assert len(renderer._node_items) == 2
|
|
assert seen == [1]
|
|
|
|
|
|
def test_render_ignores_a_stale_scan_result(ctx, tmp_path):
|
|
"""Only the LATEST scan's result is ever rendered (no stale overwrite)."""
|
|
from cowork_local.presentation.graph.graph_renderer import GraphRenderer
|
|
|
|
renderer = GraphRenderer(ctx)
|
|
first = _fake_graph(tmp_path)
|
|
renderer._render({"graph": first, "pos": {}, "seq": renderer._scan_seq})
|
|
renderer._scan_seq += 1 # a second scan started
|
|
|
|
stale = StructureGraph(nodes=[], edges=[])
|
|
renderer._render({"graph": stale, "pos": {}, "seq": renderer._scan_seq - 1})
|
|
|
|
assert renderer.graph is first # stale result was dropped
|
|
|
|
|
|
def test_node_selection_updates_the_qa_detail_panel(ctx, tmp_path):
|
|
from cowork_local.presentation.graph.graph_qa_widget import GraphQaWidget
|
|
from cowork_local.presentation.graph.graph_renderer import GraphRenderer
|
|
|
|
renderer = GraphRenderer(ctx)
|
|
graph = _fake_graph(tmp_path)
|
|
renderer._render({"graph": graph, "pos": {"n1": (0, 0), "n2": (100, 0)}, "seq": renderer._scan_seq})
|
|
qa = GraphQaWidget(ctx, renderer)
|
|
|
|
node = graph.nodes[1]
|
|
renderer.node_selected.emit(node)
|
|
|
|
assert "hello" in qa.detail.toPlainText()
|
|
assert "says hi" in qa.detail.toPlainText()
|
|
|
|
|
|
def test_candidate_file_paths_uses_selected_nodes_when_present(ctx, tmp_path):
|
|
from cowork_local.presentation.graph.graph_qa_widget import GraphQaWidget
|
|
from cowork_local.presentation.graph.graph_renderer import GraphRenderer
|
|
|
|
renderer = GraphRenderer(ctx)
|
|
graph = _fake_graph(tmp_path)
|
|
renderer._render({"graph": graph, "pos": {"n1": (0, 0), "n2": (100, 0)}, "seq": renderer._scan_seq})
|
|
qa = GraphQaWidget(ctx, renderer)
|
|
|
|
# No selection -> every file node in the graph (both nodes share one
|
|
# file here, so this also proves the path-dedup in _candidate_file_paths).
|
|
assert qa._candidate_file_paths() == [graph.nodes[0].path]
|
|
|
|
renderer._node_items[0].setSelected(True)
|
|
assert qa._candidate_file_paths() == [graph.nodes[0].path]
|
|
|
|
|
|
def test_project_change_clears_the_qa_extraction_cache(ctx, tmp_path):
|
|
from cowork_local.presentation.graph.graph_qa_widget import GraphQaWidget
|
|
from cowork_local.presentation.graph.graph_renderer import GraphRenderer
|
|
|
|
renderer = GraphRenderer(ctx)
|
|
qa = GraphQaWidget(ctx, renderer)
|
|
qa._extract_cache = {"some/path.py": "cached text"}
|
|
|
|
renderer.project_changed.emit()
|
|
|
|
assert qa._extract_cache == {}
|
|
|
|
|
|
def test_qa_collapse_resizes_the_shells_splitter(ctx):
|
|
"""Exact pixel width is Qt's splitter-layout arithmetic, not this code's
|
|
concern - what matters is that collapsing narrows the QA pane a lot
|
|
(down near the strip's width) while the strip itself becomes visible and
|
|
the total splitter width is conserved."""
|
|
from cowork_local.presentation.graph.structure_graph_view import StructureGraphView
|
|
from cowork_local.ui.widgets import CollapseStrip
|
|
|
|
view = StructureGraphView(ctx)
|
|
before = view._split.sizes()
|
|
|
|
view.qa._set_collapsed(True)
|
|
|
|
after = view._split.sizes()
|
|
assert after[1] <= CollapseStrip.WIDTH + 2
|
|
assert view.qa.maximumWidth() == CollapseStrip.WIDTH + 2
|
|
assert sum(after) == sum(before) # total width conserved, just redistributed
|
|
|
|
|
|
def test_hide_event_clears_extracts(ctx):
|
|
from cowork_local.presentation.graph.structure_graph_view import StructureGraphView
|
|
|
|
view = StructureGraphView(ctx)
|
|
view.qa._extract_cache = {"x": "y"}
|
|
|
|
from PySide6.QtGui import QHideEvent
|
|
view.hideEvent(QHideEvent())
|
|
|
|
assert view.qa._extract_cache == {}
|