Files
whetstone_DSL/editor/tests/step1975_test.cpp
Bill 03dc4dc208 Sprint 289: Integration into generate_taskitems (steps 1973-1977)
EnrichedExecutionContract, TaskitemLibraryAnnotator, AnnotatedTaskitemValidator,
DispatchJustificationReport, Sprint289IntegrationSummary. 25/25 tests passing.
Full pipeline: spec -> classifier -> selector -> advisor -> enriched contracts.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-02 10:21:06 -07:00

117 lines
3.9 KiB
C++

// Step 1975: AnnotatedTaskitemValidator
//
// t1: all enriched contracts, required=true -> all pass
// t2: unenriched contract, required=true -> fails with taskDescription in error
// t3: unenriched contract, required=false -> passes
// t4: enriched contract with capabilityScore > 1 -> fails
// t5: empty contracts vector -> 0 pass, 0 fail
#include "AnnotatedTaskitemValidator.h"
#include <iostream>
#include <algorithm>
namespace ws = whetstone;
static int p = 0, f = 0;
#define T(n) { std::cout << " " << #n << "... "; }
#define P() { std::cout << "PASS\n"; ++p; }
#define F(m) { std::cout << "FAIL: " << m << "\n"; ++f; }
#define C(c, m) if (!(c)) { F(m); return; }
static ws::EnrichedExecutionContract makeEnriched(const std::string& task,
const std::string& lib,
const std::string& domain,
float score) {
ws::EnrichedExecutionContract ec;
ec.taskDescription = task;
ec.selectedLibrary = lib;
ec.operationDomain = domain;
ec.capabilityScore = score;
return ec;
}
static ws::EnrichedExecutionContract makeUnenriched(const std::string& task) {
ws::EnrichedExecutionContract ec;
ec.taskDescription = task;
return ec;
}
void t1() {
T(all_enriched_required_true_all_pass);
ws::AnnotatedTaskitemValidator v;
std::vector<ws::EnrichedExecutionContract> contracts = {
makeEnriched("task A", "nlohmann_json", "serialization.json", 0.92f),
makeEnriched("task B", "cublas", "compute.matrix", 0.99f),
};
auto report = v.validate(contracts, true);
C(report.passCount == 2, "2 pass");
C(report.failCount == 0, "0 fail");
C(report.allPassed(), "allPassed");
P();
}
void t2() {
T(unenriched_required_true_fails_with_taskdesc);
ws::AnnotatedTaskitemValidator v;
std::vector<ws::EnrichedExecutionContract> contracts = {
makeEnriched("enriched task", "cublas", "compute.matrix", 0.99f),
makeUnenriched("unenriched task"),
};
auto report = v.validate(contracts, true);
C(report.passCount == 1, "1 pass");
C(report.failCount == 1, "1 fail");
C(!report.errors.empty(), "errors non-empty");
// Error must include taskDescription
bool found = false;
for (const auto& e : report.errors) {
if (e.find("unenriched task") != std::string::npos) found = true;
}
C(found, "error contains taskDescription");
P();
}
void t3() {
T(unenriched_required_false_passes);
ws::AnnotatedTaskitemValidator v;
std::vector<ws::EnrichedExecutionContract> contracts = {
makeUnenriched("unnamed work"),
makeEnriched("known task", "thrust", "compute.parallel", 0.97f),
};
auto report = v.validate(contracts, false);
C(report.passCount == 2, "2 pass");
C(report.failCount == 0, "0 fail");
C(report.allPassed(), "allPassed");
P();
}
void t4() {
T(enriched_bad_capability_score_fails);
ws::AnnotatedTaskitemValidator v;
ws::EnrichedExecutionContract bad = makeEnriched("bad task", "lib", "domain", 1.5f);
auto report = v.validate({bad}, true);
C(report.failCount == 1, "1 fail");
C(!report.errors.empty(), "errors non-empty");
bool found = false;
for (const auto& e : report.errors) {
if (e.find("bad task") != std::string::npos) found = true;
}
C(found, "error mentions bad task");
P();
}
void t5() {
T(empty_contracts_zero_counts);
ws::AnnotatedTaskitemValidator v;
auto report = v.validate({}, true);
C(report.passCount == 0, "0 pass");
C(report.failCount == 0, "0 fail");
C(report.allPassed(), "allPassed on empty");
P();
}
int main() {
std::cout << "Step 1975: AnnotatedTaskitemValidator\n";
t1(); t2(); t3(); t4(); t5();
std::cout << "\n" << p << "/" << (p + f) << " passed\n";
return f > 0 ? 1 : 0;
}