Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
eba3bcc
claude: Add dual-path conformance testing (basic/non_basic mode)
Liam-DeVoe Apr 11, 2026
fb434ee
claude: Simplify list conformance test to report raw elements
Liam-DeVoe Apr 11, 2026
488e6e9
claude: Remove mode support from scalar conformance binaries
Liam-DeVoe Apr 11, 2026
fe271a0
Merge remote-tracking branch 'origin/main' into add-dual-path-conform…
Liam-DeVoe Apr 14, 2026
8bbaea6
claude: bump hegel-core to 0.4.1 for dual-path conformance
Liam-DeVoe Apr 14, 2026
cbfeb49
claude: fix vectors/dictionaries fallback uniqueness
Liam-DeVoe Apr 14, 2026
2f82900
Merge remote-tracking branch 'origin/main' into add-dual-path-conform…
Liam-DeVoe Apr 16, 2026
4985922
claude: merge main, resolve conformance conflicts
Liam-DeVoe Apr 16, 2026
1f02ea0
claude: merge main, adapt uniqueness to TestCase API
Liam-DeVoe Apr 16, 2026
4f9e558
claude: merge main, resolve RELEASE.md conflict
Liam-DeVoe Apr 16, 2026
8c9ff54
Merge remote-tracking branch 'origin/main' into add-dual-path-conform…
Liam-DeVoe Apr 17, 2026
3a24196
claude: merge main, adapt uniqueness and conformance to new generator…
Liam-DeVoe Apr 20, 2026
77e8c97
Merge remote-tracking branch 'origin/main' into add-dual-path-conform…
Liam-DeVoe Apr 20, 2026
452ad55
claude: merge main, adapt new tests to renamed API
Liam-DeVoe Apr 20, 2026
7842c5c
claude: merge main, resolve HealthCheck namespace conflict
Liam-DeVoe Apr 20, 2026
d8f7838
Merge remote-tracking branch 'origin/main' into add-dual-path-conform…
Liam-DeVoe Apr 20, 2026
505b21a
claude: merge main, keep RELEASE.md for vectors/maps fallback fix
Liam-DeVoe Apr 20, 2026
5681f5c
Merge remote-tracking branch 'origin/main' into add-dual-path-conform…
Liam-DeVoe Apr 20, 2026
4d8edff
Merge remote-tracking branch 'origin/main' into add-dual-path-conform…
Liam-DeVoe Apr 20, 2026
76805aa
claude: merge main, combine RELEASE.md entries
Liam-DeVoe Apr 20, 2026
db30de8
claude: merge main, drop released docs entry from RELEASE.md
Liam-DeVoe Apr 20, 2026
97df10a
Merge remote-tracking branch 'origin/main' into add-dual-path-conform…
Liam-DeVoe Apr 20, 2026
04eea24
Merge remote-tracking branch 'origin/main' into add-dual-path-conform…
Liam-DeVoe Apr 21, 2026
0b84cef
Merge remote-tracking branch 'origin/main' into add-dual-path-conform…
Liam-DeVoe Apr 23, 2026
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ jobs:
python-version: '3.13'

- name: Install hegel
run: pip install hegel-core==0.4.0
run: pip install hegel-core==0.4.1

- name: Run conformance tests
timeout-minutes: 10
Expand Down
10 changes: 10 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
RELEASE_TYPE: patch

Fix the compositional fallback path of `vectors` and `maps` to
correctly honor uniqueness when element/key generators lack a schema.
Previously the fallback for `vectors({.unique = true})` produced a
potentially non-unique vector, and `maps` could loop for an
unbounded number of attempts when the key generator repeatedly returned
duplicates. Both now cap attempts and reject the test case via
`tc.assume()` when the generator cannot satisfy the requested size with
unique values.
37 changes: 35 additions & 2 deletions include/hegel/generators/collections.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#pragma once

#include <algorithm>
#include <map>
#include <set>
#include <tuple>
#include <vector>

#include "hegel/core.h"
#include "hegel/generators/numeric.h"
#include "hegel/internal.h"

namespace hegel::generators {

Expand Down Expand Up @@ -94,6 +96,27 @@ namespace hegel::generators {
size_t len = length_gen.do_draw(tc);
std::vector<T> result;
result.reserve(len);

if constexpr (requires(T a, T b) { a == b; }) {
if (params_.unique) {
size_t max_attempts = len * 10 + 10;
for (size_t attempts = 0;
result.size() < len && attempts < max_attempts;
++attempts) {
T elem = elements_.do_draw(tc);
if (std::find(result.begin(), result.end(), elem) ==
result.end()) {
result.push_back(std::move(elem));
}
}
// If the element generator can't produce enough unique
// values (e.g. it's heavily constrained), reject this
// test case rather than returning a short vector.
tc.assume(result.size() == len);
return result;
}
}

for (size_t i = 0; i < len; ++i) {
result.push_back(elements_.do_draw(tc));
}
Expand Down Expand Up @@ -220,11 +243,21 @@ namespace hegel::generators {
{.min_value = params_.min_size, .max_value = max_size});
size_t len = length_gen.do_draw(tc);
std::map<K, V> result;
while (result.size() < len) {

size_t max_attempts = len * 10 + 10;
for (size_t attempts = 0;
result.size() < len && attempts < max_attempts; ++attempts) {
K key = keys_.do_draw(tc);
if (result.find(key) != result.end()) {
continue;
}
V value = values_.do_draw(tc);
result[std::move(key)] = std::move(value);
result.emplace(std::move(key), std::move(value));
}
// If the key generator can't produce enough unique keys
// (e.g. it's heavily constrained), reject this test case
// rather than returning a smaller map.
tc.assume(result.size() == len);
return result;
}

Expand Down
16 changes: 16 additions & 0 deletions tests/conformance/cpp/metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <cstdlib>
#include <fstream>
#include <hegel/hegel.h>
#include <hegel/json.h>
#include <nlohmann/json.hpp>
#include <string>
Expand Down Expand Up @@ -36,4 +37,19 @@ namespace conformance {
}
}

// Wrap a generator in a trivial filter so it loses its schema,
// forcing the compositional fallback path.
template <typename T>
hegel::generators::Generator<T>
make_non_basic(hegel::generators::Generator<T> gen) {
return gen.filter([](const T&) { return true; });
}

inline std::string get_mode(const nlohmann::json& args) {
if (args.contains("mode") && args["mode"].is_string()) {
return args["mode"].get<std::string>();
}
return "basic";
}

} // namespace conformance
31 changes: 20 additions & 11 deletions tests/conformance/cpp/test_hashmaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,24 @@ int main(int argc, char* argv[]) {
int max_key = args["max_key"].get<int>();
int min_value = args["min_value"].get<int>();
int max_value = args["max_value"].get<int>();
std::string mode = conformance::get_mode(args);
int test_cases = conformance::get_test_cases();

hegel::test(
[=](hegel::TestCase& tc) {
nlohmann::json metrics;

if (key_type == "integer") {
auto gen =
gs::maps(gs::integers<int>(
{.min_value = min_key, .max_value = max_key}),
gs::integers<int>({.min_value = min_value,
.max_value = max_value}),
{.min_size = min_size, .max_size = max_size});
auto key_gen = gs::integers<int>(
{.min_value = min_key, .max_value = max_key});
auto val_gen = gs::integers<int>(
{.min_value = min_value, .max_value = max_value});
auto gen = gs::maps(
mode == "non_basic" ? conformance::make_non_basic(key_gen)
: key_gen,
mode == "non_basic" ? conformance::make_non_basic(val_gen)
: val_gen,
{.min_size = min_size, .max_size = max_size});

auto dict = tc.draw(gen);

Expand All @@ -61,11 +66,15 @@ int main(int argc, char* argv[]) {
}
} else {
// string keys
auto gen =
gs::maps(gs::text(),
gs::integers<int>({.min_value = min_value,
.max_value = max_value}),
{.min_size = min_size, .max_size = max_size});
auto text_gen = gs::text();
auto val_gen = gs::integers<int>(
{.min_value = min_value, .max_value = max_value});
auto gen = gs::maps(
mode == "non_basic" ? conformance::make_non_basic(text_gen)
: text_gen,
mode == "non_basic" ? conformance::make_non_basic(val_gen)
: val_gen,
{.min_size = min_size, .max_size = max_size});

auto dict = tc.draw(gen);

Expand Down
23 changes: 9 additions & 14 deletions tests/conformance/cpp/test_lists.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <algorithm>
#include <hegel/json.h>
#include <iostream>
#include <optional>
Expand Down Expand Up @@ -30,25 +29,21 @@ int main(int argc, char* argv[]) {
args["max_value"].is_null()
? std::nullopt
: std::optional<int>(args["max_value"].get<int>());
bool unique = args["unique"].get<bool>();
std::string mode = conformance::get_mode(args);
int test_cases = conformance::get_test_cases();

hegel::test(
[=](hegel::TestCase& tc) {
auto gen =
gs::vectors(gs::integers<int>({.min_value = min_value,
.max_value = max_value}),
{.min_size = min_size, .max_size = max_size});
auto elem_gen = gs::integers<int>(
{.min_value = min_value, .max_value = max_value});
auto gen = gs::vectors(
mode == "non_basic" ? conformance::make_non_basic(elem_gen)
: elem_gen,
{.min_size = min_size, .max_size = max_size, .unique = unique});

auto vec = tc.draw(gen);

nlohmann::json metrics = {{"size", vec.size()}};
if (!vec.empty()) {
metrics["min_element"] =
*std::min_element(vec.begin(), vec.end());
metrics["max_element"] =
*std::max_element(vec.begin(), vec.end());
}
conformance::write_metrics(metrics);
conformance::write_metrics({{"elements", vec}});
},
{.test_cases = test_cases});

Expand Down
Loading