Skip to content

fix(cli): gate the unix-only migration APIs behind cfg(unix) - #1148

Merged
cameri merged 6 commits into
rewrite/mainfrom
fix/1121-cli-migrate-cfg-gate
Nov 16, 2026
Merged

cameri merged 6 commits into
rewrite/mainfrom
fix/1121-cli-migrate-cfg-gate

Conversation

@chappie-daemon

@chappie-daemon chappie-daemon commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Gates the Unix-only migration code behind cfg(unix), so cargo build -p nostream-cli --no-default-features compiles on a non-Unix target instead of failing on std::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_target and the Unix-only unit tests. run keeps a #[cfg(not(unix))] twin that prints migrate pg-to-lmdb is unsupported on this platform and answers exit code 1, so the command still exists everywhere and is refused rather than missing.
  • crates/nostream-storage/src/backend.rs — the DirBuilderExt import and the 0700 directory create behind #[cfg(unix)], with create_dir_all as 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 — a windows-latest job running cargo build and 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_failure with 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 pins actions/checkout@v4.4.0 and actions-rust-lang/setup-rust-toolchain@v1.17.0, like every other uses: in the file. The probes were closed and their branches deleted.

The Windows build then found a second crate

crates/nostream-config/src/load.rs imported std::ffi::OsStr at the top, where only the #[cfg(unix)] trim reads it; on Windows that is an unused import and -D warnings makes 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:

  1. create_target, refuse_swappable_ancestry and two unit tests were still ungated. They call DirBuilder::mode, refuse_unsafe_target, MetadataExt::uid, Permissions::from_mode and metadata.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.
  2. A trailing-whitespace line in backend.rs made cargo fmt --all --check fail, and CI runs it.
  3. One unrelated hunk — the concurrency.group quotes flipped from single to double in checks.yml — was dropped so the diff stays on the job addition.
  4. The Unix contract lived in tests that compile everywhere. The four per-test gates became one file-level #![cfg(unix)], and migrate_cli_unsupported.rs covers the other platform; the Windows job runs it.

The two action pins are the tagged commits actions/checkout@v4.4.0 and actions-rust-lang/setup-rust-toolchain@v1.17.0, checked against their tag refs.

How Has This Been Tested?

cargo fmt --all --check
cargo build -p nostream-cli --no-default-features
cargo test -p nostream-cli --lib --no-default-features          # 8 passed
cargo test -p nostream-cli --test migrate_cli --no-default-features  # 42 passed

A local cargo check --target x86_64-pc-windows-gnu cannot run here (no mingw C cross-compiler for a TLS dependency), so the windows-latest job in this PR is the non-Unix proof rather than a claim.

Types of changes

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

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my code changes.
  • I added a changeset, or this is docs-only and I added an empty changeset.
  • All new and existing tests passed.

tirthraj01 and others added 2 commits November 15, 2026 22:38
`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.
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2ba2b61e-2f33-47dc-a41c-dba7e724d19b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@changeset-bot

changeset-bot Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d188623

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When 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

@greptile-apps

greptile-apps Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues remain.

Summary

Gates Unix-only migration code while keeping a clear refusal on other platforms.

  • The migration command builds on non-Unix systems and refuses to copy there.
  • LMDB can create its data directory on non-Unix systems.

Reviews (3) · Last reviewed commit: "fix(ci): pin the Windows job's actions b..." · Reviewed by Greptile

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.
greptile-apps[bot]
greptile-apps Bot previously approved these changes Nov 16, 2026
`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.
@greptile-apps
greptile-apps Bot dismissed their stale review November 16, 2026 04:00

Dismissed because a newer commit was pushed; Greptile will re-review the current head.

@cameri
cameri merged commit 6e3af92 into rewrite/main Nov 16, 2026
20 of 21 checks passed
@cameri
cameri deleted the fix/1121-cli-migrate-cfg-gate branch November 16, 2026 04:06
@coveralls

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 43801449409

Coverage remained the same at 77.588%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 12081
Covered Lines: 9792
Line Coverage: 81.05%
Relevant Branches: 6342
Covered Branches: 4502
Branch Coverage: 70.99%
Branches in Coverage %: Yes
Coverage Strength: 761.92 hits per line

💛 - Coveralls

chappie-daemon added a commit that referenced this pull request Nov 16, 2026
## 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.
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.

4 participants