## Summary - Extract shared test utilities into `tests/integration/utils/` (client, workspace, assertions, wait, cache) - Migrate 12 test files into categorized subdirectories: `lifecycle/`, `compilation/`, `features/`, `modules/`, `extensions/`, `stress/` - Merge `test_include_completion.py` + `test_import_completion.py` → `features/test_completion.py` - Remove stale directory-tree comments and section divider comments ## Test plan - [x] `pytest --collect-only` collects all 113 tests - [x] All test module imports verified - [x] `pixi run format` applied 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Reorganized integration suites: added new feature tests (completion, server) and removed older duplicated modules. * Centralized shared test utilities and assertion helpers for diagnostics, workspace operations, waiting/synchronization, and cache inspection. * **Chores / Refactor** * Standardized test client lifecycle and helper usage across suites for more reliable test flows. * Improved server session lifecycle handling for more predictable document/session resets during tests. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
"""Diagnostic assertion helpers for integration tests."""
|
|
|
|
from lsprotocol.types import Diagnostic, DiagnosticSeverity
|
|
|
|
|
|
def get_errors(diagnostics: list[Diagnostic]) -> list[Diagnostic]:
|
|
"""Filter diagnostics to errors only (severity == 1)."""
|
|
return [d for d in diagnostics if d.severity == DiagnosticSeverity.Error]
|
|
|
|
|
|
def assert_no_errors(client, uri: str, msg: str = "") -> None:
|
|
"""Assert that there are no error-level diagnostics for the given URI."""
|
|
diags = client.diagnostics.get(uri, [])
|
|
errors = get_errors(diags)
|
|
if msg:
|
|
assert len(errors) == 0, f"{msg}: {errors}"
|
|
else:
|
|
assert len(errors) == 0, f"Expected no errors, got: {errors}"
|
|
|
|
|
|
def assert_has_errors(client, uri: str, msg: str = "") -> None:
|
|
"""Assert that there is at least one error-level diagnostic for the given URI."""
|
|
diags = client.diagnostics.get(uri, [])
|
|
errors = get_errors(diags)
|
|
if msg:
|
|
assert len(errors) > 0, msg
|
|
else:
|
|
assert len(errors) > 0, "Expected at least one error diagnostic"
|
|
|
|
|
|
def assert_diagnostics_count(
|
|
client,
|
|
uri: str,
|
|
count: int,
|
|
*,
|
|
severity: int | None = None,
|
|
) -> None:
|
|
"""Assert exact number of diagnostics, optionally filtered by severity."""
|
|
diags = client.diagnostics.get(uri, [])
|
|
if severity is not None:
|
|
diags = [d for d in diags if d.severity == severity]
|
|
assert len(diags) == count, (
|
|
f"Expected {count} diagnostics (severity={severity}), got {len(diags)}: {diags}"
|
|
)
|
|
|
|
|
|
def assert_clean_compile(client, uri: str) -> None:
|
|
"""Assert the file compiled without any diagnostics at all."""
|
|
diags = client.diagnostics.get(uri, [])
|
|
assert len(diags) == 0, f"Expected clean compile, got: {diags}"
|