Repository navigation
fix(cli): gate the unix-only migration APIs behind cfg(unix) - #1148
Conversation
(cherry picked from commit 6450901)
`create_target` still called `DirBuilder::mode` and the now-gated `refuse_unsafe_target`, and two unit tests still read `uid()` and `Permissions::from_mode`, so `cargo build -p nostream-cli --no-default-features` on a non-Unix target still failed to compile — the class #1121 exists to close, and what the new Windows job reports. Gate the function and both tests; nothing calls them outside the `#[cfg(unix)] run()`, so no stub is needed.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
🦋 Changeset detectedLatest commit: d188623 The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
[Medium impact] The PR appears safe to merge; no actionable issues remain.
|
Greptile's first finding: `refuse_swappable_ancestry` reads `metadata.permissions().mode()` and was not gated, so Rust still type-checked it on Windows and the build still failed. Greptile's second: the Unix contract lived in tests that would compile on every platform and assert Unix behaviour. `migrate_cli.rs` now carries `#![cfg(unix)]` for the whole file (which is what the four per-test gates were reaching for), and `migrate_cli_unsupported.rs` pins the refusal where the copy cannot run. The Windows job runs that test too, so the refusal is executed on the platform it describes rather than merely built.
`std::ffi::OsStr` is read in `trim_trailing_separators`'s `#[cfg(unix)]` body alone, so on Windows the top-level import is unused and the build fails under `-D warnings`. The Windows CLI job reaches this crate through `nostream-cli`, which is how it surfaced.
A SHA pin makes this repository's `pull_request` run fail at startup with no jobs created — measured on two probe branches: the same job with tag pins starts, with SHA pins it does not. Every other `uses:` in this workflow is a tag, so the job follows the existing convention.
Dismissed because a newer commit was pushed; Greptile will re-review the current head.
Coverage Report for CI Build 43801449409Coverage remained the same at 77.588%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats💛 - Coveralls |
## Description `#1148` gated `run` and every helper it could reach individually. Rust still type-checks a function nothing on the platform can call, so the Windows job it added then failed on eleven dead-code errors — `PostgresBackend` in the imports, `records_progress`, `describe_source`, `is_url_with_host`, `without_credentials`, `probe_budget`, `no_store`, `store_present`, `check_resume_store`, `open_target`, `open_existing_target` — all reachable only from the `#[cfg(unix)] run()`. This takes the shape the issue asked for instead of more attributes: - `crates/nostream-cli/src/commands/mod.rs` — `#[cfg(unix)] pub mod migrate;` and, on the other platform, `#[cfg(not(unix))] #[path = "migrate_unsupported.rs"] pub mod migrate;` - `crates/nostream-cli/src/commands/migrate_unsupported.rs` — the same `MigrateOptions` and a `run` that writes `migrate pg-to-lmdb is unsupported on this platform` and answers exit code 1. - `main.rs` needs no `cfg` arm: both modules answer the same names. `migrate.rs` keeps its internal gates (they are inert inside a Unix-only module) and loses the now-duplicate `#[cfg(not(unix))] run`. ## Related Issue Closes #1121 ## How Has This Been Tested? The non-Unix arm is compiled on Linux by swapping the two module attributes in a scratch copy, which is exactly the configuration the Windows runner builds: ``` cargo clippy -p nostream-cli --no-default-features --lib --bins -- -D warnings # clean cargo fmt --all --check # clean cargo build -p nostream-cli --no-default-features # clean cargo test -p nostream-cli --lib --no-default-features # 8 passed cargo test -p nostream-cli --test migrate_cli --no-default-features # 42 passed cargo clippy -p nostream-cli --no-default-features --all-targets -- -D warnings # clean ``` The `windows-latest` job in `checks.yml`, added by `#1148`, is the platform proof; `migrate_cli_unsupported.rs` pins the refusal and that job runs it. ## Types of changes - [x] Bug fix (non-breaking change which fixes an issue) - [ ] Non-functional change (docs, style, minor refactor) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) ## Checklist: - [x] My code follows the code style of this project. - [ ] My change requires a change to the documentation. - [ ] I have updated the documentation accordingly. - [x] I have read the **CONTRIBUTING** document. - [x] I have added tests to cover my code changes. - [x] I added a changeset, or this is docs-only and I added an empty changeset. - [x] All new and existing tests passed.
Description
Gates the Unix-only migration code behind
cfg(unix), socargo build -p nostream-cli --no-default-featurescompiles on a non-Unix target instead of failing onstd::os::unix::fs.crates/nostream-cli/src/commands/migrate.rs— the Unix imports,run,refuse_unsafe_target,refuse_unsafe_target_for,effective_uid,refuse_swappable_ancestry,create_targetand the Unix-only unit tests.runkeeps a#[cfg(not(unix))]twin that printsmigrate pg-to-lmdb is unsupported on this platformand answers exit code 1, so the command still exists everywhere and is refused rather than missing.crates/nostream-storage/src/backend.rs— theDirBuilderExtimport and the0700directory create behind#[cfg(unix)], withcreate_dir_allas the non-Unix path.crates/nostream-cli/tests/migrate_cli.rs—#![cfg(unix)]for the file, because every test in it drives the copy.crates/nostream-cli/tests/migrate_cli_unsupported.rs— the refusal pinned where the copy cannot run: exit 1 and the message naming the command..github/workflows/checks.yml— awindows-latestjob runningcargo buildand then the refusal test, so the non-Unix path is executed rather than only built.The workflow job could not start CI at all
Every run on this branch ended
startup_failurewith zero jobs created, so the Rust checks never ran either. Four probe PRs isolated the cause: the same job starts when its actions are pinned by tag and fails when they are pinned by SHA, which this repository's runner policy rejects at startup. The job now pinsactions/checkout@v4.4.0andactions-rust-lang/setup-rust-toolchain@v1.17.0, like every otheruses:in the file. The probes were closed and their branches deleted.The Windows build then found a second crate
crates/nostream-config/src/load.rsimportedstd::ffi::OsStrat the top, where only the#[cfg(unix)]trim reads it; on Windows that is an unused import and-D warningsmakes it a build error. The import moved into the function that uses it. That is a pre-existing Windows break, not one this patch introduced, and it is the class the issue's acceptance names.Related Issue
Closes #1121
Credit
The change is @tirthraj01's, from
#1121 (comment) and his fork
(
tirthraj01:fix/1121-cli-migrate-cfg-gate). He remains the author of that commit; the Windows job and its SHA-pinned actions are his.Applied here with corrections, each measured:
create_target,refuse_swappable_ancestryand two unit tests were still ungated. They callDirBuilder::mode,refuse_unsafe_target,MetadataExt::uid,Permissions::from_modeandmetadata.permissions().mode(), none of which exist off Unix — so the Windows job would have failed. Gating a caller does not stop Rust type-checking a function, which is why each function needed its own gate.backend.rsmadecargo fmt --all --checkfail, and CI runs it.concurrency.groupquotes flipped from single to double inchecks.yml— was dropped so the diff stays on the job addition.#![cfg(unix)], andmigrate_cli_unsupported.rscovers the other platform; the Windows job runs it.The two action pins are the tagged commits
actions/checkout@v4.4.0andactions-rust-lang/setup-rust-toolchain@v1.17.0, checked against their tag refs.How Has This Been Tested?
A local
cargo check --target x86_64-pc-windows-gnucannot run here (no mingw C cross-compiler for a TLS dependency), so thewindows-latestjob in this PR is the non-Unix proof rather than a claim.Types of changes
Checklist: