- ui/monitoring_tab.py (1546 dong) tach thanh presentation/monitoring/** (container + 7 tab/card + shared helper), ui/monitoring_tab.py con lai re-export shim de app.py khong doi. - infrastructure/telemetry/audit_logger.py: CanonicalAuditLogger, core/audit_log.py thanh wrapper mong, tuong thich nguoc 100% voi schema .jsonl cu. - application/monitoring/monitoring_query_service.py: MonitoringQueryService read-only, filter/sort/pagination, khong import PySide6. - Go circular import model_pricing<->usage_tracker va agent_security<-> agent_security_alert (core/agent_security_types.py moi). - infrastructure/sandbox/sandbox_capabilities.py: SandboxCapabilityMatrix theo OS (Windows/Linux/macOS), chua dau noi vao core/sandbox_manager.py. - conftest.py: sua loi checkout khong ten cowork_local khien pytest import nham thu muc khac. - 77 test moi, 167/167 pass. QA da xac nhan UI/business logic khong doi (xem evidence/report/unified_report.html). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
74 lines
2.8 KiB
Python
74 lines
2.8 KiB
Python
"""Task 1 (sub-step 6e) — SandboxDetailsCard / PermissionsCard.
|
|
|
|
Verifies the Permissions card is nested INSIDE the Sandbox card's fold
|
|
(matching the pre-refactor layout exactly) and that refresh()/retranslate()
|
|
compute the same values the original MonitoringTab methods did.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import copy
|
|
import os
|
|
|
|
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
|
|
|
import pytest
|
|
|
|
QApplication = pytest.importorskip("PySide6.QtWidgets").QApplication
|
|
|
|
from cowork_local.config import AppConfig, DEFAULT_CONFIG
|
|
from cowork_local.presentation.monitoring.tabs.sandbox_tab import SandboxDetailsCard
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def qapp():
|
|
app = QApplication.instance() or QApplication([])
|
|
yield app
|
|
|
|
|
|
class _FakeCtx:
|
|
def __init__(self, tmp_path, block_network=False):
|
|
self.config = AppConfig(data=copy.deepcopy(DEFAULT_CONFIG), path=tmp_path / "c.json")
|
|
self.config.data["agent_security"]["block_network"] = block_network
|
|
self.config.data["agent_security"]["resource_limit_cpu_percent"] = 50
|
|
import time
|
|
self.started_at = time.time() - 65 # ~1m5s uptime
|
|
|
|
|
|
def test_permissions_card_nested_inside_sandbox_fold(qapp, tmp_path) -> None:
|
|
card = SandboxDetailsCard(_FakeCtx(tmp_path), on_settings_changed=lambda: None)
|
|
assert card.permissions_card.parent() is card._detail
|
|
|
|
|
|
def test_refresh_computes_uptime_and_resource_limits(qapp, tmp_path) -> None:
|
|
card = SandboxDetailsCard(_FakeCtx(tmp_path), on_settings_changed=lambda: None)
|
|
card.retranslate()
|
|
card.refresh()
|
|
assert "CPU 50%" in card.limits_lbl.text()
|
|
assert "m" in card.uptime_val.text()
|
|
|
|
|
|
def test_refresh_reflects_network_blocked_on_both_cards(qapp, tmp_path) -> None:
|
|
card = SandboxDetailsCard(_FakeCtx(tmp_path, block_network=True), on_settings_changed=lambda: None)
|
|
card.retranslate()
|
|
card.refresh()
|
|
assert card.net_val.objectName() == "badgeWarn"
|
|
assert card.permissions_card.network_val.objectName() == "badgeWarn"
|
|
|
|
|
|
def test_refresh_reflects_network_allowed(qapp, tmp_path) -> None:
|
|
card = SandboxDetailsCard(_FakeCtx(tmp_path, block_network=False), on_settings_changed=lambda: None)
|
|
card.retranslate()
|
|
card.refresh()
|
|
assert card.net_val.objectName() == "badgeSuccess"
|
|
assert card.permissions_card.network_val.objectName() == "badgeSuccess"
|
|
|
|
|
|
def test_fold_starts_collapsed(qapp, tmp_path) -> None:
|
|
# isVisible() alone can't tell (it also depends on ancestors actually
|
|
# being shown on screen, which nothing here is) — isHidden() reflects
|
|
# the explicit setVisible(False) call regardless of the parent chain.
|
|
card = SandboxDetailsCard(_FakeCtx(tmp_path), on_settings_changed=lambda: None)
|
|
assert card._detail.isHidden() is True
|
|
card.more_btn.setChecked(True)
|
|
assert card._detail.isHidden() is False
|