Skip to content

test: cover session close graduation export#261

Closed
Gradata wants to merge 2 commits into
mainfrom
gra-1102-session-sweep-agents
Closed

test: cover session close graduation export#261
Gradata wants to merge 2 commits into
mainfrom
gra-1102-session-sweep-agents

Conversation

@Gradata

@Gradata Gradata commented Jun 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add a deterministic Stop/session-close CI fixture for GRA-1102.
  • Seeds three low-confidence INSTINCT lessons plus an eligible PATTERN, triggers the session-close waterfall from a CORRECTION event, and asserts AGENTS.md includes the promoted RULE.

Paperclip issue: d100fb3c-a477-449c-84d5-84de5a044879

Verification

  • python3 -m pytest tests/test_hooks_learning.py::test_session_close_graduates_fixture_to_agents_md -q
  • python3 -m pytest tests/test_hooks_learning.py -q

@greptile-apps greptile-apps 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.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitai

coderabbitai Bot commented Jun 6, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 834ff042-042d-44b7-b200-3c92ae4c3952

📥 Commits

Reviewing files that changed from the base of the PR and between 4467662 and 74d6123.

📒 Files selected for processing (1)
  • Gradata/tests/test_hooks_learning.py
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: pytest ubuntu-latest / py3.11
  • GitHub Check: pytest windows-latest / py3.12
  • GitHub Check: pytest macos-latest / py3.11
  • GitHub Check: pytest macos-latest / py3.12
  • GitHub Check: pytest windows-latest / py3.11
  • GitHub Check: pytest ubuntu-latest / py3.12
  • GitHub Check: pytest (py3.11)
  • GitHub Check: pytest (py3.12)
🧰 Additional context used
📓 Path-based instructions (1)
Gradata/tests/**/*.py

📄 CodeRabbit inference engine (Gradata/AGENTS.md)

Gradata/tests/**/*.py: Set BRAIN_DIR environment variable via tmp_path in conftest.py for test isolation — ensure _paths.py module cache refreshes when calling Brain.init() directly inside tests
Add unit tests in tests/test_*.py for every CI push without LLM calls (deterministic); mark integration tests with @pytest.mark.integration and skip them by default (they hit real LLM APIs)

Files:

  • Gradata/tests/test_hooks_learning.py
🧠 Learnings (4)
📓 Common learnings
Learnt from: Gradata
Repo: Gradata/gradata PR: 0
File: :0-0
Timestamp: 2026-04-17T17:18:07.439Z
Learning: In PR `#102` (gradata/gradata), Round 2 addressed: cli.py env-first brain resolution (GRADATA_BRAIN > --brain-dir > cwd), _tenant.py corrupt .tenant_id overwrite, _env_int default clamping to minimum, and _events.py tenant-scoped fallback SELECT for dedup. All ruff and 99 tests green after these fixes.
Learnt from: CR
Repo: Gradata/gradata PR: 0
File: Gradata/AGENTS.md:0-0
Timestamp: 2026-05-01T15:50:32.772Z
Learning: Applies to Gradata/tests/**/*.py : Add unit tests in `tests/test_*.py` for every CI push without LLM calls (deterministic); mark integration tests with `pytest.mark.integration` and skip them by default (they hit real LLM APIs)
📚 Learning: 2026-04-17T17:18:07.439Z
Learnt from: Gradata
Repo: Gradata/gradata PR: 0
File: :0-0
Timestamp: 2026-04-17T17:18:07.439Z
Learning: In PR `#102` (gradata/gradata), Round 2 addressed: cli.py env-first brain resolution (GRADATA_BRAIN > --brain-dir > cwd), _tenant.py corrupt .tenant_id overwrite, _env_int default clamping to minimum, and _events.py tenant-scoped fallback SELECT for dedup. All ruff and 99 tests green after these fixes.

Applied to files:

  • Gradata/tests/test_hooks_learning.py
📚 Learning: 2026-05-01T15:50:32.772Z
Learnt from: CR
Repo: Gradata/gradata PR: 0
File: Gradata/AGENTS.md:0-0
Timestamp: 2026-05-01T15:50:32.772Z
Learning: Applies to Gradata/tests/**/*.py : Set `BRAIN_DIR` environment variable via `tmp_path` in conftest.py for test isolation — ensure `_paths.py` module cache refreshes when calling `Brain.init()` directly inside tests

Applied to files:

  • Gradata/tests/test_hooks_learning.py
📚 Learning: 2026-05-01T15:50:32.772Z
Learnt from: CR
Repo: Gradata/gradata PR: 0
File: Gradata/AGENTS.md:0-0
Timestamp: 2026-05-01T15:50:32.772Z
Learning: Applies to Gradata/tests/**/*.py : Add unit tests in `tests/test_*.py` for every CI push without LLM calls (deterministic); mark integration tests with `pytest.mark.integration` and skip them by default (they hit real LLM APIs)

Applied to files:

  • Gradata/tests/test_hooks_learning.py
🔇 Additional comments (1)
Gradata/tests/test_hooks_learning.py (1)

380-435: LGTM!


📝 Walkthrough
  • Added deterministic CI test test_session_close_graduates_fixture_to_agents_md to Gradata/tests/test_hooks_learning.py (uses brain_dir fixture for deterministic setup)
  • Seeds lessons.md with three low-confidence INSTINCT lessons and one eligible PATTERN lesson (contains the "merged PR artifact URL" phrase)
  • Seeds system.db events with a CORRECTION event and triggers session-close waterfall via close_main(session_number=7)
  • Asserts eligible PATTERN lesson is promoted to a RULE and that AGENTS.md includes the promoted rule text plus expected headers (# AGENTS.md, ## PROCESS)
  • Verifies .last_close_ts timestamp file is created
  • Test update replaces prior ad-hoc setup by leveraging the brain_dir fixture for environment determinism and reuse
  • +57/-0 lines of test code
  • References Paperclip issue d100fb3c-a477-449c-84de5a044879
  • No breaking changes, security fixes, or new public API methods introduced by this test-only change

Walkthrough

Adds one integration pytest that seeds a deterministic lessons.md and system.db (with a CORRECTION event), runs close_main(session_number=7), and asserts a PATTERN lesson is promoted to a RULE, AGENTS.md is created/contains headers and the promoted rule, and .last_close_ts is written.

Changes

Session Close Graduation Integration Test

Layer / File(s) Summary
Integration test for session close graduation to AGENTS.md
Gradata/tests/test_hooks_learning.py
Test test_session_close_graduates_fixture_to_agents_md seeds lessons.md with low-confidence INSTINCT and a high-confidence PATTERN (containing “merged PR artifact URL”), populates system.db with a CORRECTION event, runs close_main(session_number=7), and asserts the eligible PATTERN is promoted to a RULE whose description includes the artifact URL, AGENTS.md is created and contains # AGENTS.md, ## PROCESS, and the promoted rule text, and .last_close_ts exists.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • Gradata/gradata#249: Related to auto-export of AGENTS.md and session-close graduation behavior that this test verifies.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% 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 'test: cover session close graduation export' clearly and specifically describes the main change: adding a test for the session-close graduation feature and its AGENTS.md export.
Description check ✅ Passed The description is directly related to the changeset, explaining the test's purpose, setup (seeds lessons and CORRECTION event), expectations (AGENTS.md promotion), and verification steps.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch gra-1102-session-sweep-agents

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 OpenGrep (1.22.0)

OpenGrep fatal error (exit code 2):
┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

�[1m Loading rules from local config...�[0m
[00.16][ERROR]: Error: exception Glob.Lexer.Syntax_error("malformed glob pattern: missing ']'")
Raised at Glob__Lexer.syntax_error in file "libs/glob/Lexer.mll", line 8, characters 2-26
Called from Glob__Lexer.__ocaml_lex_token_rec in file "libs/glob/Lexer.mll", line 29, characters 26-53
Cal


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 `@Gradata/tests/test_hooks_learning.py`:
- Around line 416-417: Replace the ad-hoc os.environ patch that sets
GRADATA_BRAIN_DIR around the close_main({"session_number": 7}) call with the
shared brain-dir test fixture provided in conftest.py: remove the
patch.dict(...) block and add the conftest fixture parameter (the brain-dir
fixture that wires BRAIN_DIR and companion env from tmp_path) to the test
signature so the test runs with the fixture-provided tmp_path/BRAIN_DIR, keeping
the call to close_main({"session_number": 7}) unchanged; ensure any references
to GRADATA_BRAIN_DIR in the test are removed or rely on the fixture's
environment setup instead.
🪄 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d3e2ea75-0a0d-4da8-9fe9-23dd5848fff3

📥 Commits

Reviewing files that changed from the base of the PR and between 6d00ffd and 4467662.

📒 Files selected for processing (1)
  • Gradata/tests/test_hooks_learning.py
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: pytest windows-latest / py3.11
  • GitHub Check: pytest ubuntu-latest / py3.11
  • GitHub Check: pytest ubuntu-latest / py3.12
  • GitHub Check: pytest macos-latest / py3.12
  • GitHub Check: pytest macos-latest / py3.11
  • GitHub Check: pytest windows-latest / py3.12
  • GitHub Check: pytest (py3.11)
  • GitHub Check: pytest (py3.12)
🧰 Additional context used
📓 Path-based instructions (1)
Gradata/tests/**/*.py

📄 CodeRabbit inference engine (Gradata/AGENTS.md)

Gradata/tests/**/*.py: Set BRAIN_DIR environment variable via tmp_path in conftest.py for test isolation — ensure _paths.py module cache refreshes when calling Brain.init() directly inside tests
Add unit tests in tests/test_*.py for every CI push without LLM calls (deterministic); mark integration tests with @pytest.mark.integration and skip them by default (they hit real LLM APIs)

Files:

  • Gradata/tests/test_hooks_learning.py
🧠 Learnings (1)
📓 Common learnings
Learnt from: Gradata
Repo: Gradata/gradata PR: 0
File: :0-0
Timestamp: 2026-04-17T17:18:07.439Z
Learning: In PR `#102` (gradata/gradata), Round 2 addressed: cli.py env-first brain resolution (GRADATA_BRAIN > --brain-dir > cwd), _tenant.py corrupt .tenant_id overwrite, _env_int default clamping to minimum, and _events.py tenant-scoped fallback SELECT for dedup. All ruff and 99 tests green after these fixes.
Learnt from: CR
Repo: Gradata/gradata PR: 0
File: Gradata/AGENTS.md:0-0
Timestamp: 2026-05-01T15:50:32.772Z
Learning: Ensure the 4 deterministic guarantees have tests: (1) Correction in → rule extracted out, (2) Rule retrieved/applied in subsequent session, (3) Contradicting evidence lowers confidence, (4) Stale rules decay below threshold
🔇 Additional comments (1)
Gradata/tests/test_hooks_learning.py (1)

417-417: Ensure close_main in Gradata/tests/test_hooks_learning.py stays CI-deterministic (no real LLM/network).

close_main({"session_number": 7}) delegates to Gradata/src/gradata/hooks/session_close.py:_run_pipeline, which imports and runs gradata.enhancements.rule_pipeline.run_rule_pipeline (i.e., it’s not stubbed in this test). A scan for common LLM/network libraries (openai, anthropic, requests, httpx, aiohttp, etc.) didn’t find direct matches in Gradata/src/Gradata/tests, but determinism still can’t be guaranteed because the call path goes into run_rule_pipeline. Mock that step (or force the non-LLM branch) or mark/skip as @pytest.mark.integration per policy.

Comment thread Gradata/tests/test_hooks_learning.py Outdated

@greptile-apps greptile-apps 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.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@Gradata

Gradata commented Jun 6, 2026

Copy link
Copy Markdown
Owner Author

Superseded by merged PR #263 for GRA-1102.

@Gradata Gradata closed this Jun 6, 2026
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