From e1bd63a8aa23f8d126c8182030455c3b9ca75b3d Mon Sep 17 00:00:00 2001 From: palmoni5 Date: Thu, 5 Nov 2026 17:21:01 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=D7=93=D7=99=D7=95=D7=95=D7=97=D7=99=D7=9D?= =?UTF-8?q?=20=D7=90=D7=95=D7=A4=D7=9C=D7=99=D7=99=D7=9F:=20=D7=A9=D7=99?= =?UTF-8?q?=D7=9E=D7=95=D7=A8=20=D7=97=D7=95=D7=96=D7=94=20=D7=94=D7=A6?= =?UTF-8?q?=D7=A8=D7=95=D7=A4=D7=95=D7=AA=20=D7=94=D7=97=D7=93=D7=A9=20?= =?UTF-8?q?=D7=95=D7=90=D7=99=D7=A1=D7=95=D7=A3=20=D7=AA=D7=95=D7=A8=D7=99?= =?UTF-8?q?=D7=9D=20=D7=91=D7=9C=D7=99=20=D7=98=D7=99=D7=95=D7=98=D7=95?= =?UTF-8?q?=D7=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AGENTS.md | 9 +- error_reports_manager/README.md | 36 ++++- .../launcher_report/app_report_service.dart | 39 ++++- .../lib/src/port/app_report.dart | 96 ++++++++++-- .../lib/src/port/app_report_image.dart | 17 +- .../lib/src/port/app_report_minidump.dart | 22 ++- .../lib/src/services/report_uploader.dart | 57 ++++++- .../src/services/user_state_report_queue.dart | 44 ++++-- .../test/app_report_service_test.dart | 89 ++++++++--- .../test/fixtures/app_report_schema2.json | 72 +++++++++ error_reports_manager/test/port_test.dart | 41 +++++ .../test/report_uploader_test.dart | 57 +++++++ .../test/user_state_report_queue_test.dart | 147 +++++++++++++++++- .../screens/app_report/app_report_dialog.dart | 1 + .../app_report/app_report_images_section.dart | 13 +- .../app_report/app_report_result_snack.dart | 6 + launcher_app/test/app_reports_test.dart | 4 +- otzaria_l10n/lib/src/app_strings.dart | 3 + otzaria_l10n/lib/src/strings_en.dart | 13 +- otzaria_l10n/lib/src/strings_he.dart | 13 +- 20 files changed, 699 insertions(+), 80 deletions(-) create mode 100644 error_reports_manager/test/fixtures/app_report_schema2.json diff --git a/AGENTS.md b/AGENTS.md index 5812bea4..ec9c55f7 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -2357,7 +2357,7 @@ and `lib/utils/canonical_json.dart`, plus `AppReport` and `PluginReportRecord`. by Otzaria's own code (commit named in the fixture); a change there must be re-ported and the vectors regenerated, or the server receives a body Otzaria would never send. -**Never write to a DB we do not understand.** A `reportsQueueFormat` other than 1 in +**Never write to a DB we do not understand.** A `reportsQueueFormat` other than 1 or 2 in `otzaria_capabilities.json` (or, without that file, `PRAGMA user_version` above `UserStateReportQueue.knownSchemaVersion`), a missing `pending_reports` table, or a book report's `schemaVersion` above 2 all mean "no offer" and no write. A leftover @@ -2420,7 +2420,12 @@ new id (`report_id` / `reportId`), is rewritten in the outbox under it, and is r once. A 503 `{"error":"shabbat"}` stops the run with its own message. A drive file can come from anywhere, so the endpoint is checked before any POST — and before the rate-limit wait, since it is not a request. Rejection reasons go to the log only. -One exception, as in Otzaria: an app report carrying the consented crash `minidump` +Schema 2 app reports retain their full outbox file on server rejection and stop with +a visible message; their 10 MiB per attachment / 20 MiB total policy never strips a +minidump or truncates diagnostics/logs. Validation precedes sending, and the 128 MiB +request envelope covers JSON escaping. Existing schema 1 behavior remains below. + +One legacy exception, as in Otzaria: a schema 1 app report carrying the consented crash `minidump` that gets a 413, or a 422 naming `attachments.minidump`, is re-sent once without the dump (after the window wait), and only that answer decides the file's fate. If the run stops after the dump was dropped (a transient answer, a timeout, a network error or diff --git a/error_reports_manager/README.md b/error_reports_manager/README.md index b7171041..6c1a3323 100644 --- a/error_reports_manager/README.md +++ b/error_reports_manager/README.md @@ -24,14 +24,14 @@ Flutter), במקביל ל-`custom_apps_manager`. נוסף על נשיאת הדיווחים של אוצריא, החבילה שולחת גם דיווחים על **הלאנצ'ר עצמו** — פורט של "דיווח על התוכנה" של אוצריא (`lib/app_report/`), עם אותו -חוזה (`POST https://otzaria.org/api/app-reports`, schema 1) ועם שדה אחד +חוזה (`POST https://otzaria.org/api/app-reports`, schema 2; דיווחים ישנים שומרים schema 1) ועם שדה אחד נוסף: `"product": "offline-update"`. האתר מנתב לפיו את הדיווח ל-issue בריפו `Otzaria/Otzaria_Offline_update`. דיווח בלי השדה הוא של אוצריא, ולכן `UserStateReportQueue` מוחק אותו מכל דיווח שנאסף מהתור של אוצריא. | | | | --- | --- | -| `AppReportService` | שליחה, תור והיסטוריה. 2xx עם `success:true` — נשלח (עם `issueNumber`/`issueUrl`/`merged`/`issuePending`); 409 — מזהה חדש ושליחה חוזרת; 400/413/422 — דחייה סופית; 429/5xx/רשת/זמן קצוב — לתור. שליחה מיידית, ושליחת התור בעלייה ואחת ל-5 דקות (עד 4 בקשות בסבב ברקע ו-8 ב"שלח עכשיו"; עוצרת בכשל הזמני הראשון; `FlushOutcome` נושא גם `failed` — שגיאה מקומית — ו-`dropped` — נדחו והוסרו). נעילה לפי מזהה דיווח, וההיסטוריה נכתבת בטור | +| `AppReportService` | שליחה, תור והיסטוריה. 2xx עם `success:true` — נשלח (עם `issueNumber`/`issueUrl`/`merged`/`issuePending`); 409 — מזהה חדש ושליחה חוזרת; 400/413/422 — דחייה: בגרסה 2 התוכן נשמר לתיקון, ובגרסה 1 התור נשאר עם ההתנהגות הישנה; 429/5xx/רשת/זמן קצוב — לתור. שליחה מיידית, ושליחת התור בעלייה ואחת ל-5 דקות (עד 4 בקשות בסבב ברקע ו-8 ב"שלח עכשיו"; עוצרת בכשל הזמני הראשון; `FlushOutcome` נושא גם `failed` — שגיאה מקומית או דיווח חדש שנדחה ונשמר — ו-`dropped` — נדחו והוסרו). נעילה לפי מזהה דיווח, וההיסטוריה נכתבת בטור | | איפה | `/reports/launcher/pending/..json` לכל דיווח בתור (כולל הצרופות; הסדר והספירה נקראים משם הקובץ בלבד, בלי פענוח), ו-`sent.json` להיסטוריה: 100 האחרונים בלי צרופות, ומונה כולל. כתיבה לקובץ זמני ואז `rename`, וקבצי `.tmp` שנשארו מנוקים בעלייה; קובץ פגום מועבר ל-`.bad` ואינו נספר | | רקע | סבב אחד לכל היותר (קריאה בזמן סבב מצטרפת אליו), עד 4 בקשות בסבב ברקע ו-8 ב"שלח עכשיו" — השרת מאפשר 8 בדקה, והמכסה משותפת להעלאת דיווחי אוצריא. כל רשומה עטופה: שגיאת דיסק נרשמת ב-`log` בלבד, כי שורת שגיאה שלא נתפסה היא ראיה לקריסה. ב-409 חוזר 3 פעמים הדיווח מוסר | | סדר הכתיבה | בהצלחה — קודם ההיסטוריה ורק אז מחיקת קובץ התור; `submitPendingReport` מוחק רק אחרי תוצאה סופית. כשל קריאה זמני של `sent.json` (למשל אנטי-וירוס) מנוסה שוב ואז מבטל את הכתיבה — לעולם אינו נחשב "היסטוריה ריקה"; קובץ פגום באמת מועבר ל-`.bad` | @@ -95,9 +95,9 @@ Flutter), במקביל ל-`custom_apps_manager`. | | | | --- | --- | -| קריאה | `pending_reports` בסוגי `error_reports_queue/pending_reports`, `app_reports_queue/pending_reports`, `plugin_reports_queue/pending_reports`, עם `busy_timeout=5000` | +| קריאה | `pending_reports` בסוגי `error_reports_queue/pending_reports`, `app_reports_queue/pending_reports`, `app_reports_queue/pending_reports_v2`, `plugin_reports_queue/pending_reports`, עם `busy_timeout=5000` | | איפה זה רץ | כל עבודת ה-SQLite — פתיחה, בדיקת הסכמה, פענוח, ה-digest והסימון — ב-`Isolate.run` (מוזרק: `runIsolated`); רק כתיבת הקבצים לתיבה נשארת ב-isolate הראשי, אסינכרונית. FFI סינכרוני ב-isolate של הממשק מקפיא אותו בעלייה (AGENTS §5.9) | -| שמירת סכמה | `reportsQueueFormat` מ-`otzaria_capabilities.json` (C1) שאינו 1, או בלי הטבלה — לא נוגעים, אין הצעה. בלי הקובץ (אוצריא ישנה): `PRAGMA user_version` גבוה מ-`knownSchemaVersion` (1) | +| שמירת סכמה | `reportsQueueFormat` מ-`otzaria_capabilities.json` (C1) שאינו 1 או 2, או בלי הטבלה — לא נוגעים, אין הצעה. בלי הקובץ (אוצריא ישנה): `PRAGMA user_version` גבוה מ-`knownSchemaVersion` (2) | | קריאה בזיכרון | המעבר הראשון שומר לכל שורה רק מזהה ו-SHA-256 של ה-payload; כל דיווח נקרא ומקודד שוב ב-isolate משלו רק לפני כתיבתו לתיבה | | ההיסטוריה | הרשומה שעוברת ל-`sent_reports` מקבלת `carriedBy: "offline-update"` ו-`carriedAt` (C3), ואוצריא מציגה אותה "הועבר לשליחה דרך עדכוני אוצריא" | | דיווח שלא יישלח | `schemaVersion` חדש מ-2, `fromJson` שנכשל, surrogate בודד (אין digest), גוף מעל 256KB — נשאר בתור | @@ -150,6 +150,34 @@ Flutter), במקביל ל-`custom_apps_manager`. `source` של `test/fixtures/api_payload_golden.json`. גרסת סכמה חדשה (3) פירושה שהפורט אינו מכיר את הדיווח, והוא נשאר בתור. + +## תאימות ומגבלות צרופות + +`AppReport.schema` נשמר גם ברשומה המקומית וגם בגוף הבקשה. רשומה בלי השדה היא +דיווח ישן עם schema 1; אין לשכתב את הסכמה בזמן איסוף או ניסיון שליחה חוזר. +דיווחים חדשים הם schema 2: עד 10 MiB לקובץ ועד 20 MiB לכל הצרופות יחד, +כאשר 1 MiB הוא 1,048,576 בתים. גם אבחון ולוג מוגבלים ל־10 MiB כל אחד, ללא קיצוץ שקט. הסכום כולל תמונות, dump לפני דחיסת gzip, +אבחון ב־JSON קומפקטי ב־UTF-8 ויומן ב־UTF-8 אחרי הקיצוץ הקיים. GIF נשמר כמו שהוא. +תקציב גוף הבקשה כולל את הרחבת base64, את תקורת gzip ואת שדות הדיווח. + +הלקוח מציין `reportsQueueFormat: 2`. המעדכן תומך בפורמטים 1 ו־2. רשומות התור החדשות נשמרות בסוג +`app_reports_queue/pending_reports_v2`, שאוסף ישן אינו בוחר אפילו כאשר +קובץ היכולות חסר או נדרס בלקוח ישן. האוסף החדש קורא את שני סוגי התור +ושומר את הסכמה המקורית ואת יעד ההיסטוריה. +סדר ההפצה: שרת שמקבל schema 1 ו־2, אחריו גרסת המעדכן הזאת, ואחריה לקוח +שמייצר schema 2. שרת תואם ממשיך לקבל תורים ישנים עם מדיניות הצרופות הישנה. +תקרת גוף הבקשה היא 128 MiB כדי לכלול גם הרחבת תווי בקרה ב־JSON; גבולות הצרופות נבדקים בנפרד. דחיית שרת בגרסה 2 משאירה את הדיווח וכל הצרופות בתור, ומוצגת למשתמש; אין הסרה אוטומטית של dump. + +`test/fixtures/app_report_schema2.json` הופק מ־`AppReport.toApiPayload` בחבילת +`otzaria_report_contract`; אותו וקטור נבדק גם באוצריא ובאתר. + +מסד הנתונים בגרסה 2 מוסיף טבלאות טיוטה בלבד; המעדכן קורא גם את מסד גרסה 1 הישן. +טיוטות נמצאות בטבלאות `report_drafts` ו־`report_draft_attachments` המקומיות. +האוסף קורא רק את סוגי תור השליחה המפורשים (כולל סוג התוכנה החדש); גם טיוטה ישנה +מסוג `app_reports_queue/draft` אינה נבחרת. רק העברה מכוונת של דיווח לתור +יוצרת רשומה שנאספת. בדיקות SQLite מאמתות שהטיוטות והצרופות אינן מועתקות +ואינן משתנות, ושדיווחים ממתינים קיימים ממשיכים להיאסף. + ## תיבת היציאה `/reports/outbox` — **לא** תחת `mirror/`. ניקוי המראה diff --git a/error_reports_manager/lib/src/launcher_report/app_report_service.dart b/error_reports_manager/lib/src/launcher_report/app_report_service.dart index fe89e4f6..aae2ad87 100644 --- a/error_reports_manager/lib/src/launcher_report/app_report_service.dart +++ b/error_reports_manager/lib/src/launcher_report/app_report_service.dart @@ -209,7 +209,11 @@ class AppReportService { ); case _AttemptKind.permanent: case _AttemptKind.idConflict: - await _deletePendingFile(originalId); + if (current.schema == 1) { + await _deletePendingFile(originalId); + } else { + await _keepQueued(originalId, current, idChanges); + } _notify(); return AppReportDeliveryResult( status: AppReportDeliveryStatus.failed, @@ -238,13 +242,24 @@ class AppReportService { int idChanges, ) async { final existing = await _findPending(originalId); - if (existing != null && report.reportId == originalId) return; - if (existing != null) await _deletePendingFile(originalId); + if (existing != null && report.reportId == originalId) { + if (report.schema == 1) return; + await _writePending(report, + queuedAt: existing.stamp, idChanges: idChanges); + _notify(); + return; + } + if (existing != null && report.schema == 1) { + await _deletePendingFile(originalId); + } await _writePending( report, queuedAt: existing?.stamp, idChanges: idChanges, ); + if (existing != null && report.schema != 1) { + await _deletePendingFile(originalId); + } _notify(); } @@ -355,6 +370,7 @@ class AppReportService { ); if (step == _FlushStep.sent) sent++; if (step == _FlushStep.dropped) dropped++; + if (step == _FlushStep.retained) failed++; if (step == _FlushStep.skipped) skipped++; if (step == _FlushStep.transient) { transient = true; @@ -396,6 +412,7 @@ class AppReportService { return _FlushStep.sent; case _AttemptKind.idConflict: if (read.idChanges + 1 >= maxIdChanges) { + if (queued.schema != 1) return _FlushStep.retained; log?.call('App report id conflict kept recurring, removed'); await _deleteQuietly(File(meta.path)); return _FlushStep.dropped; @@ -410,6 +427,10 @@ class AppReportService { await _deleteQuietly(File(meta.path)); return _FlushStep.skipped; case _AttemptKind.permanent: + if (queued.schema != 1) { + log?.call('App report rejected, retained: ${attempt.httpStatus}'); + return _FlushStep.retained; + } log?.call('App report rejected, removed: ${attempt.httpStatus}'); await _deleteQuietly(File(meta.path)); return _FlushStep.dropped; @@ -739,7 +760,7 @@ class AppReportService { final body = payload.bytes; if (body == null) { log?.call('App report payload invalid: ${payload.error}'); - return const _Attempt(_AttemptKind.permanent); + return _Attempt(_AttemptKind.permanent, rejectedField: payload.error); } if (body.length > AppReport.maxRequestBytes) { return const _Attempt( @@ -867,9 +888,15 @@ class _EncodedBody { _EncodedBody _encodeForSending(AppReport report) { try { final stamped = report.copyWith(product: AppReport.offlineUpdateProduct); + if (stamped.schema != 1) { + final invalidField = stamped.validate(); + if (invalidField != null) return _EncodedBody.failed(invalidField); + } return _EncodedBody( utf8.encode(jsonEncode(stamped.toApiPayload())), - heavy: report.images.isNotEmpty || report.minidump != null, + heavy: report.images.isNotEmpty || + report.minidump != null || + report.otherAttachmentBytes > AppReport.maxBodyBytes, ); } catch (error) { return _EncodedBody.failed('$error'); @@ -916,7 +943,7 @@ _PendingDecoded _decodePendingFile(String path, _PendingDecode mode) { } } -enum _FlushStep { sent, skipped, dropped, transient } +enum _FlushStep { sent, skipped, dropped, retained, transient } class _SentHistory { _SentHistory(this.total, this.reports); diff --git a/error_reports_manager/lib/src/port/app_report.dart b/error_reports_manager/lib/src/port/app_report.dart index c0da429d..5d160934 100644 --- a/error_reports_manager/lib/src/port/app_report.dart +++ b/error_reports_manager/lib/src/port/app_report.dart @@ -51,6 +51,7 @@ class AppReport { required this.appVersion, required this.platform, required this.createdAt, + this.schema = schemaVersion, this.description = '', this.stepsToReproduce = '', this.reporterEmail = '', @@ -71,7 +72,7 @@ class AppReport { this.sentAt, }); - static const int schemaVersion = 1; + static const int schemaVersion = 2; /// ערך `product` בדיווחים של הלאנצ'ר על עצמו — האתר מנתב לפיו לריפו שלו. /// דיווח בלעדיו הוא של אוצריא, ולכן דיווחים שנאספו מאוצריא לא מקבלים אותו. @@ -84,14 +85,16 @@ class AppReport { static const int maxArchLength = 20; static const int maxSentryEventIdLength = 64; - /// גבולות בבייטים; מחושבים ב-1000 כדי להישאר מתחת לגבול השרת בכל פירוש. - static const int maxDiagnosticsBytes = 300 * 1000; - static const int maxErrorLogBytes = 250 * 1000; + /// Schema 2 counts all attachments in binary MiB, without truncating them. + static const int maxDiagnosticsBytes = 10 * 1024 * 1024; + static const int maxErrorLogBytes = 10 * 1024 * 1024; + static const int legacyMaxDiagnosticsBytes = 300 * 1000; + static const int legacyMaxErrorLogBytes = 250 * 1000; static const int maxBodyBytes = 700 * 1000; - static const int maxRequestBytes = maxBodyBytes + - AppReportImage.maxPayloadBytes + - AppReportMinidump.maxPayloadBytes; + /// Includes worst-case JSON escaping (six bytes per control character), + /// base64, gzip overhead and metadata. Attachment validation runs first. + static const int maxRequestBytes = 128 * 1024 * 1024; static const Set platforms = { 'windows', @@ -102,6 +105,7 @@ class AppReport { }; final String reportId; + final int schema; final AppReportType type; final AppReportTrigger trigger; final String title; @@ -161,6 +165,7 @@ class AppReport { /// שם השדה הראשון שהשרת ידחה (422), או null כשהדיווח תקין לשליחה. String? validate() { + if (schema != 1 && schema != schemaVersion) return 'schema'; if (reportId.isEmpty || reportId.length > 100) return 'reportId'; if (title.trim().isEmpty) return 'title'; final email = reporterEmail.trim(); @@ -171,26 +176,83 @@ class AppReport { return 'reporterEmail'; } if (appVersion.trim().isEmpty) return 'appVersion'; + final imageLimit = + schema == 1 ? AppReportImage.legacyMaxBytes : AppReportImage.maxBytes; + if (images.length > AppReportImage.maxCount || + images.any((image) => image.bytes.length > imageLimit)) { + return 'attachments.images'; + } + final imageBytes = images.fold( + 0, + (sum, image) => sum + image.bytes.length, + ); + if (schema == 1) { + if (imageBytes > AppReportImage.legacyMaxTotalBytes) { + return 'attachments.images'; + } + // Legacy queues may contain dumps produced before raw size was tracked. + if (minidump != null && + minidump!.gzipBytes.length > + AppReportMinidump.legacyMaxRawBytes + + AppReportMinidump.compressionAllowance) { + return 'attachments.minidump'; + } + } else { + if (diagnostics != null && + _utf8Length(jsonEncode(diagnostics)) > maxDiagnosticsBytes) { + return 'attachments.diagnostics'; + } + if (errorLog != null && _utf8Length(errorLog!) > maxErrorLogBytes) { + return 'attachments.errorLog'; + } + final dump = minidump; + if (dump != null && + (dump.rawByteLength == null || + dump.rawByteLength! > AppReportMinidump.maxRawBytes || + dump.gzipBytes.length > + AppReportMinidump.maxRawBytes + + AppReportMinidump.compressionAllowance)) { + return 'attachments.minidump'; + } + if (imageBytes + otherAttachmentBytes > AppReportImage.maxTotalBytes) { + return 'attachments'; + } + } return null; } - /// גוף הבקשה לשרת, חתוך לגבולות החוזה ולגבול הגוף הכולל. - Map toApiPayload() { + /// Counts complete text for schema 2 and legacy truncation for schema 1, + /// without allocating image base64 during form budget checks. + int get otherAttachmentBytes { + final attachments = _textPayload()['attachments'] as Map?; + final diag = attachments?['diagnostics']; + final log = attachments?['errorLog']; + return (diag == null ? 0 : _utf8Length(jsonEncode(diag))) + + (log is String ? _utf8Length(log) : 0) + + (minidump?.rawByteLength ?? 0); + } + + /// גוף הבקשה לשרת; חיתוך צרופות נשמר רק לתאימות schema 1. + Map toApiPayload() => _addImages(_textPayload()); + + Map _textPayload() { final payload = _basePayload(); final attachments = {}; final diag = diagnostics; if (diag != null) { - attachments['diagnostics'] = _utf8Length(jsonEncode(diag)) <= - maxDiagnosticsBytes + attachments['diagnostics'] = schema != 1 || + _utf8Length(jsonEncode(diag)) <= legacyMaxDiagnosticsBytes ? diag : {'truncated': true, 'reason': 'diagnostics exceeded size limit'}; } final log = errorLog; if (log != null && log.isNotEmpty) { - attachments['errorLog'] = keepTailBytes(log, maxErrorLogBytes); + attachments['errorLog'] = + schema == 1 ? keepTailBytes(log, legacyMaxErrorLogBytes) : log; } - if (attachments.isEmpty) return _addImages(payload); + if (attachments.isEmpty) return payload; payload['attachments'] = attachments; + if (schema != 1) return payload; // מעבר לגבול הכולל — מקצרים קודם את הלוג (מהישן), ורק אז מוותרים על האבחון. var overflow = _utf8Length(jsonEncode(payload)) - maxBodyBytes; @@ -205,10 +267,10 @@ class AppReport { overflow = _utf8Length(jsonEncode(payload)) - maxBodyBytes; } if (overflow > 0) attachments.remove('diagnostics'); - _addImages(payload); return payload; } + /// Binary data is encoded only when constructing the actual request. Map _addImages(Map payload) { final attachments = (payload['attachments'] as Map?) ?? {}; @@ -228,7 +290,7 @@ class AppReport { Map _basePayload() { final email = reporterEmail.trim(); return { - 'schema': schemaVersion, + 'schema': schema, if (product != null && product!.isNotEmpty) 'product': product, 'reportId': reportId, 'type': type.name, @@ -267,6 +329,7 @@ class AppReport { factory AppReport.fromJson(Map json) { final diagnostics = json['diagnostics']; return AppReport( + schema: json['schema'] is int ? json['schema'] as int : 1, reportId: '${json['reportId'] ?? ''}', type: AppReportType.parse(json['type']), trigger: AppReportTrigger.parse(json['trigger']), @@ -303,6 +366,7 @@ class AppReport { /// הרשומה המלאה לתור המקומי, כולל שדות התוצאה. Map toJson() => { + 'schema': schema, 'reportId': reportId, 'type': type.name, 'trigger': trigger.wireName, @@ -334,6 +398,7 @@ class AppReport { static const Object _unset = Object(); AppReport copyWith({ + int? schema, String? reportId, AppReportType? type, String? title, @@ -354,6 +419,7 @@ class AppReport { Object? sentAt = _unset, }) { return AppReport( + schema: schema ?? this.schema, reportId: reportId ?? this.reportId, type: type ?? this.type, trigger: trigger, diff --git a/error_reports_manager/lib/src/port/app_report_image.dart b/error_reports_manager/lib/src/port/app_report_image.dart index 5a6495ec..86ddad2c 100644 --- a/error_reports_manager/lib/src/port/app_report_image.dart +++ b/error_reports_manager/lib/src/port/app_report_image.dart @@ -12,9 +12,12 @@ class AppReportImage { /// מספר התמונות המרבי בדיווח אחד. static const int maxCount = 5; - /// גבולות בבייטים; מחושבים ב-1000 כדי להישאר מתחת לגבול השרת (MiB). - static const int maxBytes = 5 * 1000 * 1000; - static const int maxTotalBytes = 15 * 1000 * 1000; + /// גבולות בבייטים לפי MiB, זהים לחוזה של אוצריא והשרת. + static const int megabyte = 1024 * 1024; + static const int maxBytes = 10 * megabyte; + static const int legacyMaxBytes = 5 * megabyte; + static const int maxTotalBytes = 20 * megabyte; + static const int legacyMaxTotalBytes = 15 * megabyte; /// הנפח המרבי של התמונות בגוף הבקשה: base64 ועוד שם וסוג לכל תמונה. static const int maxPayloadBytes = @@ -99,11 +102,13 @@ enum AppReportImageRejection { tooLarge, tooMany, totalTooLarge } ({List images, AppReportImageRejection? rejection}) mergeAppReportImages( List existing, - List incoming, -) { + List incoming, { + int otherAttachmentBytes = 0, +}) { AppReportImageRejection? rejection; final images = [...existing]; - var total = images.fold(0, (sum, image) => sum + image.bytes.length); + var total = images.fold( + otherAttachmentBytes, (sum, image) => sum + image.bytes.length); for (final image in incoming) { if (image.bytes.length > AppReportImage.maxBytes) { rejection ??= AppReportImageRejection.tooLarge; diff --git a/error_reports_manager/lib/src/port/app_report_minidump.dart b/error_reports_manager/lib/src/port/app_report_minidump.dart index 161d9dd5..bf7c51e6 100644 --- a/error_reports_manager/lib/src/port/app_report_minidump.dart +++ b/error_reports_manager/lib/src/port/app_report_minidump.dart @@ -4,15 +4,33 @@ import 'dart:typed_data'; class AppReportMinidump { const AppReportMinidump({required this.gzipBytes, required this.fileName}); - static const int maxRawBytes = 16 * 1000 * 1000; + static const int maxRawBytes = 10 * 1024 * 1024; + static const int legacyMaxRawBytes = 16 * 1024 * 1024; + // gzip can grow for incompressible input at the exact raw file limit. + static const int compressionAllowance = 64 * 1024; - static const int maxPayloadBytes = (maxRawBytes + 2) ~/ 3 * 4 + 1024; + /// הנפח המרבי בגוף הבקשה: base64 של dump שלא התכווץ, ועוד השם. + static const int maxPayloadBytes = + (maxRawBytes + compressionAllowance + 2) ~/ 3 * 4 + 1024; static const int maxFileNameLength = 200; final Uint8List gzipBytes; final String fileName; + int? get rawByteLength { + if (gzipBytes.length < 18 || + gzipBytes[0] != 0x1f || + gzipBytes[1] != 0x8b || + gzipBytes[2] != 8) { + return null; + } + return ByteData.sublistView(gzipBytes).getUint32( + gzipBytes.length - 4, + Endian.little, + ); + } + Map toJson() => { 'fileName': fileName, 'data': base64Encode(gzipBytes), diff --git a/error_reports_manager/lib/src/services/report_uploader.dart b/error_reports_manager/lib/src/services/report_uploader.dart index f0a3ab50..56734a61 100644 --- a/error_reports_manager/lib/src/services/report_uploader.dart +++ b/error_reports_manager/lib/src/services/report_uploader.dart @@ -125,6 +125,22 @@ class ErrorReportUploader { ); } + final sourceBody = body; + final appEndpoint = + item.endpoint.toString() == OutboxReport.appReportingEndpoint; + final policy = await Isolate.run( + () => _inspectAttachmentPolicy(sourceBody, appEndpoint), + ); + if (policy.invalidField != null) { + return finish( + error: AppL10n.strings.errorReportsDomain.uploadReportKept( + policy.invalidField!.startsWith('attachments') + ? AppL10n.strings.appReports.attachmentsInvalidSnack + : AppL10n.strings.appReports.sendFailedSnack, + ), + ); + } + Map? strippedBody; Future stop({ String? error, @@ -173,7 +189,7 @@ class ErrorReportUploader { _windowCount = batchSize; continue; } - if (_minidumpRejection(attempt)) { + if (!policy.preserveAttachments && _minidumpRejection(attempt)) { final sentBody = body; final stripped = await Isolate.run(() { final withoutMinidump = _withoutMinidump(sentBody); @@ -220,6 +236,13 @@ class ErrorReportUploader { await _removeQuietly(outbox, item); sent++; } else if (_rejectStatuses.contains(status)) { + if (policy.preserveAttachments) { + return stop( + error: AppL10n.strings.errorReportsDomain.uploadReportKept( + AppL10n.strings.errorReportsDomain.uploadHttpStatus(status), + ), + ); + } await _removeQuietly(outbox, item); rejected++; rejections.add(_rejection(item, '$status ${attempt.excerpt}')); @@ -290,7 +313,9 @@ class ErrorReportUploader { Completer abort, ) async { final timeout = report.endpoint.path == '/api/app-reports' && - (report.hasImages || report.hasMinidump) + (report.hasImages || + report.hasMinidump || + body.length > AppReport.maxBodyBytes) ? requestTimeoutWithImages : requestTimeout; final request = http.AbortableRequest( @@ -344,6 +369,34 @@ class ErrorReportUploader { (attempt.statusCode == 422 && attempt.rejectedField == 'attachments.minidump'); + static ({bool preserveAttachments, String? invalidField}) + _inspectAttachmentPolicy(Uint8List bytes, bool appEndpoint) { + if (!appEndpoint) { + return (preserveAttachments: false, invalidField: null); + } + try { + final json = jsonDecode(utf8.decode(bytes)); + if (json is! Map || + json['schema'] == null || + json['schema'] == 1) { + return (preserveAttachments: false, invalidField: null); + } + if (bytes.length > AppReport.maxRequestBytes) { + return (preserveAttachments: true, invalidField: 'attachments'); + } + final attachments = json['attachments']; + final report = AppReport.fromJson({ + ...json, + if (attachments is Map) + for (final field in ['diagnostics', 'errorLog', 'images', 'minidump']) + if (attachments.containsKey(field)) field: attachments[field], + }); + return (preserveAttachments: true, invalidField: report.validate()); + } catch (_) { + return (preserveAttachments: true, invalidField: 'body'); + } + } + static Map? _withoutMinidump(Uint8List bytes) { final decoded = jsonDecode(utf8.decode(bytes)); if (decoded is! Map) return null; diff --git a/error_reports_manager/lib/src/services/user_state_report_queue.dart b/error_reports_manager/lib/src/services/user_state_report_queue.dart index 58f12cc1..e802aa0f 100644 --- a/error_reports_manager/lib/src/services/user_state_report_queue.dart +++ b/error_reports_manager/lib/src/services/user_state_report_queue.dart @@ -179,9 +179,9 @@ class UserStateReportQueue implements OtzariaReportQueue { /// ה-`user_version` שאוצריא כותבת (`UserStateDatabase._schemaVersion`). מסד /// חדש ממנו — לא נוגעים בו בכלל. - static const int knownSchemaVersion = 1; + static const int knownSchemaVersion = 2; - static const int knownQueueFormat = 1; + static const int knownQueueFormat = 2; static const String carriedBy = 'offline-update'; @@ -189,6 +189,7 @@ class UserStateReportQueue implements OtzariaReportQueue { static const String pendingKind = 'error_reports_queue/pending_reports'; static const String sentKind = 'error_reports_queue/sent_reports'; static const String appPendingKind = 'app_reports_queue/pending_reports'; + static const String appPendingKindV2 = 'app_reports_queue/pending_reports_v2'; static const String pluginPendingKind = 'plugin_reports_queue/pending_reports'; static const String counterBox = 'error_reports_queue'; @@ -277,7 +278,11 @@ class UserStateReportQueue implements OtzariaReportQueue { /// `null` = אין מה לגעת בו: אין קובץ, פורמט תור לא מוכר, או בלי הטבלה. static Database? _open(String dbPath, int? queueFormat) { if (!File(dbPath).existsSync()) return null; - if (queueFormat != null && queueFormat != knownQueueFormat) return null; + if (queueFormat != null && + queueFormat != 1 && + queueFormat != knownQueueFormat) { + return null; + } final db = sqlite3.open(dbPath, mode: OpenMode.readWrite); try { db.execute('PRAGMA busy_timeout=5000'); @@ -306,11 +311,11 @@ class UserStateReportQueue implements OtzariaReportQueue { final seen = {}; final statement = db.prepare( 'SELECT id, kind, payload_json FROM pending_reports ' - 'WHERE kind IN (?, ?, ?) ORDER BY id', + 'WHERE kind IN (?, ?, ?, ?) ORDER BY id', ); try { final cursor = statement.selectCursor( - [pendingKind, appPendingKind, pluginPendingKind], + [pendingKind, appPendingKind, appPendingKindV2, pluginPendingKind], ); while (cursor.moveNext()) { final built = _build(cursor.current); @@ -333,7 +338,7 @@ class UserStateReportQueue implements OtzariaReportQueue { final rows = db.select( 'SELECT id, kind, payload_json FROM pending_reports ' 'WHERE id = ? AND kind = ?', - [mark.rowId, mark.kind.pendingKind], + [mark.rowId, mark.pendingKind], ); if (rows.isEmpty) return null; final built = _build(rows.first); @@ -351,8 +356,11 @@ class UserStateReportQueue implements OtzariaReportQueue { try { final decoded = jsonDecode(json); if (decoded is! Map) return null; - final kind = _ReportKind.values - .firstWhere((kind) => kind.pendingKind == row['kind']); + final pendingKind = row['kind'] as String; + final kind = pendingKind == appPendingKindV2 + ? _ReportKind.app + : _ReportKind.values + .firstWhere((kind) => kind.pendingKind == pendingKind); final String id; final String title; final String createdAt; @@ -393,6 +401,7 @@ class UserStateReportQueue implements OtzariaReportQueue { rowId: row['id'] as int, payloadDigest: _digest(json), kind: kind, + pendingKind: pendingKind, reportId: id, ); return ( @@ -449,7 +458,7 @@ class UserStateReportQueue implements OtzariaReportQueue { static bool _markAsSent(Database db, _MarkRow row, int now) { final kind = row.kind; - final pendingKind = kind.pendingKind; + final pendingKind = row.pendingKind; final sentKind = '${kind.box}/sent_reports'; final idOf = _field('json_extract', '\$.${kind.idField}'); final rejection = _field('json_type', r'$.rejectionReason'); @@ -499,10 +508,17 @@ class UserStateReportQueue implements OtzariaReportQueue { } // `deletePendingReport`: כל השורות הממתינות באותו מזהה. - db.execute( - 'DELETE FROM pending_reports WHERE kind = ? AND $idOf = ?', - [pendingKind, reportId], - ); + if (kind == _ReportKind.app) { + db.execute( + 'DELETE FROM pending_reports WHERE kind IN (?, ?) AND $idOf = ?', + [appPendingKind, appPendingKindV2, reportId], + ); + } else { + db.execute( + 'DELETE FROM pending_reports WHERE kind = ? AND $idOf = ?', + [pendingKind, reportId], + ); + } db.execute('COMMIT'); return true; } catch (_) { @@ -552,10 +568,12 @@ class _MarkRow { required this.payloadDigest, required this.reportId, required this.kind, + required this.pendingKind, }); final int rowId; final _ReportKind kind; + final String pendingKind; final String payloadDigest; final String reportId; diff --git a/error_reports_manager/test/app_report_service_test.dart b/error_reports_manager/test/app_report_service_test.dart index 3e35aa7c..82b795bf 100644 --- a/error_reports_manager/test/app_report_service_test.dart +++ b/error_reports_manager/test/app_report_service_test.dart @@ -10,7 +10,12 @@ import 'package:http/testing.dart'; import 'package:path/path.dart' as p; import 'package:test/test.dart'; -AppReport _report({String? id, String title = 'באג'}) => AppReport( +AppReport _report( + {String? id, + String title = 'באג', + int schema = AppReport.schemaVersion}) => + AppReport( + schema: schema, reportId: id ?? AppReport.generateReportId(), type: AppReportType.bug, trigger: AppReportTrigger.manual, @@ -89,7 +94,7 @@ void main() { expect(result.issueNumber, 55); expect(result.merged, isTrue); expect(sentBody!['product'], 'offline-update'); - expect(sentBody!['schema'], 1); + expect(sentBody!['schema'], 2); expect(sentBody!['reportId'], report.reportId); expect(sentBody!['attachments'], { 'diagnostics': {'x': 1}, @@ -144,21 +149,21 @@ void main() { expect((await service.getSentReports()).single.reportId, ids.last); }); - test('409 פעמיים: כשל idConflict, לא נכנס לתור', () async { + test('schema1: 409 פעמיים: כשל idConflict, לא נכנס לתור', () async { final service = build(MockClient((_) async => _json(409, {}))); - final result = await service.send(_report()); + final result = await service.send(_report(schema: 1)); expect(result.isFailed, isTrue); expect(result.failureReason, AppReportFailureReason.idConflict); expect(await service.getPendingReportsCount(), 0); }); - test('422: דחייה קבועה, לא נכנס לתור', () async { + test('schema1: 422: דחייה קבועה, לא נכנס לתור', () async { final service = build( MockClient( (_) async => _json(422, {'error': 'invalid', 'field': 'reporterEmail'}), ), ); - final result = await service.send(_report()); + final result = await service.send(_report(schema: 1)); expect(result.isFailed, isTrue); expect(result.failureReason, AppReportFailureReason.rejected); expect(result.rejectedField, 'reporterEmail'); @@ -167,14 +172,63 @@ void main() { }); for (final status in [400, 413]) { - test('$status: דחייה קבועה', () async { + test('schema1: $status: דחייה קבועה', () async { final service = build(MockClient((_) async => _json(status, {}))); - final result = await service.send(_report()); + final result = await service.send(_report(schema: 1)); expect(result.failureReason, AppReportFailureReason.rejected); expect(await service.getPendingReportsCount(), 0); }); } + for (final status in [400, 409, 413, 422]) { + test('schema 2 rejection $status preserves the complete report on disk', + () async { + final service = build(MockClient( + (_) async => _json(status, {'field': 'attachments.minidump'}))); + final report = _report().copyWith(errorLog: 'complete log'); + final result = await service.send(report); + expect(result.isFailed, isTrue); + expect(await service.getPendingReportsCount(), 1); + final file = + Directory(p.join(AppReportService.dirIn(tmp.path), 'pending')) + .listSync() + .whereType() + .single; + final saved = + (jsonDecode(file.readAsStringSync()) as Map)['report'] as Map; + expect(saved['schema'], 2); + expect(saved['diagnostics'], report.diagnostics); + expect(saved['errorLog'], report.errorLog); + final outcome = await service.flush(); + expect(outcome.sent, 0); + expect(outcome.dropped, 0); + expect(await service.getPendingReportsCount(), 1); + }); + } + + test('schema 2 validates oversized log before sending and keeps its bytes', + () async { + var calls = 0; + final service = build(MockClient((_) async { + calls++; + return _json(200, {'success': true}); + })); + final report = _report().copyWith(errorLog: 'x' * (10 * 1024 * 1024 + 1)); + final result = await service.send(report); + expect(result.isFailed, isTrue); + expect(result.rejectedField, 'attachments.errorLog'); + expect(calls, 0); + expect(await service.getPendingReportsCount(), 1); + final file = Directory(p.join(AppReportService.dirIn(tmp.path), 'pending')) + .listSync() + .whereType() + .single; + expect( + ((jsonDecode(file.readAsStringSync()) as Map)['report'] + as Map)['errorLog'], + report.errorLog); + }); + for (final status in [429, 500, 503]) { test('$status נשמר בתור עם הצרופות', () async { final service = build(MockClient((_) async => http.Response('', status))); @@ -204,7 +258,7 @@ void main() { test('flush: שולח, מסיר נדחים, מחליף מזהה ב-409 ועוצר בכשל זמני', () async { final a = _report(title: 'a'); - final rejected = _report(title: 'rejected'); + final rejected = _report(title: 'rejected', schema: 1); final conflict = _report(title: 'conflict'); final transient = _report(title: 'transient'); final after = _report(title: 'after'); @@ -487,7 +541,7 @@ void main() { expect(outcome.sent, 0); }); - test('409 חוזר: אחרי 3 החלפות מזהה הדיווח מוסר', () async { + test('schema2: אחרי 3 החלפות מזהה הדיווח נשמר לטיפול', () async { final service = build(MockClient((_) async => _json(409, {}))); await service.queueReport(_report()); await service.flush(); @@ -495,7 +549,7 @@ void main() { await service.flush(); expect(await service.getPendingReportsCount(), 1); await service.flush(); - expect(await service.getPendingReportsCount(), 0); + expect(await service.getPendingReportsCount(), 1); expect(await service.getSentReports(), isEmpty); }); @@ -587,8 +641,7 @@ void main() { expect((await service.getSentReports()).single.issueNumber, 5); }); - test('submitPendingReport: כשל זמני משאיר אותו בתור, ודחייה מסירה', - () async { + test('schema2: submitPendingReport משאיר תוכן גם בדחיית שרת', () async { var status = 503; final service = build( MockClient((_) async => http.Response('', status)), @@ -599,7 +652,7 @@ void main() { expect(await service.getPendingReportsCount(), 1); status = 422; expect((await service.submitPendingReport(report)).isFailed, isTrue); - expect(await service.getPendingReportsCount(), 0); + expect(await service.getPendingReportsCount(), 1); }); test('הרשימה בחלון בלי צרופות, והשליחה מהתור כוללת אותן', () async { @@ -747,9 +800,9 @@ void main() { }); group('ספירת תוצאות הסבב', () { - test('דחיית שרת מוסרת ונספרת כ-dropped, לא כ-sent', () async { + test('schema1: דחיית שרת מוסרת ונספרת כ-dropped, לא כ-sent', () async { final service = build(MockClient((_) async => _json(422, {}))); - await service.queueReport(_report()); + await service.queueReport(_report(schema: 1)); final outcome = await service.flush(); expect(outcome.sent, 0); expect(outcome.dropped, 1); @@ -757,9 +810,9 @@ void main() { expect(await service.getPendingReportsCount(), 0); }); - test('409 חוזר: ה-dropped נספר בסבב השלישי', () async { + test('schema1: 409 חוזר: ה-dropped נספר בסבב השלישי', () async { final service = build(MockClient((_) async => _json(409, {}))); - await service.queueReport(_report()); + await service.queueReport(_report(schema: 1)); expect((await service.flush()).dropped, 0); expect((await service.flush()).dropped, 0); expect((await service.flush()).dropped, 1); diff --git a/error_reports_manager/test/fixtures/app_report_schema2.json b/error_reports_manager/test/fixtures/app_report_schema2.json new file mode 100644 index 00000000..e862b43f --- /dev/null +++ b/error_reports_manager/test/fixtures/app_report_schema2.json @@ -0,0 +1,72 @@ +{ + "source": "Otzaria otzaria_report_contract AppReport.toApiPayload schema 2", + "stored": { + "schema": 2, + "reportId": "c3efb70b-1986-4445-aac3-4790a0b1aac8", + "type": "bug", + "trigger": "manual", + "title": "בדיקת צרופות", + "description": "תמונה מונפשת וטקסט בעברית", + "stepsToReproduce": "", + "reporterEmail": "reporter@example.com", + "appVersion": "1.0.0", + "platform": "windows", + "osVersion": "Windows 11", + "createdAt": "2026-11-05T00:00:00.000Z", + "diagnostics": { + "locale": "he", + "הפעלה": true, + "count": 2 + }, + "errorLog": "שורה ראשונה\nsecond line 😀", + "images": [ + { + "fileName": "תמונה מונפשת.gif", + "mimeType": "image/gif", + "data": "R0lGODlhAgACAIEAAP8AAAAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQACgAAACwAAAAAAgACAAAIBgABCAQQEAAh+QQBCgABACwAAAAAAgACAIEAAP8AAAAAAAAAAAAIBgABCAQQEAA7" + } + ], + "minidump": { + "fileName": "fixture.dmp", + "data": "H4sIAAAAAAAAA/N18Q1gYGRiBgBJ1tZGCAAAAA==" + }, + "merged": false, + "duplicate": false, + "issuePending": false + }, + "payload": { + "schema": 2, + "reportId": "c3efb70b-1986-4445-aac3-4790a0b1aac8", + "type": "bug", + "trigger": "manual", + "title": "בדיקת צרופות", + "description": "תמונה מונפשת וטקסט בעברית", + "reporterEmail": "reporter@example.com", + "appVersion": "1.0.0", + "platform": "windows", + "osVersion": "Windows 11", + "createdAt": "2026-11-05T00:00:00.000Z", + "attachments": { + "diagnostics": { + "locale": "he", + "הפעלה": true, + "count": 2 + }, + "errorLog": "שורה ראשונה\nsecond line 😀", + "images": [ + { + "fileName": "תמונה מונפשת.gif", + "mimeType": "image/gif", + "data": "R0lGODlhAgACAIEAAP8AAAAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQACgAAACwAAAAAAgACAAAIBgABCAQQEAAh+QQBCgABACwAAAAAAgACAIEAAP8AAAAAAAAAAAAIBgABCAQQEAA7" + } + ], + "minidump": { + "fileName": "fixture.dmp", + "data": "H4sIAAAAAAAAA/N18Q1gYGRiBgBJ1tZGCAAAAA==" + } + } + }, + "attachmentBytes": 200, + "imageBytes": 111, + "dumpRawBytes": 8 +} diff --git a/error_reports_manager/test/port_test.dart b/error_reports_manager/test/port_test.dart index 9fa65f82..c1c08e62 100644 --- a/error_reports_manager/test/port_test.dart +++ b/error_reports_manager/test/port_test.dart @@ -16,6 +16,47 @@ Map _fixture(String name) => as Map; void main() { + test('schema 2 matches the current Dart contract shared with the server', () { + final fixture = _fixture('app_report_schema2.json'); + final original = + AppReport.fromJson(Map.from(fixture['stored'] as Map)); + final report = + AppReport.fromJson(original.toJson()).copyWith(product: null); + expect(report.validate(), isNull); + expect(report.toApiPayload(), fixture['payload']); + expect(report.otherAttachmentBytes + report.images.single.bytes.length, + fixture['attachmentBytes']); + }); + + test('schema 2 preserves full diagnostics/log at 10/20 MiB byte boundaries', + () { + const limit = 10 * 1024 * 1024; + final original = AppReport.fromJson(Map.from( + _fixture('app_report_schema2.json')['stored'] as Map)); + final diagnostics = {'blob': 'x' * (limit - 11)}; + final log = String.fromCharCode(0) * limit; + final report = original.copyWith( + diagnostics: diagnostics, + errorLog: log, + images: [], + minidump: null, + ); + expect(report.validate(), isNull); + expect(report.otherAttachmentBytes, 2 * limit); + expect(report.toApiPayload()['attachments'], { + 'diagnostics': diagnostics, + 'errorLog': log, + }); + expect(utf8.encode(jsonEncode(report.toApiPayload())).length, + lessThanOrEqualTo(AppReport.maxRequestBytes)); + expect(report.copyWith(errorLog: '${log}x').validate(), + 'attachments.errorLog'); + expect( + report.copyWith( + diagnostics: {'blob': '${diagnostics['blob']}x'}).validate(), + 'attachments.diagnostics'); + }); + group('דיווחי תוכנה ותוספים מול המודלים המקוריים של אוצריא', () { final golden = _fixture('other_reports_golden.json'); test('המקור מתועד', () { diff --git a/error_reports_manager/test/report_uploader_test.dart b/error_reports_manager/test/report_uploader_test.dart index 2cd81224..62fc3260 100644 --- a/error_reports_manager/test/report_uploader_test.dart +++ b/error_reports_manager/test/report_uploader_test.dart @@ -394,6 +394,63 @@ void main() { return outbox; } + Future schema2Outbox({String? log}) async { + final fixture = jsonDecode( + File('test/fixtures/app_report_schema2.json').readAsStringSync()) + as Map; + final body = Map.from(fixture['payload'] as Map); + if (log != null) { + body['attachments'] = {...body['attachments'] as Map, 'errorLog': log}; + } + final outbox = MemoryOutbox([]); + await outbox.write( + 'app-modern', + OutboxReport.encodeFile(OutboxReport.fileJson( + reportId: 'app-modern', + bookTitle: 'Modern report', + createdAt: '2026-11-05T00:00:00Z', + endpoint: OutboxReport.appReportingEndpoint, + body: body, + ))); + return outbox; + } + + for (final status in [400, 413, 422]) { + test('schema 2 HTTP $status retains all data without a stripped retry', + () async { + final outbox = await schema2Outbox(); + final originalBody = outbox.bodyOf(outbox.reports.single); + var calls = 0; + final result = await uploader((_) async { + calls++; + return http.Response( + jsonEncode({'field': 'attachments.minidump'}), status); + }).upload(outbox); + expect(calls, 1); + expect(result.sent, 0); + expect(result.rejected, 0); + expect(result.remaining, 1); + expect(result.error, isNotNull); + expect(outbox.bodyOf(outbox.reports.single), originalBody); + }); + } + + test('schema 2 excess byte is retained and rejected locally before HTTP', + () async { + final outbox = await schema2Outbox(log: 'x' * (10 * 1024 * 1024 + 1)); + final originalBody = outbox.bodyOf(outbox.reports.single); + var calls = 0; + final result = await uploader((_) async { + calls++; + return http.Response(_ok, 200); + }).upload(outbox); + expect(calls, 0); + expect(result.sent, 0); + expect(result.remaining, 1); + expect(result.error, isNotNull); + expect(outbox.bodyOf(outbox.reports.single), originalBody); + }); + test('דיווח תוכנה עם minidump מקבל זמן העלאה ארוך יותר', () async { final outbox = await dumpOutbox(); final sender = ErrorReportUploader( diff --git a/error_reports_manager/test/user_state_report_queue_test.dart b/error_reports_manager/test/user_state_report_queue_test.dart index dfe3f40f..b3afe983 100644 --- a/error_reports_manager/test/user_state_report_queue_test.dart +++ b/error_reports_manager/test/user_state_report_queue_test.dart @@ -11,7 +11,7 @@ import 'package:test/test.dart'; import 'support.dart'; -void _createOtzariaSchema(Database db, {int userVersion = 1}) { +void _createOtzariaSchema(Database db, {int userVersion = 2}) { db.execute(''' CREATE TABLE IF NOT EXISTS lists ( box TEXT NOT NULL, @@ -30,6 +30,17 @@ void _createOtzariaSchema(Database db, {int userVersion = 1}) { ) '''); db.execute('PRAGMA user_version = $userVersion'); + if (userVersion < 2) return; + // Same separate local tables as Otzaria's ReportDraftStore. + db.execute('''CREATE TABLE report_drafts ( + id TEXT PRIMARY KEY, kind TEXT NOT NULL, title TEXT NOT NULL, + payload_json TEXT NOT NULL, created_at INTEGER NOT NULL, + updated_at INTEGER NOT NULL, revision INTEGER NOT NULL + )'''); + db.execute('''CREATE TABLE report_draft_attachments ( + draft_id TEXT PRIMARY KEY REFERENCES report_drafts(id) ON DELETE CASCADE, + payload_json TEXT NOT NULL + )'''); } Map _stored(String id, @@ -59,7 +70,7 @@ void main() { }); tearDown(() => temp.deleteSync(recursive: true)); - Database create({int userVersion = 1}) { + Database create({int userVersion = 2}) { final db = sqlite3.open(dbPath); _createOtzariaSchema(db, userVersion: userVersion); return db; @@ -100,6 +111,136 @@ void main() { } } + test( + 'local drafts and their attachments are never collected, explicit queued reports are', + () async { + final fixture = jsonDecode( + File('test/fixtures/app_report_schema2.json').readAsStringSync()) + as Map; + final app = Map.from(fixture['stored'] as Map); + final book = _stored('book-draft'); + final db = create(); + for (final (id, kind, payload) in [ + ('app-draft', 'app', app), + ('book-draft', 'book', book), + ]) { + db.execute('INSERT INTO report_drafts VALUES (?,?,?,?,0,0,1)', + [id, kind, 'unfinished', jsonEncode(payload)]); + db.execute('INSERT INTO report_draft_attachments VALUES (?,?)', [ + id, + jsonEncode({'images': app['images'], 'localOnly': 'draft-secret'}) + ]); + } + // A fully valid legacy draft must also remain local, even though its old + // storage uses pending_reports with a different kind. + insert(db, 'app_reports_queue/draft', app); + insert(db, pending, _stored('old-pending')); + insert(db, pending, _stored('explicitly-queued')); + insert(db, UserStateReportQueue.appPendingKindV2, app); + final draftRows = db + .select('SELECT * FROM report_drafts ORDER BY id') + .map((r) => Map.from(r)) + .toList(); + final attachmentRows = db + .select('SELECT * FROM report_draft_attachments ORDER BY draft_id') + .map((r) => Map.from(r)) + .toList(); + db.close(); + + final outbox = MemoryOutbox(const []); + final queue = UserStateReportQueue(dbPath, reportsQueueFormat: 2); + expect(await queue.countSendable(), 3); + expect((await queue.collectTo(outbox)).collected, 3); + expect(outbox.reports.map((r) => r.reportId), + ['old-pending', 'explicitly-queued', 'app-${app['reportId']}']); + expect(outbox.bodyOf(outbox.reports.last), fixture['payload']); + for (final report in outbox.reports) { + expect( + jsonEncode(outbox.bodyOf(report)), isNot(contains('draft-secret'))); + } + expect(rows('app_reports_queue/draft'), [app]); + final after = sqlite3.open(dbPath); + try { + expect( + after + .select('SELECT * FROM report_drafts ORDER BY id') + .map((r) => Map.from(r)) + .toList(), + draftRows); + expect( + after + .select( + 'SELECT * FROM report_draft_attachments ORDER BY draft_id') + .map((r) => Map.from(r)) + .toList(), + attachmentRows); + } finally { + after.close(); + } + }); + + for (final userVersion in [1, 2]) { + for (final queueFormat in [null, 1, 2]) { + test('DB $userVersion, queue format $queueFormat preserves both schemas', + () async { + final fixture = jsonDecode(File('test/fixtures/app_report_schema2.json') + .readAsStringSync()) as Map; + final schema2 = Map.from(fixture['stored'] as Map); + final schema1 = {...schema2, 'reportId': 'legacy'}..remove('schema'); + final db = create(userVersion: userVersion); + insert(db, UserStateReportQueue.appPendingKind, schema1); + insert(db, UserStateReportQueue.appPendingKindV2, schema2); + db.close(); + final outbox = MemoryOutbox(const []); + final queue = + UserStateReportQueue(dbPath, reportsQueueFormat: queueFormat); + expect((await queue.collectTo(outbox)).collected, 2); + expect(outbox.bodyOf(outbox.reports[0])['schema'], 1); + expect(outbox.bodyOf(outbox.reports[1])['schema'], 2); + expect(rows(UserStateReportQueue.appPendingKind), isEmpty); + expect(rows(UserStateReportQueue.appPendingKindV2), isEmpty); + expect(rows('app_reports_queue/sent_reports').length, 2); + }); + } + } + + test( + '20 MiB payload survives real queue and outbox; an excess byte stays pending', + () async { + const limit = 10 * 1024 * 1024; + final fixture = jsonDecode( + File('test/fixtures/app_report_schema2.json').readAsStringSync()) + as Map; + final data = base64Encode(Uint8List(limit)); + final stored = { + ...Map.from(fixture['stored'] as Map), + 'images': [ + {'fileName': 'first.gif', 'mimeType': 'image/gif', 'data': data}, + {'fileName': 'second.gif', 'mimeType': 'image/gif', 'data': data}, + ], + } + ..remove('diagnostics') + ..remove('errorLog') + ..remove('minidump'); + final db = create(); + insert(db, UserStateReportQueue.appPendingKindV2, stored); + insert(db, UserStateReportQueue.appPendingKindV2, + {...stored, 'reportId': 'excess', 'errorLog': 'x'}); + db.close(); + final queue = UserStateReportQueue(dbPath, reportsQueueFormat: 2); + expect(await queue.countSendable(), 1); + final outbox = MemoryOutbox(const []); + expect((await queue.collectTo(outbox)).collected, 1); + final payload = outbox.bodyOf(outbox.reports.single); + expect(payload['schema'], 2); + expect( + ((payload['attachments'] as Map)['images'] as List) + .map((i) => base64Decode(i['data'] as String).length), + [limit, limit]); + expect(rows(UserStateReportQueue.appPendingKindV2).single['reportId'], + 'excess'); + }); + test('כל עבודת ה-SQLite עוברת ב-isolate, ובאיסוף שורה אחת בכל פעם', () async { final db = create(); insert(db, pending, _stored('a')); @@ -559,7 +700,7 @@ void main() { db.close(); final before = File(dbPath).readAsBytesSync(); - final queue = UserStateReportQueue(dbPath, reportsQueueFormat: 2); + final queue = UserStateReportQueue(dbPath, reportsQueueFormat: 3); expect(await queue.countSendable(), 0); expect((await queue.collectTo(MemoryOutbox(const []))).collected, 0); expect(File(dbPath).readAsBytesSync(), before); diff --git a/launcher_app/lib/src/screens/app_report/app_report_dialog.dart b/launcher_app/lib/src/screens/app_report/app_report_dialog.dart index fe06bced..62033f6c 100644 --- a/launcher_app/lib/src/screens/app_report/app_report_dialog.dart +++ b/launcher_app/lib/src/screens/app_report/app_report_dialog.dart @@ -280,6 +280,7 @@ class _AppReportDialogState extends State { const SizedBox(height: AppTokens.spaceMD), AppReportImagesSection( images: form.images, + otherAttachmentBytes: form.buildReport().otherAttachmentBytes, enabled: enabled, source: widget.imageSource, onChanged: (images) => form.update(images: images), diff --git a/launcher_app/lib/src/screens/app_report/app_report_images_section.dart b/launcher_app/lib/src/screens/app_report/app_report_images_section.dart index 6bda2c43..82cd867c 100644 --- a/launcher_app/lib/src/screens/app_report/app_report_images_section.dart +++ b/launcher_app/lib/src/screens/app_report/app_report_images_section.dart @@ -111,12 +111,14 @@ class AppReportImagesSection extends StatelessWidget { required this.images, required this.onChanged, this.enabled = true, + this.otherAttachmentBytes = 0, this.source = const AppReportImageSource(), }); final List images; final ValueChanged> onChanged; final bool enabled; + final int otherAttachmentBytes; final AppReportImageSource source; Future _pick(BuildContext context) async { @@ -130,7 +132,8 @@ class AppReportImagesSection extends StatelessWidget { return; } if (!enabled) return; - final merged = mergeAppReportImages(images, picked.images); + final merged = mergeAppReportImages(images, picked.images, + otherAttachmentBytes: otherAttachmentBytes); // הודעה אחת בכל פעם (`UiSnack` ללא תור): קובץ שלא נקרא קודם לשאר. if (picked.unreadable > 0) { UiSnack.showError(t.imageReadFailed); @@ -138,7 +141,8 @@ class AppReportImagesSection extends StatelessWidget { switch (picked.limit ?? merged.rejection) { case AppReportImageRejection.totalTooLarge: UiSnack.showError( - t.imagesTotalTooLarge(AppReportImage.maxTotalBytes ~/ 1000000), + t.imagesTotalTooLarge( + AppReportImage.maxTotalBytes ~/ AppReportImage.megabyte), ); case AppReportImageRejection.tooMany: UiSnack.showError(t.tooManyImages(AppReportImage.maxCount)); @@ -146,7 +150,8 @@ class AppReportImagesSection extends StatelessWidget { case null: if (picked.tooLarge || merged.rejection != null) { UiSnack.showError( - t.imageTooLarge(AppReportImage.maxBytes ~/ 1000000), + t.imageTooLarge( + AppReportImage.maxBytes ~/ AppReportImage.megabyte), ); } } @@ -195,6 +200,8 @@ class AppReportImagesSection extends StatelessWidget { ), ), ), + const SizedBox(height: AppTokens.spaceSM), + Text(t.attachmentLimitsHint, style: theme.textTheme.bodySmall), if (images.isNotEmpty) ...[ const SizedBox(height: AppTokens.spaceSM), Wrap( diff --git a/launcher_app/lib/src/screens/app_report/app_report_result_snack.dart b/launcher_app/lib/src/screens/app_report/app_report_result_snack.dart index ca28fa60..b77b27b7 100644 --- a/launcher_app/lib/src/screens/app_report/app_report_result_snack.dart +++ b/launcher_app/lib/src/screens/app_report/app_report_result_snack.dart @@ -32,6 +32,12 @@ String appReportInvalidFieldMessage(String field, {required bool emailEmpty}) { 'title' => t.titleRequiredSnack, 'description' => t.descriptionRequiredSnack, 'reporterEmail' => emailEmpty ? t.emailRequiredSnack : t.invalidEmailSnack, + 'attachments' || + 'attachments.images' || + 'attachments.diagnostics' || + 'attachments.errorLog' || + 'attachments.minidump' => + t.attachmentsInvalidSnack, _ => t.sendFailedSnack, }; } diff --git a/launcher_app/test/app_reports_test.dart b/launcher_app/test/app_reports_test.dart index 948dd156..eeb23a7b 100644 --- a/launcher_app/test/app_reports_test.dart +++ b/launcher_app/test/app_reports_test.dart @@ -1295,10 +1295,10 @@ void main() { write('d.png', big), write('e.png', 20), ]); - // כמו `mergeAppReportImages`: d נדחה, e עדיין נכנס. + // c ו-d חורגים מ-20 MiB; e עדיין נכנס בדיוק בגבול. expect( picked.images.map((i) => i.fileName), - ['a.png', 'b.png', 'c.png', 'e.png'], + ['a.png', 'b.png', 'e.png'], ); expect(picked.limit, AppReportImageRejection.totalTooLarge); expect(picked.unreadable, 0); diff --git a/otzaria_l10n/lib/src/app_strings.dart b/otzaria_l10n/lib/src/app_strings.dart index 73cdfdac..f7ba096a 100644 --- a/otzaria_l10n/lib/src/app_strings.dart +++ b/otzaria_l10n/lib/src/app_strings.dart @@ -2480,6 +2480,7 @@ abstract class ErrorReportsDomainStrings { String get someNotCollected; String uploadHttpStatus(int statusCode); + String uploadReportKept(String reason); String get uploadShabbat; String get uploadTimedOut; String uploadNetworkError(String error); @@ -2571,6 +2572,8 @@ abstract class AppReportsStrings { // ── תמונות ── String get imagesPrompt; + String get attachmentLimitsHint; + String get attachmentsInvalidSnack; String get imagesPickDialogTitle; String get removeImageTooltip; String imageTooLarge(int megabytes); diff --git a/otzaria_l10n/lib/src/strings_en.dart b/otzaria_l10n/lib/src/strings_en.dart index 243ff471..8252cd69 100644 --- a/otzaria_l10n/lib/src/strings_en.dart +++ b/otzaria_l10n/lib/src/strings_en.dart @@ -4783,6 +4783,9 @@ class _ErrorReportsDomain extends ErrorReportsDomainStrings { String uploadHttpStatus(int statusCode) => 'The server answered with code $statusCode'; @override + String uploadReportKept(String reason) => + '$reason. The report and all its attachments remain on the drive for review.'; + @override String get uploadShabbat => 'The Otzaria site is closed on Shabbat and Yom Tov. The reports stay on the drive and will be sent next time, after Shabbat ends.'; @override @@ -4947,18 +4950,24 @@ class _AppReports extends AppReportsStrings { @override String get imagesPrompt => 'Click to choose a screenshot'; @override + String get attachmentLimitsHint => + 'Up to 10 MiB per file and 20 MiB for all attachments together (1 MiB = 1,048,576 bytes).'; + @override + String get attachmentsInvalidSnack => + 'Attachments exceed the limits: 10 MiB per file and 20 MiB in total. Remove an attachment and try again.'; + @override String get imagesPickDialogTitle => 'Choose screenshots for the report'; @override String get removeImageTooltip => 'Remove image'; @override String imageTooLarge(int megabytes) => - 'An image larger than $megabytes MB was not attached.'; + 'An image larger than $megabytes MiB was not attached.'; @override String tooManyImages(int count) => 'Up to $count images can be attached to a report.'; @override String imagesTotalTooLarge(int megabytes) => - 'The images are limited to $megabytes MB in total.'; + 'All attachments are limited to $megabytes MiB in total.'; @override String get imageReadFailed => 'The image could not be read.'; diff --git a/otzaria_l10n/lib/src/strings_he.dart b/otzaria_l10n/lib/src/strings_he.dart index 857c0460..67a5be70 100644 --- a/otzaria_l10n/lib/src/strings_he.dart +++ b/otzaria_l10n/lib/src/strings_he.dart @@ -4519,6 +4519,9 @@ class _ErrorReportsDomain extends ErrorReportsDomainStrings { String uploadHttpStatus(int statusCode) => 'אתר אוצריא השיב בקוד שגיאה $statusCode'; @override + String uploadReportKept(String reason) => + '$reason. הדיווח וכל צרופותיו נשמרו בכונן להמשך טיפול.'; + @override String get uploadShabbat => 'אתר אוצריא סגור בשבת ובימים טובים. הדיווחים נשמרו בכונן ויישלחו בפעם הבאה, אחרי צאת השבת.'; @override @@ -4683,17 +4686,23 @@ class _AppReports extends AppReportsStrings { @override String get imagesPrompt => 'לחץ כאן לבחירת צילום מסך'; @override + String get attachmentLimitsHint => + 'עד 10 MiB לקובץ, ועד 20 MiB לכל הצרופות יחד (1 MiB = 1,048,576 בתים).'; + @override + String get attachmentsInvalidSnack => + 'הצרופות אינן עומדות במגבלות: עד 10 MiB לקובץ ועד 20 MiB יחד. הסירו צרופה ונסו שוב.'; + @override String get imagesPickDialogTitle => 'בחירת צילומי מסך לדיווח'; @override String get removeImageTooltip => 'הסרת התמונה'; @override String imageTooLarge(int megabytes) => - 'תמונה גדולה מ-\u2066$megabytes\u00a0MB\u2069 לא צורפה.'; + 'תמונה גדולה מ-\u2066$megabytes\u00a0MiB\u2069 לא צורפה.'; @override String tooManyImages(int count) => 'ניתן לצרף עד $count תמונות לדיווח.'; @override String imagesTotalTooLarge(int megabytes) => - 'הגודל הכולל של התמונות מוגבל ל-\u2066$megabytes\u00a0MB\u2069.'; + 'הגודל הכולל של הצרופות מוגבל ל-\u2066$megabytes\u00a0MiB\u2069.'; @override String get imageReadFailed => 'לא ניתן היה לקרוא את התמונה.'; From e75bb9aa92bea1996c0b9d05b005246a3280d2fd Mon Sep 17 00:00:00 2001 From: palmoni5 Date: Thu, 5 Nov 2026 20:14:47 +0200 Subject: [PATCH 2/3] =?UTF-8?q?=D7=93=D7=99=D7=95=D7=95=D7=97=D7=99=D7=9D:?= =?UTF-8?q?=20=D7=91=D7=93=D7=99=D7=A7=D7=AA=20=D7=A6=D7=A8=D7=95=D7=A4?= =?UTF-8?q?=D7=95=D7=AA=20=D7=9E=D7=91=D7=95=D7=93=D7=93=D7=AA=20=D7=A8?= =?UTF-8?q?=D7=A7=20=D7=91=D7=9E=D7=A1=D7=9C=D7=95=D7=9C=20=D7=93=D7=99?= =?UTF-8?q?=D7=95=D7=95=D7=97=D7=99=20=D7=AA=D7=95=D7=9B=D7=A0=D7=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/src/services/report_uploader.dart | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/error_reports_manager/lib/src/services/report_uploader.dart b/error_reports_manager/lib/src/services/report_uploader.dart index 56734a61..76447a22 100644 --- a/error_reports_manager/lib/src/services/report_uploader.dart +++ b/error_reports_manager/lib/src/services/report_uploader.dart @@ -125,12 +125,11 @@ class ErrorReportUploader { ); } - final sourceBody = body; final appEndpoint = item.endpoint.toString() == OutboxReport.appReportingEndpoint; - final policy = await Isolate.run( - () => _inspectAttachmentPolicy(sourceBody, appEndpoint), - ); + final policy = appEndpoint + ? await _inspectAppAttachmentPolicy(body) + : (preserveAttachments: false, invalidField: null); if (policy.invalidField != null) { return finish( error: AppL10n.strings.errorReportsDomain.uploadReportKept( @@ -369,11 +368,12 @@ class ErrorReportUploader { (attempt.statusCode == 422 && attempt.rejectedField == 'attachments.minidump'); + static Future<({bool preserveAttachments, String? invalidField})> + _inspectAppAttachmentPolicy(Uint8List bytes) => + Isolate.run(() => _inspectAttachmentPolicy(bytes)); + static ({bool preserveAttachments, String? invalidField}) - _inspectAttachmentPolicy(Uint8List bytes, bool appEndpoint) { - if (!appEndpoint) { - return (preserveAttachments: false, invalidField: null); - } + _inspectAttachmentPolicy(Uint8List bytes) { try { final json = jsonDecode(utf8.decode(bytes)); if (json is! Map || From a1d11f43d02cb0bee3df18ea98f4f7d3eb10f421 Mon Sep 17 00:00:00 2001 From: ypl <7353755@gmail.com> Date: Fri, 6 Nov 2026 03:01:14 +0200 Subject: [PATCH 3/3] =?UTF-8?q?=D7=AA=D7=99=D7=A7=D7=95=D7=9F=20=D7=AA?= =?UTF-8?q?=D7=A7=D7=A6=D7=99=D7=91=20=D7=A6=D7=A8=D7=95=D7=A4=D7=95=D7=AA?= =?UTF-8?q?=20=D7=9C=D7=A4=D7=A0=D7=99=20=D7=91=D7=97=D7=99=D7=A8=D7=AA=20?= =?UTF-8?q?=D7=A1=D7=95=D7=92=20=D7=93=D7=99=D7=95=D7=95=D7=97=20=D7=9C?= =?UTF-8?q?=D7=90=D7=97=D7=A8=20=D7=A9=D7=99=D7=9C=D7=95=D7=91=20#204?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/screens/app_report/app_report_dialog.dart | 2 +- .../src/screens/app_report/app_report_form.dart | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/launcher_app/lib/src/screens/app_report/app_report_dialog.dart b/launcher_app/lib/src/screens/app_report/app_report_dialog.dart index 62033f6c..8b889d3e 100644 --- a/launcher_app/lib/src/screens/app_report/app_report_dialog.dart +++ b/launcher_app/lib/src/screens/app_report/app_report_dialog.dart @@ -280,7 +280,7 @@ class _AppReportDialogState extends State { const SizedBox(height: AppTokens.spaceMD), AppReportImagesSection( images: form.images, - otherAttachmentBytes: form.buildReport().otherAttachmentBytes, + otherAttachmentBytes: form.otherAttachmentBytes, enabled: enabled, source: widget.imageSource, onChanged: (images) => form.update(images: images), diff --git a/launcher_app/lib/src/screens/app_report/app_report_form.dart b/launcher_app/lib/src/screens/app_report/app_report_form.dart index 99acc2ab..d5ecfcc6 100644 --- a/launcher_app/lib/src/screens/app_report/app_report_form.dart +++ b/launcher_app/lib/src/screens/app_report/app_report_form.dart @@ -144,14 +144,17 @@ class AppReportForm extends ChangeNotifier { /// השרת דחה את הדיווח (400/413/422/409 חוזר) — לא נשמר לשליחה חוזרת. bool get wasRejected => result?.isFailed ?? false; - /// הדיווח מהמצב הנוכחי — בדיוק מה שיישלח, ולכן גם מה שהתצוגה המקדימה - /// מראה. ההסתרה חלה על הטקסטים של המשתמש; הצרופות כבר הוסתרו פעם אחת - /// באיסוף ([AppReportAttachmentsCollector]), ולכן אינן עוברות אותה שוב בכל - /// הקלדה. - AppReport buildReport() { + int get otherAttachmentBytes => + _buildReport(type ?? AppReportType.bug).otherAttachmentBytes; + + /// הדיווח שיישלח ויוצג בתצוגה המקדימה; רק טקסטי המשתמש מוסתרים כאן. + /// הצרופות הוסתרו כבר באיסוף, ולא עוברות הסתרה מחדש בכל הקלדה. + AppReport buildReport() => _buildReport(type!); + + AppReport _buildReport(AppReportType reportType) { final fields = AppReport( reportId: _reportId, - type: type!, + type: reportType, trigger: trigger, title: title, description: description,