@marktiderman/genesis-cli 1.17.3 → 1.18.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.
@@ -6,6 +6,7 @@ import { describe, expect, it } from "vitest";
6
6
  import starter from "../starter.config";
7
7
  import { defineStarter, easConfig, nativePlatforms, privacyBlocks, type StarterConfig } from "../src/lib/define-starter";
8
8
  import { copy, format } from "../src/copy";
9
+ import { linkHosts } from "../src/lib/link-hosts";
9
10
  import { findInlineCopy } from "./inline-copy";
10
11
 
11
12
  const root = join(__dirname, "..");
@@ -16,6 +17,10 @@ const notificationsPackage = dirname(createRequire(join(root, "package.json")).r
16
17
  const shippedSql = (path: string) => readFileSync(join(supabasePackage, "migrations", path), "utf8");
17
18
  const chatPackage = dirname(createRequire(join(root, "package.json")).resolve("@marktiderman/genesis-chat/package.json"));
18
19
  const chatSql = (path: string) => readFileSync(join(chatPackage, "migrations", path), "utf8");
20
+ // A switch that carries a block (genesis.config.json `starter.blocks`): an app made with
21
+ // `genesis init --without <switch>` has none of that block's migrations, tests or functions, so
22
+ // the checks of those files run only while it's on.
23
+ const { updates, push, notifications, support, chat } = starter.features;
19
24
 
20
25
  function filesUnder(dir: string): string[] {
21
26
  return readdirSync(join(root, dir)).flatMap((name) => {
@@ -59,7 +64,7 @@ describe("starter.config.ts", () => {
59
64
  });
60
65
 
61
66
  it("declares in the privacy manifest only the blocks that are on", () => {
62
- expect(privacyBlocks(starter.features)).toEqual(["account", "observability", "push", "support"]);
67
+ expect(privacyBlocks({ observability: true, push: true, support: true })).toEqual(["account", "observability", "push", "support"]);
63
68
  expect(privacyBlocks({ observability: false, push: false, support: false })).toEqual(["account"]);
64
69
  });
65
70
 
@@ -78,12 +83,24 @@ describe("starter.config.ts", () => {
78
83
  expect(() => defineStarter({ ...starter, app: { ...starter.app, easProjectId: "" } })).not.toThrow();
79
84
  });
80
85
 
81
- it("ships with the updates block on and no EAS project (a placeholder for `eas init`)", () => {
82
- expect(starter.features.updates).toBe(true);
86
+ it("ships with no EAS project (a placeholder for `eas init`)", () => {
83
87
  expect(starter.app.easProjectId).toBe("");
84
88
  });
85
89
  });
86
90
 
91
+ describe("deep links", () => {
92
+ it("opens the hosts in genesis.config.json's links block", () => {
93
+ expect(linkHosts({ links: { hosts: ["example.com", "app.example.com"] } })).toEqual(["example.com", "app.example.com"]);
94
+ expect(read("src/lib/links.ts")).toContain("hosts: linkHosts(genesisConfig)");
95
+ });
96
+
97
+ it("has no app links, and doesn't throw, when no domain is configured", () => {
98
+ expect(linkHosts({})).toEqual([]);
99
+ expect(linkHosts({ links: null })).toEqual([]);
100
+ expect(linkHosts({ links: {} })).toEqual([]);
101
+ });
102
+ });
103
+
87
104
  describe("EAS config", () => {
88
105
  it("turns expo-updates off in builds until there is an EAS project", () => {
89
106
  expect(easConfig({ easProjectId: "" })).toEqual({ updates: { enabled: false } });
@@ -219,19 +236,19 @@ describe("supabase/migrations", () => {
219
236
  expect(read("supabase/tests/database/genesis_account_deletion.test.sql")).toBe(shipped);
220
237
  });
221
238
 
222
- it("carries the app-release-policy migration unchanged (the updates block reads it)", () => {
239
+ it.runIf(updates)("carries the app-release-policy migration unchanged (the updates block reads it)", () => {
223
240
  const shipped = shippedSql("0002_genesis_app_release_policy.sql");
224
241
  const copies = filesUnder("supabase/migrations").filter((f) => f.endsWith("_genesis_app_release_policy.sql"));
225
242
  expect(copies).toHaveLength(1);
226
243
  expect(read(copies[0]!)).toBe(shipped);
227
244
  });
228
245
 
229
- it("carries its pgTAP test unchanged", () => {
246
+ it.runIf(updates)("carries the app-release-policy pgTAP test unchanged", () => {
230
247
  const shipped = shippedSql("tests/0002_genesis_app_release_policy.test.sql");
231
248
  expect(read("supabase/tests/database/genesis_app_release_policy.test.sql")).toBe(shipped);
232
249
  });
233
250
 
234
- it("applies account deletion before the release policy", () => {
251
+ it.runIf(updates)("applies account deletion before the release policy", () => {
235
252
  const order = filesUnder("supabase/migrations").sort();
236
253
  expect(order.findIndex((f) => f.endsWith("_genesis_account_deletion.sql"))).toBeLessThan(order.findIndex((f) => f.endsWith("_genesis_app_release_policy.sql")));
237
254
  });
@@ -243,7 +260,7 @@ describe("supabase/migrations", () => {
243
260
  expect(read("supabase/tests/database/genesis_apple_token_revocation.test.sql")).toBe(shippedSql("tests/0003_genesis_apple_token_revocation.test.sql"));
244
261
  });
245
262
 
246
- it("carries the push migration unchanged, after the Apple one, without its pgTAP test (superseded by the notifications migration)", () => {
263
+ it.runIf(push)("carries the push migration unchanged, after the Apple one, without its pgTAP test (superseded by the notifications migration)", () => {
247
264
  const copies = filesUnder("supabase/migrations").filter((f) => f.endsWith("_genesis_push.sql"));
248
265
  expect(copies).toHaveLength(1);
249
266
  expect(read(copies[0]!)).toBe(shippedSql("0005_genesis_push.sql"));
@@ -253,7 +270,7 @@ describe("supabase/migrations", () => {
253
270
  expect(order.indexOf(copies[0]!)).toBeGreaterThan(order.findIndex((f) => f.endsWith("_genesis_apple_token_revocation.sql")));
254
271
  });
255
272
 
256
- it("carries @marktiderman/genesis-notifications' migration and its pgTAP test unchanged, after every other package's (it adopts the push tables)", () => {
273
+ it.runIf(notifications)("carries @marktiderman/genesis-notifications' migration and its pgTAP test unchanged, after every other package's (it adopts the push tables)", () => {
257
274
  const shipped = (rel: string) => readFileSync(join(notificationsPackage, "migrations", rel), "utf8");
258
275
  const copies = filesUnder("supabase/migrations").filter((f) => f.endsWith("_genesis_notifications.sql"));
259
276
  expect(copies).toHaveLength(1);
@@ -265,7 +282,7 @@ describe("supabase/migrations", () => {
265
282
  expect(packaged.at(-1)).toBe(copies[0]);
266
283
  });
267
284
 
268
- it("carries the support migration and its pgTAP test unchanged (the support block reads it), after the push one", () => {
285
+ it.runIf(support)("carries the support migration and its pgTAP test unchanged (the support block reads it), after the push one", () => {
269
286
  const copies = filesUnder("supabase/migrations").filter((f) => f.endsWith("_genesis_support.sql"));
270
287
  expect(copies).toHaveLength(1);
271
288
  expect(read(copies[0]!)).toBe(shippedSql("0006_genesis_support.sql"));
@@ -290,7 +307,7 @@ describe("supabase/functions", () => {
290
307
  expect(read("supabase/config.toml")).toMatch(/\[functions\.genesis-apple-revoke\]\s*\nverify_jwt = false/);
291
308
  });
292
309
 
293
- it("carries the genesis-push-send function unchanged, deployed without the gateway's JWT check (it checks GENESIS_PUSH_SECRET)", () => {
310
+ it.runIf(push)("carries the genesis-push-send function unchanged, deployed without the gateway's JWT check (it checks GENESIS_PUSH_SECRET)", () => {
294
311
  const shipped = join(supabasePackage, "functions", "genesis-push-send");
295
312
  const names = readdirSync(shipped).sort();
296
313
  expect(names).toEqual(["expo.ts", "handler.ts", "index.ts"]);
@@ -303,8 +320,7 @@ describe("supabase/functions", () => {
303
320
  });
304
321
 
305
322
  describe("push", () => {
306
- it("ships with the push block on, behind the one `push` switch", () => {
307
- expect(starter.features.push).toBe(true);
323
+ it("puts the push block behind the one `push` switch", () => {
308
324
  expect(read("src/lib/app.ts")).toContain("features.push ? createStarterPush() : undefined");
309
325
  });
310
326
 
@@ -321,8 +337,7 @@ describe("push", () => {
321
337
  });
322
338
 
323
339
  describe("support", () => {
324
- it("ships with the support block on, behind the one `support` switch, needing a signed-in person", () => {
325
- expect(starter.features.support).toBe(true);
340
+ it("puts the support block behind the one `support` switch, needing a signed-in person", () => {
326
341
  expect(read("src/lib/app.ts")).toMatch(/blocks: \[[^\]]*\bsupport\b/);
327
342
  expect(read("src/lib/support.ts")).toContain("starter.features.support ? createStarterSupport() : undefined");
328
343
  expect(read("src/lib/app.ts")).toContain('appFeatures: ["account"]');
@@ -342,8 +357,7 @@ describe("support", () => {
342
357
  });
343
358
 
344
359
  describe("chat", () => {
345
- it("ships with chat on, its migration and pgTAP test copied unchanged after the support one, and genesis_chat served by the API", () => {
346
- expect(starter.features.chat).toBe(true);
360
+ it.runIf(chat)("carries chat's migration and pgTAP test unchanged after the support one, and serves genesis_chat through the API", () => {
347
361
  const copies = filesUnder("supabase/migrations").filter((f) => f.endsWith("_genesis_chat.sql"));
348
362
  expect(copies).toHaveLength(1);
349
363
  expect(read(copies[0]!)).toBe(chatSql("0001_genesis_chat.sql"));
@@ -364,7 +378,7 @@ describe("chat", () => {
364
378
  expect(JSON.parse(read("genesis.config.json")).doctor.supabase.exposedSchemas).toContain("genesis_chat");
365
379
  });
366
380
 
367
- it("carries chat's 0002 migration (topics, scheduled send, availability, broadcast, search) and its pgTAP test unchanged, after 0001", () => {
381
+ it.runIf(chat)("carries chat's 0002 migration (topics, scheduled send, availability, broadcast, search) and its pgTAP test unchanged, after 0001", () => {
368
382
  const copies = filesUnder("supabase/migrations").filter((f) => f.endsWith("_genesis_chat_coaching.sql"));
369
383
  expect(copies).toHaveLength(1);
370
384
  expect(read(copies[0]!)).toBe(chatSql("0002_genesis_chat_coaching.sql"));
@@ -409,7 +423,7 @@ describe("chat", () => {
409
423
  expect(read("src/lib/chat.tsx")).toContain("starter.features.chat && starter.features.push");
410
424
  });
411
425
 
412
- it("names people from their auth metadata through chat_people, after the chat migration, with its pgTAP test", () => {
426
+ it.runIf(chat)("names people from their auth metadata through chat_people, after the chat migration, with its pgTAP test", () => {
413
427
  const copies = filesUnder("supabase/migrations").filter((f) => f.endsWith("_chat_people.sql"));
414
428
  expect(copies).toHaveLength(1);
415
429
  const order = filesUnder("supabase/migrations").sort();
@@ -8,5 +8,15 @@
8
8
  "links": {
9
9
  "hosts": ["example.com"],
10
10
  "paths": ["/notifications", "/messages", "/settings"]
11
+ },
12
+ "starter": {
13
+ "$comment": "The blocks each starter.config.ts switch carries. A block whose switch is off isn't in genesis.lock.json, and genesis upgrade and migrate leave it out (genesis init --without leaves its files out too).",
14
+ "blocks": {
15
+ "updates": ["app-updates"],
16
+ "push": ["push"],
17
+ "notifications": ["notifications"],
18
+ "support": ["support-feedback"],
19
+ "chat": ["chat"]
20
+ }
11
21
  }
12
22
  }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The web hosts whose links open in the app: genesis.config.json's `links.hosts`. An app with no
3
+ * domain yet has no `links` block (or no hosts in it), so it has no app links and only its
4
+ * schemes open it. Kept free of React Native imports so the tests can read it.
5
+ */
6
+ export function linkHosts(config: { links?: { hosts?: readonly string[] } | null }): string[] {
7
+ return [...(config.links?.hosts ?? [])];
8
+ }
@@ -7,6 +7,7 @@ import Constants from "expo-constants";
7
7
  import { createLinkHold, type LinkOptions } from "@marktiderman/genesis-native";
8
8
  import genesisConfig from "../../genesis.config.json";
9
9
  import starter from "../../starter.config";
10
+ import { linkHosts } from "./link-hosts";
10
11
 
11
12
  /**
12
13
  * The schemes this build answers to. withGenesis gives each APP_VARIANT its own
@@ -26,7 +27,7 @@ export function appSchemes(base: string, built: string | readonly string[] | und
26
27
  /** Incoming link paths and the screens they open. `/` is always known; anything else opens `/`. */
27
28
  export const links: LinkOptions = {
28
29
  schemes: appSchemes(starter.app.scheme, Constants.expoConfig?.scheme),
29
- hosts: genesisConfig.links.hosts,
30
+ hosts: linkHosts(genesisConfig),
30
31
  map: {
31
32
  ...(starter.features.notifications ? { "/notifications": "/notifications" } : {}),
32
33
  // The check-in example's link (`genesis-starter://check-in?location=hilltop` fills in the location; `genesis-starter-dev://` in a development build).
@@ -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'));