feat(server): add project RBAC and guarded workflows
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
from collections import defaultdict
|
||||
|
||||
from app.algorithms.isolation import valve
|
||||
|
||||
|
||||
def test_non_isolatable_omits_affected_node_ids_but_keeps_count(monkeypatch):
|
||||
pipe_adj = defaultdict(
|
||||
set,
|
||||
{
|
||||
"A": {"B"},
|
||||
"B": {"A", "C"},
|
||||
"C": {"B"},
|
||||
},
|
||||
)
|
||||
topology = (
|
||||
pipe_adj,
|
||||
{"V-optional": ("A", "C")},
|
||||
{"P-1": ("A", "B", "pipe")},
|
||||
{"A", "B", "C"},
|
||||
)
|
||||
monkeypatch.setattr(valve, "_get_network_topology", lambda _network: topology)
|
||||
|
||||
result = valve.valve_isolation_analysis("demo", "P-1")
|
||||
|
||||
assert result["isolatable"] is False
|
||||
assert result["affected_node_count"] == 3
|
||||
assert result["affected_nodes"] == []
|
||||
assert result["optional_valves"] == ["V-optional"]
|
||||
|
||||
|
||||
def test_isolatable_keeps_affected_node_ids_and_count(monkeypatch):
|
||||
pipe_adj = defaultdict(set, {"A": {"B"}, "B": {"A"}})
|
||||
topology = (
|
||||
pipe_adj,
|
||||
{"V-close": ("B", "C")},
|
||||
{"P-1": ("A", "B", "pipe")},
|
||||
{"A", "B", "C"},
|
||||
)
|
||||
monkeypatch.setattr(valve, "_get_network_topology", lambda _network: topology)
|
||||
|
||||
result = valve.valve_isolation_analysis("demo", "P-1")
|
||||
|
||||
assert result["isolatable"] is True
|
||||
assert result["affected_node_count"] == 2
|
||||
assert result["affected_nodes"] == ["A", "B"]
|
||||
assert result["must_close_valves"] == ["V-close"]
|
||||
|
||||
|
||||
def test_disabled_valve_expands_affected_area_before_counting(monkeypatch):
|
||||
pipe_adj = defaultdict(set, {"A": {"B"}, "B": {"A"}})
|
||||
topology = (
|
||||
pipe_adj,
|
||||
{
|
||||
"V-disabled": ("B", "C"),
|
||||
"V-close": ("C", "D"),
|
||||
},
|
||||
{"P-1": ("A", "B", "pipe")},
|
||||
{"A", "B", "C", "D"},
|
||||
)
|
||||
monkeypatch.setattr(valve, "_get_network_topology", lambda _network: topology)
|
||||
|
||||
result = valve.valve_isolation_analysis(
|
||||
"demo",
|
||||
"P-1",
|
||||
disabled_valves=["V-disabled"],
|
||||
)
|
||||
|
||||
assert result["isolatable"] is True
|
||||
assert result["affected_node_count"] == 3
|
||||
assert result["affected_nodes"] == ["A", "B", "C"]
|
||||
assert result["must_close_valves"] == ["V-close"]
|
||||
Reference in New Issue
Block a user