state: a state file without a section loads it empty (closes #267) #278

Merged
clawbot merged 1 commits from fix/267-state-missing-sections into next 2026-10-13 20:27:27 +02:00
Collaborator

Fixes #267.

Load now gives an empty map to each of domains, hostnames, ports and certificates that the state file leaves out or holds as null. Before this, such a section loaded as a nil map. The first check then panicked writing into it, so a state file holding {} stopped the process at every start.

A state test loads {}, then a file missing each section in turn, and checks that every section is an empty map. A watcher test loads {}, and a file without the certificates section, runs the first check against live DNS through runChecks, and checks that the check saved domain, hostname, port and certificate entries. One added sentence in the README's State File Format section says what such a file loads as.

  • Judgement call: the watcher test loads two of the five files, not all five, since each runs a domain check against live DNS; the state test covers all five.
  • Judgement call: a file holding {} still loads with version 0. Nothing reads the version, so Load leaves it as it was loaded.

Model: opus-5-5

Fixes https://git.eeqj.de/sneak/dnswatcher/issues/267. `Load` now gives an empty map to each of `domains`, `hostnames`, `ports` and `certificates` that the state file leaves out or holds as `null`. Before this, such a section loaded as a nil map. The first check then panicked writing into it, so a state file holding `{}` stopped the process at every start. A state test loads `{}`, then a file missing each section in turn, and checks that every section is an empty map. A watcher test loads `{}`, and a file without the `certificates` section, runs the first check against live DNS through `runChecks`, and checks that the check saved domain, hostname, port and certificate entries. One added sentence in the README's State File Format section says what such a file loads as. - Judgement call: the watcher test loads two of the five files, not all five, since each runs a domain check against live DNS; the state test covers all five. - Judgement call: a file holding `{}` still loads with `version` 0. Nothing reads the version, so `Load` leaves it as it was loaded. Model: opus-5-5
clawbot added the needs-review label 2026-10-13 18:53:26 +02:00
clawbot self-assigned this 2026-10-13 18:53:26 +02:00
Author
Collaborator

Review: FAIL

  • internal/state/state_test.go, TestLoadFileWithoutSections: the "Done when" of #267 asks for a test showing that the first check runs after loading {} or a file missing a section. This test calls the four setters and never runs a check. Live DNS is no reason to leave it out, because the watcher tests already run first checks against live DNS through runChecks, and its prepare function can write the state file and call Load. Acceptable: a watcher test that writes {}, and a file missing a section, to the state file, loads it in prepare, runs the first check with runChecks, and checks that the check saved domain, hostname, port and certificate entries.
  • The branch conflicts with current next in TODO.md Completed Steps only. Rebase, keeping every entry with this PR's on top.

Model: opus-5-5

Review: FAIL - `internal/state/state_test.go`, `TestLoadFileWithoutSections`: the "Done when" of https://git.eeqj.de/sneak/dnswatcher/issues/267 asks for a test showing that the first check runs after loading `{}` or a file missing a section. This test calls the four setters and never runs a check. Live DNS is no reason to leave it out, because the watcher tests already run first checks against live DNS through `runChecks`, and its `prepare` function can write the state file and call `Load`. Acceptable: a watcher test that writes `{}`, and a file missing a section, to the state file, loads it in `prepare`, runs the first check with `runChecks`, and checks that the check saved domain, hostname, port and certificate entries. - The branch conflicts with current `next` in `TODO.md` Completed Steps only. Rebase, keeping every entry with this PR's on top. Model: opus-5-5
clawbot added needs-rework and removed needs-review labels 2026-10-13 19:34:33 +02:00
clawbot added 1 commit 2026-10-13 20:06:17 +02:00
Load fills in each of domains, hostnames, ports and certificates that
the file leaves out or holds as null with an empty map. Before, such a
section loaded as a nil map, and the first check's write into it
panicked, so a state file holding {} stopped the watcher at every
start.

A state test loads {} and a file missing each section in turn, and
checks that every section is an empty map. A watcher test loads {}, and
a file without the certificates section, runs the first check against
live DNS, and checks that it saved domain, hostname, port and
certificate entries.

Model: opus-5-5
clawbot force-pushed fix/267-state-missing-sections from d6f6132951 to 83b68923d9 2026-10-13 20:06:17 +02:00 Compare
Author
Collaborator

Rework:

  • First check: new watcher test TestFirstCheckAfterLoadingFileWithoutSections writes {}, and a file without the certificates section, loads it in prepare, runs the first check with runChecks, and checks that domain, hostname, port and certificate entries were saved. TestLoadFileWithoutSections now only checks the empty maps.
  • TODO.md: rebased onto current next; every Completed Steps entry kept, this PR's on top.

Model: opus-5-5

Rework: - First check: new watcher test `TestFirstCheckAfterLoadingFileWithoutSections` writes `{}`, and a file without the `certificates` section, loads it in `prepare`, runs the first check with `runChecks`, and checks that domain, hostname, port and certificate entries were saved. `TestLoadFileWithoutSections` now only checks the empty maps. - `TODO.md`: rebased onto current `next`; every Completed Steps entry kept, this PR's on top. Model: opus-5-5
clawbot added needs-review and removed needs-rework labels 2026-10-13 20:06:31 +02:00
Author
Collaborator

Review: PASS

Model: opus-5-5

Review: PASS Model: opus-5-5
clawbot removed the needs-review label 2026-10-13 20:18:20 +02:00
clawbot merged commit 9e6871817a into next 2026-10-13 20:27:27 +02:00
clawbot deleted branch fix/267-state-missing-sections 2026-10-13 20:27:28 +02:00
Sign in to join this conversation.