Files
cowork-local/tests/unit/test_check_imports.py
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
1.8 KiB
Python

"""Unit tests for the Clean Architecture AST Import Guard (check_imports.py)."""
from __future__ import annotations
from pathlib import Path
from scripts.check_imports import FORBIDDEN_MODULE_PREFIXES, scan_file
def test_clean_python_file_passes(tmp_path: Path) -> None:
"""Verify that pure Python code without GUI imports produces 0 violations."""
clean_code = """
import os
import json
from dataclasses import dataclass
from typing import List
@dataclass
class UserRequest:
id: str
prompt: str
"""
clean_file = tmp_path / "clean_service.py"
clean_file.write_text(clean_code, encoding="utf-8")
violations = scan_file(clean_file, FORBIDDEN_MODULE_PREFIXES)
assert len(violations) == 0
def test_forbidden_pyside_import_detected(tmp_path: Path) -> None:
"""Verify that PySide6 import is caught with correct line number."""
dirty_code = """
from dataclasses import dataclass
from PySide6.QtWidgets import QWidget
class BadService:
pass
"""
dirty_file = tmp_path / "bad_service.py"
dirty_file.write_text(dirty_code, encoding="utf-8")
violations = scan_file(dirty_file, FORBIDDEN_MODULE_PREFIXES)
assert len(violations) == 1
assert violations[0].line_number == 3
assert "PySide6" in violations[0].imported_module
def test_forbidden_ui_and_app_import_detected(tmp_path: Path) -> None:
"""Verify that importing concrete UI or app modules from domain is caught."""
dirty_code = """
import ui.chat_panel
from app import MainWindow
"""
dirty_file = tmp_path / "cross_layer_leak.py"
dirty_file.write_text(dirty_code, encoding="utf-8")
violations = scan_file(dirty_file, FORBIDDEN_MODULE_PREFIXES)
assert len(violations) == 2
modules = [v.imported_module for v in violations]
assert "ui.chat_panel" in modules
assert "app" in modules