fix(cli): preserve program names from anchor.toml when scaffold runbook#680
Conversation
b41e779 to
53f5c2c
Compare
Greptile SummaryThis PR fixes a bug where program names from
Confidence Score: 5/5Safe to merge — the change is a targeted fix to a name-mangling bug with full test coverage and no regressions introduced. Both affected code paths (Anchor manifest and Cargo manifest) are corrected with minimal, focused changes. The old convert_case calls are removed entirely, and the replacement logic (clone() / replace('-', "_")) is straightforwardly correct. Three new unit tests and one integration test assert the expected behavior, including the digit-splitting regression case. No existing behavior is broken for names that did not contain digits. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Scaffold runbook] --> B{Anchor.toml present?}
B -- yes --> C[Parse AnchorManifest]
C --> D["deser_programs()"]
D --> E["name.clone() ✅\n(was: to_case(Case::Snake) ❌)"]
E --> F[program_name preserved verbatim]
B -- no --> G[Walk workspace Cargo.toml members]
G --> H{lib.name present?}
H -- yes --> I[use lib.name directly]
H -- no --> J["package.name.replace('-', '_') ✅\n(was: to_case(Case::Snake) ❌)"]
I --> K[program_name preserved]
J --> K
F --> L[Construct .so path & check existence]
K --> L
L --> M[ProgramMetadata]
Reviews (5): Last reviewed commit: "chore: update package-lock" | Re-trigger Greptile |
| #[derive(Debug, Clone, Deserialize)] | ||
| pub struct Lib { | ||
| pub name: String, | ||
| } |
There was a problem hiding this comment.
The
name field on Lib is non-optional, which means CargoManifestFile::from_manifest_str will fail with a deserialization error for any Cargo.toml that has a [lib] section without an explicit name key. This is extremely common — both in this very repository (crates/core, crates/types, crates/sdk all have [lib] path = "src/lib.rs" with no name) and in standard Anchor/Solana projects where [lib] crate-type = ["cdylib", "lib"] is typical. When the workspace scanner hits any such member, scaffolding fails entirely rather than falling back to the package name.
| let program_name = manifest | ||
| .lib | ||
| .as_ref() | ||
| .map(|lib| lib.name.clone()) | ||
| .unwrap_or_else(|| package.name.replace('-', "_")); |
There was a problem hiding this comment.
Once
Lib.name becomes Option<String>, the fallback chain here needs to use and_then instead of map so a Lib present but with no name still falls through to the package-name logic.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
53f5c2c to
4ea3ac4
Compare
|
@greptileai I've addressed your comments - ready for rereview |
|
Want your agent to iterate on Greptile's feedback? Try greploops. |
Fixes #679