Restructure into a three-tab app with Progress, goals, and Meditation
The UX redesign's first landing (spec in UX-REDESIGN.md): ContentView becomes a Today / Progress / Settings TabView, "Routine" replaces "Split" in every user-facing string and view name (code-level types keep their names), and workout starting moves to shared WorkoutStarter / StartedWorkoutNavigator plumbing. - New Progress tab: weekly goal streaks, workout trends, per-exercise weight progression, achievements, and the full history list (WorkoutLogsView -> WorkoutHistoryView). - Goals: stable categories workouts roll up to, managed from Settings. - New Meditation exercise + starter routine; timed sits record to Apple Health as Mind & Body sessions. Claude-Session: https://claude.ai/code/session_012qw2itfzKyEJ1HpsFt8Ex4
This commit is contained in:
@@ -3,7 +3,7 @@ import Testing
|
||||
@testable import Workouts
|
||||
|
||||
/// Locks the survivor rules of `DuplicateCleanupPlanner` — the safety-critical
|
||||
/// part of the developer duplicate-cleanup tool. Referenced-split and seed
|
||||
/// part of the developer duplicate-cleanup tool. Referenced-routine and seed
|
||||
/// protection must always beat "earliest ULID wins," an in-progress workout must
|
||||
/// never be touched, and the HealthKit-link holder must always survive (deleting
|
||||
/// it would cascade-delete the real Health sample). Fixed 26-char ULID-like ids
|
||||
@@ -26,12 +26,12 @@ struct DuplicateCleanupPlannerTests {
|
||||
)
|
||||
}
|
||||
|
||||
private func split(
|
||||
id splitID: String, name: String = "Push Day", exercises: [ExerciseDocument]? = nil,
|
||||
private func routine(
|
||||
id routineID: String, name: String = "Push Day", exercises: [ExerciseDocument]? = nil,
|
||||
createdAt: Date = Date(timeIntervalSince1970: 0)
|
||||
) -> SplitDocument {
|
||||
SplitDocument(
|
||||
schemaVersion: SplitDocument.currentSchemaVersion, id: splitID, name: name, color: "indigo",
|
||||
) -> RoutineDocument {
|
||||
RoutineDocument(
|
||||
schemaVersion: RoutineDocument.currentSchemaVersion, id: routineID, name: name, color: "indigo",
|
||||
systemImage: "dumbbell.fill", order: 0, createdAt: createdAt, updatedAt: createdAt,
|
||||
exercises: exercises ?? [exercise()], activityType: nil
|
||||
)
|
||||
@@ -46,13 +46,13 @@ struct DuplicateCleanupPlannerTests {
|
||||
}
|
||||
|
||||
private func workout(
|
||||
id workoutID: String, splitID: String? = "SPLIT-1", splitName: String? = "Push Day",
|
||||
id workoutID: String, routineID: String? = "RT-1", routineName: String? = "Push Day",
|
||||
start: Date, status: String = WorkoutStatus.completed.rawValue,
|
||||
logs: [WorkoutLogDocument]? = nil, metrics: WorkoutMetrics? = nil
|
||||
) -> WorkoutDocument {
|
||||
WorkoutDocument(
|
||||
schemaVersion: WorkoutDocument.currentSchemaVersion, id: workoutID, splitID: splitID,
|
||||
splitName: splitName, start: start, end: nil, status: status, createdAt: start, updatedAt: start,
|
||||
schemaVersion: WorkoutDocument.currentSchemaVersion, id: workoutID, routineID: routineID,
|
||||
routineName: routineName, start: start, end: nil, status: status, createdAt: start, updatedAt: start,
|
||||
logs: logs ?? [log(date: start)], metrics: metrics
|
||||
)
|
||||
}
|
||||
@@ -77,56 +77,56 @@ struct DuplicateCleanupPlannerTests {
|
||||
)
|
||||
}
|
||||
|
||||
// MARK: - Split survivor rules
|
||||
// MARK: - Routine survivor rules
|
||||
|
||||
@Test func identicalUnreferencedSplitsKeepEarliestULID() {
|
||||
let earlier = split(id: id(1))
|
||||
let later = split(id: id(2))
|
||||
@Test func identicalUnreferencedRoutinesKeepEarliestULID() {
|
||||
let earlier = routine(id: id(1))
|
||||
let later = routine(id: id(2))
|
||||
let plan = DuplicateCleanupPlanner.plan(
|
||||
splits: [later, earlier], workouts: [], referencedSplitIDs: [], isSeed: { _ in false }
|
||||
routines: [later, earlier], workouts: [], referencedRoutineIDs: [], isSeed: { _ in false }
|
||||
)
|
||||
#expect(plan.splitGroups.count == 1)
|
||||
#expect(plan.splitGroups[0].keep.map(\.id) == [id(1)])
|
||||
#expect(plan.splitGroups[0].delete.map(\.id) == [id(2)])
|
||||
#expect(plan.routineGroups.count == 1)
|
||||
#expect(plan.routineGroups[0].keep.map(\.id) == [id(1)])
|
||||
#expect(plan.routineGroups[0].delete.map(\.id) == [id(2)])
|
||||
}
|
||||
|
||||
/// Referenced-protection must override "earliest ULID wins": a later,
|
||||
/// referenced split survives and the earlier, unreferenced duplicate is the
|
||||
/// referenced routine survives and the earlier, unreferenced duplicate is the
|
||||
/// one deleted — the opposite of the no-protection tiebreak.
|
||||
@Test func referencedProtectionOverridesEarliestWins() {
|
||||
let earlier = split(id: id(1)) // unreferenced, would win the earliest-id tiebreak alone
|
||||
let later = split(id: id(2)) // referenced by a workout
|
||||
let earlier = routine(id: id(1)) // unreferenced, would win the earliest-id tiebreak alone
|
||||
let later = routine(id: id(2)) // referenced by a workout
|
||||
let plan = DuplicateCleanupPlanner.plan(
|
||||
splits: [earlier, later], workouts: [], referencedSplitIDs: [id(2)], isSeed: { _ in false }
|
||||
routines: [earlier, later], workouts: [], referencedRoutineIDs: [id(2)], isSeed: { _ in false }
|
||||
)
|
||||
#expect(plan.splitGroups.count == 1)
|
||||
#expect(plan.splitGroups[0].keep.map(\.id) == [id(2)])
|
||||
#expect(plan.splitGroups[0].delete.map(\.id) == [id(1)])
|
||||
#expect(plan.routineGroups.count == 1)
|
||||
#expect(plan.routineGroups[0].keep.map(\.id) == [id(2)])
|
||||
#expect(plan.routineGroups[0].delete.map(\.id) == [id(1)])
|
||||
}
|
||||
|
||||
@Test func seedMemberNeverDeleted() throws {
|
||||
let seedSplit = split(id: id(1))
|
||||
let duplicate = split(id: id(2))
|
||||
let seedRoutine = routine(id: id(1))
|
||||
let duplicate = routine(id: id(2))
|
||||
let plan = DuplicateCleanupPlanner.plan(
|
||||
splits: [seedSplit, duplicate], workouts: [], referencedSplitIDs: [],
|
||||
routines: [seedRoutine, duplicate], workouts: [], referencedRoutineIDs: [],
|
||||
isSeed: { $0 == id(1) }
|
||||
)
|
||||
let group = try #require(plan.splitGroups.first)
|
||||
let group = try #require(plan.routineGroups.first)
|
||||
#expect(group.keep.map(\.id) == [id(1)])
|
||||
#expect(group.delete.map(\.id) == [id(2)])
|
||||
#expect(!group.delete.contains { $0.id == id(1) })
|
||||
}
|
||||
|
||||
@Test func differingExerciseContentNotGrouped() {
|
||||
let a = split(id: id(1), exercises: [exercise(weight: 100)])
|
||||
let b = split(id: id(2), exercises: [exercise(weight: 105)])
|
||||
let a = routine(id: id(1), exercises: [exercise(weight: 100)])
|
||||
let b = routine(id: id(2), exercises: [exercise(weight: 105)])
|
||||
let plan = DuplicateCleanupPlanner.plan(
|
||||
splits: [a, b], workouts: [], referencedSplitIDs: [], isSeed: { _ in false }
|
||||
routines: [a, b], workouts: [], referencedRoutineIDs: [], isSeed: { _ in false }
|
||||
)
|
||||
#expect(plan.splitGroups.isEmpty)
|
||||
#expect(plan.routineGroups.isEmpty)
|
||||
}
|
||||
|
||||
/// Machine comfort settings are real content: splits identical except for a
|
||||
/// Machine comfort settings are real content: routines identical except for a
|
||||
/// setting value — or for the nil (non-machine) vs. empty (machine, nothing
|
||||
/// recorded) distinction — must not be judged duplicates.
|
||||
@Test func differingMachineSettingsNotGrouped() {
|
||||
@@ -137,14 +137,14 @@ struct DuplicateCleanupPlannerTests {
|
||||
var machineNothingRecorded = exercise()
|
||||
machineNothingRecorded.machineSettings = []
|
||||
|
||||
let a = split(id: id(1), exercises: [lowSeat])
|
||||
let b = split(id: id(2), exercises: [highSeat])
|
||||
let c = split(id: id(3), exercises: [machineNothingRecorded])
|
||||
let d = split(id: id(4)) // machineSettings nil — not a machine exercise
|
||||
let a = routine(id: id(1), exercises: [lowSeat])
|
||||
let b = routine(id: id(2), exercises: [highSeat])
|
||||
let c = routine(id: id(3), exercises: [machineNothingRecorded])
|
||||
let d = routine(id: id(4)) // machineSettings nil — not a machine exercise
|
||||
let plan = DuplicateCleanupPlanner.plan(
|
||||
splits: [a, b, c, d], workouts: [], referencedSplitIDs: [], isSeed: { _ in false }
|
||||
routines: [a, b, c, d], workouts: [], referencedRoutineIDs: [], isSeed: { _ in false }
|
||||
)
|
||||
#expect(plan.splitGroups.isEmpty)
|
||||
#expect(plan.routineGroups.isEmpty)
|
||||
}
|
||||
|
||||
// MARK: - Workout grouping / survivor rules
|
||||
@@ -155,7 +155,7 @@ struct DuplicateCleanupPlannerTests {
|
||||
let w1 = workout(id: id(1), start: day)
|
||||
let w2 = workout(id: id(2), start: sameDayLater)
|
||||
let plan = DuplicateCleanupPlanner.plan(
|
||||
splits: [], workouts: [w1, w2], referencedSplitIDs: [], isSeed: { _ in false }
|
||||
routines: [], workouts: [w1, w2], referencedRoutineIDs: [], isSeed: { _ in false }
|
||||
)
|
||||
#expect(plan.workoutGroups.count == 1)
|
||||
#expect(plan.workoutGroups[0].keep.id == id(1))
|
||||
@@ -166,7 +166,7 @@ struct DuplicateCleanupPlannerTests {
|
||||
let w1 = workout(id: id(1), start: fixedDate(day: 15))
|
||||
let w2 = workout(id: id(2), start: fixedDate(day: 16))
|
||||
let plan = DuplicateCleanupPlanner.plan(
|
||||
splits: [], workouts: [w1, w2], referencedSplitIDs: [], isSeed: { _ in false }
|
||||
routines: [], workouts: [w1, w2], referencedRoutineIDs: [], isSeed: { _ in false }
|
||||
)
|
||||
#expect(plan.workoutGroups.isEmpty)
|
||||
}
|
||||
@@ -176,7 +176,7 @@ struct DuplicateCleanupPlannerTests {
|
||||
let w1 = workout(id: id(1), start: start, status: WorkoutStatus.inProgress.rawValue)
|
||||
let w2 = workout(id: id(2), start: start, status: WorkoutStatus.inProgress.rawValue)
|
||||
let plan = DuplicateCleanupPlanner.plan(
|
||||
splits: [], workouts: [w1, w2], referencedSplitIDs: [], isSeed: { _ in false }
|
||||
routines: [], workouts: [w1, w2], referencedRoutineIDs: [], isSeed: { _ in false }
|
||||
)
|
||||
#expect(plan.workoutGroups.isEmpty)
|
||||
}
|
||||
@@ -189,7 +189,7 @@ struct DuplicateCleanupPlannerTests {
|
||||
let earlierNoLink = workout(id: id(1), start: start, metrics: nil)
|
||||
let laterWithLink = workout(id: id(2), start: start, metrics: metrics(healthKitWorkoutUUID: "HK-UUID"))
|
||||
let plan = DuplicateCleanupPlanner.plan(
|
||||
splits: [], workouts: [earlierNoLink, laterWithLink], referencedSplitIDs: [], isSeed: { _ in false }
|
||||
routines: [], workouts: [earlierNoLink, laterWithLink], referencedRoutineIDs: [], isSeed: { _ in false }
|
||||
)
|
||||
let group = try #require(plan.workoutGroups.first)
|
||||
#expect(group.keep.id == id(2))
|
||||
|
||||
Reference in New Issue
Block a user