// Step 1974: TaskitemLibraryAnnotator // // t1: annotates JSON serialization task with nlohmann_json // t2: returns unenriched for unknown domain text // t3: returns unenriched when no library scores > 0 for domain // t4: avoidedLibraries populated when runner-up has score > 0 // t5: preferredAPIs populated from ledger record #include "TaskitemLibraryAnnotator.h" #include "Sprint286IntegrationSummary.h" #include "Sprint288IntegrationSummary.h" #include 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::LibraryCapabilityLedger makeLedger() { return ws::Sprint286IntegrationSummary::buildSeedLedger(); } static ws::LibrarySymbolCatalog makeCatalog() { return ws::Sprint288IntegrationSummary::buildSeedCatalog(); } void t1() { T(annotates_json_task_with_nlohmann); auto ledger = makeLedger(); auto catalog = makeCatalog(); ws::TaskitemLibraryAnnotator ann; auto ec = ann.annotate("implement JSON serialization", {"nlohmann_json", "protobuf"}, ledger, catalog); C(ec.isEnriched(), "enriched"); C(ec.selectedLibrary == "nlohmann_json", "nlohmann_json selected"); C(ec.operationDomain == "serialization.json", "domain serialization.json"); C(ec.capabilityScore > 0.0f, "score > 0"); C(ec.taskDescription == "implement JSON serialization", "taskDescription set"); P(); } void t2() { T(unenriched_for_unknown_domain); auto ledger = makeLedger(); auto catalog = makeCatalog(); ws::TaskitemLibraryAnnotator ann; auto ec = ann.annotate("xyzzy frobnicate quantum entanglement", {"nlohmann_json", "protobuf"}, ledger, catalog); C(!ec.isEnriched(), "not enriched for unknown domain"); C(ec.selectedLibrary.empty(), "selectedLibrary empty"); C(ec.taskDescription == "xyzzy frobnicate quantum entanglement", "taskDescription still set"); P(); } void t3() { T(unenriched_when_no_library_scores_above_zero); auto ledger = makeLedger(); auto catalog = makeCatalog(); ws::TaskitemLibraryAnnotator ann; // Use compute.fft domain; neither library has any score in ledger auto ec = ann.annotate("compute FFT transform", {"nlohmann_json", "protobuf"}, ledger, catalog); C(!ec.isEnriched(), "not enriched when no library qualifies"); P(); } void t4() { T(avoided_libraries_populated_for_runner_up); auto ledger = makeLedger(); auto catalog = makeCatalog(); ws::TaskitemLibraryAnnotator ann; // nlohmann_json (0.92) vs protobuf (0.60) for serialization.json auto ec = ann.annotate("JSON serialization task", {"nlohmann_json", "protobuf"}, ledger, catalog); C(ec.isEnriched(), "enriched"); C(!ec.avoidedLibraries.empty(), "avoidedLibraries non-empty"); C(ec.avoidedLibraries[0].name == "protobuf", "protobuf avoided"); P(); } void t5() { T(preferred_apis_populated); auto ledger = makeLedger(); auto catalog = makeCatalog(); ws::TaskitemLibraryAnnotator ann; auto ec = ann.annotate("perform matrix multiply on GPU", {"cublas", "numpy"}, ledger, catalog); C(ec.isEnriched(), "enriched"); C(ec.selectedLibrary == "cublas", "cublas selected"); C(!ec.preferredAPIs.empty(), "preferredAPIs non-empty"); P(); } int main() { std::cout << "Step 1974: TaskitemLibraryAnnotator\n"; t1(); t2(); t3(); t4(); t5(); std::cout << "\n" << p << "/" << (p + f) << " passed\n"; return f > 0 ? 1 : 0; }