Files
iLSP/tests/test_proxy.py
Henrik Jess Nielsen 44da791f5a
All checks were successful
Build and Deploy iLSP / build-and-deploy (push) Successful in 2m6s
Build and Deploy iLSP / test (push) Successful in 19s
fix: update tests to match thread-based proxy API (_frame, _inject_completions)
BicepProxy class and _ContentLengthFramer no longer exist after rewrite.
Tests now call module-level functions directly.
2026-05-10 13:35:40 +02:00

78 lines
2.4 KiB
Python

"""Unit tests for Bicep proxy message injection."""
import json
import pytest
from ilsp.bicep_lsp.modules import BicepModuleCatalog
from ilsp.bicep_lsp.proxy import _frame, _inject_completions
def test_frame_produces_correct_header():
body = b'{"jsonrpc":"2.0"}'
framed = _frame(body)
assert framed.startswith(b"Content-Length: 17\r\n\r\n")
assert framed.endswith(body)
@pytest.fixture(autouse=True)
def reset_modules():
BicepModuleCatalog._modules = []
yield
def _completion_response(items: list) -> dict:
return {
"jsonrpc": "2.0",
"id": 1,
"result": {"isIncomplete": False, "items": items},
}
def test_standard_items_not_downgraded_without_lru():
"""Without LRU modules, standard items keep their original sortText."""
msg = _completion_response([{"label": "Microsoft.Storage", "sortText": "az"}])
out = json.loads(_inject_completions(msg))
# No LRU modules → no downgrade, original sortText preserved
assert out["result"]["items"][0]["sortText"] == "az"
def test_lru_modules_injected_at_top():
BicepModuleCatalog._modules = [{
"name": "appservice",
"path": "bicep/modules/appservice",
"versions": ["2.3.0", "latest"],
"latest": "latest",
"registry": "iactemplatereg.azurecr.io",
}]
msg = _completion_response([{"label": "Microsoft.Web/sites", "sortText": "az"}])
out = json.loads(_inject_completions(msg))
items = out["result"]["items"]
assert items[0]["label"] == "appservice"
assert items[0]["sortText"].startswith("0_lru_")
assert items[1]["label"] == "Microsoft.Web/sites"
assert items[1]["sortText"].startswith("1_az_")
def test_list_result_also_handled():
BicepModuleCatalog._modules = [{
"name": "roleassignments",
"path": "bicep/modules/roleassignments",
"versions": ["2.0.0"],
"latest": "2.0.0",
"registry": "iactemplatereg.azurecr.io",
}]
msg = {"jsonrpc": "2.0", "id": 2, "result": [{"label": "az-item", "sortText": "az"}]}
out = json.loads(_inject_completions(msg))
assert isinstance(out["result"], list)
assert out["result"][0]["label"] == "roleassignments"
def test_non_completion_message_passthrough():
msg = {"jsonrpc": "2.0", "method": "initialized", "params": {}}
out = json.loads(_inject_completions(msg))
assert out["method"] == "initialized"