@marktiderman/genesis-cli 1.17.3 → 1.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/README.md +162 -17
  2. package/dist/cli.js +2099 -747
  3. package/dist/cli.js.map +1 -1
  4. package/dist/{config-1jP8eCZy.d.ts → config-Dj_f9T7J.d.ts} +14 -1
  5. package/dist/doctor.d.ts +3 -3
  6. package/dist/doctor.js +944 -361
  7. package/dist/doctor.js.map +1 -1
  8. package/dist/expo.d.ts +2 -2
  9. package/dist/expo.js +18 -0
  10. package/dist/expo.js.map +1 -1
  11. package/dist/genesis-catalog.json +29 -16
  12. package/dist/index.d.ts +1 -1
  13. package/dist/index.js +944 -361
  14. package/dist/index.js.map +1 -1
  15. package/dist/starter/README.md +9 -0
  16. package/dist/starter/__tests__/components/gestures.test.tsx +64 -0
  17. package/dist/starter/__tests__/components/resolver.js +14 -2
  18. package/dist/starter/__tests__/components/setup.ts +5 -0
  19. package/dist/starter/__tests__/starter.test.ts +56 -22
  20. package/dist/starter/genesis.config.json +10 -0
  21. package/dist/starter/jest.config.js +3 -0
  22. package/dist/starter/package.json +2 -0
  23. package/dist/starter/src/lib/link-hosts.ts +12 -0
  24. package/dist/starter/src/lib/links.ts +2 -1
  25. package/dist/starter/supabase/functions/genesis-apple-revoke/apple.ts +7 -2
  26. package/dist/starter/supabase/migrations/20261024000700_genesis_support_findings.sql +339 -0
  27. package/dist/starter/supabase/tests/database/genesis_notifications.test.sql +5 -3
  28. package/dist/starter/supabase/tests/database/genesis_support.test.sql +1 -1
  29. package/dist/starter/supabase/tests/database/genesis_support_findings.test.sql +219 -0
  30. package/dist/templates/ci/genesis-upgrade.yml +1 -0
  31. package/dist/vite.js +945 -362
  32. package/dist/vite.js.map +1 -1
  33. package/package.json +3 -3
@@ -0,0 +1,339 @@
1
+ -- Genesis support findings: severity, the verify loop and report handlers
2
+ --
3
+ -- Part of the `support-feedback` block of `@marktiderman/genesis-support`. Apply it after
4
+ -- `0006_genesis_support.sql` from `@marktiderman/genesis-supabase` (`genesis add
5
+ -- support-feedback` orders them).
6
+ --
7
+ -- severity low, medium, high or critical, as the person (or an agent) sent it, in its
8
+ -- own column (the intake function also keeps it in `context`).
9
+ -- handlers Besides support staff, the app may name who else handles a report: they read
10
+ -- it and its screenshots, reply as support and set its status. The app's hook
11
+ -- `private.genesis_support_report_handler(report uuid, person uuid)` returns
12
+ -- boolean; it is optional, and without it only staff handle reports. Handlers
13
+ -- don't observe a report's support-chat thread (staff-only internal notes
14
+ -- stay staff-only); their replies reach it as support.
15
+ -- verify loop The person confirms a fix (verified_at) or reopens the report (back to
16
+ -- in_progress, reopened_at) with support_verify_report. Marking a report
17
+ -- addressed or wont_fix stamps resolved_at.
18
+ -- verify prompt Off unless the app turns it on with its hook
19
+ -- `private.genesis_support_verify_prompt_enabled()` returning true: then a
20
+ -- report someone else marks addressed asks its person, in its thread, to check
21
+ -- the fix (at most once an hour per report). That reply is the system's
22
+ -- (support_replies.prompt = 'verify'): it doesn't count against anyone's reply
23
+ -- limit. It is a staff reply, so it marks the report unread for its person,
24
+ -- ends their editing, and with support-chat is pushed as the marker's message.
25
+ -- If it can't be posted (a reply rule that refuses it, a limit), the status
26
+ -- change still goes through without it.
27
+ --
28
+ -- The support-email block (`0002_genesis_support_email.sql`) also replaces
29
+ -- private.genesis_support_new_reply. This file's version keeps the email channel's rules when
30
+ -- that block is already installed; if support-email is added after this file, handlers can no
31
+ -- longer reply (status changes still work, without the prompt) until this file's
32
+ -- genesis_support_new_reply is applied again.
33
+ --
34
+ -- Never edit it once applied; change it with a new migration.
35
+ --
36
+ -- Verify: the pgTAP test beside this file (`tests/0003_genesis_support_findings.test.sql`).
37
+
38
+ create schema if not exists private;
39
+
40
+ alter table public.support_reports
41
+ add column if not exists severity text constraint support_reports_severity check (severity in ('low', 'medium', 'high', 'critical')),
42
+ add column if not exists resolved_at timestamptz,
43
+ add column if not exists verified_at timestamptz,
44
+ add column if not exists reopened_at timestamptz;
45
+
46
+ comment on column public.support_reports.severity is
47
+ 'How bad it is, as the person sent it: low, medium, high or critical. Genesis support.';
48
+ comment on column public.support_reports.resolved_at is
49
+ 'When it was last marked addressed or wont_fix (cleared when it is reopened). Genesis support.';
50
+ comment on column public.support_reports.verified_at is
51
+ 'When its person confirmed the fix. Genesis support.';
52
+ comment on column public.support_reports.reopened_at is
53
+ 'When its person last said the fix did not work. Genesis support.';
54
+
55
+ -- The person sends it with the report.
56
+ grant insert (severity) on table public.support_reports to authenticated;
57
+
58
+ -- A reply the system posted, and which: only the database writes it (no column grant).
59
+ alter table public.support_replies
60
+ add column if not exists prompt text constraint support_replies_prompt check (prompt in ('verify'));
61
+
62
+ comment on column public.support_replies.prompt is
63
+ 'Set on a reply the system posted: verify (asks the person to check a fix). Genesis support.';
64
+
65
+ -- Handlers ----------------------------------------------------------------------------
66
+
67
+ -- Staff, or whom the app's hook names for this report.
68
+ create or replace function private.genesis_support_handler(report uuid, person uuid)
69
+ returns boolean
70
+ language plpgsql
71
+ stable
72
+ security definer
73
+ set search_path = ''
74
+ as $$
75
+ begin
76
+ if person is null or report is null then
77
+ return false;
78
+ end if;
79
+ -- The staff hook is the app's (0006); without it, nobody is staff.
80
+ if to_regprocedure('private.genesis_support_staff(uuid)') is not null then
81
+ if coalesce(private.genesis_support_staff(person), false) then
82
+ return true;
83
+ end if;
84
+ end if;
85
+ if to_regprocedure('private.genesis_support_report_handler(uuid, uuid)') is null then
86
+ return false;
87
+ end if;
88
+ return coalesce(private.genesis_support_report_handler(report, person), false);
89
+ end;
90
+ $$;
91
+
92
+ revoke execute on function private.genesis_support_handler(uuid, uuid) from public, anon, authenticated;
93
+
94
+ -- Does the signed-in person handle this report? Policies and the client ask; it answers only
95
+ -- about the caller.
96
+ create or replace function public.support_handles(report uuid)
97
+ returns boolean
98
+ language sql
99
+ stable
100
+ security definer
101
+ set search_path = ''
102
+ as $$
103
+ select private.genesis_support_handler(report, auth.uid())
104
+ $$;
105
+
106
+ comment on function public.support_handles(uuid) is
107
+ 'Whether the signed-in person handles this report (staff, or whom the app''s hook names). Genesis support.';
108
+ revoke execute on function public.support_handles(uuid) from public, anon;
109
+ grant execute on function public.support_handles(uuid) to authenticated;
110
+
111
+ drop policy if exists support_reports_read on public.support_reports;
112
+ create policy support_reports_read on public.support_reports
113
+ for select to authenticated
114
+ using (user_id = (select auth.uid()) or (select public.support_is_staff()) or public.support_handles(id));
115
+
116
+ drop policy if exists support_attachments_read on public.support_attachments;
117
+ create policy support_attachments_read on public.support_attachments
118
+ for select to authenticated
119
+ using (user_id = (select auth.uid()) or (select public.support_is_staff()) or public.support_handles(report_id));
120
+
121
+ drop policy if exists support_replies_read on public.support_replies;
122
+ create policy support_replies_read on public.support_replies
123
+ for select to authenticated
124
+ using (
125
+ (select public.support_is_staff()) or public.support_handles(report_id)
126
+ or exists (select 1 from public.support_reports r where r.id = report_id and r.user_id = (select auth.uid()))
127
+ );
128
+ drop policy if exists support_replies_send on public.support_replies;
129
+ create policy support_replies_send on public.support_replies
130
+ for insert to authenticated
131
+ with check (
132
+ (select public.support_is_staff()) or public.support_handles(report_id)
133
+ or exists (select 1 from public.support_reports r where r.id = report_id and r.user_id = (select auth.uid()))
134
+ );
135
+
136
+ -- Who wrote a reply, and whether as support, come from the session. A handler writes as support
137
+ -- on someone else's report. A reply the system posts (genesis_support_ask_to_verify, with
138
+ -- `prompt` set, which no person can write) isn't counted against the limit. With the support-email block installed, server code may write on
139
+ -- an email ticket and a ticket without a person takes support's replies only, as that block has it.
140
+ create or replace function private.genesis_support_new_reply()
141
+ returns trigger
142
+ language plpgsql
143
+ security definer
144
+ set search_path = ''
145
+ as $$
146
+ declare
147
+ me uuid := auth.uid();
148
+ report public.support_reports;
149
+ handles boolean;
150
+ begin
151
+ select * into report from public.support_reports r where r.id = new.report_id;
152
+ if report.id is null then
153
+ raise exception 'support: not your report' using errcode = '42501';
154
+ end if;
155
+ if me is null then
156
+ -- Server code (anon has no right on this table): only on an email ticket (support-email).
157
+ if coalesce(to_jsonb(report) ->> 'channel', '') <> 'email' then
158
+ raise exception 'support: not your report' using errcode = '42501';
159
+ end if;
160
+ new.author_id := null;
161
+ new.created_at := clock_timestamp();
162
+ return new;
163
+ end if;
164
+ handles := private.genesis_support_handler(new.report_id, me);
165
+ if report.user_id is null then
166
+ if not handles then
167
+ raise exception 'support: not your report' using errcode = '42501';
168
+ end if;
169
+ new.author_id := me;
170
+ new.from_staff := true;
171
+ else
172
+ if report.user_id <> me and not handles then
173
+ raise exception 'support: not your report' using errcode = '42501';
174
+ end if;
175
+ new.author_id := me;
176
+ -- On their own report a staff member writes as the person.
177
+ new.from_staff := handles and report.user_id <> me;
178
+ end if;
179
+ new.created_at := clock_timestamp();
180
+ if new.prompt is null then
181
+ perform private.genesis_support_rate_limit(me, 'reply', 60, interval '1 hour');
182
+ end if;
183
+ return new;
184
+ end;
185
+ $$;
186
+
187
+ revoke execute on function private.genesis_support_new_reply() from public, anon, authenticated;
188
+
189
+ -- Screenshots: a handler of the report the attachment row belongs to reads it too.
190
+ create or replace function public.support_can_read(object_name text, uploaded_at timestamptz)
191
+ returns boolean
192
+ language sql
193
+ stable
194
+ security definer
195
+ set search_path = ''
196
+ as $$
197
+ select auth.uid() is not null and (
198
+ exists (select 1 from public.support_attachments a
199
+ where a.path = object_name
200
+ and (split_part(object_name, '/', 1) = auth.uid()::text or public.support_is_staff()
201
+ or private.genesis_support_handler(a.report_id, auth.uid())))
202
+ or (split_part(object_name, '/', 1) = auth.uid()::text and uploaded_at > now() - interval '1 hour')
203
+ )
204
+ $$;
205
+
206
+ comment on function public.support_can_read(text, timestamptz) is
207
+ 'Whether the signed-in person may read this support screenshot (their own, or as staff or a handler). Genesis support.';
208
+
209
+ -- Status: staff, or a handler of the report.
210
+ create or replace function public.support_set_report_status(report uuid, status text, feature text default null)
211
+ returns void
212
+ language plpgsql
213
+ security definer
214
+ set search_path = ''
215
+ as $$
216
+ begin
217
+ if not private.genesis_support_handler(report, auth.uid()) then
218
+ raise exception 'support_set_report_status: only staff' using errcode = '42501';
219
+ end if;
220
+ update public.support_reports r
221
+ set status = support_set_report_status.status,
222
+ feature_id = case when feature = '' then null else coalesce(feature, r.feature_id) end
223
+ where r.id = report;
224
+ if not found then
225
+ raise exception 'support_set_report_status: no such report' using errcode = 'P0002';
226
+ end if;
227
+ end;
228
+ $$;
229
+
230
+ comment on function public.support_set_report_status(uuid, text, text) is
231
+ 'Staff or a handler set a report''s status and the FeatureId it is about. Genesis support.';
232
+
233
+ -- The verify loop ---------------------------------------------------------------------
234
+
235
+ -- Addressed or wont_fix: stamped, and not yet verified. Back to open or in progress: cleared.
236
+ create or replace function private.genesis_support_resolution()
237
+ returns trigger
238
+ language plpgsql
239
+ security definer
240
+ set search_path = ''
241
+ as $$
242
+ begin
243
+ if new.status in ('addressed', 'wont_fix') and old.status is distinct from new.status then
244
+ new.resolved_at := now();
245
+ new.verified_at := null;
246
+ elsif old.status in ('addressed', 'wont_fix') and new.status in ('open', 'submitted', 'in_progress') then
247
+ new.resolved_at := null;
248
+ new.verified_at := null;
249
+ end if;
250
+ return new;
251
+ end;
252
+ $$;
253
+
254
+ revoke execute on function private.genesis_support_resolution() from public, anon, authenticated;
255
+ drop trigger if exists genesis_support_resolution on public.support_reports;
256
+ create trigger genesis_support_resolution
257
+ before update of status on public.support_reports
258
+ for each row execute function private.genesis_support_resolution();
259
+
260
+ -- The verify prompt, only when the app's hook turns it on: someone other than the person marked
261
+ -- it addressed (a reply needs a session), so ask them to check it, at most once an hour per
262
+ -- report, so a status flipped back and forth can't flood the thread. The reply is the system's
263
+ -- (prompt = 'verify'): it doesn't count against the marker's reply limit. If a reply rule
264
+ -- refuses it (support-email's trigger applied after this file refuses a handler) or a limit
265
+ -- stops it, the status change still goes through, without the prompt.
266
+ create or replace function private.genesis_support_ask_to_verify()
267
+ returns trigger
268
+ language plpgsql
269
+ security definer
270
+ set search_path = ''
271
+ as $$
272
+ begin
273
+ -- A status set directly is depth 1; through support-chat's conversation sync, 2. Deeper is a
274
+ -- loop of triggers, never a person marking a fix.
275
+ if pg_trigger_depth() > 2 then
276
+ return null;
277
+ end if;
278
+ -- Two statements: one SQL expression may evaluate the call even when the hook is missing.
279
+ if to_regprocedure('private.genesis_support_verify_prompt_enabled()') is null then
280
+ return null;
281
+ end if;
282
+ if not coalesce(private.genesis_support_verify_prompt_enabled(), false) then
283
+ return null;
284
+ end if;
285
+ if auth.uid() is null or auth.uid() = new.user_id
286
+ or exists (select 1 from public.support_replies r
287
+ where r.report_id = new.id and r.prompt = 'verify' and r.created_at > now() - interval '1 hour') then
288
+ return null;
289
+ end if;
290
+ begin
291
+ insert into public.support_replies (report_id, body, prompt)
292
+ values (new.id, 'This is marked fixed. Please check it: confirm the fix, or reopen it if it isn''t fixed.', 'verify');
293
+ exception
294
+ when insufficient_privilege or sqlstate 'GS429' then
295
+ raise log 'genesis-support: the verify prompt for report % was not posted (%)', new.id, sqlerrm;
296
+ end;
297
+ return null;
298
+ end;
299
+ $$;
300
+
301
+ revoke execute on function private.genesis_support_ask_to_verify() from public, anon, authenticated;
302
+ drop trigger if exists genesis_support_ask_to_verify on public.support_reports;
303
+ create trigger genesis_support_ask_to_verify
304
+ after update of status on public.support_reports
305
+ for each row when (new.status = 'addressed' and old.status is distinct from 'addressed')
306
+ execute function private.genesis_support_ask_to_verify();
307
+
308
+ -- The person confirms the fix, or reopens the report (with what's still wrong, in the thread).
309
+ create or replace function public.support_verify_report(report uuid, fixed boolean, note text default null)
310
+ returns void
311
+ language plpgsql
312
+ security definer
313
+ set search_path = ''
314
+ as $$
315
+ declare
316
+ _r public.support_reports;
317
+ begin
318
+ select * into _r from public.support_reports where id = report;
319
+ if _r.id is null or _r.user_id is distinct from auth.uid() then
320
+ raise exception 'support_verify_report: not your report' using errcode = '42501';
321
+ end if;
322
+ if _r.status <> 'addressed' then
323
+ raise exception 'support_verify_report: it isn''t marked fixed' using errcode = '22023';
324
+ end if;
325
+ if nullif(btrim(note), '') is not null then
326
+ insert into public.support_replies (report_id, body) values (report, btrim(note));
327
+ end if;
328
+ if fixed then
329
+ update public.support_reports set verified_at = now() where id = report;
330
+ else
331
+ update public.support_reports set status = 'in_progress', reopened_at = now() where id = report;
332
+ end if;
333
+ end;
334
+ $$;
335
+
336
+ comment on function public.support_verify_report(uuid, boolean, text) is
337
+ 'The person confirms a fix, or reopens their report with an optional note. Genesis support.';
338
+ revoke execute on function public.support_verify_report(uuid, boolean, text) from public, anon;
339
+ grant execute on function public.support_verify_report(uuid, boolean, text) to authenticated;
@@ -203,10 +203,12 @@ update public.notification_preferences set quiet_hours_start = '06:00' where use
203
203
  select is(private.genesis_notifications_quiet_until(pg_temp.u('c3'), '2026-11-01 10:59+00'), null, 'a start equal to the end is no quiet hours');
204
204
 
205
205
  -- Push during quiet hours waits; a transactional one doesn't ----------------------------
206
- -- a1 is quiet all day long, in UTC.
206
+ -- a1 is quiet from an hour before now to an hour after, in UTC: a window around the test's own
207
+ -- clock (it may run past midnight, which the claim handles), never a fixed one a clock can be outside.
207
208
  insert into public.notification_preferences (user_id, quiet_hours_enabled, quiet_hours_start, quiet_hours_end, time_zone)
208
- values (pg_temp.u('a1'), true, '00:00', '23:59', 'UTC')
209
- on conflict (user_id) do update set quiet_hours_enabled = true, quiet_hours_start = '00:00', quiet_hours_end = '23:59', time_zone = 'UTC';
209
+ values (pg_temp.u('a1'), true, ((now() at time zone 'UTC') - interval '1 hour')::time, ((now() at time zone 'UTC') + interval '1 hour')::time, 'UTC')
210
+ on conflict (user_id) do update set quiet_hours_enabled = true, quiet_hours_start = excluded.quiet_hours_start,
211
+ quiet_hours_end = excluded.quiet_hours_end, time_zone = 'UTC';
210
212
  insert into k select 'q1', notification_id from public.genesis_notify('gntest.message', jsonb_build_array(pg_temp.u('a1')), '{}', 'push:msg-q');
211
213
  insert into k select 'q2', notification_id from public.genesis_notify('gntest.alert', jsonb_build_array(pg_temp.u('a1')), '{}', 'alert-1');
212
214
  update public.notification_deliveries set send_after = now() - interval '1 minute' where notification_id in (pg_temp.k('q1'), pg_temp.k('q2'));
@@ -1,4 +1,4 @@
1
- -- @feat:support-feedback @feat:feature-voting
1
+ -- @feat:support-feedback
2
2
  -- pgTAP test for 0006_genesis_support.sql.
3
3
  -- Copy into your app's `supabase/tests/database/` and run `supabase test db`.
4
4
  -- It writes only its own users, reports, ideas and storage rows and rolls everything back.
@@ -0,0 +1,219 @@
1
+ -- @feat:support-feedback
2
+ -- pgTAP test for 0003_genesis_support_findings.sql (after 0006_genesis_support.sql). Copy into
3
+ -- your app's `supabase/tests/database/` and run `supabase test db`. It writes only its own
4
+ -- users, reports and replies and rolls everything back. If your app already has the staff hook
5
+ -- (`private.genesis_support_staff`), the handler hook (`private.genesis_support_report_handler`)
6
+ -- or the verify prompt hook (`private.genesis_support_verify_prompt_enabled`), they are replaced
7
+ -- inside this transaction only, as is the reply trigger function (to stand for a later rule).
8
+ --
9
+ -- People: a1 reports, b2 is someone else, c3 is staff, d4 handles a1's first report (the app's
10
+ -- hook says so), nobody else's.
11
+ begin;
12
+ create extension if not exists pgtap with schema extensions;
13
+ select plan(32);
14
+
15
+ insert into auth.users (id, aud, role, email, instance_id)
16
+ select ('00000000-0000-4000-8000-0000000003' || n)::uuid, 'authenticated', 'authenticated',
17
+ 'genesis-support-findings-' || n || '@example.test', '00000000-0000-0000-0000-000000000000'
18
+ from unnest(array['a1', 'b2', 'c3', 'd4']) n;
19
+
20
+ create function pg_temp.person(n text) returns uuid language sql immutable as $$ select ('00000000-0000-4000-8000-0000000003' || n)::uuid $$;
21
+ create function pg_temp.sign_in(n text) returns void language plpgsql as $$
22
+ begin
23
+ perform set_config('request.jwt.claims', json_build_object('sub', pg_temp.person(n), 'role', 'authenticated')::text, true);
24
+ perform set_config('request.jwt.claim.sub', pg_temp.person(n)::text, true);
25
+ end $$;
26
+ create table pg_temp.ids (name text primary key, id uuid);
27
+ create function pg_temp.remember(name text, q text) returns void language plpgsql as $$
28
+ declare v uuid;
29
+ begin
30
+ execute q into v;
31
+ insert into pg_temp.ids values (name, v);
32
+ end $$;
33
+ create function pg_temp.id(n text) returns uuid language sql stable as $$ select id from pg_temp.ids where name = n $$;
34
+ grant select, insert on pg_temp.ids to anon, authenticated;
35
+ grant execute on function pg_temp.person(text), pg_temp.sign_in(text), pg_temp.remember(text, text), pg_temp.id(text)
36
+ to anon, authenticated, service_role;
37
+
38
+ drop function if exists private.genesis_support_staff(uuid);
39
+ create function private.genesis_support_staff(person uuid) returns boolean
40
+ language sql stable set search_path = '' as $$
41
+ select person = '00000000-0000-4000-8000-0000000003c3'::uuid
42
+ $$;
43
+ revoke execute on function private.genesis_support_staff(uuid) from public, anon, authenticated;
44
+
45
+ -- The schema --------------------------------------------------------------------------
46
+ select has_column('public', 'support_reports', 'severity', 'a report has a severity');
47
+ select ok(
48
+ has_column_privilege('authenticated', 'public.support_reports', 'severity', 'insert')
49
+ and not has_column_privilege('authenticated', 'public.support_reports', 'severity', 'update'),
50
+ 'the person sends a severity with the report, and can''t change it after'
51
+ );
52
+ select ok(
53
+ not has_function_privilege('authenticated', 'private.genesis_support_handler(uuid, uuid)', 'execute')
54
+ and not has_function_privilege('anon', 'public.support_handles(uuid)', 'execute')
55
+ and not has_function_privilege('anon', 'public.support_verify_report(uuid, boolean, text)', 'execute')
56
+ and has_function_privilege('authenticated', 'public.support_verify_report(uuid, boolean, text)', 'execute'),
57
+ 'the handler check is the database''s, and anon calls nothing'
58
+ );
59
+ select ok(
60
+ not has_column_privilege('authenticated', 'public.support_replies', 'prompt', 'insert'),
61
+ 'nobody writes a reply as the system''s'
62
+ );
63
+
64
+ -- Severity ----------------------------------------------------------------------------
65
+ select pg_temp.sign_in('a1');
66
+ set local role authenticated;
67
+ select pg_temp.remember('r1', $$ insert into public.support_reports (type, title, message, severity) values ('bug', 'Export broke', 'It broke', 'high') returning id $$);
68
+ select pg_temp.remember('r2', $$ insert into public.support_reports (type, title, message) values ('bug', 'Second', 'Another') returning id $$);
69
+ select throws_ok($$ insert into public.support_reports (type, message, severity) values ('bug', 'x', 'dire') $$,
70
+ '23514', null, 'a severity outside the list is refused');
71
+ reset role;
72
+ select is((select severity from public.support_reports where id = pg_temp.id('r1')), 'high', 'the severity is kept');
73
+
74
+ -- Without the app's handler hook, only the person and staff handle a report ----------------
75
+ select pg_temp.sign_in('d4');
76
+ set local role authenticated;
77
+ select ok(not public.support_handles(pg_temp.id('r1')), 'without the hook, someone else doesn''t handle it');
78
+ select is((select count(*)::int from public.support_reports where id = pg_temp.id('r1')), 0, 'or read it');
79
+ reset role;
80
+ select pg_temp.sign_in('c3');
81
+ set local role authenticated;
82
+ select ok(public.support_handles(pg_temp.id('r1')), 'staff handle every report');
83
+ reset role;
84
+
85
+ -- The app names a handler ---------------------------------------------------------------
86
+ drop function if exists private.genesis_support_report_handler(uuid, uuid);
87
+ create function private.genesis_support_report_handler(report uuid, person uuid) returns boolean
88
+ language sql stable set search_path = '' as $$
89
+ select person = '00000000-0000-4000-8000-0000000003d4'::uuid
90
+ and report = (select id from pg_temp.ids where name = 'r1')
91
+ $$;
92
+ revoke execute on function private.genesis_support_report_handler(uuid, uuid) from public, anon, authenticated;
93
+
94
+ select pg_temp.sign_in('d4');
95
+ set local role authenticated;
96
+ select ok(public.support_handles(pg_temp.id('r1')), 'the hook''s handler handles the report it names');
97
+ select ok(not public.support_handles(pg_temp.id('r2')), 'and not another');
98
+ select is((select count(*)::int from public.support_reports where user_id = pg_temp.person('a1')), 1, 'and reads only that one');
99
+ insert into public.support_replies (report_id, body) values (pg_temp.id('r1'), 'Looking at it');
100
+ select is((select from_staff from public.support_replies where report_id = pg_temp.id('r1') and body = 'Looking at it'), true,
101
+ 'a handler replies as support');
102
+ select throws_ok($$ insert into public.support_replies (report_id, body) values (pg_temp.id('r2'), 'Not mine') $$,
103
+ '42501', null, 'but not on a report they don''t handle');
104
+ select lives_ok($$ select public.support_set_report_status(pg_temp.id('r1'), 'in_progress') $$, 'a handler sets the status');
105
+ select throws_ok($$ select public.support_set_report_status(pg_temp.id('r2'), 'in_progress') $$,
106
+ '42501', null, 'not on a report they don''t handle');
107
+ reset role;
108
+
109
+ select pg_temp.sign_in('b2');
110
+ set local role authenticated;
111
+ select ok(not public.support_handles(pg_temp.id('r1')), 'someone else doesn''t handle it');
112
+ reset role;
113
+
114
+ -- The verify loop -----------------------------------------------------------------------
115
+ drop function if exists private.genesis_support_verify_prompt_enabled();
116
+
117
+ select pg_temp.sign_in('d4');
118
+ set local role authenticated;
119
+ select public.support_set_report_status(pg_temp.id('r1'), 'addressed');
120
+ reset role;
121
+ select isnt((select resolved_at from public.support_reports where id = pg_temp.id('r1')), null, 'marked addressed, it is stamped');
122
+ select is((select count(*)::int from public.support_replies where report_id = pg_temp.id('r1') and prompt is not null), 0,
123
+ 'without the app''s hook, nobody is asked to check the fix');
124
+
125
+ -- The app turns the prompt on.
126
+ create function private.genesis_support_verify_prompt_enabled() returns boolean
127
+ language sql stable set search_path = '' as $$ select true $$;
128
+ revoke execute on function private.genesis_support_verify_prompt_enabled() from public, anon, authenticated;
129
+
130
+ select pg_temp.sign_in('d4');
131
+ set local role authenticated;
132
+ select public.support_set_report_status(pg_temp.id('r1'), 'in_progress');
133
+ reset role;
134
+ select is((select resolved_at from public.support_reports where id = pg_temp.id('r1')), null, 'back in progress, no longer resolved');
135
+ select pg_temp.sign_in('d4');
136
+ set local role authenticated;
137
+ select public.support_set_report_status(pg_temp.id('r1'), 'addressed');
138
+ reset role;
139
+ select is((select count(*)::int from public.support_replies where report_id = pg_temp.id('r1') and from_staff and prompt = 'verify'), 1,
140
+ 'with the hook on, its person is asked to check the fix, as the system');
141
+
142
+ -- Flipped back and forth within the hour: asked once.
143
+ select pg_temp.sign_in('d4');
144
+ set local role authenticated;
145
+ select public.support_set_report_status(pg_temp.id('r1'), 'in_progress');
146
+ select public.support_set_report_status(pg_temp.id('r1'), 'addressed');
147
+ reset role;
148
+ select is((select count(*)::int from public.support_replies where report_id = pg_temp.id('r1') and prompt = 'verify'), 1,
149
+ 'a status flipped back and forth asks once an hour');
150
+
151
+ select pg_temp.sign_in('b2');
152
+ set local role authenticated;
153
+ select throws_ok($$ select public.support_verify_report(pg_temp.id('r1'), true) $$, '42501', null, 'only its person verifies it');
154
+ reset role;
155
+
156
+ select pg_temp.sign_in('a1');
157
+ set local role authenticated;
158
+ select public.support_verify_report(pg_temp.id('r1'), false, 'Still broken');
159
+ reset role;
160
+ select is((select status from public.support_reports where id = pg_temp.id('r1')), 'in_progress', 'not fixed: it is reopened');
161
+ select ok((select reopened_at is not null and resolved_at is null from public.support_reports where id = pg_temp.id('r1')),
162
+ 'stamped reopened, and no longer resolved');
163
+ select is((select count(*)::int from public.support_replies where report_id = pg_temp.id('r1') and not from_staff and body = 'Still broken'), 1,
164
+ 'with what is still wrong in the thread');
165
+
166
+ select pg_temp.sign_in('a1');
167
+ set local role authenticated;
168
+ select throws_ok($$ select public.support_verify_report(pg_temp.id('r1'), true) $$, '22023', null, 'a report not marked fixed can''t be confirmed');
169
+ reset role;
170
+
171
+ select pg_temp.sign_in('c3');
172
+ set local role authenticated;
173
+ select public.support_set_report_status(pg_temp.id('r1'), 'addressed');
174
+ reset role;
175
+ select pg_temp.sign_in('a1');
176
+ set local role authenticated;
177
+ select public.support_verify_report(pg_temp.id('r1'), true);
178
+ reset role;
179
+ select ok((select status = 'addressed' and verified_at is not null from public.support_reports where id = pg_temp.id('r1')),
180
+ 'fixed: it stays addressed, confirmed');
181
+
182
+ -- Won't fix is resolved too.
183
+ select pg_temp.sign_in('c3');
184
+ set local role authenticated;
185
+ select public.support_set_report_status(pg_temp.id('r2'), 'wont_fix');
186
+ reset role;
187
+ select isnt((select resolved_at from public.support_reports where id = pg_temp.id('r2')), null, 'marked won''t fix, it is stamped');
188
+
189
+ -- A reply rule installed later that refuses the prompt (support-email's 0002 applied after this
190
+ -- file lets only staff reply on someone else's report) never blocks the status change.
191
+ select pg_temp.sign_in('c3');
192
+ set local role authenticated;
193
+ select public.support_set_report_status(pg_temp.id('r1'), 'in_progress');
194
+ reset role;
195
+ delete from public.support_replies where report_id = pg_temp.id('r1') and prompt = 'verify';
196
+ create or replace function private.genesis_support_new_reply() returns trigger
197
+ language plpgsql security definer set search_path = '' as $$
198
+ declare owner uuid;
199
+ begin
200
+ select r.user_id into owner from public.support_reports r where r.id = new.report_id;
201
+ if auth.uid() is null or owner is null or (owner <> auth.uid() and not public.support_is_staff()) then
202
+ raise exception 'support: not your report' using errcode = '42501';
203
+ end if;
204
+ new.author_id := auth.uid();
205
+ new.from_staff := public.support_is_staff() and owner <> auth.uid();
206
+ new.created_at := clock_timestamp();
207
+ return new;
208
+ end $$;
209
+ select pg_temp.sign_in('d4');
210
+ set local role authenticated;
211
+ select lives_ok($$ select public.support_set_report_status(pg_temp.id('r1'), 'addressed') $$,
212
+ 'a handler still marks it addressed when a later reply rule refuses the prompt');
213
+ reset role;
214
+ select is((select status from public.support_reports where id = pg_temp.id('r1')), 'addressed', 'the status change is kept');
215
+ select is((select count(*)::int from public.support_replies where report_id = pg_temp.id('r1') and prompt = 'verify'), 0,
216
+ 'without the prompt');
217
+
218
+ select * from finish();
219
+ rollback;
@@ -16,6 +16,7 @@ jobs:
16
16
  uses: marktiderman/genesis/.github/workflows/genesis-upgrade.yml@GENESIS_SHA # @marktiderman/genesis@X.Y.Z
17
17
  with:
18
18
  package-manager: pnpm # or bun, npm
19
+ # base-branch: staging # the branch the pull request targets; default: the default branch
19
20
  # So CI runs on the pull request (the default token can't start workflows):
20
21
  # secrets:
21
22
  # token: ${{ secrets.GENESIS_UPGRADE_TOKEN }}