Skip to content

fix(data): save entries.json atomically and reject a boolean version - #202

Merged
jamesconwaydev merged 1 commit into
devstreamhq:mainfrom
foothillsdigital:fix/entries-save-validate
Nov 6, 2026
Merged

jamesconwaydev merged 1 commit into
devstreamhq:mainfrom
foothillsdigital:fix/entries-save-validate

Conversation

@foothillsdigital

Copy link
Copy Markdown
Collaborator

What and why

Closes #50.

  • Atomic save. save() writes entries.json.tmp beside the target, then os.replaces it over the original, so a crash or full disk mid-write leaves the old file intact. The temp file is removed if anything fails. Same directory, so the rename never crosses filesystems.
  • Version check. True == 1 and 1.0 == 1 in Python, so both passed. The CLI now requires type(version) is int.
  • One status list. Status is the Literal, and STATUSES = get_args(Status). A new test checks that schema.json's enum matches it, so the third copy can't drift either.
  • Validator tests now assert the exact messages instead of "some error". A new CLI test covers exit 0 for a good file and exit 1 (with the message) for version: true, version: 1.0, a non-list entries, a missing entries, a bad entry and invalid JSON.

The save and CLI tests fail on main and pass here.

Checks

  • The PR title follows Conventional Commits
  • python3 -m unittest discover -s scripts -t . passes
  • npm --prefix site test passes (if you touched site/)
  • npx prettier --check . passes
  • This doesn't edit data/entries.json by hand (submissions go through the form)

save() now writes a temp file beside entries.json and renames it over
the old one, so a crash mid-write can no longer leave a broken file.

The validator checked version with ==, so true and 1.0 passed as 1.
It now needs the integer 1.

Statuses are defined once, as the Status Literal, and STATUSES comes
from it. A test checks they match schema.json, and the validator
tests now assert the exact messages and the CLI exit codes.

@jamesconwaydev jamesconwaydev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice. The True == 1 catch is a good one, and tying STATUSES to the Literal (with the schema test) kills the drift for good. Same-directory temp file plus os.replace is exactly right.

@jamesconwaydev
jamesconwaydev merged commit e543db6 into devstreamhq:main Nov 6, 2026
9 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.

Make entries.json saves atomic and tighten validation

2 participants