Skip to content

test: cover session-close graduation fixture#262

Closed
Gradata wants to merge 1 commit into
mainfrom
GRA-1102-session-close-graduation
Closed

test: cover session-close graduation fixture#262
Gradata wants to merge 1 commit into
mainfrom
GRA-1102-session-close-graduation

Conversation

@Gradata

@Gradata Gradata commented Jun 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add a deterministic CI fixture for GRA-1102 covering the Stop/session-close graduation path.
  • Verifies three INSTINCT entries exist before sweep, the gated session-close waterfall runs, and a promoted RULE is exported into AGENTS.md/export_rules payload.

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

Tests

  • python3 -m pytest tests/test_session_close_graduation_fixture.py -q
  • python3 -m pytest tests/test_session_close_graduation_fixture.py tests/test_rule_file_materialization.py tests/test_rule_export.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: 654ad7b6-8ba0-4c8b-a808-d6a76e0f4e5a

📥 Commits

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

📒 Files selected for processing (1)
  • Gradata/tests/test_session_close_graduation_fixture.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.12
  • GitHub Check: pytest windows-latest / py3.12
  • GitHub Check: pytest ubuntu-latest / py3.11
  • GitHub Check: pytest macos-latest / py3.11
  • GitHub Check: pytest windows-latest / py3.11
  • GitHub Check: pytest macos-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_session_close_graduation_fixture.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.
📚 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_session_close_graduation_fixture.py
📚 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_session_close_graduation_fixture.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_session_close_graduation_fixture.py
🔇 Additional comments (1)
Gradata/tests/test_session_close_graduation_fixture.py (1)

1-97: LGTM!


📝 Walkthrough
  • Added regression test for GRA-1102 covering the session-close "Stop hook" graduation flow
  • Test verifies that a PATTERN lesson with high confidence is promoted to a RULE lesson during session-close sweep
  • Test confirms promoted RULE is exported into AGENTS.md and export_rules payload
  • Test uses deterministic synthetic brain with three INSTINCT entries and one PATTERN entry (fire_count=3, confidence=0.95)
  • Test validates .last_close_ts marker file is created after session-close execution
  • New test: test_stop_session_close_sweep_graduates_rule_into_agents_payload (+96 lines)

Walkthrough

This PR adds a new pytest regression test for GRA-1102 that validates the session-close "Stop hook" graduation flow. The test constructs a deterministic brain, initiates a session-close event for a specific session ID, and verifies that a PATTERN lesson is promoted to RULE and exported into AGENTS.md.

Changes

Session-close graduation test

Layer / File(s) Summary
Module documentation and imports
Gradata/tests/test_session_close_graduation_fixture.py
Module docstring explaining the GRA-1102 regression test for session-close graduation, plus imports for typing, lesson operations, rule export, session_close hook, and test brain initialization.
Graduation test implementation
Gradata/tests/test_session_close_graduation_fixture.py
Test function test_stop_session_close_sweep_graduates_rule_into_agents_payload that builds a synthetic brain with INSTINCT and PATTERN lessons, emits a CORRECTION trigger, invokes session_close.main, and validates that the PATTERN lesson is promoted to RULE in the rewritten lessons.md, that AGENTS.md is created with the promoted rule text, and that export_rules(target="agents") includes the graduated rule in its payload.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • Gradata/gradata#249: Implements the session-close "Stop hook" graduation flow that promotes PATTERN lessons to RULE and exports them via export_rules(target="agents") into AGENTS.md, which this PR's test directly validates.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 fixture' directly and clearly describes the main change: adding test coverage for the session-close graduation flow.
Description check ✅ Passed The description is directly related to the changeset, clearly explaining the test fixture's purpose (GRA-1102 coverage), what it verifies (INSTINCT entries, graduation waterfall, RULE promotion), and providing test commands.
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-close-graduation

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.

@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