LifeMate — Personal, Family & Learning Companion
fix: preserve exact study duration in parent reports
Quinn White committed
Oct 12, 2026 at 08:29 UTC
d0b3446d736b67fdb4e0218282ad15f0e74fdb55
6 files changed
+144
-12
CHANGELOG.md
+2
-1
@@ -4,7 +4,8 @@
4
5
- Fix a real three-account PWA acceptance blocker: public auth capabilities no longer consume sensitive login/delivery attempts, and refresh/logout have a separate bounded session bucket.
6
- Keep strict sensitive-auth limits and trusted-proxy rules; near-match methods/paths remain strict. Add production-entrypoint PostgreSQL tests for shared-IP family rotation and rate-limit boundaries.
7
-- Flutter remains0.7.0+6 because the client protocol and application source are unchanged. Release signing, hardware/Safari/Iran access and real content review remain UNVERIFIED.
7
+- The initial auth-only hotfix kept Flutter0.7.0+6. Follow-up client0.7.1+7 shows exact minute/second durations in parent totals, daily trends, subjects and tasks; zero and whole-minute labels stay compatible. Bound the daily label width for narrow RTL screens and update the public static cache version.
8
+- Release signing, hardware/Safari/Iran access and real content review remain UNVERIFIED.
9
10
## 0.7.0 — 2026-10-12 — learning and family operations (test candidate)
11
apps/lifemate/lib/dashboard_ui.dart
+17
-7
@@ -348,8 +348,15 @@ class _LearningReportPageState extends State<LearningReportPage>
348
}
349
}
350
351
- String minutes(dynamic seconds) =>
352
- '${((seconds as num? ?? 0) / 60).round()} دقیقه';
351
+ String formatDurationSeconds(dynamic seconds) {
352
+ final total = (seconds as num? ?? 0).toInt();
353
+ final minutes = total ~/ 60;
354
+ final remainder = total % 60;
355
+ if (remainder == 0) return '$minutes دقیقه';
356
+ if (minutes == 0) return '$remainder ثانیه';
357
+ return '$minutes دقیقه و $remainder ثانیه';
358
+ }
359
+
360
@override
361
Widget build(BuildContext context) {
362
final r = reportNamespace == widget.api.cacheNamespace ? report : null;
@@ -446,11 +453,12 @@ class _LearningReportPageState extends State<LearningReportPage>
453
Text(
454
'کل سابقه مجاز: ${allTime['totalTasks'] ?? 0} تکلیف · ${allTime['completedTasks'] ?? 0} انجامشده'),
455
Text(
449
- 'زمان برنامهریزیشده: ${minutes(m['plannedInRangeDurationSeconds'] ?? m['plannedDurationSeconds'])}'),
456
+ 'زمان برنامهریزیشده: ${formatDurationSeconds(m['plannedInRangeDurationSeconds'] ?? m['plannedDurationSeconds'])}'),
457
if (!hasPeriod && m['plannedInRangeDurationSeconds'] == null)
458
const Text(
459
'زمان برنامهریزیشده مربوط به کل سابقه مجاز است؛ زمان بازه جداگانه از سرور دریافت نشده است.'),
453
- Text('زمان ثبتشده: ${minutes(m['recordedDurationSeconds'])}'),
460
+ Text(
461
+ 'زمان ثبتشده: ${formatDurationSeconds(m['recordedDurationSeconds'])}'),
462
const Text(
463
'زمان ثبتشده فقط بخش جلسههای مجاز داخل بازه است؛ ممکن است به تکلیفی با موعد خارج از بازه مربوط باشد.'),
464
Text('روند زمان ثبتشده',
@@ -467,7 +475,9 @@ class _LearningReportPageState extends State<LearningReportPage>
475
(row['recordedDurationSeconds'] as num? ?? 0) /
476
max)),
477
const SizedBox(width: 8),
470
- Text(minutes(row['recordedDurationSeconds']))
478
+ Flexible(
479
+ child: Text(formatDurationSeconds(
480
+ row['recordedDurationSeconds'])))
481
]));
482
}),
483
Text(hasPeriod ? 'درسها در بازه' : 'درسها در کل سابقه مجاز',
@@ -477,7 +487,7 @@ class _LearningReportPageState extends State<LearningReportPage>
487
return ListTile(
488
title: Text(row['subjectName']?.toString() ?? 'بدون درس'),
489
subtitle: Text(
480
- '${row['completedTasks']}/${row['totalTasks']} تکمیل ${hasPeriod ? 'تکلیفهای بازه' : 'کل سابقه'} · ${minutes(row['recordedDurationSeconds'])}${hasPeriod && row['gradePercent'] != null ? '\nنمره وزنی امتحانهای مجاز: ${row['gradePercent']}٪ (${row['gradedExamCount']} امتحان)' : ''}'));
490
+ '${row['completedTasks']}/${row['totalTasks']} تکمیل ${hasPeriod ? 'تکلیفهای بازه' : 'کل سابقه'} · ${formatDurationSeconds(row['recordedDurationSeconds'])}${hasPeriod && row['gradePercent'] != null ? '\nنمره وزنی امتحانهای مجاز: ${row['gradePercent']}٪ (${row['gradedExamCount']} امتحان)' : ''}'));
491
}),
492
if (hasPeriod) ...[
493
Text('امتحانهای مجاز در بازه',
@@ -522,7 +532,7 @@ class _LearningReportPageState extends State<LearningReportPage>
532
child: ListTile(
533
title: Text(i['title']?.toString() ?? ''),
534
subtitle: Text(
525
- '${faKind(i['kind']?.toString() ?? 'task')} · $state\nآخرین ثبت وضعیت: ${shortDate(i['activityAt'])}\nموعد: ${shortDate(i['dueAt'] ?? i['startsAt'])}\nبرنامه ${minutes(i['plannedDurationSeconds'])} · ثبت ${minutes(i['recordedDurationSeconds'])}${hasPeriod && i['taskInRange'] != true ? '\nموعد این تکلیف خارج از بازه است؛ فقط زمان ثبتشده در بازه نمایش داده میشود.' : ''}${i['gradePoints'] == null ? '' : '\nنمره ${i['gradePoints']}/${i['gradeOutOf']}'}')));
535
+ '${faKind(i['kind']?.toString() ?? 'task')} · $state\nآخرین ثبت وضعیت: ${shortDate(i['activityAt'])}\nموعد: ${shortDate(i['dueAt'] ?? i['startsAt'])}\nبرنامه ${formatDurationSeconds(i['plannedDurationSeconds'])} · ثبت ${formatDurationSeconds(i['recordedDurationSeconds'])}${hasPeriod && i['taskInRange'] != true ? '\nموعد این تکلیف خارج از بازه است؛ فقط زمان ثبتشده در بازه نمایش داده میشود.' : ''}${i['gradePoints'] == null ? '' : '\nنمره ${i['gradePoints']}/${i['gradeOutOf']}'}')));
536
}),
537
],
538
TextButton(
apps/lifemate/pubspec.yaml
+1
-1
@@ -1,5 +1,5 @@
1
name: lifemate
2
-version: 0.7.0+6
2
+version: 0.7.1+7
3
publish_to: none
4
description: LifeGuide personal, family and learning companion.
5
environment:
apps/lifemate/test/dashboard_periods_test.dart
+107
@@ -117,6 +117,113 @@ Widget _page(HttpIdentityApi api, {String childId = 'child'}) => MaterialApp(
117
api: api, familyId: 'family', childId: childId, childName: 'فرزند'));
118
119
void main() {
120
+ for (final entry in <int, String>{
121
+ 0: '0 دقیقه',
122
+ 4: '4 ثانیه',
123
+ 29: '29 ثانیه',
124
+ 30: '30 ثانیه',
125
+ 59: '59 ثانیه',
126
+ 60: '1 دقیقه',
127
+ 61: '1 دقیقه و 1 ثانیه',
128
+ 90: '1 دقیقه و 30 ثانیه',
129
+ 1500: '25 دقیقه',
130
+ }.entries) {
131
+ testWidgets('recorded ${entry.key} seconds keeps exact parent report time',
132
+ (tester) async {
133
+ final report = _report('تکلیف با زمان دقیق');
134
+ (report['periodMetrics'] as Map)['recordedDurationSeconds'] = entry.key;
135
+ final api = _api((_) async => _response(report));
136
+ await tester.pumpWidget(_page(api));
137
+ await tester.pumpAndSettle();
138
+ expect(find.text('زمان ثبتشده: ${entry.value}'), findsOneWidget);
139
+ expect(find.text('زمان برنامهریزیشده: 30 دقیقه'), findsOneWidget);
140
+ await tester.pumpWidget(const SizedBox());
141
+ api.close();
142
+ });
143
+ }
144
+
145
+ testWidgets('short duration remains exact in daily, subject and task rows',
146
+ (tester) async {
147
+ final report = _report('تکلیف چهارثانیهای');
148
+ (report['periodMetrics'] as Map)['recordedDurationSeconds'] = 4;
149
+ report['daily'] = [
150
+ {'date': '2026-10-11', 'recordedDurationSeconds': 4}
151
+ ];
152
+ (report['periodSubjects'] as List).single['recordedDurationSeconds'] = 4;
153
+ report['items'] = [
154
+ {
155
+ 'id': 'short-task',
156
+ 'title': 'تکلیف چهارثانیهای',
157
+ 'kind': 'assignment',
158
+ 'taskInRange': true,
159
+ 'plannedDurationSeconds': 1800,
160
+ 'recordedDurationSeconds': 4
161
+ }
162
+ ];
163
+ final api = _api((_) async => _response(report));
164
+ await tester.pumpWidget(_page(api));
165
+ await tester.pumpAndSettle();
166
+ await tester.scrollUntilVisible(find.text('4 ثانیه'), 200);
167
+ expect(find.text('4 ثانیه'), findsOneWidget);
168
+ await tester.scrollUntilVisible(
169
+ find.textContaining('1/2 تکمیل تکلیفهای بازه · 4 ثانیه'), 200);
170
+ expect(find.textContaining('1/2 تکمیل تکلیفهای بازه · 4 ثانیه'),
171
+ findsOneWidget);
172
+ await tester.scrollUntilVisible(
173
+ find.textContaining('برنامه 30 دقیقه · ثبت 4 ثانیه'), 200);
174
+ expect(
175
+ find.textContaining('برنامه 30 دقیقه · ثبت 4 ثانیه'), findsOneWidget);
176
+ await tester.pumpWidget(const SizedBox());
177
+ api.close();
178
+ });
179
+
180
+ testWidgets('legacy report preserves planned seconds without rounding',
181
+ (tester) async {
182
+ final report = _report('تکلیف سرور قبلی')
183
+ ..remove('periodMetrics')
184
+ ..remove('periodSubjects')
185
+ ..remove('periodExams');
186
+ (report['metrics'] as Map)
187
+ ..['plannedDurationSeconds'] = 95
188
+ ..['recordedDurationSeconds'] = 4;
189
+ final api = _api((_) async => _response(report));
190
+ await tester.pumpWidget(_page(api));
191
+ await tester.pumpAndSettle();
192
+ expect(
193
+ find.text('زمان برنامهریزیشده: 1 دقیقه و 35 ثانیه'), findsOneWidget);
194
+ expect(find.text('زمان ثبتشده: 4 ثانیه'), findsOneWidget);
195
+ expect(find.textContaining('سرور آمار تکلیفهای بازه را ارائه نکرده'),
196
+ findsOneWidget);
197
+ await tester.pumpWidget(const SizedBox());
198
+ api.close();
199
+ });
200
+
201
+ testWidgets('mixed duration fits a narrow RTL daily report', (tester) async {
202
+ tester.view.physicalSize = const Size(320, 960);
203
+ tester.view.devicePixelRatio = 1;
204
+ addTearDown(tester.view.resetPhysicalSize);
205
+ addTearDown(tester.view.resetDevicePixelRatio);
206
+ final report = _report('تکلیف نیمدقیقه اضافه');
207
+ report['daily'] = [
208
+ {'date': '2026-10-11', 'recordedDurationSeconds': 90}
209
+ ];
210
+ final api = _api((_) async => _response(report));
211
+ await tester.pumpWidget(MaterialApp(
212
+ home: Directionality(
213
+ textDirection: TextDirection.rtl,
214
+ child: LearningReportPage(
215
+ api: api,
216
+ familyId: 'family',
217
+ childId: 'child',
218
+ childName: 'فرزند'))));
219
+ await tester.pumpAndSettle();
220
+ await tester.scrollUntilVisible(find.text('1 دقیقه و 30 ثانیه'), 200);
221
+ expect(find.text('1 دقیقه و 30 ثانیه'), findsOneWidget);
222
+ expect(tester.takeException(), isNull);
223
+ await tester.pumpWidget(const SizedBox());
224
+ api.close();
225
+ });
226
+
227
testWidgets(
228
'range dashboard uses period counters and preserves explicitly labelled history',
229
(tester) async {
apps/lifemate/web/lifeguide-sw.js
+1
-1
@@ -1,6 +1,6 @@
1
// Current code/settings use the network. A cold disconnected navigation may
2
// show only a public notice, never cached login, permissions or personal data.
3
-const CACHE = 'lifeguide-static-v0.7.0-6';
3
+const CACHE = 'lifeguide-static-v0.7.1-7';
4
const BASE_PATH = new URL('.', self.location.href).pathname;
5
const OFFLINE_URL = new URL('offline.html', self.location.href).href;
6
const RETRY_URL = new URL('offline-retry.js', self.location.href).href;
scripts/pwa-browser-smoke.py
+16
-2
@@ -26,6 +26,20 @@ parser.add_argument("--expected-planned-seconds", type=int)
26
parser.add_argument("--expected-status")
27
parser.add_argument("--resume-parent-session", action="store_true")
28
args = parser.parse_args()
29
+
30
+def duration_label(total_seconds):
31
+ minutes, seconds = divmod(total_seconds, 60)
32
+ if not seconds:
33
+ return f"{minutes} دقیقه"
34
+ if not minutes:
35
+ return f"{seconds} ثانیه"
36
+ return f"{minutes} دقیقه و {seconds} ثانیه"
37
+
38
+def duration_is_shown(rendered, prefix, total_seconds):
39
+ # A whole-minute expectation must not accept an extra second component.
40
+ expected = re.escape(f"{prefix} {duration_label(total_seconds)}")
41
+ return re.search(expected + r"(?!\s+و\b)", rendered) is not None
42
+
43
origin = args.origin.rstrip("/")
44
parsed = urlparse(origin)
45
if parsed.scheme != "https" or parsed.username or parsed.password or parsed.path or parsed.query or parsed.fragment:
@@ -121,11 +135,11 @@ with sync_playwright() as playwright:
135
assert time.monotonic() < deadline, "Expected allowed report was not rendered in PWA"
136
page.wait_for_timeout(100)
137
if args.expected_recorded_seconds is not None:
124
- assert f"ثبت {round(args.expected_recorded_seconds / 60)} دقیقه" in rendered, "Recorded task duration not shown in PWA"
138
+ assert duration_is_shown(rendered, "ثبت", args.expected_recorded_seconds), "Exact recorded task duration not shown in PWA"
139
if args.expected_status == "completed":
140
assert "انجامشده به گزارش فرزند" in rendered, "Recorded completion status not shown in PWA"
141
if args.expected_planned_seconds is not None:
128
- assert f"زمان برنامهریزیشده: {round(args.expected_planned_seconds / 60)} دقیقه" in rendered, "Planned duration for report range not shown in PWA"
142
+ assert duration_is_shown(rendered, "زمان برنامهریزیشده:", args.expected_planned_seconds), "Exact planned duration for report range not shown in PWA"
143
assert "SYNTHETIC-OWNER-PRIVATE-NOTE" not in rendered, "Private owner note rendered for parent"
144
login_verified, report_verified = True, True
145
external = [request for request in requests if request["origin"] != origin]