test(grpc-data): A4 live scenarios part 2 harness — A03 origin failover (same-incarnation stream reset via mapping revision bump, clear-and-re-raise in the gap, RefreshRequired, BadEventIdUnknown, refreshed EventId acks), A06 consumer Primary change across both nodes + second CONSUMER principal fixture-cli-alt, A07 consumer restart refresh-vs-barrier; CLI alarms prints EventType (names RefreshStart/End/Required)

This commit is contained in:
Joseph Doherty
2026-11-25 01:44:58 -05:00
parent c82b8683b0
commit 9ea50c11b2
8 changed files with 365 additions and 12 deletions
@@ -2,9 +2,9 @@
python3 scripts/validation/grpc-data/conditions_scenarios.py --run-id <id> [--only A01,A02,A04,A05,A08]
Part 1 implements A01, A02, A04, A05 and A08. Part 2 (A03 origin failover, A06 consumer Primary change, A07 consumer
restart) adds `scenario_A03`/`scenario_A06`/`scenario_A07` methods to `ConditionScenarios` and their ids to `SCENARIOS`;
everything else (watchers, browse-resolved ids, per-scenario restore + JSON/markdown result) is shared.
Part 1 implemented A01, A02, A04, A05 and A08; part 2 adds A03 (origin failover + EventId re-binding), A06 (consumer
Primary change, both consumer nodes, two principals) and A07 (consumer node restart, ConditionRefresh vs the first
snapshot barrier). Everything else (watchers, browse-resolved ids, per-scenario restore + JSON/markdown result) is shared.
Rules every scenario follows:
- ids are RESOLVED, never constructed: projected folders by browsing the consumer's address space, imported ConditionIds
@@ -30,8 +30,10 @@ from pathlib import Path
import rig
import scenarios
SCENARIOS = ("A01", "A02", "A04", "A05", "A08") # part 2 appends A03, A06, A07
TIMEOUTS = {"A01": 420, "A02": 360, "A04": 480, "A05": 720, "A08": 720}
SCENARIOS = ("A01", "A02", "A03", "A04", "A05", "A06", "A07", "A08")
TIMEOUTS = {"A01": 420, "A02": 360, "A03": 1200, "A04": 480, "A05": 720, "A06": 1200, "A07": 900, "A08": 720}
REFRESH_REQUIRED = "RefreshRequiredEventType"
_LOG_TIME = re.compile(r"(\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.\d+)?)")
NO_ACK = int(0b111111111111) & ~(1 << 8) # NodePermissions.Admin (4095) without AlarmAcknowledge (1 << 8)
ADMIN = 4095
_BROWSE = re.compile(r"^(\s*)\[(\w+)\]\s+(.*?)\s+\(NodeId:\s*(.*)\)\s*$")
@@ -40,7 +42,7 @@ _BROWSE = re.compile(r"^(\s*)\[(\w+)\]\s+(.*?)\s+\(NodeId:\s*(.*)\)\s*$")
class Watch:
"""One CLI `alarms` subscription (Server object by default, or a notifier folder) writing to a restricted log."""
def __init__(self, runner, node, name, *, notifier=None, key=None, refresh=True):
def __init__(self, runner, node, name, *, notifier=None, key=None, refresh=True, extra=()):
self.log = runner.folder / name
self.started = time.time()
descriptor = os.open(self.log, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
@@ -49,6 +51,7 @@ class Watch:
argv += ["-n", notifier]
if refresh:
argv.append("--refresh")
argv += list(extra)
self.process = subprocess.Popen(argv, stdout=descriptor, stderr=subprocess.STDOUT, start_new_session=True, cwd=rig.ROOT)
os.close(descriptor)
@@ -72,7 +75,7 @@ class Watch:
continue
fields = {"Time": header.group(1), "Source": header.group(2).strip()}
for line in block.splitlines():
match = re.match(r"\s*(Condition|State|Severity|Message|Retain|ConditionNodeId|EventId):\s*(.*)$", line)
match = re.match(r"\s*(Condition|State|Severity|Message|Retain|ConditionNodeId|EventId|EventType):\s*(.*)$", line)
if match:
fields[match.group(1)] = match.group(2).strip()
if condition is None or fields.get("Condition") == condition:
@@ -102,6 +105,7 @@ class ConditionScenarios:
raise scenarios.ScenarioError("the run was not seeded with the conditions profile (rig.py up --conditions)")
files = self.r.manifest["credentials"]["data_key_files"]
self.nogrant_key = Path(files["cli_nogrant"]).read_text().strip()
self.alt_key = Path(files["cli_alt"]).read_text().strip() if "cli_alt" in files else None
self.report = None
# ---- primitives -------------------------------------------------------------------------------------------------
@@ -432,6 +436,292 @@ class ConditionScenarios:
self.raise_scripted(0)
time.sleep(4)
# ---- part 2 primitives ------------------------------------------------------------------------------------------
@staticmethod
def utc(offset=0.0):
return time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(time.time() + offset))
def log_lines(self, node, since, needle):
"""Timestamped log lines of `node` since `since` containing `needle` (e.g. the imported-conditions runner lines)."""
output = self.r.rig.compose("logs", "--no-color", "--timestamps", "--since", since, node, timeout=60)
return [line for line in output.splitlines() if needle in line]
def stream_opened(self, node, since, serving=None):
return [l for l in self.log_lines(node, since, "Imported conditions: stream") if " opened " in l and (serving is None or serving in l)]
def barriers(self, node, since):
return self.log_lines(node, since, "snapshot barrier passed")
@staticmethod
def log_time(line):
match = _LOG_TIME.search(line or "")
return match.group(1)[:26] if match else None
@staticmethod
def block_time(block):
return (block or {}).get("Time", "")[:26] or None
@staticmethod
def refresh_required(blocks):
return [b for b in blocks if REFRESH_REQUIRED in (b.get("EventType") or "")]
@staticmethod
def latest(watcher, name, predicate=lambda b: True):
return next((b for b in reversed(watcher.blocks(name)) if b.get("EventId") and predicate(b)), None)
@staticmethod
def unique_event_ids(blocks):
ids = [b["EventId"] for b in blocks if b.get("EventId")]
return len(ids) == len(set(ids))
def partner(self, pair, node):
return next(n for n in self.r.manifest["nodes"] if n.startswith(pair + "-") and n != node)
def start_watch(self, node, tag, attempts=40, **options):
"""A watcher on a node that may still be starting: relaunch until the CLI reports the subscription."""
for attempt in range(attempts):
watcher = self.watch(node, f"{tag}-{attempt}", **options)
wait_for(lambda: "Subscribed to alarm events" in watcher.text() or watcher.process.poll() is not None, 30, 0.25)
if watcher.process.poll() is None and "Subscribed to alarm events" in watcher.text():
return watcher
watcher.stop()
self.watchers.remove(watcher)
time.sleep(2)
raise scenarios.ScenarioError(f"no alarm subscription on {node}")
def ack(self, node, condition, event_id, tag, command="ack"):
code, text = self.cli(node, command, "-n", condition, "-e", event_id, "-c", f"{self.r.active} {tag}", tag=tag)
return {"code": code, "output": text[-300:], "good": code == 0 and ("successful" in text or "Comment added" in text),
"event_id_unknown": "BadEventIdUnknown" in text}
# ---- part 2 scenarios -------------------------------------------------------------------------------------------
def scenario_A03(self):
"""Origin failover mid-stream with standing active alarms. Phase 1: a consumer stream reset against the SAME origin
incarnation (mapping revision bump) keeps the old EventId usable and reports nothing for unchanged state. Phase 2:
stop the SOURCE Primary, clear-and-re-raise ScalarHigh during the gap (record time changes, state does not) ⇒
RefreshRequired, the pre-failover EventId is BadEventIdUnknown (never re-bound), ConditionRefresh yields a new
EventId that acks Good, nothing still active is retired, no duplicate EventIds, and a real transition after the
resync arrives exactly once (positive control)."""
name, native = self.fixture["conditions"]["scripted"]["condition"], self.fixture["conditions"]["native"]["condition"]
source, consumer = self.r.primary("source"), self.r.primary("consumer")
partner = self.partner("source", source)
self.report["nodes"] = {"source_primary": source, "source_partner": partner, "consumer": consumer}
imported = self.watch(consumer, "consumer")
time.sleep(6)
self.raise_scripted()
active = wait_for(lambda: self.latest(imported, name, lambda b: b.get("State") == "Active, Unacknowledged"), 120)
native_seen = wait_for(lambda: self.latest(imported, native), 150)
if not self.check("scripted_and_native_imported", active and native_seen):
return
condition, native_condition = active["ConditionNodeId"], native_seen["ConditionNodeId"]
self.report["condition_ids"] = {"scripted": condition, "native": native_condition}
# Phase 1 — stream reset against the same origin incarnation.
since = self.utc(-2)
e1 = self.latest(imported, name)["EventId"]
mark = len(imported.blocks(name))
self.r.mutate(bump_mapping_revision=self.fixture["conditions"]["native"]["mappings"]["pumpb"])
self.r.manifest = self.r.rig.load()
opened = wait_for(lambda: self.stream_opened(consumer, since), 120)
barrier = wait_for(lambda: self.barriers(consumer, since), 120)
time.sleep(8)
reset_events = imported.blocks(name)[mark:]
self.report["phase1"] = {"stream_opened": opened[-2:], "barrier": barrier[-2:], "events_during_reset": [(b.get("State"), b.get("EventType")) for b in reset_events],
"watcher_alive": imported.process.poll() is None}
self.check("p1_stream_reopened_same_origin", opened and all(source in line for line in opened))
self.check("p1_barrier_after_reset", barrier)
self.check("p1_no_event_for_unchanged_state", not [b for b in reset_events if b.get("State")])
comment = self.ack(consumer, condition, e1, "comment-old-eventid-same-incarnation", command="comment")
self.report["phase1"]["comment_with_pre_reset_eventid"] = comment
self.check("p1_pre_reset_eventid_still_accepted", comment["good"])
time.sleep(6)
# Phase 2 — origin failover with a clear-and-re-raise in the gap.
pre = self.latest(imported, name)
native_pre = self.latest(imported, native)
self.check("p2_pre_failover_active_unacked", pre and pre.get("State") == "Active, Unacknowledged")
mark_all, mark_named, mark_native = len(imported.blocks()), len(imported.blocks(name)), len(imported.blocks(native))
since = self.utc(-1)
phase2 = self.report["phase2"] = {"pre_eventid": pre["EventId"], "pre_time": pre.get("Time"), "native_pre": native_pre}
with self.r.stopped(source):
self.r.device("set", address=20, value=0)
time.sleep(4)
self.raise_scripted()
phase2["gap_clear_reraise_at"] = self.utc()
phase2["new_source_primary"] = self.r.wait_primary("source", exclude=source)
reopened = wait_for(lambda: self.stream_opened(consumer, since, partner), 240)
barrier = wait_for(lambda: self.barriers(consumer, since), 120)
required = wait_for(lambda: self.refresh_required(imported.blocks()[mark_all:]), 60)
phase2.update(stream_opened=reopened[-2:], barrier=barrier[-2:], refresh_required=required[:3])
during = imported.blocks(name)[mark_named:]
phase2["scripted_events_after_failover"] = [(b.get("State"), b.get("Time")) for b in during]
self.check("p2_stream_reopened_on_new_primary", reopened and phase2["new_source_primary"] == partner)
self.check("p2_gap_covered_no_inactive_seen", not [b for b in during if (b.get("State") or "").startswith("Inactive")])
self.check("p2_refresh_required_received", required)
old = self.ack(consumer, condition, pre["EventId"], "ack-pre-failover-eventid")
phase2["ack_pre_failover"] = old
self.check("p2_pre_failover_eventid_bad_event_id_unknown", old["event_id_unknown"] and not old["good"])
if native_pre: # D7 (informational): the native condition's re-bind depends on whether its record time moved
phase2["native_ack_pre_failover"] = self.ack(consumer, native_condition, native_pre["EventId"], "ack-native-pre-failover")
refreshed = self.watch(consumer, "post-failover-refresh")
replay = wait_for(lambda: self.latest(refreshed, name), 60)
native_replay = wait_for(lambda: self.latest(refreshed, native), 30)
phase2["replay"] = {"scripted": replay, "native": native_replay}
self.check("p2_refresh_replays_scripted_same_condition_new_eventid", replay and replay["ConditionNodeId"] == condition
and replay["EventId"] != pre["EventId"] and replay.get("State") == "Active, Unacknowledged")
self.check("p2_native_still_present_same_condition", native_replay and native_replay["ConditionNodeId"] == native_condition)
if replay:
new = self.ack(consumer, condition, replay["EventId"], "ack-refreshed-eventid")
phase2["ack_refreshed"] = new
self.check("p2_refreshed_eventid_acks_good", new["good"])
self.check("p2_ack_observed", wait_for(lambda: self.latest(imported, name, lambda b: b.get("State") == "Active, Acknowledged"), 30))
# Positive control: a real transition after the resync must arrive, exactly once.
clear_mark = len(imported.blocks(name))
self.r.device("set", address=20, value=0)
wait_for(lambda: [b for b in imported.blocks(name)[clear_mark:] if (b.get("State") or "").startswith("Inactive")], 40)
time.sleep(6)
cleared = [b for b in imported.blocks(name)[clear_mark:] if (b.get("State") or "").startswith("Inactive")]
phase2["clear_events"] = [(b.get("State"), b.get("EventId")) for b in cleared]
self.check("p2_positive_control_clear_exactly_once", len(cleared) == 1)
self.check("p2_no_duplicate_eventids", self.unique_event_ids(imported.blocks(name)[mark_named:])
and self.unique_event_ids(imported.blocks(native)[mark_native:]))
self.check("p2_watcher_alive_throughout", imported.process.poll() is None)
phase2["source_restarted"] = source
def scenario_A06(self):
"""Consumer Primary change with clients on BOTH consumer nodes (two principals): the same ConditionId everywhere; after
the Primary stops, the partner's clients see a real transition exactly once with no duplicate EventIds; the restarted
node converges to the same ConditionIds/state. Also records whether a folder item made first on a fresh node (no
Server-object demand) is refused (part-1 observation 1)."""
if not self.check("alt_principal_seeded", self.alt_key):
return
name, native = self.fixture["conditions"]["scripted"]["condition"], self.fixture["conditions"]["native"]["condition"]
primary = self.r.primary("consumer")
partner = self.partner("consumer", primary)
self.report["nodes"] = {"consumer_primary": primary, "consumer_partner": partner}
watches = {"primary-cli": self.watch(primary, "primary-cli", extra=("-F", self.r.endpoint(partner))),
"primary-alt": self.watch(primary, "primary-alt", key=self.alt_key),
"partner-cli": self.watch(partner, "partner-cli"),
"partner-alt": self.watch(partner, "partner-alt", key=self.alt_key)}
time.sleep(6)
self.raise_scripted()
def ready(w):
return self.latest(w, name, lambda b: b.get("State") == "Active, Unacknowledged") and self.latest(w, native)
wait_for(lambda: all(ready(w) for w in watches.values()), 150)
ids = {k: {"scripted": (self.latest(w, name) or {}).get("ConditionNodeId"), "native": (self.latest(w, native) or {}).get("ConditionNodeId")}
for k, w in watches.items()}
self.report["condition_ids_before"] = ids
reference = ids["primary-cli"]
if not self.check("same_condition_ids_both_nodes_both_principals", reference["scripted"] and reference["native"]
and all(v == reference for v in ids.values())):
return
marks = {k: len(w.blocks(name)) for k, w in watches.items()}
change = self.report["primary_change"] = {}
with self.r.stopped(primary):
change["new_primary"] = self.r.wait_primary("consumer", exclude=primary)
self.check("partner_became_primary", change["new_primary"] == partner)
time.sleep(10)
self.r.device("set", address=20, value=0)
survivors = ("partner-cli", "partner-alt")
wait_for(lambda: all([b for b in watches[k].blocks(name)[marks[k]:] if (b.get("State") or "").startswith("Inactive")] for k in survivors), 60)
time.sleep(6)
for k, w in watches.items():
after = w.blocks(name)[marks[k]:]
change[k] = {"states": states(after), "inactive": len([b for b in after if (b.get("State") or "").startswith("Inactive")]),
"unique_eventids": self.unique_event_ids(w.blocks(name)), "alive": w.process.poll() is None,
"refresh_required": len(self.refresh_required(w.blocks()))}
self.check("partner_clients_see_clear_exactly_once", all(change[k]["inactive"] == 1 for k in survivors))
self.check("partner_clients_no_duplicate_eventids", all(change[k]["unique_eventids"] for k in survivors))
remarks = {k: len(watches[k].blocks(name)) for k in survivors}
self.raise_scripted()
self.check("partner_clients_see_reraise", wait_for(lambda: all([b for b in watches[k].blocks(name)[remarks[k]:]
if b.get("State") == "Active, Unacknowledged"] for k in survivors), 60))
self.stop_watchers()
# The old Primary restarted (manifest endpoints refreshed). Observation 1: a folder item made FIRST on this fresh node.
restarted = primary
folders = wait_for(lambda: self.projected_folders(restarted).get("raw"), 180, 5)
folder_first = {"folder": folders[0]["node_id"] if folders else None}
if folders:
fw = self.watch(restarted, "restarted-folder-first", notifier=folders[0]["node_id"], refresh=False)
time.sleep(20)
folder_first.update(refused="BadNotSupported" in fw.text(), exited=fw.process.poll() is not None,
events_before_server_item=len(fw.blocks()), tail=fw.text()[-400:])
converge = {"restarted-cli": self.start_watch(restarted, "restarted-cli"), "partner-alt2": self.watch(partner, "partner-alt2", key=self.alt_key)}
wait_for(lambda: all(ready(w) for w in converge.values()), 150)
if folders and not folder_first["exited"]:
time.sleep(4)
folder_first["events_after_server_item"] = len(fw.blocks())
self.report["folder_first_on_fresh_node"] = folder_first
ids_after = {k: {"scripted": (self.latest(w, name) or {}).get("ConditionNodeId"), "native": (self.latest(w, native) or {}).get("ConditionNodeId")}
for k, w in converge.items()}
self.report["condition_ids_after_restart"] = ids_after
self.check("restarted_node_converges_same_condition_ids", all(v == reference for v in ids_after.values()))
self.check("restarted_node_same_scripted_state", all((self.latest(w, name) or {}).get("State") == "Active, Unacknowledged" for w in converge.values()))
marks = {k: len(w.blocks(name)) for k, w in converge.items()}
self.r.device("set", address=20, value=0)
wait_for(lambda: all([b for b in w.blocks(name)[marks[k]:] if (b.get("State") or "").startswith("Inactive")] for k, w in converge.items()), 60)
time.sleep(6)
counts = {k: len([b for b in w.blocks(name)[marks[k]:] if (b.get("State") or "").startswith("Inactive")]) for k, w in converge.items()}
self.report["converged_clear_counts"] = counts
self.check("converged_clear_exactly_once_both_nodes", all(v == 1 for v in counts.values()))
self.check("converged_no_duplicate_eventids", all(self.unique_event_ids(w.blocks(name)) for w in converge.values()))
def scenario_A07(self):
"""Consumer node restart (the non-Primary member, so no Primary change): a client that subscribes + ConditionRefreshes
as soon as the node is up (before the first snapshot barrier) — does it get RefreshRequired, and does it end with the
correct view? A ConditionRefresh after the barrier replays the right conditions/state/ConditionIds."""
name, native = self.fixture["conditions"]["scripted"]["condition"], self.fixture["conditions"]["native"]["condition"]
source, primary = self.r.primary("source"), self.r.primary("consumer")
node = self.partner("consumer", primary)
self.report["nodes"] = {"restarted": node, "consumer_primary": primary}
origin = self.watch(source, "origin")
before = self.watch(node, "before-restart")
time.sleep(6)
self.raise_scripted()
wait_for(lambda: self.latest(before, name, lambda b: b.get("State") == "Active, Unacknowledged") and self.latest(before, native), 150)
reference = {"scripted": (self.latest(before, name) or {}).get("ConditionNodeId"), "native": (self.latest(before, native) or {}).get("ConditionNodeId")}
self.report["condition_ids_before"] = reference
if not self.check("restart_target_imports_before", reference["scripted"] and reference["native"]):
return
before.stop()
since = self.utc(-1)
with self.r.stopped(node):
time.sleep(3)
early = self.start_watch(node, "early")
subscribed_at = self.utc()
barrier = wait_for(lambda: self.barriers(node, since), 180)
time.sleep(10)
late = self.watch(node, "late")
wait_for(lambda: self.latest(late, name) and self.latest(late, native), 60)
time.sleep(3)
blocks = early.blocks()
end = next((i for i, b in enumerate(blocks) if "RefreshEnd" in (b.get("EventType") or "")), None)
end_time = self.block_time(blocks[end]) if end is not None else None
barrier_time = self.log_time(barrier[0]) if barrier else None
replay_imported = [b for b in blocks[:end] if b.get("Condition") in (name, native)] if end is not None else []
required = self.refresh_required(blocks)
self.report["early"] = {"subscribed_at": subscribed_at, "refresh_end_time": end_time, "first_barrier": barrier[:1],
"barrier_time": barrier_time, "refresh_preceded_barrier": bool(end_time and barrier_time and end_time < barrier_time),
"imported_in_refresh_replay": len(replay_imported), "refresh_required": [(b.get("Time"), b.get("Source")) for b in required],
"imported_after_refresh": [(b.get("Condition"), b.get("State"), b.get("Time")) for b in blocks[(end or 0) + 1:] if b.get("Condition") in (name, native)][:10]}
self.check("early_refresh_completed", end is not None)
self.check("first_barrier_logged", barrier)
view = {k: {c: ((self.latest(w, c) or {}).get("ConditionNodeId"), (self.latest(w, c) or {}).get("State")) for c in (name, native)}
for k, w in (("early", early), ("late", late))}
origin_scripted = (self.latest(origin, name) or {}).get("State")
self.report["views"] = {**view, "origin_scripted_state": origin_scripted}
self.check("late_refresh_after_snapshot_correct", view["late"][name] == (reference["scripted"], "Active, Unacknowledged")
and view["late"][native][0] == reference["native"] and origin_scripted == "Active, Unacknowledged")
self.check("early_client_view_matches_after_snapshot", view["early"][name] == view["late"][name] and view["early"][native][0] == view["late"][native][0])
marks = {"early": len(early.blocks(name)), "late": len(late.blocks(name))}
self.r.device("set", address=20, value=0)
wait_for(lambda: all([b for b in w.blocks(name)[marks[k]:] if (b.get("State") or "").startswith("Inactive")] for k, w in (("early", early), ("late", late))), 60)
time.sleep(5)
counts = {k: len([b for b in w.blocks(name)[marks[k]:] if (b.get("State") or "").startswith("Inactive")]) for k, w in (("early", early), ("late", late))}
self.report["clear_counts"] = counts
self.check("positive_control_clear_exactly_once", all(v == 1 for v in counts.values()))
self.check("no_duplicate_eventids", self.unique_event_ids(early.blocks(name)) and self.unique_event_ids(late.blocks(name)))
# ---- helpers ----------------------------------------------------------------------------------------------------
@staticmethod
def _records_summary(result):
@@ -462,7 +752,7 @@ class ConditionScenarios:
self.stop_watchers()
try:
self.r.device("set", address=20, value=0)
if scenario in ("A08",):
if scenario in ("A03", "A08"):
self.r.deadline = time.monotonic() + 600
self.r.baseline()
self.report["restored"] = self.report.get("restored", True)
+1
View File
@@ -953,6 +953,7 @@ class LocalRig:
# A4: the UNS-only origin principal (A04) and the CONSUMER CLI principal without a mapping grant (A05).
manifest["credentials"]["data_key_files"]["source_unsonly"] = str(self.folder / "seed" / "source-unsonly.key")
manifest["credentials"]["data_key_files"]["cli_nogrant"] = str(self.folder / "seed" / "cli-nogrant.key")
manifest["credentials"]["data_key_files"]["cli_alt"] = str(self.folder / "seed" / "cli-alt.key")
manifest["state"] = "seeded"
self.capture(manifest)
return manifest
+13 -1
View File
@@ -175,7 +175,7 @@ try
var root = mutation.RootElement;
string[] allowedFields = ["connection_id", "target_mode", "target_node_id", "consistency", "consumer_node_ids", "connection_enabled", "connection_allowed_operations",
"mapping_enabled", "write_through", "allowed_operations", "export_id", "export_enabled", "export_allowed_operations", "source_redundancy_mode", "consumer_redundancy_mode",
"control_redundancy_mode", "rename_tag", "upsert_tag", "upsert_reference", "remove_tag_id", "disable_feature", "key_action", "key_expiry_seconds", "upsert_connection", "upsert_mapping", "upsert_export", "remove_mapping_id", "maintenance_mode", "acl_permissions"];
"control_redundancy_mode", "rename_tag", "upsert_tag", "upsert_reference", "remove_tag_id", "disable_feature", "key_action", "key_expiry_seconds", "upsert_connection", "upsert_mapping", "upsert_export", "remove_mapping_id", "maintenance_mode", "acl_permissions", "bump_mapping_revision"];
if (root.ValueKind != JsonValueKind.Object || root.EnumerateObject().Any(property => !allowedFields.Contains(property.Name, StringComparer.Ordinal)))
throw new InvalidOperationException("unknown fixture mutation field");
await using var db = await factory.CreateDbContextAsync();
@@ -223,6 +223,13 @@ try
if (existing is null) db.DataExports.Add(candidate);
else { candidate.DataExportRowId = existing.DataExportRowId; db.Entry(existing).CurrentValues.SetValues(candidate); }
}
if (root.TryGetProperty("bump_mapping_revision", out var bumpMapping))
{
// A03: a consumer condition-stream reset against the SAME origin incarnation — a changed mapping revision restarts the
// connection's condition runner (new stream + complete snapshot, materialised conditions handed over).
var bumped = await db.RemoteNamespaceMappings.SingleAsync(x => x.RemoteNamespaceMappingId == bumpMapping.GetString());
bumped.Revision++;
}
if (root.TryGetProperty("remove_mapping_id", out var removeMapping))
await db.RemoteNamespaceMappings.Where(x => x.RemoteNamespaceMappingId == removeMapping.GetString()).ExecuteDeleteAsync();
var connectionId = root.TryGetProperty("connection_id", out var selected) ? selected.GetString() : "consumer-source";
@@ -463,6 +470,10 @@ try
db.NodeAcls.Add(new() { NodeAclRowId = Guid.NewGuid(), NodeAclId = "source-peer-unsonly", ClusterId = "SOURCE", Principal = "fixture-unsonly",
ScopeKind = NodeAclScopeKind.Cluster, PermissionFlags = NodePermissions.Admin });
// A05: the CONSUMER-local principal `fixture-cli-nogrant` deliberately has NO NodeAcl row (no mapping grant).
// A06: a SECOND granted CONSUMER principal, so the two consumer pair members can be watched under different
// principals (the imported ConditionId must not depend on who asks).
db.NodeAcls.Add(new() { NodeAclRowId = Guid.NewGuid(), NodeAclId = "cli-alt-CONSUMER", ClusterId = "CONSUMER", Principal = "fixture-cli-alt",
ScopeKind = NodeAclScopeKind.Cluster, PermissionFlags = NodePermissions.Admin });
}
if (history)
// The second principal's origin ACL also lacks HistoryRead: with its export's HistoryRead off the RPC is refused
@@ -478,6 +489,7 @@ try
{
await SaveText("source-unsonly.key", await seedAdmin.CreateAsync("source-issued-unsonly", "fixture-unsonly", null, "SOURCE UNS-only export (A04)", default));
await SaveText("cli-nogrant.key", await seedAdmin.CreateAsync("fixture-cli-nogrant", "fixture-cli-nogrant", null, "CONSUMER principal without a mapping grant (A05)", default));
await SaveText("cli-alt.key", await seedAdmin.CreateAsync("fixture-cli-alt", "fixture-cli-alt", null, "second granted CONSUMER principal (A06)", default));
}
if (history)
await SaveText("source-nohistory.key", await seedAdmin.CreateAsync("source-issued-nohistory", "fixture-nohistory", null, "SOURCE export without HistoryRead", default));