feat: implement MoloApp plans 01-15 with integration
Full C++23 framework tree: runtime, observability, security, data, app, realtime, supervisor, clients, CLI, example plus enterprise tenancy, audit, operability, governance, supplychain. Postgres via docker compose for tests.
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
// Dev server: config split enforcement, backoff math, polling watcher.
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
#include "dev/dev_config.hpp"
|
||||
#include "dev/dev_server.hpp"
|
||||
#include "dev/polling_watcher.hpp"
|
||||
#include "dev/reloader.hpp"
|
||||
|
||||
#define CHECK(cond, label) \
|
||||
do { \
|
||||
if (!(cond)) { \
|
||||
std::cerr << "FAIL: " << label << "\n"; \
|
||||
return 1; \
|
||||
} \
|
||||
std::cout << "PASS: " << label << "\n"; \
|
||||
} while (0)
|
||||
|
||||
int main() {
|
||||
using namespace molo::dev;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
CHECK(DevServer::should_refuse(true, true, false), "prod+reload refused");
|
||||
CHECK(!DevServer::should_refuse(true, true, true), "allow-prod passes");
|
||||
CHECK(!DevServer::should_refuse(false, true, false), "dev reload passes");
|
||||
|
||||
CHECK(Reloader::backoff_for(1) == 1, "backoff 1s");
|
||||
CHECK(Reloader::backoff_for(2) == 2, "backoff 2s");
|
||||
CHECK(Reloader::backoff_for(3) == 4, "backoff 4s");
|
||||
CHECK(Reloader::backoff_for(99) == 30, "backoff holds at 30s");
|
||||
|
||||
fs::path dir = fs::temp_directory_path() / "molo-dev-test";
|
||||
fs::remove_all(dir);
|
||||
fs::create_directories(dir);
|
||||
{ std::ofstream(dir / ".env.json") << "{\"MOLO_ENV\": \"prod\", \"PORT\": 9000}"; }
|
||||
unsetenv("MOLO_ENV");
|
||||
ConfigLoader loader;
|
||||
LoadedConfig prod = loader.load((dir / ".env.json").string(), true, false);
|
||||
CHECK(!prod.ok(), "prod reload without allow-prod errors");
|
||||
LoadedConfig prod_ok = loader.load((dir / ".env.json").string(), true, true);
|
||||
CHECK(prod_ok.ok() && prod_ok.is_prod() && prod_ok.dev.port == 9000, "allow-prod loads prod");
|
||||
setenv("MOLO_ENV", "dev", 1);
|
||||
LoadedConfig dev = loader.load((dir / ".env.json").string(), true, false);
|
||||
CHECK(dev.ok() && !dev.is_prod(), "MOLO_ENV overrides file");
|
||||
unsetenv("MOLO_ENV");
|
||||
|
||||
PollingFileWatcher watcher;
|
||||
std::string error;
|
||||
CHECK(watcher.start({dir.string()}, error), "watcher starts: " + error);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
{ std::ofstream(dir / "t.txt") << "x"; }
|
||||
bool saw = false;
|
||||
for (int i = 0; i < 20 && !saw; ++i) {
|
||||
auto events = watcher.poll(200);
|
||||
for (const auto& event : events) {
|
||||
if (event.path.find("t.txt") != std::string::npos) saw = true;
|
||||
}
|
||||
}
|
||||
CHECK(saw, "watcher sees new file");
|
||||
watcher.stop();
|
||||
fs::remove_all(dir);
|
||||
std::cout << "ALL_DEV_OK\n";
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user