From 1e2bc6d7f08f68a15a1aa43f5f5d120981ba20ee Mon Sep 17 00:00:00 2001 From: intentos-dev Date: Sun, 21 Jun 2026 17:00:39 +0200 Subject: [PATCH] feat(init): scaffold a starter bench.toml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `cu-profiler init` now writes a commented `bench.toml` template for the turnkey real-CU path, so `cu-profiler bench` is discoverable and validates out of the box. Added to .gitignore's self-init list and documented in reference §15. Integration test asserts the scaffolded plan passes `bench` validation. Gate: grade A. Co-Authored-By: Claude Opus 4.8 (1M context) --- .gitignore | 1 + CHANGELOG.md | 4 ++++ crates/cu-profiler-cli/src/commands/init.rs | 21 +++++++++++++++++++ crates/cu-profiler-cli/tests/cli.rs | 23 +++++++++++++++++++++ docs/reference.md | 1 + 5 files changed, 50 insertions(+) diff --git a/.gitignore b/.gitignore index 8edaa86..a804ce4 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ # Scaffolding from running `init` in the repo root (the tool profiling itself) /cu-profiler.toml /examples/ +/bench.toml # Local-only tooling and agent config — intentionally not shared .gate/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 39408bb..32e367d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- `cu-profiler init` now scaffolds a starter `bench.toml` for the turnkey real-CU + path, so `cu-profiler bench` is discoverable and validates out of the box. + ## [0.2.0] - 2026-06-21 ### Added diff --git a/crates/cu-profiler-cli/src/commands/init.rs b/crates/cu-profiler-cli/src/commands/init.rs index 57b414d..d753ad0 100644 --- a/crates/cu-profiler-cli/src/commands/init.rs +++ b/crates/cu-profiler-cli/src/commands/init.rs @@ -86,6 +86,26 @@ pub fn swap_exact_in() -> Scenario { } "#; +const BENCH_TOML: &str = r#"# bench.toml — the turnkey real-CU path (`cu-profiler bench`). +# +# Declare the instruction(s) to run against your compiled SBF program so that +# cu-profiler bench --program-name +# meters their REAL compute units (via the Linux `cu-profiler-bench` executor). +# Replace the placeholder program_id with your program's address, and add the +# accounts and instruction data your program needs. + +[[instruction]] +scenario = "swap_exact_in" +program_id = "11111111111111111111111111111111" # <-- replace with your program id +data = "" # hex instruction data ("" = no args) + +# [[instruction.account]] +# pubkey = "11111111111111111111111111111111" +# signer = true +# writable = true +# lamports = 1000000 +"#; + const WORKFLOW: &str = r#"name: CU Profiler on: @@ -148,6 +168,7 @@ pub fn run(args: &InitArgs, quiet: bool) -> Result { args.force, quiet, )?; + write_file(&dir.join("bench.toml"), BENCH_TOML, args.force, quiet)?; if args.workflow { write_file( &dir.join(".github/workflows/cu-profiler.yml"), diff --git a/crates/cu-profiler-cli/tests/cli.rs b/crates/cu-profiler-cli/tests/cli.rs index 5d65463..4ec87b7 100644 --- a/crates/cu-profiler-cli/tests/cli.rs +++ b/crates/cu-profiler-cli/tests/cli.rs @@ -260,6 +260,29 @@ fn import_file_without_logs_reports_error() { assert!(!dir.join(".cu/logs/empty.log").exists()); } +#[test] +fn init_scaffolds_a_valid_bench_toml() { + let dir = scratch_dir("init-bench"); + assert!(run(&dir, &["init"]).status.success()); + + // `init` writes a starter bench.toml, and it must pass `bench`'s validation + // out of the box (so the turnkey path is discoverable and correct by default). + assert!( + dir.join("bench.toml").exists(), + "init should scaffold bench.toml" + ); + let out = run(&dir, &["bench"]); // defaults to --fixtures bench.toml + assert!( + out.status.success(), + "scaffolded bench.toml should validate: {out:?}" + ); + assert!( + String::from_utf8_lossy(&out.stdout).contains("bench plan OK"), + "stdout: {}", + String::from_utf8_lossy(&out.stdout) + ); +} + #[test] fn bench_validates_a_plan_and_summarises() { let dir = scratch_dir("bench-ok"); diff --git a/docs/reference.md b/docs/reference.md index de7fea4..ad8388a 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -561,6 +561,7 @@ cu-profiler.toml .cu/baseline.json (if desired) .github/workflows/cu-profiler.yml (if flag) examples/scenarios.rs +bench.toml (starter plan for the turnkey real-CU path) ``` ### `cu-profiler run`