fix(04): revise plans based on checker feedback
All checks were successful
CI / build-test (push) Successful in 1m31s

This commit is contained in:
2026-03-24 09:50:11 +01:00
parent 81fc110224
commit 010daa227d
4 changed files with 55 additions and 26 deletions

View File

@@ -133,12 +133,14 @@ mux.HandleFunc("/api/updates", srv.UpdatesHandler)
<tasks>
<task type="auto" tdd="true">
<name>Task 1: Extend Store interface and implement AcknowledgeAll + AcknowledgeByTag in both stores</name>
<files>pkg/diunwebhook/store.go, pkg/diunwebhook/sqlite_store.go, pkg/diunwebhook/postgres_store.go</files>
<name>Task 1: Extend Store interface and implement AcknowledgeAll + AcknowledgeByTag with store-level tests</name>
<files>pkg/diunwebhook/store.go, pkg/diunwebhook/sqlite_store.go, pkg/diunwebhook/postgres_store.go, pkg/diunwebhook/diunwebhook_test.go, pkg/diunwebhook/export_test.go</files>
<read_first>
- pkg/diunwebhook/store.go
- pkg/diunwebhook/sqlite_store.go
- pkg/diunwebhook/postgres_store.go
- pkg/diunwebhook/diunwebhook_test.go
- pkg/diunwebhook/export_test.go
</read_first>
<behavior>
- Test 1: AcknowledgeAll on empty DB returns count=0, no error
@@ -149,22 +151,47 @@ mux.HandleFunc("/api/updates", srv.UpdatesHandler)
- Test 6: AcknowledgeByTag does not affect updates in other tags or untagged updates
</behavior>
<action>
1. Add two methods to the Store interface in `store.go` (per D-01):
TDD approach -- write tests first, then implement:
1. Add test helper exports to `export_test.go`:
```go
func (s *Server) TestAcknowledgeAll() (int, error) {
return s.Store().AcknowledgeAll()
}
func (s *Server) TestAcknowledgeByTag(tagID int) (int, error) {
return s.Store().AcknowledgeByTag(tagID)
}
```
(Add a `Store() Store` accessor method on Server if not already present, or access the store field directly via an existing test export pattern.)
2. Write store-level tests in `diunwebhook_test.go` following existing `Test<Function>_<Scenario>` convention:
- `TestAcknowledgeAll_Empty`: create server, call TestAcknowledgeAll, assert count=0, no error
- `TestAcknowledgeAll_AllUnacknowledged`: upsert 3 events via TestUpsertEvent, call TestAcknowledgeAll, assert count=3, then call GetUpdates and verify all have acknowledged=true
- `TestAcknowledgeAll_MixedState`: upsert 3 events, acknowledge 1 via existing dismiss, call TestAcknowledgeAll, assert count=2
- `TestAcknowledgeByTag_MatchingTag`: upsert 2 events, create tag, assign both to tag, call TestAcknowledgeByTag(tagID), assert count=2
- `TestAcknowledgeByTag_NonExistentTag`: call TestAcknowledgeByTag(9999), assert count=0, no error
- `TestAcknowledgeByTag_OnlyAffectsTargetTag`: upsert 3 events, create 2 tags, assign 2 events to tag1 and 1 to tag2, call TestAcknowledgeByTag(tag1.ID), assert count=2, verify tag2's event is still unacknowledged via GetUpdates
Run tests -- they must FAIL (RED) since methods don't exist yet.
3. Add two methods to the Store interface in `store.go` (per D-01):
```go
AcknowledgeAll() (count int, err error)
AcknowledgeByTag(tagID int) (count int, err error)
```
2. Implement in `sqlite_store.go` (following AcknowledgeUpdate pattern with mutex):
4. Implement in `sqlite_store.go` (following AcknowledgeUpdate pattern with mutex):
- `AcknowledgeAll`: `s.mu.Lock()`, `s.db.Exec("UPDATE updates SET acknowledged_at = datetime('now') WHERE acknowledged_at IS NULL")`, return `int(RowsAffected())`
- `AcknowledgeByTag`: `s.mu.Lock()`, `s.db.Exec("UPDATE updates SET acknowledged_at = datetime('now') WHERE acknowledged_at IS NULL AND image IN (SELECT image FROM tag_assignments WHERE tag_id = ?)", tagID)`, return `int(RowsAffected())`
3. Implement in `postgres_store.go` (no mutex, use NOW() and $1 positional param):
5. Implement in `postgres_store.go` (no mutex, use NOW() and $1 positional param):
- `AcknowledgeAll`: `s.db.Exec("UPDATE updates SET acknowledged_at = NOW() WHERE acknowledged_at IS NULL")`, return `int(RowsAffected())`
- `AcknowledgeByTag`: `s.db.Exec("UPDATE updates SET acknowledged_at = NOW() WHERE acknowledged_at IS NULL AND image IN (SELECT image FROM tag_assignments WHERE tag_id = $1)", tagID)`, return `int(RowsAffected())`
6. Run tests again -- they must PASS (GREEN).
</action>
<verify>
<automated>cd /home/jean-luc-makiola/Development/projects/DiunDashboard && go build ./...</automated>
<automated>cd /home/jean-luc-makiola/Development/projects/DiunDashboard && go test -v -run "TestAcknowledge(All|ByTag)_" ./pkg/diunwebhook/</automated>
</verify>
<acceptance_criteria>
- store.go contains `AcknowledgeAll() (count int, err error)` in the Store interface
@@ -177,13 +204,15 @@ mux.HandleFunc("/api/updates", srv.UpdatesHandler)
- postgres_store.go contains `func (s *PostgresStore) AcknowledgeAll() (int, error)`
- postgres_store.go contains `func (s *PostgresStore) AcknowledgeByTag(tagID int) (int, error)`
- postgres_store.go AcknowledgeByTag contains `$1` (positional param)
- `go build ./...` exits 0
- diunwebhook_test.go contains `TestAcknowledgeAll_Empty`
- diunwebhook_test.go contains `TestAcknowledgeByTag_OnlyAffectsTargetTag`
- `go test -v -run "TestAcknowledge(All|ByTag)_" ./pkg/diunwebhook/` exits 0
</acceptance_criteria>
<done>Store interface extended with 2 new methods; both SQLiteStore and PostgresStore compile and implement the interface</done>
<done>Store interface extended with 2 new methods; both SQLiteStore and PostgresStore compile and implement the interface; 6 store-level tests pass</done>
</task>
<task type="auto" tdd="true">
<name>Task 2: Add HTTP handlers, route registration, and tests for bulk acknowledge endpoints</name>
<name>Task 2: Add HTTP handlers, route registration, and handler tests for bulk acknowledge endpoints</name>
<files>pkg/diunwebhook/diunwebhook.go, pkg/diunwebhook/diunwebhook_test.go, pkg/diunwebhook/export_test.go, cmd/diunwebhook/main.go</files>
<read_first>
- pkg/diunwebhook/diunwebhook.go
@@ -268,7 +297,7 @@ mux.HandleFunc("/api/updates", srv.UpdatesHandler)
}
```
5. Write tests in `diunwebhook_test.go` following the existing `Test<Handler>_<Scenario>` naming convention. Use `NewTestServer()` for each test. Setup: use `TestUpsertEvent` to create events, `TestCreateTag` + `TestAssignTag` to setup tag assignments.
5. Write handler tests in `diunwebhook_test.go` following the existing `Test<Handler>_<Scenario>` naming convention. Use `NewTestServer()` for each test. Setup: use `TestUpsertEvent` to create events, `TestCreateTag` + `TestAssignTag` to setup tag assignments.
6. Also add the Vite dev proxy for the two new endpoints in `frontend/vite.config.ts` -- NOT needed, the existing proxy config already proxies all `/api` requests to `:8080`.
</action>