Skip to content

feat: add rust toy app for e2e tests#69

Open
leynos wants to merge 3 commits intomainfrom
codex/create-rust-toy-app-with-tests-lfjcvf
Open

feat: add rust toy app for e2e tests#69
leynos wants to merge 3 commits intomainfrom
codex/create-rust-toy-app-with-tests-lfjcvf

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Sep 6, 2025

Summary

  • scaffold rust-toy-app with clap-based CLI and build.rs generating man page
  • add unit and assert_cmd integration tests for toy app
  • document design decisions and mark scaffolding task complete
  • target Rust 2024 edition and set MSRV to 1.89

Testing

  • cargo test --manifest-path rust-toy-app/Cargo.toml
  • make lint
  • make markdownlint
  • make test

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

Summary by Sourcery

Introduce a minimal Rust toy application for end-to-end tests with CLI, man page generation, and accompanying tests

New Features:

  • Scaffold a rust-toy-app crate with a clap-based CLI and build.rs for man page generation

Enhancements:

  • Target the crate at Rust 2024 edition and set the MSRV to 1.89

Documentation:

  • Update the Rust build and release pipeline docs to mark the toy app scaffold complete and add design decisions

Tests:

  • Add unit tests for the greeting logic and integration tests using assert_cmd

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Sep 6, 2025

Reviewer's Guide

This PR scaffolds a new Rust toy application for E2E tests, including a clap-based CLI, build.rs-driven man page generation, project configuration for Rust 2024 with an MSRV of 1.89, accompanying unit and integration tests, and updates to pipeline documentation.

Sequence diagram for rust-toy-app CLI execution flow

sequenceDiagram
    participant User as actor User
    participant Main as main()
    participant Cli as Cli
    User->>Main: Run rust-toy-app binary
    Main->>Cli: Cli::parse()
    Main->>Cli: cli.run()
    Cli-->>Main: "Hello, {name}!"
    Main->>User: Print greeting
Loading

Sequence diagram for build.rs man page generation

sequenceDiagram
    participant BuildScript as build.rs
    participant Cli as cli::command()
    participant ClapMangen as clap_mangen::Man
    participant File as File
    BuildScript->>Cli: command()
    BuildScript->>ClapMangen: Man::new(cmd)
    BuildScript->>ClapMangen: render()
    ClapMangen-->>BuildScript: man page buffer
    BuildScript->>File: create(rust-toy-app.1)
    BuildScript->>File: write_all(buffer)
    File-->>BuildScript: success
Loading

File-Level Changes

Change Details Files
Scaffold a Clap-based Rust toy application with man page support
  • Define Cli struct with name option and run() method
  • Provide command() helper for clap CommandFactory
  • Implement build.rs to render man page via clap_mangen into OUT_DIR
  • Add main.rs to parse CLI and print greeting
rust-toy-app/src/cli.rs
rust-toy-app/build.rs
rust-toy-app/src/main.rs
Configure Cargo project targeting Rust 2024 and MSRV 1.89 with required dependencies
  • Set edition = "2024" and rust-version = "1.89"
  • Add clap and clap_mangen as dependencies and assert_cmd, predicates, rstest as dev-dependencies
  • Include generated Cargo.lock from initial build
rust-toy-app/Cargo.toml
rust-toy-app/Cargo.lock
Implement testing suite for the toy app
  • Add unit test in src/lib.rs verifying greeting logic
  • Add integration tests in tests/cli.rs using assert_cmd for named and default cases
rust-toy-app/src/lib.rs
rust-toy-app/tests/cli.rs
Update E2E test pipeline documentation
  • Adjust markdownlint rules and mark toy app scaffolding step complete
  • Refine Python test checklist to verify man page generation path
  • Append design decisions section covering CLI design, build script, testing, edition, and MSRV
docs/rust-build-release-pipeline.md

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 Sep 6, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Warning

Rate limit exceeded

@leynos has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 5 minutes and 27 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 642bc62 and 06418d5.

📒 Files selected for processing (7)
  • docs/rust-build-release-pipeline.md (2 hunks)
  • rust-toy-app/Cargo.toml (1 hunks)
  • rust-toy-app/build.rs (1 hunks)
  • rust-toy-app/src/cli.rs (1 hunks)
  • rust-toy-app/src/lib.rs (1 hunks)
  • rust-toy-app/src/main.rs (1 hunks)
  • rust-toy-app/tests/cli.rs (1 hunks)

Summary by CodeRabbit

  • New Features

    • Introduced a minimal Rust CLI utility that greets a provided name or defaults to “world”.
    • Automatic manual page generation during build.
  • Documentation

    • Updated the Rust build and release pipeline guide: Phase 1 marked complete, clarified test validation to check generated man page output, and added design decisions for the toy app. Expanded markdownlint exceptions.
  • Tests

    • Added integration tests to verify CLI greeting behaviour for named and default cases.

Walkthrough

Add a new Rust toy CLI crate with Clap-based parsing, a build script that generates a man page via clap_mangen, unit and integration tests, and documentation updates reflecting Phase 1 status and design decisions. No changes to Phase 2 or packaging.

Changes

Cohort / File(s) Summary of changes
Documentation updates
docs/rust-build-release-pipeline.md
Update Phase 1 status, test validation steps, and add “Design Decisions”. Extend markdownlint disables (MD007, MD013, MD026).
New crate manifest
rust-toy-app/Cargo.toml
Define package metadata (edition 2024, rust-version 1.89). Add dependencies: clap (derive), build-deps: clap, clap_mangen; dev-deps: assert_cmd, predicates, rstest.
Build-time man-page generation
rust-toy-app/build.rs
Generate man page from Clap command via clap_mangen; write rust-toy-app.1 to $OUT_DIR.
CLI implementation and library
rust-toy-app/src/cli.rs, rust-toy-app/src/lib.rs, rust-toy-app/src/main.rs
Add Cli with optional --name flag, run() returning greeting, command() helper. Expose pub mod cli. Wire binary to parse args and print greeting. Add a unit test in lib.
Integration tests
rust-toy-app/tests/cli.rs
Add parameterised tests using assert_cmd/rstest verifying greeting with and without --name.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Dev as Developer
  participant Cargo as Cargo Build
  participant BuildRS as build.rs
  participant CliMod as cli::command()
  participant Mangen as clap_mangen
  participant FS as File System (OUT_DIR)

  Dev->>Cargo: cargo build
  rect rgba(200,230,255,0.25)
    note right of Cargo: Build script phase
    Cargo->>BuildRS: Execute build.rs
    BuildRS->>CliMod: Load command definition
    BuildRS->>Mangen: Generate man from Command
    Mangen-->>BuildRS: Man page bytes
    BuildRS->>FS: Write rust-toy-app.1
  end
  Cargo-->>Dev: Build artefacts incl. man page
Loading
sequenceDiagram
  autonumber
  actor User
  participant Bin as rust-toy-app (binary)
  participant Clap as Clap Parser
  participant Cli as Cli::run()
  participant Out as stdout

  User->>Bin: Invoke [--name NAME]
  Bin->>Clap: Parse args
  Clap-->>Bin: Cli instance
  Bin->>Cli: run()
  Cli-->>Bin: "Hello, {name}!"
  Bin->>Out: Print greeting
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

A tiny clap, a greeting bright,
The build script forges man-page light.
Hello to Bob, and world by default,
Tests march in lockstep, no revolt.
Cargo hums, the pipeline sings—
A toy today, with neatly tied strings.

✨ 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/create-rust-toy-app-with-tests-lfjcvf

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

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `rust-toy-app/build.rs:9` </location>
<code_context>
+#[path = "src/cli.rs"]
+mod cli;
+
+fn main() -> Result<(), Box<dyn std::error::Error>> {
+    let out_dir = PathBuf::from(env::var("OUT_DIR")?);
+    let cmd = cli::command();
+    let man = clap_mangen::Man::new(cmd);
+    let mut buffer = Vec::new();
+    man.render(&mut buffer)?;
+    let mut out = File::create(out_dir.join("rust-toy-app.1"))?;
+    out.write_all(&buffer)?;
+    Ok(())
+}
</code_context>

<issue_to_address>
The build script writes the man page to OUT_DIR, but does not print rerun-if-changed directives.

Add println!("cargo:rerun-if-changed=src/cli.rs"); and println!("cargo:rerun-if-changed=build.rs"); to ensure the build script reruns when these files change, preventing stale man pages.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread rust-toy-app/build.rs
Comment on lines +9 to +17
fn main() -> Result<(), Box<dyn std::error::Error>> {
let out_dir = PathBuf::from(env::var("OUT_DIR")?);
let cmd = cli::command();
let man = clap_mangen::Man::new(cmd);
let mut buffer = Vec::new();
man.render(&mut buffer)?;
let mut out = File::create(out_dir.join("rust-toy-app.1"))?;
out.write_all(&buffer)?;
Ok(())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion (bug_risk): The build script writes the man page to OUT_DIR, but does not print rerun-if-changed directives.

Add println!("cargo:rerun-if-changed=src/cli.rs"); and println!("cargo:rerun-if-changed=build.rs"); to ensure the build script reruns when these files change, preventing stale man pages.

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: 15

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
docs/rust-build-release-pipeline.md (2)

346-347: Fix backtick in inline code.

Close the backtick around cargo_mangen.

-   - [ ] Add `cargo_mangen step and validate that a manpage is correctly produced by
+   - [ ] Add `cargo_mangen` step and validate that a manpage is correctly produced by

126-129: Document lower-overhead alternative to build.rs for man pages.

Note the xtask approach as an alternative to reduce build-time cost.

Add after the paragraph:

Tip: Generate man pages via a dedicated cargo “xtask” rather than build.rs to avoid recompiling the CLI inside the build script and to keep normal builds lean.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f4472fd and 642bc62.

⛔ Files ignored due to path filters (1)
  • rust-toy-app/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (7)
  • docs/rust-build-release-pipeline.md (2 hunks)
  • rust-toy-app/Cargo.toml (1 hunks)
  • rust-toy-app/build.rs (1 hunks)
  • rust-toy-app/src/cli.rs (1 hunks)
  • rust-toy-app/src/lib.rs (1 hunks)
  • rust-toy-app/src/main.rs (1 hunks)
  • rust-toy-app/tests/cli.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.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.
  • Environment access (env::set_var and env::remove_var) are always unsafe in Rust 2024 and MUST be marked as such

    • For testing of functionality depending upon environment variables, dependency injection and the mockable crate are the preferred option.
    • If mockable cannot be used, env mutations in tests ...

Files:

  • rust-toy-app/src/main.rs
  • rust-toy-app/tests/cli.rs
  • rust-toy-app/build.rs
  • rust-toy-app/src/cli.rs
  • rust-toy-app/src/lib.rs
{README.md,docs/**}

📄 CodeRabbit inference engine (.rules/python-00.md)

Colocate documentation near reusable packages: keep README.md or docs/ and include usage examples

Files:

  • docs/rust-build-release-pipeline.md
**/*.md

⚙️ CodeRabbit configuration file

**/*.md: * Avoid 2nd person or 1st person pronouns ("I", "you", "we")

  • Use en-GB-oxendict (-ize / -our) spelling and grammar
  • Headings must not be wrapped.
  • Documents must start with a level 1 heading
  • Headings must correctly increase or decrease by no more than one level at a time
  • Use GitHub-flavoured Markdown style for footnotes and endnotes.
  • Numbered footnotes must be numbered by order of appearance in the document.

Files:

  • docs/rust-build-release-pipeline.md
🧬 Code graph analysis (3)
rust-toy-app/src/main.rs (1)
rust-toy-app/src/cli.rs (1)
  • run (12-15)
rust-toy-app/build.rs (2)
rust-toy-app/src/main.rs (1)
  • main (4-7)
rust-toy-app/src/cli.rs (1)
  • command (18-20)
rust-toy-app/src/lib.rs (1)
rust-toy-app/src/cli.rs (1)
  • run (12-15)
🔍 Remote MCP

Additional Context for PR Review

  1. Rust Minimum Supported Version (MSRV) and Edition

    • The PR sets rust-version = "1.89" and edition = "2024" in the new rust-toy-app/Cargo.toml. Rust 1.89.0 was released on August 7, 2025, making this exactly the current stable version at the time of this PR (blog.rust-lang.org).
  2. Clap and Man-Page Generation

    • The PR uses clap = { version = "4", features = ["derive"] } alongside clap_mangen = "0.2" in build-dependencies. The clap_mangen crate (0.2.x series) is actively maintained, with 37 patch releases up to v0.2.23 as of July 25, 2024 (lib.rs).
    • Note: clap_mangen’s own documentation recommends using a dedicated cargo “xtask” instead of a build.rs to avoid build-time overhead:

      Tip: Consider a cargo xtask instead of a build.rs to reduce build costs. (lib.rs)

  3. Testing Libraries Versions

    • assert_cmd = "2" is at v2.0.17 (released April 16, 2025), which adds a cargo_bin! macro for custom build directories (docs.rs).
    • predicates = "3" is at v3.1.3 (released December 19, 2024), providing default features for matching CLI output in tests (lib.rs).
    • rstest = "0.21" was released June 1, 2024, offering procedural-macro-driven fixtures and parameterized tests (docs.rs).
  4. Packaging Considerations

    • The PR updates Phase 1 of the release pipeline docs to mark the toy-app task complete and adds man-page generation logic, but leaves Phase 2 (packaging) unchanged. Reviewers might verify that the pipeline’s packaging step includes the generated rust-toy-app.1 man page (e.g., via EXTRA_FILES or similar artifact inputs) to ensure it’s published alongside binaries.

These points should help confirm that the chosen crate versions align with current stable releases, acknowledge a potential build-time trade-off in using build.rs, and highlight a packaging consideration for the generated man page.

🔇 Additional comments (2)
rust-toy-app/tests/cli.rs (1)

10-10: Approve binary name test
package.name matches “rust-toy-app”.

rust-toy-app/src/cli.rs (1)

18-20: Drop build-dependencies verification
clap with the derive feature is already listed under [build-dependencies].

Comment thread rust-toy-app/build.rs
Comment on lines +1 to +5
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Import time for reproducible dates.

Prepare for SOURCE_DATE_EPOCH handling.

 use std::env;
 use std::fs::File;
 use std::io::Write;
 use std::path::PathBuf;
+use time::{format_description::well_known::Iso8601, OffsetDateTime};
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
use time::{format_description::well_known::Iso8601, OffsetDateTime};
🤖 Prompt for AI Agents
In rust-toy-app/build.rs around lines 1 to 5, add imports and logic to support
reproducible builds via SOURCE_DATE_EPOCH: import std::time::{SystemTime,
UNIX_EPOCH} (in addition to existing std::env, std::fs::File, std::io::Write,
std::path::PathBuf), then when producing any build-time timestamp read
SOURCE_DATE_EPOCH from the environment and parse it as u64 if present, otherwise
compute the current UNIX timestamp from
SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs(); use that
resulting seconds value for any generated timestamps so builds respect
SOURCE_DATE_EPOCH.

Comment thread rust-toy-app/build.rs
Comment on lines +6 to +7
#[path = "src/cli.rs"]
mod cli;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Avoid duplicating CLI in the build script long-term.

Move man-page generation to an xtask to reduce compile-time and dependency load in build.rs.

🤖 Prompt for AI Agents
In rust-toy-app/build.rs around lines 6-7, the build script pulls in the CLI via
#[path = "src/cli.rs"] mod cli; and duplicates CLI logic for man-page
generation; move man-page generation out of build.rs into an xtask to avoid
increasing compile-time and dependency load. Create an xtask binary crate (e.g.
workspace member xtask) that depends on the real crate or reads its CLI
definition to generate man pages, implement the existing man-generation logic
there, update CI/build documentation to run cargo run -p xtask -- man (or
similar) as part of release/docs, and remove the #[path = "src/cli.rs"] mod cli;
and any man-generation invocation from build.rs so build.rs contains only
minimal build-time tasks.

Comment thread rust-toy-app/build.rs
Comment on lines +9 to +18
fn main() -> Result<(), Box<dyn std::error::Error>> {
let out_dir = PathBuf::from(env::var("OUT_DIR")?);
let cmd = cli::command();
let man = clap_mangen::Man::new(cmd);
let mut buffer = Vec::new();
man.render(&mut buffer)?;
let mut out = File::create(out_dir.join("rust-toy-app.1"))?;
out.write_all(&buffer)?;
Ok(())
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Make man-page generation reproducible and incremental.

Emit rerun-if-changed and honour SOURCE_DATE_EPOCH.

 fn main() -> Result<(), Box<dyn std::error::Error>> {
+    // Re-run when CLI definition changes.
+    println!("cargo:rerun-if-changed=src/cli.rs");
     let out_dir = PathBuf::from(env::var("OUT_DIR")?);
     let cmd = cli::command();
-    let man = clap_mangen::Man::new(cmd);
+    let date = env::var("SOURCE_DATE_EPOCH")
+        .ok()
+        .and_then(|s| s.parse::<i64>().ok())
+        .and_then(|ts| OffsetDateTime::from_unix_timestamp(ts).ok())
+        .and_then(|dt| dt.format(&Iso8601::DATE).ok())
+        .unwrap_or_else(|| "1970-01-01".to_string());
+    let man = clap_mangen::Man::new(cmd).date(date);
     let mut buffer = Vec::new();
     man.render(&mut buffer)?;
     let mut out = File::create(out_dir.join("rust-toy-app.1"))?;
     out.write_all(&buffer)?;
     Ok(())
 }

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In rust-toy-app/build.rs around lines 9 to 18, the build script currently
renders the man page unconditionally and non-deterministically; update it to
emit cargo rerun hints and honor SOURCE_DATE_EPOCH: add
println!("cargo:rerun-if-changed=<path>") entries for the build script and any
source files that influence cli::command (e.g., src/cli.rs or src/main.rs) so
Cargo only rebuilds the man page when those inputs change, and read the
SOURCE_DATE_EPOCH env var (if present) to set a fixed/ reproducible date on the
clap_mangen::Man instance (or clear the date) before rendering so the output is
deterministic across builds.

Comment thread rust-toy-app/Cargo.toml
Comment on lines +1 to +6
[package]
name = "rust-toy-app"
version = "0.1.0"
edition = "2024"
rust-version = "1.89"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add minimal package metadata and mark as non-publishable.

Avoid crates.io warnings and accidental publishes for a toy crate.

Apply:

 [package]
 name = "rust-toy-app"
 version = "0.1.0"
 edition = "2024"
 rust-version = "1.89"
+description = "Toy CLI used for E2E tests in shared-actions"
+license = "MIT OR Apache-2.0"
+repository = "https://github.com/leynos/shared-actions"
+publish = false
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
[package]
name = "rust-toy-app"
version = "0.1.0"
edition = "2024"
rust-version = "1.89"
[package]
name = "rust-toy-app"
version = "0.1.0"
edition = "2024"
rust-version = "1.89"
description = "Toy CLI used for E2E tests in shared-actions"
license = "MIT OR Apache-2.0"
repository = "https://github.com/leynos/shared-actions"
publish = false
🤖 Prompt for AI Agents
In rust-toy-app/Cargo.toml around lines 1 to 6, the package lacks minimal
metadata and isn't marked non-publishable; add basic fields (description,
authors or maintainers, license or license-file, repository if available) and
set publish = false under the [package] section to avoid crates.io warnings and
prevent accidental publishing.

Comment thread rust-toy-app/Cargo.toml
name = "rust-toy-app"
version = "0.1.0"
edition = "2024"
rust-version = "1.89"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Enforce MSRV in tooling.

Pin the toolchain so CI and local devs build with Rust 1.89.

Add a file at rust-toy-app/rust-toolchain.toml:

[toolchain]
channel = "1.89.0"
components = ["clippy", "rustfmt"]
profile = "minimal"
🤖 Prompt for AI Agents
In rust-toy-app/Cargo.toml around line 5 the MSRV is declared but tooling is not
pinned; create a new file rust-toy-app/rust-toolchain.toml at the repo with the
toolchain locked to 1.89.0 and include clippy and rustfmt components and a
minimal profile so CI and local devs use the same Rust toolchain (channel =
"1.89.0", components = ["clippy", "rustfmt"], profile = "minimal").

Comment thread rust-toy-app/src/lib.rs
Comment thread rust-toy-app/src/lib.rs Outdated
Comment on lines +7 to +11
#[test]
fn run_returns_greeting() {
let cli = Cli { name: Some("Alice".into()) };
assert_eq!(cli.run(), "Hello, Alice!");
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Parametrise with rstest.

Replace duplicated cases with parameterised tests per guidelines.

Example:

use rstest::rstest;

#[rstest]
#[case(&["rust-toy-app"], "Hello, world!")]
#[case(&["rust-toy-app", "--name", "Alice"], "Hello, Alice!")]
fn run_returns_greeting(#[case] args: &[&str], #[case] expected: &str) {
    let cli = Cli::parse_from(args);
    assert_eq!(cli.run(), expected);
}
🤖 Prompt for AI Agents
In rust-toy-app/src/lib.rs around lines 7 to 11, the current test duplicates
cases and should be converted to a parameterised rstest: add use rstest::rstest
at the top, replace the single test with a #[rstest] function that accepts two
cases (one for default invocation and one for --name "Alice"), change the test
to build the CLI via Cli::parse_from(args) and compare cli.run() to the expected
value, and add #[case] annotations for each args/expected pair to drive the
parameterised assertions.

🧹 Nitpick (assertive)

Avoid struct-literal construction across modules; parse args instead.

Do not rely on field visibility for tests; use Cli::parse_from for stability.

 #[test]
 fn run_returns_greeting() {
-    let cli = Cli { name: Some("Alice".into()) };
+    let cli = Cli::parse_from(["rust-toy-app", "--name", "Alice"]);
     assert_eq!(cli.run(), "Hello, Alice!");
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#[test]
fn run_returns_greeting() {
let cli = Cli { name: Some("Alice".into()) };
assert_eq!(cli.run(), "Hello, Alice!");
}
#[test]
fn run_returns_greeting() {
let cli = Cli::parse_from(["rust-toy-app", "--name", "Alice"]);
assert_eq!(cli.run(), "Hello, Alice!");
}
🤖 Prompt for AI Agents
In rust-toy-app/src/lib.rs around lines 7 to 11, the test constructs Cli via a
struct literal which relies on field visibility; replace that with constructing
the CLI via Cli::parse_from (e.g. passing program name and the name argument) so
the test exercises argument parsing instead of internal fields, then call run()
and assert the returned greeting is "Hello, Alice!" to keep the test stable
across module boundary changes.

Comment thread rust-toy-app/src/main.rs
Comment thread rust-toy-app/tests/cli.rs
Comment on lines +6 to +8
#[rstest]
#[case::named(&["--name", "Bob"][..], "Hello, Bob!\n")]
#[case::default(&[][..], "Hello, world!\n")]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Add a short-flag case and basic help/version smoke tests

Exercise -n alongside --name, and assert help/version to lock the public CLI surface.

Extend the parameterised cases:

 #[rstest]
 #[case::named(&["--name", "Bob"][..], "Hello, Bob!\n")]
+#[case::short(&["-n", "Bob"][..], "Hello, Bob!\n")]
 #[case::default(&[][..], "Hello, world!\n")]

Add a new test:

use predicates::str::{contains, starts_with};

#[test]
fn prints_help_and_version() {
    // help
    Command::cargo_bin("rust-toy-app")
        .expect("binary should build")
        .arg("--help")
        .assert()
        .success()
        .stdout(contains("A toy app for E2E tests"));

    // version
    Command::cargo_bin("rust-toy-app")
        .expect("binary should build")
        .arg("--version")
        .assert()
        .success()
        .stdout(starts_with(env!("CARGO_PKG_VERSION")));
}
🤖 Prompt for AI Agents
In rust-toy-app/tests/cli.rs around lines 6 to 8, the parameterised test cases
only exercise the long `--name` flag and default, and there are no smoke tests
for help/version; add a third case that passes the short `-n` flag (e.g.,
&["-n", "Bob"][..], "Hello, Bob!\n") to mirror the existing `--name` case, and
add a new test function `prints_help_and_version` that runs the built binary
with `--help` and asserts stdout contains the crate description (e.g., "A toy
app for E2E tests") and runs it with `--version` and asserts stdout starts with
env!("CARGO_PKG_VERSION") using `predicates::str::{contains, starts_with}` to
lock the public CLI surface.

Comment thread rust-toy-app/tests/cli.rs
Comment on lines +11 to +13
for a in args {
cmd.arg(a);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Collapse the arg loop into .args(args)

Reduce noise and keep intent clear.

Apply:

-    for a in args {
-        cmd.arg(a);
-    }
+    cmd.args(args);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for a in args {
cmd.arg(a);
}
cmd.args(args);
🤖 Prompt for AI Agents
In rust-toy-app/tests/cli.rs around lines 11 to 13, the loop that calls
cmd.arg(a) for each element should be collapsed into a single call to
cmd.args(args) to reduce noise; replace the for-loop with cmd.args(args),
ensuring the variable passed is an iterator or slice of &str (or convert with
args.iter().map(|s| s.as_str()) as needed) so types and ownership remain
correct.

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.

1 participant