Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9d2f414
feat(power-loss): power-loss autostop core — MCP V1 signal, pure poli…
Nov 14, 2026
3d6f1e4
fix(power-loss): POWER_NEAR_LIMIT haptic routers + double-precision R…
Nov 14, 2026
547dcb9
feat(power-loss): frozen P3/P4/P5 evidence contract (#1392)
Nov 17, 2026
b8a92be
feat(power-loss): frozen power-history export v1 facade (#1392)
Nov 17, 2026
120561d
feat(power-loss): P5 UI state, copy, config draft, HUD/summary/histor…
Nov 17, 2026
1128553
feat(power-loss): P4 tier-1 companions + migration 64 + atomic eviden…
Nov 17, 2026
26ac02d
feat(power-loss): ExerciseConfigModal Set target section (#1392 P5)
Nov 17, 2026
53fb295
feat(power-loss): WorkoutHud power-loss readout + attempt identity (#…
Nov 17, 2026
dd29acd
feat(power-loss): power-history export v1 (PowerHistoryExporterImpl +…
Nov 17, 2026
f49c30c
feat(power-loss): SetSummaryCard power-loss headline block (#1392 P5)
Nov 17, 2026
e194b71
feat(power-loss): HistoryTab compact power-loss rows (#1392 P5)
Nov 17, 2026
d6ca8dc
feat(power-loss): P3 one-winner evidence latch, WORKOUT_COMPLETE cap …
Nov 17, 2026
0e3695a
Merge branch 'pkt/1392-p3' into feature/1392-power-loss-autostop
Nov 17, 2026
2b3666c
Merge branch 'pkt/1392-p4' into feature/1392-power-loss-autostop
Nov 17, 2026
620dc71
Merge branch 'pkt/1392-p5' into feature/1392-power-loss-autostop
Nov 17, 2026
5a6ff36
test(power-loss): golden no-new-wire-keys guard for mobile-sync-push …
Nov 17, 2026
9b5b8f5
Merge remote-tracking branch 'origin/main' into feature/1392-power-lo…
Nov 17, 2026
20e839d
fix(power-loss): pin QA schema-head contract markers to user_version …
Nov 17, 2026
a769777
feat(power-loss): propagate one effective execution target plan throu…
Nov 18, 2026
b87ce5e
feat(power-loss): backup v7 companion sections + versioned routine CS…
Nov 18, 2026
d46adc3
feat(power-loss): bottom-sheet/JustLift/set-ready surfaces + config p…
Nov 18, 2026
a2f60d0
Merge branch 'pkt/1392-p3r' into feature/1392-power-loss-autostop
Nov 18, 2026
31be4e7
Merge branch 'pkt/1392-p4r' into feature/1392-power-loss-autostop
Nov 18, 2026
c2d74d5
Merge branch 'pkt/1392-p5r' into feature/1392-power-loss-autostop
Nov 18, 2026
5864dcd
Merge remote-tracking branch 'origin/main' into feature/1392-power-lo…
Nov 18, 2026
6cc4688
fix(power-loss): pin QA schema-head doc markers to user_version 68 (#…
Nov 18, 2026
24ab81f
fix(power-loss): wire live HUD power facts into the active workout HU…
Nov 18, 2026
1cab000
fix(power-loss): render the full ui-spec §4 power panel in the HUD re…
Nov 18, 2026
b05f928
fix(power-loss): render the ui-spec §6 summary block + per-attempt ta…
Nov 18, 2026
d023766
fix(power-loss): render the E04 uncertain-reference HUD state (#1392)
Nov 18, 2026
4484dd5
fix(power-loss): reset the live power HUD at set boundaries (#1392)
Nov 18, 2026
1590b3c
fix(power-loss): keep the committed cap winner in set summary + evide…
Nov 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/qa/persisted-file-upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This runbook verifies PR 709's physical filename migration without treating a synthetic fixture as production evidence. The automated harness is destructive only to one explicitly selected disposable emulator and one exact package name; it never clears data during an upgrade.

The harness default `-ExpectedSchemaVersion` is 66, the current database `user_version` (highest migration file + 1). Pass that parameter only to override it.
The harness default `-ExpectedSchemaVersion` is 68, the current database `user_version` (highest migration file + 1). Pass that parameter only to override it.

## Automated v0.9.6 debug-lineage matrix

Expand Down
6 changes: 3 additions & 3 deletions docs/qa/profile-schema42-fixture.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Profile schema-42 Android fixture

This recipe materializes the pre-profile database and legacy preference input used to prove the schema-42 to current-schema upgrade. The fixture source is commit `ac84d9bb8e156002833ad526bf324a8f12710da0`; do not substitute a moving branch or shortened SHA. The upgrade candidate is a debug APK from the current checkout. After that install, `PRAGMA user_version` must be 66 (highest migration file + 1).
This recipe materializes the pre-profile database and legacy preference input used to prove the schema-42 to current-schema upgrade. The fixture source is commit `ac84d9bb8e156002833ad526bf324a8f12710da0`; do not substitute a moving branch or shortened SHA. The upgrade candidate is a debug APK from the current checkout. After that install, `PRAGMA user_version` must be 68 (highest migration file + 1).

All commands below are PowerShell commands. Start at the repository root. They use the installed Android SDK (`ANDROID_HOME`, else `ANDROID_SDK_ROOT`, else `%LOCALAPPDATA%\Android\Sdk`) and must not contact Supabase. The only network use is the explicit `git fetch` of the pinned fixture commit and Gradle dependency resolution for that commit. Do not pass `--offline`.

Expand Down Expand Up @@ -171,9 +171,9 @@ foreach ($suffix in @('-wal', '-shm')) {
if ($LASTEXITCODE -eq 0) { Receive-SandboxBytes $relative "$inspectDb$suffix" -AllowEmpty }
}
$userVersion = (& $hostSqlite -readonly -batch $inspectDb 'PRAGMA user_version;').Trim()
if ($userVersion -ne '66') { throw "Expected user_version 66 after upgrade, got $userVersion" }
if ($userVersion -ne '68') { throw "Expected user_version 68 after upgrade, got $userVersion" }
& $hostSqlite -readonly -batch $inspectDb 'SELECT profile_id, legacy_migration_version, body_weight_kg, weight_unit, weight_increment, led_color_scheme_id, equipment_rack_json, workout_preferences_json, vbt_preferences_json FROM UserProfilePreferences ORDER BY profile_id;'
& $adb shell run-as $package cat shared_prefs/phoenix_preferences.xml
```

The host `sqlite3` query must report `user_version` 66, each existing profile row must have `legacy_migration_version = 1`, and the sentinel values from the tracked XML must appear in the corresponding profile preference sections.
The host `sqlite3` query must report `user_version` 68, each existing profile row must have `legacy_migration_version = 1`, and the sentinel values from the tracked XML must appear in the corresponding profile preference sections.
2 changes: 1 addition & 1 deletion scripts/qa/Invoke-PhoenixPersistedFileUpgrade.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ param(
[string] $EvidenceDirectory = (Join-Path ([IO.Path]::GetTempPath()) 'phoenix-persisted-file-upgrade'),

[Parameter()]
[int] $ExpectedSchemaVersion = 66
[int] $ExpectedSchemaVersion = 68
)

Set-StrictMode -Version Latest
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
package com.devil.phoenixproject.data.export

import app.cash.sqldelight.driver.jdbc.sqlite.JdbcSqliteDriver
import com.devil.phoenixproject.data.local.ExerciseImporter
import com.devil.phoenixproject.data.repository.PowerLossCompanionStore
import com.devil.phoenixproject.data.repository.SqlDelightExerciseRepository
import com.devil.phoenixproject.data.repository.SqlDelightWorkoutRepository
import com.devil.phoenixproject.database.PhoenixDatabase
import com.devil.phoenixproject.domain.model.WorkoutSession
import com.devil.phoenixproject.domain.powerloss.PowerCable
import com.devil.phoenixproject.domain.powerloss.PowerLossAttemptRecord
import com.devil.phoenixproject.domain.powerloss.PowerLossSetEvidence
import com.devil.phoenixproject.domain.powerloss.PowerStopReason
import com.devil.phoenixproject.domain.powerloss.SampleQualityMarkers
import com.devil.phoenixproject.domain.powerloss.TargetMode
import com.devil.phoenixproject.testutil.FakePreferencesManager
import com.devil.phoenixproject.testutil.createTestSchema
import kotlin.test.assertEquals
import kotlin.test.assertNull
import kotlin.test.assertTrue
import kotlinx.coroutines.test.runTest
import org.junit.After
import org.junit.Before
import org.junit.Test

/**
* Issue #1392 (packet P4) — power-history export v1 roundtrip.
*
* P4 acceptance: "power-history export roundtrips preserving null/zero/identity".
* Export → parse back → field-equal, INCLUDING the null-vs-zero distinction: a
* measured 0 must survive as 0 and a missing metric must survive as null — the
* two must never collapse into each other.
*/
class PowerHistoryExportRoundtripTest {

private lateinit var driver: JdbcSqliteDriver
private lateinit var database: PhoenixDatabase
private lateinit var exporter: PowerHistoryExporter

@Before
fun setup() {
driver = JdbcSqliteDriver(JdbcSqliteDriver.IN_MEMORY)
createTestSchema(driver)
database = PhoenixDatabase(driver)
val exerciseRepository = SqlDelightExerciseRepository(
database,
ExerciseImporter(database),
FakePreferencesManager(),
)
val workoutRepository = SqlDelightWorkoutRepository(database, exerciseRepository)
exporter = PowerHistoryExporterImpl(database)
// The exporter enumerates sessions per profile; seed one owned session and one
// foreign-profile session (which must never appear in the export).
kotlinx.coroutines.runBlocking {
workoutRepository.saveSession(WorkoutSession(id = SESSION_ID, profileId = PROFILE_ID))
workoutRepository.saveSession(WorkoutSession(id = OTHER_SESSION_ID, profileId = OTHER_PROFILE_ID))
}
}

@After
fun tearDown() {
driver.close()
}

@Test
fun `export roundtrips field-equal with null-vs-zero preserved`() = runTest {
val queries = database.phoenixDatabaseQueries
PowerLossCompanionStore.commitEvidence(queries, ownEvidence(), nowMs = 1_000L)
PowerLossCompanionStore.commitEvidence(queries, foreignEvidence(), nowMs = 2_000L)

val result = exporter.exportPowerData(PROFILE_ID)

assertEquals(1, result.version)
assertEquals("power-history-v1-$PROFILE_ID.json", result.displayName)
// The document identifies itself and its units explicitly.
assertTrue(result.content.contains("\"documentType\": \"power-history-export\""), result.content)
assertTrue(result.content.contains("\"version\": 1"), result.content)
assertTrue(result.content.contains("\"power\": \"watts\""), result.content)
assertTrue(result.content.contains("\"rom\": \"millimeters\""), result.content)
assertTrue(result.content.contains("\"duration\": \"milliseconds\""), result.content)

val document = PowerHistoryExportCodec.decode(result.content)
assertEquals(1, document.version)
assertEquals(PROFILE_ID, document.profileId)
// Profile scoping: only this profile's session, only sessions with evidence.
assertEquals(listOf(SESSION_ID), document.sessions.map { it.sessionId })
assertEquals(1, document.sessions.single().sets.size)

// Full field-equality against the seeded evidence (identity + every metric).
val decoded = document.sessions.single().sets.single()
assertEquals(ownEvidence(), decoded)

// Null-vs-zero, called out explicitly on top of the deep equality.
val measuredZero = decoded.attempts.first { it.workingConcentricOrdinal == 1 }
val missing = decoded.attempts.first { it.workingConcentricOrdinal == 2 }
assertEquals(0.0f, measuredZero.mcpWatts, "a measured zero must not roundtrip as null")
assertEquals(0L, measuredZero.concentricDurationMs)
assertEquals(0.0f, measuredZero.lossPercentAtDecision)
assertEquals(0.0f, measuredZero.romAMm)
assertNull(missing.mcpWatts, "a missing metric must not roundtrip as 0")
assertNull(missing.eccentricPowerWatts)
assertNull(missing.concentricDurationMs)
assertNull(missing.eccentricDurationMs)
assertNull(missing.lossPercentAtDecision)
assertNull(missing.romAMm)
assertNull(missing.romBMm)
assertNull(missing.romAPercentOfReference)
assertNull(missing.romBPercentOfReference)
// Attempt-only identity survives (pending ≠ completed).
assertEquals(false, missing.completed)
assertNull(missing.legacyRepIndex)
// Set-level facts survive: reference/trigger/winner + BOTH qualification facts.
assertEquals(1, decoded.referenceWorkingOrdinal)
assertEquals(100.5f, decoded.referenceMcpWatts)
assertNull(decoded.referenceRomBMm)
assertEquals(2, decoded.triggerWorkingOrdinal)
assertEquals(PowerStopReason.POWER_LOSS, decoded.winnerReason)
assertEquals(true, decoded.shortRomObserved)
assertEquals(true, decoded.powerLossObserved)
}

/** Measured zeros on one attempt, missing (null) metrics on the attempt-only row. */
private fun ownEvidence(): PowerLossSetEvidence = PowerLossSetEvidence(
sessionId = SESSION_ID,
setId = "set-1",
metricVersion = 1,
targetMode = TargetMode.POWER,
thresholdPercent = 25,
maxWorkingReps = null,
requireTwoConsecutive = true,
savedNominalReps = 12,
activeCables = setOf(PowerCable.A, PowerCable.B),
activeCableProvenance = "frozen-mask",
referenceWorkingOrdinal = 1,
referenceMcpWatts = 100.5f,
referenceRomAMm = 420.0f,
referenceRomBMm = null,
triggerWorkingOrdinal = 2,
winnerReason = PowerStopReason.POWER_LOSS,
shortRomObserved = true,
powerLossObserved = true,
lossPercentAtDecision = 21.5f,
attempts = listOf(
PowerLossAttemptRecord(
workingConcentricOrdinal = 1,
completed = true,
legacyRepIndex = 0,
mcpWatts = 0.0f,
eccentricPowerWatts = null,
concentricDurationMs = 0L,
eccentricDurationMs = null,
lossPercentAtDecision = 0.0f,
referenceWorkingOrdinal = 1,
romAMm = 0.0f,
romBMm = null,
romAPercentOfReference = 0.0f,
romBPercentOfReference = null,
romTrustworthy = true,
quality = SampleQualityMarkers(stale = true),
shortRom = true,
powerLossQualified = false,
),
PowerLossAttemptRecord(
workingConcentricOrdinal = 2,
completed = false,
legacyRepIndex = null,
mcpWatts = null,
eccentricPowerWatts = null,
concentricDurationMs = null,
eccentricDurationMs = null,
lossPercentAtDecision = null,
referenceWorkingOrdinal = 2,
romAMm = null,
romBMm = null,
romAPercentOfReference = null,
romBPercentOfReference = null,
romTrustworthy = false,
quality = SampleQualityMarkers(),
shortRom = false,
powerLossQualified = true,
),
),
)

private fun foreignEvidence(): PowerLossSetEvidence = PowerLossSetEvidence(
sessionId = OTHER_SESSION_ID,
setId = "set-foreign",
metricVersion = 1,
targetMode = TargetMode.REP_TARGET,
thresholdPercent = 20,
maxWorkingReps = 20,
requireTwoConsecutive = false,
savedNominalReps = null,
activeCables = setOf(PowerCable.A),
activeCableProvenance = "frozen-mask",
referenceWorkingOrdinal = null,
referenceMcpWatts = null,
referenceRomAMm = null,
referenceRomBMm = null,
triggerWorkingOrdinal = null,
winnerReason = null,
shortRomObserved = false,
powerLossObserved = false,
lossPercentAtDecision = null,
attempts = emptyList(),
)

private companion object {
const val PROFILE_ID = "profile-roundtrip"
const val OTHER_PROFILE_ID = "profile-other"
const val SESSION_ID = "session-roundtrip"
const val OTHER_SESSION_ID = "session-other"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Android109UpgradeTest {

@Test
fun v108Database_upgradesThroughProductionDriver_andReopensWithOldAndNewData() {
assertEquals(66L, PhoenixDatabase.Schema.version, "Revisit this release-specific fixture when the schema advances")
assertEquals(68L, PhoenixDatabase.Schema.version, "Revisit this release-specific fixture when the schema advances")
seedReleased108Database()

val upgraded = DriverFactory(context).createDriver()
Expand Down Expand Up @@ -136,7 +136,7 @@ class Android109UpgradeTest {
}

private fun assertHealthyUpgrade(driver: SqlDriver) {
assertEquals(66L, driver.longValue("PRAGMA user_version"))
assertEquals(68L, driver.longValue("PRAGMA user_version"))
assertEquals("ok", driver.textValue("PRAGMA quick_check"))
assertEquals(1L, driver.longValue("PRAGMA foreign_keys"))
driver.executeQuery(null, "PRAGMA foreign_key_check", { cursor ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ class IntervalsMigrationTest {
// Schema.version is the version every open validates against; the six
// additive tables are what a 64-schema database carries beyond v63. This
// fixture pins a v64 database itself, so it stays valid as the schema advances
// (v65 adds RepBiomechanics.aggregateEligible, Issue #1400).
// (v65 adds RepBiomechanics.aggregateEligible, Issue #1400; v66/v67 add the
// issue #1392 power-loss companion and config tables).
assertTrue(PhoenixDatabase.Schema.version >= 64L, "Schema must include the v64 Intervals tables")

val file = File.createTempFile("intervals-migration-downgrade", ".db")
Expand Down Expand Up @@ -537,7 +538,7 @@ class IntervalsMigrationTest {
// ==================== EXPECTED 63.sqm SHAPE ====================

private companion object {
private const val EXPECTED_SCHEMA_VERSION = 66L
private const val EXPECTED_SCHEMA_VERSION = 68L

private val EXPECTED_TABLES: Map<String, Map<String, String>> = linkedMapOf(
"IntervalsConnection" to linkedMapOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,7 @@ class SchemaParityTest {
// ==================== HELPERS ====================

companion object {
private const val EXPECTED_SCHEMA_VERSION = 66L
private const val EXPECTED_SCHEMA_VERSION = 68L

/**
* A database built the way every existing user gets it: minimal v1 schema, each
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import com.devil.phoenixproject.domain.model.Exercise
import com.devil.phoenixproject.domain.model.Routine
import com.devil.phoenixproject.domain.model.RoutineExercise
import com.devil.phoenixproject.domain.model.RoutineGroup
import com.devil.phoenixproject.domain.powerloss.PowerLossConfig
import com.devil.phoenixproject.domain.powerloss.TargetMode
import com.devil.phoenixproject.testutil.FakeExerciseRepository
import com.devil.phoenixproject.testutil.createTestDatabase
import kotlinx.coroutines.flow.first
Expand All @@ -20,6 +22,7 @@ import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertIs
import kotlin.test.assertNotNull
import kotlin.test.assertNull
import kotlin.test.assertTrue

/** Issue #772: the CSV import commit against real SQLite (foreign keys on). */
Expand Down Expand Up @@ -287,6 +290,40 @@ class RoutineCsvImportRepositoryTest {
),
)

@Test
fun powerLossConfigSurvivesSaveReloadAndTheVersion3CsvRoundTrip() = runTest {
val powerConfig = PowerLossConfig(
targetMode = TargetMode.POWER,
thresholdPercent = 25,
maxWorkingReps = 15,
requireTwoConsecutive = true,
savedNominalReps = 12,
)
val configured = routine("r-power", "Power day").let { base ->
base.copy(exercises = base.exercises.map { it.copy(powerLoss = powerConfig) })
}

repository.saveRoutine(configured)

val stored = repository.getRoutineById("r-power")!!
assertEquals(powerConfig, stored.exercises.single().powerLoss)

val exported = assertIs<RoutineCsvExportResult.Exported>(RoutineCsvCodec.encode(stored, null, null))
assertTrue(exported.content.startsWith("# phoenix_routine_csv_version=3"), "a POWER routine exports as version 3")
val reparsed = assertIs<RoutineCsvParseResult.Parsed>(RoutineCsvCodec.parse(exported.content)).routines.single()
assertEquals(powerConfig, reparsed.exercises.single().powerLoss)
}

@Test
fun legacyRowsKeepInertRepDefaultsWithNullsNotZeros() = runTest {
repository.saveRoutine(routine("r-legacy", "Legacy day"))

val stored = repository.getRoutineById("r-legacy")!!
val powerLoss = stored.exercises.single().powerLoss
assertEquals(TargetMode.REP_TARGET, powerLoss.targetMode)
assertNull(powerLoss.savedNominalReps)
}

private companion object {
const val HEADER = "routine_id,routine_name,routine_description,group_name,group_order,exercise_id,exercise_name," +
"exercise_order,superset_key,superset_name,superset_order,superset_rest_seconds,set_reps,set_weights_kg," +
Expand Down
Loading
Loading