backend-manager 5.9.7 → 5.9.8
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.
- package/package.json +5 -3
- package/templates/_.env +42 -0
- package/templates/_.gitignore +60 -0
- package/templates/backend-manager-config.json +249 -0
- package/templates/database.rules.json +83 -0
- package/templates/firebase.json +66 -0
- package/templates/firestore.indexes.json +4 -0
- package/templates/firestore.rules +112 -0
- package/templates/public/404.html +26 -0
- package/templates/public/index.html +24 -0
- package/templates/remoteconfig.template.json +1 -0
- package/templates/storage-lifecycle-config-1-day.json +9 -0
- package/templates/storage-lifecycle-config-30-days.json +9 -0
- package/templates/storage.rules +8 -0
- package/test/_init/accounts-validation.js +58 -0
- package/test/_legacy/ai/index.js +231 -0
- package/test/_legacy/ai/test.jpg +0 -0
- package/test/_legacy/ai/test.pdf +0 -0
- package/test/_legacy/index.js +31 -0
- package/test/_legacy/payment-resolver/chargebee/orders/refunded.json +0 -0
- package/test/_legacy/payment-resolver/chargebee/orders/unpaid.json +98 -0
- package/test/_legacy/payment-resolver/chargebee/subscriptions/active.json +578 -0
- package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-in-trial.json +38 -0
- package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-skipped-to-active.json +135 -0
- package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-active-to-cancelled.json +42 -0
- package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-active.json +44 -0
- package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-cancelled.json +39 -0
- package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-refund.json +143 -0
- package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-suspended.json +48 -0
- package/test/_legacy/payment-resolver/coinbase/orders/regular.json +204 -0
- package/test/_legacy/payment-resolver/coinbase/subscriptions/cancelled.json +204 -0
- package/test/_legacy/payment-resolver/coinbase/subscriptions/paid-2.json +125 -0
- package/test/_legacy/payment-resolver/index.js +1558 -0
- package/test/_legacy/payment-resolver/paypal/orders/refunded.json +0 -0
- package/test/_legacy/payment-resolver/paypal/orders/regular.json +120 -0
- package/test/_legacy/payment-resolver/paypal/subscriptions/active-refund-previous-stmnt.json +323 -0
- package/test/_legacy/payment-resolver/paypal/subscriptions/active.json +192 -0
- package/test/_legacy/payment-resolver/paypal/subscriptions/trial-in-trial.json +125 -0
- package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-not-complete.json +76 -0
- package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-overdue-2.json +114 -0
- package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-overdue.json +114 -0
- package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-active-to-cancelled.json +111 -0
- package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-active.json +132 -0
- package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-cancelled.json +107 -0
- package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-expired.json +91 -0
- package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-refund.json +147 -0
- package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-suspended.json +120 -0
- package/test/_legacy/payment-resolver/stripe/orders/refunded.json +0 -0
- package/test/_legacy/payment-resolver/stripe/orders/regular.json +91 -0
- package/test/_legacy/payment-resolver/stripe/subscriptions/active.json +421 -0
- package/test/_legacy/payment-resolver/stripe/subscriptions/trial-in-trial.json +349 -0
- package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-active-failed-authorization.json +430 -0
- package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-active.json +319 -0
- package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-cancelled.json +319 -0
- package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-refund.json +414 -0
- package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-suspended.json +319 -0
- package/test/_legacy/payment-resolver/stripe/subscriptions/unsure.json +339 -0
- package/test/_legacy/test-new +1178 -0
- package/test/_legacy/test.md +89 -0
- package/test/_legacy/usage.js +175 -0
- package/test/_legacy/user.js +31 -0
- package/test/ai/tools-live.js +170 -0
- package/test/boot/emulator-boots.js +37 -0
- package/test/content/blog-generate.js +160 -0
- package/test/email/campaign-send.js +45 -0
- package/test/email/consent-lifecycle.js +257 -0
- package/test/email/feedback-and-plain-send.js +52 -0
- package/test/email/fixtures/clean.json +30 -0
- package/test/email/fixtures/editorial.json +30 -0
- package/test/email/fixtures/field-report.json +53 -0
- package/test/email/marketing-lifecycle.js +132 -0
- package/test/email/newsletter-generate.js +819 -0
- package/test/email/newsletter-templates.js +491 -0
- package/test/email/templates.js +207 -0
- package/test/email/transactional-send.js +34 -0
- package/test/email/transactional.js +560 -0
- package/test/email/validation.js +710 -0
- package/test/events/auth-delete-race.js +201 -0
- package/test/events/payments/journey-payments-cancel-endpoint.js +100 -0
- package/test/events/payments/journey-payments-cancel.js +182 -0
- package/test/events/payments/journey-payments-discount.js +89 -0
- package/test/events/payments/journey-payments-failure.js +146 -0
- package/test/events/payments/journey-payments-legacy-product.js +149 -0
- package/test/events/payments/journey-payments-one-time-failure.js +111 -0
- package/test/events/payments/journey-payments-one-time.js +136 -0
- package/test/events/payments/journey-payments-plan-change.js +144 -0
- package/test/events/payments/journey-payments-refund-webhook.js +180 -0
- package/test/events/payments/journey-payments-suspend.js +181 -0
- package/test/events/payments/journey-payments-trial-cancel.js +130 -0
- package/test/events/payments/journey-payments-trial.js +171 -0
- package/test/events/payments/journey-payments-uid-resolution.js +132 -0
- package/test/events/payments/journey-payments-upgrade.js +135 -0
- package/test/fixtures/chargebee/invoice-one-time.json +27 -0
- package/test/fixtures/chargebee/subscription-active.json +44 -0
- package/test/fixtures/chargebee/subscription-cancelled.json +42 -0
- package/test/fixtures/chargebee/subscription-in-trial.json +41 -0
- package/test/fixtures/chargebee/subscription-legacy-plan.json +41 -0
- package/test/fixtures/chargebee/subscription-non-renewing.json +41 -0
- package/test/fixtures/chargebee/subscription-paused.json +42 -0
- package/test/fixtures/chargebee/webhook-payment-failed.json +51 -0
- package/test/fixtures/chargebee/webhook-subscription-created.json +47 -0
- package/test/fixtures/paypal/order-approved.json +62 -0
- package/test/fixtures/paypal/order-completed.json +110 -0
- package/test/fixtures/paypal/subscription-active.json +76 -0
- package/test/fixtures/paypal/subscription-cancelled.json +50 -0
- package/test/fixtures/paypal/subscription-suspended.json +65 -0
- package/test/fixtures/stripe/checkout-session-completed.json +130 -0
- package/test/fixtures/stripe/invoice-payment-failed.json +148 -0
- package/test/fixtures/stripe/invoice-subscription-payment-failed.json +28 -0
- package/test/fixtures/stripe/subscription-active.json +161 -0
- package/test/fixtures/stripe/subscription-canceled.json +161 -0
- package/test/fixtures/stripe/subscription-trialing.json +161 -0
- package/test/functions/admin/database-read.js +134 -0
- package/test/functions/admin/database-write.js +159 -0
- package/test/functions/admin/edit-post.js +366 -0
- package/test/functions/admin/firestore-query.js +207 -0
- package/test/functions/admin/firestore-read.js +129 -0
- package/test/functions/admin/firestore-write.js +105 -0
- package/test/functions/admin/get-stats.js +115 -0
- package/test/functions/admin/send-email.js +119 -0
- package/test/functions/admin/send-notification.js +208 -0
- package/test/functions/admin/write-repo-content.js +223 -0
- package/test/functions/general/add-marketing-contact.js +335 -0
- package/test/functions/general/fetch-post.js +54 -0
- package/test/functions/general/generate-uuid.js +114 -0
- package/test/functions/test/authenticate.js +64 -0
- package/test/functions/user/create-custom-token.js +73 -0
- package/test/functions/user/delete.js +135 -0
- package/test/functions/user/get-active-sessions.js +111 -0
- package/test/functions/user/get-subscription-info.js +99 -0
- package/test/functions/user/regenerate-api-keys.js +156 -0
- package/test/functions/user/resolve.js +52 -0
- package/test/functions/user/sign-out-all-sessions.js +94 -0
- package/test/functions/user/sign-up.js +252 -0
- package/test/functions/user/submit-feedback.js +104 -0
- package/test/functions/user/validate-settings.js +82 -0
- package/test/helpers/ai-request-payload.js +300 -0
- package/test/helpers/ai-test-provider.js +202 -0
- package/test/helpers/ai-tools-format.js +383 -0
- package/test/helpers/content/blog-auto-publisher.js +484 -0
- package/test/helpers/content/feed-parser.js +528 -0
- package/test/helpers/content/ghostii-blocks.js +134 -0
- package/test/helpers/content/ghostii-feed-integration.js +404 -0
- package/test/helpers/content/ghostii-write-article.js +243 -0
- package/test/helpers/environment.js +230 -0
- package/test/helpers/infer-contact.js +113 -0
- package/test/helpers/merge-line-files.js +271 -0
- package/test/helpers/payment/chargebee/parse-webhook.js +413 -0
- package/test/helpers/payment/chargebee/to-unified-one-time.js +147 -0
- package/test/helpers/payment/chargebee/to-unified-subscription.js +648 -0
- package/test/helpers/payment/paypal/parse-webhook.js +539 -0
- package/test/helpers/payment/paypal/to-unified-one-time.js +382 -0
- package/test/helpers/payment/paypal/to-unified-subscription.js +820 -0
- package/test/helpers/payment/stripe/parse-webhook.js +447 -0
- package/test/helpers/payment/stripe/to-unified-one-time.js +306 -0
- package/test/helpers/payment/stripe/to-unified-subscription.js +708 -0
- package/test/helpers/sanitize.js +222 -0
- package/test/helpers/slugify.js +394 -0
- package/test/helpers/storage.js +194 -0
- package/test/helpers/user.js +755 -0
- package/test/helpers/webhook-forward.js +418 -0
- package/test/mcp/discovery.js +53 -0
- package/test/mcp/oauth.js +161 -0
- package/test/mcp/protocol.js +268 -0
- package/test/mcp/roles.js +188 -0
- package/test/mcp/utils.js +245 -0
- package/test/routes/admin/create-post.js +364 -0
- package/test/routes/admin/database.js +131 -0
- package/test/routes/admin/deduplicate-image-alts.js +190 -0
- package/test/routes/admin/email.js +114 -0
- package/test/routes/admin/firestore-query.js +204 -0
- package/test/routes/admin/firestore.js +127 -0
- package/test/routes/admin/infer-contact.js +218 -0
- package/test/routes/admin/notification.js +198 -0
- package/test/routes/admin/post-resize-image.js +184 -0
- package/test/routes/admin/post.js +368 -0
- package/test/routes/admin/repo-content.js +223 -0
- package/test/routes/admin/stats.js +112 -0
- package/test/routes/content/post.js +54 -0
- package/test/routes/general/uuid.js +115 -0
- package/test/routes/marketing/campaign.js +125 -0
- package/test/routes/marketing/contact.js +370 -0
- package/test/routes/marketing/email-preferences.js +292 -0
- package/test/routes/marketing/push-send.js +32 -0
- package/test/routes/marketing/webhook-forward.js +61 -0
- package/test/routes/marketing/webhook.js +639 -0
- package/test/routes/payments/cancel.js +163 -0
- package/test/routes/payments/discount.js +80 -0
- package/test/routes/payments/dispute-alert.js +320 -0
- package/test/routes/payments/intent.js +336 -0
- package/test/routes/payments/portal.js +92 -0
- package/test/routes/payments/refund.js +179 -0
- package/test/routes/payments/trial-eligibility.js +71 -0
- package/test/routes/payments/webhook.js +107 -0
- package/test/routes/test/authenticate.js +59 -0
- package/test/routes/test/schema.js +554 -0
- package/test/routes/test/usage.js +342 -0
- package/test/routes/user/api-keys.js +156 -0
- package/test/routes/user/delete.js +136 -0
- package/test/routes/user/feedback.js +104 -0
- package/test/routes/user/sessions.js +199 -0
- package/test/routes/user/settings-validate.js +82 -0
- package/test/routes/user/signup.js +542 -0
- package/test/routes/user/subscription.js +99 -0
- package/test/routes/user/token.js +73 -0
- package/test/routes/user/user.js +157 -0
- package/test/rules/notifications.js +410 -0
- package/test/rules/payments-carts.js +371 -0
- package/test/rules/user.js +396 -0
|
@@ -0,0 +1,230 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,271 @@
|
|
|
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
|
+
};
|