8000 feat(habits): add good and bad habit types by ahmet-cetinkaya · Pull Request #304 · ahmet-cetinkaya/whph · GitHub
[go: up one dir, main page]

Skip to content

feat(habits): add good and bad habit types - #304

Merged
ahmet-cetinkaya merged 20 commits into
mainfrom
feat/habit-types-good-bad
Sep 5, 2026
Merged

ahmet-cetinkaya merged 20 commits into
mainfrom
feat/habit-types-good-bad

Conversation

@ahmet-cetinkaya
Copy link
Copy Markdown
Owner

Summary

Adds first-class good and bad habit types. Good habits retain their existing completion-based behavior; bad habits track successful avoidance.

Changes by area

  • Domain & schema: adds the habit-type contract and migrates Drift schema v36 → v37.
  • Application: propagates types through saves, mappings, queries, day-state resolution, and record operations.
  • UI: adds type selection and type-aware add/details, cards, calendar, and presentation behavior.
  • Widgets & notifications: updates widget aggregation/toggles/background handling, reminders, notification handlers, and application registration.
  • Compatibility: preserves import/export and sync compatibility, with end-to-end coverage.
  • i18n: adds habit-type copy across all 22 locale YAMLs.

Behavior specification

  • Bad habits are binary.
  • Every local calendar day from creation through today is applicable, capped at the archive date.
  • For a bad habit, no record means successfully avoided; a notDone record means the habit was performed that day.
  • complete history is preserved when converting types, but is ignored while a habit is in bad mode.
  • Good-habit behavior is unchanged.

QA evidence

Artifacts are available under .omo/evidence/.

  • Full Flutter suite: EXIT=0, 2372 passing
  • dart analyze: clean
  • rps lint: 0
  • rps test:locale: 0
  • rps test:migrate: 0 (673 tests)

Defects found and fixed during development

  • Fixed a good-habit goal-period filtering regression, found twice during review.
  • Fixed false “Habit completed!” widget feedback when a bad habit failed.
  • Fixed log-id interpolation from '$TaskErrorIds.x' to '${TaskErrorIds.x}'; applied the same correction to the task handler for contract consistency.
  • Fixed a DST local-day range bug in write commands and its order-dependent test.

Risks / notes

  • Includes schema migration v36 → v37.
  • A pre-existing upstream quirk—period-aware filtering runs after LIMIT/OFFSET—was intentionally left untouched as out of scope.

@ahmet-cetinkaya
ahmet-cetinkaya force-pushed the feat/habit-types-good-bad branch from f5c3588 to b46f6d4 Compare September 5, 2026 15:00
The Zed debug session failed to link the Linux desktop build on NixOS:

    clang++: error: linker command failed with exit code 1
    ld: cannot find -lgstapp-1.0

Two independent causes:

1. flake.nix passed only `-Wl,-rpath-link` to CMake. ld uses that solely to
   resolve indirect dependencies, never as a library *search* path, so plugins
   linking with bare `-l` flags (audioplayers_linux -> -lgstapp-1.0, -lglib-2.0)
   could not be resolved. The generated link line contained no `-L` at all.
   Add `-L` for every Nix build input.

2. The Dart extension never entered the dev shell. It ignores `customTool`
   entirely and resolves the binary via `worktree.which("fvm")` *before* the
   debug config's `env` map is applied, so neither the existing wrapper script
   nor a project-local PATH override could redirect it
   (zed-extensions/dart, src/dart.rs).

   Drop the dead `customTool` entry and keep `useFvm: true`, which the extension
   does honour — without it the adapter looks for a bare `flutter` and reports
   "flutter not found in PATH", since Flutter is pinned via FVM here.

   The remaining piece is host-side and cannot live in the repo, because it must
   sit on the PATH Zed itself sees: a `~/.local/bin/fvm` shim that re-enters
   `nix develop` for flake projects and delegates straight through elsewhere.

Verified from a clean build/linux with `env -i` and only ~/.local/bin on PATH.
@ahmet-cetinkaya
ahmet-cetinkaya force-pushed the feat/habit-types-good-bad branch from b46f6d4 to d5c6876 Compare September 5, 2026 15:01
…axis labels

- Fix x-axis month/percent labels duplication by adding missing fl_chart interval configuration
- Fix bad-habit trend data scoped to current month with day-level keys; now uses real trailing-12-month trend
- Add comprehensive test coverage for habit statistics view and query logic
A rebase artifact left both SUM(...) and TOTAL(...) projections aliased
as total_duration, causing SQLite to compute the same aggregate twice per
group. The ORDER BY clause now uses SUM to match the projection, ensuring
the sort key is consistent with the selected value.

Adds integration test covering sorting by actual time, which previously
had no coverage.
_presenter was a getter, so every one of the up-to-42 month-grid cells
constructed a new HabitDayPresenter and re-indexed all habit records.
It is now built once per grid build and passed into the day builders,
with late keeping it unbuilt on the good-habit path that never reads it.
WidgetHabitData.fromJson used Enum.values.byName, which handled an absent field but threw ArgumentError on a present-but-unrecognised value; since the persisted widget blob survives app upgrades and downgrades, a name written by a newer version broke the widget permanently with no way to self-heal. It now reuses the domain's total HabitType.fromJson and a name-map lookup for HabitDayState, matching how every neighbouring field degrades. Adds a regression test.
updateType mutated the habit and notified listeners before awaiting the save, so a failed save left the UI showing the new type with hasGoal, targetFrequency, periodDays, and dailyTarget blanked while the database still held the old values; editing any other field would then persist that corrupted state.

saveHabitImmediately now accepts an onError hook and updateType restores the previous values plus the goal field's visibility.

Adds a regression test.
The handler caught only BusinessException, so infrastructure failures
(DB lock, disk full) in this fire-and-forget notification callback
propagated with nothing logged. This left the user with a dismissed
notification, no recorded habit, and no diagnostic trail.

A general catch now logs the error with its stack trace and rethrows,
preserving the existing propagation behavior that
notification_handlers_test.dart asserts.
The repository decoded the column with HabitType.values[...], which threw an uncaught RangeError on any value outside 0..1 — reachable from a row written by a newer build or from corrupted data — and silently tied the stored meaning to enum declaration order, so reordering variants would reinterpret every existing row.

HabitType now declares an explicit id per variant with a fromId function that defaults unknown ids to good, matching the existing fromJson policy. Tests cover the out-of-range row, the id mapping, and a guard asserting each id still equals its ordinal, since the Drift intEnum column persists the index.
The raw filter SQL passed HabitType.bad.index while the repository now decodes the column through HabitType.fromId, splitting one persistence contract across two sources. The four query variables now use HabitType.bad.id so reads and writes agree on a single identity. Values are unchanged, so behavior is identical today.
@ahmet-cetinkaya
ahmet-cetinkaya merged commit b2ffb25 into main Sep 5, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0