Add step 609 change freeze calendar

This commit is contained in:
Bill
2026-02-17 12:05:01 -07:00
parent fba186f4fc
commit 7091176103
4 changed files with 255 additions and 0 deletions

View File

@@ -4360,4 +4360,13 @@ target_link_libraries(step608_test PRIVATE
tree_sitter_javascript tree_sitter_typescript
tree_sitter_java tree_sitter_rust tree_sitter_go)
add_executable(step609_test tests/step609_test.cpp)
target_include_directories(step609_test PRIVATE src)
target_link_libraries(step609_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)

View File

@@ -0,0 +1,67 @@
#pragma once
// Step 609: Change Freeze Calendar
#include <map>
#include <string>
#include <vector>
#include "ValidationErrorUtil.h"
struct FreezeWindow {
std::string windowId;
std::string environmentId;
int startDay = 0;
int endDay = 0;
std::string reason;
};
class ChangeFreezeCalendar {
public:
bool addWindow(const FreezeWindow& window, std::string* error) {
if (!error) return false;
error->clear();
if (window.windowId.empty()) return failWith(error, "window_id_missing");
if (window.environmentId.empty()) return failWith(error, "environment_id_missing");
if (window.startDay < 0) return failWith(error, "start_day_invalid");
if (window.endDay < 0) return failWith(error, "end_day_invalid");
if (window.endDay < window.startDay) return failWith(error, "window_range_invalid");
if (window.reason.empty()) return failWith(error, "reason_missing");
if (windows_.count(window.windowId) != 0) return failWith(error, "window_duplicate");
windows_[window.windowId] = window;
order_.push_back(window.windowId);
return true;
}
bool frozen(const std::string& environmentId, int day, std::string* error) const {
if (!error) return false;
error->clear();
if (environmentId.empty()) return failWith(error, "environment_id_missing");
if (day < 0) return failWith(error, "day_invalid");
for (const auto& id : order_) {
const auto& w = windows_.at(id);
if (w.environmentId == environmentId && day >= w.startDay && day <= w.endDay) return true;
}
return false;
}
int windowCount(const std::string& environmentId) const {
int count = 0;
for (const auto& id : order_) {
if (environmentId.empty() || windows_.at(id).environmentId == environmentId) ++count;
}
return count;
}
std::vector<FreezeWindow> activeOnDay(int day) const {
std::vector<FreezeWindow> out;
for (const auto& id : order_) {
const auto& w = windows_.at(id);
if (day >= w.startDay && day <= w.endDay) out.push_back(w);
}
return out;
}
private:
std::map<std::string, FreezeWindow> windows_;
std::vector<std::string> order_;
};

View File

@@ -0,0 +1,149 @@
// Step 609: Change Freeze Calendar (12 tests)
#include "ChangeFreezeCalendar.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 FreezeWindow window(const std::string& id,
const std::string& env,
int startDay,
int endDay) {
return {id, env, startDay, endDay, "release_freeze"};
}
void test_add_window_success() {
TEST(add_window_success);
ChangeFreezeCalendar cal;
std::string error;
CHECK(cal.addWindow(window("w1", "prod", 10, 12), &error), "add should succeed");
CHECK(cal.windowCount("prod") == 1, "count mismatch");
PASS();
}
void test_add_window_rejects_missing_window_id() {
TEST(add_window_rejects_missing_window_id);
ChangeFreezeCalendar cal;
std::string error;
CHECK(!cal.addWindow(window("", "prod", 10, 12), &error), "add should fail");
CHECK(error == "window_id_missing", "wrong error");
PASS();
}
void test_add_window_rejects_missing_environment_id() {
TEST(add_window_rejects_missing_environment_id);
ChangeFreezeCalendar cal;
std::string error;
CHECK(!cal.addWindow(window("w1", "", 10, 12), &error), "add should fail");
CHECK(error == "environment_id_missing", "wrong error");
PASS();
}
void test_add_window_rejects_invalid_range() {
TEST(add_window_rejects_invalid_range);
ChangeFreezeCalendar cal;
std::string error;
CHECK(!cal.addWindow(window("w1", "prod", 12, 10), &error), "add should fail");
CHECK(error == "window_range_invalid", "wrong error");
PASS();
}
void test_add_window_rejects_duplicate() {
TEST(add_window_rejects_duplicate);
ChangeFreezeCalendar cal;
std::string error;
CHECK(cal.addWindow(window("w1", "prod", 10, 12), &error), "first add failed");
CHECK(!cal.addWindow(window("w1", "prod", 13, 15), &error), "duplicate should fail");
CHECK(error == "window_duplicate", "wrong error");
PASS();
}
void test_frozen_true_inside_window() {
TEST(frozen_true_inside_window);
ChangeFreezeCalendar cal;
std::string error;
CHECK(cal.addWindow(window("w1", "prod", 10, 12), &error), "add failed");
CHECK(cal.frozen("prod", 11, &error), "should be frozen");
PASS();
}
void test_frozen_false_outside_window() {
TEST(frozen_false_outside_window);
ChangeFreezeCalendar cal;
std::string error;
CHECK(cal.addWindow(window("w1", "prod", 10, 12), &error), "add failed");
CHECK(!cal.frozen("prod", 13, &error), "should not be frozen");
PASS();
}
void test_frozen_rejects_missing_environment() {
TEST(frozen_rejects_missing_environment);
ChangeFreezeCalendar cal;
std::string error;
CHECK(!cal.frozen("", 10, &error), "query should fail");
CHECK(error == "environment_id_missing", "wrong error");
PASS();
}
void test_frozen_rejects_invalid_day() {
TEST(frozen_rejects_invalid_day);
ChangeFreezeCalendar cal;
std::string error;
CHECK(!cal.frozen("prod", -1, &error), "query should fail");
CHECK(error == "day_invalid", "wrong error");
PASS();
}
void test_window_count_empty_environment_returns_all() {
TEST(window_count_empty_environment_returns_all);
ChangeFreezeCalendar cal;
std::string error;
CHECK(cal.addWindow(window("w1", "prod", 10, 12), &error), "add w1 failed");
CHECK(cal.addWindow(window("w2", "staging", 10, 12), &error), "add w2 failed");
CHECK(cal.windowCount("") == 2, "all count mismatch");
PASS();
}
void test_active_on_day_returns_matching_windows() {
TEST(active_on_day_returns_matching_windows);
ChangeFreezeCalendar cal;
std::string error;
CHECK(cal.addWindow(window("w1", "prod", 10, 12), &error), "add w1 failed");
CHECK(cal.addWindow(window("w2", "staging", 11, 13), &error), "add w2 failed");
CHECK(cal.activeOnDay(11).size() == 2, "active size mismatch");
PASS();
}
void test_active_on_day_returns_empty_when_none() {
TEST(active_on_day_returns_empty_when_none);
ChangeFreezeCalendar cal;
std::string error;
CHECK(cal.addWindow(window("w1", "prod", 10, 12), &error), "add failed");
CHECK(cal.activeOnDay(30).empty(), "active set should be empty");
PASS();
}
int main() {
std::cout << "Step 609: Change Freeze Calendar\n";
test_add_window_success(); // 1
test_add_window_rejects_missing_window_id(); // 2
test_add_window_rejects_missing_environment_id(); // 3
test_add_window_rejects_invalid_range(); // 4
test_add_window_rejects_duplicate(); // 5
test_frozen_true_inside_window(); // 6
test_frozen_false_outside_window(); // 7
test_frozen_rejects_missing_environment(); // 8
test_frozen_rejects_invalid_day(); // 9
test_window_count_empty_environment_returns_all();// 10
test_active_on_day_returns_matching_windows(); // 11
test_active_on_day_returns_empty_when_none(); // 12
std::cout << "\nResults: " << passed << "/" << (passed + failed) << " passed\n";
return failed == 0 ? 0 : 1;
}

View File

@@ -11860,3 +11860,33 @@ status/percent rollups.
- `editor/src/IncidentPostmortemLedger.h` within header-size limit (`85` <= `600`)
- `editor/tests/step608_test.cpp` within test-file size guidance (`151` lines)
- Header-only architecture and naming conventions remain aligned with `ARCHITECTURE.md`
### Step 609: Change Freeze Calendar
**Status:** PASS (12/12 tests)
Implements deployment change-freeze windows with environment/day freeze checks
and active-window listing.
**Files added:**
- `editor/src/ChangeFreezeCalendar.h` - freeze calendar module:
- freeze window registration with validation/duplicate guards
- freeze checks by environment and day
- aggregate window counting and active-on-day filtering
- `editor/tests/step609_test.cpp` - 12 tests covering:
- window add success/failure behavior
- freeze query behavior and invalid query inputs
- aggregate count and active-window listing behavior
**Files modified:**
- `editor/CMakeLists.txt` - `step609_test` target
**Verification run:**
- `cmake -S editor -B editor/build-native` - PASS
- `cmake --build editor/build-native --target step609_test step608_test` - PASS
- `./editor/build-native/step609_test` - PASS (12/12)
- `./editor/build-native/step608_test` - PASS (12/12) regression coverage
**Architecture gate check:**
- `editor/src/ChangeFreezeCalendar.h` within header-size limit (`67` <= `600`)
- `editor/tests/step609_test.cpp` within test-file size guidance (`149` lines)
- Header-only architecture and naming conventions remain aligned with `ARCHITECTURE.md`