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>
11 lines
22 KiB
JSON
11 lines
22 KiB
JSON
{
|
|
"Makefile": "CXX ?= g++\nCXXFLAGS ?= -std=c++17 -O2 -Wall -Wextra -Wpedantic\nCPPFLAGS += -Iinclude\nSOURCES = src/resource_job.cpp src/finite_store.cpp src/observe.cpp\nresource-observe: $(SOURCES) include/resource_job.hpp include/finite_store.hpp\n\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(SOURCES) -o $@\n.PHONY: demo clean\ndemo: resource-observe\n\t./resource-observe < examples/field.txt\nclean:\n\trm -f resource-observe\n",
|
|
"README.md": "# \u914d\u7f6e\u91c7\u96c6\u4f5c\u4e1a\u7684\u8f6f\u4ef6\u89c2\u5bdf\u73af\u5883\n\n\u5148\u8bfb docs/resource-job.md \u5168\u90e811\u6761\u548c include/resource_job.hpp\u3002make \u6784\u5efa resource-observe\uff1bmake demo \u8fd0\u884c examples/field.txt\u3002\u89c2\u5bdf\u7ed3\u679c\u7684\u751f\u547d\u5468\u671f\u8bb0\u5f55\u7531\u6709\u9650\u6d41\u540e\u7aef\u4ea7\u751f\uff0c\u4e0d\u8bfb\u53d6\u771f\u5b9e\u7cfb\u7edf\u6587\u4ef6\u3002\u6700\u7ec8\u53ea\u63d0\u4ea4 src/resource_job.cpp\u3002\n",
|
|
"docs/resource-job.md": "# Finite configuration resource job, revision 1\n\n1. The C++17 interface is include/resource_job.hpp. execute is called with 0..8 Source entries and a Provider. A Source has key (0..7), scale (-20..20), and borrowed (-1 means acquire; otherwise a valid caller-owned handle at position zero). Repeated keys are distinct opens. An empty request succeeds. No real system configuration files are consulted.\n2. All owned entries are acquired using open in source order before any read. Borrowed entries need no open. If any open returns -1, stop acquisition immediately and return OpenError and its zero-based source index. No reads may occur in that request. On success/failure, each successfully opened owned handle is closed exactly once, in reverse acquisition order. Borrowed handles are never closed by execute, including failures.\n3. Once acquisition succeeds, consume streams in source order. read(handle, buffer, capacity) returns 1..capacity raw bytes, 0 at EOF, -1 on error. capacity must be 1..64. Streams contain at most 4096 bytes, including arbitrary invalid record bytes. Short reads are normal. Streams with an injected read error contain syntactically valid record content; competing read/parse errors in one stream are outside this fixture contract. A read error returns ReadError at that source and stops processing later sources. Implementations may choose any legal read sizes or buffer strategy. No requirement is imposed on postfailure cursor positions.\n4. Physical lines are separated only by byte LF. Every LF finishes one physical line; a nonempty residual at EOF finishes one more. An empty stream has zero lines, and a trailing LF does not create an extra line. For interpreting a line, strip SPACE, TAB and CR from both ends. Empty lines and lines whose first remaining byte is # are ignored records, but count as physical lines.\n5. A data line is key=value. key is 1..12 ASCII lower-case letters. Exactly one equals is present. The value is optional + or - followed by one or more ASCII decimal digits, with numeric value in [-1000000,1000000]. Arbitrary leading zeros are valid. Strip SPACE, TAB and CR separately around key and value. No other whitespace, comments, bytes or syntax are accepted. Invalid lines return ParseError at that source and stop later sources. Duplicate keys each count as a separate record.\n6. For each source, Item.lines counts physical lines, Item.records counts data records, Item.value sums value*scale. Each parsed record updates Item.checksum = (old*131 + keyhash + (value+1000000)*17) modulo 1000000007, starting at zero, where keyhash starts zero and consumes ASCII key bytes by h=(h*33+byte) modulo 1000000007. Ignored records do not update checksum. Output items preserve source order.\n7. Success returns Ok, failed_source=-1, opened=number of owned source entries, all items, and totals obtained by summing lines/records/value across items. Any failure returns its status/index, opened=0, empty items and zero totals. Only fully completed jobs publish business results. Resource lifetime and ownership observations remain visible on failures.\n8. Provider never throws C++ exceptions and valid resource counts are small. read/open failures are represented by -1. execute must return normally. Caller repeated execute calls use fresh source streams; there is no process-global job state.\n9. The public observer is src/observe.cpp and src/finite_store.cpp. It prints one JSON array per input case: [status,failed_source,opened,total_lines,total_records,total_value,items,lifecycle,owned_live,borrowed_live,early_read,invalid_calls]. Each item is [lines,records,value,checksum]. lifecycle records [1,key,handle] for open success, [2,key,-1] for failed open, [3,handle,0] for close. Resource handles start at 100 per case; borrowed handles are allocated before owned acquisition in source order. Reads are deliberately not logged because legal buffering strategies differ. early_read counts reads made before all expected opens; invalid_calls counts invalid handles/capacities or duplicate closes. borrowed_live is the number of caller-owned handles still live. The observer itself exits 0 after normal cases; stderr may contain arbitrary diagnostic bytes and is ignored for behavior.\n10. Observer stdin is decimal case count (0..10000), then for each case decimal catalog count and source count; then one catalog line per key: key open_failure read_failure_offset chunk hexdata; then one source line: key scale borrowed_flag. Integer fields use stream-style SPACE/TAB/CR/LF separators, optional sign and leading zeros. Catalog keys are distinct 0..7; open_failure and borrowed_flag are 0 or 1; read_failure_offset is -1 or 0..4096; chunk is 1..64. hexdata is even ASCII hex (either case) or '-' for empty. Borrowed entries require non-failing open and valid catalog key. No missing catalog keys are supplied. JSON numeric values are integers, fields/array structure follow clause 9; representation of JSON whitespace is unrestricted.\n11. Build with make, run ./resource-observe < examples/field.txt, or make demo. g++, make and Python 3 are the only tools used. src/resource_job.cpp is the only candidate file; all public support is reconstructed for formal grading. Follow all clauses of this document.\n",
|
|
"examples/field.txt": "2\n2 2\n0 0 -1 3 616c7068613d320a\n1 1 -1 4 626574613d330a\n0 2 0\n1 3 0\n2 2\n0 0 -1 2 616c7068613d320a\n1 0 -1 4 626574613d330a\n0 2 0\n1 3 0\n",
|
|
"include/finite_store.hpp": "#ifndef FINITE_STORE_HPP\n#define FINITE_STORE_HPP\n#include \"resource_job.hpp\"\n#include <array>\n#include <iosfwd>\n#include <map>\n#include <optional>\nnamespace resource {\nstruct CatalogEntry {\n int key=0;\n bool open_failure=false;\n int read_failure=-1;\n std::size_t chunk=1;\n std::string bytes;\n};\nstruct Event {\n int kind;\n int first;\n int second;\n};\nstruct StreamState {\n int key;\n bool borrowed;\n bool live;\n std::size_t cursor;\n};\nclass FiniteStore final: public Provider {\npublic:\n explicit FiniteStore(std::vector<CatalogEntry> entries);\n int borrow(int key);\n void expect_opens(int count);\n int open(int key) override;\n int read(int handle,char *output,std::size_t capacity) override;\n void close(int handle) override;\n std::size_t owned_live() const;\n std::size_t borrowed_live() const;\n void describe_live(std::ostream &out) const;\n int early_reads() const;\n int invalid_calls() const;\n const std::vector<Event> &events() const;\n const CatalogEntry *catalog(int key) const;\n const StreamState *stream(int handle) const;\nprivate:\n int create_stream(int key,bool borrowed);\n std::map<int,CatalogEntry> entries_;\n std::map<int,StreamState> streams_;\n std::vector<Event> events_;\n int next_handle_=100;\n int expected_opens_=0;\n int attempted_opens_=0;\n int early_reads_=0;\n int invalid_calls_=0;\n};\nstruct CaseInput {\n std::vector<CatalogEntry> catalog;\n std::vector<std::array<int,3>> sources;\n};\nbool read_case_count(std::istream &in,int &count);\nbool read_case(std::istream &in,CaseInput &output);\nvoid print_observation(std::ostream &out,const Result &result,const FiniteStore &store);\n}\n#endif\n",
|
|
"include/resource_job.hpp": "#ifndef RESOURCE_JOB_HPP\n#define RESOURCE_JOB_HPP\n#include <cstddef>\n#include <cstdint>\n#include <string>\n#include <vector>\nnamespace resource {\nconstexpr std::int64_t modulus = 1000000007;\nconstexpr std::size_t maximum_chunk = 64;\nconstexpr std::size_t maximum_bytes = 4096;\nenum class Status { Ok=0, OpenError=1, ReadError=2, ParseError=3 };\nstruct Source {\n int key;\n int scale;\n int borrowed;\n};\nstruct Item {\n std::int64_t lines=0;\n std::int64_t records=0;\n std::int64_t value=0;\n std::int64_t checksum=0;\n};\nstruct Result {\n Status status=Status::Ok;\n int failed_source=-1;\n int opened=0;\n std::int64_t lines=0;\n std::int64_t records=0;\n std::int64_t value=0;\n std::vector<Item> items;\n};\nclass Provider {\npublic:\n virtual ~Provider()=default;\n virtual int open(int key)=0;\n virtual int read(int handle,char *output,std::size_t capacity)=0;\n virtual void close(int handle)=0;\n};\nResult execute(Provider &provider,const std::vector<Source> &sources);\n}\n#endif\n",
|
|
"src/finite_store.cpp": "#include \"finite_store.hpp\"\n#include <algorithm>\n#include <cstring>\n#include <ostream>\n#include <utility>\nnamespace resource {\nFiniteStore::FiniteStore(std::vector<CatalogEntry> entries) {\n for (auto &entry:entries) {\n const int key=entry.key;\n entries_.emplace(key,std::move(entry));\n }\n}\nconst CatalogEntry *FiniteStore::catalog(int key) const {\n auto found=entries_.find(key);\n if (found==entries_.end()) {\n return nullptr;\n }\n return &found->second;\n}\nconst StreamState *FiniteStore::stream(int handle) const {\n auto found=streams_.find(handle);\n if (found==streams_.end()) {\n return nullptr;\n }\n return &found->second;\n}\nint FiniteStore::create_stream(int key,bool borrowed) {\n const int handle=next_handle_;\n ++next_handle_;\n StreamState state;\n state.key=key;\n state.borrowed=borrowed;\n state.live=true;\n state.cursor=0;\n streams_.emplace(handle,state);\n return handle;\n}\nint FiniteStore::borrow(int key) {\n const CatalogEntry *entry=catalog(key);\n if (entry==nullptr || entry->open_failure) {\n ++invalid_calls_;\n return -1;\n }\n return create_stream(key,true);\n}\nvoid FiniteStore::expect_opens(int count) {\n expected_opens_=count;\n attempted_opens_=0;\n}\nint FiniteStore::open(int key) {\n ++attempted_opens_;\n const CatalogEntry *entry=catalog(key);\n if (entry==nullptr || entry->open_failure) {\n events_.push_back({2,key,-1});\n return -1;\n }\n const int handle=create_stream(key,false);\n events_.push_back({1,key,handle});\n return handle;\n}\nint FiniteStore::read(int handle,char *output,std::size_t capacity) {\n if (attempted_opens_<expected_opens_) {\n ++early_reads_;\n }\n if (capacity==0 || capacity>maximum_chunk || output==nullptr) {\n ++invalid_calls_;\n return -1;\n }\n auto found=streams_.find(handle);\n if (found==streams_.end() || !found->second.live) {\n ++invalid_calls_;\n return -1;\n }\n StreamState &state=found->second;\n const CatalogEntry *entry=catalog(state.key);\n if (entry==nullptr) {\n ++invalid_calls_;\n return -1;\n }\n const std::size_t cursor=state.cursor;\n if (entry->read_failure>=0 && cursor>=static_cast<std::size_t>(entry->read_failure)) {\n return -1;\n }\n if (cursor>=entry->bytes.size()) {\n return 0;\n }\n std::size_t count=std::min(capacity,entry->chunk);\n count=std::min(count,entry->bytes.size()-cursor);\n if (entry->read_failure>=0) {\n const std::size_t boundary=static_cast<std::size_t>(entry->read_failure);\n count=std::min(count,boundary-cursor);\n }\n if (count==0) {\n return -1;\n }\n std::memcpy(output,entry->bytes.data()+cursor,count);\n state.cursor+=count;\n return static_cast<int>(count);\n}\nvoid FiniteStore::close(int handle) {\n auto found=streams_.find(handle);\n if (found==streams_.end() || !found->second.live) {\n ++invalid_calls_;\n return;\n }\n found->second.live=false;\n events_.push_back({3,handle,0});\n}\nstd::size_t FiniteStore::owned_live() const {\n std::size_t count=0;\n for (const auto &pair:streams_) {\n const StreamState &state=pair.second;\n if (state.live && !state.borrowed) {\n ++count;\n }\n }\n return count;\n}\nstd::size_t FiniteStore::borrowed_live() const {\n std::size_t count=0;\n for (const auto &pair:streams_) {\n const StreamState &state=pair.second;\n if (state.live && state.borrowed) {\n ++count;\n }\n }\n return count;\n}\nvoid FiniteStore::describe_live(std::ostream &out) const {\n for (const auto &entry:streams_) {\n const int handle=entry.first;\n const StreamState &state=entry.second;\n if (!state.live) {\n continue;\n }\n out<<\"live stream handle=\"<<handle;\n out<<\" key=\"<<state.key;\n out<<\" ownership=\"<<(state.borrowed ? \"caller\" : \"job\");\n out<<\" cursor=\"<<state.cursor;\n const CatalogEntry *metadata=catalog(state.key);\n if (metadata!=nullptr) {\n out<<\" bytes=\"<<metadata->bytes.size();\n out<<\" chunk=\"<<metadata->chunk;\n out<<\" read-failure=\"<<metadata->read_failure;\n }\n out<<'\\n';\n }\n}\nint FiniteStore::early_reads() const {\n return early_reads_;\n}\nint FiniteStore::invalid_calls() const {\n return invalid_calls_;\n}\nconst std::vector<Event> &FiniteStore::events() const {\n return events_;\n}\n}\n",
|
|
"src/observe.cpp": "#include \"finite_store.hpp\"\n#include <iostream>\n#include <limits>\n#include <string>\n#include <utility>\nnamespace resource {\nnamespace {\n\nbool delimiter(int byte) {\n return byte==' ' || byte=='\\t' || byte=='\\r' || byte=='\\n';\n}\nclass DecimalToken {\npublic:\n bool read(std::istream &input) {\n bytes_.clear();\n bool started=false;\n for (;;) {\n const int next=input.peek();\n if (next==std::char_traits<char>::eof()) {\n return started;\n }\n if (delimiter(next)) {\n input.get();\n if (started) {\n return true;\n }\n continue;\n }\n started=true;\n bytes_.push_back(static_cast<char>(input.get()));\n }\n }\n bool convert(int &output) const {\n if (bytes_.empty()) {\n return false;\n }\n std::size_t position=0;\n const bool negative=bytes_.front()=='-';\n if (negative || bytes_.front()=='+') {\n position=1;\n }\n if (position==bytes_.size()) {\n return false;\n }\n for (std::size_t i=position;i<bytes_.size();++i) {\n if (bytes_[i]<'0' || bytes_[i]>'9') {\n return false;\n }\n }\n while (position<bytes_.size() && bytes_[position]=='0') {\n ++position;\n }\n const std::string limit=negative ? \"2147483648\" : \"2147483647\";\n const std::size_t significant=bytes_.size()-position;\n if (significant>limit.size()) {\n return false;\n }\n if (significant==limit.size() && bytes_.compare(position,significant,limit)>0) {\n return false;\n }\n unsigned int magnitude=0;\n while (position<bytes_.size()) {\n magnitude=magnitude*10+static_cast<unsigned int>(bytes_[position]-'0');\n ++position;\n }\n if (negative && magnitude==2147483648u) {\n output=std::numeric_limits<int>::min();\n } else if (negative) {\n output=-static_cast<int>(magnitude);\n } else {\n output=static_cast<int>(magnitude);\n }\n return true;\n }\n const std::string &bytes() const {\n return bytes_;\n }\nprivate:\n std::string bytes_;\n};\nbool read_integer(std::istream &in,int &value) {\n DecimalToken token;\n if (!token.read(in)) {\n return false;\n }\n return token.convert(value);\n}\nbool read_hex_token(std::istream &in,std::string &value) {\n DecimalToken token;\n if (!token.read(in)) {\n return false;\n }\n value=token.bytes();\n return true;\n}\nint hex_digit(char byte) {\n if (byte>='0' && byte<='9') {\n return byte-'0';\n }\n if (byte>='a' && byte<='f') {\n return byte-'a'+10;\n }\n if (byte>='A' && byte<='F') {\n return byte-'A'+10;\n }\n return -1;\n}\nbool decode_hex(const std::string &token,std::string &bytes) {\n bytes.clear();\n if (token==\"-\") {\n return true;\n }\n if (token.size()%2!=0 || token.size()/2>maximum_bytes) {\n return false;\n }\n bytes.reserve(token.size()/2);\n for (std::size_t i=0;i<token.size();i+=2) {\n const int high=hex_digit(token[i]);\n const int low=hex_digit(token[i+1]);\n if (high<0 || low<0) {\n return false;\n }\n bytes.push_back(static_cast<char>(high*16+low));\n }\n return true;\n}\nbool read_entry(std::istream &in,CatalogEntry &entry) {\n int fail;\n int chunk;\n std::string encoded;\n if (!read_integer(in,entry.key) || !read_integer(in,fail)) {\n return false;\n }\n if (!read_integer(in,entry.read_failure) || !read_integer(in,chunk)) {\n return false;\n }\n if (!read_hex_token(in,encoded) || entry.key<0 || entry.key>7) {\n return false;\n }\n if (fail<0 || fail>1 || chunk<1 || chunk>64) {\n return false;\n }\n if (entry.read_failure < -1 || entry.read_failure>4096) {\n return false;\n }\n entry.open_failure=fail!=0;\n entry.chunk=static_cast<std::size_t>(chunk);\n return decode_hex(encoded,entry.bytes);\n}\nvoid print_item(std::ostream &out,const Item &item) {\n out<<'['<<item.lines<<','<<item.records<<',';\n out<<item.value<<','<<item.checksum<<']';\n}\nvoid print_event(std::ostream &out,const Event &event) {\n out<<'['<<event.kind<<','<<event.first<<','<<event.second<<']';\n}\n}\nbool read_case_count(std::istream &in,int &count) {\n return read_integer(in,count) && count>=0 && count<=10000;\n}\nbool read_case(std::istream &in,CaseInput &output) {\n int catalogs;\n int sources;\n if (!read_integer(in,catalogs) || !read_integer(in,sources)) {\n return false;\n }\n if (catalogs<0 || catalogs>8 || sources<0 || sources>8) {\n return false;\n }\n output.catalog.clear();\n output.sources.clear();\n std::array<bool,8> keys{};\n for (int i=0;i<catalogs;++i) {\n CatalogEntry entry;\n if (!read_entry(in,entry) || keys[entry.key]) {\n return false;\n }\n keys[entry.key]=true;\n output.catalog.push_back(std::move(entry));\n }\n for (int i=0;i<sources;++i) {\n std::array<int,3> source{};\n for (int &value:source) {\n if (!read_integer(in,value)) {\n return false;\n }\n }\n if (source[0]<0 || source[0]>7 || !keys[source[0]]) {\n return false;\n }\n if (source[1]<-20 || source[1]>20 || source[2]<0 || source[2]>1) {\n return false;\n }\n if (source[2]) {\n bool fail=false;\n for (const CatalogEntry &entry:output.catalog) {\n if (entry.key==source[0]) {\n fail=entry.open_failure;\n }\n }\n if (fail) {\n return false;\n }\n }\n output.sources.push_back(source);\n }\n return true;\n}\nvoid print_observation(std::ostream &out,const Result &result,const FiniteStore &store) {\n out<<'['<<static_cast<int>(result.status)<<','<<result.failed_source<<',';\n out<<result.opened<<','<<result.lines<<','<<result.records<<','<<result.value<<\",[\";\n bool first=true;\n for (const Item &item:result.items) {\n if (!first) {\n out<<',';\n }\n first=false;\n print_item(out,item);\n }\n out<<\"],[\";\n first=true;\n for (const Event &event:store.events()) {\n if (!first) {\n out<<',';\n }\n first=false;\n print_event(out,event);\n }\n out<<\"],\"<<store.owned_live()<<','<<store.borrowed_live()<<',';\n out<<store.early_reads()<<','<<store.invalid_calls()<<\"]\\n\";\n}\n}\nint main() {\n std::ios::sync_with_stdio(false);\n int count;\n if (!resource::read_case_count(std::cin,count)) {\n std::cerr<<\"invalid case count\\n\";\n return 2;\n }\n for (int case_index=0;case_index<count;++case_index) {\n resource::CaseInput input;\n if (!resource::read_case(std::cin,input)) {\n std::cerr<<\"invalid observer input at case \"<<case_index<<'\\n';\n return 2;\n }\n resource::FiniteStore store(std::move(input.catalog));\n std::vector<resource::Source> sources;\n int opens=0;\n for (const auto &raw:input.sources) {\n resource::Source source{raw[0],raw[1],-1};\n if (raw[2]) {\n source.borrowed=store.borrow(raw[0]);\n } else {\n ++opens;\n }\n sources.push_back(source);\n }\n store.expect_opens(opens);\n resource::Result result=resource::execute(store,sources);\n resource::print_observation(std::cout,result,store);\n if (store.owned_live()!=0) {\n store.describe_live(std::cerr);\n }\n }\n return 0;\n}\n"
|
|
}
|