One user-space repair task per eligible HWE debug-diag / compile-deploy base ID: 320 admitted (C 218, C++ 97, build scripts 5), 1 skipped by the content filter. Each ships a public spec with a check-to-basis table, at least two defects with single-fix fixtures, a symptom-masking fixture and an alternative correct implementation. Claude re-checked all 320: structure, the HWE quality items and trace6 Docker calibration receipts against current digests (320/320 USABLE). Difficulty is unmeasured. Known follow-up: 212 tasks use 120 ad-hoc family names; the next batch maps them to the canonical list. The batch's 1,256-line progress log stays in its factory report and the 36-local branch batch15-hwe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 line
16 KiB
JSON
1 line
16 KiB
JSON
{"include/probe.hpp": "#pragma once\n\n#include <cstddef>\n#include <map>\n#include <stdexcept>\n#include <string>\n#include <vector>\n\nnamespace probe {\n\nenum class Fault { none, acquire, send, receive };\nenum class Status { ok, unavailable, send_error, receive_error };\n\nstruct Request {\n unsigned id;\n Fault fault;\n std::string token;\n};\n\nstruct Result {\n Status status;\n std::string reply;\n};\n\nstruct Observation {\n unsigned id;\n unsigned opened;\n unsigned closed;\n unsigned live;\n std::string events;\n std::string sent;\n std::string received;\n};\n\nclass EndpointError : public std::runtime_error {\npublic:\n explicit EndpointError(const std::string& message);\n};\n\nclass Port {\npublic:\n explicit Port(Request request);\n int acquire();\n void send(int handle, const std::string& bytes);\n std::string receive(int handle);\n void close(int handle);\n Observation observation() const;\n bool owns(int handle) const;\n\nprivate:\n struct HandleState {\n bool open = false;\n bool sent = false;\n bool received = false;\n unsigned sequence = 0;\n std::string outgoing;\n std::string incoming;\n };\n\n Request request_;\n unsigned opened_ = 0;\n unsigned closed_ = 0;\n unsigned sequence_ = 0;\n std::string events_;\n std::string sent_;\n std::string received_;\n std::map<int, HandleState> handles_;\n\n HandleState& require_open(int handle);\n const HandleState& require_open(int handle) const;\n void record(char code);\n int next_handle();\n std::string make_reply(const std::string& payload) const;\n};\n\nResult run_probe(Port& port, const Request& request);\nFault parse_fault(char code);\nchar fault_code(Fault fault);\nstd::string status_name(Status status);\nstd::string hex_encode(const std::string& bytes);\nstd::string hex_decode(const std::string& text);\nstd::vector<Request> read_requests(const std::string& input);\nstd::string render_result(const Request& request, const Result& result,\n const Observation& observation);\n\n} // namespace probe\n", "src/main.cpp": "#include \"probe.hpp\"\n\n#include <algorithm>\n#include <cctype>\n#include <cstdlib>\n#include <iostream>\n#include <limits>\n#include <set>\n#include <sstream>\n#include <string>\n#include <utility>\n#include <vector>\n\nnamespace probe {\nnamespace {\n\nclass Cursor {\npublic:\n explicit Cursor(std::string text) : text_(std::move(text)) {}\n\n bool finished() const {\n return offset_ == text_.size();\n }\n\n std::size_t position() const {\n return offset_;\n }\n\n char peek() const {\n if (finished()) {\n throw EndpointError(\"unexpected input end\");\n }\n return text_[offset_];\n }\n\n char take() {\n const char next = peek();\n ++offset_;\n return next;\n }\n\n void expect(char expected) {\n if (take() != expected) {\n throw EndpointError(\"unexpected separator\");\n }\n }\n\n void horizontal_space() {\n if (finished() || (peek() != ' ' && peek() != '\\t')) {\n throw EndpointError(\"expected horizontal space\");\n }\n while (!finished() && (peek() == ' ' || peek() == '\\t')) {\n take();\n }\n }\n\n void optional_horizontal_space() {\n while (!finished() && (peek() == ' ' || peek() == '\\t')) {\n take();\n }\n }\n\n bool consume_line_end() {\n if (finished()) {\n return false;\n }\n if (peek() == '\\r') {\n take();\n expect('\\n');\n return true;\n }\n if (peek() == '\\n') {\n take();\n return true;\n }\n throw EndpointError(\"expected line end\");\n }\n\n std::string word() {\n const std::size_t start = offset_;\n while (!finished()) {\n const char current = peek();\n if (current == ' ' || current == '\\t' || current == '\\r' || current == '\\n') {\n break;\n }\n take();\n }\n if (offset_ == start) {\n throw EndpointError(\"empty word\");\n }\n return text_.substr(start, offset_ - start);\n }\n\nprivate:\n std::string text_;\n std::size_t offset_ = 0;\n};\n\nunsigned decimal(const std::string& text, unsigned ceiling) {\n if (text.empty()) {\n throw EndpointError(\"empty decimal\");\n }\n unsigned result = 0;\n for (const unsigned char digit : text) {\n if (digit < '0' || digit > '9') {\n throw EndpointError(\"nondecimal input\");\n }\n const unsigned part = static_cast<unsigned>(digit - '0');\n if (result > (ceiling - part) / 10U) {\n throw EndpointError(\"decimal range\");\n }\n result = result * 10U + part;\n }\n return result;\n}\n\nRequest parse_request(Cursor& cursor) {\n const unsigned id = decimal(cursor.word(), 100000U);\n cursor.horizontal_space();\n const std::string fault_token = cursor.word();\n if (fault_token.size() != 1U) {\n throw EndpointError(\"fault token size\");\n }\n const Fault fault = parse_fault(fault_token[0]);\n cursor.horizontal_space();\n const std::string encoded = cursor.word();\n const std::string token = hex_decode(encoded);\n if (token.empty() || token.size() > 64U) {\n throw EndpointError(\"token size\");\n }\n for (const unsigned char byte : token) {\n if (byte < 33U || byte > 126U) {\n throw EndpointError(\"token byte range\");\n }\n }\n cursor.optional_horizontal_space();\n cursor.consume_line_end();\n return Request{id, fault, token};\n}\n\nstd::vector<Request> parse_batch(Cursor& cursor) {\n const unsigned count = decimal(cursor.word(), 128U);\n cursor.optional_horizontal_space();\n cursor.consume_line_end();\n std::vector<Request> requests;\n requests.reserve(count);\n std::set<unsigned> ids;\n for (unsigned index = 0; index < count; ++index) {\n Request request = parse_request(cursor);\n if (!ids.insert(request.id).second) {\n throw EndpointError(\"duplicate id\");\n }\n requests.push_back(std::move(request));\n }\n if (!cursor.finished()) {\n throw EndpointError(\"trailing input\");\n }\n return requests;\n}\n\nstd::string field(const std::string& value) {\n if (value.empty()) {\n return \"-\";\n }\n return value;\n}\n\nstd::string count_field(unsigned number) {\n return std::to_string(number);\n}\n\nstd::string result_row(const Request& request, const Result& result,\n const Observation& observation) {\n std::vector<std::string> columns;\n columns.push_back(count_field(request.id));\n columns.push_back(status_name(result.status));\n columns.push_back(field(hex_encode(result.reply)));\n columns.push_back(count_field(observation.opened));\n columns.push_back(count_field(observation.closed));\n columns.push_back(count_field(observation.live));\n columns.push_back(field(observation.events));\n columns.push_back(field(hex_encode(observation.sent)));\n columns.push_back(field(hex_encode(observation.received)));\n std::string output;\n for (std::size_t index = 0; index < columns.size(); ++index) {\n if (index > 0U) {\n output.push_back('|');\n }\n output += columns[index];\n }\n return output;\n}\n\nstruct BatchSummary {\n unsigned requests = 0;\n unsigned opened = 0;\n unsigned closed = 0;\n unsigned live = 0;\n unsigned successful = 0;\n unsigned unavailable = 0;\n unsigned send_errors = 0;\n unsigned receive_errors = 0;\n\n void include(const Result& result, const Observation& observation) {\n ++requests;\n opened += observation.opened;\n closed += observation.closed;\n live += observation.live;\n switch (result.status) {\n case Status::ok: ++successful; break;\n case Status::unavailable: ++unavailable; break;\n case Status::send_error: ++send_errors; break;\n case Status::receive_error: ++receive_errors; break;\n }\n }\n\n std::string render() const {\n std::vector<unsigned> numbers = {\n requests, opened, closed, live, successful,\n unavailable, send_errors, receive_errors\n };\n std::string line = \"batch\";\n for (const unsigned number : numbers) {\n line.push_back('|');\n line += std::to_string(number);\n }\n return line;\n }\n};\n\n} // namespace\n\nstd::vector<Request> read_requests(const std::string& input) {\n Cursor cursor(input);\n return parse_batch(cursor);\n}\n\nstd::string render_result(const Request& request, const Result& result,\n const Observation& observation) {\n if (observation.id != request.id) {\n throw EndpointError(\"observation id mismatch\");\n }\n return result_row(request, result, observation);\n}\n\n} // namespace probe\n\nint main() {\n using namespace probe;\n try {\n std::ostringstream buffer;\n buffer << std::cin.rdbuf();\n const std::vector<Request> requests = read_requests(buffer.str());\n BatchSummary summary;\n for (const Request& request : requests) {\n Port port(request);\n const Result result = run_probe(port, request);\n const Observation observation = port.observation();\n summary.include(result, observation);\n std::cout << render_result(request, result, observation) << '\\n';\n }\n std::cout << summary.render() << '\\n';\n return 0;\n } catch (const std::exception& error) {\n std::cerr << \"probe input or engine error: \" << error.what() << '\\n';\n return 2;\n }\n}\n", "src/port.cpp": "#include \"probe.hpp\"\n\n#include <algorithm>\n#include <cctype>\n#include <climits>\n#include <iomanip>\n#include <limits>\n#include <sstream>\n#include <utility>\n\nnamespace probe {\n\nEndpointError::EndpointError(const std::string& message)\n : std::runtime_error(message) {}\n\nPort::Port(Request request)\n : request_(std::move(request)) {}\n\nvoid Port::record(char code) {\n events_.push_back(code);\n ++sequence_;\n}\n\nint Port::next_handle() {\n const unsigned candidate = request_.id * 13U + 17U;\n if (candidate > static_cast<unsigned>(INT_MAX)) {\n throw EndpointError(\"handle range\");\n }\n return static_cast<int>(candidate);\n}\n\nPort::HandleState& Port::require_open(int handle) {\n const auto found = handles_.find(handle);\n if (found == handles_.end()) {\n throw EndpointError(\"unknown handle\");\n }\n if (!found->second.open) {\n throw EndpointError(\"closed handle\");\n }\n return found->second;\n}\n\nconst Port::HandleState& Port::require_open(int handle) const {\n const auto found = handles_.find(handle);\n if (found == handles_.end()) {\n throw EndpointError(\"unknown handle\");\n }\n if (!found->second.open) {\n throw EndpointError(\"closed handle\");\n }\n return found->second;\n}\n\nint Port::acquire() {\n record('A');\n if (request_.fault == Fault::acquire) {\n record('X');\n throw EndpointError(\"acquisition rejected\");\n }\n if (opened_ != 0U) {\n throw EndpointError(\"one endpoint per request\");\n }\n const int handle = next_handle();\n HandleState state;\n state.open = true;\n state.sequence = sequence_;\n handles_.emplace(handle, std::move(state));\n ++opened_;\n record('O');\n return handle;\n}\n\nvoid Port::send(int handle, const std::string& bytes) {\n HandleState& state = require_open(handle);\n record('S');\n if (state.sent) {\n throw EndpointError(\"send already attempted\");\n }\n state.sent = true;\n if (request_.fault == Fault::send) {\n record('X');\n throw EndpointError(\"send rejected\");\n }\n state.outgoing = bytes;\n sent_ = bytes;\n state.sequence = sequence_;\n record('T');\n}\n\nstd::string Port::make_reply(const std::string& payload) const {\n const std::string prefix = \"ping:\";\n if (payload.size() < prefix.size()) {\n throw EndpointError(\"short request\");\n }\n if (payload.compare(0, prefix.size(), prefix) != 0) {\n throw EndpointError(\"request prefix\");\n }\n const std::string token = payload.substr(prefix.size());\n if (token != request_.token) {\n throw EndpointError(\"request token mismatch\");\n }\n return \"pong:\" + token;\n}\n\nstd::string Port::receive(int handle) {\n HandleState& state = require_open(handle);\n record('R');\n if (!state.sent) {\n throw EndpointError(\"receive before send\");\n }\n if (state.received) {\n throw EndpointError(\"receive already attempted\");\n }\n state.received = true;\n if (request_.fault == Fault::receive) {\n record('X');\n throw EndpointError(\"receive rejected\");\n }\n const std::string reply = make_reply(state.outgoing);\n state.incoming = reply;\n state.sequence = sequence_;\n received_ = reply;\n record('D');\n return reply;\n}\n\nvoid Port::close(int handle) {\n HandleState& state = require_open(handle);\n if (state.sequence > sequence_) {\n throw EndpointError(\"event order\");\n }\n state.open = false;\n ++closed_;\n record('C');\n}\n\nbool Port::owns(int handle) const {\n const auto found = handles_.find(handle);\n return found != handles_.end() && found->second.open;\n}\n\nObservation Port::observation() const {\n unsigned live = 0;\n for (const auto& entry : handles_) {\n if (entry.second.open) {\n ++live;\n }\n }\n return Observation{request_.id, opened_, closed_, live, events_, sent_, received_};\n}\n\nFault parse_fault(char code) {\n switch (code) {\n case 'N': return Fault::none;\n case 'A': return Fault::acquire;\n case 'S': return Fault::send;\n case 'R': return Fault::receive;\n default: throw EndpointError(\"unknown fault code\");\n }\n}\n\nchar fault_code(Fault fault) {\n switch (fault) {\n case Fault::none: return 'N';\n case Fault::acquire: return 'A';\n case Fault::send: return 'S';\n case Fault::receive: return 'R';\n }\n throw EndpointError(\"unknown fault\");\n}\n\nstd::string status_name(Status status) {\n switch (status) {\n case Status::ok: return \"ok\";\n case Status::unavailable: return \"unavailable\";\n case Status::send_error: return \"send_error\";\n case Status::receive_error: return \"receive_error\";\n }\n throw EndpointError(\"unknown status\");\n}\n\nstd::string hex_encode(const std::string& bytes) {\n static const char digits[] = \"0123456789abcdef\";\n std::string encoded;\n encoded.reserve(bytes.size() * 2U);\n for (const unsigned char byte : bytes) {\n encoded.push_back(digits[byte >> 4U]);\n encoded.push_back(digits[byte & 15U]);\n }\n return encoded;\n}\n\nnamespace {\n\nunsigned hex_value(char input) {\n if (input >= '0' && input <= '9') {\n return static_cast<unsigned>(input - '0');\n }\n if (input >= 'a' && input <= 'f') {\n return static_cast<unsigned>(input - 'a' + 10);\n }\n if (input >= 'A' && input <= 'F') {\n return static_cast<unsigned>(input - 'A' + 10);\n }\n throw EndpointError(\"invalid hex digit\");\n}\n\n} // namespace\n\nstd::string hex_decode(const std::string& text) {\n if ((text.size() % 2U) != 0U) {\n throw EndpointError(\"odd hex length\");\n }\n std::string bytes;\n bytes.reserve(text.size() / 2U);\n for (std::size_t index = 0; index < text.size(); index += 2U) {\n const unsigned high = hex_value(text[index]);\n const unsigned low = hex_value(text[index + 1U]);\n bytes.push_back(static_cast<char>((high << 4U) | low));\n }\n return bytes;\n}\n\n} // namespace probe\n"} |