From 33ca4c218f7cf12519a995b701605853857e8ae7 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Fri, 20 Nov 2026 13:26:51 -0700 Subject: [PATCH] Check estimated seasons monthly, and write the season steps into the audit --- .github/workflows/season-check.yml | 26 ++++++++++ docs/audit.md | 12 +++++ tools/tests/test_season_audit.py | 80 ++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 .github/workflows/season-check.yml create mode 100644 docs/audit.md create mode 100644 tools/tests/test_season_audit.py diff --git a/.github/workflows/season-check.yml b/.github/workflows/season-check.yml new file mode 100644 index 0000000..35c32fc --- /dev/null +++ b/.github/workflows/season-check.yml @@ -0,0 +1,26 @@ +name: Season check + +# Once a month, rerun the machine estimate for every estimated season and the fit against the +# sourced seasons. A failure lists the estimates whose inputs have changed; see docs/audit.md. +on: + schedule: + - cron: "17 6 1 * *" + workflow_dispatch: + +jobs: + check: + runs-on: ubuntu-latest + timeout-minutes: 120 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + - id: month + run: echo "month=$(date +%Y-%m)" >> "$GITHUB_OUTPUT" + - uses: actions/cache@v4 + with: + path: ~/.cache/longhikes-climate + key: climate-${{ steps.month.outputs.month }} + restore-keys: climate- + - run: python3 tools/estimate_season.py check diff --git a/docs/audit.md b/docs/audit.md new file mode 100644 index 0000000..4c363f8 --- /dev/null +++ b/docs/audit.md @@ -0,0 +1,12 @@ +# The monthly audit + +The checklist for the roughly monthly audit of everything. `/refresh-trails` (`.claude/skills/refresh-trails/SKILL.md`) is the step for pages and records. Each section below is one topic, with its own numbered steps. A section is self-contained: it says what to run, what to act on, and when the step is done. + +## Seasons + +Every trail has a season. Where a page states one, the season is that page's. Where none does, the season is an estimate: set by a reviewer from the trail's climate and the seasons of similar trails, with its confidence on the record (`docs/season-judging.md`). The aim of this audit is that estimates shrink over time, and that none goes stale unnoticed. + +1. Search afresh for a page that states the season of every trail still marked `estimate`. List them with `python3 tools/estimate_season.py estimates`. For each, follow `docs/season-research.md`: the trail's holder or a government page first, then an established hiking reference, a guidebook publisher's page or an association list. When a page states a season, replace the estimate through `tools/refresh.py` (propose, collect, apply): give the page's season and months, the basis (`primary`, `sources` or `source`), the page as a `[[hike.source]]` naming `season` and `months`, and remove the climate source and `season_method`. A change to the season gets a `[[history]]` entry like any other fact. Then run `python3 tools/season_judge.py inputs` so that the record of estimate inputs drops the trail. A trail with no page found stays an estimate, and nothing else about it changes. +2. Re-run the machine estimate and flag any estimate whose inputs have changed: `python3 tools/estimate_season.py check`. It reruns the machine estimate for every estimate, compares it, the climate at the trail and the sourced trails it is compared with against what was recorded in `tools/season_inputs.json` when the season was set, and lists each trail whose inputs differ. The listing is a flag, not a rewrite. For each trail listed, build its packet (`python3 tools/season_judge.py packets`), look at what changed, and either keep the season or set it again by judgement. Then run `python3 tools/season_judge.py inputs` to record the inputs as they now are. The check also fails when the blind test of the method (`tools/season_blind_test.json`) is below its bar, or when the fit of the machine estimate against the sourced seasons has got worse. + +The same check runs on its own on the first of each month (`.github/workflows/season-check.yml`), so a changed estimate is noticed even when the audit is late. The audit is still the step that acts on it. diff --git a/tools/tests/test_season_audit.py b/tools/tests/test_season_audit.py new file mode 100644 index 0000000..5cb1ccb --- /dev/null +++ b/tools/tests/test_season_audit.py @@ -0,0 +1,80 @@ +"""Tests for the written audit checklist and the monthly season check. + +Run from the repository root: + python3 -m unittest discover tools/tests +""" +import os +import re +import sys +import unittest + +sys.dont_write_bytecode = True +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + +import estimate_season as E # noqa: E402 + +ROOT = E.ROOT + + +def read(*parts): + with open(os.path.join(ROOT, *parts), encoding="utf-8") as f: + return f.read() + + +def section(text, heading): + start = text.index(f"## {heading}") + nxt = text.find("\n## ", start + 1) + return text[start:nxt if nxt != -1 else len(text)] + + +class AuditChecklistTest(unittest.TestCase): + def test_the_audit_checklist_has_a_seasons_section_naming_both_steps(self): + doc = read("docs", "audit.md") + seasons = section(doc, "Seasons") + self.assertIn("estimate_season.py check", seasons) + self.assertIn("estimate_season.py estimates", seasons) + self.assertIn("docs/season-research.md", seasons) + self.assertIn("search afresh for a page that states the season", seasons.lower().replace("\n", " ")) + self.assertIn("re-run the machine estimate", seasons.lower()) + self.assertIn("1. ", seasons) + self.assertIn("2. ", seasons) + + def test_the_commands_it_names_exist(self): + import contextlib + import io + import season_judge + for module, subs in ((E, ("check", "estimates")), (season_judge, ("inputs", "packets", "score", "proposals"))): + for sub in subs: + out = io.StringIO() + with contextlib.redirect_stdout(out), self.assertRaises(SystemExit) as stop: + module.main([sub, "--help"]) + self.assertEqual(stop.exception.code, 0, sub) + self.assertIn(f" {sub}", out.getvalue()) + + def test_the_estimates_command_prints_one_id_a_line(self): + ids = E.estimates(ROOT) + self.assertEqual(len(ids), 69) + self.assertEqual(ids, sorted(ids)) + + def test_house_wording_in_the_audit_doc_and_workflow(self): + dash = re.compile("[\u2013\u2014]") + for rel in (("docs", "audit.md"), ("docs", "season-judging.md")): + text = re.sub(r"`[^`]*`", "", read(*rel)) + self.assertIsNone(dash.search(text), rel) + self.assertNotIn(" - ", text, rel) + # in the workflow a dash is YAML's own, so only its comments are read + comments = " ".join(l for l in read(".github", "workflows", "season-check.yml").splitlines() + if l.lstrip().startswith("#")) + self.assertIsNone(dash.search(comments)) + self.assertNotIn(" - ", comments) + + +class MonthlyWorkflowTest(unittest.TestCase): + def test_the_monthly_workflow_runs_the_check_on_a_schedule(self): + text = read(".github", "workflows", "season-check.yml") + for want in ("schedule", "workflow_dispatch", "estimate_season.py check", "cron:", "longhikes-climate"): + self.assertIn(want, text) + + +if __name__ == "__main__": + unittest.main()