Przeglądaj źródła

Record inputs for incosistent makeProfile calls

This commit adds the ability to record inputs for makeProfile calls
when the JS and Swift implementations are inconsistant. These inputs
are used as part of our replay system for debugging the oref Swift
implementation.
Sam King 4 miesięcy temu
rodzic
commit
f9246f3df6

+ 12 - 0
Trio/Resources/InfoPlist.xcstrings

@@ -457,6 +457,18 @@
         }
         }
       }
       }
     },
     },
+    "NSCalendarsFullAccessUsageDescription" : {
+      "comment" : "Privacy - Calendars Full Access Usage Description",
+      "extractionState" : "extracted_with_value",
+      "localizations" : {
+        "en" : {
+          "stringUnit" : {
+            "state" : "new",
+            "value" : "To create events with BG reading values, so that they can be viewed on Apple Watch and CarPlay"
+          }
+        }
+      }
+    },
     "NSCalendarsUsageDescription" : {
     "NSCalendarsUsageDescription" : {
       "comment" : "Privacy - Calendars Usage Description",
       "comment" : "Privacy - Calendars Usage Description",
       "extractionState" : "extracted_with_value",
       "extractionState" : "extracted_with_value",

+ 12 - 6
Trio/Sources/APS/OpenAPS/OpenAPS.swift

@@ -570,6 +570,7 @@ final class OpenAPS {
             }
             }
         }
         }
 
 
+        let clock = Date()
         do {
         do {
             let pumpProfile = try await makeProfile(
             let pumpProfile = try await makeProfile(
                 preferences: adjustedPreferences,
                 preferences: adjustedPreferences,
@@ -582,7 +583,8 @@ final class OpenAPS {
                 model: model,
                 model: model,
                 autotune: RawJSON.null,
                 autotune: RawJSON.null,
                 trioSettings: trioSettings,
                 trioSettings: trioSettings,
-                useSwiftOref: useSwiftOref
+                useSwiftOref: useSwiftOref,
+                clock: clock
             )
             )
 
 
             let profile = try await makeProfile(
             let profile = try await makeProfile(
@@ -596,7 +598,8 @@ final class OpenAPS {
                 model: model,
                 model: model,
                 autotune: RawJSON.null,
                 autotune: RawJSON.null,
                 trioSettings: trioSettings,
                 trioSettings: trioSettings,
-                useSwiftOref: useSwiftOref
+                useSwiftOref: useSwiftOref,
+                clock: clock
             )
             )
 
 
             // Save the profiles
             // Save the profiles
@@ -1026,7 +1029,8 @@ final class OpenAPS {
         model: JSON,
         model: JSON,
         autotune: JSON,
         autotune: JSON,
         trioSettings: JSON,
         trioSettings: JSON,
-        useSwiftOref: Bool
+        useSwiftOref: Bool,
+        clock: Date
     ) async throws -> RawJSON {
     ) async throws -> RawJSON {
         let startJavascriptAt = Date()
         let startJavascriptAt = Date()
         let jsResult = await makeProfileJavascript(
         let jsResult = await makeProfileJavascript(
@@ -1050,7 +1054,7 @@ final class OpenAPS {
         }
         }
 
 
         let startSwiftAt = Date()
         let startSwiftAt = Date()
-        let swiftResult = OpenAPSSwift.makeProfile(
+        let (swiftResult, makeProfileInputs) = OpenAPSSwift.makeProfile(
             preferences: preferences,
             preferences: preferences,
             pumpSettings: pumpSettings,
             pumpSettings: pumpSettings,
             bgTargets: bgTargets,
             bgTargets: bgTargets,
@@ -1059,7 +1063,8 @@ final class OpenAPS {
             carbRatio: carbRatio,
             carbRatio: carbRatio,
             tempTargets: tempTargets,
             tempTargets: tempTargets,
             model: model,
             model: model,
-            trioSettings: trioSettings
+            trioSettings: trioSettings,
+            clock: clock
         )
         )
         let swiftDuration = Date().timeIntervalSince(startSwiftAt)
         let swiftDuration = Date().timeIntervalSince(startSwiftAt)
 
 
@@ -1068,7 +1073,8 @@ final class OpenAPS {
             swift: swiftResult,
             swift: swiftResult,
             swiftDuration: swiftDuration,
             swiftDuration: swiftDuration,
             javascript: jsResult,
             javascript: jsResult,
-            javascriptDuration: javascriptDuration
+            javascriptDuration: javascriptDuration,
+            makeProfileInputs: makeProfileInputs
         )
         )
 
 
         return try jsResult.returnOrThrow()
         return try jsResult.returnOrThrow()

+ 17 - 0
Trio/Sources/APS/OpenAPSSwift/Logging/AlgorithmComparison.swift

@@ -109,6 +109,20 @@ struct DetermineBasalInputs: Codable {
     let clock: Date
     let clock: Date
 }
 }
 
 
+/// For tracking inputs to `makeProfile` when there is a mismatch
+struct MakeProfileInputs: Codable {
+    let preferences: Preferences
+    let pumpSettings: PumpSettings
+    let bgTargets: BGTargets
+    let basalProfile: [BasalProfileEntry]
+    let isf: InsulinSensitivities
+    let carbRatios: CarbRatios
+    let tempTargets: [TempTarget]
+    let model: String
+    let trioSettings: TrioSettings
+    let clock: Date
+}
+
 /// Represents a complete comparison between JS and Swift implementations
 /// Represents a complete comparison between JS and Swift implementations
 struct AlgorithmComparison: Codable {
 struct AlgorithmComparison: Codable {
     let id: UUID
     let id: UUID
@@ -137,6 +151,7 @@ struct AlgorithmComparison: Codable {
     let mealInput: MealInputs?
     let mealInput: MealInputs?
     let autosensInput: AutosensInputs?
     let autosensInput: AutosensInputs?
     let determineBasalInput: DetermineBasalInputs?
     let determineBasalInput: DetermineBasalInputs?
+    let makeProfileInput: MakeProfileInputs?
 
 
     init(
     init(
         function: OrefFunction,
         function: OrefFunction,
@@ -151,6 +166,7 @@ struct AlgorithmComparison: Codable {
         mealInputs: MealInputs? = nil,
         mealInputs: MealInputs? = nil,
         autosensInputs: AutosensInputs? = nil,
         autosensInputs: AutosensInputs? = nil,
         determineBasalInputs: DetermineBasalInputs? = nil,
         determineBasalInputs: DetermineBasalInputs? = nil,
+        makeProfileInputs: MakeProfileInputs? = nil,
         id: UUID = UUID(),
         id: UUID = UUID(),
         createdAt: Date = Date()
         createdAt: Date = Date()
     ) {
     ) {
@@ -168,6 +184,7 @@ struct AlgorithmComparison: Codable {
         mealInput = mealInputs
         mealInput = mealInputs
         autosensInput = autosensInputs
         autosensInput = autosensInputs
         determineBasalInput = determineBasalInputs
         determineBasalInput = determineBasalInputs
+        makeProfileInput = makeProfileInputs
         timezone = TimeZone.current.identifier
         timezone = TimeZone.current.identifier
         version = "4"
         version = "4"
         #if targetEnvironment(simulator)
         #if targetEnvironment(simulator)

+ 14 - 7
Trio/Sources/APS/OpenAPSSwift/Logging/JSONCompare.swift

@@ -87,7 +87,8 @@ enum JSONCompare {
         iobInputs: IobInputs? = nil,
         iobInputs: IobInputs? = nil,
         mealInputs: MealInputs? = nil,
         mealInputs: MealInputs? = nil,
         autosensInputs: AutosensInputs? = nil,
         autosensInputs: AutosensInputs? = nil,
-        determineBasalInputs: DetermineBasalInputs? = nil
+        determineBasalInputs: DetermineBasalInputs? = nil,
+        makeProfileInputs: MakeProfileInputs? = nil
     ) {
     ) {
         let comparison = createComparison(
         let comparison = createComparison(
             function: function,
             function: function,
@@ -98,7 +99,8 @@ enum JSONCompare {
             iobInputs: iobInputs,
             iobInputs: iobInputs,
             mealInputs: mealInputs,
             mealInputs: mealInputs,
             autosensInputs: autosensInputs,
             autosensInputs: autosensInputs,
-            determineBasalInputs: determineBasalInputs
+            determineBasalInputs: determineBasalInputs,
+            makeProfileInputs: makeProfileInputs
         )
         )
 
 
         Task {
         Task {
@@ -119,7 +121,8 @@ enum JSONCompare {
         iobInputs: IobInputs?,
         iobInputs: IobInputs?,
         mealInputs: MealInputs?,
         mealInputs: MealInputs?,
         autosensInputs: AutosensInputs?,
         autosensInputs: AutosensInputs?,
-        determineBasalInputs: DetermineBasalInputs?
+        determineBasalInputs: DetermineBasalInputs?,
+        makeProfileInputs: MakeProfileInputs?
     ) -> AlgorithmComparison {
     ) -> AlgorithmComparison {
         switch (swift, javascript) {
         switch (swift, javascript) {
         case let (.success(swiftJson), .success(javascriptJson)):
         case let (.success(swiftJson), .success(javascriptJson)):
@@ -135,7 +138,8 @@ enum JSONCompare {
                     iobInputs: differences.isEmpty ? nil : iobInputs,
                     iobInputs: differences.isEmpty ? nil : iobInputs,
                     mealInputs: differences.isEmpty ? nil : mealInputs,
                     mealInputs: differences.isEmpty ? nil : mealInputs,
                     autosensInputs: differences.isEmpty ? nil : autosensInputs,
                     autosensInputs: differences.isEmpty ? nil : autosensInputs,
-                    determineBasalInputs: differences.isEmpty ? nil : determineBasalInputs
+                    determineBasalInputs: differences.isEmpty ? nil : determineBasalInputs,
+                    makeProfileInputs: differences.isEmpty ? nil : makeProfileInputs
                 )
                 )
             } catch {
             } catch {
                 return AlgorithmComparison(
                 return AlgorithmComparison(
@@ -147,7 +151,8 @@ enum JSONCompare {
                     iobInputs: iobInputs,
                     iobInputs: iobInputs,
                     mealInputs: mealInputs,
                     mealInputs: mealInputs,
                     autosensInputs: autosensInputs,
                     autosensInputs: autosensInputs,
-                    determineBasalInputs: determineBasalInputs
+                    determineBasalInputs: determineBasalInputs,
+                    makeProfileInputs: makeProfileInputs
                 )
                 )
             }
             }
 
 
@@ -168,7 +173,8 @@ enum JSONCompare {
                 iobInputs: iobInputs,
                 iobInputs: iobInputs,
                 mealInputs: mealInputs,
                 mealInputs: mealInputs,
                 autosensInputs: autosensInputs,
                 autosensInputs: autosensInputs,
-                determineBasalInputs: determineBasalInputs
+                determineBasalInputs: determineBasalInputs,
+                makeProfileInputs: makeProfileInputs
             )
             )
 
 
         case let (.success, .failure(jsError)):
         case let (.success, .failure(jsError)):
@@ -180,7 +186,8 @@ enum JSONCompare {
                 iobInputs: iobInputs,
                 iobInputs: iobInputs,
                 mealInputs: mealInputs,
                 mealInputs: mealInputs,
                 autosensInputs: autosensInputs,
                 autosensInputs: autosensInputs,
-                determineBasalInputs: determineBasalInputs
+                determineBasalInputs: determineBasalInputs,
+                makeProfileInputs: makeProfileInputs
             )
             )
         }
         }
     }
     }

+ 21 - 5
Trio/Sources/APS/OpenAPSSwift/OpenAPSSwift.swift

@@ -10,8 +10,11 @@ struct OpenAPSSwift {
         carbRatio: JSON,
         carbRatio: JSON,
         tempTargets: JSON,
         tempTargets: JSON,
         model: JSON,
         model: JSON,
-        trioSettings: JSON
-    ) -> OrefFunctionResult {
+        trioSettings: JSON,
+        clock: Date
+    ) -> (OrefFunctionResult, MakeProfileInputs?) {
+        var makeProfileInputs: MakeProfileInputs?
+
         do {
         do {
             let preferences = try JSONBridge.preferences(from: preferences)
             let preferences = try JSONBridge.preferences(from: preferences)
             let pumpSettings = try JSONBridge.pumpSettings(from: pumpSettings)
             let pumpSettings = try JSONBridge.pumpSettings(from: pumpSettings)
@@ -23,6 +26,19 @@ struct OpenAPSSwift {
             let model = JSONBridge.model(from: model)
             let model = JSONBridge.model(from: model)
             let trioSettings = try JSONBridge.trioSettings(from: trioSettings)
             let trioSettings = try JSONBridge.trioSettings(from: trioSettings)
 
 
+            makeProfileInputs = MakeProfileInputs(
+                preferences: preferences,
+                pumpSettings: pumpSettings,
+                bgTargets: bgTargets,
+                basalProfile: basalProfile,
+                isf: isf,
+                carbRatios: carbRatio,
+                tempTargets: tempTargets,
+                model: model,
+                trioSettings: trioSettings,
+                clock: clock
+            )
+
             let profile = try ProfileGenerator.generate(
             let profile = try ProfileGenerator.generate(
                 pumpSettings: pumpSettings,
                 pumpSettings: pumpSettings,
                 bgTargets: bgTargets,
                 bgTargets: bgTargets,
@@ -32,12 +48,12 @@ struct OpenAPSSwift {
                 carbRatios: carbRatio,
                 carbRatios: carbRatio,
                 tempTargets: tempTargets,
                 tempTargets: tempTargets,
                 model: model,
                 model: model,
-                trioSettings: trioSettings
+                clock: clock
             )
             )
 
 
-            return try .success(JSONBridge.to(profile))
+            return (try .success(JSONBridge.to(profile)), makeProfileInputs)
         } catch {
         } catch {
-            return .failure(error)
+            return (.failure(error), makeProfileInputs)
         }
         }
     }
     }
 
 

+ 2 - 2
Trio/Sources/APS/OpenAPSSwift/Profile/Basal.swift

@@ -1,8 +1,8 @@
 import Foundation
 import Foundation
 
 
 struct Basal {
 struct Basal {
-    static func basalLookup(_ basalProfile: [BasalProfileEntry], now: Date? = nil) throws -> Decimal? {
-        let nowDate = now ?? Date()
+    static func basalLookup(_ basalProfile: [BasalProfileEntry], now: Date) throws -> Decimal? {
+        let nowDate = now
 
 
         // Original had a sort but it was a no-op if 'i' wasn't present, so we can skip it
         // Original had a sort but it was a no-op if 'i' wasn't present, so we can skip it
         let basalProfileData = basalProfile
         let basalProfileData = basalProfile

+ 1 - 1
Trio/Sources/APS/OpenAPSSwift/Profile/Carbs.swift

@@ -1,7 +1,7 @@
 import Foundation
 import Foundation
 
 
 struct Carbs {
 struct Carbs {
-    static func carbRatioLookup(carbRatio: CarbRatios, now: Date = Date()) -> Decimal? {
+    static func carbRatioLookup(carbRatio: CarbRatios, now: Date) -> Decimal? {
         // Get last schedule as default
         // Get last schedule as default
         guard let lastSchedule = carbRatio.schedule.last else { return nil }
         guard let lastSchedule = carbRatio.schedule.last else { return nil }
         var currentRatio = lastSchedule.ratio
         var currentRatio = lastSchedule.ratio

+ 2 - 2
Trio/Sources/APS/OpenAPSSwift/Profile/Isf.swift

@@ -4,9 +4,9 @@ import Foundation
 struct Isf {
 struct Isf {
     static func isfLookup(
     static func isfLookup(
         isfDataInput: InsulinSensitivities,
         isfDataInput: InsulinSensitivities,
-        timestamp: Date? = nil
+        timestamp: Date
     ) throws -> (Decimal, ComputedInsulinSensitivities) {
     ) throws -> (Decimal, ComputedInsulinSensitivities) {
-        let now = timestamp ?? Date()
+        let now = timestamp
 
 
         let isfData = isfDataInput.computedInsulinSensitivies()
         let isfData = isfDataInput.computedInsulinSensitivies()
 
 

+ 12 - 9
Trio/Sources/APS/OpenAPSSwift/Profile/ProfileGenerator.swift

@@ -74,7 +74,7 @@ enum ProfileGenerator {
         carbRatios: CarbRatios,
         carbRatios: CarbRatios,
         tempTargets: [TempTarget],
         tempTargets: [TempTarget],
         model: String,
         model: String,
-        trioSettings _: TrioSettings
+        clock: Date
     ) throws -> Profile {
     ) throws -> Profile {
         let model = model.replacingOccurrences(of: "\"", with: "").trimmingCharacters(in: .whitespacesAndNewlines)
         let model = model.replacingOccurrences(of: "\"", with: "").trimmingCharacters(in: .whitespacesAndNewlines)
 
 
@@ -97,7 +97,7 @@ enum ProfileGenerator {
             debug(.openAPS, "don't modify insulin peak time")
             debug(.openAPS, "don't modify insulin peak time")
         }
         }
 
 
-        return try generate(
+        return try generateProfile(
             pumpSettings: pumpSettings,
             pumpSettings: pumpSettings,
             bgTargets: bgTargets,
             bgTargets: bgTargets,
             basalProfile: basalProfile,
             basalProfile: basalProfile,
@@ -105,12 +105,13 @@ enum ProfileGenerator {
             preferences: preferences,
             preferences: preferences,
             carbRatios: carbRatios,
             carbRatios: carbRatios,
             tempTargets: tempTargets,
             tempTargets: tempTargets,
-            model: model
+            model: model,
+            clock: clock
         )
         )
     }
     }
 
 
     /// Direct port of the OpenAPS profile generate function
     /// Direct port of the OpenAPS profile generate function
-    private static func generate(
+    private static func generateProfile(
         pumpSettings: PumpSettings,
         pumpSettings: PumpSettings,
         bgTargets: BGTargets,
         bgTargets: BGTargets,
         basalProfile: [BasalProfileEntry],
         basalProfile: [BasalProfileEntry],
@@ -118,7 +119,8 @@ enum ProfileGenerator {
         preferences: Preferences,
         preferences: Preferences,
         carbRatios: CarbRatios,
         carbRatios: CarbRatios,
         tempTargets: [TempTarget],
         tempTargets: [TempTarget],
-        model: String
+        model: String,
+        clock: Date
     ) throws -> Profile {
     ) throws -> Profile {
         var profile = Profile() // start with the defaults
         var profile = Profile() // start with the defaults
 
 
@@ -138,7 +140,7 @@ enum ProfileGenerator {
         profile.model = model
         profile.model = model
         profile.skipNeutralTemps = preferences.skipNeutralTemps
         profile.skipNeutralTemps = preferences.skipNeutralTemps
 
 
-        profile.currentBasal = try Basal.basalLookup(basalProfile)
+        profile.currentBasal = try Basal.basalLookup(basalProfile, now: clock)
         profile.basalprofile = basalProfile
         profile.basalprofile = basalProfile
 
 
         let basalProfile = basalProfile
         let basalProfile = basalProfile
@@ -169,7 +171,8 @@ enum ProfileGenerator {
         }
         }
 
 
         profile.outUnits = bgTargets.userPreferredUnits
         profile.outUnits = bgTargets.userPreferredUnits
-        let (updatedTargets, range) = try Targets.bgTargetsLookup(targets: bgTargets, tempTargets: tempTargets, profile: profile)
+        let (updatedTargets, range) = try Targets
+            .bgTargetsLookup(targets: bgTargets, tempTargets: tempTargets, profile: profile, now: clock)
         profile.minBg = range.minBg?.rounded()
         profile.minBg = range.minBg?.rounded()
         profile.maxBg = range.maxBg?.rounded()
         profile.maxBg = range.maxBg?.rounded()
         // Note: we're using updatedTargets here because in Javascript the bgTargetsLookup
         // Note: we're using updatedTargets here because in Javascript the bgTargetsLookup
@@ -195,7 +198,7 @@ enum ProfileGenerator {
         )
         )
 
 
         profile.temptargetSet = range.temptargetSet
         profile.temptargetSet = range.temptargetSet
-        let (sens, isfUpdated) = try Isf.isfLookup(isfDataInput: isf)
+        let (sens, isfUpdated) = try Isf.isfLookup(isfDataInput: isf, timestamp: clock)
         profile.sens = sens
         profile.sens = sens
         profile.isfProfile = isfUpdated
         profile.isfProfile = isfUpdated
 
 
@@ -208,7 +211,7 @@ enum ProfileGenerator {
         }
         }
 
 
         // Handle carb ratio data
         // Handle carb ratio data
-        guard let currentCarbRatio = Carbs.carbRatioLookup(carbRatio: carbRatios) else {
+        guard let currentCarbRatio = Carbs.carbRatioLookup(carbRatio: carbRatios, now: clock) else {
             throw ProfileError.invalidCarbRatio
             throw ProfileError.invalidCarbRatio
         }
         }
         profile.carbRatio = currentCarbRatio
         profile.carbRatio = currentCarbRatio

+ 1 - 1
Trio/Sources/APS/OpenAPSSwift/Profile/Targets.swift

@@ -84,7 +84,7 @@ struct Targets {
         targets: BGTargets,
         targets: BGTargets,
         tempTargets: [TempTarget],
         tempTargets: [TempTarget],
         profile: Profile,
         profile: Profile,
-        now: Date = Date()
+        now: Date
     ) throws -> (ComputedBGTargets, ComputedBGTargetEntry) {
     ) throws -> (ComputedBGTargets, ComputedBGTargetEntry) {
         var (computedBgTargets, targetIdx) = try lookup(targets: targets, tempTargets: tempTargets, profile: profile, now: now)
         var (computedBgTargets, targetIdx) = try lookup(targets: targets, tempTargets: tempTargets, profile: profile, now: now)
         let currentTarget = boundTargetRange(computedBgTargets.targets[targetIdx])
         let currentTarget = boundTargetRange(computedBgTargets.targets[targetIdx])

+ 0 - 1
Trio/Sources/Localizations/Main/Localizable.xcstrings

@@ -10037,7 +10037,6 @@
       }
       }
     },
     },
     "%lld h" : {
     "%lld h" : {
-      "extractionState" : "stale",
       "localizations" : {
       "localizations" : {
         "bg" : {
         "bg" : {
           "stringUnit" : {
           "stringUnit" : {

+ 2 - 1
TrioTests/OpenAPSSwiftTests/AutosensJsonTests.swift

@@ -38,7 +38,8 @@ import Testing
             iobInputs: nil,
             iobInputs: nil,
             mealInputs: nil,
             mealInputs: nil,
             autosensInputs: nil,
             autosensInputs: nil,
-            determineBasalInputs: nil
+            determineBasalInputs: nil,
+            makeProfileInputs: nil
         )
         )
 
 
         if comparison.resultType == .valueDifference {
         if comparison.resultType == .valueDifference {

+ 4 - 2
TrioTests/OpenAPSSwiftTests/DetermineBasalJsonTests.swift

@@ -82,7 +82,8 @@ import Testing
             iobInputs: nil,
             iobInputs: nil,
             mealInputs: nil,
             mealInputs: nil,
             autosensInputs: nil,
             autosensInputs: nil,
-            determineBasalInputs: nil
+            determineBasalInputs: nil,
+            makeProfileInputs: nil
         )
         )
 
 
         if comparison.resultType == .valueDifference {
         if comparison.resultType == .valueDifference {
@@ -173,7 +174,8 @@ import Testing
             iobInputs: nil,
             iobInputs: nil,
             mealInputs: nil,
             mealInputs: nil,
             autosensInputs: nil,
             autosensInputs: nil,
-            determineBasalInputs: nil
+            determineBasalInputs: nil,
+            makeProfileInputs: nil
         )
         )
 
 
         if comparison.resultType == .valueDifference {
         if comparison.resultType == .valueDifference {

+ 4 - 2
TrioTests/OpenAPSSwiftTests/IobJsonTests.swift

@@ -134,7 +134,8 @@ import Testing
             iobInputs: nil,
             iobInputs: nil,
             mealInputs: nil,
             mealInputs: nil,
             autosensInputs: nil,
             autosensInputs: nil,
-            determineBasalInputs: nil
+            determineBasalInputs: nil,
+            makeProfileInputs: nil
         )
         )
 
 
         if comparison.resultType == .valueDifference {
         if comparison.resultType == .valueDifference {
@@ -173,7 +174,8 @@ import Testing
             iobInputs: nil,
             iobInputs: nil,
             mealInputs: nil,
             mealInputs: nil,
             autosensInputs: nil,
             autosensInputs: nil,
-            determineBasalInputs: nil
+            determineBasalInputs: nil,
+            makeProfileInputs: nil
         )
         )
 
 
         if comparison.resultType != .valueDifference {
         if comparison.resultType != .valueDifference {

+ 4 - 2
TrioTests/OpenAPSSwiftTests/MealJsonTests.swift

@@ -78,7 +78,8 @@ import Testing
             iobInputs: nil,
             iobInputs: nil,
             mealInputs: nil,
             mealInputs: nil,
             autosensInputs: nil,
             autosensInputs: nil,
-            determineBasalInputs: nil
+            determineBasalInputs: nil,
+            makeProfileInputs: nil
         )
         )
 
 
         if comparison.resultType == .valueDifference {
         if comparison.resultType == .valueDifference {
@@ -155,7 +156,8 @@ import Testing
             iobInputs: nil,
             iobInputs: nil,
             mealInputs: nil,
             mealInputs: nil,
             autosensInputs: nil,
             autosensInputs: nil,
-            determineBasalInputs: nil
+            determineBasalInputs: nil,
+            makeProfileInputs: nil
         )
         )
 
 
         #expect(comparison.resultType == .matching)
         #expect(comparison.resultType == .matching)

+ 3 - 3
TrioTests/OpenAPSSwiftTests/ProfileBasalTests.swift

@@ -40,7 +40,7 @@ import Testing
     }
     }
 
 
     @Test("should return nil with an empty profile") func handleEmptyProfile() async throws {
     @Test("should return nil with an empty profile") func handleEmptyProfile() async throws {
-        let rate = try Basal.basalLookup([])
+        let rate = try Basal.basalLookup([], now: Date())
         #expect(rate == nil)
         #expect(rate == nil)
     }
     }
 
 
@@ -49,7 +49,7 @@ import Testing
             BasalProfileEntry(start: "00:00", minutes: 0, rate: 1.0)
             BasalProfileEntry(start: "00:00", minutes: 0, rate: 1.0)
         ]
         ]
 
 
-        let rate = try Basal.basalLookup(basalProfile)
+        let rate = try Basal.basalLookup(basalProfile, now: Date())
         #expect(rate == 1.0)
         #expect(rate == 1.0)
     }
     }
 
 
@@ -58,7 +58,7 @@ import Testing
             BasalProfileEntry(start: "00:00", minutes: 0, rate: 0.0)
             BasalProfileEntry(start: "00:00", minutes: 0, rate: 0.0)
         ]
         ]
 
 
-        let rate = try Basal.basalLookup(basalProfile)
+        let rate = try Basal.basalLookup(basalProfile, now: Date())
         #expect(rate == nil)
         #expect(rate == nil)
     }
     }
 
 

+ 1 - 1
TrioTests/OpenAPSSwiftTests/ProfileCarbsTests.swift

@@ -31,7 +31,7 @@ import Testing
                 CarbRatioEntry(start: "00:00:00", offset: 0, ratio: 12)
                 CarbRatioEntry(start: "00:00:00", offset: 0, ratio: 12)
             ]
             ]
         )
         )
-        let ratio = Carbs.carbRatioLookup(carbRatio: exchangeSchedule)
+        let ratio = Carbs.carbRatioLookup(carbRatio: exchangeSchedule, now: Date())
         #expect(ratio == 1) // 12 grams per exchange
         #expect(ratio == 1) // 12 grams per exchange
     }
     }
 
 

+ 1 - 1
TrioTests/OpenAPSSwiftTests/ProfileIsfTests.swift

@@ -56,7 +56,7 @@ import Testing
                 InsulinSensitivityEntry(sensitivity: 100, offset: 30, start: "00:30:00")
                 InsulinSensitivityEntry(sensitivity: 100, offset: 30, start: "00:30:00")
             ]
             ]
         )
         )
-        let (sensitivity, _) = try Isf.isfLookup(isfDataInput: invalidISF)
+        let (sensitivity, _) = try Isf.isfLookup(isfDataInput: invalidISF, timestamp: Date())
         #expect(sensitivity == -1)
         #expect(sensitivity == -1)
     }
     }
 }
 }

+ 12 - 10
TrioTests/OpenAPSSwiftTests/ProfileJavascriptTests.swift

@@ -69,7 +69,7 @@ struct ProfileGeneratorTests {
             carbRatios: inputs.5,
             carbRatios: inputs.5,
             tempTargets: inputs.6,
             tempTargets: inputs.6,
             model: inputs.7,
             model: inputs.7,
-            trioSettings: inputs.8
+            clock: Date()
         )
         )
 
 
         #expect(profile.maxIob == 0)
         #expect(profile.maxIob == 0)
@@ -112,7 +112,7 @@ struct ProfileGeneratorTests {
             carbRatios: inputs.5,
             carbRatios: inputs.5,
             tempTargets: inputs.6,
             tempTargets: inputs.6,
             model: inputs.7,
             model: inputs.7,
-            trioSettings: inputs.8
+            clock: currentTime
         )
         )
 
 
         #expect(profile.maxIob == 0)
         #expect(profile.maxIob == 0)
@@ -156,7 +156,7 @@ struct ProfileGeneratorTests {
             carbRatios: inputs.5,
             carbRatios: inputs.5,
             tempTargets: inputs.6,
             tempTargets: inputs.6,
             model: inputs.7,
             model: inputs.7,
-            trioSettings: inputs.8
+            clock: currentTime
         )
         )
 
 
         #expect(profile.maxIob == 0)
         #expect(profile.maxIob == 0)
@@ -199,7 +199,7 @@ struct ProfileGeneratorTests {
             carbRatios: inputs.5,
             carbRatios: inputs.5,
             tempTargets: inputs.6,
             tempTargets: inputs.6,
             model: inputs.7,
             model: inputs.7,
-            trioSettings: inputs.8
+            clock: currentTime
         )
         )
 
 
         #expect(profile.maxIob == 0)
         #expect(profile.maxIob == 0)
@@ -229,7 +229,7 @@ struct ProfileGeneratorTests {
                 carbRatios: inputs.5,
                 carbRatios: inputs.5,
                 tempTargets: inputs.6,
                 tempTargets: inputs.6,
                 model: inputs.7,
                 model: inputs.7,
-                trioSettings: inputs.8
+                clock: Date()
             )
             )
         }
         }
     }
     }
@@ -252,7 +252,7 @@ struct ProfileGeneratorTests {
                 carbRatios: inputs.5,
                 carbRatios: inputs.5,
                 tempTargets: inputs.6,
                 tempTargets: inputs.6,
                 model: inputs.7,
                 model: inputs.7,
-                trioSettings: inputs.8
+                clock: Date()
             )
             )
         }
         }
     }
     }
@@ -270,7 +270,7 @@ struct ProfileGeneratorTests {
             carbRatios: inputs.5,
             carbRatios: inputs.5,
             tempTargets: inputs.6,
             tempTargets: inputs.6,
             model: inputs.7,
             model: inputs.7,
-            trioSettings: inputs.8
+            clock: Date()
         )
         )
 
 
         #expect(profile.model == "554")
         #expect(profile.model == "554")
@@ -309,7 +309,7 @@ struct ProfileGeneratorTests {
             trioSettings: inputs.8
             trioSettings: inputs.8
         )
         )
 
 
-        let swiftResult = OpenAPSSwift.makeProfile(
+        let (swiftResult, makeProfileInputs) = OpenAPSSwift.makeProfile(
             preferences: inputs.4,
             preferences: inputs.4,
             pumpSettings: inputs.0,
             pumpSettings: inputs.0,
             bgTargets: inputs.1,
             bgTargets: inputs.1,
@@ -318,7 +318,8 @@ struct ProfileGeneratorTests {
             carbRatio: inputs.5,
             carbRatio: inputs.5,
             tempTargets: tempTargets,
             tempTargets: tempTargets,
             model: inputs.7,
             model: inputs.7,
-            trioSettings: inputs.8
+            trioSettings: inputs.8,
+            clock: now
         )
         )
 
 
         let comparison = JSONCompare.createComparison(
         let comparison = JSONCompare.createComparison(
@@ -330,7 +331,8 @@ struct ProfileGeneratorTests {
             iobInputs: nil,
             iobInputs: nil,
             mealInputs: nil,
             mealInputs: nil,
             autosensInputs: nil,
             autosensInputs: nil,
-            determineBasalInputs: nil
+            determineBasalInputs: nil,
+            makeProfileInputs: makeProfileInputs
         )
         )
 
 
         if comparison.resultType == .valueDifference {
         if comparison.resultType == .valueDifference {

+ 17 - 9
TrioTests/OpenAPSSwiftTests/ProfileJsNativeCompareTests.swift

@@ -77,7 +77,7 @@ import Testing
             trioSettings: inputs.8
             trioSettings: inputs.8
         )
         )
 
 
-        let profileSwift = OpenAPSSwift.makeProfile(
+        let (profileSwift, _) = OpenAPSSwift.makeProfile(
             preferences: inputs.0,
             preferences: inputs.0,
             pumpSettings: inputs.1,
             pumpSettings: inputs.1,
             bgTargets: inputs.2,
             bgTargets: inputs.2,
@@ -86,7 +86,8 @@ import Testing
             carbRatio: inputs.5,
             carbRatio: inputs.5,
             tempTargets: inputs.6,
             tempTargets: inputs.6,
             model: inputs.7,
             model: inputs.7,
-            trioSettings: inputs.8
+            trioSettings: inputs.8,
+            clock: Date()
         )
         )
 
 
         let comparison = JSONCompare.createComparison(
         let comparison = JSONCompare.createComparison(
@@ -98,7 +99,8 @@ import Testing
             iobInputs: nil,
             iobInputs: nil,
             mealInputs: nil,
             mealInputs: nil,
             autosensInputs: nil,
             autosensInputs: nil,
-            determineBasalInputs: nil
+            determineBasalInputs: nil,
+            makeProfileInputs: nil
         )
         )
 
 
         #expect(comparison.resultType == .matching)
         #expect(comparison.resultType == .matching)
@@ -131,7 +133,8 @@ import Testing
             iobInputs: nil,
             iobInputs: nil,
             mealInputs: nil,
             mealInputs: nil,
             autosensInputs: nil,
             autosensInputs: nil,
-            determineBasalInputs: nil
+            determineBasalInputs: nil,
+            makeProfileInputs: nil
         )
         )
 
 
         #expect(comparison.resultType == .matching)
         #expect(comparison.resultType == .matching)
@@ -153,7 +156,8 @@ import Testing
             iobInputs: nil,
             iobInputs: nil,
             mealInputs: nil,
             mealInputs: nil,
             autosensInputs: nil,
             autosensInputs: nil,
-            determineBasalInputs: nil
+            determineBasalInputs: nil,
+            makeProfileInputs: nil
         )
         )
 
 
         #expect(comparison.resultType == .valueDifference)
         #expect(comparison.resultType == .valueDifference)
@@ -177,7 +181,8 @@ import Testing
             iobInputs: nil,
             iobInputs: nil,
             mealInputs: nil,
             mealInputs: nil,
             autosensInputs: nil,
             autosensInputs: nil,
-            determineBasalInputs: nil
+            determineBasalInputs: nil,
+            makeProfileInputs: nil
         )
         )
 
 
         #expect(comparison.resultType == .matchingExceptions)
         #expect(comparison.resultType == .matchingExceptions)
@@ -198,7 +203,8 @@ import Testing
             iobInputs: nil,
             iobInputs: nil,
             mealInputs: nil,
             mealInputs: nil,
             autosensInputs: nil,
             autosensInputs: nil,
-            determineBasalInputs: nil
+            determineBasalInputs: nil,
+            makeProfileInputs: nil
         )
         )
 
 
         #expect(comparison.resultType == .swiftOnlyException)
         #expect(comparison.resultType == .swiftOnlyException)
@@ -221,7 +227,8 @@ import Testing
             iobInputs: nil,
             iobInputs: nil,
             mealInputs: nil,
             mealInputs: nil,
             autosensInputs: nil,
             autosensInputs: nil,
-            determineBasalInputs: nil
+            determineBasalInputs: nil,
+            makeProfileInputs: nil
         )
         )
 
 
         #expect(comparison.resultType == .jsOnlyException)
         #expect(comparison.resultType == .jsOnlyException)
@@ -243,7 +250,8 @@ import Testing
             iobInputs: nil,
             iobInputs: nil,
             mealInputs: nil,
             mealInputs: nil,
             autosensInputs: nil,
             autosensInputs: nil,
-            determineBasalInputs: nil
+            determineBasalInputs: nil,
+            makeProfileInputs: nil
         )
         )
 
 
         #expect(comparison.resultType == .comparisonError)
         #expect(comparison.resultType == .comparisonError)

+ 1 - 1
TrioTests/OpenAPSSwiftTests/ProfileTargetsTests.swift

@@ -95,7 +95,7 @@ import Testing
                 BGTargetEntry(low: 40, high: 250, start: "00:00:00", offset: 0)
                 BGTargetEntry(low: 40, high: 250, start: "00:00:00", offset: 0)
             ]
             ]
         )
         )
-        let (_, result) = try Targets.bgTargetsLookup(targets: extremeTargets, tempTargets: [], profile: profile)
+        let (_, result) = try Targets.bgTargetsLookup(targets: extremeTargets, tempTargets: [], profile: profile, now: Date())
         #expect(result.maxBg == 80)
         #expect(result.maxBg == 80)
         #expect(result.minBg == 80)
         #expect(result.minBg == 80)
     }
     }