Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pm-stack/aggregator/src/alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,11 @@ export class AlertsStore {
}

async listSubscriptions(): Promise<PushSubscriptionRow[]> {
return this.db.query<PushSubscriptionRow>(`select * from alerts.push_subscriptions order by created_at`);
const rows = await this.db.query<PushSubscriptionRow>(`select * from alerts.push_subscriptions order by created_at`);
// #3702 decision 3: old stored prefs are not rewritten, but must not
// be reinterpreted on read. Apply the same per-field fallbacks used at
// intake so delivery and the prefs page see safe values.
return rows.map((row) => ({ ...row, quiet: mergeQuiet(row.quiet) }));
}

/** Design §4: a 404/410 marks the subscription gone; two consecutive
Expand Down
51 changes: 51 additions & 0 deletions pm-stack/aggregator/test/alerts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,57 @@ describe("class + quiet merges (design §1/§2)", () => {
});
});

describe("stored subscription preference reads (#4978)", () => {
test("invalid stored quiet fields fall back per field without rewriting rows", async () => {
const invalidQuiet = { start: "99:99", end: "24:60", tz: "Not/AZone", enabled: true };
const validQuiet = { start: "22:30", end: "06:15", tz: "UTC", enabled: true };
const rawRows: PushSubscriptionRow[] = [
{
id: "sub-invalid",
endpoint: "https://push.example/invalid",
p256dh: "p256dh",
auth: "auth",
classes: { incident: true },
quiet: invalidQuiet,
user_agent: null,
created_at: "2026-11-01T00:00:00Z",
last_seen_at: "2026-11-01T00:00:00Z",
gone_count: 0,
},
{
id: "sub-valid",
endpoint: "https://push.example/valid",
p256dh: "p256dh",
auth: "auth",
classes: { incident: true },
quiet: validQuiet,
user_agent: null,
created_at: "2026-11-02T00:00:00Z",
last_seen_at: "2026-11-02T00:00:00Z",
gone_count: 0,
},
];
const queries: string[] = [];
const db: SupabaseClient = {
ref: "test",
async query<T>(sql: string): Promise<T[]> {
queries.push(sql);
return rawRows as unknown as T[];
},
};

const loaded = await new AlertsStore(db).listSubscriptions();

expect(loaded.map((row) => row.quiet)).toEqual([
{ start: "23:00", end: "07:00", tz: "America/Chicago", enabled: true },
validQuiet,
]);
expect(inQuietHours(loaded[0].quiet, new Date("2026-01-15T12:00:00Z"))).toBe(true);
expect(rawRows.map((row) => row.quiet)).toEqual([invalidQuiet, validQuiet]);
expect(queries).toEqual(["select * from alerts.push_subscriptions order by created_at"]);
});
});

const incident: Incident = {
id: "11111111-2222-3333-4444-555555555555",
source: "globalping-watch",
Expand Down