Repository navigation
AutoStory: CheckpointId value type - #520
Conversation
CheckpointId parses "SS.CC" ids like "03.08" (exactly two digits, a dot, two digits), prints them back, orders them, and starts_segment() tells a caller when a run enters a new segment so it can count Segments Started.
FRLG splits boss battles out of a checkpoint without renumbering the ones after it (00.12b, 12.02b). The suffix sorts after the bare id and before the next checkpoint; starts_segment ignores it.
dayfine
left a comment
There was a problem hiding this comment.
Reviewed SHA: 6d5cfa4
Verdict
NEEDS_REWORK
The parser is correct and well tested. The rework is the sentinel suffix (house style) plus small ordering nits. Note: Fork Draft CI's build was still pending when I read the checks; code-health and no-tabs passed.
Medium (style, the user's rule): char suffix = '\0' is a sentinel. Use std::optional<char> suffix;. This doesn't break anything:
- the defaulted
operator<=>still works, sincestd::optional<char>has<=>andnulloptorders before any value, so 12.02 < 12.02b < 12.02c holds without changes; parse()sets it only in the length-6 branch, andto_string()becomesif (suffix){ ret += *suffix; };- the order tests change from
{3, 8, '\0'}to{3, 8, std::nullopt}(or{3, 8}).
It also removes the comment 'a' to 'z', or '\0' for none, which explains the sentinel.
Low: segment and checkpoint have no default member initializer. A default-constructed CheckpointId holds indeterminate values. Give them = 0 (or = {}). Windows clang also warns on designated init with missing fields unless they have defaults.
Low: the public fields let invalid ids exist. CheckpointId{3, 8, 'B'} builds and prints "03.08B", which parse() rejects, and segment = 120 prints three digits. That's fine for a plain value type, but say in the header comment that parse() is the only validated way to build one, or make the fields private with an accessor. Your call; not blocking.
Nit: list order. In SourceFiles.cmake, the Pokemon_CheckpointId.* entries sit between AutoStorySelect and AutoStoryStats; alphabetically they go after AutoStoryStats_Tests.h. The same applies to the #include in ComputerPrograms_UnitTestRunner.cpp (the add_tests_CheckpointId call is already after Stats).
Nit: the test expectation has two parallel optionals. ParseExpectation{std::optional<std::string> id; std::optional<std::string> segment;} uses id for "accepted?" and then dereferences *expected.segment unguarded. If a future case sets id but forgets segment, that's UB. Use one std::optional<struct{std::string id; std::string segment;}>, or check segment before reading it.
Nit: the starts_segment header comment names AutoStoryStats::m_segments_started, which couples this file's doc to its caller. "The caller counts a segment start" is enough. That comment line is also over 100 columns.
Checked, OK:
- Parse edge cases: length 5/6 gate plus
text[2] == '.'(no out-of-range index: the length check comes first via||short-circuit). Two-digit fields reject signs, spaces and letters. A suffix must bea–z, so"03.08\0"(embedded NUL, length 6) is rejected too. "100.08", "03.100" and "03.081" fail on the length or dot position. std::format("{:02}", uint8_t)prints as an integer (unsigned charis an integer type forstd::format; onlycharprints as a character).- Member order (segment, checkpoint, suffix) gives the documented ordering; the tests cover equal, checkpoint, segment-over-checkpoint, none-before-suffix, letter order and suffix-before-next.
starts_segmentignores the suffix, as documented, and the tests cover a suffixed id at a segment boundary.- Test shape is name / input / expectation with nested structs;
std::string_viewis passed by value; it's registered in SourceFiles.cmake and the runner.
Counts: 1 medium, 2 low, 3 nits.
suffix is std::optional<char> instead of a '\0' sentinel, the fields have defaults and are private behind accessors, so parse() is the only way to build an id. Order tests take ids as text. The parse test expects one optional. Sorted the CMake list and the test-runner include; shortened the starts_segment comment.
…ostory/checkpoint-id
|
Review 5909634128, fixed in 6a78529 (then merged #519 in, c05380b):
|
dayfine
left a comment
There was a problem hiding this comment.
Reviewed SHA: c05380b
Verdict
APPROVED
Re-review of the commits since 6d5cfa4 (6a78529 and the base merge c05380b). Every item from the last review is fixed:
- Medium, sentinel suffix: it is now
std::optional<char> m_suffix.parse()sets it only for a validateda-zletter,to_string()appends*m_suffixonly when it is set, and the'\0'comment is gone. The defaulted<=>still orders nullopt before any letter, which the order tests check. - Low, no default initializers:
m_segment = 0,m_checkpoint = 0. - Low, invalid ids via public fields:
CheckpointIdis now a class with a private constructor and read-only accessors. The header saysparse()is the only way to build one. The order tests now build ids from strings throughparse()and fail loudly on bad test input, so the tests no longer need the constructor. - Nit, list order: the SourceFiles.cmake entries and the runner
#includenow come after AutoStoryStats. - Nit, two parallel optionals: these are now one
std::optional<ParsedId>, with no unguarded dereference. - Nit, starts_segment comment: the reference to
AutoStoryStats::m_segments_startedis gone, and the line is under 100 columns.
Merge c05380b: it brings in only the base's (#519) changes to AutoStoryStats and the SV AutoStoryTools. Its diff against autostory/shared-stats is exactly this PR's six files. The CheckpointId files keep CRLF on every line. The test helpers are in an anonymous namespace. Fork Draft CI (Ubuntu build + tests), code-health and no-tabs all pass at this SHA.
No new findings.
Counts: 0 blocking, 0 medium, 0 low, 0 nits.
Depends on #519
The new AutoStory programs need a real checkpoint id like
03.08for logs and stats instead of passing loose strings around. This addsPokemon::CheckpointId, which onlyparse()can build: it takes two digits, a dot, two digits and at most one lowercase letter (rejects03.08B,03.08bc,3.08,03.08.01and the like),to_string()andsegment_string()print it back, and ids order by segment, checkpoint, then letter (12.02 < 12.02b < 12.02c < 12.03). The letter exists because FRLG splits a boss battle out of a checkpoint without renumbering the ones after it (00.12b,12.02b).starts_segment(previous, next)tells a caller when a run enters a new segment so it can count Segments Started; the letter does not matter there. Nothing uses it yet; the story engine wires it in later. Tested with the new CheckpointId unit tests (parse table, ordering, segment starts), run by Fork Draft CI.