Files
clice/tests/integration/utils/workspace.py
ykiko 8b3e3a9595 refactor(tests): reorganize integration tests into domain-based subdirectories (#409)
## 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>
2026-04-09 02:40:10 +08:00

66 lines
2.0 KiB
Python

"""Workspace and file utilities for integration tests."""
import json
from pathlib import Path
from lsprotocol.types import (
DidChangeTextDocumentParams,
TextDocumentContentChangeWholeDocument,
TextDocumentIdentifier,
VersionedTextDocumentIdentifier,
)
def doc(uri: str) -> TextDocumentIdentifier:
"""Create a TextDocumentIdentifier from a URI string."""
return TextDocumentIdentifier(uri=uri)
def write_cdb(
workspace: Path,
files: list[str],
*,
extra_args: list[str] | None = None,
std: str = "c++17",
) -> None:
"""Write a compile_commands.json for the given source files.
Args:
workspace: Root directory of the workspace.
files: List of source file names (relative to workspace).
extra_args: Additional compiler arguments (e.g. ["-DFOO", "-I/bar"]).
std: C++ standard version (default: c++17).
"""
entries = []
for f in files:
args = ["clang++", f"-std={std}", "-fsyntax-only"]
if extra_args:
args.extend(extra_args)
args.append(str(workspace / f))
entries.append(
{
"directory": str(workspace),
"file": str(workspace / f),
"arguments": args,
}
)
(workspace / "compile_commands.json").write_text(json.dumps(entries, indent=2))
def write_source(workspace: Path, name: str, content: str) -> Path:
"""Write a source file to the workspace directory. Returns the file path."""
path = workspace / name
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(content)
return path
def did_change(client, uri: str, version: int, text: str) -> None:
"""Send a didChange notification with whole-document replacement."""
client.text_document_did_change(
DidChangeTextDocumentParams(
text_document=VersionedTextDocumentIdentifier(uri=uri, version=version),
content_changes=[TextDocumentContentChangeWholeDocument(text=text)],
)
)