-
Notifications
You must be signed in to change notification settings - Fork 0
feat(sync): retire hook-based cloud sync now that write-through is live (day 4 of #194) #201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| """Test the GRADATA_DISABLE_WRITE_THROUGH gate on session_close cloud sync. | ||
|
|
||
| #194 day 4: Brain.correct() write-through is the default cloud sync path. | ||
| The session_close hook's legacy cloud_sync_tick is now skipped by default | ||
| to avoid double-writes. Only runs when GRADATA_DISABLE_WRITE_THROUGH=1. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from unittest.mock import patch | ||
|
|
||
| from gradata.hooks import session_close | ||
|
|
||
|
|
||
| def test_run_cloud_sync_skipped_when_write_through_default(monkeypatch): | ||
| """Default behavior: write-through covers it, session_close tick is skipped.""" | ||
| monkeypatch.setenv("GRADATA_API_KEY", "gd_live_test") | ||
| monkeypatch.delenv("GRADATA_DISABLE_WRITE_THROUGH", raising=False) | ||
| with patch("gradata._core.cloud_sync_tick") as mock_tick: | ||
| session_close._run_cloud_sync("/tmp/fake-brain", {"session_number": 1}) | ||
| ( | ||
| mock_tick.assert_not_called(), | ||
| ("session_close must NOT call cloud_sync_tick when write-through is on"), | ||
| ) | ||
|
|
||
|
|
||
| def test_run_cloud_sync_invoked_when_write_through_disabled(monkeypatch): | ||
| """Opt-out via GRADATA_DISABLE_WRITE_THROUGH=1: legacy path runs.""" | ||
| monkeypatch.setenv("GRADATA_API_KEY", "gd_live_test") | ||
| monkeypatch.setenv("GRADATA_DISABLE_WRITE_THROUGH", "1") | ||
| with patch("gradata._core.cloud_sync_tick") as mock_tick: | ||
| session_close._run_cloud_sync("/tmp/fake-brain", {"session_number": 1}) | ||
| mock_tick.assert_called_once_with("/tmp/fake-brain", 1) | ||
|
|
||
|
|
||
| def test_run_cloud_sync_skipped_when_no_api_key(monkeypatch): | ||
| """No API key: never call cloud regardless of write-through state.""" | ||
| monkeypatch.delenv("GRADATA_API_KEY", raising=False) | ||
| monkeypatch.setenv("GRADATA_DISABLE_WRITE_THROUGH", "1") | ||
| with patch("gradata._core.cloud_sync_tick") as mock_tick: | ||
| session_close._run_cloud_sync("/tmp/fake-brain", {"session_number": 1}) | ||
| mock_tick.assert_not_called() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: Gradata/gradata
Length of output: 146
Remove the no-op tuple wrapper around
assert_not_called().This tuple expression serves no purpose and obfuscates the assertion.
Suggested diff
🤖 Prompt for AI Agents