158 lines
5.6 KiB
Python
158 lines
5.6 KiB
Python
from fastapi.testclient import TestClient
|
|
|
|
from runtime_adapter.main import app
|
|
|
|
|
|
def test_runtime_adapter_mock_import_returns_normalized_project(monkeypatch):
|
|
monkeypatch.setenv("RUNTIME_ADAPTER_MODE", "mock")
|
|
client = TestClient(app)
|
|
|
|
response = client.post("/runtime/import", json={"source_kind": "CF_FILE", "project_id": "demo"})
|
|
|
|
assert response.status_code == 200
|
|
payload = response.json()
|
|
assert payload["status"] == "mock_imported"
|
|
assert payload["mode"] == "mock"
|
|
assert payload["normalized_project"]["project_id"] == "demo"
|
|
|
|
|
|
def test_runtime_adapter_local_1c_requires_designer(monkeypatch):
|
|
monkeypatch.setenv("RUNTIME_ADAPTER_MODE", "local_1c")
|
|
monkeypatch.delenv("ONEC_DESIGNER_PATH", raising=False)
|
|
monkeypatch.setenv("ONEC_DISABLE_AUTO_DISCOVERY", "true")
|
|
client = TestClient(app)
|
|
|
|
response = client.post("/runtime/import", json={"source_kind": "CF_FILE", "path": "/tmp/demo.cf"})
|
|
|
|
assert response.status_code == 503
|
|
|
|
|
|
def test_runtime_adapter_local_1c_normalizes_edt_without_designer_execution(monkeypatch, tmp_path):
|
|
(tmp_path / "metadata.xml").write_text(
|
|
"""
|
|
<Configuration>
|
|
<Catalog name="Контрагенты" qualifiedName="Справочник.Контрагенты" />
|
|
</Configuration>
|
|
""",
|
|
encoding="utf-8",
|
|
)
|
|
monkeypatch.setenv("RUNTIME_ADAPTER_MODE", "local_1c")
|
|
monkeypatch.delenv("ONEC_DESIGNER_PATH", raising=False)
|
|
monkeypatch.setenv("ONEC_DISABLE_AUTO_DISCOVERY", "true")
|
|
client = TestClient(app)
|
|
|
|
response = client.post(
|
|
"/runtime/import",
|
|
json={"source_kind": "EDT_PROJECT", "project_id": "edt", "path": str(tmp_path)},
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
payload = response.json()
|
|
assert payload["status"] == "normalized"
|
|
assert payload["normalized_project"]["configuration"]["groups"][0]["name"] == "Справочники"
|
|
|
|
|
|
def test_runtime_adapter_local_1c_returns_cf_dump_plan_without_execution(monkeypatch, tmp_path):
|
|
designer = tmp_path / "1cv8.exe"
|
|
designer.write_text("", encoding="utf-8")
|
|
cf_file = tmp_path / "demo.cf"
|
|
cf_file.write_text("binary-placeholder", encoding="utf-8")
|
|
monkeypatch.setenv("RUNTIME_ADAPTER_MODE", "local_1c")
|
|
monkeypatch.setenv("ONEC_DESIGNER_PATH", str(designer))
|
|
monkeypatch.delenv("ONEC_ENABLE_DESIGNER_EXECUTION", raising=False)
|
|
client = TestClient(app)
|
|
|
|
response = client.post(
|
|
"/runtime/import",
|
|
json={"source_kind": "CF_FILE", "project_id": "cf", "path": str(cf_file)},
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
payload = response.json()
|
|
assert payload["status"] == "designer_dump_planned"
|
|
assert payload["platform_found"] is True
|
|
assert any("DumpConfigToFiles" in item for item in payload["dump_plan"])
|
|
|
|
|
|
def test_runtime_adapter_live_infobase_dump_plan_redacts_password(monkeypatch, tmp_path):
|
|
designer = tmp_path / "1cv8.exe"
|
|
designer.write_text("", encoding="utf-8")
|
|
monkeypatch.setenv("RUNTIME_ADAPTER_MODE", "local_1c")
|
|
monkeypatch.setenv("ONEC_DESIGNER_PATH", str(designer))
|
|
client = TestClient(app)
|
|
|
|
response = client.post(
|
|
"/runtime/import",
|
|
json={
|
|
"source_kind": "LIVE_INFOBASE",
|
|
"project_id": "live",
|
|
"credentials_ref": "runtime://prompt/live",
|
|
"metadata": {"connection_string": 'Srvr="192.168.200.95";Ref="upo";Pwd="secret"'},
|
|
},
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
payload = response.json()
|
|
plan = "\n".join(payload["dump_plan"])
|
|
assert "secret" not in plan
|
|
assert "Pwd=<redacted>" in plan
|
|
|
|
|
|
def test_runtime_platform_reports_capabilities(monkeypatch, tmp_path):
|
|
designer = tmp_path / "1cv8.exe"
|
|
designer.write_text("", encoding="utf-8")
|
|
monkeypatch.setenv("RUNTIME_ADAPTER_MODE", "local_1c")
|
|
monkeypatch.setenv("ONEC_DESIGNER_PATH", str(designer))
|
|
client = TestClient(app)
|
|
|
|
response = client.get("/runtime/platform")
|
|
|
|
assert response.status_code == 200
|
|
payload = response.json()
|
|
assert payload["platform_found"] is True
|
|
assert "cf_dump_plan" in payload["capabilities"]
|
|
|
|
|
|
def test_runtime_adapter_local_1c_executes_cf_dump(monkeypatch, tmp_path):
|
|
designer = tmp_path / "fake_designer.py"
|
|
designer.write_text(
|
|
"""
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
args = sys.argv[1:]
|
|
if args and args[0] == "CREATEINFOBASE":
|
|
target = next(item for item in args[1:] if item.startswith("File="))[5:].rstrip(";")
|
|
Path(target).mkdir(parents=True, exist_ok=True)
|
|
raise SystemExit(0)
|
|
if "/DumpConfigToFiles" in args:
|
|
target = Path(args[args.index("/DumpConfigToFiles") + 1])
|
|
target.mkdir(parents=True, exist_ok=True)
|
|
(target / "metadata.xml").write_text(
|
|
"<Configuration><Catalog name='Контрагенты' qualifiedName='Справочник.Контрагенты' /></Configuration>",
|
|
encoding="utf-8",
|
|
)
|
|
raise SystemExit(0)
|
|
raise SystemExit(0)
|
|
""",
|
|
encoding="utf-8",
|
|
)
|
|
cf_file = tmp_path / "demo.cf"
|
|
cf_file.write_text("binary-placeholder", encoding="utf-8")
|
|
monkeypatch.setenv("RUNTIME_ADAPTER_MODE", "local_1c")
|
|
monkeypatch.setenv("ONEC_DESIGNER_PATH", str(designer))
|
|
monkeypatch.setenv("ONEC_ENABLE_DESIGNER_EXECUTION", "true")
|
|
client = TestClient(app)
|
|
|
|
response = client.post(
|
|
"/runtime/import",
|
|
json={"source_kind": "CF_FILE", "project_id": "cf-exec", "path": str(cf_file)},
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
payload = response.json()
|
|
assert payload["status"] == "normalized"
|
|
assert payload["platform_found"] is True
|
|
assert payload["normalized_project"]["project_id"] == "cf-exec"
|
|
assert "Local .cf converted to metadata export" in "\n".join(payload["diagnostics"])
|