feat: add audited work records and controlled digest retries
Build and publish container images / images (push) Successful in 12m27s
Build and publish container images / images (push) Successful in 12m27s
This commit is contained in:
1 parent
6e0aecdfb3
commit
e65ca56f92
33 files changed
+2262
-114
No files matched your search
@@ -110,6 +110,88 @@ func TestDashboardUpgradePreservesTaskPreferences(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkHistoryUpgradePreservesLegacySessions(t *testing.T) {
|
||||
st := newSchemaTestStore(t)
|
||||
if err := db.ApplySQLiteMigrations(context.Background(), st.DB, "task-productivity", taskProductivityMigrations[:2]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := st.DB.Exec(`INSERT INTO organizer_work_sessions VALUES('w','d','u','t',100,200,2)`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for range 2 {
|
||||
if err := st.ensureSchemaComponent("task-productivity"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
var start, end, version, cancelled int64
|
||||
if err := st.DB.QueryRow(`SELECT start_ms,end_ms,version,cancelled_ms FROM organizer_work_sessions WHERE uuid='w'`).Scan(&start, &end, &version, &cancelled); err != nil || start != 100 || end != 200 || version != 2 || cancelled != 0 {
|
||||
t.Fatal(start, end, version, cancelled, err)
|
||||
}
|
||||
var count int
|
||||
if err := st.DB.QueryRow(`SELECT count(*) FROM organizer_work_revisions`).Scan(&count); err != nil || count != 0 {
|
||||
t.Fatal("invented history", count, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDigestHistoryUpgradePreservesReservations(t *testing.T) {
|
||||
st := newSchemaTestStore(t)
|
||||
ctx := context.Background()
|
||||
if err := db.ApplySQLiteMigrations(ctx, st.DB, "task-productivity", taskProductivityMigrations[:3]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for i, state := range []string{"sent", "sending", "uncertain", "cancelled"} {
|
||||
if _, err := st.DB.Exec(`INSERT INTO organizer_digest_deliveries VALUES(?,?,?, ?,?)`, "d", state, "2026-11-01", state, 100+i); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
for range 2 {
|
||||
if err := st.ensureSchemaComponent("task-productivity"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
var count int
|
||||
if err := st.DB.QueryRow(`SELECT count(*) FROM organizer_digest_deliveries d JOIN organizer_digest_attempts a ON a.uuid=d.attempt_uuid AND a.domain_uuid=d.domain_uuid AND a.owner_uuid=d.owner_uuid AND a.day=d.day AND a.state=d.state AND a.updated_ms=d.updated_ms WHERE a.kind='legacy' AND a.preference_version=0`).Scan(&count); err != nil || count != 4 {
|
||||
t.Fatal("reservation migration", count, err)
|
||||
}
|
||||
var integrity string
|
||||
if err := st.DB.QueryRow(`PRAGMA integrity_check`).Scan(&integrity); err != nil || integrity != "ok" {
|
||||
t.Fatal(integrity, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDigestHistoryMigrationRollback(t *testing.T) {
|
||||
st := newSchemaTestStore(t)
|
||||
ctx := context.Background()
|
||||
if err := db.ApplySQLiteMigrations(ctx, st.DB, "task-productivity", taskProductivityMigrations[:3]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := st.DB.Exec(`INSERT INTO organizer_digest_deliveries VALUES('d','u','2026-11-01','sent',123)`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
steps := append([]db.SQLMigration(nil), taskProductivityMigrations...)
|
||||
steps[3].Statements = append(append([]string(nil), steps[3].Statements...), `INVALID MIGRATION STATEMENT`)
|
||||
if err := db.ApplySQLiteMigrations(ctx, st.DB, "task-productivity", steps); err == nil {
|
||||
t.Fatal("failed migration committed")
|
||||
}
|
||||
var columns, ledger, attempts int
|
||||
if err := st.DB.QueryRow(`SELECT count(*) FROM pragma_table_info('organizer_digest_deliveries')`).Scan(&columns); err != nil || columns != 5 {
|
||||
t.Fatal("DDL not rolled back", columns, err)
|
||||
}
|
||||
if err := st.DB.QueryRow(`SELECT count(*) FROM schema_migration_steps WHERE component='task-productivity'`).Scan(&ledger); err != nil || ledger != 3 {
|
||||
t.Fatal(ledger, err)
|
||||
}
|
||||
if err := st.DB.QueryRow(`SELECT count(*) FROM sqlite_master WHERE name='organizer_digest_attempts'`).Scan(&attempts); err != nil || attempts != 0 {
|
||||
t.Fatal(attempts, err)
|
||||
}
|
||||
var state string
|
||||
if err := st.DB.QueryRow(`SELECT state FROM organizer_digest_deliveries`).Scan(&state); err != nil || state != "sent" {
|
||||
t.Fatal(state, err)
|
||||
}
|
||||
if err := st.ensureSchemaComponent("task-productivity"); err != nil {
|
||||
t.Fatal("retry migration", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestManagedSchemasFreshRepeatAndReadOnly(t *testing.T) {
|
||||
for component := range managedStoreSchemas {
|
||||
t.Run(component, func(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user