Batch 24 (20261102-C-bos-seed-24) screened all 3078 Bos seed queries. Only 23 themes were in scope (pure user-space reliability, at most one task per theme); the rest were single operations or explanations, installs and networking, system administration, ROS2, board-only or GUI requests. Two finished drafts were withdrawn as too close to existing tasks. Seeds supply direction only: all sources, contracts and tests are new, and no task shares more than 14 characters with its seed text. Each task passed the local gate and the trace6 Docker gate (5 runs per sample class). Claude rebuilt the catalog from the calibration receipts: 23/23 USABLE. 16 of 23 are C/C++. Only the task directories are taken; the batch worktree's lowered disk floor in rollout/core.py stays out of main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
128 lines
3.0 KiB
C++
128 lines
3.0 KiB
C++
#include "admission.hpp"
|
|
|
|
#include <charconv>
|
|
#include <limits>
|
|
#include <system_error>
|
|
|
|
namespace admission {
|
|
|
|
bool valid_key(const std::string &text)
|
|
{
|
|
if (text.empty() || text.size() > 24) {
|
|
return false;
|
|
}
|
|
for (unsigned char ch : text) {
|
|
const bool lower = ch >= 'a' && ch <= 'z';
|
|
const bool upper = ch >= 'A' && ch <= 'Z';
|
|
const bool digit = ch >= '0' && ch <= '9';
|
|
if (!lower && !upper && !digit && ch != '_' && ch != '-') {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool valid_policy(const Policy &policy)
|
|
{
|
|
if (policy.limit == 0 || policy.limit > 1000) {
|
|
return false;
|
|
}
|
|
if (policy.window == 0 || policy.window > 1000000) {
|
|
return false;
|
|
}
|
|
if (policy.capacity == 0 || policy.capacity > 1000) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool parse_u64(const std::string &text, std::uint64_t &out)
|
|
{
|
|
if (text.empty()) {
|
|
return false;
|
|
}
|
|
if (text.size() > 1 && text[0] == '0') {
|
|
return false;
|
|
}
|
|
for (unsigned char ch : text) {
|
|
if (ch < '0' || ch > '9') {
|
|
return false;
|
|
}
|
|
}
|
|
std::uint64_t value = 0;
|
|
const char *start = text.data();
|
|
const char *finish = start + text.size();
|
|
auto parsed = std::from_chars(start, finish, value, 10);
|
|
if (parsed.ec != std::errc{} || parsed.ptr != finish) {
|
|
return false;
|
|
}
|
|
out = value;
|
|
return true;
|
|
}
|
|
|
|
bool parse_u32(const std::string &text, std::uint32_t &out)
|
|
{
|
|
std::uint64_t value = 0;
|
|
if (!parse_u64(text, value)) {
|
|
return false;
|
|
}
|
|
if (value > std::numeric_limits<std::uint32_t>::max()) {
|
|
return false;
|
|
}
|
|
out = static_cast<std::uint32_t>(value);
|
|
return true;
|
|
}
|
|
|
|
bool parse_policy(const std::vector<std::string> &tokens, std::size_t offset,
|
|
Policy &out)
|
|
{
|
|
if (tokens.size() != offset + 3) {
|
|
return false;
|
|
}
|
|
Policy parsed;
|
|
if (!parse_u32(tokens[offset], parsed.limit)) {
|
|
return false;
|
|
}
|
|
if (!parse_u64(tokens[offset + 1], parsed.window)) {
|
|
return false;
|
|
}
|
|
if (!parse_u32(tokens[offset + 2], parsed.capacity)) {
|
|
return false;
|
|
}
|
|
out = parsed;
|
|
return true;
|
|
}
|
|
|
|
const char *request_name(RequestResult result)
|
|
{
|
|
switch (result) {
|
|
case RequestResult::Admit: return "ADMIT";
|
|
case RequestResult::Quota: return "QUOTA";
|
|
case RequestResult::Backwards: return "BACKWARDS";
|
|
case RequestResult::Capacity: return "CAPACITY";
|
|
case RequestResult::BadKey: return "BAD_KEY";
|
|
}
|
|
return "UNKNOWN";
|
|
}
|
|
|
|
const char *config_name(ConfigResult result)
|
|
{
|
|
switch (result) {
|
|
case ConfigResult::Ok: return "OK";
|
|
case ConfigResult::Policy: return "POLICY";
|
|
case ConfigResult::TooManyClients: return "TOO_MANY_CLIENTS";
|
|
}
|
|
return "UNKNOWN";
|
|
}
|
|
|
|
const char *drop_name(DropResult result)
|
|
{
|
|
switch (result) {
|
|
case DropResult::Ok: return "OK";
|
|
case DropResult::Missing: return "MISSING";
|
|
}
|
|
return "UNKNOWN";
|
|
}
|
|
|
|
} // namespace admission
|