Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RELEASE_TYPE: patch

Add support for @reproduce_failure and print blob.
1 change: 1 addition & 0 deletions include/hegel/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace hegel::internal::json {
bool is_array() const noexcept;
bool is_object() const noexcept;

json_raw_ref& operator=(const std::string& other);
json_raw_ref& operator=(const size_t& other);
json_raw_ref& operator=(const double& other);
json_raw_ref& operator=(const std::nullptr_t& other);
Expand Down
4 changes: 4 additions & 0 deletions include/hegel/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,9 @@ namespace hegel::options {
std::optional<std::string> hegel_path;

std::optional<uint64_t> seed;

std::optional<std::string> failure_blob;

bool print_blob;
};
} // namespace hegel::options
32 changes: 16 additions & 16 deletions nix/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion nix/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";
hegel.url = "git+https://github.com/hegeldev/hegel-core.git";
hegel.url = "git+https://github.com/hegeldev/hegel-core.git?dir=nix";
};

outputs =
Expand Down Expand Up @@ -126,6 +126,8 @@
inputsFrom = [ self.packages.${system}.default ];
packages = [
pkgs.clang-tools
pkgs.uv
pkgs.just
];
};
}
Expand Down
36 changes: 36 additions & 0 deletions src/hegel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <cstdlib>
#include <cstring>
#include <exception>
#include <optional>
#include <string>
#include <vector>

Expand Down Expand Up @@ -116,10 +117,20 @@ namespace hegel {
} else {
run_test_msg["seed"] = nullptr;
}

if (options.failure_blob.has_value()) {
run_test_msg["failure_blob"] = options.failure_blob.value();
} else {
run_test_msg["failure_blob"] = nullptr;
}

conn.request(0, run_test_msg);

// Event loop on test channel
bool test_passed = true;
std::vector<std::string> failure_blobs;
std::string health_check_msg;
std::string flaky_test_msg;
int final_replays_remaining = 0;
bool done = false;
while (!done) {
Expand Down Expand Up @@ -194,8 +205,18 @@ namespace hegel {
if (payload.contains("results")) {
auto& results = ImplUtil::raw(payload["results"]);
test_passed = results.value("passed", true);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

actually i think we should save results and then when we break out of the loop process all the different fields?

health_check_msg =
results.value("health_check_failure", "");
flaky_test_msg = results.value("flaky", "");
final_replays_remaining =
results.value("interesting_test_cases", 0);
for (const auto& blob : results["failure_blobs"]) {
auto byte_sequence = blob.get_binary();
std::string failure_blob_string(
reinterpret_cast<const char*>(byte_sequence.data()),
byte_sequence.size());
failure_blobs.push_back(failure_blob_string);
}
}
if (final_replays_remaining <= 0) {
done = true;
Expand All @@ -210,6 +231,21 @@ namespace hegel {
waitpid(child_pid, &status, 0);
std::filesystem::remove_all(temp_dir);

if (test_passed && options.failure_blob.has_value()) {
throw std::runtime_error("Failure blob did not cause a failure");
}
if (options.print_blob && !failure_blobs.empty()) {
std::cerr << "Failure blobs for reproduction:\n";
for (const auto& blob : failure_blobs) {
std::cerr << blob << "\n";
}
}
if (health_check_msg.length() > 0) {
std::cerr << health_check_msg << "\n";
}
if (flaky_test_msg.length() > 0) {
std::cerr << flaky_test_msg << "\n";
}
if (!test_passed) {
throw std::runtime_error("Hegel test failed");
}
Expand Down
4 changes: 4 additions & 0 deletions src/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ namespace hegel::internal::json {

size_t json_raw_ref::size() const noexcept { return ref->data.size(); }

json_raw_ref& json_raw_ref::operator=(const std::string& other) {
ref->data = other;
return *this;
}
json_raw_ref& json_raw_ref::operator=(const size_t& other) {
ref->data = other;
return *this;
Expand Down
Loading