Skip to content

Remove process env mutation (#177) (#221) - #223

Draft
leynos wants to merge 3 commits into
feat/align-workspace-lint-policyfrom
issue-177-221-remove-in-process-env-mutation
Draft

Remove process env mutation (#177) (#221)#223
leynos wants to merge 3 commits into
feat/align-workspace-lint-policyfrom
issue-177-221-remove-in-process-env-mutation

Conversation

@leynos

@leynos leynos commented Aug 24, 2026

Copy link
Copy Markdown
Owner

Summary

This change removes process-global environment mutation from the HNSW property
tests. Configuration now flows through injected mockable::Env objects, and
tests use MockEnv, so they can execute independently and in parallel.

It applies the same injection boundary to the workspace remaining
environment-variable readers and denies direct std::env methods that would
bypass it.

Closes #177
Closes #221

Review walkthrough

Validation

  • make check-fmt
  • make test (1,082 passed; 1 skipped)
  • make typecheck
  • make lint
  • make markdownlint
  • make nixie
  • coderabbit review --agent --committed --base origin/feat/align-workspace-lint-policy (0 findings)

References

@coderabbitai

coderabbitai Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

Warning

Your free Security trial is over. An organization admin can activate billing to continue.


Comment @coderabbitai help to get the list of available commands.

codescene-access[bot]

This comment was marked as outdated.

@leynos
leynos force-pushed the issue-177-221-remove-in-process-env-mutation branch from aaacec5 to 519396a Compare August 24, 2026 13:44
codescene-access[bot]

This comment was marked as outdated.

@codescene-access codescene-access 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.

No quality gates enabled for this code.

@sourcery-ai

sourcery-ai Bot commented Aug 24, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR establishes mockable::Env as the workspace boundary for environment-variable access, using DefaultEnv in production and MockEnv in tests; HNSW property tests no longer mutate process-global state, remaining readers are migrated, and Clippy now prevents direct reads or mutations from being reintroduced.

Sequence diagram for injected environment configuration

sequenceDiagram
    participant EntryPoint
    participant Env as mockable::Env
    participant Configuration

    EntryPoint->>Configuration: load_with_env(Env)
    Configuration->>Env: string(variable)
    Env-->>Configuration: configured value or None
    Configuration-->>EntryPoint: resolved configuration

    Note over EntryPoint,Env: Production supplies DefaultEnv, tests supply MockEnv
Loading

File-Level Changes

Change Details Files
Introduces dependency-injected environment access across runtime, benchmark, CI, and test-support code.
  • Adds mockable and uses DefaultEnv at production entry points.
  • Threads &dyn Env through environment-dependent helpers.
  • Preserves existing defaults, parsing, and error handling while replacing direct reads with string, os_string, or raw access.
Cargo.toml
chutoro-benches/Cargo.toml
chutoro-benches/benches/hnsw.rs
chutoro-benches/benches/hnsw_ef_sweep.rs
chutoro-benches/src/criterion_support.rs
chutoro-benches/src/neighbour_scoring/benchmark_runner.rs
chutoro-benches/src/neighbour_scoring/build_profile.rs
chutoro-benches/src/source/mnist/mod.rs
chutoro-cli/Cargo.toml
chutoro-cli/src/logging.rs
chutoro-core/src/mst/property/types.rs
chutoro-providers/dense/Cargo.toml
chutoro-providers/dense/build.rs
chutoro-test-support/Cargo.toml
chutoro-test-support/src/bin/benchmark_regression_gate.rs
chutoro-test-support/src/bin/kani_nightly_gate.rs
chutoro-test-support/src/ci/benchmark_regression_profile.rs
chutoro-test-support/src/ci/property_test_profile.rs
chutoro-test-support/tests/benchmark_regression_gate_cli.rs
chutoro-test-support/tests/kani_nightly_gate_cli.rs
Removes process-global environment mutation from HNSW property tests and replaces serialized real-environment tests with isolated mocks.
  • Adds an injectable search-property configuration seam with DefaultEnv for production and MockEnv for tests.
  • Rewrites unset, valid, and invalid override tests without set_var, remove_var, or a global mutex.
  • Adds injectable coverage detection and MST concurrency configuration loading.
chutoro-core/Cargo.toml
chutoro-core/src/hnsw/tests/property/search_config.rs
chutoro-core/src/hnsw/tests/support.rs
chutoro-core/src/mst/property/types.rs
Enforces the environment-access boundary through workspace lint policy.
  • Denies direct std::env variable reads and process mutation via Clippy.
  • Applies the deny lint to benchmark targets as well as workspace lints.
  • Retains narrowly scoped std::env usage for supported operations such as arguments, temp directories, and error types.
clippy.toml
Cargo.toml
chutoro-benches/Cargo.toml
Updates environment-driven test-support profiles and their tests to use mockable environments.
  • Replaces generic lookup closures with Env injection in property-test and benchmark-regression profile loaders.
  • Uses MockEnv in profile unit tests for deterministic, parallel-safe cases.
  • Routes CLI integration-test binary discovery through DefaultEnv.
chutoro-test-support/src/ci/property_test_profile.rs
chutoro-test-support/src/ci/benchmark_regression_profile.rs
chutoro-test-support/tests/benchmark_regression_gate_cli.rs
chutoro-test-support/tests/kani_nightly_gate_cli.rs

Assessment against linked issues

Issue Objective Addressed Explanation
#177 Rework the HNSW search configuration property tests so configuration is supplied through an injected environment seam rather than process-global environment access.
#177 Remove the local ENV_LOCK and every unsafe std::env::set_var or std::env::remove_var call from search_config.rs.
#177 Ensure the workspace no longer permits direct environment reads or mutations that bypass the injection boundary, allowing the property tests to run in parallel without global environment serialization.
#221 Refactor the HNSW search-configuration loader to use an injected environment reader, with production code using the real environment and tests using isolated stubs instead of process-global mutation.
#221 Remove the HNSW tests' in-process environment mutations, mutex guard, unsafe blocks, and global-state coupling while preserving coverage of unset, valid, and invalid environment values.
#221 Add a workspace Clippy policy that denies direct std::env variable reads and mutation methods, preventing the prohibited pattern from returning.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

leynos added 3 commits August 24, 2026 18:04
Replace process-global HNSW test mutation with MockEnv-backed configuration
injection, so property tests can run concurrently without unsafe access.

Route environment-variable reads through mockable::Env across the workspace
and deny the direct std::env methods to prevent regression.
Regenerate the lockfile for the lint-policy branch dependency graph and
resolve the rebased test configuration lint findings. Record the isolated
property-test timeout experiment and the shared test-binary reader decision
for the active lint-policy plan.
Keep the parent branch's `map_or` policy parsing while preserving the
injected mockable environment reader. The previous rebase replay left both
loader bodies in the implementation block, preventing the test-support
crate from compiling.
@leynos
leynos force-pushed the issue-177-221-remove-in-process-env-mutation branch from 519396a to f3c778f Compare August 24, 2026 16:27
@leynos
leynos changed the base branch from main to feat/align-workspace-lint-policy August 24, 2026 16:27

@codescene-access codescene-access 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.

Code Health Improved (1 files improve in Code Health)

Gates Failed
Enforce advisory code health rules (1 file with String Heavy Function Arguments)

Our agent can fix these. Install it.

Gates Passed
5 Quality Gates Passed

Reason for failure
Enforce advisory code health rules Violations Code Health Impact
process.rs 1 advisory rule 9.69 Suppress

See analysis details in CodeScene

View Improvements
File Code Health Impact Categories Improved
tests.rs 9.39 → 10.00 Code Duplication

Absence of Expected Change Pattern

  • chutoro/chutoro-core/src/hnsw/tests/property/types.rs is usually changed with: chutoro/chutoro-core/src/hnsw/tests/property/strategies.rs
  • chutoro/chutoro-providers/dense/src/simd/tests.rs is usually changed with: chutoro/chutoro-providers/dense/src/simd/kernels.rs

Quality Gate Profile: Pay Down Tech Debt
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.

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

Labels

None yet

Projects

None yet

1 participant