Repository navigation
Description
What
Re-filed from the startup tracker, where it was created by mistake (was HYP-1718, deleted 2026-10-20).
syncExpenses (src/bot/commands/sync.ts) picks defaultUserId = users[0]?.id ?? 1. For a group with no users rows, new sheet rows are inserted with user_id 1 — a user of some OTHER group when one exists. SQLite's FK only checks that user 1 exists, so the expense gets cross-group ownership, and deleting that user cascades into this group's expenses. Fix: skip (and report) new rows when the group has no user, or resolve the owner from the group's admin/member, never a global id.
Why (motivation)
Found by review of HYP-1686 (stage auto-sync FK failure), 2026-10-15; pre-existing, out of that fix's scope.
User impact
A group whose sheet is synced before any member is registered gets expenses silently owned by another group's user; removing that user deletes them.
Cost of inaction
Rare but silent data corruption across groups; cascade deletes lose expenses.
Acceptance criteria
- A sync for a group with no users never writes an expense whose user belongs to another group (regression test with an in-memory DB holding user 1 in another group) — forced: Regression test in PR fix(sync): never import sheet rows into a userless group (Refs #184) #246 (src/bot/commands/sync-expenses.test.ts, 'importExpensesFromSheet ownership fallback'): in-memory DB, user id=1 created in ANOTHER group; import into a userless group returns inserted=0, expenses.findByGroupId(group)===[] — no row ever owned by another group's user. Suite: bun test src/bot/commands/sync-expenses.test.ts → 9 pass / 0 fail; full server suite 253 files / 6073 tests / 0 fail (PR fix(sync): never import sheet rows into a userless group (Refs #184) #246 CI: test pass).
- Such rows are reported to the user (the /sync report lists them) instead of silently written or dropped — forced: Reported, not silent: importExpensesFromSheet now returns SheetImportResult{inserted, skippedNoOwner}; /reconnect report (src/bot/commands/reconnect.ts formatExpenseSyncSection) shows «⏭️ Таблица → БД: пропущено N строк — в группе нет ни одного участника; они добавятся после того, как кто-нибудь сделает /start» INSTEAD of «расходы синхронизированы»; cron recovery logs '[RECOVER] ... skipped N row(s) — no user in the group' at warn. Tests: src/bot/commands/reconnect.test.ts ('skipped-no-owner rows are listed', asserts not-contains 'расходы синхронизированы') 22 pass; src/bot/cron.test.ts ('warns when a userless group forced the import to skip rows') 32 pass; sync-expenses.test asserts skippedNoOwner=1. Suite 6073/6073 pass (PR fix(sync): never import sheet rows into a userless group (Refs #184) #246 CI: test pass).
Screenshots
(none)
Deploy
Deployed: no
Links
Skipped gates
- links: found in review of HYP-1686; no PR yet
- screenshots: backend data-integrity bug, nothing visual
Activity
fix(sync): never import sheet rows into a userless group (Refs #184)
fix(sync): never import sheet rows into a userless group (Refs #184)
fix(sync): never import sheet rows into a userless group (Refs #184) (#…
alex-mextner commentedon Nov 7, 2026
Shipped: merged via #246.
Merge commit: 073908e
This does NOT close the ticket — acceptance still needs proof. Run
task read #184for the outstanding criteria, thentask check/task done.