openspec(backport-keg-catalog): apply artifacts

Implementation is on agent/backport-keg-catalog. Groups 1-4 and 6.1-6.3
are done; group 5 (on-device) is blocked on the repo owner and the reason
is recorded in tasks.md.

Two artifact corrections that came out of the apply phase:

design.md now cherry-picks Brett's commit instead of copying the file.
The original decision rejected a cherry-pick on the assumption that the
pre-v0.1 merge-base would make it conflict. Wrong: 0982d20 touches one
file, and that file at 0982d20^ is byte-identical to master's, so only
the touched blob has to match and it applies clean. This is the better
option anyway — copying would have landed 28 observed keg names under the
committer's name with the author erased, whereas the cherry-pick keeps
Brett as author and carries the commit message that documents the
provenance and each of the four corrections.

design.md also records a trap found while writing the tests, because it
invalidates the provenance-marker idea the risks section suggested:
_load_keg_catalog builds {int(k): v ...} and catches ValueError by
returning {}, so adding a "_meta" or "_source" key to the catalog would
disable it entirely and leave every keg with no name, logged only at
debug level. Embedding metadata requires changing the loader first.
This commit is contained in:
2026-09-06 16:19:53 +02:00
parent de326cb3ad
commit 3ddd4684e3
2 changed files with 48 additions and 22 deletions
@@ -36,8 +36,17 @@ Provenance of the added data, from the fork's commit `0982d20`: the product IDs
## Decisions
**Take the fork's file wholesale rather than merging entry-by-entry.**
The fork's version is a strict superset of ours except for the four corrections, and it preserves our formatting convention (no indentation, numeric key order). Copying the file gives the same result as a hand-merge with less room for transcription error, and the resulting diff is reviewable line-by-line anyway. Alternative considered: cherry-pick `0982d20`. Rejected because the histories share only a pre-v0.1 merge-base, so a cherry-pick would drag in unrelated context and conflict; the file is self-contained data and copying it is cleaner than fighting git.
**Cherry-pick Brett's commit rather than copying the file.**
*Revised during apply — the original decision here was to copy the file and reject a cherry-pick on the assumption that the pre-v0.1 merge-base would make it conflict. That assumption was wrong and worth correcting, because the cherry-pick is the better option on both provenance and credit.*
`0982d20` touches exactly one file, and that file at `0982d20^` is byte-identical to `master`'s copy. The merge-base is irrelevant: a cherry-pick only needs the touched blob to match, so it applies cleanly with no conflict.
That matters beyond convenience. Copying the data would land 28 observed keg names under the committer's name with the original author erased from the record. Cherry-picking preserves `Brett Jenkins <brett@brettjenkins.co.uk>` as author and carries his commit message — which is where the provenance actually lives, since it documents that the IDs were observed from machines and explains each of the four corrections. `-x` records the source SHA, and `Backported-from` / `Backported-via` trailers name the fork and PR, which the bare SHA does not.
So the attribution is structural rather than a courtesy note: `git log --author` and `git blame` both attribute the catalog correctly, permanently, with no dependence on anyone remembering to mention it.
Rick's own follow-up work (version bump, README credit, format tests) goes in a separate commit so Brett's stays pure data.
**Accept the four name corrections, reject the eleven styling changes.**
The corrections fix real errors: `32814` displays a beer that no longer exists under that name, and three entries carry shop-listing cruft (`Short Date`, `6L Keg`, a 2024 best-before date) that is not part of the beer's name. The styling differences (`Trooper`/`TROOPER`, `St`/`Saint Feuillien`) are cosmetic, the current spellings match the shop, and changing them would churn the diff for no user benefit. This matches the fork author's own reasoning.
@@ -59,7 +68,9 @@ Adding catalog data changes no behaviour contract and no requirement that existi
**The four corrections surprise a user whose automation matches on the `Keg` sensor's string** → Real but unavoidable; the current strings are wrong. Three of them contain a 2024 best-before date or a pack size, which no sane automation would match deliberately. Call the corrections out in the release notes.
**The catalog keeps drifting as PerfectDraft adds products, and nothing records where these names came from** → Out of scope here, but worth its own change. Today the only record that these entries were measured rather than guessed is a commit message on someone else's fork. Options for later: a `_meta` key in the catalog, or making an unmapped ID surface the raw product number so users can report gaps.
**The catalog keeps drifting as PerfectDraft adds products** → Out of scope here, but worth its own change. Partly mitigated now: the cherry-pick puts the provenance in `git log` and `git blame` rather than in a commit message on someone else's fork, and the README explains why the file is hand-maintained and how to report a missing ID.
**A future attempt to embed metadata in the catalog would silently disable it** → Discovered during apply, and it invalidates the obvious next step. `_load_keg_catalog` builds `{int(k): v for k, v in raw.items()}` and catches `ValueError` by returning `{}`. So adding a `_meta` or `_source` key — the natural way to record provenance in the file itself — makes `int("_meta")` raise, swallows the exception, and leaves every keg with no name and only a debug-level log line. Any such change must touch the loader first. `tests/test_keg_catalog.py::test_keys_are_numeric` now fails loudly if anyone tries, and documents why in its docstring.
## Open Questions
+34 -19
View File
@@ -1,33 +1,48 @@
## 1. Set up the worktree
- [ ] 1.1 Create the isolated worktree and branch: `scripts/agent-worktree.sh create backport-keg-catalog`
- [ ] 1.2 Write `.agent-lock` in `.worktree/backport-keg-catalog` with owner, task, and timestamp
- [ ] 1.3 Confirm the fork's catalog is available to copy from — clone `https://github.com/brettjenkins/hassio-integration-perfectdraft-pro.git` to a scratch dir if `/tmp/bj-fork` is gone, and verify `git show origin/master:custom_components/perfectdraft/keg_catalog.json` parses as JSON with 114 entries
- [x] 1.1 Create the isolated worktree and branch: `scripts/agent-worktree.sh create backport-keg-catalog`
- [x] 1.2 Write `.agent-lock` in `.worktree/backport-keg-catalog` with owner, task, and timestamp
- [x] 1.3 Confirm the fork's catalog is available to copy from — clone `https://github.com/brettjenkins/hassio-integration-perfectdraft-pro.git` to a scratch dir if `/tmp/bj-fork` is gone, and verify `git show origin/master:custom_components/perfectdraft/keg_catalog.json` parses as JSON with 114 entries
## 2. Backport the catalog data
- [ ] 2.1 Record the pre-change baseline: entry count (expect 86) and the current names for IDs 32814, 43235, 44331, 44536
- [ ] 2.2 Copy the fork's `custom_components/perfectdraft/keg_catalog.json` over the worktree's copy
- [ ] 2.3 Diff against `master` and confirm the change is exactly 28 added IDs, 4 changed names, and one added trailing newline — no reordering, no reindentation, no other name edits
- [ ] 2.4 Confirm the 4 changed names are only the intended ones: 32814 → "Romola", 43235 → "Corona Cero (0.0% abv)", 44331 → "Ninkasi Flower Lager", 44536 → "Tiny Rebel Stay Puft"
- [ ] 2.5 Confirm none of the 11 styling-only differences were pulled in (spot-check Trooper and St Feuillien)
- [x] 2.1 Record the pre-change baseline: entry count (expect 86) and the current names for IDs 32814, 43235, 44331, 44536
- [x] 2.2 Copy the fork's `custom_components/perfectdraft/keg_catalog.json` over the worktree's copy
- [x] 2.3 Diff against `master` and confirm the change is exactly 28 added IDs, 4 changed names, and one added trailing newline — no reordering, no reindentation, no other name edits
- [x] 2.4 Confirm the 4 changed names are only the intended ones: 32814 → "Romola", 43235 → "Corona Cero (0.0% abv)", 44331 → "Ninkasi Flower Lager", 44536 → "Tiny Rebel Stay Puft"
- [x] 2.5 Confirm none of the 11 styling-only differences were pulled in (spot-check Trooper and St Feuillien)
## 3. Verify the file mechanically
- [ ] 3.1 Assert `json.load` succeeds and `len()` is exactly 114 — a duplicate key would silently collapse and change the count
- [ ] 3.2 Assert every key parses as an int and every value is a non-empty string
- [ ] 3.3 Assert keys are in ascending numeric order
- [ ] 3.4 Assert no value contains shop-listing artefacts: `6L`, `Short Date`, or `BBE`
- [ ] 3.5 Assert all 86 original IDs are still present (superset check)
- [ ] 3.6 Import `sensor.py`'s loader against the new file and confirm `_KEG_CATALOG` has 114 int-keyed entries
- [x] 3.1 Assert `json.load` succeeds and `len()` is exactly 114 — a duplicate key would silently collapse and change the count
- [x] 3.2 Assert every key parses as an int and every value is a non-empty string
- [x] 3.3 Assert keys are in ascending numeric order
- [x] 3.4 Assert no value contains shop-listing artefacts: `6L`, `Short Date`, or `BBE`
- [x] 3.5 Assert all 86 original IDs are still present (superset check)
- [x] 3.6 Import `sensor.py`'s loader against the new file and confirm `_KEG_CATALOG` has 114 int-keyed entries
## 4. Bump the version
- [ ] 4.1 Set `custom_components/perfectdraft/manifest.json` version to `0.3.2` — continuing from 0.3.1, not from the fork's 0.4.1
- [ ] 4.2 Leave `hacs.json` untouched, including the `homeassistant: 2024.11.0` floor
- [x] 4.1 Set `custom_components/perfectdraft/manifest.json` version to `0.3.2` — continuing from 0.3.1, not from the fork's 0.4.1
- [x] 4.2 Leave `hacs.json` untouched, including the `homeassistant: 2024.11.0` floor
## 5. Verify on the machine
**BLOCKED — needs the repo owner.** No Home Assistant instance is reachable from the
dev host (nothing on `localhost:8123`), and the standalone route failed too: the
refresh token in `.credentials.json` is expired, so `refresh_access_token()` returns
`NotAuthorizedException: Refresh Token has expired`. Recovering it needs the browser
reCAPTCHA step from the README, which only the owner can do.
Note also that `test_harness.py` expects a `user_id` key that `.credentials.json` no
longer has — pre-existing drift, unrelated to this change, left alone.
Static verification stands in for now and is recorded in groups 2 and 3: the diff shape
is confirmed exactly (28 added, 0 removed, 4 changed), the loader transform was
reproduced to 114 int keys, and `tests/test_keg_catalog.py` guards the format
permanently. What remains unproven is only that the live integration still resolves the
fitted keg after the file was replaced wholesale.
- [ ] 5.1 Deploy to Home Assistant and reload the integration
- [ ] 5.2 Confirm the `Keg` sensor still resolves the currently fitted keg's name correctly (regression check — the file was replaced wholesale)
- [ ] 5.3 Confirm the `Keg Product` sensor reports the same product ID as before the change
@@ -36,9 +51,9 @@
## 6. Sync specs and close out
- [ ] 6.1 Run `openspec validate --changes backport-keg-catalog` and fix any reported issues
- [ ] 6.2 Commit in the worktree with a message explaining the provenance of the data and naming the 4 corrections
- [ ] 6.3 Mark tasks complete and commit the artifact updates in the main checkout
- [x] 6.1 Run `openspec validate --changes backport-keg-catalog` and fix any reported issues
- [x] 6.2 Commit in the worktree with a message explaining the provenance of the data and naming the 4 corrections
- [x] 6.3 Mark tasks complete and commit the artifact updates in the main checkout
- [ ] 6.4 Sync the `entities` delta into `openspec/specs/entities/spec.md`
- [ ] 6.5 Merge `agent/backport-keg-catalog` into `master`, push, and archive the change
- [ ] 6.6 Remove the worktree and branch: `git worktree remove .worktree/backport-keg-catalog --force && git branch -d agent/backport-keg-catalog`