-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodex_review.diff
More file actions
1368 lines (1340 loc) · 130 KB
/
Copy pathcodex_review.diff
File metadata and controls
1368 lines (1340 loc) · 130 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/dev/reports/PR_26179_OWNER_035-dev-auth-user-key-db-authority_branch_validation.md b/dev/reports/PR_26179_OWNER_035-dev-auth-user-key-db-authority_branch_validation.md
new file mode 100644
index 000000000..50c821aaa
--- /dev/null
+++ b/dev/reports/PR_26179_OWNER_035-dev-auth-user-key-db-authority_branch_validation.md
@@ -0,0 +1,34 @@
+# Branch Validation: PR_26179_OWNER_035-dev-auth-user-key-db-authority
+
+## Status
+
+PASS
+
+## Branch
+
+- Current branch: `PR_26179_OWNER_035-dev-auth-user-key-db-authority`
+- Source branch: `main`
+- Worktree at report time: modified files only for this PR plus generated report artifacts
+
+## Validation Commands
+
+- PASS `node --check src/dev-runtime/server/local-api-router.mjs`
+- PASS `node --check src/dev-runtime/testing/supabase-dev-creator-identity-seed-sync.mjs`
+- PASS `node --check dev/tests/dev-runtime/SupabaseProviderContractStub.test.mjs`
+- PASS `node --check dev/tests/dev-runtime/SupabaseDevCreatorIdentitySeedSync.test.mjs`
+- PASS `node --check src/dev-runtime/toolbox-api/alfa-tool-services.mjs`
+- PASS `node --check dev/scripts/sync-supabase-dev-creator-identities.mjs`
+- PASS `node --check dev/tests/dev-runtime/TagsApiService.test.mjs`
+- PASS `node --test dev/tests/dev-runtime/SupabaseDevCreatorIdentitySeedSync.test.mjs`
+- PASS `node --test --test-name-pattern "Supabase sign-in resolves|Supabase sign-in does not" dev/tests/dev-runtime/SupabaseProviderContractStub.test.mjs`
+- PASS `node --test dev/tests/dev-runtime/TagsApiService.test.mjs`
+- PASS `git diff --check`
+- PASS `npm run validate:canonical-structure`
+
+## DEV Identity Verification
+
+- PASS `qbytes.dq@gmail.com` exists in Supabase Auth.
+- PASS `qbytes.dq@gmail.com` exists in product `users`.
+- PASS `users.authProviderUserId` matches Supabase Auth id.
+- PASS DEV identity sync ran with password updates disabled.
+- PASS `/api/auth/sign-in` resolves qbytes to the database `users.key`.
diff --git a/dev/reports/PR_26179_OWNER_035-dev-auth-user-key-db-authority_manual_validation_notes.md b/dev/reports/PR_26179_OWNER_035-dev-auth-user-key-db-authority_manual_validation_notes.md
new file mode 100644
index 000000000..363e4ccda
--- /dev/null
+++ b/dev/reports/PR_26179_OWNER_035-dev-auth-user-key-db-authority_manual_validation_notes.md
@@ -0,0 +1,16 @@
+# Manual Validation Notes: PR_26179_OWNER_035-dev-auth-user-key-db-authority
+
+Manual browser validation was not run because this PR changes server-side auth/session resolution and DEV identity sync behavior. The targeted API-level tests and live API sign-in smoke cover the affected user-visible outcomes:
+
+- A valid Supabase Auth id linked to `users.authProviderUserId` signs in and returns the database-owned `users.key`.
+- A matching email with stale `users.authProviderUserId` does not sign in and returns the existing Creator-safe identity setup message.
+- The browser response does not expose raw Auth ids or database user keys on the failure path.
+
+Live DEV notes:
+
+- Initial audit found Supabase Auth present but product `users` missing for `qbytes.dq@gmail.com`.
+- The missing database row was caused by a toolbox helper upserting seed users over the reserved account keys.
+- The helper was fixed so toolbox seeding no longer upserts `users`.
+- The approved DEV account DML restored the missing rows.
+- DEV identity sync ran with password updates disabled.
+- Final `/api/auth/sign-in` smoke for `qbytes.dq@gmail.com` passed and resolved to the database `users.key`.
diff --git a/dev/reports/PR_26179_OWNER_035-dev-auth-user-key-db-authority_report.md b/dev/reports/PR_26179_OWNER_035-dev-auth-user-key-db-authority_report.md
new file mode 100644
index 000000000..fb83e9015
--- /dev/null
+++ b/dev/reports/PR_26179_OWNER_035-dev-auth-user-key-db-authority_report.md
@@ -0,0 +1,93 @@
+# PR_26179_OWNER_035-dev-auth-user-key-db-authority
+
+## Summary
+
+This PR makes DEV account session resolution treat the database `users` row as authoritative.
+
+Runtime sign-in now resolves a session only when the Supabase Auth user id matches `users.authProviderUserId`. Matching by email alone is no longer accepted for login/session resolution. Email remains valid only for the DEV identity sync step that locates the existing database `users` row before writing the real Supabase Auth id back to `users.authProviderUserId`.
+
+## Diagnostic Findings
+
+### Where `users.key` currently comes from
+
+- DEV seed setup defines static user keys in `src/dev-runtime/seed/seed-db-keys.mjs`.
+- Current database seed DML also contains DEV account rows under `dev/build/database/dml/account.sql`.
+- Before this PR, `src/dev-runtime/testing/supabase-dev-creator-identity-seed-sync.mjs` imported those seed keys and used them as the canonical keys during DEV Supabase identity sync.
+- After this PR, DEV sync locates existing `users` rows by email and reads `users.key` from the database row. The sync no longer imports `SEED_DB_KEYS`.
+
+### Where `authProviderUserId` is populated
+
+- Account creation provisioning still writes `authProviderUserId` in `src/dev-runtime/server/local-api-router.mjs` through `provisionSupabaseIdentityForAuthPayload()`.
+- DEV identity sync now reads `auth.users.id` from Supabase Auth, reads `users.key` from the database row found by email, and sends that database-owned key plus the real Auth id through `databaseProvider.initializeIdentity()`.
+
+### Seed constant use
+
+- Seed constants remain valid for DEV seed setup, seed fixtures, and existing test/demo data.
+- They are no longer used by the DEV identity sync helper as the authoritative app user key source.
+- Runtime sign-in/session resolution does not hardcode DavidQ or other user keys. It reads identity tables and resolves `matchingUser.key` after matching Supabase Auth id to `users.authProviderUserId`.
+
+## Exact Fix
+
+- Removed email fallback from Supabase sign-in session resolution.
+- Added a Creator-safe setup failure when Auth succeeds but the matching email row has not been linked to the Auth id.
+- Added a narrow server-side Postgres client injection hook for tests, with default runtime behavior unchanged.
+- Refactored DEV creator identity sync so canonical identity definitions are email-based and database `users.key` is read from existing rows.
+- Changed role assignment and cleanup repair logic to derive canonical user keys from database rows.
+- Removed the Alfa toolbox tag/design/configuration helper behavior that upserted seed `users` rows over the static DEV account keys.
+- Changed the DEV identity sync default so existing Supabase Auth users are updated without sending a password. Password updates now require an explicit `--update-passwords` flag.
+- Added regression tests proving:
+ - Sign-in uses the database-owned `users.key` matched by `authProviderUserId`.
+ - Sign-in does not create a session from matching email when `authProviderUserId` is stale.
+ - DEV sync preserves non-seed database user keys.
+ - DEV sync fails if an expected database `users` row is missing.
+ - Tags API seeding does not upsert rows into `users`.
+ - Existing Auth user sync does not send a password by default.
+
+## DEV Database Verification
+
+Performed against the current `.env` DEV database target.
+
+Initial audit:
+
+- `qbytes.dq@gmail.com` existed in Supabase Auth.
+- `qbytes.dq@gmail.com` was missing from the product `users` table.
+- The reserved static DEV account keys for User 1 and DavidQ had been overwritten by seed `Creator` / `Forge Bot` rows.
+
+Repair and sync:
+
+- Re-applied the approved DEV account DML to restore the missing database identity rows.
+- Ran the DEV identity sync with `updatePasswords: false`.
+- qbytes sync action: `updated`.
+- qbytes password update: `false`.
+
+Final audit:
+
+- Supabase Auth match count: `1`.
+- Product `users` match count: `1`.
+- `users.authProviderUserId` equals Supabase Auth `auth.users.id`: PASS.
+- Sign-in smoke through `/api/auth/sign-in`: PASS.
+- Session resolved to the database `users.key`: PASS.
+
+## Files Changed
+
+- `src/dev-runtime/server/local-api-router.mjs`
+- `src/dev-runtime/testing/supabase-dev-creator-identity-seed-sync.mjs`
+- `dev/tests/dev-runtime/SupabaseProviderContractStub.test.mjs`
+- `dev/tests/dev-runtime/SupabaseDevCreatorIdentitySeedSync.test.mjs`
+
+## Validation
+
+PASS:
+
+- `node --check src/dev-runtime/server/local-api-router.mjs`
+- `node --check src/dev-runtime/testing/supabase-dev-creator-identity-seed-sync.mjs`
+- `node --check dev/tests/dev-runtime/SupabaseProviderContractStub.test.mjs`
+- `node --check dev/tests/dev-runtime/SupabaseDevCreatorIdentitySeedSync.test.mjs`
+- `node --check src/dev-runtime/toolbox-api/alfa-tool-services.mjs`
+- `node --check dev/scripts/sync-supabase-dev-creator-identities.mjs`
+- `node --check dev/tests/dev-runtime/TagsApiService.test.mjs`
+- `node --test dev/tests/dev-runtime/SupabaseDevCreatorIdentitySeedSync.test.mjs`
+- `node --test --test-name-pattern "Supabase sign-in resolves|Supabase sign-in does not" dev/tests/dev-runtime/SupabaseProviderContractStub.test.mjs`
+- `node --test dev/tests/dev-runtime/TagsApiService.test.mjs`
+- `git diff --check`
+- `npm run validate:canonical-structure`
diff --git a/dev/reports/PR_26179_OWNER_035-dev-auth-user-key-db-authority_requirement_checklist.md b/dev/reports/PR_26179_OWNER_035-dev-auth-user-key-db-authority_requirement_checklist.md
new file mode 100644
index 000000000..0b53b8e3a
--- /dev/null
+++ b/dev/reports/PR_26179_OWNER_035-dev-auth-user-key-db-authority_requirement_checklist.md
@@ -0,0 +1,25 @@
+# Requirement Checklist: PR_26179_OWNER_035-dev-auth-user-key-db-authority
+
+- PASS Do not use hardcoded user keys as runtime identity source.
+- PASS Use email only to locate the existing DEV `users` row during DEV identity sync.
+- PASS Read `users.key` from the database row during DEV sync.
+- PASS Read `auth.users.id` from Supabase Auth during DEV sync.
+- PASS Write `auth.users.id` into `users.authProviderUserId`.
+- PASS Login/session resolution matches Supabase Auth id to `users.authProviderUserId`.
+- PASS Do not create browser-owned auth.
+- PASS Do not create fake login.
+- PASS Do not add password tables.
+- PASS Do not use `displayName` as an identity key.
+- PASS Do not hardcode DavidQ/user keys in runtime login resolution.
+- PASS Verify qbytes exists in Supabase Auth.
+- PASS Verify qbytes exists in the product `users` table.
+- PASS Verify `users.authProviderUserId` equals Supabase Auth id.
+- PASS If the database row/link is stale, run DEV identity sync.
+- PASS Do not change password during existing Auth user sync.
+- PASS Do not recreate qbytes Auth user because it already exists.
+- PASS Do not use email fallback for session resolution.
+- PASS Re-test sign-in after sync.
+- PASS Report where `users.key` currently comes from.
+- PASS Report where `authProviderUserId` is populated.
+- PASS Report whether seed constants are setup-only or runtime identity authority.
+- PASS Report exact fix.
diff --git a/dev/reports/PR_26179_OWNER_035-dev-auth-user-key-db-authority_validation_lane_report.md b/dev/reports/PR_26179_OWNER_035-dev-auth-user-key-db-authority_validation_lane_report.md
new file mode 100644
index 000000000..d3aa670c1
--- /dev/null
+++ b/dev/reports/PR_26179_OWNER_035-dev-auth-user-key-db-authority_validation_lane_report.md
@@ -0,0 +1,21 @@
+# Validation Lane Report: PR_26179_OWNER_035-dev-auth-user-key-db-authority
+
+## Lane
+
+Targeted auth and DEV identity sync validation.
+
+## Commands
+
+- PASS `node --test dev/tests/dev-runtime/SupabaseDevCreatorIdentitySeedSync.test.mjs`
+- PASS `node --test --test-name-pattern "Supabase sign-in resolves|Supabase sign-in does not" dev/tests/dev-runtime/SupabaseProviderContractStub.test.mjs`
+- PASS `node --test dev/tests/dev-runtime/TagsApiService.test.mjs`
+- PASS live DEV identity audit and sign-in smoke for `qbytes.dq@gmail.com`
+
+## Coverage
+
+- DEV identity sync reads existing database `users.key` values by email.
+- DEV identity sync writes real Supabase Auth ids to `users.authProviderUserId`.
+- Existing Auth user sync does not update passwords by default.
+- Session resolution accepts only `auth.users.id` matched to `users.authProviderUserId`.
+- Email-only session resolution is rejected with the existing Creator-safe setup message.
+- Tags API setup no longer writes seed rows to the account `users` table.
diff --git a/dev/reports/PR_26179_OWNER_035-dev-auth-user-key-db-authority_validation_report.md b/dev/reports/PR_26179_OWNER_035-dev-auth-user-key-db-authority_validation_report.md
new file mode 100644
index 000000000..bc901b4c1
--- /dev/null
+++ b/dev/reports/PR_26179_OWNER_035-dev-auth-user-key-db-authority_validation_report.md
@@ -0,0 +1,36 @@
+# Validation Report: PR_26179_OWNER_035-dev-auth-user-key-db-authority
+
+## Result
+
+PASS
+
+## Targeted Validation
+
+- `node --check src/dev-runtime/server/local-api-router.mjs`: PASS
+- `node --check src/dev-runtime/testing/supabase-dev-creator-identity-seed-sync.mjs`: PASS
+- `node --check dev/tests/dev-runtime/SupabaseProviderContractStub.test.mjs`: PASS
+- `node --check dev/tests/dev-runtime/SupabaseDevCreatorIdentitySeedSync.test.mjs`: PASS
+- `node --check src/dev-runtime/toolbox-api/alfa-tool-services.mjs`: PASS
+- `node --check dev/scripts/sync-supabase-dev-creator-identities.mjs`: PASS
+- `node --check dev/tests/dev-runtime/TagsApiService.test.mjs`: PASS
+- `node --test dev/tests/dev-runtime/SupabaseDevCreatorIdentitySeedSync.test.mjs`: PASS, 2 tests
+- `node --test --test-name-pattern "Supabase sign-in resolves|Supabase sign-in does not" dev/tests/dev-runtime/SupabaseProviderContractStub.test.mjs`: PASS, 2 tests
+- `node --test dev/tests/dev-runtime/TagsApiService.test.mjs`: PASS, 3 tests
+
+## Live DEV Validation
+
+- PASS Initial audit detected Supabase Auth user for `qbytes.dq@gmail.com`.
+- PASS Initial audit detected missing/stale product `users` row and halted sign-in retest.
+- PASS Approved DEV account DML restored the missing identity rows.
+- PASS DEV identity sync completed with `updatePasswords: false`.
+- PASS Final audit verified `users.authProviderUserId` equals Supabase Auth id.
+- PASS `/api/auth/sign-in` returned HTTP 200 and resolved the session to the database `users.key`.
+
+## Repository Guardrails
+
+- `git diff --check`: PASS
+- `npm run validate:canonical-structure`: PASS
+
+## Notes
+
+The targeted tests use a server-side Postgres client fixture to exercise the Local API route without opening a real database connection. Default runtime behavior remains unchanged because the injected client defaults to `null`.
diff --git a/dev/reports/codex_changed_files.txt b/dev/reports/codex_changed_files.txt
index 9883c823c..451d447a3 100644
--- a/dev/reports/codex_changed_files.txt
+++ b/dev/reports/codex_changed_files.txt
@@ -1,98 +1,52 @@
-# Alfa Objects Stack EOD Changed Files
+# git status --short
+M dev/reports/PR_26179_OWNER_035-dev-auth-user-key-db-authority_branch_validation.md
+ M dev/reports/PR_26179_OWNER_035-dev-auth-user-key-db-authority_manual_validation_notes.md
+ M dev/reports/PR_26179_OWNER_035-dev-auth-user-key-db-authority_report.md
+ M dev/reports/PR_26179_OWNER_035-dev-auth-user-key-db-authority_requirement_checklist.md
+ M dev/reports/PR_26179_OWNER_035-dev-auth-user-key-db-authority_validation_lane_report.md
+ M dev/reports/PR_26179_OWNER_035-dev-auth-user-key-db-authority_validation_report.md
+ M dev/reports/codex_changed_files.txt
+ M dev/reports/codex_review.diff
+ M dev/scripts/sync-supabase-dev-creator-identities.mjs
+ M dev/tests/dev-runtime/SupabaseDevCreatorIdentitySeedSync.test.mjs
+ M dev/tests/dev-runtime/TagsApiService.test.mjs
+ M src/dev-runtime/testing/supabase-dev-creator-identity-seed-sync.mjs
+ M src/dev-runtime/toolbox-api/alfa-tool-services.mjs
-Base before Objects stack: 13ed907456492612adce750a434b52058301bbf5
-Objects stack merge head: 54b4c4a894e8e6ddf75d8dabdda0cc0f87f92a51
-Current branch during report: main
-main...origin/main during report: 0 0
-
-# Merged PRs
-- PR_26179_ALFA_011-objects-manager-mvp: a2da07a84adea589a22b05ed8985bdcf7d5806db Merge PR_26179_ALFA_011 Objects Manager MVP
-- PR_26179_ALFA_012-objects-properties-mvp: 76ef2bcfff8a8fb0a3949901dc32a090593a4480 Merge PR_26179_ALFA_012 Object Properties MVP
-- PR_26179_ALFA_013-objects-asset-links: 22464cc322f6d8c2721124dd1ca30d13f0adc8cf Merge PR_26179_ALFA_013 Objects Asset Links
-- PR_26179_ALFA_014-objects-journey-readiness: 54b4c4a894e8e6ddf75d8dabdda0cc0f87f92a51 Merge PR_26179_ALFA_014 Objects Journey Readiness
-
-# git status --short before report refresh
-M dev/reports/codex_review.diff
-
-# git diff --name-status 13ed907456492612adce750a434b52058301bbf5..54b4c4a894e8e6ddf75d8dabdda0cc0f87f92a51
-M assets/toolbox/game-journey/js/index.js
-M assets/toolbox/objects/js/index.js
-A dev/reports/PR_26179_ALFA_011-objects-manager-mvp_branch-validation.md
-A dev/reports/PR_26179_ALFA_011-objects-manager-mvp_manual-validation-notes.md
-A dev/reports/PR_26179_ALFA_011-objects-manager-mvp_report.md
-A dev/reports/PR_26179_ALFA_011-objects-manager-mvp_requirement-checklist.md
-A dev/reports/PR_26179_ALFA_011-objects-manager-mvp_validation-lane.md
-A dev/reports/PR_26179_ALFA_011-objects-manager-mvp_validation-report.md
-A dev/reports/PR_26179_ALFA_012-objects-properties-mvp_branch_validation.md
-A dev/reports/PR_26179_ALFA_012-objects-properties-mvp_manual_validation_notes.md
-A dev/reports/PR_26179_ALFA_012-objects-properties-mvp_report.md
-A dev/reports/PR_26179_ALFA_012-objects-properties-mvp_requirement_checklist.md
-A dev/reports/PR_26179_ALFA_012-objects-properties-mvp_validation_lane.md
-A dev/reports/PR_26179_ALFA_012-objects-properties-mvp_validation_report.md
-A dev/reports/PR_26179_ALFA_013-objects-asset-links_branch_validation.md
-A dev/reports/PR_26179_ALFA_013-objects-asset-links_manual_validation_notes.md
-A dev/reports/PR_26179_ALFA_013-objects-asset-links_report.md
-A dev/reports/PR_26179_ALFA_013-objects-asset-links_requirement_checklist.md
-A dev/reports/PR_26179_ALFA_013-objects-asset-links_validation_lane.md
-A dev/reports/PR_26179_ALFA_013-objects-asset-links_validation_report.md
-A dev/reports/PR_26179_ALFA_014-objects-journey-readiness_branch_validation.md
-A dev/reports/PR_26179_ALFA_014-objects-journey-readiness_eod_report.md
-A dev/reports/PR_26179_ALFA_014-objects-journey-readiness_manual_validation_notes.md
-A dev/reports/PR_26179_ALFA_014-objects-journey-readiness_report.md
-A dev/reports/PR_26179_ALFA_014-objects-journey-readiness_requirement_checklist.md
-A dev/reports/PR_26179_ALFA_014-objects-journey-readiness_validation_lane.md
-A dev/reports/PR_26179_ALFA_014-objects-journey-readiness_validation_report.md
-A dev/reports/PR_26179_ALFA_objects-stack_product-owner-review-notes.md
+# git diff --name-status main
+A dev/reports/PR_26179_OWNER_035-dev-auth-user-key-db-authority_branch_validation.md
+A dev/reports/PR_26179_OWNER_035-dev-auth-user-key-db-authority_manual_validation_notes.md
+A dev/reports/PR_26179_OWNER_035-dev-auth-user-key-db-authority_report.md
+A dev/reports/PR_26179_OWNER_035-dev-auth-user-key-db-authority_requirement_checklist.md
+A dev/reports/PR_26179_OWNER_035-dev-auth-user-key-db-authority_validation_lane_report.md
+A dev/reports/PR_26179_OWNER_035-dev-auth-user-key-db-authority_validation_report.md
M dev/reports/codex_changed_files.txt
M dev/reports/codex_review.diff
-M dev/reports/coverage_changed_js_guardrail.txt
-M dev/reports/playwright_v8_coverage_report.txt
-A dev/tests/dev-runtime/ObjectsApiService.test.mjs
-M dev/tests/playwright/tools/GameJourneyTool.spec.mjs
-M dev/tests/playwright/tools/ObjectsTool.spec.mjs
+M dev/scripts/sync-supabase-dev-creator-identities.mjs
+M dev/tests/dev-runtime/SupabaseDevCreatorIdentitySeedSync.test.mjs
+M dev/tests/dev-runtime/SupabaseProviderContractStub.test.mjs
+M dev/tests/dev-runtime/TagsApiService.test.mjs
M src/dev-runtime/server/local-api-router.mjs
+M src/dev-runtime/testing/supabase-dev-creator-identity-seed-sync.mjs
M src/dev-runtime/toolbox-api/alfa-tool-services.mjs
-M toolbox/game-journey/index.html
-M toolbox/objects/index.html
-# git diff --stat 13ed907456492612adce750a434b52058301bbf5..54b4c4a894e8e6ddf75d8dabdda0cc0f87f92a51
-assets/toolbox/game-journey/js/index.js | 285 +++++-
- assets/toolbox/objects/js/index.js | 598 ++++++++++++-
- ...FA_011-objects-manager-mvp_branch-validation.md | 10 +
- ...-objects-manager-mvp_manual-validation-notes.md | 19 +
- ...PR_26179_ALFA_011-objects-manager-mvp_report.md | 39 +
- ...11-objects-manager-mvp_requirement-checklist.md | 16 +
- ...ALFA_011-objects-manager-mvp_validation-lane.md | 17 +
- ...FA_011-objects-manager-mvp_validation-report.md | 19 +
- ...012-objects-properties-mvp_branch_validation.md | 26 +
- ...jects-properties-mvp_manual_validation_notes.md | 22 +
- ...26179_ALFA_012-objects-properties-mvp_report.md | 40 +
- ...objects-properties-mvp_requirement_checklist.md | 23 +
- ...A_012-objects-properties-mvp_validation_lane.md | 23 +
- ...012-objects-properties-mvp_validation_report.md | 18 +
- ...FA_013-objects-asset-links_branch_validation.md | 27 +
- ...-objects-asset-links_manual_validation_notes.md | 24 +
- ...PR_26179_ALFA_013-objects-asset-links_report.md | 41 +
- ...13-objects-asset-links_requirement_checklist.md | 15 +
- ...ALFA_013-objects-asset-links_validation_lane.md | 23 +
- ...FA_013-objects-asset-links_validation_report.md | 16 +
- ...-objects-journey-readiness_branch_validation.md | 24 +
- ...LFA_014-objects-journey-readiness_eod_report.md | 27 +
- ...ts-journey-readiness_manual_validation_notes.md | 14 +
- ...79_ALFA_014-objects-journey-readiness_report.md | 34 +
- ...ects-journey-readiness_requirement_checklist.md | 17 +
- ...14-objects-journey-readiness_validation_lane.md | 20 +
- ...-objects-journey-readiness_validation_report.md | 19 +
- ...LFA_objects-stack_product-owner-review-notes.md | 87 ++
- dev/reports/codex_changed_files.txt | 55 +-
- dev/reports/codex_review.diff | 988 ++++++++++++++++++++-
- dev/reports/coverage_changed_js_guardrail.txt | 4 +-
- dev/reports/playwright_v8_coverage_report.txt | 31 +-
- dev/tests/dev-runtime/ObjectsApiService.test.mjs | 224 +++++
- .../playwright/tools/GameJourneyTool.spec.mjs | 94 ++
- dev/tests/playwright/tools/ObjectsTool.spec.mjs | 211 ++++-
- src/dev-runtime/server/local-api-router.mjs | 14 +-
- src/dev-runtime/toolbox-api/alfa-tool-services.mjs | 417 +++++++++
- toolbox/game-journey/index.html | 21 +
- toolbox/objects/index.html | 53 ++
- 39 files changed, 3601 insertions(+), 54 deletions(-)
+# git ls-files --others --exclude-standard
+(no output)
+
+# git diff --stat main
+...auth-user-key-db-authority_branch_validation.md | 34 ++
+ ...ser-key-db-authority_manual_validation_notes.md | 16 +
+ ...ER_035-dev-auth-user-key-db-authority_report.md | 93 +++++
+ ...-user-key-db-authority_requirement_checklist.md | 25 ++
+ ...user-key-db-authority_validation_lane_report.md | 21 +
+ ...auth-user-key-db-authority_validation_report.md | 36 ++
+ dev/reports/codex_changed_files.txt | 33 +-
+ dev/reports/codex_review.diff | 448 ++++++++++++++++-----
+ .../sync-supabase-dev-creator-identities.mjs | 5 +-
+ .../SupabaseDevCreatorIdentitySeedSync.test.mjs | 192 ++++++---
+ .../SupabaseProviderContractStub.test.mjs | 138 ++++++-
+ dev/tests/dev-runtime/TagsApiService.test.mjs | 1 +
+ src/dev-runtime/server/local-api-router.mjs | 24 +-
+ .../supabase-dev-creator-identity-seed-sync.mjs | 167 +++++---
+ src/dev-runtime/toolbox-api/alfa-tool-services.mjs | 31 --
+ 15 files changed, 996 insertions(+), 268 deletions(-)
diff --git a/dev/scripts/sync-supabase-dev-creator-identities.mjs b/dev/scripts/sync-supabase-dev-creator-identities.mjs
index 0363e1483..31bcc5f08 100644
--- a/dev/scripts/sync-supabase-dev-creator-identities.mjs
+++ b/dev/scripts/sync-supabase-dev-creator-identities.mjs
@@ -66,14 +66,16 @@ function formatRecordList(label, records, selector) {
const args = new Set(process.argv.slice(2));
const json = args.has("--json");
const dryRun = args.has("--dry-run");
+const updatePasswords = args.has("--update-passwords");
const envLoad = loadEnvLocal();
try {
- const result = await syncSupabaseDevCreatorIdentities({ dryRun });
+ const result = await syncSupabaseDevCreatorIdentities({ dryRun, updatePasswords });
if (json) {
console.log(JSON.stringify({
envLocalLoaded: envLoad.loaded,
envLocalLoadedKeys: envLoad.loadedKeys,
+ updatePasswords,
...result,
}, null, 2));
} else {
@@ -81,6 +83,7 @@ try {
console.log(envLoad.loaded
? `.env.local loaded (${envLoad.loadedKeys} key(s) applied).`
: ".env.local was not found.");
+ console.log(`Password updates for existing Auth users: ${updatePasswords ? "enabled" : "disabled"}.`);
formatCounts("Before", result.beforeCounts);
formatCounts("After", result.afterCounts);
formatRecordList("Auth upserts", result.authUpsertRecords, (record) => `${record.email}: ${record.action}`);
diff --git a/dev/tests/dev-runtime/SupabaseDevCreatorIdentitySeedSync.test.mjs b/dev/tests/dev-runtime/SupabaseDevCreatorIdentitySeedSync.test.mjs
index 39ba2d5c7..c3176b89c 100644
--- a/dev/tests/dev-runtime/SupabaseDevCreatorIdentitySeedSync.test.mjs
+++ b/dev/tests/dev-runtime/SupabaseDevCreatorIdentitySeedSync.test.mjs
@@ -11,11 +11,19 @@ import {
} from "../../../src/dev-runtime/testing/supabase-dev-creator-identity-seed-sync.mjs";
const syncEnv = Object.freeze({
+ GAMEFOUNDRY_DATABASE_SSL: "disable",
+ GAMEFOUNDRY_DATABASE_URL: "postgres://sync_user:sync_password@dev-sync.example.test/gamefoundry",
GAMEFOUNDRY_ENV: "dev",
GAMEFOUNDRY_SUPABASE_ANON_KEY: "test-anon-key",
GAMEFOUNDRY_SUPABASE_SERVICE_ROLE_KEY: "test-service-role-key",
GAMEFOUNDRY_SUPABASE_URL: "https://supabase-sync.example.test",
});
+const DEV_DB_USER_KEYS = Object.freeze({
+ davidq: "01J00000000000000000000014",
+ user1: "01J00000000000000000000011",
+ user2: "01J00000000000000000000012",
+ user3: "01J00000000000000000000013",
+});
function decodeEqFilter(searchParams, key) {
const value = searchParams.get(key) || "";
@@ -43,10 +51,10 @@ function createFakeSupabaseSyncState() {
{ key: "role-user", roleSlug: "user", name: "User", isActive: true, isSystemRole: false, ...audit },
],
user_roles: [
- { key: "old-user-role", userKey: SEED_DB_KEYS.users.user1, roleKey: "role-user", ...audit },
- { key: "missing-role-reference", userKey: SEED_DB_KEYS.users.admin, roleKey: "01KV6FVP0ASR2RRR9WXCBKTV6C", ...audit },
+ { key: "old-user-role", userKey: DEV_DB_USER_KEYS.user1, roleKey: "role-user", ...audit },
+ { key: "missing-role-reference", userKey: DEV_DB_USER_KEYS.davidq, roleKey: "01KV6FVP0ASR2RRR9WXCBKTV6C", ...audit },
{ key: "extra-user-role", userKey: "user-extra-codex", roleKey: "role-creator", ...audit },
- { key: "davidq-admin-role", userKey: SEED_DB_KEYS.users.admin, roleKey: "role-admin", ...audit },
+ { key: "davidq-admin-role", userKey: DEV_DB_USER_KEYS.davidq, roleKey: "role-admin", ...audit },
],
users: [
{
@@ -55,7 +63,34 @@ function createFakeSupabaseSyncState() {
displayName: "User 1",
email: "user1@example.invalid",
isActive: true,
- key: SEED_DB_KEYS.users.user1,
+ key: DEV_DB_USER_KEYS.user1,
+ ...audit,
+ },
+ {
+ authProvider: "dev-static-seed",
+ authProviderUserId: "user-2",
+ displayName: "User 2",
+ email: "user2@example.invalid",
+ isActive: true,
+ key: DEV_DB_USER_KEYS.user2,
+ ...audit,
+ },
+ {
+ authProvider: "dev-static-seed",
+ authProviderUserId: "user-3",
+ displayName: "User 3",
+ email: "user3@example.invalid",
+ isActive: true,
+ key: DEV_DB_USER_KEYS.user3,
+ ...audit,
+ },
+ {
+ authProvider: "dev-static-seed",
+ authProviderUserId: "davidq",
+ displayName: "DavidQ",
+ email: "qbytes.dq@gmail.com",
+ isActive: true,
+ key: DEV_DB_USER_KEYS.davidq,
...audit,
},
{
@@ -72,6 +107,65 @@ function createFakeSupabaseSyncState() {
const calls = [];
let generatedKey = 1;
+ function mutateTableRequest(tableName, { body = {}, method = "GET", query = "select=*" } = {}) {
+ calls.push({
+ body,
+ method,
+ path: `/rest/v1/${tableName}?${query}`,
+ });
+
+ state[tableName] = state[tableName] || [];
+ if (method === "POST") {
+ const rows = Array.isArray(body) ? body : [body];
+ rows.forEach((row) => {
+ const rowWithKey = {
+ ...row,
+ key: row.key || `generated-${generatedKey++}`,
+ };
+ const index = state[tableName].findIndex((existing) => existing.key === rowWithKey.key);
+ if (index === -1) {
+ state[tableName].push(rowWithKey);
+ } else {
+ state[tableName][index] = {
+ ...state[tableName][index],
+ ...rowWithKey,
+ };
+ }
+ });
+ return rows;
+ }
+ if (method === "DELETE") {
+ const searchParams = new URLSearchParams(query);
+ const filterField = searchParams.has("key")
+ ? "key"
+ : searchParams.has("roleKey")
+ ? "roleKey"
+ : tableName === "users"
+ ? "key"
+ : "userKey";
+ const filterValue = decodeEqFilter(searchParams, filterField);
+ const deleted = state[tableName].filter((row) => row[filterField] === filterValue);
+ state[tableName] = state[tableName].filter((row) => row[filterField] !== filterValue);
+ return deleted;
+ }
+ if (method === "PATCH") {
+ const searchParams = new URLSearchParams(query);
+ const filterField = searchParams.has("createdBy") ? "createdBy" : "updatedBy";
+ const filterValue = decodeEqFilter(searchParams, filterField);
+ const changed = [];
+ state[tableName] = state[tableName].map((row) => {
+ if (row[filterField] !== filterValue) {
+ return row;
+ }
+ const nextRow = { ...row, ...body };
+ changed.push(nextRow);
+ return nextRow;
+ });
+ return changed;
+ }
+ return state[tableName].map((row) => ({ ...row }));
+ }
+
async function fetchImpl(url, options = {}) {
const requestUrl = new URL(url);
const method = options.method || "GET";
@@ -130,57 +224,6 @@ function createFakeSupabaseSyncState() {
};
}
- if (requestUrl.pathname.startsWith("/rest/v1/")) {
- const tableName = decodeURIComponent(requestUrl.pathname.split("/").pop() || "");
- state[tableName] = state[tableName] || [];
- if (method === "POST") {
- const rows = Array.isArray(body) ? body : [body];
- rows.forEach((row) => {
- const rowWithKey = {
- ...row,
- key: row.key || `generated-${generatedKey++}`,
- };
- const index = state[tableName].findIndex((existing) => existing.key === rowWithKey.key);
- if (index === -1) {
- state[tableName].push(rowWithKey);
- } else {
- state[tableName][index] = {
- ...state[tableName][index],
- ...rowWithKey,
- };
- }
- });
- return {
- json: async () => rows,
- ok: true,
- status: 200,
- };
- }
- if (method === "DELETE") {
- const filterField = requestUrl.searchParams.has("key") ? "key" : tableName === "users" ? "key" : "userKey";
- const filterValue = decodeEqFilter(requestUrl.searchParams, filterField);
- const deleted = state[tableName].filter((row) => row[filterField] === filterValue);
- state[tableName] = state[tableName].filter((row) => row[filterField] !== filterValue);
- return {
- json: async () => deleted,
- ok: true,
- status: 200,
- };
- }
- if (method === "PATCH") {
- return {
- json: async () => [],
- ok: true,
- status: 200,
- };
- }
- return {
- json: async () => state[tableName].map((row) => ({ ...row })),
- ok: true,
- status: 200,
- };
- }
-
return {
json: async () => ({ message: "Unhandled fake route" }),
ok: false,
@@ -188,7 +231,14 @@ function createFakeSupabaseSyncState() {
};
}
- return { calls, fetchImpl, state };
+ return {
+ calls,
+ fetchImpl,
+ postgresClient: {
+ requestTable: async (tableName, options = {}) => mutateTableRequest(tableName, options),
+ },
+ state,
+ };
}
test("Supabase DEV creator identity sync upserts canonical users and deletes extra managed accounts", async () => {
@@ -201,8 +251,8 @@ test("Supabase DEV creator identity sync upserts canonical users and deletes ext
}),
databaseProvider: new SupabasePostgresProviderAdapter({
env: syncEnv,
- fetchImpl: fake.fetchImpl,
keyFactory: () => `provider-generated-key-${providerGeneratedKey++}`,
+ postgresClient: fake.postgresClient,
}),
env: syncEnv,
});
@@ -239,6 +289,11 @@ test("Supabase DEV creator identity sync upserts canonical users and deletes ext
assert.deepEqual(fake.state.authUsers.map((user) => user.email).sort(), canonicalEmails);
assert.deepEqual(fake.state.users.map((user) => user.email).sort(), canonicalEmails);
assert.equal(fake.state.users.find((user) => user.email === "qbytes.dq@gmail.com").displayName, "DavidQ");
+ assert.equal(fake.state.users.find((user) => user.email === "qbytes.dq@gmail.com").key, DEV_DB_USER_KEYS.davidq);
+ assert.equal(fake.state.users.find((user) => user.email === "user1@example.invalid").key, DEV_DB_USER_KEYS.user1);
+ assert.equal(fake.state.users.find((user) => user.email === "user2@example.invalid").key, DEV_DB_USER_KEYS.user2);
+ assert.equal(fake.state.users.find((user) => user.email === "user3@example.invalid").key, DEV_DB_USER_KEYS.user3);
+ assert.equal(fake.state.users.some((user) => Object.values(SEED_DB_KEYS.users).includes(user.key)), false);
assert.equal(fake.state.users.every((user) => user.authProvider === "supabase-auth"), true);
assert.equal(fake.state.roles.some((role) => role.roleSlug === "user"), false);
assert.equal(fake.state.roles.find((role) => role.roleSlug === "owner").isActive, true);
@@ -246,4 +301,27 @@ test("Supabase DEV creator identity sync upserts canonical users and deletes ext
const davidq = fake.state.users.find((user) => user.email === "qbytes.dq@gmail.com");
assert.equal(fake.state.user_roles.some((row) => row.userKey === davidq.key && row.roleKey === ownerRole.key), true);
assert.equal(fake.calls.some((call) => call.path === "/auth/v1/admin/users?page=1&per_page=100" && call.method === "GET"), true);
+ const existingUserUpdate = fake.calls.find((call) => call.method === "PUT" && call.path === "/auth/v1/admin/users/auth-user-1");
+ assert.equal(Boolean(existingUserUpdate), true);
+ assert.equal(Object.hasOwn(existingUserUpdate.body, "password"), false);
+ assert.equal(result.authUpsertRecords.find((record) => record.email === "user1@example.invalid").passwordUpdated, false);
+});
+
+test("Supabase DEV creator identity sync requires existing database users rows by email", async () => {
+ const fake = createFakeSupabaseSyncState();
+ fake.state.users = fake.state.users.filter((user) => user.email !== "qbytes.dq@gmail.com");
+ await assert.rejects(
+ () => syncSupabaseDevCreatorIdentities({
+ authProvider: new SupabaseAuthProviderAdapter({
+ env: syncEnv,
+ fetchImpl: fake.fetchImpl,
+ }),
+ databaseProvider: new SupabasePostgresProviderAdapter({
+ env: syncEnv,
+ postgresClient: fake.postgresClient,
+ }),
+ env: syncEnv,
+ }),
+ /requires existing database users rows for: qbytes\.dq@gmail\.com/,
+ );
});
diff --git a/dev/tests/dev-runtime/SupabaseProviderContractStub.test.mjs b/dev/tests/dev-runtime/SupabaseProviderContractStub.test.mjs
index 3f5d81a00..b86a95014 100644
--- a/dev/tests/dev-runtime/SupabaseProviderContractStub.test.mjs
+++ b/dev/tests/dev-runtime/SupabaseProviderContractStub.test.mjs
@@ -38,8 +38,8 @@ function withEnv(nextEnv, callback) {
});
}
-function startApiServer() {
- const handleRequest = createLocalApiRouter();
+function startApiServer(routerOptions = {}) {
+ const handleRequest = createLocalApiRouter(routerOptions);
const server = http.createServer((request, response) => {
const address = server.address();
const port = address && typeof address !== "string" ? address.port : 0;
@@ -313,6 +313,12 @@ function fakeSupabaseIdentityTables(overrides = {}) {
};
}
+function fakePostgresIdentityClient(identityTables = {}) {
+ return {
+ requestTable: async (tableName) => (identityTables[tableName] || []).map((row) => ({ ...row })),
+ };
+}
+
test("Supabase provider contract does not require provider selector variables", () => {
const snapshot = createProviderContractSnapshot({});
assert.equal(snapshot.activeProviders.authProviderId, "supabase-auth");
@@ -881,6 +887,134 @@ test("Create account provisions Supabase identity user default role and user_rol
await fakeSupabase.close();
});
+test("Supabase sign-in resolves the session from database users.key matched by Auth id", async () => {
+ const databaseOwnedUserKey = "01J00000000000000000000001";
+ const timestamp = "2026-06-15T00:00:00.000Z";
+ const audit = {
+ createdAt: timestamp,
+ createdBy: SEED_DB_KEYS.users.admin,
+ updatedAt: timestamp,
+ updatedBy: SEED_DB_KEYS.users.admin,
+ };
+ const identityTables = fakeSupabaseIdentityTables({
+ user_roles: [
+ {
+ key: SEED_DB_KEYS.userRoles.user1User,
+ userKey: databaseOwnedUserKey,
+ roleKey: SEED_DB_KEYS.roles.creator,
+ ...audit,
+ },
+ ],
+ users: [
+ {
+ key: databaseOwnedUserKey,
+ displayName: "Database Creator",
+ email: "user1@example.invalid",
+ authProvider: "supabase-auth",
+ authProviderUserId: "supabase-user-1",
+ isActive: true,
+ ...audit,
+ },
+ ],
+ });
+ const fakeSupabase = await startFakeSupabaseAuthServer({ identityTables });
+ await withEnv({
+ GAMEFOUNDRY_DATABASE_SSL: "disable",
+ GAMEFOUNDRY_DATABASE_URL: "postgres://contract_user:contract_password@supabase-provider.example.test/gamefoundry",
+ GAMEFOUNDRY_AUTH_PROVIDER: "supabase-auth",
+ GAMEFOUNDRY_DB_PROVIDER: "supabase-postgres",
+ GAMEFOUNDRY_SUPABASE_ANON_KEY: "test-anon-key",
+ GAMEFOUNDRY_SUPABASE_SERVICE_ROLE_KEY: "test-service-role-key",
+ GAMEFOUNDRY_SUPABASE_URL: fakeSupabase.baseUrl,
+ }, async () => {
+ const server = await startApiServer({
+ supabasePostgresClient: fakePostgresIdentityClient(identityTables),
+ });
+ try {
+ const signIn = await postApiPayload(server.baseUrl, "/api/auth/sign-in", {
+ email: "user1@example.invalid",
+ password: "not-stored-locally",
+ });
+ assert.equal(signIn.status, 200);
+ assert.equal(signIn.payload.data.sessionResolved, true);
+ assert.equal(signIn.payload.data.userKey, databaseOwnedUserKey);
+ assert.equal(Object.values(SEED_DB_KEYS.users).includes(signIn.payload.data.userKey), false);
+
+ const current = await apiJson(server.baseUrl, "/api/session/current");
+ assert.equal(current.authenticated, true);
+ assert.equal(current.userKey, databaseOwnedUserKey);
+ assert.equal(current.displayName, "Database Creator");
+ } finally {
+ await server.close();
+ }
+ });
+ await fakeSupabase.close();
+});
+
+test("Supabase sign-in does not resolve a session from email when authProviderUserId is stale", async () => {
+ const databaseOwnedUserKey = "01J00000000000000000000002";
+ const timestamp = "2026-06-15T00:00:00.000Z";
+ const audit = {
+ createdAt: timestamp,
+ createdBy: SEED_DB_KEYS.users.admin,
+ updatedAt: timestamp,
+ updatedBy: SEED_DB_KEYS.users.admin,
+ };
+ const identityTables = fakeSupabaseIdentityTables({
+ user_roles: [
+ {
+ key: SEED_DB_KEYS.userRoles.user1User,
+ userKey: databaseOwnedUserKey,
+ roleKey: SEED_DB_KEYS.roles.creator,
+ ...audit,
+ },
+ ],
+ users: [
+ {
+ key: databaseOwnedUserKey,
+ displayName: "Database Creator",
+ email: "user1@example.invalid",
+ authProvider: "supabase-auth",
+ authProviderUserId: "stale-supabase-user-1",
+ isActive: true,
+ ...audit,
+ },
+ ],
+ });
+ const fakeSupabase = await startFakeSupabaseAuthServer({ identityTables });
+ await withEnv({
+ GAMEFOUNDRY_DATABASE_SSL: "disable",
+ GAMEFOUNDRY_DATABASE_URL: "postgres://contract_user:contract_password@supabase-provider.example.test/gamefoundry",
+ GAMEFOUNDRY_AUTH_PROVIDER: "supabase-auth",
+ GAMEFOUNDRY_DB_PROVIDER: "supabase-postgres",
+ GAMEFOUNDRY_SUPABASE_ANON_KEY: "test-anon-key",
+ GAMEFOUNDRY_SUPABASE_SERVICE_ROLE_KEY: "test-service-role-key",
+ GAMEFOUNDRY_SUPABASE_URL: fakeSupabase.baseUrl,
+ }, async () => {
+ const server = await startApiServer({
+ supabasePostgresClient: fakePostgresIdentityClient(identityTables),
+ });
+ try {
+ const signIn = await postApiPayload(server.baseUrl, "/api/auth/sign-in", {
+ email: "user1@example.invalid",
+ password: "not-stored-locally",
+ });
+ assert.equal(signIn.status, 503);
+ assert.equal(signIn.payload.ok, false);
+ assert.equal(signIn.payload.error, "Account identity setup is incomplete. Please contact support.");
+ assert.equal(JSON.stringify(signIn.payload).includes("stale-supabase-user-1"), false);
+ assert.equal(JSON.stringify(signIn.payload).includes(databaseOwnedUserKey), false);
+
+ const current = await apiJson(server.baseUrl, "/api/session/current");
+ assert.equal(current.authenticated, false);
+ assert.equal(current.userKey, null);
+ } finally {
+ await server.close();
+ }
+ });
+ await fakeSupabase.close();
+});
+
test("Create account provider failure returns generic browser error and logs safe operator diagnostics", async () => {
const fakeSupabase = await startFakeSupabaseAuthServer({
failAdminCreateAccount: {
diff --git a/dev/tests/dev-runtime/TagsApiService.test.mjs b/dev/tests/dev-runtime/TagsApiService.test.mjs
index bf9a6512a..8a9a3f6ef 100644
--- a/dev/tests/dev-runtime/TagsApiService.test.mjs
+++ b/dev/tests/dev-runtime/TagsApiService.test.mjs
@@ -115,6 +115,7 @@ test("Tags list reads and seeds through the API database adapter", async () => {
assert.equal(adapter.calls.some(([action, table]) => action === "requestTable" && table === "project_tags"), true);
assert.equal(adapter.calls.some(([action, table]) => action === "upsertProductTable" && table === "project_tags"), true);
assert.equal(adapter.calls.some(([action, table]) => action === "upsertProductTable" && table === "project_tag_assignments"), true);
+ assert.equal(adapter.calls.some(([action, table]) => action === "upsertTable" && table === "users"), false);
});
test("Tags list reports an actionable setup error when readTables cannot read the schema", async () => {
diff --git a/src/dev-runtime/server/local-api-router.mjs b/src/dev-runtime/server/local-api-router.mjs
index bfe82e4e8..ae2b7bf72 100644
--- a/src/dev-runtime/server/local-api-router.mjs
+++ b/src/dev-runtime/server/local-api-router.mjs
@@ -3785,9 +3785,11 @@ class ApiRuntimeDataSource {
messagesPostgresClient = null,
messagesService = null,
repoRoot = process.cwd(),
+ supabasePostgresClient = null,
} = {}) {
this.messagesService = messagesService || createMessagesPostgresService({ postgresClient: messagesPostgresClient });
this.gameJourneyCompletionMetricsPostgresClient = gameJourneyCompletionMetricsPostgresClient;
+ this.supabasePostgresClient = supabasePostgresClient;
this.repositoryCounter = 1;
this.repositoryById = new Map();
this.sessionModeId = FIXED_ACCOUNT_SESSION_MODE.id;
@@ -3824,7 +3826,7 @@ class ApiRuntimeDataSource {
supabaseDatabaseAdapter(action) {
this.assertSupabaseDatabaseProvider(action);
- const adapter = new SupabasePostgresProviderAdapter();
+ const adapter = new SupabasePostgresProviderAdapter({ postgresClient: this.supabasePostgresClient });
adapter.connect();
return adapter;
}
@@ -3835,8 +3837,7 @@ class ApiRuntimeDataSource {
}
async readSupabaseIdentityTablesUnchecked(action) {
- this.assertSupabaseDatabaseProvider(action);
- const adapter = new SupabasePostgresProviderAdapter();
+ const adapter = this.supabaseDatabaseAdapter(action);
const [users, roles, userRoles] = await Promise.all([
adapter.getUsers(),
adapter.getRoles(),
@@ -6202,15 +6203,20 @@ SELECT pg_database_size(current_database()) AS database_size_bytes,
throw authUnavailableError(action, "Supabase Auth did not return an account identity to resolve.");
}
const tables = await this.readSupabaseIdentityTables(`${action} session resolution`);
- const matchingUser = (tables.users || []).find((user) => {
+ const activeSupabaseUsers = (tables.users || []).filter((user) => {
if (user.isActive === false || user.authProvider !== SUPABASE_AUTH_PROVIDER_ID) {
return false;
}
- return (authUserId && String(user.authProviderUserId || "") === authUserId) ||
- (authEmail && normalizedAuthEmail(user.email).toLowerCase() === authEmail.toLowerCase());
+ return true;
});
+ const matchingUser = activeSupabaseUsers.find((user) => authUserId && String(user.authProviderUserId || "") === authUserId);
if (!matchingUser) {
- throw authIdentitySetupError(action, "Account authentication succeeded, but no matching users record exists for this account.");
+ const matchingEmailUser = activeSupabaseUsers.find((user) =>
+ authEmail && normalizedAuthEmail(user.email).toLowerCase() === authEmail.toLowerCase());
+ const diagnostic = matchingEmailUser
+ ? "Account authentication succeeded, but the users record is not linked to this account identity. Run the approved DEV identity sync before signing in."
+ : "Account authentication succeeded, but no matching users record exists for this account.";
+ throw authIdentitySetupError(action, diagnostic);
}
const session = sessionUserFromIdentityTables(tables, matchingUser.key, this.sessionModeId, "Supabase identity");
if (!session.authenticated) {
@@ -6230,7 +6236,7 @@ SELECT pg_database_size(current_database()) AS database_size_bytes,
throw authIdentitySetupError(action, "Supabase Auth did not return the user id and email required for identity provisioning.");
}
- const adapter = new SupabasePostgresProviderAdapter();
+ const adapter = this.supabaseDatabaseAdapter(`${action} identity provisioning`);
const tables = await this.readSupabaseIdentityTablesUnchecked(`${action} identity provisioning`);
const users = tables.users || [];
const roles = tables.roles || [];
@@ -7415,12 +7421,14 @@ export function createLocalApiRouter({
messagesPostgresClient = null,
messagesService = null,
repoRoot = process.cwd(),
+ supabasePostgresClient = null,
} = {}) {
const dataSource = new ApiRuntimeDataSource({
gameJourneyCompletionMetricsPostgresClient,
messagesPostgresClient,
messagesService,
repoRoot,
+ supabasePostgresClient,
});
async function handleApiRuntimeRequest(request, response, requestUrl) {
diff --git a/src/dev-runtime/testing/supabase-dev-creator-identity-seed-sync.mjs b/src/dev-runtime/testing/supabase-dev-creator-identity-seed-sync.mjs
index 6f214f7a2..9da3e7a87 100644
--- a/src/dev-runtime/testing/supabase-dev-creator-identity-seed-sync.mjs
+++ b/src/dev-runtime/testing/supabase-dev-creator-identity-seed-sync.mjs
@@ -1,4 +1,3 @@
-import { SEED_DB_KEYS } from "../seed/seed-db-keys.mjs";
import {
SUPABASE_AUTH_PROVIDER_ID,
SupabaseAuthProviderAdapter,
@@ -10,31 +9,27 @@ export const DEV_CREATOR_IDENTITIES = Object.freeze([
Object.freeze({
displayName: "User 1",
email: "user1@example.invalid",
- key: SEED_DB_KEYS.users.user1,
passwordSuffix: "1!!",
}),
Object.freeze({
displayName: "User 2",
email: "user2@example.invalid",
- key: SEED_DB_KEYS.users.user2,
passwordSuffix: "2!!",
}),
Object.freeze({
displayName: "User 3",
email: "user3@example.invalid",
- key: SEED_DB_KEYS.users.user3,
passwordSuffix: "3!!",
}),
Object.freeze({
displayName: "DavidQ",
email: "qbytes.dq@gmail.com",
- key: SEED_DB_KEYS.users.admin,
passwordSuffix: "$2026",
}),
]);
const CANONICAL_EMAILS = new Set(DEV_CREATOR_IDENTITIES.map((identity) => identity.email.toLowerCase()));