Route HTML5 AI structure CF/CFE through Windows Agent
CI / python (push) Has been cancelled
CI / rust (push) Has been cancelled

This commit is contained in:
2026-05-22 00:39:02 +03:00
parent 23800dea71
commit b85bff6e06
4 changed files with 391 additions and 2 deletions
+78
View File
@@ -1809,6 +1809,84 @@ def test_ai_structure_prepare_reports_cf_cfe_export_required(tmp_path: Path):
assert "Статус: `export_required`" in (output / payload["codex_package_folder"] / "README.md").read_text(encoding="utf-8")
def test_html5_ai_structure_routes_binary_cf_through_windows_agent(tmp_path: Path):
metadata_root = tmp_path / "metadata"
metadata_root.mkdir()
(metadata_root / "metadata.xml").write_text(
"""
<Configuration>
<Catalog name="Контрагенты" qualifiedName="Справочник.Контрагенты" />
</Configuration>
""",
encoding="utf-8",
)
cf_input = tmp_path / "demo.cf"
cf_input.write_bytes(b"binary-cf")
output = tmp_path / "ai-out"
client = TestClient(app)
project_id = f"ai-agent-{uuid4()}"
agent_id = f"win-agent-{uuid4()}"
indexed = client.post("/projects/index", json={"path": str(metadata_root), "project_id": project_id})
assert indexed.status_code == 200
settings = client.post(
f"/projects/{project_id}/settings",
json={
"name": "AI Agent Demo",
"structure_source": "CF_FILE",
"agent": {
"cf_agent_id": agent_id,
"one_c_server": "192.168.200.95",
"one_c_infobase": "upo_test",
"one_c_user": "svc",
"one_c_password": "secret",
},
},
)
assert settings.status_code == 200
heartbeat = client.post("/agent/heartbeat", json={"agent_id": agent_id, "host": "test-host"})
assert heartbeat.status_code == 200
queued = client.post(
f"/html5/projects/{project_id}/ai-structure/run",
data={"project_id": project_id, "input_path": str(cf_input), "output_path": str(output)},
)
assert queued.status_code == 200
assert "Windows Agent" in queued.text
assert "/ai-structure/jobs/" in queued.text
match = re.search(r"/html5/projects/[^/]+/ai-structure/jobs/([A-Za-z0-9-]+)", queued.text)
assert match is not None
job_id = match.group(1)
claimed = client.get("/agent/jobs/next", params={"agent_id": agent_id})
assert claimed.status_code == 200
assert claimed.json()["job_id"] == job_id
assert claimed.json()["source"] == "CF_FILE"
completed = client.post(
f"/agent/jobs/{job_id}/result",
json={
"status": "SUCCEEDED",
"server_path": str(metadata_root),
"logs": ["Выгрузка конфигурации завершена."],
},
)
assert completed.status_code == 200
deadline = time.monotonic() + 10
fragment = ""
while time.monotonic() < deadline:
polled = client.get(f"/html5/projects/{project_id}/ai-structure/jobs/{job_id}")
assert polled.status_code == 200
fragment = polled.text
if "готово" in fragment:
break
time.sleep(0.05)
assert "готово" in fragment
assert "codex-1c-context" in fragment
assert (output / f"codex-1c-context-{project_id}" / "AGENTS.md").exists()
def test_import_full_replace_replaces_current_normalized_project(tmp_path: Path):
first = tmp_path / "first"
second = tmp_path / "second"