feat(workflow): example covers security, platform, enterprise and resilience features

105 route tests, matrix crawl, spec and README updated.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-24 02:19:52 +02:00
co-authored by Claude Sonnet 5.5
parent 00af65613d
commit 62fdd08da8
90 changed files with 8038 additions and 11 deletions
+28
View File
@@ -0,0 +1,28 @@
// Route: /data/migrations (check preview, apply, drift, heal)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
static const char* kForm = "application/x-www-form-urlencoded";
int main() {
Fixture f;
auto page = f.client->get("/data/migrations");
check(page.status == 200, "status 200");
check(contains(page.body, "CREATE TABLE users") && contains(page.body, "CREATE TABLE posts"), "preview lists pending sql");
check(contains(page.body, "none"), "nothing applied by viewing");
auto one = f.client->post("/data/migrations/apply", "limit=1", kForm);
check(contains(one.body, "1 migration(s) applied"), "apply one step");
check(!contains(one.body, "CREATE TABLE users"), "applied step leaves the preview");
check(contains(one.body, "CREATE TABLE posts"), "later steps still pending");
auto rest = f.client->post("/data/migrations/apply", "limit=3", kForm);
check(contains(rest.body, "2 migration(s) applied"), "rest applied");
check(contains(rest.body, "table posts"), "side effect: table exists");
f.client->post("/data/migrations/drift", "", kForm);
check(contains(f.client->get("/data/migrations").body, "003 posts"), "drift detected");
check(contains(f.client->post("/data/migrations/heal", "", kForm).body, "1 table(s) healed"), "healer repairs drift");
auto bad = f.client->post("/data/migrations/apply", "limit=9", kForm);
check(bad.status == 422 && contains(bad.body, "must be between 1 and 3"), "422 step limit");
return finish("data/migrations");
}
+24
View File
@@ -0,0 +1,24 @@
// Route: /data/query (query builder and has-many relation)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
static const char* kForm = "application/x-www-form-urlencoded";
int main() {
Fixture f;
check(f.client->get("/data/query").status == 200, "status 200");
auto all = f.client->post("/data/query/run", "limit=10&order=title", kForm);
check(contains(all.body, "ORDER BY posts.title LIMIT 10"), "sql built");
check(contains(all.body, "5 row(s)"), "five posts");
check(contains(all.body, "Alpha by ada") && contains(all.body, "Beta by grace"), "relation joins author");
auto ada = f.client->post("/data/query/run", "user_id=1", kForm);
check(contains(ada.body, "WHERE posts.user_id = 1") && contains(ada.body, "3 row(s)"), "where filter");
auto lim = f.client->post("/data/query/run", "limit=2", kForm);
check(contains(lim.body, "2 row(s)"), "limit applied");
auto bad = f.client->post("/data/query/run", "order=name", kForm);
check(bad.status == 422 && contains(bad.body, "must be one of: id, title"), "422 order whitelist");
check(f.client->post("/data/query/run", "limit=99", kForm).status == 422, "422 limit above cap");
return finish("data/query");
}
+22
View File
@@ -0,0 +1,22 @@
// Route: /data/singleflight (concurrent loads collapse into one)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
static const char* kForm = "application/x-www-form-urlencoded";
int main() {
Fixture f;
check(f.client->get("/data/singleflight").status == 200, "status 200");
auto res = f.client->post("/data/singleflight/run", "callers=8", kForm);
check(contains(res.body, "8 callers, 1 load(s)"), "eight callers share one load");
auto one = f.client->post("/data/singleflight/run", "callers=1", kForm);
check(contains(one.body, "1 callers, 1 load(s)"), "single caller loads once");
auto max = f.client->post("/data/singleflight/run", "callers=16", kForm);
check(contains(max.body, "16 callers, 1 load(s)"), "cap of 16 threads still collapses");
auto bad = f.client->post("/data/singleflight/run", "callers=17", kForm);
check(bad.status == 422 && contains(bad.body, "must be between 1 and 16"), "422 above thread cap");
check(contains(f.client->get("/data/singleflight").body, ">3<"), "side effect: three runs counted");
return finish("data/singleflight");
}
+26
View File
@@ -0,0 +1,26 @@
// Route: /data/transaction (commit and rollback)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
static const char* kForm = "application/x-www-form-urlencoded";
int main() {
Fixture f;
check(f.client->get("/data/transaction").status == 200, "status 200");
auto ok = f.client->post("/data/transaction/transfer", "amount=30", kForm);
check(contains(ok.body, "committed"), "commit");
check(f.services.sqlite != nullptr, "fixture alive");
auto fail = f.client->post("/data/transaction/transfer", "amount=10&fail_after_debit=1", kForm);
check(contains(fail.body, "rolled back: failure after debit"), "failure rolls back");
auto over = f.client->post("/data/transaction/transfer", "amount=500", kForm);
check(contains(over.body, "rolled back: insufficient funds"), "overdraft rolls back");
auto json = f.client->request(Method::Post, "/data/transaction/transfer", "{\"amount\":\"1\"}", {{"Content-Type", "application/json"}});
check(json.status == 200 && contains(json.body, "\"alice\":\"69\""), "alice 100-30-1; rollbacks changed nothing");
check(contains(json.body, "\"rollbacks\":\"2\"") && contains(json.body, "\"commits\":\"2\""), "side effect: counters");
auto same = f.client->post("/data/transaction/transfer", "from=bob&to=bob&amount=5", kForm);
check(same.status == 422 && contains(same.body, "must differ"), "422 same account");
check(f.client->post("/data/transaction/transfer", "amount=0", kForm).status == 422, "422 amount limit");
return finish("data/transaction");
}
+26
View File
@@ -0,0 +1,26 @@
// Route: /data/ttl (TTL expiry, LRU eviction, pubsub events)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
static const char* kForm = "application/x-www-form-urlencoded";
int main() {
Fixture f;
check(f.client->get("/data/ttl").status == 200, "status 200");
f.client->post("/data/ttl/set", "key=a&value=1&ttl_s=5", kForm);
check(contains(f.client->post("/data/ttl/get", "key=a", kForm).body, "hit: 1"), "hit");
f.client->post("/data/ttl/tick", "", kForm);
auto gone = f.client->post("/data/ttl/get", "key=a", kForm);
check(contains(gone.body, "miss") && contains(gone.body, "expired a"), "expired after ttl, event published");
for (int i = 0; i < 6; ++i)
f.client->post("/data/ttl/set", "key=k" + std::to_string(i) + "&value=v&ttl_s=60", kForm);
auto page = f.client->get("/data/ttl");
check(contains(page.body, "5/5"), "capacity capped at 5");
check(contains(page.body, "evicted k0 (lru)"), "oldest key evicted");
auto bad = f.client->post("/data/ttl/set", "key=&value=x&ttl_s=0", kForm);
check(bad.status == 422 && contains(bad.body, "is required"), "422 missing key");
check(f.client->post("/data/ttl/set", "key=a&value=b&ttl_s=999", kForm).status == 422, "422 ttl above cap");
return finish("data/ttl");
}