Skip to content

Parse ISO dates strictly: fixed-width digits, plain decimal seconds - #52

Merged
dmccoystephenson merged 2 commits into
mainfrom
feat/strict-iso-date-parsing
Nov 15, 2026
Merged

dmccoystephenson merged 2 commits into
mainfrom
feat/strict-iso-date-parsing

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Summary

  • parseIsoDate (src/orrery/time.cpp) no longer uses sscanf %d / %lf. Each field is read as exactly its width in ASCII digits (YYYY-MM-DD, HH:MM, SS), and seconds as two digits with an optional decimal fraction. Signed fields, short fields (2026-1-5), a space before the hour, and exponent or hex-float seconds (1e1, 0x10) are now rejected, as the header already promised. Text after an embedded NUL is rejected too.
  • The fraction is kept as an integer numerator (up to 15 digits) and divided once, so 15.3 reads as the double nearest 15.3.
  • The header comment in src/orrery/time.hpp now also names the decimal-fraction seconds form (already accepted and tested) and that a failure leaves out unchanged (already tested).
  • tests/test_time.cpp gains a section with 19 rejection cases from the issue and its neighbours, the embedded-NUL case, and three fractional-seconds acceptance checks. No existing CHECK was changed.

Every documented form (README.md --date examples, the J entry, orrery --help's YYYY-MM-DD[THH:MM[:SS]]) and every date the app writes (formatIsoDate uses %04d-%02d-%02d %02d:%02d:%02d) still parses. Only src/orrery/ changed; no data, tolerance, strata.ref or workflow file is touched.

Closes #51

Test plan

  • CI Data, ephemeris tests, render smoke test green on the PR head (runs test_time with -Werror)
  • Local build: UNVERIFIED. The dispatch sandbox refused to run cmake and g++ here, so the CI run on the exact head SHA is the anchor.
  • Regression proof (new rejection tests fail against the old parser): not run. A temporary revert on the PR head is not used in a headless dispatch, and no earlier test asserted the old behaviour. This has to be checked by a human before merge.

This PR description was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).


drafted by Claude on behalf of Daniel Stephenson

parseIsoDate read each field with sscanf %d / %lf, so it took
"2026-1-5", signed fields, a space before the hour, and seconds written
"1e1" or "0x10" -- none of which its header documents. Each field is now
read as exactly its width in ASCII digits, and seconds as two digits with
an optional decimal fraction. Text after an embedded NUL is rejected too.

Closes #51

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the changes tightening parseIsoDate input validation.

No open issues 🎉

What changed in this PR

Tightens parseIsoDate to match its documented input formats, addressing issue #51 while preserving supported date and time forms.

Changes:

  • Replaces sscanf parsing with fixed-width ASCII digit checks and plain decimal seconds parsing.
  • Rejects trailing content after embedded NULs and adds malformed-input and fractional-seconds regression tests.
  • Clarifies that fractional seconds are supported and failed parsing leaves the output unchanged.
File Description
tests/​test_time.cpp Adds rejection cases and fractional-seconds acceptance checks.
src/​orrery/​time.hpp Clarifies the parser’s format and failure guarantees.
src/​orrery/​time.cpp Implements strict field parsing and full-input validation.

Review effort: Balanced

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dmccoystephenson

Copy link
Copy Markdown
Member Author

Self-review rubric (Copilot review request did not register: reviewRequests came back empty after gh pr edit 52 --add-reviewer @copilot, so this rubric is the review of record):

  • Scope: PASS. The diff touches src/orrery/time.cpp (the parser), src/orrery/time.hpp (its header comment), tests/test_time.cpp (new cases) and one sentence of README.md (the test_time description). All four are needed for parseIsoDate accepts forms its header says it rejects #51.
  • Tests-new: PASS. The new anonymous-namespace helpers (isDigit, readDigits, expect) are internal. They are exercised through parseIsoDate by the new section "ISO date parsing: every field has its fixed width in digits".
  • Tests-fix: FAIL (not established). The sandbox refused to run cmake and g++ here, so the new tests could not be run against the reverted parser. Ladder rung 1 (a temporary revert pushed to the PR head) is not used in a headless dispatch. Rung 2 does not apply because no earlier test asserted the old, looser behaviour. Under the regression gate the PR is therefore handed off rather than merged. A local ctest -R time with git checkout origin/main -- src/orrery/time.cpp should fail on cases such as 2026-1-5, 2026-10-18T 6:30, 2026-10-18T06:30:1e1 and 2026-10-18T06:30:0x10.
  • Sibling structure: PASS. The new test section uses the file's existing SECTION / for (const char* bad : {...}) CHECK_MSG(...) pattern.
  • Sibling renames: N/A. Nothing was renamed.
  • Docs: PASS after one fix. These rows were checked:
    • README --date examples, the J row in Controls, and usage()'s YYYY-MM-DD[THH:MM[:SS]]: all are still accepted.
    • web/shell.html <input type="date"> emits YYYY-MM-DD, which is still accepted.
    • formatIsoDate output (%04d-%02d-%02d %02d:%02d:%02d) still parses back.
    • README line 315 (the test_time description) was corrected in the second commit to name the new rejection classes.
    • DATA_SOURCES.md and CMakeLists.txt: not affected.
  • Visuals: N/A. Nothing drawn changed.
  • Issue resolution: PASS. Every form parseIsoDate accepts forms its header says it rejects #51 lists (2026-1-5, 2026-+10-18 style signs, T 6:30, 1e1, 0x10) is now rejected and has a test case. The header now describes what is accepted.
  • CI: PASS. Both Data, ephemeris tests, render smoke test (ctest 18/18 passed, including time, on the first head) and Web build and smoke test (headless Chromium) are green on the current head.
  • Privacy: PASS. The only repos named are this public repository itself (the visibility API call was not permitted in this sandbox) and the Gardener link required by the dispatch. There are no addresses or coordinates.
  • Tolerances: PASS. No existing CHECK or tolerance was changed. Only additions are in tests/.
  • Derived data: N/A. No data, strata.ref, data/kernels.sha256 or .gitignore changes.
  • Sources: N/A. No new body or constant.
  • Core purity: PASS. Only <cstddef> was added to src/orrery/time.cpp.
  • Docs follow the change: PASS. No new option or key.

Out-of-diff observation: src/orrery/time.cpp:139 compares the consumed length to text.size() so that std::string input with an embedded NUL is rejected. The C-string entry point orrery_set_date (app/main.cpp:872) cannot carry one, so that check only matters for C++ callers.

Summary: the change is green in CI, but the regression proof required by the merge gate could not be produced in this sandbox, so the PR is left open for a human to confirm FAIL→PASS locally.

This review was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).


drafted by Claude on behalf of Daniel Stephenson

@dmccoystephenson

Copy link
Copy Markdown
Member Author

Status re-check (a later dispatch cycle), with the PR still handed off:

  • Branch currency: the PR's merge base equals origin/main HEAD (7f8e6ef), and GitHub reports it MERGEABLE / CLEAN. No rebase was needed.
  • CI: both Data, ephemeris tests, render smoke test and Web build and smoke test (headless Chromium) are green on head 8b31af9.
  • Review: the Copilot review arrived after the self-review was posted and recommends approval with no open issues. The diff was read again in full, and no blocking finding was raised. The rejection cases match the new readDigits/expect paths. formatIsoDate output (%04d-%02d-%02d %02d:%02d:%02d) and every documented --date form still go through the accepting path. The exact-equality fraction checks (15.25, 15.3, 59.999) pass in CI.
  • Regression gate: still not satisfied. Compilers (g++, cmake) were again refused by this dispatch's sandbox, so the new tests could not be run against the old parser. CI only runs on pushes to main and on pull requests, so a throwaway revert branch could not produce a red run without opening a second PR. A temporary revert on this PR's head is not used in a headless dispatch.

To clear the gate locally:

git checkout origin/main -- src/orrery/time.cpp && cmake --build build -j4 && ctest --test-dir build -R time   # expect FAIL (e.g. "2026-1-5", "2026-10-18T06:30:1e1")
git checkout HEAD -- src/orrery/time.cpp && cmake --build build -j4 && ctest --test-dir build -R time            # expect PASS

If that confirms FAIL→PASS, the PR is ready to squash-merge.

This comment was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).


drafted by Claude on behalf of Daniel Stephenson

@dmccoystephenson

Copy link
Copy Markdown
Member Author

Review re-run in a third dispatch cycle. The PR remains handed off.

  • State: head 8b31af9, merge base equal to main HEAD 7f8e6ef, MERGEABLE / CLEAN. Data, ephemeris tests, render smoke test and Web build and smoke test (headless Chromium) are both green.

  • Diff re-read, with no new findings. Every parseIsoDate call site was checked against the stricter grammar:

    • app/main.cpp:1016-1019: the smoke-test dates are all "2026-10-18".
    • app/main.cpp:947: --date, as usage() documents it.
    • app/main.cpp:323: mission dates. Each one is parsed by tests/test_missions.cpp:81, which is green in CI on this head.
    • app/main.cpp:583: the J entry.
    • app/main.cpp:874: orrery_set_date from the browser's <input type="date">.

    None of these depend on a short, signed or padded field, or on a year outside four digits. DE440s coverage (1849–2150) is inside the four-digit range anyway.

  • Regression gate: still not satisfied. g++ and cmake were refused by this dispatch's sandbox again. CI has no workflow_dispatch trigger and runs only on pushes to main and on pull requests. Both remaining automated routes need something this loop does not do on its own: a revert pushed to this PR's head (excluded in headless runs), or a second throwaway PR (excluded while this PR is open).

What unblocks the merge is the local FAIL→PASS check already given in the comment above (git checkout origin/main -- src/orrery/time.cpp, then ctest -R time should fail; restoring it, the test should pass). Alternatively, the owner can explicitly allow a throwaway draft PR that reverts only src/orrery/time.cpp on top of this branch to get the red CI run.

This comment was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).


drafted by Claude on behalf of Daniel Stephenson

@dmccoystephenson
dmccoystephenson merged commit f1071fb into main Nov 15, 2026
2 checks passed
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.

parseIsoDate accepts forms its header says it rejects

2 participants