Skip to content

Add property tests for cycles, separators, interpolation (#322)#377

Draft
leynos wants to merge 1 commit into
mainfrom
issue-322-proptest-cycle-ninja-interp
Draft

Add property tests for cycles, separators, interpolation (#322)#377
leynos wants to merge 1 commit into
mainfrom
issue-322-proptest-cycle-ninja-interp

Conversation

@leynos

@leynos leynos commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #322

Adds the three groups of generative coverage the issue requests (proptest was already a dev-dependency, so no Cargo.toml change was needed):

  1. Cycle detection (src/ir/cycle_analyse_tests.rs):

    • forward-edge-only graphs never report a cycle, regardless of node count or edge layout;
    • any graph with a back-edge (closed over a guaranteed chain) always reports one;
    • missing-dependency records are exactly the edges whose targets are absent from the target map (subset property plus completeness);
    • results are stable across arbitrary HashMap insertion orderings (prop_shuffle).
  2. Ninja separator ordering (tests/ninja_property_tests.rs): for arbitrary non-empty inputs/implicit_deps/order_only_deps, the build line is exactly build out: act <inputs> | <implicit> || <order-only>; with empty implicit_deps the | separator is absent while || remains.

  3. Command interpolation (src/ir/cmd_interpolate.rs): $in, $out, and both __NETSUKE_*_PLACEHOLDER__ tokens inside backticks survive verbatim for arbitrary path lists; placeholders outside backticks are always replaced with the joined lists.

Existing canonicalisation/detector property tests already covered determinism; these additions fill the gaps the issue identified.

Validation

  • make check-fmt / make lint / make test — pass (38 suites; new ninja_property_tests binary included)

🤖 Generated with Claude Code

Summary by Sourcery

Add property-based tests to strengthen guarantees around cycle analysis, Ninja separator ordering, and command interpolation behavior.

Enhancements:

  • Clarify and enforce invariants of the cycle analysis logic via property-based specifications for acyclic, cyclic, and missing-dependency scenarios.
  • Document and lock in the expected Ninja build-line separator contract across varying dependency layouts using generative tests.
  • Specify interpolation behavior for command templates with placeholders inside and outside backticks using property-based tests.

Tests:

  • Introduce proptest-based coverage for cycle detection, missing-dependency reporting, and stability across HashMap insertion orders in the IR cycle analysis tests.
  • Add property-based Ninja generator tests to assert correct ordering and conditional presence of | and || separators in build lines.
  • Add property-based command interpolation tests to ensure placeholders inside backticks are preserved and placeholders outside are always substituted with joined path lists.

Chores:

  • Add a regression corpus file for cycle analysis property tests.

Add the generative coverage requested for the invariants introduced or
extended by PR #315 (`proptest` was already a dev-dependency):

- Cycle detection (`src/ir/cycle_analyse_tests.rs`): graphs built from
  arbitrary forward edges never report a cycle; any graph with a
  back-edge (closed over a guaranteed chain) always does;
  missing-dependency records are exactly the edges whose targets are
  absent from the target map; and `analyse` results are stable across
  arbitrary `HashMap` insertion orderings.

- Ninja separator ordering (`tests/ninja_property_tests.rs`): for any
  `BuildEdge` with non-empty `inputs`, `implicit_deps`, and
  `order_only_deps`, the emitted build line is exactly
  `inputs | implicit || order-only`; the `|` separator is absent when
  `implicit_deps` is empty while `||` is still emitted.

- Command interpolation (`src/ir/cmd_interpolate.rs`): `$in`/`$out`
  and `__NETSUKE_*_PLACEHOLDER__` tokens inside backtick-delimited
  regions survive verbatim for arbitrary input/output lists, and
  placeholders outside backticks are always replaced with the joined
  lists.
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: ae8c7ddc-1a7b-44fd-a69d-8ea02898f1ef

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-322-proptest-cycle-ninja-interp

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

@sourcery-ai

sourcery-ai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds property-based tests for cycle analysis, Ninja build-line separator ordering, and command interpolation, including helper generators and regression seeds, to strengthen invariants around cycles, missing dependencies, determinism across HashMap insertion order, Ninja output formatting, and placeholder handling within and outside backticks.

Flow diagram for command interpolation behavior with backticks and placeholders

flowchart LR
    Tmpl["template with tokens ($in, $out, __NETSUKE_INS_PLACEHOLDER__, __NETSUKE_OUTS_PLACEHOLDER__)"]
    Ins["ins: list of input paths"]
    Outs["outs: list of output paths"]

    Tmpl --> IC["interpolate_command(template, ins, outs)"]
    Ins --> IC
    Outs --> IC

    IC --> BQ{"token inside backticks?"}

    BQ -- "yes" --> Preserve["leave token text unchanged in output"]
    Preserve --> Cmd1["command equals original template"]

    BQ -- "no" --> PH{"is token a __NETSUKE_*_PLACEHOLDER__?"}

    PH -- "yes" --> Replace["replace placeholder with joined ins/outs (space separated)"]
    Replace --> Cmd2["command contains expanded paths and no PLACEHOLDER text"]

    PH -- "no" --> Other["process other tokens (e.g. $in, $out) according to existing rules"]
Loading

File-Level Changes

Change Details Files
Introduce proptest-based coverage for cycle analysis invariants in the IR graph.
  • Add helper function to build DAGs from forward-only edge specifications using sequential node names and EdgeBuilder.
  • Add property test asserting that graphs with only forward edges never produce cycle reports, regardless of node count or edge layout.
  • Add property test asserting that graphs with a guaranteed back-edge over a connected chain always report a cycle.
  • Add property test that missing-dependency records match exactly the edges whose targets are absent from the build target map, including subset and completeness properties.
  • Add property test that analyse results (cycle and missing-dependencies) are stable across different HashMap insertion orders by shuffling node insertion.
src/ir/cycle_analyse_tests.rs
proptest-regressions/ir/cycle_analyse_tests.txt
Add property-based tests to lock in Ninja build-line separator ordering for explicit, implicit, and order-only dependencies.
  • Introduce helper functions to construct small BuildGraph instances from string dependency lists and extract the generated Ninja build line.
  • Define a string generator for short, shell-safe path names to use as inputs and dependencies.
  • Add property test that for non-empty inputs/implicit/order-only lists, generated build lines always follow the `build out: act
Add command interpolation property tests ensuring correct handling of placeholders inside and outside backticks.
  • Add path_list strategy for generating short, shell-safe Utf8PathBuf lists and a token strategy for selecting placeholder tokens.
  • Add property test asserting that $in, $out and placeholder tokens inside backticks are never substituted and survive verbatim after interpolation.
  • Add property test asserting that placeholder tokens outside backticks are always replaced with joined input and output lists and that no placeholder substrings remain in the resulting command.
src/ir/cmd_interpolate.rs

Assessment against linked issues

Issue Objective Addressed Explanation
#322 Ensure proptest is available as a dev-dependency in the project (so property-based tests can be added).
#322 Add proptest-based property tests for cycle detection covering: (a) forward-edge-only graphs never report cycles, (b) any graph with a back-edge reports a cycle, (c) missing-dependency records correspond exactly to edges whose targets are absent from the target map, and (d) results are stable across arbitrary HashMap insertion orderings.
#322 Add proptest-based property tests for (a) Ninja separator ordering (inputs then ` implicit_depsthen

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

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.

Add proptest property-based tests for cycle detection, Ninja separator ordering, and command interpolation

1 participant