backend-manager 5.9.5 → 5.9.7

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 (246) hide show
  1. package/package.json +8 -1
  2. package/src/manager/events/cron/runner.js +0 -1
  3. package/src/manager/libraries/email/data/disposable-domains.json +21 -0
  4. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/metadata.json +14 -0
  5. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/newsletter.html +486 -0
  6. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/newsletter.md +41 -0
  7. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/newsletter.mjml +97 -0
  8. package/{test/email/fixtures/clean.json → src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/structure.json} +16 -4
  9. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/summary.md +1 -0
  10. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/metadata.json +14 -0
  11. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/newsletter.html +486 -0
  12. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/newsletter.md +41 -0
  13. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/newsletter.mjml +97 -0
  14. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/structure.json +42 -0
  15. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/summary.md +1 -0
  16. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/metadata.json +14 -0
  17. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/newsletter.html +486 -0
  18. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/newsletter.md +41 -0
  19. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/newsletter.mjml +97 -0
  20. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/structure.json +42 -0
  21. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/summary.md +1 -0
  22. package/src/test/fixtures/firebase-project/.temp/test-mode.json +6 -0
  23. package/src/test/fixtures/firebase-project/database-debug.log +12 -0
  24. package/src/test/fixtures/firebase-project/firestore-debug.log +132 -0
  25. package/src/test/fixtures/firebase-project/pubsub-debug.log +17 -0
  26. package/.codeclimate.yml +0 -32
  27. package/.nvmrc +0 -1
  28. package/CHANGELOG.md +0 -1440
  29. package/PROGRESS.md +0 -93
  30. package/TODO-2.md +0 -121
  31. package/TODO-CHARGEBLAST.md +0 -32
  32. package/TODO-WEBHOOK-KEY-LEGACY-REMOVAL.md +0 -15
  33. package/TODO-WEBHOOK-KEY-UPGRADE.md +0 -138
  34. package/TODO-email-auth.md +0 -14
  35. package/TODO.md +0 -187
  36. package/plans/mcp2.md +0 -247
  37. package/plans/suspended-subscription-dead-zone.md +0 -97
  38. package/scripts/test-helper-providers.js +0 -162
  39. package/scripts/update-disposable-domains.js +0 -44
  40. package/templates/_.env +0 -42
  41. package/templates/_.gitignore +0 -60
  42. package/templates/backend-manager-config.json +0 -249
  43. package/templates/database.rules.json +0 -83
  44. package/templates/firebase.json +0 -66
  45. package/templates/firestore.indexes.json +0 -4
  46. package/templates/firestore.rules +0 -112
  47. package/templates/public/404.html +0 -26
  48. package/templates/public/index.html +0 -24
  49. package/templates/remoteconfig.template.json +0 -1
  50. package/templates/storage-lifecycle-config-1-day.json +0 -9
  51. package/templates/storage-lifecycle-config-30-days.json +0 -9
  52. package/templates/storage.rules +0 -8
  53. package/test/_init/accounts-validation.js +0 -58
  54. package/test/_legacy/ai/index.js +0 -231
  55. package/test/_legacy/ai/test.jpg +0 -0
  56. package/test/_legacy/ai/test.pdf +0 -0
  57. package/test/_legacy/index.js +0 -31
  58. package/test/_legacy/payment-resolver/chargebee/orders/refunded.json +0 -0
  59. package/test/_legacy/payment-resolver/chargebee/orders/unpaid.json +0 -98
  60. package/test/_legacy/payment-resolver/chargebee/subscriptions/active.json +0 -578
  61. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-in-trial.json +0 -38
  62. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-skipped-to-active.json +0 -135
  63. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-active-to-cancelled.json +0 -42
  64. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-active.json +0 -44
  65. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-cancelled.json +0 -39
  66. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-refund.json +0 -143
  67. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-suspended.json +0 -48
  68. package/test/_legacy/payment-resolver/coinbase/orders/regular.json +0 -204
  69. package/test/_legacy/payment-resolver/coinbase/subscriptions/cancelled.json +0 -204
  70. package/test/_legacy/payment-resolver/coinbase/subscriptions/paid-2.json +0 -125
  71. package/test/_legacy/payment-resolver/index.js +0 -1558
  72. package/test/_legacy/payment-resolver/paypal/orders/refunded.json +0 -0
  73. package/test/_legacy/payment-resolver/paypal/orders/regular.json +0 -120
  74. package/test/_legacy/payment-resolver/paypal/subscriptions/active-refund-previous-stmnt.json +0 -323
  75. package/test/_legacy/payment-resolver/paypal/subscriptions/active.json +0 -192
  76. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-in-trial.json +0 -125
  77. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-not-complete.json +0 -76
  78. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-overdue-2.json +0 -114
  79. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-overdue.json +0 -114
  80. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-active-to-cancelled.json +0 -111
  81. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-active.json +0 -132
  82. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-cancelled.json +0 -107
  83. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-expired.json +0 -91
  84. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-refund.json +0 -147
  85. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-suspended.json +0 -120
  86. package/test/_legacy/payment-resolver/stripe/orders/refunded.json +0 -0
  87. package/test/_legacy/payment-resolver/stripe/orders/regular.json +0 -91
  88. package/test/_legacy/payment-resolver/stripe/subscriptions/active.json +0 -421
  89. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-in-trial.json +0 -349
  90. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-active-failed-authorization.json +0 -430
  91. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-active.json +0 -319
  92. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-cancelled.json +0 -319
  93. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-refund.json +0 -414
  94. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-suspended.json +0 -319
  95. package/test/_legacy/payment-resolver/stripe/subscriptions/unsure.json +0 -339
  96. package/test/_legacy/test-new +0 -1178
  97. package/test/_legacy/test.md +0 -89
  98. package/test/_legacy/usage.js +0 -175
  99. package/test/_legacy/user.js +0 -31
  100. package/test/ai/tools-live.js +0 -170
  101. package/test/boot/emulator-boots.js +0 -37
  102. package/test/content/blog-generate.js +0 -160
  103. package/test/email/campaign-send.js +0 -45
  104. package/test/email/consent-lifecycle.js +0 -257
  105. package/test/email/feedback-and-plain-send.js +0 -52
  106. package/test/email/fixtures/editorial.json +0 -30
  107. package/test/email/fixtures/field-report.json +0 -53
  108. package/test/email/marketing-lifecycle.js +0 -132
  109. package/test/email/newsletter-generate.js +0 -819
  110. package/test/email/newsletter-templates.js +0 -491
  111. package/test/email/templates.js +0 -207
  112. package/test/email/transactional-send.js +0 -34
  113. package/test/email/transactional.js +0 -560
  114. package/test/email/validation.js +0 -710
  115. package/test/events/auth-delete-race.js +0 -201
  116. package/test/events/payments/journey-payments-cancel-endpoint.js +0 -100
  117. package/test/events/payments/journey-payments-cancel.js +0 -182
  118. package/test/events/payments/journey-payments-discount.js +0 -89
  119. package/test/events/payments/journey-payments-failure.js +0 -146
  120. package/test/events/payments/journey-payments-legacy-product.js +0 -149
  121. package/test/events/payments/journey-payments-one-time-failure.js +0 -111
  122. package/test/events/payments/journey-payments-one-time.js +0 -136
  123. package/test/events/payments/journey-payments-plan-change.js +0 -144
  124. package/test/events/payments/journey-payments-refund-webhook.js +0 -180
  125. package/test/events/payments/journey-payments-suspend.js +0 -181
  126. package/test/events/payments/journey-payments-trial-cancel.js +0 -130
  127. package/test/events/payments/journey-payments-trial.js +0 -171
  128. package/test/events/payments/journey-payments-uid-resolution.js +0 -132
  129. package/test/events/payments/journey-payments-upgrade.js +0 -135
  130. package/test/fixtures/chargebee/invoice-one-time.json +0 -27
  131. package/test/fixtures/chargebee/subscription-active.json +0 -44
  132. package/test/fixtures/chargebee/subscription-cancelled.json +0 -42
  133. package/test/fixtures/chargebee/subscription-in-trial.json +0 -41
  134. package/test/fixtures/chargebee/subscription-legacy-plan.json +0 -41
  135. package/test/fixtures/chargebee/subscription-non-renewing.json +0 -41
  136. package/test/fixtures/chargebee/subscription-paused.json +0 -42
  137. package/test/fixtures/chargebee/webhook-payment-failed.json +0 -51
  138. package/test/fixtures/chargebee/webhook-subscription-created.json +0 -47
  139. package/test/fixtures/paypal/order-approved.json +0 -62
  140. package/test/fixtures/paypal/order-completed.json +0 -110
  141. package/test/fixtures/paypal/subscription-active.json +0 -76
  142. package/test/fixtures/paypal/subscription-cancelled.json +0 -50
  143. package/test/fixtures/paypal/subscription-suspended.json +0 -65
  144. package/test/fixtures/stripe/checkout-session-completed.json +0 -130
  145. package/test/fixtures/stripe/invoice-payment-failed.json +0 -148
  146. package/test/fixtures/stripe/invoice-subscription-payment-failed.json +0 -28
  147. package/test/fixtures/stripe/subscription-active.json +0 -161
  148. package/test/fixtures/stripe/subscription-canceled.json +0 -161
  149. package/test/fixtures/stripe/subscription-trialing.json +0 -161
  150. package/test/functions/admin/database-read.js +0 -134
  151. package/test/functions/admin/database-write.js +0 -159
  152. package/test/functions/admin/edit-post.js +0 -366
  153. package/test/functions/admin/firestore-query.js +0 -207
  154. package/test/functions/admin/firestore-read.js +0 -129
  155. package/test/functions/admin/firestore-write.js +0 -105
  156. package/test/functions/admin/get-stats.js +0 -115
  157. package/test/functions/admin/send-email.js +0 -119
  158. package/test/functions/admin/send-notification.js +0 -208
  159. package/test/functions/admin/write-repo-content.js +0 -223
  160. package/test/functions/general/add-marketing-contact.js +0 -335
  161. package/test/functions/general/fetch-post.js +0 -54
  162. package/test/functions/general/generate-uuid.js +0 -114
  163. package/test/functions/test/authenticate.js +0 -64
  164. package/test/functions/user/create-custom-token.js +0 -73
  165. package/test/functions/user/delete.js +0 -135
  166. package/test/functions/user/get-active-sessions.js +0 -111
  167. package/test/functions/user/get-subscription-info.js +0 -99
  168. package/test/functions/user/regenerate-api-keys.js +0 -156
  169. package/test/functions/user/resolve.js +0 -52
  170. package/test/functions/user/sign-out-all-sessions.js +0 -94
  171. package/test/functions/user/sign-up.js +0 -252
  172. package/test/functions/user/submit-feedback.js +0 -104
  173. package/test/functions/user/validate-settings.js +0 -82
  174. package/test/helpers/ai-request-payload.js +0 -300
  175. package/test/helpers/ai-test-provider.js +0 -202
  176. package/test/helpers/ai-tools-format.js +0 -383
  177. package/test/helpers/content/blog-auto-publisher.js +0 -484
  178. package/test/helpers/content/feed-parser.js +0 -528
  179. package/test/helpers/content/ghostii-blocks.js +0 -134
  180. package/test/helpers/content/ghostii-feed-integration.js +0 -404
  181. package/test/helpers/content/ghostii-write-article.js +0 -243
  182. package/test/helpers/environment.js +0 -230
  183. package/test/helpers/infer-contact.js +0 -113
  184. package/test/helpers/merge-line-files.js +0 -271
  185. package/test/helpers/payment/chargebee/parse-webhook.js +0 -413
  186. package/test/helpers/payment/chargebee/to-unified-one-time.js +0 -147
  187. package/test/helpers/payment/chargebee/to-unified-subscription.js +0 -648
  188. package/test/helpers/payment/paypal/parse-webhook.js +0 -539
  189. package/test/helpers/payment/paypal/to-unified-one-time.js +0 -382
  190. package/test/helpers/payment/paypal/to-unified-subscription.js +0 -820
  191. package/test/helpers/payment/stripe/parse-webhook.js +0 -447
  192. package/test/helpers/payment/stripe/to-unified-one-time.js +0 -306
  193. package/test/helpers/payment/stripe/to-unified-subscription.js +0 -708
  194. package/test/helpers/sanitize.js +0 -222
  195. package/test/helpers/slugify.js +0 -394
  196. package/test/helpers/storage.js +0 -194
  197. package/test/helpers/user.js +0 -755
  198. package/test/helpers/webhook-forward.js +0 -418
  199. package/test/mcp/discovery.js +0 -53
  200. package/test/mcp/oauth.js +0 -161
  201. package/test/mcp/protocol.js +0 -268
  202. package/test/mcp/roles.js +0 -188
  203. package/test/mcp/utils.js +0 -245
  204. package/test/routes/admin/create-post.js +0 -364
  205. package/test/routes/admin/database.js +0 -131
  206. package/test/routes/admin/deduplicate-image-alts.js +0 -190
  207. package/test/routes/admin/email.js +0 -114
  208. package/test/routes/admin/firestore-query.js +0 -204
  209. package/test/routes/admin/firestore.js +0 -127
  210. package/test/routes/admin/infer-contact.js +0 -218
  211. package/test/routes/admin/notification.js +0 -198
  212. package/test/routes/admin/post-resize-image.js +0 -184
  213. package/test/routes/admin/post.js +0 -368
  214. package/test/routes/admin/repo-content.js +0 -223
  215. package/test/routes/admin/stats.js +0 -112
  216. package/test/routes/content/post.js +0 -54
  217. package/test/routes/general/uuid.js +0 -115
  218. package/test/routes/marketing/campaign.js +0 -125
  219. package/test/routes/marketing/contact.js +0 -370
  220. package/test/routes/marketing/email-preferences.js +0 -292
  221. package/test/routes/marketing/push-send.js +0 -32
  222. package/test/routes/marketing/webhook-forward.js +0 -61
  223. package/test/routes/marketing/webhook.js +0 -639
  224. package/test/routes/payments/cancel.js +0 -163
  225. package/test/routes/payments/discount.js +0 -80
  226. package/test/routes/payments/dispute-alert.js +0 -320
  227. package/test/routes/payments/intent.js +0 -336
  228. package/test/routes/payments/portal.js +0 -92
  229. package/test/routes/payments/refund.js +0 -179
  230. package/test/routes/payments/trial-eligibility.js +0 -71
  231. package/test/routes/payments/webhook.js +0 -107
  232. package/test/routes/test/authenticate.js +0 -59
  233. package/test/routes/test/schema.js +0 -554
  234. package/test/routes/test/usage.js +0 -342
  235. package/test/routes/user/api-keys.js +0 -156
  236. package/test/routes/user/delete.js +0 -136
  237. package/test/routes/user/feedback.js +0 -104
  238. package/test/routes/user/sessions.js +0 -199
  239. package/test/routes/user/settings-validate.js +0 -82
  240. package/test/routes/user/signup.js +0 -542
  241. package/test/routes/user/subscription.js +0 -99
  242. package/test/routes/user/token.js +0 -73
  243. package/test/routes/user/user.js +0 -157
  244. package/test/rules/notifications.js +0 -410
  245. package/test/rules/payments-carts.js +0 -371
  246. package/test/rules/user.js +0 -396
@@ -1,230 +0,0 @@
1
- /**
2
- * Test: environment detection + URL helpers
3
- * Covers the Manager's getEnvironment() SSOT, the derived is*() checks, the URL
4
- * builders (getApiUrl / getFunctionsUrl / getWebsiteUrl + parent variants), and the
5
- * assistant→Manager forwarding.
6
- *
7
- * Run: npx mgr test bem:helpers/environment
8
- *
9
- * Contract (see docs/environment-detection.md):
10
- * - getEnvironment() is the SINGLE SOURCE OF TRUTH — the only reader of the raw env
11
- * vars (BEM_TESTING / ENVIRONMENT / FUNCTIONS_EMULATOR / TERM_PROGRAM). Returns
12
- * exactly ONE of 'development' | 'testing' | 'production' (testing wins).
13
- * - isDevelopment()/isProduction()/isTesting() DERIVE from getEnvironment() — they
14
- * never read raw signals, so they can NEVER disagree with it. Exactly one is true.
15
- * - getApiUrl/getFunctionsUrl/getWebsiteUrl resolve LOCAL in dev OR testing, prod
16
- * otherwise. The parent helpers ALWAYS return the live URL (no localhost).
17
- * - The assistant forwards each method to its Manager (identical results).
18
- */
19
-
20
- // Run a thunk with the env-detection vars cleared, restoring them afterward. These are
21
- // the only inputs getEnvironment() reads, so clearing them gives a clean slate per case.
22
- function withEnv(overrides, fn) {
23
- const KEYS = ['BEM_TESTING', 'ENVIRONMENT', 'FUNCTIONS_EMULATOR', 'TERM_PROGRAM'];
24
- const saved = {};
25
- for (const k of KEYS) saved[k] = process.env[k];
26
- try {
27
- for (const k of KEYS) delete process.env[k];
28
- for (const k of Object.keys(overrides)) process.env[k] = overrides[k];
29
- return fn();
30
- } finally {
31
- for (const k of KEYS) {
32
- if (saved[k] === undefined) delete process.env[k];
33
- else process.env[k] = saved[k];
34
- }
35
- }
36
- }
37
-
38
- module.exports = {
39
- description: 'Environment detection + URL helpers',
40
- type: 'group',
41
-
42
- tests: [
43
- // ─── getEnvironment() resolution + precedence ───
44
-
45
- {
46
- name: 'getEnvironment: testing wins over everything (BEM_TESTING=true)',
47
- async run({ Manager, assert }) {
48
- withEnv({ BEM_TESTING: 'true', ENVIRONMENT: 'production' }, () => {
49
- assert.equal(Manager.getEnvironment(), 'testing');
50
- });
51
- },
52
- },
53
- {
54
- name: 'getEnvironment: production when ENVIRONMENT=production (not testing)',
55
- async run({ Manager, assert }) {
56
- withEnv({ ENVIRONMENT: 'production' }, () => {
57
- assert.equal(Manager.getEnvironment(), 'production');
58
- });
59
- },
60
- },
61
- {
62
- name: 'getEnvironment: development when ENVIRONMENT=development',
63
- async run({ Manager, assert }) {
64
- withEnv({ ENVIRONMENT: 'development' }, () => {
65
- assert.equal(Manager.getEnvironment(), 'development');
66
- });
67
- },
68
- },
69
- {
70
- name: 'getEnvironment: development when FUNCTIONS_EMULATOR is set',
71
- async run({ Manager, assert }) {
72
- withEnv({ FUNCTIONS_EMULATOR: 'true' }, () => {
73
- assert.equal(Manager.getEnvironment(), 'development');
74
- });
75
- },
76
- },
77
- {
78
- name: 'getEnvironment: defaults to production with no signal (deployed function)',
79
- async run({ Manager, assert }) {
80
- withEnv({}, () => {
81
- assert.equal(Manager.getEnvironment(), 'production');
82
- });
83
- },
84
- },
85
-
86
- // ─── The KEY invariant: is*() derive from getEnvironment() and can NEVER disagree ───
87
-
88
- {
89
- name: 'invariant: is*() exactly matches getEnvironment() across every scenario',
90
- async run({ Manager, assert }) {
91
- const scenarios = [
92
- { env: { BEM_TESTING: 'true', ENVIRONMENT: 'production' }, expect: 'testing' },
93
- { env: { ENVIRONMENT: 'production' }, expect: 'production' },
94
- { env: { ENVIRONMENT: 'development' }, expect: 'development' },
95
- { env: { FUNCTIONS_EMULATOR: 'true' }, expect: 'development' },
96
- { env: {}, expect: 'production' },
97
- ];
98
- for (const s of scenarios) {
99
- withEnv(s.env, () => {
100
- const e = Manager.getEnvironment();
101
- assert.equal(e, s.expect, `getEnvironment for ${JSON.stringify(s.env)}`);
102
- // Each is*() must equal (getEnvironment() === its value) — no independent reads.
103
- assert.equal(Manager.isDevelopment(), e === 'development', `isDevelopment for ${e}`);
104
- assert.equal(Manager.isTesting(), e === 'testing', `isTesting for ${e}`);
105
- assert.equal(Manager.isProduction(), e === 'production', `isProduction for ${e}`);
106
- });
107
- }
108
- },
109
- },
110
- {
111
- name: 'invariant: exactly one of is*() is true in every scenario (mutually exclusive)',
112
- async run({ Manager, assert }) {
113
- const envs = [
114
- { BEM_TESTING: 'true' },
115
- { ENVIRONMENT: 'production' },
116
- { ENVIRONMENT: 'development' },
117
- { FUNCTIONS_EMULATOR: 'true' },
118
- {},
119
- ];
120
- for (const env of envs) {
121
- withEnv(env, () => {
122
- const trueCount = [Manager.isDevelopment(), Manager.isTesting(), Manager.isProduction()]
123
- .filter(Boolean).length;
124
- assert.equal(trueCount, 1, `exactly one true for ${JSON.stringify(env)}`);
125
- });
126
- }
127
- },
128
- },
129
- {
130
- name: 'isProduction is a real positive check (NOT just !isDevelopment) — false in testing',
131
- async run({ Manager, assert }) {
132
- withEnv({ BEM_TESTING: 'true' }, () => {
133
- assert.equal(Manager.isDevelopment(), false, 'isDevelopment false in testing');
134
- assert.equal(Manager.isProduction(), false, 'isProduction false in testing');
135
- assert.equal(Manager.isTesting(), true, 'isTesting true in testing');
136
- });
137
- },
138
- },
139
-
140
- // ─── assistant forwards to the Manager (identical results) ───
141
-
142
- {
143
- name: 'assistant forwards getEnvironment()/is*() to the Manager (identical)',
144
- async run({ Manager, assistant, assert }) {
145
- const cases = [
146
- { BEM_TESTING: 'true' },
147
- { ENVIRONMENT: 'production' },
148
- { ENVIRONMENT: 'development' },
149
- ];
150
- for (const env of cases) {
151
- withEnv(env, () => {
152
- assert.equal(assistant.getEnvironment(), Manager.getEnvironment(), 'getEnvironment forward');
153
- assert.equal(assistant.isDevelopment(), Manager.isDevelopment(), 'isDevelopment forward');
154
- assert.equal(assistant.isTesting(), Manager.isTesting(), 'isTesting forward');
155
- assert.equal(assistant.isProduction(), Manager.isProduction(), 'isProduction forward');
156
- });
157
- }
158
- },
159
- },
160
-
161
- // ─── URL helpers: local in dev/testing, production otherwise ───
162
-
163
- {
164
- name: 'getApiUrl: localhost in development AND testing, prod otherwise',
165
- async run({ Manager, assert }) {
166
- withEnv({ FUNCTIONS_EMULATOR: 'true' }, () => {
167
- assert.equal(Manager.getApiUrl(), 'http://localhost:5002', 'dev → localhost');
168
- });
169
- withEnv({ BEM_TESTING: 'true' }, () => {
170
- assert.equal(Manager.getApiUrl(), 'http://localhost:5002', 'testing → localhost');
171
- });
172
- withEnv({ ENVIRONMENT: 'production' }, () => {
173
- assert.match(Manager.getApiUrl(), /^https:\/\/api\./, 'prod → api.<domain>');
174
- });
175
- },
176
- },
177
- {
178
- name: 'getApiUrl: explicit env arg overrides current environment',
179
- async run({ Manager, assert }) {
180
- // Under the test harness we're in 'testing', but an explicit arg forces the mapping.
181
- assert.equal(Manager.getApiUrl('development'), 'http://localhost:5002', "arg 'development' → localhost");
182
- assert.match(Manager.getApiUrl('production'), /^https:\/\/api\./, "arg 'production' → prod");
183
- },
184
- },
185
- {
186
- name: 'getFunctionsUrl: localhost in development AND testing, cloudfunctions otherwise',
187
- async run({ Manager, assert }) {
188
- withEnv({ FUNCTIONS_EMULATOR: 'true' }, () => {
189
- assert.match(Manager.getFunctionsUrl(), /^http:\/\/localhost:5001\//, 'dev → localhost:5001');
190
- });
191
- withEnv({ BEM_TESTING: 'true' }, () => {
192
- assert.match(Manager.getFunctionsUrl(), /^http:\/\/localhost:5001\//, 'testing → localhost:5001');
193
- });
194
- withEnv({ ENVIRONMENT: 'production' }, () => {
195
- assert.match(Manager.getFunctionsUrl(), /cloudfunctions\.net$/, 'prod → cloudfunctions.net');
196
- });
197
- },
198
- },
199
- {
200
- name: 'getWebsiteUrl: localhost:4000 in development AND testing, brand.url otherwise',
201
- async run({ Manager, assert }) {
202
- withEnv({ FUNCTIONS_EMULATOR: 'true' }, () => {
203
- assert.equal(Manager.getWebsiteUrl(), 'https://localhost:4000', 'dev → localhost:4000');
204
- });
205
- withEnv({ BEM_TESTING: 'true' }, () => {
206
- assert.equal(Manager.getWebsiteUrl(), 'https://localhost:4000', 'testing → localhost:4000');
207
- });
208
- withEnv({ ENVIRONMENT: 'production' }, () => {
209
- const url = Manager.getWebsiteUrl();
210
- assert.equal(url.startsWith('https://localhost'), false, 'prod → NOT localhost');
211
- });
212
- },
213
- },
214
-
215
- // ─── Parent helpers ALWAYS resolve live (never localhost), even in dev/testing ───
216
-
217
- {
218
- name: 'getParentApiUrl / getParentUrl never redirect to localhost (always live)',
219
- async run({ Manager, assert }) {
220
- // Even under the test harness ('testing'), the parent is a real remote server.
221
- const parentUrl = Manager.getParentUrl();
222
- const parentApi = Manager.getParentApiUrl();
223
- assert.equal((parentUrl || '').includes('localhost'), false, 'getParentUrl not localhost');
224
- assert.equal((parentApi || '').includes('localhost'), false, 'getParentApiUrl not localhost');
225
- // When set, the parent API URL carries the api. subdomain.
226
- if (parentApi) assert.match(parentApi, /^https:\/\/api\./, 'parent api uses api. subdomain');
227
- },
228
- },
229
- ],
230
- };
@@ -1,113 +0,0 @@
1
- /**
2
- * Test: libraries/infer-contact.js
3
- * Unit tests for contact inference from email addresses
4
- *
5
- * AI tests only run when TEST_EXTENDED_MODE is set.
6
- */
7
- const { inferContact, capitalize } = require('../../src/manager/libraries/infer-contact.js');
8
-
9
- module.exports = {
10
- description: 'Infer contact from email',
11
- type: 'group',
12
-
13
- tests: [
14
- // ─── capitalize ───
15
-
16
- {
17
- name: 'capitalize-single-word',
18
- async run({ assert }) {
19
- assert.equal(capitalize('john'), 'John', 'Should capitalize first letter');
20
- },
21
- },
22
-
23
- {
24
- name: 'capitalize-multiple-words',
25
- async run({ assert }) {
26
- assert.equal(capitalize('john doe'), 'John Doe', 'Should capitalize each word');
27
- },
28
- },
29
-
30
- {
31
- name: 'capitalize-all-uppercase',
32
- async run({ assert }) {
33
- assert.equal(capitalize('JOHN'), 'John', 'Should lowercase after first letter');
34
- },
35
- },
36
-
37
- {
38
- name: 'capitalize-mixed-case',
39
- async run({ assert }) {
40
- assert.equal(capitalize('jOHN dOE'), 'John Doe', 'Should normalize mixed case');
41
- },
42
- },
43
-
44
- {
45
- name: 'capitalize-empty-string',
46
- async run({ assert }) {
47
- assert.equal(capitalize(''), '', 'Empty string should return empty');
48
- },
49
- },
50
-
51
- {
52
- name: 'capitalize-null',
53
- async run({ assert }) {
54
- assert.equal(capitalize(null), '', 'Null should return empty');
55
- },
56
- },
57
-
58
- {
59
- name: 'capitalize-undefined',
60
- async run({ assert }) {
61
- assert.equal(capitalize(undefined), '', 'Undefined should return empty');
62
- },
63
- },
64
-
65
- // ─── inferContact: returns empty without AI key ───
66
-
67
- {
68
- name: 'infer-contact-no-ai-returns-none',
69
- async run({ assert }) {
70
- // Without BACKEND_MANAGER_OPENAI_API_KEY, should return empty result
71
- const originalKey = process.env.BACKEND_MANAGER_OPENAI_API_KEY;
72
- delete process.env.BACKEND_MANAGER_OPENAI_API_KEY;
73
-
74
- try {
75
- const result = await inferContact('alice.wonderland@example.com');
76
-
77
- assert.equal(result.firstName, '', 'No first name without AI');
78
- assert.equal(result.lastName, '', 'No last name without AI');
79
- assert.equal(result.company, '', 'No company without AI');
80
- assert.equal(result.method, 'none', 'Method should be none');
81
- assert.equal(result.confidence, 0, 'Confidence should be 0');
82
- } finally {
83
- if (originalKey) {
84
- process.env.BACKEND_MANAGER_OPENAI_API_KEY = originalKey;
85
- }
86
- }
87
- },
88
- },
89
-
90
- // ─── inferContact: AI path (requires TEST_EXTENDED_MODE) ───
91
-
92
- {
93
- name: 'infer-contact-ai',
94
- skip: !process.env.TEST_EXTENDED_MODE ? 'TEST_EXTENDED_MODE not set (skipping AI inference test)' : false,
95
- timeout: 30000,
96
-
97
- async run({ assert, Manager, skip }) {
98
- if (!process.env.BACKEND_MANAGER_OPENAI_API_KEY && !process.env.OPENAI_API_KEY) {
99
- return skip('BACKEND_MANAGER_OPENAI_API_KEY not set');
100
- }
101
-
102
- const assistant = Manager.Assistant();
103
- const result = await inferContact('john.smith@microsoft.com', assistant);
104
-
105
- assert.ok(result, 'Should return a result');
106
- assert.equal(result.method, 'ai', 'Should use AI method');
107
- assert.hasProperty(result, 'firstName', 'Should have firstName');
108
- assert.hasProperty(result, 'lastName', 'Should have lastName');
109
- assert.ok(typeof result.confidence === 'number', 'Confidence should be a number');
110
- },
111
- },
112
- ],
113
- };
@@ -1,271 +0,0 @@
1
- /**
2
- * Test: mergeLineBasedFiles()
3
- * Unit tests for the line-based .env / .gitignore / CLAUDE.md merge.
4
- *
5
- * Tests the pure function directly — no emulator, no Firestore, no HTTP.
6
- *
7
- * Regression coverage for the bug that scrambled consumers' `.env` files: an
8
- * older positional implementation zipped comment lines and value lines by index,
9
- * so any drift in key order shifted every value under the wrong header. The
10
- * canonical impl merges BY KEY, so headers always re-anchor to the template and
11
- * values follow their key across sections.
12
- */
13
- const {
14
- mergeLineBasedFiles,
15
- DEFAULT_MARKER,
16
- CUSTOM_MARKER,
17
- } = require('../../src/utils/merge-line-files.js');
18
-
19
- // Setup-test helper shim — must re-export the SAME canonical impl (SSOT).
20
- const helperShim = require('../../src/cli/commands/setup-tests/helpers/merge-line-files.js');
21
-
22
- // A representative framework .env template (keys grouped under headers).
23
- const TEMPLATE = [
24
- DEFAULT_MARKER,
25
- '# GitHub',
26
- 'GH_TOKEN=""',
27
- '',
28
- '# AI',
29
- 'OPENAI_API_KEY=""',
30
- 'ANTHROPIC_API_KEY=""',
31
- '',
32
- '# Payment Processors',
33
- 'PAYPAL_CLIENT_SECRET=""',
34
- 'STRIPE_SECRET_KEY=""',
35
- '',
36
- CUSTOM_MARKER,
37
- '# Add your custom environment variables below this line',
38
- ].join('\n');
39
-
40
- // Pull the value assigned to a key in a given section of a merged result.
41
- function keyValueInSection(merged, key, section /* 'default' | 'custom' */) {
42
- const lines = merged.split('\n');
43
- let mode = null;
44
- for (const line of lines) {
45
- const trimmed = line.trim();
46
- if (trimmed === DEFAULT_MARKER) { mode = 'default'; continue; }
47
- if (trimmed === CUSTOM_MARKER) { mode = 'custom'; continue; }
48
- if (mode !== section || !trimmed || trimmed.startsWith('#')) continue;
49
- const eq = trimmed.indexOf('=');
50
- if (eq < 0) continue;
51
- if (trimmed.slice(0, eq).trim() === key) return trimmed.slice(eq + 1);
52
- }
53
- return undefined;
54
- }
55
-
56
- // Count how many times a key appears anywhere (catches duplication bugs).
57
- function keyOccurrences(merged, key) {
58
- return merged.split('\n').filter((l) => l.trim().startsWith(`${key}=`)).length;
59
- }
60
-
61
- // Assert a key sits directly under the expected comment header in the merged output.
62
- function headerAboveKey(merged, key) {
63
- const lines = merged.split('\n');
64
- const idx = lines.findIndex((l) => l.trim().startsWith(`${key}=`));
65
- if (idx < 0) return null;
66
- for (let i = idx - 1; i >= 0; i--) {
67
- const t = lines[i].trim();
68
- if (t.startsWith('#') && t !== DEFAULT_MARKER && t !== CUSTOM_MARKER) return t;
69
- if (t && !t.startsWith('#')) continue; // another key — keep scanning up
70
- }
71
- return null;
72
- }
73
-
74
- module.exports = {
75
- description: 'mergeLineBasedFiles() line-based .env / .gitignore merge',
76
- type: 'group',
77
-
78
- tests: [
79
- {
80
- name: 'ssot-helper-shim-is-same-function',
81
- async run({ assert }) {
82
- assert.equal(
83
- helperShim.mergeLineBasedFiles,
84
- mergeLineBasedFiles,
85
- 'setup-tests helper must re-export the canonical mergeLineBasedFiles (SSOT)'
86
- );
87
- assert.equal(helperShim.DEFAULT_SECTION_MARKER, DEFAULT_MARKER, 'marker alias matches');
88
- assert.equal(helperShim.CUSTOM_SECTION_MARKER, CUSTOM_MARKER, 'marker alias matches');
89
- assert.ok(helperShim.hasSectionMarkers(TEMPLATE), 'hasSectionMarkers detects markers');
90
- },
91
- },
92
-
93
- {
94
- name: 'preserves-existing-values-by-key',
95
- async run({ assert }) {
96
- const existing = [
97
- DEFAULT_MARKER,
98
- '# GitHub',
99
- 'GH_TOKEN="ghp_real"',
100
- '# AI',
101
- 'OPENAI_API_KEY="sk-real"',
102
- 'ANTHROPIC_API_KEY=""',
103
- '# Payment Processors',
104
- 'PAYPAL_CLIENT_SECRET="pp_real"',
105
- 'STRIPE_SECRET_KEY=""',
106
- CUSTOM_MARKER,
107
- ].join('\n');
108
-
109
- const merged = mergeLineBasedFiles(existing, TEMPLATE, '.env');
110
- assert.equal(keyValueInSection(merged, 'GH_TOKEN', 'default'), '"ghp_real"', 'GH_TOKEN value kept');
111
- assert.equal(keyValueInSection(merged, 'OPENAI_API_KEY', 'default'), '"sk-real"', 'OPENAI value kept');
112
- assert.equal(keyValueInSection(merged, 'PAYPAL_CLIENT_SECRET', 'default'), '"pp_real"', 'PAYPAL value kept');
113
- },
114
- },
115
-
116
- {
117
- name: 'keys-stay-under-correct-header-when-order-drifts',
118
- async run({ assert }) {
119
- // Existing file has keys in a DIFFERENT order than the template. The old
120
- // positional merge would shift values under the wrong header here.
121
- const existing = [
122
- DEFAULT_MARKER,
123
- '# Misc (old grouping)',
124
- 'STRIPE_SECRET_KEY="stripe_real"',
125
- 'OPENAI_API_KEY="openai_real"',
126
- 'GH_TOKEN="gh_real"',
127
- 'PAYPAL_CLIENT_SECRET="pp_real"',
128
- 'ANTHROPIC_API_KEY="anthropic_real"',
129
- CUSTOM_MARKER,
130
- ].join('\n');
131
-
132
- const merged = mergeLineBasedFiles(existing, TEMPLATE, '.env');
133
-
134
- assert.equal(headerAboveKey(merged, 'OPENAI_API_KEY'), '# AI', 'OPENAI under # AI');
135
- assert.equal(headerAboveKey(merged, 'ANTHROPIC_API_KEY'), '# AI', 'ANTHROPIC under # AI');
136
- assert.equal(headerAboveKey(merged, 'PAYPAL_CLIENT_SECRET'), '# Payment Processors', 'PAYPAL under # Payment Processors');
137
- assert.equal(headerAboveKey(merged, 'STRIPE_SECRET_KEY'), '# Payment Processors', 'STRIPE under # Payment Processors');
138
- assert.equal(headerAboveKey(merged, 'GH_TOKEN'), '# GitHub', 'GH_TOKEN under # GitHub');
139
-
140
- // Values still attached to the right keys.
141
- assert.equal(keyValueInSection(merged, 'STRIPE_SECRET_KEY', 'default'), '"stripe_real"', 'STRIPE value intact');
142
- assert.equal(keyValueInSection(merged, 'OPENAI_API_KEY', 'default'), '"openai_real"', 'OPENAI value intact');
143
- },
144
- },
145
-
146
- {
147
- name: 'promotes-custom-key-to-default-when-template-adopts-it',
148
- async run({ assert }) {
149
- // User had APOLLO_API_KEY in Custom; framework adds it to the template.
150
- const tplWithApollo = TEMPLATE.replace('STRIPE_SECRET_KEY=""', 'STRIPE_SECRET_KEY=""\nAPOLLO_API_KEY=""');
151
- const existing = [
152
- DEFAULT_MARKER,
153
- '# GitHub',
154
- 'GH_TOKEN="gh_real"',
155
- '# AI',
156
- 'OPENAI_API_KEY=""',
157
- 'ANTHROPIC_API_KEY=""',
158
- '# Payment Processors',
159
- 'PAYPAL_CLIENT_SECRET=""',
160
- 'STRIPE_SECRET_KEY=""',
161
- CUSTOM_MARKER,
162
- 'APOLLO_API_KEY="apollo_real"',
163
- 'GITHUB_TOKEN="legacy"',
164
- ].join('\n');
165
-
166
- const merged = mergeLineBasedFiles(existing, tplWithApollo, '.env');
167
-
168
- assert.equal(keyValueInSection(merged, 'APOLLO_API_KEY', 'default'), '"apollo_real"', 'APOLLO promoted to Default with value');
169
- assert.equal(keyValueInSection(merged, 'APOLLO_API_KEY', 'custom'), undefined, 'APOLLO removed from Custom');
170
- assert.equal(keyOccurrences(merged, 'APOLLO_API_KEY'), 1, 'APOLLO not duplicated');
171
- },
172
- },
173
-
174
- {
175
- name: 'migrates-unknown-default-key-to-custom',
176
- async run({ assert }) {
177
- // User has a legacy key in Default that the template no longer defines.
178
- const existing = [
179
- DEFAULT_MARKER,
180
- '# GitHub',
181
- 'GITHUB_TOKEN="legacy_real"', // template now uses GH_TOKEN
182
- 'GH_TOKEN="gh_real"',
183
- '# AI',
184
- 'OPENAI_API_KEY=""',
185
- 'ANTHROPIC_API_KEY=""',
186
- '# Payment Processors',
187
- 'PAYPAL_CLIENT_SECRET=""',
188
- 'STRIPE_SECRET_KEY=""',
189
- CUSTOM_MARKER,
190
- ].join('\n');
191
-
192
- const merged = mergeLineBasedFiles(existing, TEMPLATE, '.env');
193
-
194
- assert.equal(keyValueInSection(merged, 'GITHUB_TOKEN', 'custom'), '"legacy_real"', 'legacy key migrated to Custom with value');
195
- assert.equal(keyValueInSection(merged, 'GITHUB_TOKEN', 'default'), undefined, 'legacy key gone from Default');
196
- assert.equal(keyValueInSection(merged, 'GH_TOKEN', 'default'), '"gh_real"', 'GH_TOKEN kept in Default');
197
- },
198
- },
199
-
200
- {
201
- name: 'preserves-custom-section-verbatim',
202
- async run({ assert }) {
203
- const existing = [
204
- DEFAULT_MARKER,
205
- '# GitHub',
206
- 'GH_TOKEN=""',
207
- '# AI',
208
- 'OPENAI_API_KEY=""',
209
- 'ANTHROPIC_API_KEY=""',
210
- '# Payment Processors',
211
- 'PAYPAL_CLIENT_SECRET=""',
212
- 'STRIPE_SECRET_KEY=""',
213
- CUSTOM_MARKER,
214
- 'MY_CUSTOM_KEY="custom_real"',
215
- '# OAuth2',
216
- 'OAUTH_ID="abc"',
217
- ].join('\n');
218
-
219
- const merged = mergeLineBasedFiles(existing, TEMPLATE, '.env');
220
- assert.equal(keyValueInSection(merged, 'MY_CUSTOM_KEY', 'custom'), '"custom_real"', 'custom key preserved');
221
- assert.equal(keyValueInSection(merged, 'OAUTH_ID', 'custom'), '"abc"', 'custom OAuth key preserved');
222
- assert.ok(merged.includes('# OAuth2'), 'custom comment preserved');
223
- },
224
- },
225
-
226
- {
227
- name: 'normalizes-raw-values-to-double-quoted',
228
- async run({ assert }) {
229
- const existing = [
230
- DEFAULT_MARKER,
231
- '# GitHub',
232
- 'GH_TOKEN=raw-no-quotes',
233
- '# AI',
234
- "OPENAI_API_KEY='single'",
235
- 'ANTHROPIC_API_KEY=""',
236
- '# Payment Processors',
237
- 'PAYPAL_CLIENT_SECRET=""',
238
- 'STRIPE_SECRET_KEY=""',
239
- CUSTOM_MARKER,
240
- ].join('\n');
241
-
242
- const merged = mergeLineBasedFiles(existing, TEMPLATE, '.env');
243
- assert.equal(keyValueInSection(merged, 'GH_TOKEN', 'default'), '"raw-no-quotes"', 'raw value double-quoted');
244
- assert.equal(keyValueInSection(merged, 'OPENAI_API_KEY', 'default'), '"single"', 'single-quoted canonicalized to double');
245
- },
246
- },
247
-
248
- {
249
- name: 'is-idempotent',
250
- async run({ assert }) {
251
- const existing = [
252
- DEFAULT_MARKER,
253
- '# GitHub',
254
- 'GH_TOKEN="gh_real"',
255
- '# AI',
256
- 'OPENAI_API_KEY="sk"',
257
- 'ANTHROPIC_API_KEY=""',
258
- '# Payment Processors',
259
- 'PAYPAL_CLIENT_SECRET=""',
260
- 'STRIPE_SECRET_KEY=""',
261
- CUSTOM_MARKER,
262
- 'CUSTOM="x"',
263
- ].join('\n');
264
-
265
- const once = mergeLineBasedFiles(existing, TEMPLATE, '.env');
266
- const twice = mergeLineBasedFiles(once, TEMPLATE, '.env');
267
- assert.equal(once, twice, 're-running the merge produces identical output');
268
- },
269
- },
270
- ],
271
- };