Files
cowork-local/tests/test_monitoring_event_tabs.py
T
f9f6bc01fd
CI / test (push) Canceled after 0s
Feature/delta team/epic r04 (#7)
## Summary

epic r04 - begin refactor

## Change Type

- [x] Cowork feature
- [ ] Bug fix
- [ ] Core AI contribution
- [ ] Test / hardening
- [ ] Performance
- [ ] Documentation

## Related Work

Cowork Task:

Core Repo: http://34.143.229.138/gitea-admin/fsg-ai-core-assets

Core AI Issue:

Core Task:

Related PR:

## Scope

What is intentionally included?

What is intentionally NOT included?

## Validation

- [ ] Unit tests
- [ ] Integration tests
- [ ] Manual verification
- [ ] Regression check

Commands / evidence:

## Security Impact

Permission / credential / network / customer data impact:

## Compatibility

- [ ] No breaking change
- [ ] Breaking change documented

## Reviewer Notes

Anything Cowork reviewers should pay attention to.

---------

Co-authored-by: Anh Tran Nguyen Minh <anhtnm1@fpt.com>
Co-authored-by: Huong Le Thi Thien <huongltt35@fpt.com>
Co-authored-by: Nam Pham Dinh Thanh <nampdt@fpt.com>
Co-authored-by: Vu Dam Tuan <vudt15@fpt.com>
Co-authored-by: Hiep Ha Van <hiephv3@fpt.com>
Co-authored-by: Lam Hoang Van <lamhv7@fpt.com>
Reviewed-on: #7
Co-authored-by: Duy Le Huu <duylh19@fpt.com>
2026-08-31 05:15:13 +00:00

60 lines
2.1 KiB
Python

"""Task 1 (sub-step 6c) — SecurityEventsTab / McpTab / ActionLogsTab.
Widget smoke tests against the offscreen QPA platform (see
test_monitoring_event_widgets.py for why no pytest-qt is needed). Verifies
each tab wires build_filter_scaffold correctly, exposes the attributes the
container's retranslate loop needs, and forwards set_events to its table.
"""
from __future__ import annotations
import os
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
import pytest
QApplication = pytest.importorskip("PySide6.QtWidgets").QApplication
from cowork_local.presentation.monitoring.tabs.action_logs_tab import ActionLogsTab
from cowork_local.presentation.monitoring.tabs.mcp_tab import McpTab
from cowork_local.presentation.monitoring.tabs.security_events_tab import SecurityEventsTab
@pytest.fixture(scope="module")
def qapp():
app = QApplication.instance() or QApplication([])
yield app
@pytest.mark.parametrize("cls,expected_title_key", [
(SecurityEventsTab, "monitoring.security_events_title"),
(McpTab, "monitoring.mcp_history_title"),
(ActionLogsTab, "monitoring.action_logs_title"),
])
def test_tab_exposes_container_facing_attributes(qapp, cls, expected_title_key) -> None:
refresh_calls = []
tab = cls(ctx=None, on_refresh_all=lambda: refresh_calls.append(1))
assert tab.title_key == expected_title_key
assert tab.filter_edit is not None
assert tab.detail_panel is not None
tab.title_refresh_btn.click()
assert refresh_calls == [1]
def test_set_events_forwards_to_table(qapp) -> None:
tab = SecurityEventsTab(ctx=None, on_refresh_all=lambda: None)
tab.set_events([{"ts": "2026-01-01T00:00:00", "kind": "security_block", "name": "x",
"ok": False, "detail": "d", "account": "a", "machine": "m"}])
assert tab.table.rowCount() == 1
def test_retranslate_does_not_raise(qapp) -> None:
tab = McpTab(ctx=None, on_refresh_all=lambda: None)
tab.retranslate() # must not raise
def test_ai_filter_noop_when_search_box_empty(qapp) -> None:
tab = ActionLogsTab(ctx=None, on_refresh_all=lambda: None)
tab.ai_filter_btn.click() # empty search text -> start_ai_filter no-ops, must not raise