Skip to content

test: isolate quickstart smoke brain env#270

Open
Gradata wants to merge 1 commit into
mainfrom
gra-1781-env-isolated-smoke
Open

test: isolate quickstart smoke brain env#270
Gradata wants to merge 1 commit into
mainfrom
gra-1781-env-isolated-smoke

Conversation

@Gradata

@Gradata Gradata commented Jun 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • harden examples/offline_quickstart_smoke.py against inherited live Gradata brain env (BRAIN_DIR, GRADATA_BRAIN)
  • assert stats is using the temporary smoke brain, so Show HN onboarding smoke catches env contamination
  • document that the offline smoke creates a temporary HOME and ignores inherited live-brain variables

Verification

BRAIN_DIR=/home/olive/.gradata/brain GRADATA_BRAIN=/home/olive/.gradata/brain PYTHONPATH=Gradata/src python3 Gradata/examples/offline_quickstart_smoke.py
# ...
# Brain: /tmp/gradata-quickstart-ck89cjie/my-brain
# ✓ offline quickstart smoke passed
python3 -m py_compile Gradata/examples/offline_quickstart_smoke.py
git diff --check

Prior GRA-1781 docs/smoke artifact already merged in PR #236; this follow-up fixes the environment contamination found while verifying it.

@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 8, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough
  • Hardened offline_quickstart_smoke.py to clear inherited BRAIN_DIR and GRADATA_BRAIN environment variables, preventing contamination from live environments
  • Added assertion to verify that gradata stats output references the expected temporary brain directory before proceeding with audit
  • Updated documentation in install.md to clarify that the offline smoke test creates a temporary HOME and ignores inherited live-brain environment variables
  • Makes the smoke test more deterministic and safe to run in agent shells
  • No breaking changes, security fixes, or public API modifications

Walkthrough

The PR improves the offline quickstart smoke test's determinism and safety by clearing inherited environment variables that might contaminate test execution, validating that the test operates on the expected temporary brain directory, and updating installation documentation to clarify this isolation behavior.

Changes

Smoke Test and Documentation Updates

Layer / File(s) Summary
Environment isolation and stats verification in smoke test
Gradata/examples/offline_quickstart_smoke.py
Smoke test removes pre-existing BRAIN_DIR and GRADATA_BRAIN environment variables to ensure deterministic test execution. Stats output is now captured and validated to confirm the expected brain directory is present before running audit; missing expected directory causes the script to exit with an error.
Installation verification documentation
Gradata/docs/getting-started/install.md
Documentation clarifies that the offline smoke test creates a temporary HOME directory and ignores inherited live-brain environment variables (BRAIN_DIR / GRADATA_BRAIN) to keep the verification run isolated and safe.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • Gradata/gradata#236: Updates offline quickstart smoke-test with environment variable clearing and stats assertions, overlapping directly with this PR's implementation of the same isolation and validation logic.
  • Gradata/gradata#259: Adjusts offline smoke-test verification by unsetting BRAIN_DIR/GRADATA_BRAIN environment variables to prevent contamination, parallel to this PR's env isolation approach.
  • Gradata/gradata#228: Modifies install verification and offline quickstart smoke behavior by clearing BRAIN_DIR/GRADATA_* and isolating HOME during deterministic test execution, similar architectural changes as this PR.

Suggested labels

docs

🚥 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: isolate quickstart smoke brain env' directly and specifically describes the main changes—hardening the smoke test to isolate the brain environment from inherited variables.
Description check ✅ Passed The description clearly relates to the changeset by explaining the hardening of the offline smoke test, environment variable isolation, and documentation updates across both modified files.
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-1781-env-isolated-smoke

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.17][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 added the docs label Jun 8, 2026

@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/examples/offline_quickstart_smoke.py`:
- Around line 64-68: Move the assertion that verifies stats used the correct
brain directory to run immediately after obtaining stats and before calling
run(..., "audit") so the script fails fast; specifically, after the call that
assigns stats = run(["--brain-dir", str(brain), "stats"], env=env) check if
f"Brain: {brain}" is in stats and raise SystemExit(...) if not, and only then
invoke run(["--brain-dir", str(brain), "audit"], env=env) — this ensures the
stats validation gates running audit and prevents contamination.
🪄 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: 54967ac0-7069-4fba-9f9b-790fd5ce88e5

📥 Commits

Reviewing files that changed from the base of the PR and between acde088 and 8bbf6f7.

📒 Files selected for processing (2)
  • Gradata/docs/getting-started/install.md
  • Gradata/examples/offline_quickstart_smoke.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 (py3.12)
  • GitHub Check: pytest (py3.11)
  • GitHub Check: pytest ubuntu-latest / py3.12
  • GitHub Check: pytest macos-latest / py3.11
  • GitHub Check: pytest macos-latest / py3.12
  • GitHub Check: pytest ubuntu-latest / py3.11
  • GitHub Check: pytest windows-latest / py3.12
  • GitHub Check: pytest windows-latest / py3.11
🧰 Additional context used
🧠 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 : 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
📚 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/docs/getting-started/install.md
  • Gradata/examples/offline_quickstart_smoke.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/docs/getting-started/install.md
  • Gradata/examples/offline_quickstart_smoke.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: Use `from gradata import Brain` as the public entry point — `brain.correct()` is THE entry point for the headline product promise

Applied to files:

  • Gradata/examples/offline_quickstart_smoke.py
🔇 Additional comments (2)
Gradata/examples/offline_quickstart_smoke.py (1)

46-49: LGTM!

Gradata/docs/getting-started/install.md (1)

117-119: LGTM!

Comment on lines +64 to +68
stats = run(["--brain-dir", str(brain), "stats"], env=env)
run(["--brain-dir", str(brain), "audit"], env=env)

if f"Brain: {brain}" not in stats:
raise SystemExit(f"stats used the wrong brain directory:\n{stats}")

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 | 🟠 Major | ⚡ Quick win

Move the stats brain-directory assertion before audit.

Line 65 runs audit before the guard on Line 67, so contamination is only detected after another command already executed. Reorder to fail fast before audit.

Proposed fix
         run(["--brain-dir", str(brain), "recall", "draft a launch email", "--max-tokens", "400"], env=env)
         stats = run(["--brain-dir", str(brain), "stats"], env=env)
-        run(["--brain-dir", str(brain), "audit"], env=env)

         if f"Brain: {brain}" not in stats:
             raise SystemExit(f"stats used the wrong brain directory:\n{stats}")
+        run(["--brain-dir", str(brain), "audit"], env=env)
         if not (brain / "system.db").exists():
             raise SystemExit(f"missing expected brain database: {brain / 'system.db'}")

Based on learnings: CLI brain resolution is env-first (GRADATA_BRAIN/BRAIN_DIR before CLI args), so this check should gate subsequent commands.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
stats = run(["--brain-dir", str(brain), "stats"], env=env)
run(["--brain-dir", str(brain), "audit"], env=env)
if f"Brain: {brain}" not in stats:
raise SystemExit(f"stats used the wrong brain directory:\n{stats}")
stats = run(["--brain-dir", str(brain), "stats"], env=env)
if f"Brain: {brain}" not in stats:
raise SystemExit(f"stats used the wrong brain directory:\n{stats}")
run(["--brain-dir", str(brain), "audit"], env=env)
🤖 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 `@Gradata/examples/offline_quickstart_smoke.py` around lines 64 - 68, Move the
assertion that verifies stats used the correct brain directory to run
immediately after obtaining stats and before calling run(..., "audit") so the
script fails fast; specifically, after the call that assigns stats =
run(["--brain-dir", str(brain), "stats"], env=env) check if f"Brain: {brain}" is
in stats and raise SystemExit(...) if not, and only then invoke
run(["--brain-dir", str(brain), "audit"], env=env) — this ensures the stats
validation gates running audit and prevents contamination.

Source: Learnings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant