Skip to content

refactor: DRY flake metadata extraction and ref-statuses loading#232

Open
Malix-Labs wants to merge 1 commit into
DeterminateSystems:mainfrom
Malix-Labs:dry
Open

refactor: DRY flake metadata extraction and ref-statuses loading#232
Malix-Labs wants to merge 1 commit into
DeterminateSystems:mainfrom
Malix-Labs:dry

Conversation

@Malix-Labs

@Malix-Labs Malix-Labs commented Jun 17, 2026

Copy link
Copy Markdown

Summary by CodeRabbit

  • New Features
    • Added new public accessors on Node: git_ref(), last_modified(), and owner() for easier metadata retrieval.
  • Refactor
    • Centralized conversion of lock inputs into a queue-based representation and reused it throughout input chasing.
    • Updated CEL variable registration to use the new node accessors directly, with sensible default handling.
  • Tests
    • Adjusted unit tests to build reference status data via a shared loader helper.
  • Chores
    • Simplified embedded template wiring and reduced mutable state in ref-status fetching.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 255dd439-4e72-4744-94e4-b42f49116fd8

📥 Commits

Reviewing files that changed from the base of the PR and between 44a9088 and b89c2b8.

📒 Files selected for processing (6)
  • parse-flake-lock/src/lib.rs
  • src/condition.rs
  • src/flake.rs
  • src/main.rs
  • src/ref_statuses.rs
  • src/summary.rs
✅ Files skipped from review due to trivial changes (1)
  • src/ref_statuses.rs
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/summary.rs
  • src/main.rs
  • src/condition.rs
  • parse-flake-lock/src/lib.rs
  • src/flake.rs

📝 Walkthrough

Walkthrough

Three public accessor methods (git_ref(), last_modified(), owner()) are added to Node in the parse-flake-lock crate, along with Input::to_deque(). condition.rs and flake.rs are refactored to use these accessors instead of pattern matching. A shared local_ref_statuses() helper is extracted in main.rs to eliminate duplicate JSON parsing, tests are updated to use it, and minor cleanups remove unnecessary mut and simplify include_str! paths.

Changes

Node Accessor Refactoring

Layer / File(s) Summary
Input and Node public accessor methods
parse-flake-lock/src/lib.rs
Adds git_ref() -> Option<&str>, last_modified() -> Option<i64>, and owner() -> Option<&str> to Node with match arms for each variant. Introduces Input::to_deque() to convert Input::String or Input::List into VecDeque<String>. Updates FlakeLock deserialization and chase_input_node recursion to use the new to_deque() helper.
Refactor condition.rs to use Node accessors
src/condition.rs
Removes direct Node import and variant destructuring. Calls node.git_ref(), node.last_modified(), and node.owner() to extract values. Updates add_cel_variables to accept Option<&str> for git_ref and owner, and removes helper conversion functions.
Refactor flake.rs logic to use Node accessors
src/flake.rs
Consolidates Node::Repo and Node::Tarball match branches in nixpkgs_deps. Replaces Node destructuring in check_flake_lock with accessor calls for computing Disallowed, Outdated, and NonUpstream issues. Updates NonUpstream to use owner.to_string().
Extract local_ref_statuses helper and update tests
src/main.rs, src/flake.rs
Creates pub(crate) fn local_ref_statuses() in main.rs to load and deserialize ../ref-statuses.json. Updates both feature-gated and non-feature main execution paths to use this helper instead of duplicating inline JSON parsing. Updates all test functions in flake.rs to call crate::local_ref_statuses() and removes the unused BTreeMap import from the test module.
Minor cleanups and simplifications
src/ref_statuses.rs, src/summary.rs
Removes unnecessary mut from officially_supported in fetch_ref_statuses. Simplifies include_str! template paths from env!("CARGO_MANIFEST_DIR")-based absolute paths to direct relative paths.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐇 Hop hop, no more matching by hand,
Three neat accessors now gracefully stand.
git_ref, last_modified, owner in a row—
The node reveals all it has come to know.
One shared helper brings order to the fold,
A tidy warren, lean and bold! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 52.17% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main refactoring objective: centralizing flake metadata extraction via new accessor methods and DRY-ing up ref-statuses loading through a shared helper function.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread src/flake.rs
Comment on lines 164 to 165
];

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

this one was basically duplicated, i assume by mistake?

Comment thread src/summary.rs
Comment on lines -13 to +19
static CEL_MARKDOWN_TEMPLATE: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/src/templates/summary.cel.md.hbs"
));
static CEL_MARKDOWN_TEMPLATE: &str = include_str!("templates/summary.cel.md.hbs");

static CEL_TEXT_TEMPLATE: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/src/templates/summary.cel.txt.hbs"
));
static CEL_TEXT_TEMPLATE: &str = include_str!("templates/summary.cel.txt.hbs");

static STANDARD_MARKDOWN_TEMPLATE: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/src/templates/summary.standard.md.hbs"
));
static STANDARD_MARKDOWN_TEMPLATE: &str = include_str!("templates/summary.standard.md.hbs");

static STANDARD_TEXT_TEMPLATE: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/src/templates/summary.standard.txt.hbs"
));
static STANDARD_TEXT_TEMPLATE: &str = include_str!("templates/summary.standard.txt.hbs");

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

i assume that's what you meant, otherwise i don't understand why it was how it was

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/ref_statuses.rs (1)

37-44: ⚠️ Potential issue | 🟠 Major

Add an explicit timeout for the blocking ref-statuses HTTP call.

Line 38 performs a blocking network request without a timeout, which could hang indefinitely on network stalls or slow responses, impacting availability.

Use reqwest::blocking::Client::builder() with a timeout() duration:

Suggested fix
use std::collections::BTreeMap;
+use std::time::Duration;

pub(crate) fn fetch_ref_statuses() -> Result<BTreeMap<String, String>, FlakeCheckerError> {
+    let client = reqwest::blocking::Client::builder()
+        .timeout(Duration::from_secs(15))
+        .build()?;
+
-    let officially_supported: BTreeMap<String, String> =
-        reqwest::blocking::get(ALLOWED_REFS_URL)?
+    let officially_supported: BTreeMap<String, String> = client
+            .get(ALLOWED_REFS_URL)
+            .send()?
+            .error_for_status()?
             .json::<Response>()?
             .data
             .result
             .iter()
             .map(|res| (res.metric.channel.clone(), res.metric.status.clone()))
             .collect();
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/ref_statuses.rs` around lines 37 - 44, The reqwest::blocking::get() call
fetching from ALLOWED_REFS_URL has no timeout and could hang indefinitely on
network issues. Replace the direct reqwest::blocking::get() call with a
reqwest::blocking::Client created using Client::builder() with an explicit
timeout duration set via the timeout() method, then use that client's get()
method to make the request. This ensures the HTTP call will fail gracefully
after the specified timeout rather than hanging indefinitely.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/ref_statuses.rs`:
- Around line 37-44: The reqwest::blocking::get() call fetching from
ALLOWED_REFS_URL has no timeout and could hang indefinitely on network issues.
Replace the direct reqwest::blocking::get() call with a
reqwest::blocking::Client created using Client::builder() with an explicit
timeout duration set via the timeout() method, then use that client's get()
method to make the request. This ensures the HTTP call will fail gracefully
after the specified timeout rather than hanging indefinitely.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4ec27130-49c8-4de0-ad9b-76715202cc35

📥 Commits

Reviewing files that changed from the base of the PR and between ec67ebf and 44a9088.

📒 Files selected for processing (6)
  • parse-flake-lock/src/lib.rs
  • src/condition.rs
  • src/flake.rs
  • src/main.rs
  • src/ref_statuses.rs
  • src/summary.rs

@Malix-Labs Malix-Labs marked this pull request as draft June 17, 2026 02:04
@Malix-Labs Malix-Labs marked this pull request as ready for review June 17, 2026 02:11
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.

1 participant