49 lines
2.2 KiB
Python
49 lines
2.2 KiB
Python
"""Repeat history after transport outbox cleanup; never replay changed settings."""
|
|
|
|
import json
|
|
|
|
import pytest
|
|
from test_equipment_network import context, full_core_context # noqa: F401
|
|
|
|
from k1link.fleet import equipment_command_journal as journal
|
|
from k1link.fleet import equipment_command_runtime as runtime
|
|
from k1link.fleet import equipment_network as network
|
|
from k1link.fleet.equipment_command_repeat import repeat
|
|
from k1link.fleet.independent_equipment import EquipmentError
|
|
|
|
|
|
@pytest.mark.parametrize("read_only", [True, False])
|
|
def test_repeat_network_intent_after_outbox_cleanup(full_core_context, monkeypatch, read_only): # noqa: F811
|
|
equipment, hosts, row, _ = full_core_context
|
|
for host in hosts.rows():
|
|
host["status"].update(version="0.1.42", capabilities=["arnavi-b2-durable-operations-v1"])
|
|
hosts.save(host)
|
|
sent = []
|
|
|
|
def send(host, method, path, body=None):
|
|
sent.append(body)
|
|
return {"id": body["id"], "kind": body["kind"], "state": "rejected", "durable": True}
|
|
|
|
monkeypatch.setattr(network, "request", send)
|
|
original = network.start(hosts, row["id"], row["revision"], read_only)["network_operation"]
|
|
with equipment.db() as db:
|
|
assert db.execute("SELECT count(*) FROM network_outbox").fetchone()[0] == 0
|
|
repeated = repeat(hosts, row["id"], original["id"], "f" * 32)
|
|
assert repeated["state"] == "waiting"
|
|
assert "network_intent" not in repeated
|
|
assert repeat(hosts, row["id"], original["id"], "f" * 32) == repeated
|
|
runtime.pump(hosts)
|
|
assert len(sent) == 2 and sent[0]["kind"] == sent[1]["kind"]
|
|
assert sent[0]["id"] != sent[1]["id"]
|
|
if not read_only:
|
|
assert sent[0]["target_configuration"] == sent[1]["target_configuration"]
|
|
with equipment.db() as db:
|
|
current = equipment._find(db, "instances", row["id"])
|
|
current["settings"]["parameters"]["25"] += 1
|
|
db.execute("UPDATE instances SET body=? WHERE id=?", (json.dumps(current), row["id"]))
|
|
with pytest.raises(EquipmentError, match="Настройки изменились"):
|
|
repeat(hosts, row["id"], original["id"], "a" * 32)
|
|
assert all(
|
|
"network_intent" not in item for item in journal.listing(equipment, row["id"])["items"]
|
|
)
|