milestone 19 &20
Build and verify web migration / verify (push) Waiting to run

This commit is contained in:
wolf-demon
2026-09-29 20:50:40 +01:00
parent 2e8cf269fb
commit 4dd33c90e1
10 changed files with 492 additions and 2 deletions
+78
View File
@@ -0,0 +1,78 @@
import importlib.util
from pathlib import Path
import unittest
spec = importlib.util.spec_from_file_location("incident_exercise", Path(__file__).resolve().parents[1] / "deploy" / "incident_exercise.py")
exercise = importlib.util.module_from_spec(spec)
spec.loader.exec_module(exercise)
def valid_record(gate="B"):
required = exercise.GATE_C_SCENARIOS if gate == "C" else exercise.GATE_B_SCENARIOS
return {
"schemaVersion": 1,
"system": "guestops-incident-exercise",
"targetGate": gate,
"dataClassification": "synthetic-only",
"releaseCommit": "a" * 40,
"releaseRecordSha256": "b" * 64,
"environment": "https://sandbox-guestops.futuresens.co.uk",
"operator": "Exercise operator",
"incidentCommander": "Incident commander",
"reviewedBy": "Independent reviewer",
"startedAt": "2026-09-29T09:00:00Z",
"endedAt": "2026-09-29T10:00:00Z",
"reviewedAt": "2026-09-29T11:00:00Z",
"targetsMinutes": {"detection": 10, "containment": 20, "recovery": 60},
"observedMinutes": {"detection": 5, "containment": 15, "recovery": 45},
"scenarios": [
{"id": scenario, "status": "pass", "evidence": [f"restricted-ticket-{index}"]}
for index, scenario in enumerate(sorted(required), 1)
],
"postExerciseState": {
"externalWrites": "disabled", "faqMode": "off", "unresolvedOperations": 0,
},
}
class IncidentExerciseTests(unittest.TestCase):
def test_gate_b_and_c_complete_records_pass(self):
exercise.validate(valid_record("B"))
exercise.validate(valid_record("C"))
def test_gate_specific_scenarios_are_required(self):
record = valid_record("C")
record["scenarios"].pop()
with self.assertRaisesRegex(ValueError, "exact incident scenario"):
exercise.validate(record)
def test_timings_must_meet_preagreed_targets(self):
record = valid_record()
record["observedMinutes"]["containment"] = 21
with self.assertRaisesRegex(ValueError, "Observed containment"):
exercise.validate(record)
record = valid_record()
record["targetsMinutes"]["recovery"] = True
with self.assertRaisesRegex(ValueError, "recovery target"):
exercise.validate(record)
def test_independent_people_and_safe_evidence_are_required(self):
record = valid_record()
record["reviewedBy"] = record["operator"]
with self.assertRaisesRegex(ValueError, "different people"):
exercise.validate(record)
record = valid_record()
record["scenarios"][0]["evidence"] = ["guest@example.invalid"]
with self.assertRaisesRegex(ValueError, "safe opaque"):
exercise.validate(record)
def test_safe_post_exercise_state_is_required(self):
record = valid_record()
record["postExerciseState"]["externalWrites"] = "enabled"
with self.assertRaisesRegex(ValueError, "writes disabled"):
exercise.validate(record)
if __name__ == "__main__":
unittest.main()
+70
View File
@@ -0,0 +1,70 @@
import importlib.util
from pathlib import Path
import unittest
spec = importlib.util.spec_from_file_location("pilot_approval", Path(__file__).resolve().parents[1] / "deploy" / "pilot_approval.py")
approval = importlib.util.module_from_spec(spec)
spec.loader.exec_module(approval)
def valid_record(gate="B"):
ids = approval.GATE_C if gate == "C" else approval.GATE_B
return {
"schemaVersion": 1, "targetGate": gate, "decision": "approved",
"releaseCommit": "a" * 40, "releaseRecordSha256": "b" * 64,
"decidedAt": "2026-09-29T12:00:00Z",
"approvals": {
"hotelOwner": {"name": "Hotel owner", "approvedAt": "2026-09-29T11:00:00Z"},
"technicalOwner": {"name": "Technical owner", "approvedAt": "2026-09-29T11:30:00Z"},
},
"capacity": {"reportSha256": "c" * 64, "targetConcurrency": 10, "observedConcurrency": 10, "targetP95Ms": 500, "observedP95Ms": 250, "targetErrorRate": 0.01, "observedErrorRate": 0},
"evidence": [{"id": item, "status": "pass", "references": ["restricted-ticket-" + item]} for item in sorted(ids)],
}
class PilotApprovalTests(unittest.TestCase):
def test_gate_b_and_c_complete_records_pass(self):
approval.validate(valid_record("B"))
approval.validate(valid_record("C"))
def test_pending_or_missing_evidence_fails(self):
record = valid_record();record["decision"] = "pending"
with self.assertRaisesRegex(ValueError, "explicit approved"):
approval.validate(record)
record = valid_record();record["evidence"].pop()
with self.assertRaisesRegex(ValueError, "exact evidence"):
approval.validate(record)
def test_capacity_must_meet_preapproved_targets(self):
record = valid_record();record["capacity"]["observedP95Ms"] = 501
with self.assertRaisesRegex(ValueError, "observedP95Ms"):
approval.validate(record)
record = valid_record();record["capacity"]["observedConcurrency"] = 9
with self.assertRaisesRegex(ValueError, "Observed concurrency"):
approval.validate(record)
record = valid_record();record["capacity"]["targetConcurrency"] = True
with self.assertRaisesRegex(ValueError, "Observed concurrency"):
approval.validate(record)
record = valid_record();record["capacity"]["targetErrorRate"] = 2
with self.assertRaisesRegex(ValueError, "ratio"):
approval.validate(record)
def test_approvers_must_be_separate_people_without_email_addresses(self):
record = valid_record();record["approvals"]["technicalOwner"]["name"] = "Hotel owner"
with self.assertRaisesRegex(ValueError, "different people"):
approval.validate(record)
record = valid_record();record["approvals"]["hotelOwner"]["name"] = "owner@example.invalid"
with self.assertRaisesRegex(ValueError, "without an email"):
approval.validate(record)
def test_containment_requires_owner_future_expiry_and_trigger(self):
record = valid_record();item = record["evidence"][0];item["status"] = "contained"
with self.assertRaisesRegex(ValueError, "containment details"):
approval.validate(record)
item["containment"] = {"owner": "Release owner", "expiresAt": "2026-10-10T12:00:00Z", "rollbackTrigger": "Rollback if the contained condition occurs."}
approval.validate(record)
if __name__ == "__main__":
unittest.main()