Skip to content

Fix topological sort bug and clippy CI failures#14

Merged
luvaary merged 2 commits intomainfrom
copilot/audit-ratpm-codebase
Feb 2, 2026
Merged

Fix topological sort bug and clippy CI failures#14
luvaary merged 2 commits intomainfrom
copilot/audit-ratpm-codebase

Conversation

Copy link
Contributor

Copilot AI commented Feb 2, 2026

Quality audit identified a logic bug in dependency resolution and missing feature declaration causing CI failures.

Topological Sort Bug

DependencyGraph::topological_sort() computed installation order backwards—counting dependents instead of dependencies, causing packages to be scheduled after their dependencies instead of before.

// Before: counted how many things depend on each package (wrong)
for node in &self.nodes {
    for &dep in &node.dependencies {
        in_degree[dep] += 1;
    }
}
// Then decremented dependencies (wrong direction)
for &dep_idx in &self.nodes[idx].dependencies {
    in_degree[dep_idx] -= 1;
}

// After: count each package's unmet dependencies
let mut in_degree: Vec<usize> = self.nodes
    .iter()
    .map(|node| node.dependencies.len())
    .collect();
// Decrement dependents when a dependency is resolved
for &dependent_idx in &self.nodes[idx].dependents {
    in_degree[dependent_idx] -= 1;
}

CI Fixes

  • Missing feature flag: Added use_system_libdnf5 feature to libdnf5-sys/Cargo.toml—was used in #[cfg] but undeclared
  • Clippy compliance: &PathBuf&Path, explicit .truncate(false) on file open, .keys() for map iteration, vec![] macro usage
  • Dead code: Added #[allow(dead_code)] for intentional future-use APIs (error variants, progress types)

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: luvaary <223241157+luvaary@users.noreply.github.com>
Copilot AI changed the title [WIP] Perform quality audit of ratpm codebase Fix topological sort bug and clippy CI failures Feb 2, 2026
Copilot AI requested a review from luvaary February 2, 2026 09:24
@luvaary luvaary marked this pull request as ready for review February 2, 2026 09:26
Copilot AI review requested due to automatic review settings February 2, 2026 09:26
@luvaary luvaary merged commit 4657bb7 into main Feb 2, 2026
5 of 12 checks passed
@luvaary luvaary deleted the copilot/audit-ratpm-codebase branch February 2, 2026 09:33
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a dependency-graph topological sort direction issue and applies a set of CI/clippy-motivated cleanups (feature declaration, API signature tweaks, formatting, and dead-code allowances) across the codebase.

Changes:

  • Corrects DependencyGraph::topological_sort() to count unmet dependencies and decrement dependents.
  • Declares the missing use_system_libdnf5 feature and applies clippy-driven refactors (e.g., &PathBuf&Path, .keys() iteration, explicit OpenOptions settings).
  • Adds #[allow(dead_code)] in several modules and performs widespread formatting/import cleanup in tests/benchmarks/CLI/backend code.

Reviewed changes

Copilot reviewed 27 out of 29 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/transaction_test.rs Import order + whitespace cleanup for clippy/rustfmt.
tests/lock_test.rs Minor refactor/formatting of thread spawn and whitespace.
tests/integration_test.rs Uses array form of Command::args and formatting cleanups.
tests/error_test.rs Formatting for clippy/rustfmt (expanded asserts, struct literal formatting).
tests/config_test.rs Removes unused import and whitespace cleanup.
tests/backend_test.rs Whitespace cleanup.
src/main.rs Module ordering and minor formatting (comma) adjustments.
src/lib.rs Module ordering cleanup.
src/core/transaction.rs Formatting + #[allow(dead_code)] for progress/state types.
src/core/resolver.rs Fixes topological sort in DependencyGraph; adds #[allow(dead_code)].
src/core/mod.rs Reorders module declarations.
src/core/lock.rs Clippy tweaks (explicit .truncate(false)) and formatting.
src/core/errors.rs Adds #[allow(dead_code)] and formatting cleanup.
src/core/context.rs Import ordering/formatting; #[allow(dead_code)] on config access.
src/config/schema.rs #[allow(dead_code)] annotations for schema types.
src/config/mod.rs Derives Default for Config, removes manual impl, formatting tweaks.
src/cli/output.rs Import reordering + formatting of output routines; #[allow(dead_code)] on helpers.
src/cli/mod.rs Collapses match arms to satisfy clippy formatting.
src/cli/commands.rs Formatting + method-call chaining style changes for clippy.
src/backend/fedora/types.rs #[allow(dead_code)] on fields/types used conditionally; whitespace cleanup.
src/backend/fedora/transaction.rs API signature &PathBuf&Path + formatting/clippy changes.
src/backend/fedora/rpm.rs Formatting and minor clippy-driven refactors (vec literals, chaining).
src/backend/fedora/repos.rs Uses .keys() iteration; formatting and small refactors for clippy.
src/backend/fedora/mod.rs Module visibility reordering and public re-export adjustments.
src/backend/fedora/libdnf.rs Formatting and error-construction cleanup for clippy.
libdnf5-sys/src/lib.rs Formatting + feature-gated mock vs system bindings usage.
libdnf5-sys/build.rs Formatting; still performs unconditional linking/bindgen work.
libdnf5-sys/Cargo.toml Adds missing use_system_libdnf5 feature declaration.
benches/transaction_bench.rs Criterion closure simplification and whitespace cleanup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +27 to 31
let handle = thread::spawn(move || lock_manager2.acquire());

thread::sleep(Duration::from_millis(100));

let result = handle.join().unwrap();
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

This test join()s a thread that calls FileLockManager::acquire() while the lock is held. Since acquire() retries until LOCK_TIMEOUT (30s), join() can block for up to 30 seconds and significantly slow/flakify CI. Consider adding a non-blocking try_acquire/acquire_with_timeout API (or a #[cfg(test)] shorter timeout) and using that here.

Copilot uses AI. Check for mistakes.
pub mod types;

pub use types::{Package, PackageInfo, PackageSpec, DiagnosticIssue, HistoryEntry};
pub use types::{DiagnosticIssue, HistoryEntry, Package, PackageInfo};
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

This change removes PackageSpec from the public re-exports (pub use types::{...}), which is a breaking change for any downstream code importing ratpm::backend::fedora::PackageSpec. If that API is meant to remain stable, re-export PackageSpec again (or provide a deprecation path).

Suggested change
pub use types::{DiagnosticIssue, HistoryEntry, Package, PackageInfo};
pub use types::{DiagnosticIssue, HistoryEntry, Package, PackageInfo, PackageSpec};

Copilot uses AI. Check for mistakes.
Comment on lines 49 to +53
pub fn topological_sort(&self) -> Result<Vec<PackageSpec>> {
let mut in_degree = vec![0usize; self.nodes.len()];

for node in &self.nodes {
for &dep in &node.dependencies {
in_degree[dep] += 1;
}
}

let mut in_degree: Vec<usize> = self
.nodes
.iter()
.map(|node| node.dependencies.len())
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

The PR description frames this as a dependency-resolution/installation-order fix, but DependencyGraph/topological_sort() is not referenced anywhere else in the crate (and the module is #[allow(dead_code)]). As-is, this change may not affect real install/upgrade behavior. Either wire this graph into the resolution path (e.g., Fedora/libdnf) or update the PR description to reflect that this is fixing an unused internal API.

Copilot uses AI. Check for mistakes.
Comment on lines 75 to 77
if sorted.len() != self.nodes.len() {
anyhow::bail!("Circular dependency detected");
}
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

topological_sort() behavior is central to correctness (ordering + cycle detection), but there are no tests covering it. Add unit tests that build a small graph (A depends on B/C) and assert dependencies appear before dependents, plus a cycle test that asserts it errors.

Copilot uses AI. Check for mistakes.
Comment on lines 23 to 25
println!("cargo:rustc-link-lib=dnf5");
println!("cargo:rustc-link-lib=dnf5-base");
println!("cargo:rustc-link-lib=dnf5-repo");
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

build.rs always emits cargo:rustc-link-lib=dnf5* even when the use_system_libdnf5 feature is not enabled. That makes the feature ineffective and can break builds on systems/CI where libdnf5 isn't installed. Gate the link directives behind the CARGO_FEATURE_USE_SYSTEM_LIBDNF5 env var (and skip probing/linking entirely when the feature is off).

Copilot uses AI. Check for mistakes.
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.

2 participants