Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

fix(health): imported weigh-ins are never written back to Apple Health / Health Connect

Duarte Santosa7fdd4cf1478
diff --git a/frontend/src/lib/import-bodyweight.test.js b/frontend/src/lib/import-bodyweight.test.js
index 5b78be618..06f1b7ee8 100644
--- a/frontend/src/lib/import-bodyweight.test.js
+++ b/frontend/src/lib/import-bodyweight.test.js
@@ -55,3 +55,30 @@ describe('Strong measurements export', () => {
expect(parseBodyweight('Date,Measurement Type,Value,Unit,Source\n2026-10-11,Waist,98,cm,Strong').error).toBe('unrecognised')
})
})
+
+// Discord lajawi, eibergerd: an Apple Health export (or a Google Health / Health Connect CSV)
+// imported here went straight back into Apple Health / Health Connect, a second copy of every
+// weigh-in. An imported weigh-in is marked, and only one typed into openGym goes out.
+describe('imported weigh-ins never go back to the health hub', () => {
+ it('marks what an import brings, and leaves what was there alone', async () => {
+ const { mergeImport } = await import('./import-csv.js')
+ const { healthRecords, planSync } = await import('./health-connect.js')
+ const S = { unit: 'kg', workouts: [], bodyweight: [{ d: '2026-09-01', w: 79, t: Date.parse('2026-09-01T07:00:00') }] }
+ const parsed = parseImport(record('01', 80, 'kg') + record('02', 81, 'kg') + record('03', 82, 'kg'))
+ expect(mergeImport(S, parsed)).toEqual({ added: 2, skipped: 1 })
+ expect(S.bodyweight.map(b => b.src || null)).toEqual([null, 'import', 'import'])
+ // The writer both apps use (Apple Health on the iPhone, Health Connect on Android).
+ const recs = healthRecords(S, { nameOf: () => '' })
+ expect(recs.weights.map(r => r.id)).toEqual(['opengym-bw-2026-09-01'])
+ expect(planSync(recs, {}).weights.map(r => r.id)).toEqual(['opengym-bw-2026-09-01'])
+ })
+
+ it('a CSV of weights and a Hevy import count as imports too', async () => {
+ const { mergeImport } = await import('./import-csv.js')
+ const { parseHevyBodyweight } = await import('./import-hevy.js')
+ const S = { unit: 'kg', workouts: [], bodyweight: [] }
+ mergeImport(S, parseImport('Date,Weight (kg)\n2026-09-01,80\n2026-09-02,80.5'))
+ mergeImport(S, parseHevyBodyweight([{ date: '2026-09-03', weight_kg: 81 }]))
+ expect(S.bodyweight.map(b => b.src)).toEqual(['import', 'import', 'import'])
+ })
+})
diff --git a/frontend/src/lib/import-csv.js b/frontend/src/lib/import-csv.js
index 2a5c88aad..ca476926a 100644
--- a/frontend/src/lib/import-csv.js
+++ b/frontend/src/lib/import-csv.js
@@ -893,7 +893,10 @@ export function parseImport(text, opts) {
export function mergeImport(S, parsed) {
if (parsed.kind === 'bodyweight') {
const have = new Set(S.bodyweight.map(b => b.d))
- const fresh = parsed.bodyweight.filter(b => !have.has(b.d))
+ // Marked as imported (`src`, as lib/health-read.js marks what it reads): mostly another app's
+ // or the health hub's own export, so it is never written back to Apple Health or Health
+ // Connect (lib/health-connect.js healthRecords), where it would land a second time.
+ const fresh = parsed.bodyweight.filter(b => !have.has(b.d)).map(b => ({ ...b, src: b.src || 'import' }))
S.bodyweight = [...S.bodyweight, ...fresh].sort((a, b) => (a.d < b.d ? -1 : 1))
return { added: fresh.length, skipped: parsed.bodyweight.length - fresh.length }
}