Files
cleveragents-core/robot/helper_lsp_config_fields.py
hamza.khyari c97ec273a9
CI / build (pull_request) Successful in 21s
CI / helm (pull_request) Successful in 23s
CI / lint (pull_request) Successful in 26s
CI / quality (pull_request) Successful in 56s
CI / typecheck (pull_request) Successful in 1m2s
CI / security (pull_request) Successful in 1m7s
CI / integration_tests (pull_request) Successful in 5m51s
CI / unit_tests (pull_request) Successful in 7m29s
CI / docker (pull_request) Successful in 2m13s
CI / coverage (pull_request) Successful in 8m50s
CI / benchmark-publish (pull_request) Has been skipped
CI / e2e_tests (pull_request) Successful in 15m34s
CI / status-check (pull_request) Successful in 2s
CI / benchmark-regression (pull_request) Successful in 59m14s
feat(lsp): add missing LspServerConfig model fields
Add specification-required fields to LspServerConfig:

- description: str (max_length=1000, default='')
- transport: LspTransport enum (stdio/tcp/pipe, default=stdio)
- initialization: dict[str, Any] (LSP initializationOptions, default={})
- workspace_settings: dict[str, Any] (workspace/didChangeConfiguration, default={})

All fields have defaults for backward compatibility with existing
configs. LspTransport enum exported from lsp package.

Tests: 17 Behave scenarios, 5 Robot integration tests.
Existing LSP tests: 250/250 pass unchanged.

ISSUES CLOSED: #835
2026-03-30 11:51:27 +00:00

123 lines
3.8 KiB
Python

"""Robot Framework helper for LSP config fields integration tests."""
from __future__ import annotations
import importlib
import sys
from pathlib import Path
_SRC = str(Path(__file__).resolve().parents[1] / "src")
if _SRC not in sys.path:
sys.path.insert(0, _SRC)
import cleveragents # noqa: E402
importlib.reload(cleveragents)
from cleveragents.lsp.models import ( # noqa: E402
LspCapability,
LspServerConfig,
LspTransport,
)
from cleveragents.lsp.registry import LspRegistry # noqa: E402
def _run_transport_enum() -> None:
"""Verify LspTransport enum values."""
assert LspTransport.STDIO.value == "stdio"
assert LspTransport.TCP.value == "tcp"
# PIPE is not in the spec -- only stdio and tcp
assert len(LspTransport) == 2, f"Expected 2 members, got {len(LspTransport)}"
print("transport-enum-ok")
def _run_config_defaults() -> None:
"""Verify new field defaults."""
cfg = LspServerConfig(name="local/test", command="echo", languages=["python"])
assert cfg.description == ""
assert cfg.transport == LspTransport.STDIO
assert cfg.initialization == {}
assert cfg.workspace_settings == {}
print("config-defaults-ok")
def _run_config_all_fields() -> None:
"""Verify config with all fields populated."""
cfg = LspServerConfig(
name="local/pyright",
description="Pyright type checker",
command="pyright-langserver",
args=["--stdio"],
transport=LspTransport.STDIO,
languages=["python"],
capabilities=[LspCapability.DIAGNOSTICS],
initialization={"python": {"pythonPath": "/usr/bin/python3"}},
workspace_settings={"editor.formatOnSave": True},
)
assert cfg.description == "Pyright type checker"
assert cfg.transport == LspTransport.STDIO
assert "python" in cfg.initialization
assert "editor.formatOnSave" in cfg.workspace_settings
print("config-all-fields-ok")
def _run_config_roundtrip() -> None:
"""Verify serialization round-trip."""
cfg = LspServerConfig(
name="local/test",
description="Test server",
command="echo",
transport=LspTransport.TCP,
languages=["python"],
initialization={"key": "value"},
workspace_settings={"ws": True},
)
data = cfg.model_dump(mode="json")
cfg2 = LspServerConfig.model_validate(data)
assert cfg.description == cfg2.description
assert cfg.transport == cfg2.transport
assert cfg.initialization == cfg2.initialization
assert cfg.workspace_settings == cfg2.workspace_settings
print("config-roundtrip-ok")
def _run_registry_preserves() -> None:
"""Verify registry preserves new fields."""
reg = LspRegistry()
cfg = LspServerConfig(
name="local/test",
description="Test",
command="echo",
transport=LspTransport.TCP,
languages=["python"],
initialization={"k": "v"},
workspace_settings={"w": True},
)
reg.register(cfg)
retrieved = reg.get("local/test")
assert retrieved is not None
assert retrieved.description == "Test"
assert retrieved.transport == LspTransport.TCP
assert retrieved.initialization == {"k": "v"}
assert retrieved.workspace_settings == {"w": True}
print("registry-preserves-ok")
if __name__ == "__main__":
cmd = sys.argv[1] if len(sys.argv) > 1 else "all"
dispatch = {
"transport-enum": _run_transport_enum,
"config-defaults": _run_config_defaults,
"config-all-fields": _run_config_all_fields,
"config-roundtrip": _run_config_roundtrip,
"registry-preserves": _run_registry_preserves,
}
if cmd == "all":
for fn in dispatch.values():
fn()
elif cmd in dispatch:
dispatch[cmd]()
else:
print(f"Unknown command: {cmd}")
sys.exit(1)