AlertCatalogRegistryOmniFaultTests.swift 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import Foundation
  2. import LoopKit
  3. import Testing
  4. @testable import Trio
  5. /// Pins `AlertCatalogRegistry.lookup` behavior for Omni pod-fault identifiers.
  6. /// `OmniPumpManager` builds `Alert.Identifier` from the formatted
  7. /// `FaultEventCode.description` string ("Fault Event Code 0xNN: ..."), so the
  8. /// registry has to parse the hex code out of that prefix at lookup time.
  9. @Suite("TrioAlert: CatalogRegistry — Omni pod-fault hex parser") struct AlertCatalogRegistryOmniFaultTests {
  10. private func omniFaultID(_ desc: String) -> Alert.Identifier {
  11. Alert.Identifier(managerIdentifier: "Omni:pumpFault", alertIdentifier: desc)
  12. }
  13. @Test("0x14 → occlusion concept, critical, Pod Occlusion title") func code0x14Occlusion() {
  14. let entry = AlertCatalogRegistry.lookup(omniFaultID("Fault Event Code 0x14: Occluded"))
  15. #expect(entry?.concept == .occlusion)
  16. #expect(entry?.interruptionLevel == .critical)
  17. #expect(entry?.title == "Pod Occlusion")
  18. }
  19. @Test("0x18 → reservoirEmpty concept, critical") func code0x18ReservoirEmpty() {
  20. let entry = AlertCatalogRegistry.lookup(omniFaultID("Fault Event Code 0x18: Reservoir empty"))
  21. #expect(entry?.concept == .reservoirEmpty)
  22. #expect(entry?.interruptionLevel == .critical)
  23. }
  24. @Test("0x1C → deviceExpired concept, timeSensitive") func code0x1CExpired() {
  25. let entry = AlertCatalogRegistry.lookup(
  26. omniFaultID("Fault Event Code 0x1c: Exceeded maximum Pod life of 80 hours")
  27. )
  28. #expect(entry?.concept == .deviceExpired)
  29. #expect(entry?.interruptionLevel == .timeSensitive)
  30. }
  31. @Test("Unmapped fault code falls back to generic hardwareFault") func unknownCodeFallback() {
  32. let entry = AlertCatalogRegistry.lookup(omniFaultID("Fault Event Code 0x42: Some internal fault"))
  33. #expect(entry?.concept == .hardwareFault)
  34. #expect(entry?.interruptionLevel == .critical)
  35. #expect(entry?.title == "Pod Fault")
  36. }
  37. @Test("Malformed hex (non-hex chars) falls back to hardwareFault") func malformedHex() {
  38. let entry = AlertCatalogRegistry.lookup(omniFaultID("Fault Event Code 0xZZ: garbled"))
  39. #expect(entry?.concept == .hardwareFault)
  40. }
  41. @Test("Truncated identifier still resolves to hardwareFault") func truncatedIdentifier() {
  42. let entry = AlertCatalogRegistry.lookup(omniFaultID("Fault Event Code 0x"))
  43. #expect(entry?.concept == .hardwareFault)
  44. }
  45. @Test("Non-Omni managerIdentifier is ignored by the fault parser") func wrongManagerIgnored() {
  46. let id = Alert.Identifier(managerIdentifier: "Dana", alertIdentifier: "Fault Event Code 0x14: Occluded")
  47. // Dana doesn't carry this slug in the catalog, so lookup is nil even
  48. // though the alert text matches the Omni pattern.
  49. #expect(AlertCatalogRegistry.lookup(id) == nil)
  50. }
  51. }