Skip to content

Separate Ninja generation steps from runner reporting (#343)#374

Draft
leynos wants to merge 1 commit into
mainfrom
issue-343-pure-ninja-generation
Draft

Separate Ninja generation steps from runner reporting (#343)#374
leynos wants to merge 1 commit into
mainfrom
issue-343-pure-ninja-generation

Conversation

@leynos

@leynos leynos commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #343

Splits generation into composable query-style steps with reporting kept in a thin runner wrapper, as proposed.

Changes

  • src/runner/generation.rs (new): pure steps load_manifest (with an optional StageObserver callback), build_graph, and ninja_text — no StatusReporter anywhere; localised error contexts preserved.
  • src/runner/mod.rs: generate_ninja now interleaves report_pipeline_stage calls between the pure steps (identical stage sequence); stage_reporting_callback maps manifest stages to reporter updates; load_manifest_with_stage_reporting becomes a thin wrapper.
  • src/runner/graph.rs: shares generation::build_graph instead of duplicating context wrapping.

Testing

  • New generation_steps_run_without_reporter unit test composes the pure pipeline end to end (manifest file → graph → Ninja text) with no reporter.
  • All existing graph/build/manifest tests unchanged and green.

Validation

  • make check-fmt / make lint / make test — pass (37 suites)

🤖 Generated with Claude Code

Summary by Sourcery

Extract Ninja generation into pure, composable steps and keep status reporting in a thin runner wrapper.

Enhancements:

  • Introduce a dedicated generation module with pure manifest loading, build graph construction, and Ninja text synthesis steps usable without a status reporter.
  • Refactor runner manifest loading to delegate to the generation pipeline while mapping manifest load stages into pipeline status updates.
  • Reuse the shared generation-based graph-building path in the graph handler to avoid duplicated context wrapping.

Tests:

  • Add an end-to-end test that exercises the generation pipeline (manifest → graph → Ninja) without any status reporter.

`generate_ninja` mixed query-style generation work (load manifest,
build graph, synthesise Ninja text) with reporter side effects,
making the conversion path hard to reuse for dry-run or background
generation.

Introduce `runner::generation` with three pure, composable steps —
`load_manifest`, `build_graph`, and `ninja_text` — none of which
require a `StatusReporter`. Manifest-stage observation is an optional
callback (`StageObserver`), so the pure path simply passes `None`.

The runner keeps reporting in thin orchestration wrappers:
`generate_ninja` interleaves `report_pipeline_stage` calls between the
pure steps (same stage sequence as before), and
`load_manifest_with_stage_reporting` builds the reporter-mapping
callback via the extracted `stage_reporting_callback`. The graph
subcommand now shares `generation::build_graph` instead of
duplicating context wrapping.

A unit test exercises the composed pure pipeline end to end without
any reporter.
@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: 990fc8d5-b0ba-46a7-9329-3e6c4a1fc1d5

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-343-pure-ninja-generation

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

Refactors the Ninja generation pipeline into pure, composable steps in a new generation module, with runner-level reporting layered on top, and updates graph handling and tests to use the shared pipeline.

Sequence diagram for generate_ninja with separated generation steps

sequenceDiagram
    participant Runner
    participant Reporter
    participant Generation
    participant ManifestModule as manifest
    participant BuildGraphType as BuildGraph
    participant NinjaGen as ninja_gen

    Runner->>Reporter: report_pipeline_stage(PipelineStage::IrGenerationValidation)
    Runner->>Generation: generate_ninja
    activate Generation
    Generation->>BuildGraphType: build_graph(&manifest)
    deactivate Generation

    Runner->>Reporter: report_pipeline_stage(PipelineStage::NinjaSynthesisAndExecution)
    Runner->>Generation: ninja_text(&graph)
    activate Generation
    Generation->>NinjaGen: generate(&graph)
    deactivate Generation

    Generation-->>Runner: NinjaContent
Loading

Flow diagram for manifest loading and reporting separation

flowchart TD
    A[load_manifest_with_stage_reporting]
    B[stage_reporting_callback]
    C[report_pipeline_stage]
    D[generation::load_manifest]
    E[manifest::from_path_with_policy]

    A --> B
    B --> C
    A --> D
    D --> E
Loading

File-Level Changes

Change Details Files
Extract pure, composable Ninja generation steps into a new generation module and wire them into the runner.
  • Introduce generation::load_manifest, generation::build_graph, and generation::ninja_text as pure functions without StatusReporter dependencies
  • Keep localized error context when delegating from previous inlined logic to the new generation functions
  • Update generate_ninja to call the new generation steps while interleaving report_pipeline_stage calls to preserve the existing reporting sequence
src/runner/generation.rs
src/runner/mod.rs
Decouple manifest stage reporting from loading logic via a reusable callback wrapper.
  • Add stage_reporting_callback helper that maps ManifestLoadStage values to PipelineStage values and emits report_pipeline_stage calls
  • Refactor load_manifest_with_stage_reporting into a thin wrapper over generation::load_manifest using the new callback
src/runner/mod.rs
Have graph handling reuse the shared generation pipeline instead of duplicating graph construction.
  • Change graph handling to call generation::build_graph for BuildGraph construction
  • Remove duplicated context-wrapping logic around BuildGraph::from_manifest in favor of the shared generation step
src/runner/graph.rs
Add an end-to-end test for the pure generation pipeline without any status reporter.
  • Create generation_steps_run_without_reporter test to run manifest → graph → Ninja text using the new generation functions
  • Assert that the generated Ninja includes the expected build edge to validate end-to-end behavior
src/runner/tests.rs

Assessment against linked issues

Issue Objective Addressed Explanation
#343 Create a pure (or mostly pure) generation path composed of reusable steps: load manifest, build graph, and generate Ninja text, without mandatory StatusReporter side effects.
#343 Ensure runner commands still emit the same pipeline stage reporting sequence while delegating core work to the pure generation steps.
#343 Keep existing graph/build/manifest tests passing and add coverage to confirm the pure generation pipeline works end-to-end (and passes formatting/lint/test checks).

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.

Separate Ninja generation steps from runner reporting

1 participant