Skip to content

fix(notifications): resolve analytics DB path from config, not $HOME default#117

Merged
vishnujayvel merged 1 commit into
mainfrom
fix/notifications-reader-dbpath
Jun 16, 2026
Merged

fix(notifications): resolve analytics DB path from config, not $HOME default#117
vishnujayvel merged 1 commit into
mainfrom
fix/notifications-reader-dbpath

Conversation

@vishnujayvel

@vishnujayvel vishnujayvel commented Jun 16, 2026

Copy link
Copy Markdown
Owner

What & why

hookwise notifications is a reader that opened the analytics DB from only the --data-dir flag — falling through to analytics.DefaultDBPath() (~/.hookwise/analytics.db) and ignoring config.Analytics.DBPath. The writer (dispatch) records notifications to the config path. So under a custom analytics.db_path, the reader opened the wrong (default/empty) DB and showed no history.

This is the same reader/writer divergence class as the merged stats (#107) and doctor (#108) fixes — part of #109.

Fix

Resolve the path exactly like runStats: core.LoadConfig(cwd) with a GetDefaultConfig() fallback (ARCH-1 fail-open), then analytics.Open(resolveAnalyticsDBPath(dataDir, config)). Reuses the existing resolveAnalyticsDBPath helper — no new resolver. Reader-side only; the dispatch hot path and daemon coordination are untouched.

Test (TDD)

TestNotifications_ReadsConfigDBPath — with HOOKWISE_STATE_DIR pointed at an empty temp dir (so the default DB is absent) and a project hookwise.yaml setting a custom analytics.db_path, a notification seeded into the config DB is shown when --data-dir is empty. RED→GREEN verified: stashing the production fix makes the test fail ("No notifications.") on the old code.

Guarded gate green locally: GOMEMLIMIT=4GiB go test -race -p 2 ./cmd/hookwise/ok (0 zombies before/after).

Scope

Fixes divergence #1 of three found by the #109 reader-path audit. The other two (DefaultSnapshotsDir() + tuiPIDPath()) touch the daemon writer and are tracked in #116 for a supervised PR rather than autopatched here.

Refs #109

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added --data-dir flag to the notifications command for overriding the default database directory.
    • Added --limit flag to control the maximum number of notifications displayed.
  • Tests

    • Added regression test for notifications configuration database path handling.

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@vishnujayvel, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 3 minutes and 6 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 38f79d6d-646b-423a-97a4-42674aae8b62

📥 Commits

Reviewing files that changed from the base of the PR and between 26772ad and 2b31d13.

📒 Files selected for processing (2)
  • cmd/hookwise/cmd_notifications.go
  • cmd/hookwise/cmd_notifications_test.go
📝 Walkthrough

Walkthrough

The notifications CLI command is updated to resolve the analytics SQLite DB path through shared config-loading logic (resolveAnalyticsDBPath) instead of using a raw path directly. Two new flags (--data-dir, --limit) are wired in. A regression test verifies the command reads from the config-specified DB path.

Changes

Notifications DB Path Resolution

Layer / File(s) Summary
Flag wiring and config-resolved DB path
cmd/hookwise/cmd_notifications.go
Adds --data-dir and --limit flags; runNotifications now loads config (falling back to defaults on error) and opens the analytics DB via resolveAnalyticsDBPath(dataDir, config) instead of a raw path. Imports updated to include os and core.
Regression test: reads config DB path
cmd/hookwise/cmd_notifications_test.go
TestNotifications_ReadsConfigDBPath sets HOOKWISE_STATE_DIR to isolate defaults, writes hookwise.yaml with a custom analytics.db_path, seeds a notification into that DB, runs the notifications command without --data-dir, and asserts the seeded text appears in output.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: fixing the notifications command to resolve the analytics database path from configuration rather than using the default $HOME path.
Description check ✅ Passed The description comprehensively covers all required template sections: a clear summary of the problem, detailed motivation linking to issue #109, a thorough test plan with verification of the TDD approach, and a complete checklist with all items addressed.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/notifications-reader-dbpath

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/hookwise/cmd_notifications.go`:
- Around line 41-45: The os.Getwd() error is being ignored with a blank
identifier, allowing an empty cwd to be passed to core.LoadConfig when the
working directory cannot be determined. Instead of ignoring the os.Getwd()
error, check it explicitly and if os.Getwd() fails, directly assign config to
core.GetDefaultConfig() without attempting to load config with an invalid cwd.
This ensures that when getting the current working directory fails, the code
immediately falls back to defaults rather than silently proceeding with an empty
directory path that could result in pointing notifications to the wrong database
path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2e38555a-c868-46ca-a61b-492faae4d630

📥 Commits

Reviewing files that changed from the base of the PR and between fcd4586 and 26772ad.

📒 Files selected for processing (2)
  • cmd/hookwise/cmd_notifications.go
  • cmd/hookwise/cmd_notifications_test.go

Comment on lines +41 to +45
cwd, _ := os.Getwd()
config, err := core.LoadConfig(cwd)
if err != nil {
config = core.GetDefaultConfig()
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Handle os.Getwd() failure explicitly before loading config.

If os.Getwd() fails, this code currently proceeds with an empty/invalid project dir and then silently falls back to defaults, which can point notifications to the wrong DB path despite a valid project config. Treat Getwd failure as a direct fallback branch.

Suggested patch
-	cwd, _ := os.Getwd()
-	config, err := core.LoadConfig(cwd)
-	if err != nil {
-		config = core.GetDefaultConfig()
-	}
+	config := core.GetDefaultConfig()
+	if cwd, wdErr := os.Getwd(); wdErr == nil {
+		if loaded, err := core.LoadConfig(cwd); err == nil {
+			config = loaded
+		}
+	}
 
 	db, err := analytics.Open(resolveAnalyticsDBPath(dataDir, config))
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/hookwise/cmd_notifications.go` around lines 41 - 45, The os.Getwd() error
is being ignored with a blank identifier, allowing an empty cwd to be passed to
core.LoadConfig when the working directory cannot be determined. Instead of
ignoring the os.Getwd() error, check it explicitly and if os.Getwd() fails,
directly assign config to core.GetDefaultConfig() without attempting to load
config with an invalid cwd. This ensures that when getting the current working
directory fails, the code immediately falls back to defaults rather than
silently proceeding with an empty directory path that could result in pointing
notifications to the wrong database path.

`hookwise notifications` opened the analytics DB from only the --data-dir flag,
falling through to DefaultDBPath() (~/.hookwise/analytics.db) and ignoring
config.Analytics.DBPath. The writer (dispatch) records notifications to the
config path, so under a custom analytics.db_path the reader opened the wrong
(default/empty) DB and showed no history.

Resolve the path the same way `stats` does (PR #107): LoadConfig(cwd) with a
GetDefaultConfig fallback (ARCH-1 fail-open), then
analytics.Open(resolveAnalyticsDBPath(dataDir, config)). Reader-side only — no
dispatch hot path, no daemon coordination touched.

Adds TestNotifications_ReadsConfigDBPath: with HOOKWISE_STATE_DIR isolated and a
custom analytics.db_path configured, a notification seeded into the config DB is
shown when --data-dir is empty (fails on the old code, passes on the fix).

Part of the #109 reader/writer path-divergence class. The remaining two
divergences (snapshots dir + TUI PID) touch the daemon writer and are tracked
separately in #116 for a supervised PR.

Refs #109

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vishnujayvel
vishnujayvel force-pushed the fix/notifications-reader-dbpath branch from 26772ad to 2b31d13 Compare June 16, 2026 03:35
@vishnujayvel
vishnujayvel merged commit 0e4c15f into main Jun 16, 2026
5 checks passed
@vishnujayvel
vishnujayvel deleted the fix/notifications-reader-dbpath branch June 16, 2026 03:39
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