Skip to content

Comments

Merged check fix please#76

Open
heidi-dang wants to merge 3 commits intomainfrom
fix-ci-collection-failures-11963828567652270193
Open

Merged check fix please#76
heidi-dang wants to merge 3 commits intomainfrom
fix-ci-collection-failures-11963828567652270193

Conversation

@heidi-dang
Copy link
Owner

This PR addresses the issue where CI fails during pytest collection on macOS because tests import the optional C++ extension heidi_cpp at module import time.

Changes:

  • Added tests/conftest.py with requires_heidi_cpp marker logic.
  • Refactored tests/test_budget_guardrails.py, tests/test_core_integration.py, and tests/test_perf_baseline.py to use lazy-loading fixtures.
  • Updated tests/test_cpp_ext.py, tests/test_doctor.py, and tests/test_sec_redteam.py to use the new marker system.
  • Added a check in tests/test_daemon.py to skip tests if the heidid binary is not found.

Verification:

  • Confirmed tests are skipped when heidi_cpp is missing.
  • Confirmed tests pass when heidi_cpp is built and installed.

PR created automatically by Jules for task 11963828567652270193 started by @heidi-dang

Implement Option A: skip C++-dependent tests when heidi_cpp is not installed.
This prevents pytest collection failures on platforms like macOS by:
1. Creating tests/conftest.py with a `requires_heidi_cpp` marker and skip logic.
2. Removing module-level `import heidi_cpp` in dependent tests.
3. Using session-scoped fixtures for lazy loading of the heidi_cpp extension.
4. Adding explicit skip logic for daemon tests if the heidid binary is missing.
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist
Copy link

Summary of Changes

Hello @heidi-dang, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses and resolves CI failures, particularly on macOS, which were occurring because tests attempted to import the optional heidi_cpp C++ extension during pytest collection when the extension was not present. The solution involves implementing a new pytest marker and lazy-loading fixtures to ensure that tests dependent on heidi_cpp are only executed when the extension is available. Additionally, a check for the heidid binary was integrated into relevant tests to prevent failures in environments where the daemon executable is missing.

Highlights

  • Conditional Test Skipping: Introduced a new pytest marker, requires_heidi_cpp, to conditionally skip tests that depend on the heidi_cpp C++ extension if it's not installed, preventing CI failures.
  • Lazy-Loading for C++ Extension: Refactored multiple test files to use a pytest fixture for lazy-loading the heidi_cpp module, ensuring the extension is only imported when tests are actually run, not during collection.
  • Daemon Binary Availability Check: Added a check in tests/test_daemon.py to skip tests if the heidid binary is not found, improving test robustness across different environments.
Changelog
  • tests/conftest.py
    • Added a new file to define the requires_heidi_cpp pytest marker.
    • Implemented pytest_collection_modifyitems to skip tests marked with requires_heidi_cpp if the heidi_cpp module is not found.
  • tests/test_budget_guardrails.py
    • Removed direct import of heidi_cpp.
    • Added pytestmark = pytest.mark.requires_heidi_cpp to the module.
    • Introduced a heidi_cpp_mod session-scoped fixture for lazy-loading heidi_cpp.
    • Updated test functions to use the heidi_cpp_mod fixture instead of direct heidi_cpp calls.
  • tests/test_core_integration.py
    • Removed direct import of heidi_cpp.
    • Added pytestmark = pytest.mark.requires_heidi_cpp to the module.
    • Introduced a heidi_cpp_mod session-scoped fixture for lazy-loading heidi_cpp.
    • Updated test functions to use the heidi_cpp_mod fixture instead of direct heidi_cpp calls.
  • tests/test_cpp_ext.py
    • Removed the module-level try-except block for heidi_cpp import.
    • Added pytestmark = pytest.mark.requires_heidi_cpp to the module.
    • Introduced a heidi_cpp_mod session-scoped fixture for lazy-loading heidi_cpp.
    • Updated all test and benchmark functions to use the heidi_cpp_mod fixture.
  • tests/test_daemon.py
    • Added a check to skip the daemon_process test if the heidid binary is not found at the expected path.
  • tests/test_doctor.py
    • Applied the pytest.mark.requires_heidi_cpp marker to test_real_mode_blocked_in_core_integration.
  • tests/test_perf_baseline.py
    • Removed direct import of heidi_cpp.
    • Added pytestmark = pytest.mark.requires_heidi_cpp to the module.
    • Introduced a heidi_cpp_mod session-scoped fixture for lazy-loading heidi_cpp.
    • Updated test functions to use the heidi_cpp_mod fixture instead of direct heidi_cpp calls.
Activity
  • No human activity (comments, reviews, etc.) has been recorded for this pull request.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively resolves the CI failures on macOS related to the optional heidi_cpp extension by introducing a pytest marker and lazy-loading fixtures. The overall strategy is solid. However, there is an opportunity to improve maintainability by reducing code duplication. The heidi_cpp_mod fixture is defined identically in several test files. This fixture should be centralized in tests/conftest.py to be available to all tests, which will make the test suite cleaner and easier to maintain.

Comment on lines +10 to +13
@pytest.fixture(scope="session")
def heidi_cpp_mod():
import heidi_cpp
return heidi_cpp

Choose a reason for hiding this comment

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

medium

To improve maintainability and reduce code duplication, this heidi_cpp_mod fixture should be defined only once in tests/conftest.py. Pytest will automatically discover and provide it to the tests that need it. Please define the fixture in tests/conftest.py and remove the duplicated definitions from this file and other test files (tests/test_core_integration.py, tests/test_cpp_ext.py, tests/test_perf_baseline.py).

Comment on lines +6 to +9
@pytest.fixture(scope="session")
def heidi_cpp_mod():
import heidi_cpp
return heidi_cpp

Choose a reason for hiding this comment

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

medium

This is a duplicated fixture definition. As mentioned in the comment for tests/test_budget_guardrails.py, please remove it and centralize it in tests/conftest.py.

Comment on lines +10 to +13
@pytest.fixture(scope="session")
def heidi_cpp_mod():
import heidi_cpp
return heidi_cpp

Choose a reason for hiding this comment

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

medium

This is a duplicated fixture definition. As mentioned in the comment for tests/test_budget_guardrails.py, please remove it and centralize it in tests/conftest.py.

Comment on lines 26 to 28
def test_real_mode_blocked_in_core_integration():
import heidi_cpp
core = heidi_cpp.Core()

Choose a reason for hiding this comment

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

medium

For consistency with other tests, this test should use the shared heidi_cpp_mod fixture (from conftest.py) instead of importing heidi_cpp directly.

Suggested change
def test_real_mode_blocked_in_core_integration():
import heidi_cpp
core = heidi_cpp.Core()
def test_real_mode_blocked_in_core_integration(heidi_cpp_mod):
core = heidi_cpp_mod.Core()

Comment on lines +9 to +12
@pytest.fixture(scope="session")
def heidi_cpp_mod():
import heidi_cpp
return heidi_cpp

Choose a reason for hiding this comment

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

medium

This is a duplicated fixture definition. As mentioned in the comment for tests/test_budget_guardrails.py, please remove it and centralize it in tests/conftest.py.

import shutil
import pytest

pytestmark = pytest.mark.requires_heidi_cpp

Choose a reason for hiding this comment

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

medium

While adding this marker is correct, the test_fuzzing function still uses a local import heidi_cpp. For consistency, please refactor it to use the shared heidi_cpp_mod fixture from conftest.py.

This PR resolves multiple CI failures including:
1. Pytest collection errors due to module-level heidi_cpp imports.
2. NameError in scripts/02_validate_clean.py due to missing validate_schema.
3. SystemExit in tests due to strict Zero-Trust validation in general JSONL loading.
4. ImportError in tests/test_loop_runner.py when using the dummy CppLoopRunner placeholder.

Changes:
- Added `tests/conftest.py` with `requires_heidi_cpp` marker logic.
- Refactored tests to use lazy-loading fixtures for `heidi_cpp`.
- Implemented missing `validate_schema` in `scripts/02_validate_clean.py`.
- Added `is_journal` parameter to `load_jsonl` in `heidi_engine/utils/io_jsonl.py` to allow graceful skipping of invalid lines for non-journal files.
- Updated `tests/test_loop_runner.py` to exclude `CppLoopRunner` if extension is missing.
- Updated journal tests to explicitly enable strict validation.
Implement Option A for CI stability and refactor JSONL utilities for security.
This PR resolves CI collection failures and preserves Zero-Trust pipeline integrity by:
1. Creating tests/conftest.py with a `requires_heidi_cpp` marker and skip logic.
2. Refactoring tests to use lazy-loading fixtures for `heidi_cpp`.
3. Updating `CppLoopRunner` parametrization to avoid dummy placeholder instantiation.
4. Restoring `validate_schema` in `scripts/02_validate_clean.py` and adding regression tests.
5. Splitting `heidi_engine/utils/io_jsonl.py` into `load_jsonl_strict` (default) and `load_jsonl_best_effort`.
6. Updating non-critical scripts to use `load_jsonl_best_effort` while keeping journal paths strict.
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