Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/libstore-tests/nix_api_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -955,4 +955,55 @@ TEST_F(nix_api_store_test, nix_derivation_clone)
nix_derivation_free(drv2);
}

TEST_F(nix_api_store_test, nix_store_build_paths)
{
nix::experimentalFeatureSettings.set("extra-experimental-features", "ca-derivations");
nix::settings.substituters = {};

auto * store = open_local_store();

std::filesystem::path unitTestData{getenv("_NIX_TEST_UNIT_DATA")};
std::ifstream t{unitTestData / "derivation/ca/self-contained.json"};
std::stringstream buffer;
buffer << t.rdbuf();

// Replace the hardcoded system with the current system
std::string jsonStr = nix::replaceStrings(buffer.str(), "x86_64-linux", nix::settings.thisSystem.get());

auto * drv = nix_derivation_from_json(ctx, store, jsonStr.c_str());
assert_ctx_ok();
ASSERT_NE(drv, nullptr);

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

Copy link
Copy Markdown

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.


// Realise the derivation - capture the order outputs are returned
std::map<std::string, std::string> outputs;
std::vector<std::string> output_order;
auto cb = LambdaAdapter{.fun = [&](const char * path, const char * result) {
ASSERT_NE(path, nullptr);
ASSERT_NE(result, nullptr);
output_order.push_back(path);
outputs.emplace(path, result);
}};

std::vector<StorePath *> paths = {drvPath};

auto ret = nix_store_build_paths(
ctx,
store,
const_cast<const StorePath **>(paths.data()),
paths.size(),
decltype(cb)::call_void<const char *, const char *>,
static_cast<void *>(&cb));
assert_ctx_ok();
ASSERT_EQ(ret, NIX_OK);
ASSERT_EQ(outputs.size(), 1);

nix_store_path_free(drvPath);
nix_derivation_free(drv);
nix_store_free(store);
}

} // namespace nixC