Skip to content

Extract manifest setup into test helper#132

Merged
leynos merged 5 commits intomainfrom
codex/refactor-run-to-extract-manifest-logic
Aug 21, 2025
Merged

Extract manifest setup into test helper#132
leynos merged 5 commits intomainfrom
codex/refactor-run-to-extract-manifest-logic

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Aug 19, 2025

Summary

  • factor verbose manifest path handling into ensure_manifest_exists
  • simplify process_steps::run by reusing the new helper

Closes #59

Testing

  • make fmt
  • make lint
  • make test

https://chatgpt.com/codex/tasks/task_e_68a4f22080548322848c740fcb361a81

Summary by Sourcery

Extract manifest path resolution and creation into a reusable helper and refactor process_steps::run to use it

Enhancements:

  • Add ensure_manifest_exists helper in test_support to resolve and create manifest files
  • Refactor process_steps::run to use the new helper and remove inline manifest setup code

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Aug 19, 2025

Reviewer's Guide

Introduced a reusable helper to consolidate manifest path resolution and creation, and refactored the Ninja process step to leverage this helper for cleaner and more maintainable test setup.

File-Level Changes

Change Details Files
Add ensure_manifest_exists helper for manifest setup
  • Compute manifest path based on absolute or relative input
  • Create a temporary manifest file when missing and persist it
  • Return the resolved manifest path for caller use
test_support/src/lib.rs
Refactor process_steps::run to use the new helper
  • Remove inline logic for manifest path calculation and file creation
  • Invoke ensure_manifest_exists with temp_dir and CLI file
  • Assign returned path back to world.cli.file
tests/steps/process_steps.rs

Assessment against linked issues

Issue Objective Addressed Explanation
#59 Extract manifest path resolution and creation logic from the run() function in tests/steps/process_steps.rs into a dedicated helper function.
#59 Implement the helper function (ensure_manifest_exists) in the support module to handle absolute/relative path resolution, manifest file creation when missing, and return the resolved manifest path.
#59 Refactor the run() function to use the new helper function, simplifying its implementation and improving maintainability.

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 19, 2025

Warning

Rate limit exceeded

@leynos has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 7 minutes and 55 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 0813598 and 1128cfc.

📒 Files selected for processing (2)
  • test_support/src/lib.rs (2 hunks)
  • tests/steps/process_steps.rs (2 hunks)

Summary by CodeRabbit

  • Tests

    • Consolidated manifest setup into a shared helper, improving consistency and reducing flakiness across scenarios.
    • Streamlined path handling in tests for clearer intent and easier maintenance.
  • Chores

    • Minor internal import housekeeping.

No user-facing changes in this release.

Walkthrough

Add a new public helper ensure_manifest_exists in test_support to resolve a CLI manifest path (absolute or relative), create and persist a minimal manifest file when missing, and return the resolved PathBuf. Replace inline manifest creation in tests/steps/process_steps.rs with a call to this helper.

Changes

Cohort / File(s) Summary
Test support helper addition
test_support/src/lib.rs
Add pub fn ensure_manifest_exists(temp_dir: &Path, cli_file: &Path) -> PathBuf. Resolve relative vs absolute paths, create destination directories, write a minimal manifest using NamedTempFile, persist to final path, and return resolved path. Add doc comment and necessary imports.
Process step refactor to helper
tests/steps/process_steps.rs
Remove inline manifest resolution and temp-file creation. Import and call test_support::ensure_manifest_exists(dir, cli_file) and assign returned PathBuf to world.cli.file. Adjust imports accordingly.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor Tester
    participant Run as process_steps::run()
    participant Helper as test_support::ensure_manifest_exists()
    participant FS as tempfile/FS
    participant Runner as run_ninja

    Tester->>Run: invoke run() with CLI + TempDir
    Run->>Helper: ensure_manifest_exists(temp_dir, cli_file)
    alt manifest path exists or absolute
        Helper-->>Run: return resolved PathBuf
    else manifest missing or relative
        Helper->>FS: create NamedTempFile, write minimal manifest
        Helper->>FS: persist to resolved path (create dirs if needed)
        Helper-->>Run: return resolved PathBuf
    end
    Run->>Runner: run_ninja(updated CLI)
    Runner-->>Run: result
    Run-->>Tester: result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Assessment against linked issues

Objective Addressed Explanation
Extract manifest path logic into helper and use it in run() (#59)
Handle absolute vs relative path resolution in helper (#59)
Create and persist missing manifest files in helper (#59)
Return resolved manifest path and update CLI in run() (#59)

Possibly related issues

Poem

A tiny helper springs to life,
Paths aligned, removed the strife,
Temp files stamped and placed just so,
Tests proceed with steady flow,
One call now clears the manifest woe.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/refactor-run-to-extract-manifest-logic

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

sourcery-ai[bot]

This comment was marked as resolved.

codescene-delta-analysis[bot]

This comment was marked as outdated.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

💡 Knowledge Base configuration:

  • Jira integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 4856ff7 and 94ad1f5.

📒 Files selected for processing (2)
  • test_support/src/lib.rs (2 hunks)
  • tests/steps/process_steps.rs (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.rs

📄 CodeRabbit Inference Engine (AGENTS.md)

**/*.rs: Comment why, not what; document assumptions, edge cases, trade-offs, and complexity without restating obvious code
Extract reusable logic into functions; prefer composition and declarative constructs when readable
Keep functions small, single-responsibility, and observe command/query separation
Use precise, descriptive names; boolean names should start with is/has/should
Use en-GB-oxendict spelling/grammar in comments (except external API references)
Function docs must include clear usage examples; avoid redundant examples in test docs
No Rust source file may exceed 400 lines; split long switches/tables; move large test data to external files
Fix test warnings in code; do not silence them
Extract helpers when functions are too long; group many parameters into well-named structs
Consider using Arc when returning large errors to reduce data movement
Document public APIs using Rustdoc (///) so cargo doc can generate documentation
Prefer immutable data; avoid unnecessary mut bindings
Prefer Result-based error handling over panicking where feasible
Avoid unsafe code unless absolutely necessary and document any usage clearly
Place function attributes after doc comments
Do not use return in single-line functions
Use predicate helper functions when conditionals have more than two branches
Do not silence lints except as a last resort; suppressions must be tightly scoped and include a clear reason
Prefer #[expect(...)] over #[allow(...)] for lint management
Prefer .expect() over .unwrap()
Use conditional compilation (#[cfg]/#[cfg_attr]) for functions unused under specific feature sets
Use concat!() to join long string literals rather than using backslash-newline escapes
Prefer single-line function bodies where appropriate (e.g., pub fn new(id: u64) -> Self { Self(id) })
Prefer semantic error enums deriving std::error::Error via thiserror for caller-inspectable conditions

Files:

  • test_support/src/lib.rs
  • tests/steps/process_steps.rs

⚙️ CodeRabbit Configuration File

**/*.rs: * Seek to keep the cyclomatic complexity of functions no more than 12.

  • Adhere to single responsibility and CQRS

  • Place function attributes after doc comments.

  • Do not use return in single-line functions.

  • Move conditionals with >2 branches into a predicate function.

  • Avoid unsafe unless absolutely necessary.

  • Every module must begin with a //! doc comment that explains the module's purpose and utility.

  • Comments and docs must follow en-GB-oxendict (-ize / -our) spelling and grammar

  • Lints must not be silenced except as a last resort.

    • #[allow] is forbidden.
    • Only narrowly scoped #[expect(lint, reason = "...")] is allowed.
    • No lint groups, no blanket or file-wide suppression.
    • Include FIXME: with link if a fix is expected.
  • Where code is only used by specific features, it must be conditionally compiled or a conditional expectation for unused_code applied.

  • Use rstest fixtures for shared setup and to avoid repetition between tests.

  • Replace duplicated tests with #[rstest(...)] parameterised cases.

  • Prefer mockall for mocks/stubs.

  • Prefer .expect() over .unwrap()

  • Ensure that any API or behavioural changes are reflected in the documentation in docs/

  • Ensure that any completed roadmap steps are recorded in the appropriate roadmap in docs/

  • Files must not exceed 400 lines in length

    • Large modules must be decomposed
    • Long match statements or dispatch tables should be decomposed by domain and collocated with targets
    • Large blocks of inline data (e.g., test fixtures, constants or templates) must be moved to external files and inlined at compile-time or loaded at run-time.

Files:

  • test_support/src/lib.rs
  • tests/steps/process_steps.rs
tests/**/*.rs

📄 CodeRabbit Inference Engine (AGENTS.md)

tests/**/*.rs: Use rstest fixtures for shared setup and replace duplicated tests with #[rstest(...)] parameterised cases
Prefer mockall for mocks/stubs
Mock non-deterministic dependencies via dependency injection (e.g., Env/Clock traits) using mockable crate; follow docs/reliable-testing-in-rust-via-dependency-injection.md

Files:

  • tests/steps/process_steps.rs
🧬 Code Graph Analysis (2)
test_support/src/lib.rs (2)
tests/steps/cli_steps.rs (1)
  • manifest_path (104-107)
test_support/src/env.rs (1)
  • write_manifest (167-179)
tests/steps/process_steps.rs (2)
test_support/src/lib.rs (1)
  • ensure_manifest_exists (118-134)
tests/steps/cli_steps.rs (1)
  • manifest_path (104-107)
🔍 Remote MCP Context7

Here are the key additional facts and relevant context for reviewing PR #132, organized by category:

  1. Helper Location and Signature
  • The new function is in test_support/src/lib.rs, making it part of a separate test-support crate.
  • Signature:
    pub fn ensure_manifest_exists(temp_dir: &Path, cli_file: &Path) -> PathBuf
  • It replaces inline logic in tests/steps/process_steps.rs and centralizes path resolution and file creation.
  1. Behavior of ensure_manifest_exists
  • Resolves cli_file to an absolute path under temp_dir if relative, or uses it directly if absolute.
  • If the resolved manifest file doesn’t exist:
    • Creates a temporary file (via tempfile::NamedTempFile) in temp_dir.
    • Writes the manifest contents using crate::env::write_manifest.
    • Persists the temp file to the resolved path.
  • Returns the final PathBuf to use for the CLI’s file argument.
  1. Impact on process_steps::run
  • Previously, run() manually replicated ~23 lines of path logic and file writing. Now it simply does:
    let cli_file = world.cli.file.clone();
    world.cli.file = ensure_manifest_exists(&dir, &cli_file);
  • This exactly matches the objective in issue #59 of extracting those lines into a helper.
  1. Tests and Verification
  • The PR runs make fmt, make lint, and make test.
  • All existing rstest, cucumber-rs, and insta snapshot tests pass, indicating the helper covers all prior scenarios.
  • No new tests were added for edge cases, but existing tests for manifest parsing and IR generation continue to pass unchanged.
  1. Linked Issue Confirmation
  • Issue #59 explicitly calls for this extraction; PR #132 closes it with exactly the requested scope.

No unknown regressions or conflicting changes were found in other modules.

🔇 Additional comments (3)
tests/steps/process_steps.rs (2)

8-10: Imports tidy-up: LGTM

Import ensure_manifest_exists and keep TempDir; remove per-call manifest scaffolding from this file. This aligns with the PR objective to centralise manifest handling.


83-86: Verify downstream steps don’t assume cli.file remains the original string

ensure_manifest_exists may convert a relative path into an absolute path under the temp dir. Ensure any steps that assert cli.file equals a literal path run before this mutation or are updated to accept the resolved path.

test_support/src/lib.rs (1)

22-24: Imports update: LGTM

Import Path/PathBuf and NamedTempFile/TempDir here. This consolidates dependencies for the new helper and existing fakes without leaking them to callers.

Comment thread test_support/src/lib.rs
Comment thread test_support/src/lib.rs
Comment thread tests/steps/process_steps.rs Outdated
codescene-delta-analysis[bot]

This comment was marked as outdated.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (3)
test_support/src/lib.rs (2)

108-116: Keep doctest non-executable to avoid FS side-effects

You correctly annotated the example with rust,no_run. This resolves the earlier feedback and keeps docs useful without mutating the filesystem during doctests.


125-134: Create parent directories and persist within destination FS

You now create the parent directory and create the temp file in the destination directory before persisting. This removes cross-filesystem rename pitfalls and fixes missing-parent failures.

tests/steps/process_steps.rs (1)

83-86: Avoid double-borrowing world.cli

Borrow world.cli mutably once and update in place. This applies the earlier feedback and improves clarity.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

💡 Knowledge Base configuration:

  • Jira integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 94ad1f5 and 0813598.

📒 Files selected for processing (2)
  • test_support/src/lib.rs (2 hunks)
  • tests/steps/process_steps.rs (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.rs

📄 CodeRabbit Inference Engine (AGENTS.md)

**/*.rs: Comment why, not what; document assumptions, edge cases, trade-offs, and complexity without restating obvious code
Extract reusable logic into functions; prefer composition and declarative constructs when readable
Keep functions small, single-responsibility, and observe command/query separation
Use precise, descriptive names; boolean names should start with is/has/should
Use en-GB-oxendict spelling/grammar in comments (except external API references)
Function docs must include clear usage examples; avoid redundant examples in test docs
No Rust source file may exceed 400 lines; split long switches/tables; move large test data to external files
Fix test warnings in code; do not silence them
Extract helpers when functions are too long; group many parameters into well-named structs
Consider using Arc when returning large errors to reduce data movement
Document public APIs using Rustdoc (///) so cargo doc can generate documentation
Prefer immutable data; avoid unnecessary mut bindings
Prefer Result-based error handling over panicking where feasible
Avoid unsafe code unless absolutely necessary and document any usage clearly
Place function attributes after doc comments
Do not use return in single-line functions
Use predicate helper functions when conditionals have more than two branches
Do not silence lints except as a last resort; suppressions must be tightly scoped and include a clear reason
Prefer #[expect(...)] over #[allow(...)] for lint management
Prefer .expect() over .unwrap()
Use conditional compilation (#[cfg]/#[cfg_attr]) for functions unused under specific feature sets
Use concat!() to join long string literals rather than using backslash-newline escapes
Prefer single-line function bodies where appropriate (e.g., pub fn new(id: u64) -> Self { Self(id) })
Prefer semantic error enums deriving std::error::Error via thiserror for caller-inspectable conditions

Files:

  • test_support/src/lib.rs
  • tests/steps/process_steps.rs

⚙️ CodeRabbit Configuration File

**/*.rs: * Seek to keep the cyclomatic complexity of functions no more than 12.

  • Adhere to single responsibility and CQRS

  • Place function attributes after doc comments.

  • Do not use return in single-line functions.

  • Move conditionals with >2 branches into a predicate function.

  • Avoid unsafe unless absolutely necessary.

  • Every module must begin with a //! doc comment that explains the module's purpose and utility.

  • Comments and docs must follow en-GB-oxendict (-ize / -our) spelling and grammar

  • Lints must not be silenced except as a last resort.

    • #[allow] is forbidden.
    • Only narrowly scoped #[expect(lint, reason = "...")] is allowed.
    • No lint groups, no blanket or file-wide suppression.
    • Include FIXME: with link if a fix is expected.
  • Where code is only used by specific features, it must be conditionally compiled or a conditional expectation for unused_code applied.

  • Use rstest fixtures for shared setup and to avoid repetition between tests.

  • Replace duplicated tests with #[rstest(...)] parameterised cases.

  • Prefer mockall for mocks/stubs.

  • Prefer .expect() over .unwrap()

  • Ensure that any API or behavioural changes are reflected in the documentation in docs/

  • Ensure that any completed roadmap steps are recorded in the appropriate roadmap in docs/

  • Files must not exceed 400 lines in length

    • Large modules must be decomposed
    • Long match statements or dispatch tables should be decomposed by domain and collocated with targets
    • Large blocks of inline data (e.g., test fixtures, constants or templates) must be moved to external files and inlined at compile-time or loaded at run-time.

Files:

  • test_support/src/lib.rs
  • tests/steps/process_steps.rs
tests/**/*.rs

📄 CodeRabbit Inference Engine (AGENTS.md)

tests/**/*.rs: Use rstest fixtures for shared setup and replace duplicated tests with #[rstest(...)] parameterised cases
Prefer mockall for mocks/stubs
Mock non-deterministic dependencies via dependency injection (e.g., Env/Clock traits) using mockable crate; follow docs/reliable-testing-in-rust-via-dependency-injection.md

Files:

  • tests/steps/process_steps.rs
🧬 Code Graph Analysis (2)
test_support/src/lib.rs (2)
tests/steps/cli_steps.rs (1)
  • manifest_path (104-107)
test_support/src/env.rs (1)
  • write_manifest (167-179)
tests/steps/process_steps.rs (2)
test_support/src/lib.rs (1)
  • ensure_manifest_exists (118-138)
tests/steps/cli_steps.rs (1)
  • manifest_path (104-107)
🔍 Remote MCP Deepwiki

Summary of additional relevant facts for reviewing PR #132:

  • Helper placement & signature: new helper added to test_support crate at test_support/src/lib.rs as pub fn ensure_manifest_exists(temp_dir: &Path, cli_file: &Path) -> PathBuf.
  • Behavior: resolves relative cli_file under temp_dir or uses absolute path; if missing, creates a NamedTempFile in temp_dir, writes a minimal manifest (via crate env/write_manifest), persists it to the resolved path, and returns the resolved PathBuf. Replaces ~23 lines of inline manifest-creation logic previously in tests/steps/process_steps.rs.
  • Call sites: tests/steps/process_steps.rs now calls the helper and assigns its return to world.cli.file before invoking run_ninja; NamedTempFile usage removed from that test.
  • Tests & CI: PR runs make fmt, make lint, make test; existing rstest, cucumber-rs, and insta snapshot tests remain green per PR notes — no new tests added targeting edge cases (e.g., permission errors, conflicting paths).
  • Linked issue: PR closes issue #59 ("Extract manifest path resolution logic into helper function") and matches the requested scope (parameterization by temp_dir and cli_file, resolving absolute vs relative, creating/persisting temp manifests, returning resolved path).
  • Potential review notes: behavior relies on test_support::env::write_manifest and NamedTempFile persisting to the resolved path — verify atomicity/permissions in cross-platform CI and consider adding explicit tests for absolute-path input, existing-file (no-op), and error propagation on write failures.
🔇 Additional comments (2)
tests/steps/process_steps.rs (2)

9-13: Import the manifest helper to centralise setup

Import ensure_manifest_exists from test_support to reuse the shared manifest resolution/creation logic. This removes duplication from step code and aligns with the refactor’s objective.


83-86: Verify step assertions that depend on the raw CLI path

Overwriting cli.file with the resolved (often absolute) path can affect steps that assert equality against the originally provided string (see tests/steps/cli_steps.rs Line 103). Verify no scenarios assert the manifest path after the run step using the un-resolved form.

If any such assertions exist, update those steps to compare against the resolved path or to normalise the expected value the same way ensure_manifest_exists does (resolve relative input against the temp dir before asserting).

Comment thread test_support/src/lib.rs
@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Aug 20, 2025

@coderabbitai Have the following now been resolved?

  • ensure_manifest_exists should create any missing parent directories for the target path before persisting the file so nested cli_file paths don’t break.
  • Consider including the manifest_path in your expect() messages in ensure_manifest_exists to make failures easier to diagnose.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 20, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@leynos: No, neither of these issues have been resolved in the current implementation. Looking at the ensure_manifest_exists function:

Issue 1 - Missing parent directory creation:
The current code does not create parent directories before persisting:

temp_file.persist(&manifest_path).expect("Failed to persist manifest");

This will fail if cli_file contains nested paths like nested/dir/manifest.toml and the parent directories don't exist.

Issue 2 - Generic error messages:
The expect() messages are still generic and don't include the path:

env::write_manifest(&mut temp_file, &config).expect("Failed to write manifest");
temp_file.persist(&manifest_path).expect("Failed to persist manifest");

Recommended fixes:

  1. Add parent directory creation:
if let Some(parent) = manifest_path.parent() {
    std::fs::create_dir_all(parent)
        .expect(&format!("Failed to create parent directories for {}", manifest_path.display()));
}
  1. Improve error messages:
env::write_manifest(&mut temp_file, &config)
    .expect(&format!("Failed to write manifest to {}", manifest_path.display()));
temp_file.persist(&manifest_path)
    .expect(&format!("Failed to persist manifest to {}", manifest_path.display()));

Both improvements are needed to make the function more robust and debuggable.


🏁 Script executed:

#!/bin/bash
# Let's examine the ensure_manifest_exists function implementation
cat test_support/src/lib.rs

Length of output: 4572


@leynos: I need to correct my previous assessment after examining the actual code:

Issue 1 - Missing parent directory creation:RESOLVED
The current implementation does create parent directories:

let dest_dir = manifest_path.parent().unwrap_or(temp_dir);
if !dest_dir.exists() {
    fs::create_dir_all(dest_dir).expect("Failed to create manifest parent directory");
}

Issue 2 - Generic error messages: ⚠️ PARTIALLY RESOLVED
The error messages have been made more specific with different messages for each operation:

  • "Failed to create manifest parent directory"
  • "Failed to create temporary manifest file"
  • "Failed to write manifest content"
  • "Failed to persist manifest file"

However, they still don't include the manifest_path for easier debugging. To fully resolve this, the messages should include the path:

fs::create_dir_all(dest_dir).expect(&format!("Failed to create manifest parent directory for {}", manifest_path.display()));
// ... and similar for the other expect() calls

Summary:

  • ✅ Parent directory creation is fully resolved
  • ⚠️ Error message improvement is partially resolved (more specific but missing path info)

codescene-delta-analysis[bot]

This comment was marked as outdated.

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Aug 20, 2025

@coderabbitai Please suggest a fix for this issue and supply a prompt for an AI coding agent to enable it to apply the fix:

Issue 2 - Generic error messages: ⚠️ PARTIALLY RESOLVED
The error messages have been made more specific with different messages for each operation:

"Failed to create manifest parent directory"
"Failed to create temporary manifest file"
"Failed to write manifest content"
"Failed to persist manifest file"

However, they still don't include the manifest_path for easier debugging. To fully resolve this, the messages should include the path:

fs::create_dir_all(dest_dir).expect(&format!("Failed to create manifest parent directory for {}", manifest_path.display()));
// ... and similar for the other expect() calls

Summary:

✅ Parent directory creation is fully resolved
⚠️ Error message improvement is partially resolved (more specific but missing path info)

@coderabbitai

This comment was marked as resolved.

codescene-delta-analysis[bot]

This comment was marked as outdated.

@leynos leynos merged commit fb4598f into main Aug 21, 2025
4 checks passed
@leynos leynos deleted the codex/refactor-run-to-extract-manifest-logic branch August 21, 2025 12:22
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.

Extract manifest path resolution logic into helper function

1 participant