|
| 1 | +// CrossTabMessageConsistencyTests.swift |
| 2 | +// ThumpTests |
| 3 | +// |
| 4 | +// Regression coverage for contradictory guidance across Dashboard and Stress |
| 5 | +// surfaces. These tests protect against "push hard" messaging when readiness |
| 6 | +// is still low due to poor sleep or recovery debt. |
| 7 | + |
| 8 | +import XCTest |
| 9 | +@testable import Thump |
| 10 | + |
| 11 | +final class CrossTabMessageConsistencyTests: XCTestCase { |
| 12 | + |
| 13 | + func testStressGuidance_relaxedButRecoveringReadiness_avoidsPerformanceActions() { |
| 14 | + let spec = AdvicePresenter.stressGuidance(for: .relaxed, readinessLevel: .recovering) |
| 15 | + |
| 16 | + XCTAssertFalse(spec.actions.contains("Workout"), "Recovering readiness should not promote hard workouts.") |
| 17 | + XCTAssertFalse(spec.actions.contains("Focus Time"), "Recovering readiness should avoid high-cognitive push framing.") |
| 18 | + XCTAssertTrue(spec.actions.contains("Rest"), "Recovering readiness should include recovery actions.") |
| 19 | + XCTAssertTrue(spec.actions.contains("Take a Walk"), "Recovering readiness should include low-intensity movement.") |
| 20 | + } |
| 21 | + |
| 22 | + func testStressGuidance_relaxedAndReady_keepsPerformanceActions() { |
| 23 | + let spec = AdvicePresenter.stressGuidance(for: .relaxed, readinessLevel: .ready) |
| 24 | + |
| 25 | + XCTAssertTrue(spec.actions.contains("Workout"), "Ready state should still allow performance-oriented actions.") |
| 26 | + XCTAssertTrue(spec.actions.contains("Focus Time"), "Ready state should preserve focus-window coaching.") |
| 27 | + } |
| 28 | + |
| 29 | + func testPoorSleepDashboardAndStressGuidance_areAligned() { |
| 30 | + let snapshot = HeartSnapshot( |
| 31 | + date: Date(), |
| 32 | + restingHeartRate: 62, |
| 33 | + hrvSDNN: 56, |
| 34 | + recoveryHR1m: 24, |
| 35 | + sleepHours: 4.7 |
| 36 | + ) |
| 37 | + let state = makeRecoveryAdviceState(stressGuidanceLevel: .relaxed) |
| 38 | + |
| 39 | + let dashboardText = AdvicePresenter.checkRecommendation( |
| 40 | + for: state, |
| 41 | + readinessScore: 42, |
| 42 | + snapshot: snapshot |
| 43 | + ).lowercased() |
| 44 | + let stressSpec = AdvicePresenter.stressGuidance(for: .relaxed, readinessLevel: .recovering) |
| 45 | + |
| 46 | + let recoverySignals = [ |
| 47 | + "skip structured training", |
| 48 | + "easy walk", |
| 49 | + "save harder sessions", |
| 50 | + "keep it light", |
| 51 | + "rest" |
| 52 | + ] |
| 53 | + |
| 54 | + XCTAssertTrue( |
| 55 | + recoverySignals.contains(where: { dashboardText.contains($0) }), |
| 56 | + "Low-readiness + poor-sleep dashboard guidance should clearly bias recovery." |
| 57 | + ) |
| 58 | + XCTAssertFalse( |
| 59 | + dashboardText.contains("push hard") || dashboardText.contains("high-intensity"), |
| 60 | + "Low-readiness + poor-sleep dashboard guidance should avoid hard-intensity wording." |
| 61 | + ) |
| 62 | + XCTAssertFalse(stressSpec.actions.contains("Workout")) |
| 63 | + XCTAssertFalse(stressSpec.actions.contains("Focus Time")) |
| 64 | + } |
| 65 | + |
| 66 | + private func makeRecoveryAdviceState(stressGuidanceLevel: StressGuidanceLevel?) -> AdviceState { |
| 67 | + AdviceState( |
| 68 | + mode: .lightRecovery, |
| 69 | + riskBand: .elevated, |
| 70 | + overtrainingState: .none, |
| 71 | + sleepDeprivationFlag: true, |
| 72 | + medicalEscalationFlag: false, |
| 73 | + heroCategory: .caution, |
| 74 | + heroMessageID: "hero_rough_night", |
| 75 | + buddyMoodCategory: .resting, |
| 76 | + focusInsightID: "insight_rough_night", |
| 77 | + checkBadgeID: "badge_recover", |
| 78 | + goals: [], |
| 79 | + recoveryDriver: .lowSleep, |
| 80 | + stressGuidanceLevel: stressGuidanceLevel, |
| 81 | + smartActions: [], |
| 82 | + allowedIntensity: .light, |
| 83 | + nudgePriorities: [.rest, .walk], |
| 84 | + positivityAnchorID: nil, |
| 85 | + dailyActionBudget: 3 |
| 86 | + ) |
| 87 | + } |
| 88 | +} |
0 commit comments