Add step 611 on-call coverage planner
This commit is contained in:
@@ -4378,4 +4378,13 @@ target_link_libraries(step610_test PRIVATE
|
||||
tree_sitter_javascript tree_sitter_typescript
|
||||
tree_sitter_java tree_sitter_rust tree_sitter_go)
|
||||
|
||||
add_executable(step611_test tests/step611_test.cpp)
|
||||
target_include_directories(step611_test PRIVATE src)
|
||||
target_link_libraries(step611_test PRIVATE
|
||||
nlohmann_json::nlohmann_json
|
||||
unofficial::tree-sitter::tree-sitter
|
||||
tree_sitter_python tree_sitter_cpp tree_sitter_elisp
|
||||
tree_sitter_javascript tree_sitter_typescript
|
||||
tree_sitter_java tree_sitter_rust tree_sitter_go)
|
||||
|
||||
# Step 12: Dear ImGui shell scaffolding created (main.cpp exists but not built due to dependencies)
|
||||
|
||||
78
editor/src/OnCallCoveragePlanner.h
Normal file
78
editor/src/OnCallCoveragePlanner.h
Normal file
@@ -0,0 +1,78 @@
|
||||
#pragma once
|
||||
// Step 611: On-Call Coverage Planner
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "ValidationErrorUtil.h"
|
||||
|
||||
struct OnCallShift {
|
||||
std::string shiftId;
|
||||
std::string serviceId;
|
||||
std::string primaryEngineer;
|
||||
std::string secondaryEngineer;
|
||||
int startHour = 0;
|
||||
int endHour = 0;
|
||||
};
|
||||
|
||||
class OnCallCoveragePlanner {
|
||||
public:
|
||||
bool addShift(const OnCallShift& shift, std::string* error) {
|
||||
if (!error) return false;
|
||||
error->clear();
|
||||
if (shift.shiftId.empty()) return failWith(error, "shift_id_missing");
|
||||
if (shift.serviceId.empty()) return failWith(error, "service_id_missing");
|
||||
if (shift.primaryEngineer.empty()) return failWith(error, "primary_missing");
|
||||
if (shift.secondaryEngineer.empty()) return failWith(error, "secondary_missing");
|
||||
if (shift.startHour < 0 || shift.startHour > 23) return failWith(error, "start_hour_invalid");
|
||||
if (shift.endHour < 0 || shift.endHour > 24) return failWith(error, "end_hour_invalid");
|
||||
if (shift.endHour <= shift.startHour) return failWith(error, "shift_range_invalid");
|
||||
if (shifts_.count(shift.shiftId) != 0) return failWith(error, "shift_duplicate");
|
||||
shifts_[shift.shiftId] = shift;
|
||||
order_.push_back(shift.shiftId);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool covered(const std::string& serviceId, int hour, std::string* error) const {
|
||||
if (!error) return false;
|
||||
error->clear();
|
||||
if (serviceId.empty()) return failWith(error, "service_id_missing");
|
||||
if (hour < 0 || hour > 23) return failWith(error, "hour_invalid");
|
||||
for (const auto& id : order_) {
|
||||
const auto& s = shifts_.at(id);
|
||||
if (s.serviceId == serviceId && hour >= s.startHour && hour < s.endHour) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int shiftCount(const std::string& serviceId) const {
|
||||
int count = 0;
|
||||
for (const auto& id : order_) {
|
||||
const auto& s = shifts_.at(id);
|
||||
if (serviceId.empty() || s.serviceId == serviceId) ++count;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
int coverageGaps(const std::string& serviceId) const {
|
||||
if (serviceId.empty()) return 24;
|
||||
int gaps = 0;
|
||||
for (int h = 0; h < 24; ++h) {
|
||||
bool any = false;
|
||||
for (const auto& id : order_) {
|
||||
const auto& s = shifts_.at(id);
|
||||
if (s.serviceId == serviceId && h >= s.startHour && h < s.endHour) {
|
||||
any = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!any) ++gaps;
|
||||
}
|
||||
return gaps;
|
||||
}
|
||||
|
||||
private:
|
||||
std::map<std::string, OnCallShift> shifts_;
|
||||
std::vector<std::string> order_;
|
||||
};
|
||||
147
editor/tests/step611_test.cpp
Normal file
147
editor/tests/step611_test.cpp
Normal file
@@ -0,0 +1,147 @@
|
||||
// Step 611: On-Call Coverage Planner (12 tests)
|
||||
|
||||
#include "OnCallCoveragePlanner.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
static int passed = 0, failed = 0;
|
||||
#define TEST(name) { std::cout << " " << #name << "... "; }
|
||||
#define PASS() { std::cout << "PASS\n"; ++passed; }
|
||||
#define FAIL(msg) { std::cout << "FAIL: " << msg << "\n"; ++failed; }
|
||||
#define CHECK(cond, msg) if (!(cond)) { FAIL(msg); return; } else {}
|
||||
|
||||
static OnCallShift shift(const std::string& id,
|
||||
const std::string& svc,
|
||||
int start,
|
||||
int end) {
|
||||
return {id, svc, "alice", "bob", start, end};
|
||||
}
|
||||
|
||||
void test_add_shift_success() {
|
||||
TEST(add_shift_success);
|
||||
OnCallCoveragePlanner planner;
|
||||
std::string error;
|
||||
CHECK(planner.addShift(shift("s1", "svc-a", 0, 8), &error), "add should succeed");
|
||||
CHECK(planner.shiftCount("svc-a") == 1, "shift count mismatch");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_add_shift_rejects_missing_shift_id() {
|
||||
TEST(add_shift_rejects_missing_shift_id);
|
||||
OnCallCoveragePlanner planner;
|
||||
std::string error;
|
||||
CHECK(!planner.addShift(shift("", "svc-a", 0, 8), &error), "add should fail");
|
||||
CHECK(error == "shift_id_missing", "wrong error");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_add_shift_rejects_missing_service_id() {
|
||||
TEST(add_shift_rejects_missing_service_id);
|
||||
OnCallCoveragePlanner planner;
|
||||
std::string error;
|
||||
CHECK(!planner.addShift(shift("s1", "", 0, 8), &error), "add should fail");
|
||||
CHECK(error == "service_id_missing", "wrong error");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_add_shift_rejects_invalid_range() {
|
||||
TEST(add_shift_rejects_invalid_range);
|
||||
OnCallCoveragePlanner planner;
|
||||
std::string error;
|
||||
CHECK(!planner.addShift(shift("s1", "svc-a", 8, 8), &error), "add should fail");
|
||||
CHECK(error == "shift_range_invalid", "wrong error");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_add_shift_rejects_duplicate() {
|
||||
TEST(add_shift_rejects_duplicate);
|
||||
OnCallCoveragePlanner planner;
|
||||
std::string error;
|
||||
CHECK(planner.addShift(shift("s1", "svc-a", 0, 8), &error), "first add failed");
|
||||
CHECK(!planner.addShift(shift("s1", "svc-a", 8, 16), &error), "duplicate should fail");
|
||||
CHECK(error == "shift_duplicate", "wrong error");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_covered_true_within_shift() {
|
||||
TEST(covered_true_within_shift);
|
||||
OnCallCoveragePlanner planner;
|
||||
std::string error;
|
||||
CHECK(planner.addShift(shift("s1", "svc-a", 0, 8), &error), "add failed");
|
||||
CHECK(planner.covered("svc-a", 4, &error), "should be covered");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_covered_false_outside_shift() {
|
||||
TEST(covered_false_outside_shift);
|
||||
OnCallCoveragePlanner planner;
|
||||
std::string error;
|
||||
CHECK(planner.addShift(shift("s1", "svc-a", 0, 8), &error), "add failed");
|
||||
CHECK(!planner.covered("svc-a", 9, &error), "should not be covered");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_covered_rejects_invalid_hour() {
|
||||
TEST(covered_rejects_invalid_hour);
|
||||
OnCallCoveragePlanner planner;
|
||||
std::string error;
|
||||
CHECK(!planner.covered("svc-a", 24, &error), "query should fail");
|
||||
CHECK(error == "hour_invalid", "wrong error");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_shift_count_empty_returns_all() {
|
||||
TEST(shift_count_empty_returns_all);
|
||||
OnCallCoveragePlanner planner;
|
||||
std::string error;
|
||||
CHECK(planner.addShift(shift("s1", "svc-a", 0, 8), &error), "add s1 failed");
|
||||
CHECK(planner.addShift(shift("s2", "svc-b", 0, 8), &error), "add s2 failed");
|
||||
CHECK(planner.shiftCount("") == 2, "all shift count mismatch");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_coverage_gaps_full_day_zero() {
|
||||
TEST(coverage_gaps_full_day_zero);
|
||||
OnCallCoveragePlanner planner;
|
||||
std::string error;
|
||||
CHECK(planner.addShift(shift("s1", "svc-a", 0, 12), &error), "add s1 failed");
|
||||
CHECK(planner.addShift(shift("s2", "svc-a", 12, 24), &error), "add s2 failed");
|
||||
CHECK(planner.coverageGaps("svc-a") == 0, "gaps should be zero");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_coverage_gaps_partial_day() {
|
||||
TEST(coverage_gaps_partial_day);
|
||||
OnCallCoveragePlanner planner;
|
||||
std::string error;
|
||||
CHECK(planner.addShift(shift("s1", "svc-a", 8, 16), &error), "add failed");
|
||||
CHECK(planner.coverageGaps("svc-a") == 16, "gap count mismatch");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_coverage_gaps_unknown_service_full_day() {
|
||||
TEST(coverage_gaps_unknown_service_full_day);
|
||||
OnCallCoveragePlanner planner;
|
||||
CHECK(planner.coverageGaps("missing") == 24, "unknown service should have full-day gaps");
|
||||
PASS();
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::cout << "Step 611: On-Call Coverage Planner\n";
|
||||
|
||||
test_add_shift_success(); // 1
|
||||
test_add_shift_rejects_missing_shift_id(); // 2
|
||||
test_add_shift_rejects_missing_service_id();// 3
|
||||
test_add_shift_rejects_invalid_range(); // 4
|
||||
test_add_shift_rejects_duplicate(); // 5
|
||||
test_covered_true_within_shift(); // 6
|
||||
test_covered_false_outside_shift(); // 7
|
||||
test_covered_rejects_invalid_hour(); // 8
|
||||
test_shift_count_empty_returns_all(); // 9
|
||||
test_coverage_gaps_full_day_zero(); // 10
|
||||
test_coverage_gaps_partial_day(); // 11
|
||||
test_coverage_gaps_unknown_service_full_day();// 12
|
||||
|
||||
std::cout << "\nResults: " << passed << "/" << (passed + failed) << " passed\n";
|
||||
return failed == 0 ? 0 : 1;
|
||||
}
|
||||
30
progress.md
30
progress.md
@@ -11920,3 +11920,33 @@ inbound/outbound rollups.
|
||||
- `editor/src/ServiceDependencyRiskMap.h` within header-size limit (`78` <= `600`)
|
||||
- `editor/tests/step610_test.cpp` within test-file size guidance (`154` lines)
|
||||
- Header-only architecture and naming conventions remain aligned with `ARCHITECTURE.md`
|
||||
|
||||
### Step 611: On-Call Coverage Planner
|
||||
**Status:** PASS (12/12 tests)
|
||||
|
||||
Implements on-call shift planning with coverage checks and service gap
|
||||
calculation.
|
||||
|
||||
**Files added:**
|
||||
- `editor/src/OnCallCoveragePlanner.h` - on-call coverage module:
|
||||
- shift registration with validation/duplicate guards
|
||||
- hour-based coverage checks by service
|
||||
- shift counting and daily coverage-gap calculation
|
||||
- `editor/tests/step611_test.cpp` - 12 tests covering:
|
||||
- shift add success/failure behavior
|
||||
- coverage query behavior and invalid input handling
|
||||
- aggregate count and coverage-gap behavior
|
||||
|
||||
**Files modified:**
|
||||
- `editor/CMakeLists.txt` - `step611_test` target
|
||||
|
||||
**Verification run:**
|
||||
- `cmake -S editor -B editor/build-native` - PASS
|
||||
- `cmake --build editor/build-native --target step611_test step610_test` - PASS
|
||||
- `./editor/build-native/step611_test` - PASS (12/12)
|
||||
- `./editor/build-native/step610_test` - PASS (12/12) regression coverage
|
||||
|
||||
**Architecture gate check:**
|
||||
- `editor/src/OnCallCoveragePlanner.h` within header-size limit (`78` <= `600`)
|
||||
- `editor/tests/step611_test.cpp` within test-file size guidance (`147` lines)
|
||||
- Header-only architecture and naming conventions remain aligned with `ARCHITECTURE.md`
|
||||
|
||||
Reference in New Issue
Block a user