Skip to content

fix(version): show published Cargo sources without the dev marker - #5899

Merged
Hmbown merged 2 commits into
mainfrom
fix/cargo-source-version-0913-20260905
Sep 6, 2026
Merged

fix(version): show published Cargo sources without the dev marker#5899
Hmbown merged 2 commits into
mainfrom
fix/cargo-source-version-0913-20260905

Conversation

@Hmbown

@Hmbown Hmbown commented Sep 5, 2026

Copy link
Copy Markdown
Owner

A successful crates.io install currently reports codewhale 0.9.12 (dev), making the published source package look like an unreleased checkout. Unstamped Cargo source packages now show their package version without the development marker. Unpackaged development checkouts retain (dev), and explicitly stamped builds retain their SHA.

The shared build helper recognizes Cargo's normalized source layout through Cargo.toml.orig. This is not a release-authenticity check: it reads no VCS hash, adds no Git watcher, and leaves release/telemetry provenance absent unless the build environment supplied it.

Validation:

  • Build-support tests: 5 passed, 0 failed; all-target clippy with warnings denied, formatting, and diff checks passed.
  • A real offline Cargo package/install fixture using the changed helper produced 0.9.13 from the unpacked tarball, with both commit and release provenance absent.
  • The unpackaged fixture produced 0.9.13 (dev); an explicitly stamped packaged fixture retained its SHA and provenance.
  • This fixture verifies the build-helper/Cargo boundary; it is not a newly published Codewhale binary. The runtime root has no npm test or check:web scripts.

Fixes #5891.


Note

Low Risk
Build-time version string formatting only; stamped CI/release and local (dev) behavior for git checkouts are unchanged, with a narrow new branch for Cargo-packaged sources.

Overview
Fixes crates.io-style installs reporting (dev) when the build was never stamped with a CI SHA. Unstamped builds from Cargo’s normalized source tree (detected via Cargo.toml.orig next to the manifest) now embed CODEWHALE_BUILD_VERSION as the plain package version; local unpackaged checkouts still get (dev), and env-stamped builds still get the short SHA suffix.

emit_build_version delegates to a new format_build_version helper instead of defaulting unstamped builds to (dev) unconditionally. Docs clarify that this layout check is not release provenance—no git watchers and no extra commit metadata unless the environment supplies a SHA. Tests cover packaged vs dev vs stamped version strings and that packaging alone does not invent release telemetry SHA.

Reviewed by Cursor Bugbot for commit de1a531. Bugbot is set up for automated code reviews on this repo. Configure here.

Copilot AI lite review requested due to automatic review settings September 5, 2026 13:11
@Hmbown Hmbown added this to the v0.9.13 milestone Sep 5, 2026
@cursor

cursor Bot commented Sep 5, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_1835f992-8df8-4543-96d3-22a32028d546)

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-05T13:14:14.314233Z f16cfd4 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@claude

claude Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Claude finished @Hmbown's task in 1m 37s —— View job


Claude's review of #5899

  • Gather context (diff, related code)
  • Understand the request
  • Review crates/build-support/src/lib.rs changes
  • Post review feedback

Summary

This is a small, well-scoped fix: emit_build_version now checks for Cargo.toml.orig (which Cargo writes when normalizing a packaged/distributed source tree) to distinguish an unstamped packaged source (plain 0.9.13) from an unstamped dev checkout (0.9.13 (dev)), while an explicitly stamped build keeps its SHA regardless. The doc comments are updated consistently with the new contract, and a focused unit test (packaged_sources_do_not_claim_to_be_unreleased_or_stamped) covers all three branches.

Correctness / safety: No bugs found. The one thing worth a closer look was &sha[..12] in the new format_build_version (line 80) — a raw byte-slice that would panic on a string shorter than 12 bytes. I verified this is safe today: commit only ever comes from build_commit_with, which only returns Some after full_sha validates an exact 40-character lowercase hex string, so the slice is always in bounds. I left an inline suggestion to reuse the existing short_sha helper (already used by release_build_sha) instead of re-deriving the truncation, since short_sha can't panic regardless of input length and keeps the safety invariant local to the function rather than dependent on its one caller — a minor reuse/robustness note, not a blocking issue.

Provider/model routing: Not applicable — this PR only touches build-script version stamping.

Scope: Change is minimal, matches the stated intent (no VCS reads, no new provenance source, CODEWHALE_RELEASE_BUILD_SHA/telemetry path untouched), and the doc comments were updated in step with the code.

Not verified in this session: I wasn't able to execute cargo test -p codewhale-build-support / clippy / fmt here (sandbox denied the cargo invocations), so I relied on static review plus the test results already reported in the PR description (5 passed, 0 failed).

Branch: fix/cargo-source-version-0913-20260905

Comment thread crates/build-support/src/lib.rs Outdated
packaged_source: bool,
) -> String {
match commit {
Some(sha) => format!("{package_version} ({})", &sha[..12]),

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.

Minor reuse note: this reimplements the truncation that short_sha (below, line 161) already does — and does it less defensively. short_sha truncates via .chars().take(12).collect(), which cannot panic regardless of input length; &sha[..12] panics if sha.len() < 12.

It's not reachable today — commit only ever holds a full_sha-validated 40-char hex string (see build_commit_with/full_sha), so the slice is always in bounds. But format_build_version doesn't itself enforce that invariant, so the safety is only true by virtue of its one caller. Reusing short_sha(sha.to_string()) here would keep the guarantee local to the function instead of relying on the caller, per the "already in this codebase → reuse it" rule.

Suggested change
Some(sha) => format!("{package_version} ({})", &sha[..12]),
Some(sha) => match short_sha(sha.to_string()) {
Some(short) => format!("{package_version} ({short})"),
None => format!("{package_version} (dev)"),
},

(would need short_sha in scope, e.g. use super::short_sha isn't needed since it's the same module — just call short_sha(...) directly.)

Copilot AI left a comment

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.

🟢 Approval recommended

The change is narrowly scoped to build-time version string formatting and includes a targeted unit test covering the new packaging vs. checkout distinction.

Pull request overview

This PR adjusts build-time version string formatting so that unstamped builds from Cargo’s normalized source packages (e.g., crates.io / cargo install) display the plain package version (no misleading (dev)), while unstamped local checkouts still show (dev) and stamped builds continue to show the short SHA.

Changes:

  • Detect Cargo’s normalized source layout via Cargo.toml.orig and use that to decide when to omit (dev) for unstamped builds.
  • Refactor version string construction into a dedicated format_build_version helper and add a regression test for the three cases (stamped / packaged-unstamped / checkout-unstamped).
File summaries
File Description
crates/build-support/src/lib.rs Adds Cargo source-package detection and refactors build-version formatting + tests to avoid showing (dev) for published sources.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/build-support/src/lib.rs Outdated
Comment on lines +79 to +83
match commit {
Some(sha) => format!("{package_version} ({})", &sha[..12]),
None if packaged_source => package_version.to_string(),
None => format!("{package_version} (dev)"),
}
@cursor

cursor Bot commented Sep 5, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_cad45d39-a703-45bd-880d-7b9492e2059d)

@claude

claude Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Claude finished @Hmbown's task in 49s —— View job


Claude's review of #5899 (updated after new commit)

  • Gather context (diff, related code)
  • Review latest commit 26d0f5d (refactor: reuse the shared SHA formatter)
  • Confirm prior review feedback was addressed
  • Post review feedback

Summary

The new commit 26d0f5d directly addresses the one issue flagged in the earlier review round (by both Claude and Copilot): format_build_version no longer does a raw &sha[..12] slice. It now goes through the existing short_sha helper:

fn format_build_version(
    package_version: &str,
    commit: Option<&str>,
    packaged_source: bool,
) -> String {
    match commit.and_then(|sha| short_sha(sha.to_string())) {
        Some(sha) => format!("{package_version} ({sha})"),
        None if packaged_source => package_version.to_string(),
        None => format!("{package_version} (dev)"),
    }
}

This is a strict improvement: short_sha truncates via .chars().take(12).collect(), so it can't panic regardless of input length, and the function is now total on its own rather than relying on the invariant that commit is always a validated 40-hex string from its one caller. Good "reuse the existing thing" fix per the ponytail rule in this repo's AGENTS.md.

Correctness: No bugs found in the current state. The three-way branch (stamped / packaged-unstamped / checkout-unstamped) is unambiguous and the new unit test packaged_sources_do_not_claim_to_be_unreleased_or_stamped (crates/build-support/src/lib.rs:174) exercises all three cases plus the "packaging doesn't invent a release SHA" invariant via release_build_sha.

Provider/model routing: Not applicable — build-script version stamping only, no model/provider logic touched.

Reuse/simplification: The refactor is exactly the right kind of simplification — one location (short_sha) now owns all SHA truncation instead of two independently-maintained truncation strategies.

Scope: Still minimal and matches stated intent — no VCS reads added, no new cargo:rerun-if-changed rules, CODEWHALE_RELEASE_BUILD_SHA/telemetry path untouched.

Not independently re-verified in this session: cargo test/clippy invocations are not permitted in this sandbox (same limitation as the prior review pass), so I relied on static reading of the diff plus the PR's reported "5 passed, 0 failed" test run. The logic change is small and low-risk enough that static review gives good confidence here.

No further findings — this looks ready as-is.

Branch: fix/cargo-source-version-0913-20260905

@codewhale-agent codewhale-agent Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Codewhale review

Updates build-time version formatting so unstamped Cargo source packages show the plain package version instead of a misleading (dev) marker, while checkouts and stamped builds retain prior behavior. The change is low-risk and focused on build-support formatting.

Findings

  • [INFO] Packaged-source detection is not covered by an emit_build_version test (crates/build-support/src/lib.rs:173)
    The new behavior depends on manifest_dir.join("Cargo.toml.orig").is_file(), but the added test only calls format_build_version directly. The path construction and emitted cargo:rustc-env lines for packaged versus unpackaged layouts are exactly the PR's behavioral change and remain unprotected by an automated unit test.

Assessment

Low-risk build-time formatting change with no correctness blockers found. The main gap is automated coverage for the filesystem-based detection path added in emit_build_version.


Advisory review by Codewhale (codewhale review --pr 5899 --post, head 26d0f5d9d7ee2e00ebb24bc073fa8c799dba5e08). Line-specific findings are also posted as inline review comments; mechanical fixes arrive as committable suggestions you can apply from the Files tab. CODEOWNERS approval still governs merge.

mod tests {
use super::{full_sha, release_build_sha, short_sha};

#[test]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[INFO] Packaged-source detection is not covered by an emit_build_version test

The new behavior depends on manifest_dir.join("Cargo.toml.orig").is_file(), but the added test only calls format_build_version directly. The path construction and emitted cargo:rustc-env lines for packaged versus unpackaged layouts are exactly the PR's behavioral change and remain unprotected by an automated unit test.

@Hmbown
Hmbown force-pushed the fix/cargo-source-version-0913-20260905 branch from 26d0f5d to e3db79c Compare September 6, 2026 00:07
@cursor

cursor Bot commented Sep 6, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_43a076cf-25ba-4f5f-98b8-ed6d3dd95f53)

@claude

claude Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Claude finished @Hmbown's task in 1m 0s —— View job


Claude's review of #5899 (final pass)

  • Gather context (diff vs origin/main, related build.rs callers)
  • Confirm prior review feedback (short_sha reuse) was applied
  • Verify Cargo.toml.orig detection is sound against real CARGO_MANIFEST_DIR semantics
  • Post review feedback

Summary

Reviewed the full diff at 26d0f5d / e3db79c (crates/build-support/src/lib.rs, +46/-12). This is a small, well-contained fix and the two earlier findings (Claude's and Copilot's &sha[..12] panic risk) are already resolved — format_build_version now goes through the existing short_sha helper, which truncates via .chars().take(12) and can't panic on a short string.

Correctness: No bugs. Verified the Cargo.toml.orig detection is actually sound, not just plausible:

  • crates/cli/build.rs and crates/tui/build.rs both pass CARGO_MANIFEST_DIR as manifest_dir — the crate's own manifest directory, not the workspace root.
  • Cargo only writes Cargo.toml.orig into the packaging output (target/package/...) or into the extracted registry source (~/.cargo/registry/src/.../<crate>-<version>/) — never into the original repo checkout. So a normal local dev build can't accidentally trip this check and suppress (dev).
  • The three-way branch in format_build_version (stamped → SHA; unstamped+packaged → plain version; unstamped+checkout → (dev)) is exhaustive and unambiguous.

Provider/model routing: N/A — build-script version stamping only, no model/provider code touched.

Reuse/simplification: The e3db79c refactor is exactly right — one truncation implementation (short_sha) instead of two, per the repo's rung-2 reuse rule.

Tests: The unit test (packaged_sources_do_not_claim_to_be unreleased_or_stamped, line 174) covers format_build_version directly for all three branches plus the "packaging doesn't invent a release SHA" invariant. As the automated Codewhale review already noted (INFO, non-blocking): emit_build_version's actual filesystem check (manifest_dir.join("Cargo.toml.orig").is_file()) isn't exercised by an automated test — only the pure function is. Given the analysis above (manifest_dir provenance is correct and the file can't appear in a normal checkout), this is a minor coverage gap rather than a correctness risk, and a temp-dir-based test would be the natural way to close it if desired.

Scope: Matches stated intent — no VCS reads added, no new cargo:rerun-if-changed rules, CODEWHALE_RELEASE_BUILD_SHA/telemetry path untouched.

No blocking issues. This looks ready to merge as-is.
· Branch: fix/cargo-source-version-0913-20260905

@codewhale-agent codewhale-agent Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Codewhale review

The PR correctly stops unstamped Cargo source packages from reporting a (dev) marker and keeps stamped/local checkout behavior intact. The formatting helper is unit tested, but the build-script rerun conditions do not account for the new Cargo.toml.orig input, and the filesystem classification is not covered by automated tests.

Findings

  • [WARNING] Build script does not rerun when Cargo.toml.orig changes (crates/build-support/src/lib.rs:62)
    emit_build_version now changes its output based on manifest_dir.join("Cargo.toml.orig").is_file(), but declare_rerun_conditions(_manifest_dir) still ignores manifest_dir and only emits environment-based rerun conditions. In incremental builds where the packaged/unpackaged layout changes without an environment variable change, CODEWHALE_BUILD_VERSION can remain stale. Add a cargo:rerun-if-changed directive for the marker file or update declare_rerun_conditions to use manifest_dir.
  • [INFO] Packaged-source filesystem detection is not covered by automated tests (crates/build-support/src/lib.rs:62)
    The new tests exercise format_build_version directly, but the crucial Cargo.toml.orig presence check in emit_build_version is only validated by a manual fixture. Consider extracting the path check into a small helper and unit-testing both true and false cases, or adding a tempdir integration test, so the crates.io/checkout distinction cannot regress.

Suggestions

  • crates/build-support/src/lib.rs:58 — Declare the marker file as an input so Cargo reruns the build script when the packaged/unpackaged source layout changes.

        println!("cargo:rerun-if-changed=Cargo.toml.orig");
        let commit = build_commit();
    

Assessment

The change is low risk and fixes the reported version marker problem. The formatting logic is sound and tests cover the helper, but the build script should be made rerun-sensitive to Cargo.toml.orig and the detection path deserves automated coverage.


Advisory review by Codewhale (codewhale review --pr 5899 --post, head e3db79c031a3339b93bcbc83e88c87cb3ed1a888). Line-specific findings are also posted as inline review comments; mechanical fixes arrive as committable suggestions you can apply from the Files tab. CODEOWNERS approval still governs merge.

let build_version = format_build_version(
package_version,
commit.as_deref(),
manifest_dir.join("Cargo.toml.orig").is_file(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[WARNING] Build script does not rerun when Cargo.toml.orig changes

emit_build_version now changes its output based on manifest_dir.join("Cargo.toml.orig").is_file(), but declare_rerun_conditions(_manifest_dir) still ignores manifest_dir and only emits environment-based rerun conditions. In incremental builds where the packaged/unpackaged layout changes without an environment variable change, CODEWHALE_BUILD_VERSION can remain stale. Add a cargo:rerun-if-changed directive for the marker file or update declare_rerun_conditions to use manifest_dir.

let build_version = format_build_version(
package_version,
commit.as_deref(),
manifest_dir.join("Cargo.toml.orig").is_file(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[INFO] Packaged-source filesystem detection is not covered by automated tests

The new tests exercise format_build_version directly, but the crucial Cargo.toml.orig presence check in emit_build_version is only validated by a manual fixture. Consider extracting the path check into a small helper and unit-testing both true and false cases, or adding a tempdir integration test, so the crates.io/checkout distinction cannot regress.

/// Its presence classifies the source layout, not release provenance: no VCS
/// metadata is read and no additional commit value is emitted.
pub fn emit_build_version(manifest_dir: &Path, package_version: &str) {
let commit = build_commit();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Declare the marker file as an input so Cargo reruns the build script when the packaged/unpackaged source layout changes.

Suggested change
let commit = build_commit();
println!("cargo:rerun-if-changed=Cargo.toml.orig");
let commit = build_commit();

CodeWhale Bot added 2 commits September 5, 2026 20:24
Unstamped Cargo source packages show the package version, while unpackaged checkouts retain (dev) and explicit build SHA stamps retain precedence. No Git metadata is read or added to telemetry.

Validation: 5/5 build-support tests passed; all-target clippy -D warnings, fmt, and diff checks passed. Real offline Cargo package/install fixture verified packaged, development, and stamped outputs and absent provenance for unstamped sources. Runtime root has no npm test/check:web scripts.
Signed-off-by: CodeWhale Bot <bot@codewhale.net>
Use short_sha instead of byte slicing, retaining total behavior if future callers provide a shorter string. Validation: 5/5 build-support tests and all-target clippy -D warnings pass; formatting and diff checks pass.

Signed-off-by: CodeWhale Bot <bot@codewhale.net>
@Hmbown
Hmbown force-pushed the fix/cargo-source-version-0913-20260905 branch from e3db79c to de1a531 Compare September 6, 2026 03:24
@cursor

cursor Bot commented Sep 6, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_ea8fd652-2abf-4362-b759-19ad1367ec5e)

@claude

claude Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Claude finished @Hmbown's task in 1m 27s —— View job


Review of #5899

  • Gather context (diff vs origin/main, callers, prior review threads)
  • Verify current state of crates/build-support/src/lib.rs
  • Check declare_rerun_conditions / rerun-if-changed semantics against Cargo's actual behavior
  • Post final review

Summary

Current head (de1a531) already incorporates the fixes from earlier review rounds: format_build_version (crates/build-support/src/lib.rs:74-84) goes through short_sha, so the earlier &sha[..12] panic risk (flagged independently by me, Copilot, and Cursor's static pass) is gone — short_sha truncates via .chars().take(12) and is total for any input length. The three-way branch (stamped → SHA; unstamped+packaged → plain version; unstamped+checkout → (dev)) is unambiguous and exercised by packaged_sources_do_not_claim_to_be_unreleased_or_stamped (line 174), including the "packaging must not invent a release SHA" invariant via release_build_sha.

1. Correctness: No bugs in the current diff. format_build_version is pure and panic-free.

2. Provider/model routing: N/A — build-script version stamping only.

3. Reuse/simplification: Good — one truncation implementation (short_sha) now owns all SHA formatting instead of two.

4. One real, low-severity gap — confirming the automated Codewhale bot's WARNING is correct, not just plausible:
declare_rerun_conditions (line 41-45) only emits cargo:rerun-if-env-changed=... for the three SHA env vars; it never emits any cargo:rerun-if-changed=<path> directive. Per Cargo's build-script contract, printing any rerun-if-changed/rerun-if-env-changed line opts the script out of the default "rerun if any file in the package changed" fallback — so once this script prints its env-changed lines, Cargo relies only on the declared conditions, and a change in whether Cargo.toml.orig exists next to the manifest is invisible to it. In the primary cargo install / crates.io flow this is harmless (each package version is extracted once into an immutable registry-src directory, so Cargo.toml.orig's presence never toggles within a build), but it's a real staleness edge for any workflow that reuses the same target/ across a packaged/unpackaged transition (e.g., cargo package iterating in place). A one-line println!("cargo:rerun-if-changed=Cargo.toml.orig"); in emit_build_version closes it cheaply and costs nothing on layouts where the file never appears.

5. Tests: The pure format_build_version helper is well covered. The actual filesystem check in emit_build_version (manifest_dir.join("Cargo.toml.orig").is_file(), line 62) is only exercised by the manual fixture described in the PR body, not an automated test — a small tempdir-based test (create a dir with/without Cargo.toml.orig, assert the resulting CODEWHALE_BUILD_VERSION env line) would close that gap and guard the crates.io/checkout distinction long-term. Non-blocking.

6. Security: No secret handling or exec paths touched; nothing to flag.

Assessment

Ready to merge as-is on correctness grounds — no panics, no scope creep, CODEWHALE_RELEASE_BUILD_SHA/telemetry path genuinely untouched. The two open items (rerun-if-changed for Cargo.toml.orig, and a filesystem-level test for the packaged/unpackaged branch) are real but minor; worth a fast follow-up rather than blocking this fix. Fix the rerun-if-changed gap →
· Branch: fix/cargo-source-version-0913-20260905

@codewhale-agent codewhale-agent Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Codewhale review

PR updates build-support version formatting so crates.io-style packaged Cargo sources without CI SHA print the plain package version instead of (dev), while local dev checkouts and stamped builds keep previous behavior. The helper is split into a testable format_build_version and uses Cargo.toml.orig presence as the packaged-source signal.

Findings

  • [WARNING] Build script rerun conditions do not account for Cargo.toml.orig (crates/build-support/src/lib.rs:62)
    format_build_version now depends on whether manifest_dir/Cargo.toml.orig exists, but the build script's declared rerun conditions only cover the stamping environment variables. In a reused target directory where a source tree gains or loses Cargo.toml.orig, Cargo may not rerun the build script and can keep a stale CODEWHALE_BUILD_VERSION. Fresh Cargo package builds are unaffected, which limits impact, but the new file dependency should be declared.
  • [WARNING] Invalid stamping SHA now yields plain version for packaged sources (crates/build-support/src/lib.rs:81)
    format_build_version treats any short_sha failure as an unstamped build. If CODEWHALE_BUILD_SHA/GITHUB_SHA is set but is not a valid 40-hex value, packaged sources now emit the plain package version, whereas the previous fallback was (dev). That can hide a misconfigured stamped build. Consider preserving the dev marker for invalid values or adding a test to lock in the desired behavior.
  • [INFO] Cargo.toml.orig detection lacks automated coverage (crates/build-support/src/lib.rs:62)
    The new tests exercise format_build_version directly, but no unit test creates a temporary Cargo.toml.orig next to a manifest to verify emit_build_version packaged/unpackaged classification. The PR mentions an offline fixture, but that is not part of the automated test suite and could let the filesystem branch regress.

Assessment

The change is small, focused, and likely correct for the reported crates.io install case. Before merging, I would address the build-script rerun dependency on Cargo.toml.orig and add coverage for invalid SHA input and the filesystem classification path.


Advisory review by Codewhale (codewhale review --pr 5899 --post, head de1a53127feae47a1858ea5714a023dc68208e61). Line-specific findings are also posted as inline review comments; mechanical fixes arrive as committable suggestions you can apply from the Files tab. CODEOWNERS approval still governs merge.

let build_version = format_build_version(
package_version,
commit.as_deref(),
manifest_dir.join("Cargo.toml.orig").is_file(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[WARNING] Build script rerun conditions do not account for Cargo.toml.orig

format_build_version now depends on whether manifest_dir/Cargo.toml.orig exists, but the build script's declared rerun conditions only cover the stamping environment variables. In a reused target directory where a source tree gains or loses Cargo.toml.orig, Cargo may not rerun the build script and can keep a stale CODEWHALE_BUILD_VERSION. Fresh Cargo package builds are unaffected, which limits impact, but the new file dependency should be declared.

) -> String {
match commit.and_then(|sha| short_sha(sha.to_string())) {
Some(sha) => format!("{package_version} ({sha})"),
None if packaged_source => package_version.to_string(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[WARNING] Invalid stamping SHA now yields plain version for packaged sources

format_build_version treats any short_sha failure as an unstamped build. If CODEWHALE_BUILD_SHA/GITHUB_SHA is set but is not a valid 40-hex value, packaged sources now emit the plain package version, whereas the previous fallback was (dev). That can hide a misconfigured stamped build. Consider preserving the dev marker for invalid values or adding a test to lock in the desired behavior.

let build_version = format_build_version(
package_version,
commit.as_deref(),
manifest_dir.join("Cargo.toml.orig").is_file(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[INFO] Cargo.toml.orig detection lacks automated coverage

The new tests exercise format_build_version directly, but no unit test creates a temporary Cargo.toml.orig next to a manifest to verify emit_build_version packaged/unpackaged classification. The PR mentions an offline fixture, but that is not part of the automated test suite and could let the filesystem branch regress.

@Hmbown
Hmbown merged commit 637bded into main Sep 6, 2026
34 checks passed
@Hmbown
Hmbown deleted the fix/cargo-source-version-0913-20260905 branch September 6, 2026 04:15
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.

Published Cargo install reports a misleading “(dev)” version

2 participants