Skip to content

AutoStory: CheckpointId value type - #520

Merged
dayfine merged 6 commits into
mainfrom
autostory/checkpoint-id
Nov 15, 2026
Merged

dayfine merged 6 commits into
mainfrom
autostory/checkpoint-id

Conversation

@dayfine

@dayfine dayfine commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Depends on #519

The new AutoStory programs need a real checkpoint id like 03.08 for logs and stats instead of passing loose strings around. This adds Pokemon::CheckpointId, which only parse() can build: it takes two digits, a dot, two digits and at most one lowercase letter (rejects 03.08B, 03.08bc, 3.08, 03.08.01 and the like), to_string() and segment_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.

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 dayfine left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, since std::optional<char> has <=> and nullopt orders before any value, so 12.02 < 12.02b < 12.02c holds without changes;
  • parse() sets it only in the length-6 branch, and to_string() becomes if (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 be a–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 char is an integer type for std::format; only char prints 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_segment ignores 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_view is 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.
@dayfine

dayfine commented Nov 15, 2026

Copy link
Copy Markdown
Owner Author

Review 5909634128, fixed in 6a78529 (then merged #519 in, c05380b):

  • suffix is std::optional<char>; the '\0' sentinel and its comment are gone.
  • CheckpointId is a class: private fields with defaults (= 0), accessors segment(), checkpoint(), suffix(), and a private constructor, so parse() is the only way to build one. The order tests now take ids as text and parse them.
  • The parse test expects one std::optional<ParsedId> instead of two parallel optionals.
  • SourceFiles.cmake entries and the test-runner include now sort after AutoStoryStats.
  • The starts_segment comment no longer names the caller's counter.

@dayfine dayfine left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 validated a-z letter, to_string() appends *m_suffix only 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: CheckpointId is now a class with a private constructor and read-only accessors. The header says parse() is the only way to build one. The order tests now build ids from strings through parse() 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 #include now 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_started is 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.

@dayfine
dayfine changed the base branch from autostory/shared-stats to main November 15, 2026 19:15
@dayfine
dayfine marked this pull request as ready for review November 15, 2026 19:15
@dayfine
dayfine merged commit cefa330 into main Nov 15, 2026
10 checks passed
dayfine added a commit that referenced this pull request Nov 15, 2026
dayfine added a commit that referenced this pull request Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant