Skip to content

Prepare sandbox policy for strict lint checks - #310

Draft
leynos wants to merge 1 commit into
harden-lint-build-util-20260924from
harden-lint-weaver-sandbox-20260924
Draft

leynos wants to merge 1 commit into
harden-lint-build-util-20260924from
harden-lint-weaver-sandbox-20260924

Conversation

@leynos

@leynos leynos commented Sep 24, 2026 •

Copy link
Copy Markdown
Owner

Summary

This branch prepares the sandbox policy source for the strict Rust lint baseline. It documents policy fields, path-resolution helpers, and error payloads; makes compatible accessors const; and removes an unused receiver from the cache helper. The runtime aliases added in #297 remain distinct from the caller's executable allowlist. No lint is suppressed.

This is the sandbox source-fix layer above #309 (build-script environment injection). It precedes the separate EnvGuard/launcher boundary work and the later lint-configuration layer.

Review walkthrough

  • Start with profile.rs for documented policy state, compatible const accessors, and the static cache helper. The pinned compiler does not support a const slice accessor through Vec's dereference, so runtime_paths remains an ordinary method.
  • Review sandbox.rs for launch-path documentation. Original runtime aliases remain mounted while initial-command authorisation still uses the caller's executable list.
  • Finish with error.rs for documented error payloads without API or display-string changes.

Validation

  • make check-fmt, make spelling, make lint, make test, make typecheck, make markdownlint, make nixie, and make test-workflow-contracts: all passed sequentially on commit aab776ff050f12e1448f404eab01027c500a2d8e. The test gate passed 1,589 tests with four skipped and all doctests; workflow contracts passed 187 tests. Logs: /tmp/weaver-sandbox-20260924-old-policy-gates-run1/.
  • Temporary final-policy probe: all 19 workspace members inherited the lint tables in an isolated worktree. Strict sandbox rustdoc passed. Workspace Clippy found no located diagnostics in this branch's three files, but the run failed on ten findings in EnvGuard, two in its tests, and newly reachable CLI and LSP-host source; that failing run is a lower bound, not a compliant workspace verdict. Scoped Whitaker stopped at two EnvGuard unsafe-code compiler errors before its suite ran. Logs: /tmp/weaver-sandbox-20260924-probe-*.
  • git diff --check passed. Independent static review found no blocking issue. The committed patch matches the tested source diff SHA-256 447135652b4e1efc944841b0ae5ec61580307f9948c679aa8842fc61e9efab94.

Notes

The existing configuration deliberately governs this source-fix layer. Later layers own final lint enforcement and the unresolved environment/unsafe boundary. Parent #309's hosted CI currently fails at the Whitaker installer, which may also block this stacked PR's hosted checks; that is a tooling failure rather than a local source-gate result. No claim of full-estate baseline compliance is made here.

References

Summary by Sourcery

Prepare the sandbox policy source for the strict lint baseline without changing its runtime behavior or public error messages.

Enhancements:

  • Document sandbox profile state, path resolution, launch behavior, and error payloads for stricter Rust linting.
  • Make compatible policy accessors const and simplify the cached path-resolution helper.
  • Clarify that runtime aliases remain available for mounting without expanding the executable launch allowlist.

Document the sandbox policy fields, path resolution helpers, and error
payloads so the planned private-item and public documentation gates can
be enabled without suppressions. Mark compatible accessors as const and
remove the unused receiver from the canonical path cache helper.

Keep original runtime path aliases and executable authorization separate.
@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Team

Run ID: a8d11614-8295-413f-9506-0b649e5a5fe1

📥 Commits

Reviewing files that changed from the base of the PR and between 7953675 and aab776f.

📒 Files selected for processing (3)
  • crates/weaver-sandbox/src/error.rs
  • crates/weaver-sandbox/src/profile.rs
  • crates/weaver-sandbox/src/sandbox.rs
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • leynos/nixie (auto-detected)
  • leynos/ortho-config (auto-detected)
  • leynos/typos-config-builder (auto-detected)
  • leynos/whitaker (auto-detected)
  • leynos/shared-actions (auto-detected)
  • leynos/df12-www (auto-detected)
  • leynos/corbusier (auto-detected)

Included review availability: 2 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 3 reviews per hour.


Summary

  • Document sandbox profile fields, path-resolution helpers, launch checks and error payloads.
  • Make allow_networking, network_policy and NetworkPolicy::is_denied const.
  • Call SandboxProfile::canonicalized_paths as an associated function.
  • Preserve runtime behaviour, error messages and the separation between mount path aliases and executable authorization.

No new execplan is identified in the supplied change summary. Test results are not available.

Walkthrough

The changes document sandbox error fields, profile policies, and launch checks. Selected profile methods become const. The summaries report no runtime logic change.

Changes

Sandbox API and launch behaviour

Layer / File(s) Summary
Profile policy and path-access API
crates/weaver-sandbox/src/profile.rs
Document profile fields and path accessors. Make selected policy methods const. Keep canonical-path inputs and results unchanged.
Sandbox launch and error contracts
crates/weaver-sandbox/src/error.rs, crates/weaver-sandbox/src/sandbox.rs
Document error fields, the injectable thread counter, spawn error conditions, launch checks and path resolution. The implementation remains unchanged.

Suggested labels: Issue

Priority: ⬇️ Low

Change: Refactor

Merge Risk: ⚪ Minimal · up to aab77

No actionable behavior or compatibility regression was found in the reviewed changes; no material risk remains before normal checks.


Caution

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

  • Ignore

❌ Failed checks (1 error, 2 warnings)

Check name Status Explanation Resolution
Testing (Overall) ❌ Error The pull request adds compile-time API capability without a test for it. The diff changes SandboxProfile::allow_networking, SandboxProfile::network_policy, SandboxProfile::environment_policy, an… Add compile-time tests that use the changed methods from constant contexts. Cover NetworkPolicy::is_denied with a constant expression, and define test const fn helpers that call the SandboxProfile accessors. Keep the existing runtime …
Developer Documentation ⚠️ Warning The pull request adds and changes internal sandbox interfaces without updating docs/developers-guide.md. The diff adds the injectable Sandbox::thread_counter test abstraction and `with_thread_coun… Update docs/developers-guide.md with a sandbox implementation section. Document the SandboxProfile policy state, canonical-path cache, environment and network translation, the separation between runtime aliases and the executable allowl…
Testing (Compile-Time / Ui) ⚠️ Warning The PR introduces compile-time Rust behaviour by changing SandboxProfile::allow_networking, SandboxProfile::network_policy, and NetworkPolicy::is_denied to const fn. The authoritative diff cha… Add a sandbox compile-time test using trybuild or an equivalent Rust UI harness. Compile a downstream-style fixture that uses the public methods in const fn bodies and evaluates NetworkPolicy::is_denied in a constant. Add the required…
✅ Passed checks (12 passed)
Check name Status Explanation
Title check ✅ Passed Accept the title. It accurately identifies the main change: preparing the sandbox policy for strict lint checks. No issue or roadmap reference is required by the supplied context.
Description check ✅ Passed Accept the description. It directly describes the sandbox documentation, const accessors, helper change, validation results, and scope limitations.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 3 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.
User-Facing Documentation ✅ Passed Pass the check. The pull request changes only Rust documentation, error-variant formatting, test-only injection, and const qualifiers. The diff introduces no new runtime behaviour or user-facing wor…
Module-Level Documentation ✅ Passed Pass the module-level documentation check. The PR changes only error.rs, profile.rs, and sandbox.rs; each has a //! module docstring that states its purpose and relationship to the sandbox or …
Testing (Unit And Behavioural) ✅ Passed Mark this check PASS. The reviewed diff changes documentation, const qualification, and the receiver form of an internal cache helper. It does not change runtime behaviour or an external workflow. E…
Testing (Property / Proof) ✅ Passed Pass this check. The PR adds documentation, makes existing accessors const, and removes an unused receiver from canonicalized_paths; it does not introduce runtime logic or a new invariant over a r…
Unit Architecture ✅ Passed The pull request does not introduce a Unit Architecture violation. The diff adds documentation, makes pure policy accessors const, and removes the unused &self receiver from canonicalized_paths.…
Domain Architecture ✅ Passed Accept this check. The PR changes only weaver-sandbox infrastructure code. The executable changes make policy accessors const and remove an unused receiver from the canonical-path cache helper. Th…
Observability ✅ Passed This PR makes no changes to operational behaviour. The modifications consist entirely of: 1. Documentation additions – field-level documentation for SandboxError variants and SandboxProfile st…
Full details: Testing (Overall)

Explanation

The pull request adds compile-time API capability without a test for it. The diff changes SandboxProfile::allow_networking, SandboxProfile::network_policy, SandboxProfile::environment_policy, and NetworkPolicy::is_denied to const fn; NetworkPolicy::is_denied can now be used in a constant expression. No test file changes exist. The existing tests check runtime results only, so they would still pass if the const qualifiers were removed.

Resolution

Add compile-time tests that use the changed methods from constant contexts. Cover NetworkPolicy::is_denied with a constant expression, and define test const fn helpers that call the SandboxProfile accessors. Keep the existing runtime tests for policy semantics.

Full details: Developer Documentation

Explanation

The pull request adds and changes internal sandbox interfaces without updating docs/developers-guide.md. The diff adds the injectable Sandbox::thread_counter test abstraction and with_thread_counter_for_tests, changes the internal canonical-path helper, and changes policy accessors to const. The developer guide documents sandbox behaviour tests, but it does not document these policy and test abstractions. No documentation or planning file is changed in the pull request. ADR 013 already records the runtime-alias and executable-allowlist boundary, so no new architectural decision is evident.

Resolution

Update docs/developers-guide.md with a sandbox implementation section. Document the SandboxProfile policy state, canonical-path cache, environment and network translation, the separation between runtime aliases and the executable allowlist, and the single-thread preflight. Document that tests inject the thread counter through with_thread_counter_for_tests, and record the const policy accessors and their intended compatibility role. Keep ADR 013 as the design record for the existing runtime-mount boundary unless the implementation changes that boundary.

Full details: Testing (Compile-Time / Ui)

Explanation

The PR introduces compile-time Rust behaviour by changing SandboxProfile::allow_networking, SandboxProfile::network_policy, and NetworkPolicy::is_denied to const fn. The authoritative diff changes only error.rs, profile.rs, and sandbox.rs; it adds no compile-time test. The sandbox crate has no trybuild or equivalent UI test, and its existing unit tests call these methods only at runtime. The unchanged error display strings do not require a new snapshot for this check.

Resolution

Add a sandbox compile-time test using trybuild or an equivalent Rust UI harness. Compile a downstream-style fixture that uses the public methods in const fn bodies and evaluates NetworkPolicy::is_denied in a constant. Add the required test dependency and test wiring, then keep the fixture focused on the intended const API contract.


Mark each error field with care,
Let policy methods evaluate at compile time.
Trace the paths through ancestor and suffix,
Keep launch checks clear and in view,
Then send the sandbox docs on their way.

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

@sourcery-ai

sourcery-ai Bot commented Sep 24, 2026

Copy link
Copy Markdown

Reviewer's Guide

Prepares the sandbox source for the strict Rust lint baseline through documentation, compatible const accessors, and a receiver-free canonicalization cache helper, with no intended runtime or error-display changes.

Sequence diagram for sandbox command launch validation

sequenceDiagram
    participant Caller
    participant Sandbox
    participant SandboxProfile
    participant Filesystem
    participant Birdcage

    Caller->>Sandbox: spawn(command)
    Sandbox->>Sandbox: ensure_single_threaded()
    Sandbox->>Sandbox: canonical_program(program)
    Sandbox->>SandboxProfile: executable_paths_canonicalized()
    SandboxProfile->>Filesystem: canonicalize executable paths
    Filesystem-->>SandboxProfile: canonical paths
    SandboxProfile-->>Sandbox: executable allowlist
    Sandbox->>Sandbox: ensure_program_whitelisted(program)
    Sandbox->>SandboxProfile: runtime_paths()
    SandboxProfile-->>Sandbox: original runtime aliases
    Sandbox->>Birdcage: activate and launch with exceptions
    Birdcage-->>Caller: SandboxChild
Loading

File-Level Changes

Change Details Files
Documents sandbox profile state and accessor behavior for strict lint and rustdoc expectations.
  • Adds field-level documentation for paths, caches, and policy settings.
  • Makes compatible policy accessors and predicates const.
  • Keeps runtime aliases separate from the executable launch allowlist.
crates/weaver-sandbox/src/profile.rs
Clarifies sandbox launch, validation, and path-resolution contracts without changing runtime behavior.
  • Documents launch errors, thread preflight, executable authorization, exception collection, and canonicalization helpers.
  • Retains runtime alias mounting while checking initial commands against the caller-provided executable paths.
  • Documents reconstruction of paths beneath existing ancestors.
crates/weaver-sandbox/src/sandbox.rs
Adds documentation to structured sandbox error payload fields while preserving the public error API and messages.
  • Documents rejected executables, missing paths, canonicalization failures, thread-count failures, and related payloads.
crates/weaver-sandbox/src/error.rs

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

@pandalump

Copy link
Copy Markdown
Collaborator

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot added the Issue label Sep 25, 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.

Pre-merge checks failed. Please resolve the failing checks before merging.

This branch has not been deployed

No deployments
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.

2 participants