Skip to content

Add test for nix_store_build_paths#372

Merged
RossComputerGuy merged 1 commit intomainfrom
RossComputerGuy/capi-build-paths-tests
Feb 26, 2026
Merged

Add test for nix_store_build_paths#372
RossComputerGuy merged 1 commit intomainfrom
RossComputerGuy/capi-build-paths-tests

Conversation

@RossComputerGuy
Copy link
Member

@RossComputerGuy RossComputerGuy commented Feb 26, 2026

Motivation

Adds a test for nix_store_build_paths

Context

In #210, we added nix_store_build_paths. While upstreaming in NixOS#15352, a test was added to ensure this function works.

Summary by CodeRabbit

  • Tests
    • Added test coverage for building derivations with content-addressed storage support, validating JSON derivation loading, creation, storage, and execution with proper output validation.

@github-actions
Copy link

@github-actions github-actions bot temporarily deployed to pull request February 26, 2026 19:08 Inactive
@coderabbitai
Copy link

coderabbitai bot commented Feb 26, 2026

📝 Walkthrough

Walkthrough

A new test case nix_store_build_paths is added to the nix_api_store_test suite to validate derivation creation from JSON, store operations, and output realization with callback-based result capturing and validation.

Changes

Cohort / File(s) Summary
Test Case Addition
src/libstore-tests/nix_api_store.cc
Introduces nix_store_build_paths test that exercises CA derivation JSON parsing, store operations, and derivation realization with output validation via callback.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • edolstra

Poem

🐰 A test hops forth with care so keen,
Building paths through JSON's green,
CA derivations dance in place,
While callbacks catch each output's trace! 🌿

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add test for nix_store_build_paths' directly and specifically describes the main change - adding a test for the nix_store_build_paths function, which aligns perfectly with the changeset that introduces a new test case.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch RossComputerGuy/capi-build-paths-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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/libstore-tests/nix_api_store.cc (1)

958-963: Consider using nix_api_store_test_base fixture instead.

This test uses the nix_api_store_test fixture but then creates its own store via open_local_store(). Other tests in this file that need to configure experimental features before opening a store (e.g., build_from_json at line 352, nix_store_realise_invalid_system at line 399) use nix_api_store_test_base instead.

Using nix_api_store_test_base would be more consistent with the established pattern and avoids shadowing the fixture's store member.

♻️ Suggested change
-TEST_F(nix_api_store_test, nix_store_build_paths)
+TEST_F(nix_api_store_test_base, nix_store_build_paths)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/libstore-tests/nix_api_store.cc` around lines 958 - 963, The test
nix_store_build_paths currently uses the nix_api_store_test fixture but calls
open_local_store() and shadows the fixture's store member; change the test to
use the nix_api_store_test_base fixture (replace TEST_F(nix_api_store_test, ...)
with TEST_F(nix_api_store_test_base, ...)) and remove the manual
open_local_store() call so the test uses the fixture-provided store member,
keeping the existing experimental feature setup
(nix::experimentalFeatureSettings.set(...)) before the store is opened by the
fixture.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/libstore-tests/nix_api_store.cc`:
- Line 979: The assertion after calling nix_add_derivation is checking the wrong
variable (ASSERT_NE(drv, nullptr)); change it to assert the derivation path
pointer returned by nix_add_derivation (ASSERT_NE(drvPath, nullptr)) so the test
verifies drvPath is non-null; update the assertion that references drv to use
drvPath in the test around the nix_add_derivation call.

---

Nitpick comments:
In `@src/libstore-tests/nix_api_store.cc`:
- Around line 958-963: The test nix_store_build_paths currently uses the
nix_api_store_test fixture but calls open_local_store() and shadows the
fixture's store member; change the test to use the nix_api_store_test_base
fixture (replace TEST_F(nix_api_store_test, ...) with
TEST_F(nix_api_store_test_base, ...)) and remove the manual open_local_store()
call so the test uses the fixture-provided store member, keeping the existing
experimental feature setup (nix::experimentalFeatureSettings.set(...)) before
the store is opened by the fixture.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d1c3725 and 44a2f03.

📒 Files selected for processing (1)
  • src/libstore-tests/nix_api_store.cc


auto * drvPath = nix_add_derivation(ctx, store, drv);
assert_ctx_ok();
ASSERT_NE(drv, nullptr);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Bug: Wrong variable checked in assertion.

After nix_add_derivation, the assertion checks drv instead of drvPath. This appears to be a copy-paste error from line 975.

🐛 Proposed fix
     auto * drvPath = nix_add_derivation(ctx, store, drv);
     assert_ctx_ok();
-    ASSERT_NE(drv, nullptr);
+    ASSERT_NE(drvPath, nullptr);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ASSERT_NE(drv, nullptr);
auto * drvPath = nix_add_derivation(ctx, store, drv);
assert_ctx_ok();
ASSERT_NE(drvPath, nullptr);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/libstore-tests/nix_api_store.cc` at line 979, The assertion after calling
nix_add_derivation is checking the wrong variable (ASSERT_NE(drv, nullptr));
change it to assert the derivation path pointer returned by nix_add_derivation
(ASSERT_NE(drvPath, nullptr)) so the test verifies drvPath is non-null; update
the assertion that references drv to use drvPath in the test around the
nix_add_derivation call.

@RossComputerGuy RossComputerGuy added this pull request to the merge queue Feb 26, 2026
Merged via the queue into main with commit 908be63 Feb 26, 2026
28 checks passed
@RossComputerGuy RossComputerGuy deleted the RossComputerGuy/capi-build-paths-tests branch February 26, 2026 19:53
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