backend-manager 5.9.5 → 5.9.6

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 (244) hide show
  1. package/package.json +8 -1
  2. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/metadata.json +14 -0
  3. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/newsletter.html +486 -0
  4. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/newsletter.md +41 -0
  5. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/newsletter.mjml +97 -0
  6. package/{test/email/fixtures/clean.json → src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/structure.json} +16 -4
  7. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/summary.md +1 -0
  8. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/metadata.json +14 -0
  9. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/newsletter.html +486 -0
  10. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/newsletter.md +41 -0
  11. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/newsletter.mjml +97 -0
  12. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/structure.json +42 -0
  13. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/summary.md +1 -0
  14. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/metadata.json +14 -0
  15. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/newsletter.html +486 -0
  16. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/newsletter.md +41 -0
  17. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/newsletter.mjml +97 -0
  18. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/structure.json +42 -0
  19. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/summary.md +1 -0
  20. package/src/test/fixtures/firebase-project/.temp/test-mode.json +6 -0
  21. package/src/test/fixtures/firebase-project/database-debug.log +12 -0
  22. package/src/test/fixtures/firebase-project/firestore-debug.log +136 -0
  23. package/src/test/fixtures/firebase-project/pubsub-debug.log +17 -0
  24. package/.codeclimate.yml +0 -32
  25. package/.nvmrc +0 -1
  26. package/CHANGELOG.md +0 -1440
  27. package/PROGRESS.md +0 -93
  28. package/TODO-2.md +0 -121
  29. package/TODO-CHARGEBLAST.md +0 -32
  30. package/TODO-WEBHOOK-KEY-LEGACY-REMOVAL.md +0 -15
  31. package/TODO-WEBHOOK-KEY-UPGRADE.md +0 -138
  32. package/TODO-email-auth.md +0 -14
  33. package/TODO.md +0 -187
  34. package/plans/mcp2.md +0 -247
  35. package/plans/suspended-subscription-dead-zone.md +0 -97
  36. package/scripts/test-helper-providers.js +0 -162
  37. package/scripts/update-disposable-domains.js +0 -44
  38. package/templates/_.env +0 -42
  39. package/templates/_.gitignore +0 -60
  40. package/templates/backend-manager-config.json +0 -249
  41. package/templates/database.rules.json +0 -83
  42. package/templates/firebase.json +0 -66
  43. package/templates/firestore.indexes.json +0 -4
  44. package/templates/firestore.rules +0 -112
  45. package/templates/public/404.html +0 -26
  46. package/templates/public/index.html +0 -24
  47. package/templates/remoteconfig.template.json +0 -1
  48. package/templates/storage-lifecycle-config-1-day.json +0 -9
  49. package/templates/storage-lifecycle-config-30-days.json +0 -9
  50. package/templates/storage.rules +0 -8
  51. package/test/_init/accounts-validation.js +0 -58
  52. package/test/_legacy/ai/index.js +0 -231
  53. package/test/_legacy/ai/test.jpg +0 -0
  54. package/test/_legacy/ai/test.pdf +0 -0
  55. package/test/_legacy/index.js +0 -31
  56. package/test/_legacy/payment-resolver/chargebee/orders/refunded.json +0 -0
  57. package/test/_legacy/payment-resolver/chargebee/orders/unpaid.json +0 -98
  58. package/test/_legacy/payment-resolver/chargebee/subscriptions/active.json +0 -578
  59. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-in-trial.json +0 -38
  60. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-skipped-to-active.json +0 -135
  61. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-active-to-cancelled.json +0 -42
  62. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-active.json +0 -44
  63. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-cancelled.json +0 -39
  64. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-refund.json +0 -143
  65. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-suspended.json +0 -48
  66. package/test/_legacy/payment-resolver/coinbase/orders/regular.json +0 -204
  67. package/test/_legacy/payment-resolver/coinbase/subscriptions/cancelled.json +0 -204
  68. package/test/_legacy/payment-resolver/coinbase/subscriptions/paid-2.json +0 -125
  69. package/test/_legacy/payment-resolver/index.js +0 -1558
  70. package/test/_legacy/payment-resolver/paypal/orders/refunded.json +0 -0
  71. package/test/_legacy/payment-resolver/paypal/orders/regular.json +0 -120
  72. package/test/_legacy/payment-resolver/paypal/subscriptions/active-refund-previous-stmnt.json +0 -323
  73. package/test/_legacy/payment-resolver/paypal/subscriptions/active.json +0 -192
  74. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-in-trial.json +0 -125
  75. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-not-complete.json +0 -76
  76. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-overdue-2.json +0 -114
  77. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-overdue.json +0 -114
  78. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-active-to-cancelled.json +0 -111
  79. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-active.json +0 -132
  80. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-cancelled.json +0 -107
  81. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-expired.json +0 -91
  82. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-refund.json +0 -147
  83. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-suspended.json +0 -120
  84. package/test/_legacy/payment-resolver/stripe/orders/refunded.json +0 -0
  85. package/test/_legacy/payment-resolver/stripe/orders/regular.json +0 -91
  86. package/test/_legacy/payment-resolver/stripe/subscriptions/active.json +0 -421
  87. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-in-trial.json +0 -349
  88. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-active-failed-authorization.json +0 -430
  89. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-active.json +0 -319
  90. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-cancelled.json +0 -319
  91. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-refund.json +0 -414
  92. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-suspended.json +0 -319
  93. package/test/_legacy/payment-resolver/stripe/subscriptions/unsure.json +0 -339
  94. package/test/_legacy/test-new +0 -1178
  95. package/test/_legacy/test.md +0 -89
  96. package/test/_legacy/usage.js +0 -175
  97. package/test/_legacy/user.js +0 -31
  98. package/test/ai/tools-live.js +0 -170
  99. package/test/boot/emulator-boots.js +0 -37
  100. package/test/content/blog-generate.js +0 -160
  101. package/test/email/campaign-send.js +0 -45
  102. package/test/email/consent-lifecycle.js +0 -257
  103. package/test/email/feedback-and-plain-send.js +0 -52
  104. package/test/email/fixtures/editorial.json +0 -30
  105. package/test/email/fixtures/field-report.json +0 -53
  106. package/test/email/marketing-lifecycle.js +0 -132
  107. package/test/email/newsletter-generate.js +0 -819
  108. package/test/email/newsletter-templates.js +0 -491
  109. package/test/email/templates.js +0 -207
  110. package/test/email/transactional-send.js +0 -34
  111. package/test/email/transactional.js +0 -560
  112. package/test/email/validation.js +0 -710
  113. package/test/events/auth-delete-race.js +0 -201
  114. package/test/events/payments/journey-payments-cancel-endpoint.js +0 -100
  115. package/test/events/payments/journey-payments-cancel.js +0 -182
  116. package/test/events/payments/journey-payments-discount.js +0 -89
  117. package/test/events/payments/journey-payments-failure.js +0 -146
  118. package/test/events/payments/journey-payments-legacy-product.js +0 -149
  119. package/test/events/payments/journey-payments-one-time-failure.js +0 -111
  120. package/test/events/payments/journey-payments-one-time.js +0 -136
  121. package/test/events/payments/journey-payments-plan-change.js +0 -144
  122. package/test/events/payments/journey-payments-refund-webhook.js +0 -180
  123. package/test/events/payments/journey-payments-suspend.js +0 -181
  124. package/test/events/payments/journey-payments-trial-cancel.js +0 -130
  125. package/test/events/payments/journey-payments-trial.js +0 -171
  126. package/test/events/payments/journey-payments-uid-resolution.js +0 -132
  127. package/test/events/payments/journey-payments-upgrade.js +0 -135
  128. package/test/fixtures/chargebee/invoice-one-time.json +0 -27
  129. package/test/fixtures/chargebee/subscription-active.json +0 -44
  130. package/test/fixtures/chargebee/subscription-cancelled.json +0 -42
  131. package/test/fixtures/chargebee/subscription-in-trial.json +0 -41
  132. package/test/fixtures/chargebee/subscription-legacy-plan.json +0 -41
  133. package/test/fixtures/chargebee/subscription-non-renewing.json +0 -41
  134. package/test/fixtures/chargebee/subscription-paused.json +0 -42
  135. package/test/fixtures/chargebee/webhook-payment-failed.json +0 -51
  136. package/test/fixtures/chargebee/webhook-subscription-created.json +0 -47
  137. package/test/fixtures/paypal/order-approved.json +0 -62
  138. package/test/fixtures/paypal/order-completed.json +0 -110
  139. package/test/fixtures/paypal/subscription-active.json +0 -76
  140. package/test/fixtures/paypal/subscription-cancelled.json +0 -50
  141. package/test/fixtures/paypal/subscription-suspended.json +0 -65
  142. package/test/fixtures/stripe/checkout-session-completed.json +0 -130
  143. package/test/fixtures/stripe/invoice-payment-failed.json +0 -148
  144. package/test/fixtures/stripe/invoice-subscription-payment-failed.json +0 -28
  145. package/test/fixtures/stripe/subscription-active.json +0 -161
  146. package/test/fixtures/stripe/subscription-canceled.json +0 -161
  147. package/test/fixtures/stripe/subscription-trialing.json +0 -161
  148. package/test/functions/admin/database-read.js +0 -134
  149. package/test/functions/admin/database-write.js +0 -159
  150. package/test/functions/admin/edit-post.js +0 -366
  151. package/test/functions/admin/firestore-query.js +0 -207
  152. package/test/functions/admin/firestore-read.js +0 -129
  153. package/test/functions/admin/firestore-write.js +0 -105
  154. package/test/functions/admin/get-stats.js +0 -115
  155. package/test/functions/admin/send-email.js +0 -119
  156. package/test/functions/admin/send-notification.js +0 -208
  157. package/test/functions/admin/write-repo-content.js +0 -223
  158. package/test/functions/general/add-marketing-contact.js +0 -335
  159. package/test/functions/general/fetch-post.js +0 -54
  160. package/test/functions/general/generate-uuid.js +0 -114
  161. package/test/functions/test/authenticate.js +0 -64
  162. package/test/functions/user/create-custom-token.js +0 -73
  163. package/test/functions/user/delete.js +0 -135
  164. package/test/functions/user/get-active-sessions.js +0 -111
  165. package/test/functions/user/get-subscription-info.js +0 -99
  166. package/test/functions/user/regenerate-api-keys.js +0 -156
  167. package/test/functions/user/resolve.js +0 -52
  168. package/test/functions/user/sign-out-all-sessions.js +0 -94
  169. package/test/functions/user/sign-up.js +0 -252
  170. package/test/functions/user/submit-feedback.js +0 -104
  171. package/test/functions/user/validate-settings.js +0 -82
  172. package/test/helpers/ai-request-payload.js +0 -300
  173. package/test/helpers/ai-test-provider.js +0 -202
  174. package/test/helpers/ai-tools-format.js +0 -383
  175. package/test/helpers/content/blog-auto-publisher.js +0 -484
  176. package/test/helpers/content/feed-parser.js +0 -528
  177. package/test/helpers/content/ghostii-blocks.js +0 -134
  178. package/test/helpers/content/ghostii-feed-integration.js +0 -404
  179. package/test/helpers/content/ghostii-write-article.js +0 -243
  180. package/test/helpers/environment.js +0 -230
  181. package/test/helpers/infer-contact.js +0 -113
  182. package/test/helpers/merge-line-files.js +0 -271
  183. package/test/helpers/payment/chargebee/parse-webhook.js +0 -413
  184. package/test/helpers/payment/chargebee/to-unified-one-time.js +0 -147
  185. package/test/helpers/payment/chargebee/to-unified-subscription.js +0 -648
  186. package/test/helpers/payment/paypal/parse-webhook.js +0 -539
  187. package/test/helpers/payment/paypal/to-unified-one-time.js +0 -382
  188. package/test/helpers/payment/paypal/to-unified-subscription.js +0 -820
  189. package/test/helpers/payment/stripe/parse-webhook.js +0 -447
  190. package/test/helpers/payment/stripe/to-unified-one-time.js +0 -306
  191. package/test/helpers/payment/stripe/to-unified-subscription.js +0 -708
  192. package/test/helpers/sanitize.js +0 -222
  193. package/test/helpers/slugify.js +0 -394
  194. package/test/helpers/storage.js +0 -194
  195. package/test/helpers/user.js +0 -755
  196. package/test/helpers/webhook-forward.js +0 -418
  197. package/test/mcp/discovery.js +0 -53
  198. package/test/mcp/oauth.js +0 -161
  199. package/test/mcp/protocol.js +0 -268
  200. package/test/mcp/roles.js +0 -188
  201. package/test/mcp/utils.js +0 -245
  202. package/test/routes/admin/create-post.js +0 -364
  203. package/test/routes/admin/database.js +0 -131
  204. package/test/routes/admin/deduplicate-image-alts.js +0 -190
  205. package/test/routes/admin/email.js +0 -114
  206. package/test/routes/admin/firestore-query.js +0 -204
  207. package/test/routes/admin/firestore.js +0 -127
  208. package/test/routes/admin/infer-contact.js +0 -218
  209. package/test/routes/admin/notification.js +0 -198
  210. package/test/routes/admin/post-resize-image.js +0 -184
  211. package/test/routes/admin/post.js +0 -368
  212. package/test/routes/admin/repo-content.js +0 -223
  213. package/test/routes/admin/stats.js +0 -112
  214. package/test/routes/content/post.js +0 -54
  215. package/test/routes/general/uuid.js +0 -115
  216. package/test/routes/marketing/campaign.js +0 -125
  217. package/test/routes/marketing/contact.js +0 -370
  218. package/test/routes/marketing/email-preferences.js +0 -292
  219. package/test/routes/marketing/push-send.js +0 -32
  220. package/test/routes/marketing/webhook-forward.js +0 -61
  221. package/test/routes/marketing/webhook.js +0 -639
  222. package/test/routes/payments/cancel.js +0 -163
  223. package/test/routes/payments/discount.js +0 -80
  224. package/test/routes/payments/dispute-alert.js +0 -320
  225. package/test/routes/payments/intent.js +0 -336
  226. package/test/routes/payments/portal.js +0 -92
  227. package/test/routes/payments/refund.js +0 -179
  228. package/test/routes/payments/trial-eligibility.js +0 -71
  229. package/test/routes/payments/webhook.js +0 -107
  230. package/test/routes/test/authenticate.js +0 -59
  231. package/test/routes/test/schema.js +0 -554
  232. package/test/routes/test/usage.js +0 -342
  233. package/test/routes/user/api-keys.js +0 -156
  234. package/test/routes/user/delete.js +0 -136
  235. package/test/routes/user/feedback.js +0 -104
  236. package/test/routes/user/sessions.js +0 -199
  237. package/test/routes/user/settings-validate.js +0 -82
  238. package/test/routes/user/signup.js +0 -542
  239. package/test/routes/user/subscription.js +0 -99
  240. package/test/routes/user/token.js +0 -73
  241. package/test/routes/user/user.js +0 -157
  242. package/test/rules/notifications.js +0 -410
  243. package/test/rules/payments-carts.js +0 -371
  244. package/test/rules/user.js +0 -396
@@ -1,300 +0,0 @@
1
- /**
2
- * Test: AI request payload shape (libraries/ai/providers/openai.js)
3
- *
4
- * Verifies the transformation from the BEM-facing `ai.request()` options
5
- * (specifically `options.prompt` in either legacy object form or array form)
6
- * into the eventual OpenAI HTTP payload (the `input: [...]` array).
7
- *
8
- * These tests exercise the pure helpers `normalizePrompt` and `formatHistory`
9
- * directly — no network, no assistant required.
10
- */
11
- const OpenAI = require('../../src/manager/libraries/ai/providers/openai.js');
12
- const { normalizePrompt, formatHistory, VALID_PROMPT_ROLES } = OpenAI._internals;
13
-
14
- function noopLog() {}
15
-
16
- function baseOptions(overrides = {}) {
17
- return {
18
- dedupeConsecutiveRoles: true,
19
- history: { messages: [], limit: 5 },
20
- message: { attachments: [] },
21
- ...overrides,
22
- };
23
- }
24
-
25
- module.exports = {
26
- description: 'AI request payload shape (system/developer/user roles)',
27
- type: 'group',
28
- tests: [
29
- // ─── normalizePrompt ───
30
-
31
- {
32
- name: 'normalize-undefined-returns-empty-array',
33
- async run({ assert }) {
34
- assert.deepEqual(normalizePrompt(undefined), [], 'undefined → []');
35
- },
36
- },
37
-
38
- {
39
- name: 'normalize-null-returns-empty-array',
40
- async run({ assert }) {
41
- assert.deepEqual(normalizePrompt(null), [], 'null → []');
42
- },
43
- },
44
-
45
- {
46
- name: 'normalize-empty-object-returns-empty-array',
47
- async run({ assert }) {
48
- assert.deepEqual(normalizePrompt({}), [], 'empty object → []');
49
- },
50
- },
51
-
52
- {
53
- name: 'normalize-legacy-object-form-wraps-as-system-segment',
54
- async run({ assert }) {
55
- const result = normalizePrompt({ path: '/tmp/example.md', settings: { foo: 'bar' } });
56
-
57
- assert.equal(result.length, 1, 'one segment');
58
- assert.equal(result[0].role, 'system', 'legacy object defaults to system role');
59
- assert.equal(result[0].path, '/tmp/example.md', 'path preserved');
60
- assert.deepEqual(result[0].settings, { foo: 'bar' }, 'settings preserved');
61
- },
62
- },
63
-
64
- {
65
- name: 'normalize-legacy-object-with-content-only',
66
- async run({ assert }) {
67
- const result = normalizePrompt({ content: 'inline prompt text' });
68
-
69
- assert.equal(result.length, 1, 'one segment');
70
- assert.equal(result[0].role, 'system', 'defaults to system');
71
- assert.equal(result[0].content, 'inline prompt text', 'content preserved');
72
- assert.equal(result[0].path, '', 'no path');
73
- },
74
- },
75
-
76
- {
77
- name: 'normalize-array-form-preserves-roles-and-order',
78
- async run({ assert }) {
79
- const result = normalizePrompt([
80
- { role: 'system', content: 'platform rules' },
81
- { role: 'developer', content: 'operator config' },
82
- ]);
83
-
84
- assert.equal(result.length, 2, 'two segments');
85
- assert.equal(result[0].role, 'system', 'first is system');
86
- assert.equal(result[0].content, 'platform rules', 'first content');
87
- assert.equal(result[1].role, 'developer', 'second is developer');
88
- assert.equal(result[1].content, 'operator config', 'second content');
89
- },
90
- },
91
-
92
- {
93
- name: 'normalize-array-segment-without-role-defaults-to-system',
94
- async run({ assert }) {
95
- const result = normalizePrompt([
96
- { content: 'rule 1' },
97
- { role: 'developer', content: 'rule 2' },
98
- ]);
99
-
100
- assert.equal(result[0].role, 'system', 'missing role → system');
101
- assert.equal(result[1].role, 'developer', 'explicit role preserved');
102
- },
103
- },
104
-
105
- {
106
- name: 'normalize-array-with-invalid-role-throws',
107
- async run({ assert }) {
108
- let threw = false;
109
- try {
110
- normalizePrompt([{ role: 'admin', content: 'bad' }]);
111
- } catch (e) {
112
- threw = true;
113
- assert.equal(
114
- String(e.message).includes('Invalid prompt role'),
115
- true,
116
- 'error mentions Invalid prompt role',
117
- );
118
- }
119
- assert.equal(threw, true, 'should throw on invalid role');
120
- },
121
- },
122
-
123
- {
124
- name: 'normalize-valid-roles-set-matches-openai-model-spec',
125
- async run({ assert }) {
126
- const expected = ['system', 'developer', 'user', 'assistant'];
127
- const actual = [...VALID_PROMPT_ROLES].sort();
128
-
129
- assert.deepEqual(actual, expected.sort(), 'valid roles per OpenAI Model Spec');
130
- },
131
- },
132
-
133
- {
134
- name: 'normalize-all-valid-roles-accepted',
135
- async run({ assert }) {
136
- const segments = ['system', 'developer', 'user', 'assistant'].map((role) => ({
137
- role,
138
- content: `content for ${role}`,
139
- }));
140
-
141
- const result = normalizePrompt(segments);
142
-
143
- assert.equal(result.length, 4, 'all four segments accepted');
144
- result.forEach((segment, i) => {
145
- assert.equal(segment.role, segments[i].role, `segment ${i} role preserved`);
146
- });
147
- },
148
- },
149
-
150
- // ─── formatHistory → OpenAI Responses API payload shape ───
151
-
152
- {
153
- name: 'format-single-system-prompt-emits-system-then-user',
154
- async run({ assert }) {
155
- const promptSegments = normalizePrompt({ content: 'You are a helpful assistant.' });
156
- const formatted = formatHistory(baseOptions(), promptSegments, 'Hello!', noopLog);
157
-
158
- assert.equal(formatted.length, 2, 'two messages: system + user');
159
- assert.equal(formatted[0].role, 'system', 'first message is system');
160
- assert.equal(formatted[0].content[0].type, 'input_text', 'system uses input_text');
161
- assert.equal(formatted[0].content[0].text, 'You are a helpful assistant.', 'system text');
162
- assert.equal(formatted[1].role, 'user', 'second message is user');
163
- assert.equal(formatted[1].content[0].text, 'Hello!', 'user text');
164
- },
165
- },
166
-
167
- {
168
- name: 'format-system-plus-developer-emits-three-messages-in-order',
169
- async run({ assert }) {
170
- const promptSegments = normalizePrompt([
171
- { role: 'system', content: 'Platform rules go here.' },
172
- { role: 'developer', content: 'Operator config goes here.' },
173
- ]);
174
- const formatted = formatHistory(baseOptions(), promptSegments, 'Customer email body.', noopLog);
175
-
176
- assert.equal(formatted.length, 3, 'three messages');
177
- assert.equal(formatted[0].role, 'system', 'order: system');
178
- assert.equal(formatted[1].role, 'developer', 'order: developer');
179
- assert.equal(formatted[2].role, 'user', 'order: user');
180
- assert.equal(formatted[0].content[0].text, 'Platform rules go here.', 'system content');
181
- assert.equal(formatted[1].content[0].text, 'Operator config goes here.', 'developer content');
182
- assert.equal(formatted[2].content[0].text, 'Customer email body.', 'user content');
183
- },
184
- },
185
-
186
- {
187
- name: 'format-empty-prompt-array-emits-only-user-message',
188
- async run({ assert }) {
189
- const formatted = formatHistory(baseOptions(), [], 'Just a user message.', noopLog);
190
-
191
- assert.equal(formatted.length, 1, 'only the user message');
192
- assert.equal(formatted[0].role, 'user', 'role: user');
193
- assert.equal(formatted[0].content[0].text, 'Just a user message.', 'text preserved');
194
- },
195
- },
196
-
197
- {
198
- name: 'format-interleaves-prompt-history-and-new-user-message',
199
- async run({ assert }) {
200
- const promptSegments = normalizePrompt([
201
- { role: 'system', content: 'system rules' },
202
- { role: 'developer', content: 'developer rules' },
203
- ]);
204
- const options = baseOptions({
205
- history: {
206
- messages: [
207
- { role: 'user', content: 'first user msg' },
208
- { role: 'assistant', content: 'first ai reply' },
209
- ],
210
- limit: 5,
211
- },
212
- });
213
- const formatted = formatHistory(options, promptSegments, 'second user msg', noopLog);
214
-
215
- const roleSequence = formatted.map((m) => m.role);
216
- assert.deepEqual(
217
- roleSequence,
218
- ['system', 'developer', 'user', 'assistant', 'user'],
219
- 'prompts → history → new user message',
220
- );
221
- },
222
- },
223
-
224
- {
225
- name: 'format-assistant-history-uses-output_text-type',
226
- async run({ assert }) {
227
- const options = baseOptions({
228
- history: {
229
- messages: [{ role: 'assistant', content: 'previous reply' }],
230
- limit: 5,
231
- },
232
- });
233
- const formatted = formatHistory(options, [], 'new message', noopLog);
234
-
235
- const assistantMsg = formatted.find((m) => m.role === 'assistant');
236
- assert.equal(assistantMsg.content[0].type, 'output_text', 'assistant uses output_text');
237
- },
238
- },
239
-
240
- {
241
- name: 'format-respects-history-limit',
242
- async run({ assert }) {
243
- const options = baseOptions({
244
- history: {
245
- messages: [
246
- { role: 'user', content: 'msg 1' },
247
- { role: 'assistant', content: 'msg 2' },
248
- { role: 'user', content: 'msg 3' },
249
- { role: 'assistant', content: 'msg 4' },
250
- { role: 'user', content: 'msg 5' },
251
- { role: 'assistant', content: 'msg 6' },
252
- ],
253
- limit: 2,
254
- },
255
- });
256
- const formatted = formatHistory(options, normalizePrompt({ content: 'sys' }), 'now', noopLog);
257
-
258
- // Expected: 1 system + 2 history + 1 user = 4 messages
259
- assert.equal(formatted.length, 4, 'system + 2 history + new user');
260
- assert.equal(formatted[1].content[0].text, 'msg 5', 'second-to-last history kept');
261
- assert.equal(formatted[2].content[0].text, 'msg 6', 'last history kept');
262
- assert.equal(formatted[3].content[0].text, 'now', 'new user message appended');
263
- },
264
- },
265
-
266
- {
267
- name: 'format-dedupes-trailing-user-history-when-flag-set',
268
- async run({ assert }) {
269
- const options = baseOptions({
270
- dedupeConsecutiveRoles: true,
271
- history: {
272
- messages: [
273
- { role: 'assistant', content: 'reply' },
274
- { role: 'user', content: 'should be dropped' },
275
- ],
276
- limit: 5,
277
- },
278
- });
279
- const formatted = formatHistory(options, [], 'real new message', noopLog);
280
-
281
- // history's trailing 'user' is dropped, then the real new message is appended
282
- assert.equal(formatted.length, 2, 'assistant + new user only');
283
- assert.equal(formatted[0].role, 'assistant', 'kept assistant');
284
- assert.equal(formatted[1].role, 'user', 'new user');
285
- assert.equal(formatted[1].content[0].text, 'real new message', 'new user content');
286
- },
287
- },
288
-
289
- {
290
- name: 'format-strips-and-trims-content',
291
- async run({ assert }) {
292
- const promptSegments = normalizePrompt({ content: ' padded system content \n' });
293
- const formatted = formatHistory(baseOptions(), promptSegments, ' padded user content ', noopLog);
294
-
295
- assert.equal(formatted[0].content[0].text, 'padded system content', 'system trimmed');
296
- assert.equal(formatted[1].content[0].text, 'padded user content', 'user trimmed');
297
- },
298
- },
299
- ],
300
- };
@@ -1,202 +0,0 @@
1
- /**
2
- * Test: deterministic AI test provider (libraries/ai/providers/test.js)
3
- *
4
- * The test provider is a first-class provider (the `test` payment-processor
5
- * precedent) that consumer suites drive with directives embedded in the last
6
- * user message. These tests exercise the full request() surface directly —
7
- * no network involved by design.
8
- */
9
- const TestProvider = require('../../src/manager/libraries/ai/providers/test.js');
10
- const { parseScript } = TestProvider._internals;
11
-
12
- function makeProvider() {
13
- // No Manager — the provider falls back to the BEM_TESTING signal, which the
14
- // test runner sets
15
- return new TestProvider({});
16
- }
17
-
18
- module.exports = {
19
- description: 'AI test provider (scripted sequences)',
20
- type: 'group',
21
- tests: [
22
- // ─── Script parsing ───
23
-
24
- {
25
- name: 'parse-script-orders-steps-and-strips-directives',
26
- async run({ assert }) {
27
- const { steps, cleanText } = parseScript(
28
- 'Check my order [[tool:check_order {"orderNumber":"1"}]] please [[reply:{"message":"done"}]]',
29
- );
30
-
31
- assert.equal(steps.length, 2, 'two steps');
32
- assert.equal(steps[0].type, 'tools', 'first step is a tool call');
33
- assert.equal(steps[0].calls[0].name, 'check_order', 'tool name parsed');
34
- assert.deepEqual(steps[0].calls[0].arguments, { orderNumber: '1' }, 'tool args parsed');
35
- assert.equal(steps[1].type, 'reply', 'second step is the reply');
36
- assert.equal(cleanText, 'Check my order please', 'directives stripped from echo text');
37
- },
38
- },
39
-
40
- {
41
- name: 'parse-script-delay-attaches-to-next-step',
42
- async run({ assert }) {
43
- const { steps } = parseScript('[[delay:50]][[tool:slow_tool]]');
44
-
45
- assert.equal(steps.length, 1, 'one step');
46
- assert.equal(steps[0].delay, 50, 'delay attached to the tool step');
47
- },
48
- },
49
-
50
- // ─── Echo default ───
51
-
52
- {
53
- name: 'echo-reply-without-directives',
54
- async run({ assert }) {
55
- const provider = makeProvider();
56
- const result = await provider.request({
57
- messages: [
58
- { role: 'system', content: 'sys' },
59
- { role: 'user', content: 'hello there' },
60
- ],
61
- });
62
-
63
- assert.equal(result.content, 'Echo: hello there', 'echoes the user message');
64
- assert.equal(result.stopReason, 'end', 'final turn');
65
- assert.deepEqual(result.toolCalls, [], 'no tool calls');
66
- assert.equal(result.tokens.total.count > 0, true, 'tokens accounted');
67
- },
68
- },
69
-
70
- {
71
- name: 'echo-reply-json-mode-wraps-message',
72
- async run({ assert }) {
73
- const provider = makeProvider();
74
- const result = await provider.request({
75
- response: 'json',
76
- messages: [{ role: 'user', content: 'hi' }],
77
- });
78
-
79
- assert.equal(typeof result.content, 'object', 'parsed object');
80
- assert.equal(result.content.message, 'Echo: hi', 'wrapped message');
81
- },
82
- },
83
-
84
- // ─── Scripted reply ───
85
-
86
- {
87
- name: 'scripted-json-reply',
88
- async run({ assert }) {
89
- const provider = makeProvider();
90
- const result = await provider.request({
91
- response: 'json',
92
- messages: [
93
- { role: 'user', content: 'whatever [[reply:{"message":"Hi!","actions":[{"type":"reply","label":"More"}]}]]' },
94
- ],
95
- });
96
-
97
- assert.equal(result.content.message, 'Hi!', 'scripted message');
98
- assert.equal(result.content.actions[0].label, 'More', 'scripted actions');
99
- assert.equal(result.stopReason, 'end', 'final turn');
100
- },
101
- },
102
-
103
- // ─── Tool loop sequence ───
104
-
105
- {
106
- name: 'tool-then-reply-sequence-across-turns',
107
- async run({ assert }) {
108
- const provider = makeProvider();
109
- const script = 'check it [[tool:check_order {"orderNumber":"42"}]] [[reply:{"message":"Order 42 shipped"}]]';
110
-
111
- // Turn 1: the provider emits the tool call
112
- const first = await provider.request({
113
- response: 'json',
114
- messages: [
115
- { role: 'system', content: 'sys' },
116
- { role: 'user', content: script },
117
- ],
118
- });
119
-
120
- assert.equal(first.stopReason, 'tool_use', 'first turn requests the tool');
121
- assert.equal(first.toolCalls.length, 1, 'one call');
122
- assert.equal(first.toolCalls[0].name, 'check_order', 'tool name');
123
- assert.deepEqual(first.toolCalls[0].arguments, { orderNumber: '42' }, 'tool args');
124
-
125
- // Turn 2: caller appended the assistant turn + tool result — provider
126
- // moves to the next step (the reply)
127
- const second = await provider.request({
128
- response: 'json',
129
- messages: [
130
- { role: 'system', content: 'sys' },
131
- { role: 'user', content: script },
132
- { role: 'assistant', toolCalls: first.toolCalls },
133
- { role: 'tool', toolCallId: first.toolCalls[0].id, content: '{"status":"shipped"}' },
134
- ],
135
- });
136
-
137
- assert.equal(second.stopReason, 'end', 'second turn is final');
138
- assert.equal(second.content.message, 'Order 42 shipped', 'scripted final reply');
139
- },
140
- },
141
-
142
- {
143
- name: 'parallel-tools-directive-emits-multiple-calls',
144
- async run({ assert }) {
145
- const provider = makeProvider();
146
- const result = await provider.request({
147
- messages: [
148
- { role: 'user', content: '[[tools:[{"name":"a","arguments":{"x":1}},{"name":"b","arguments":{"y":2}}]]]' },
149
- ],
150
- });
151
-
152
- assert.equal(result.stopReason, 'tool_use', 'tool turn');
153
- assert.equal(result.toolCalls.length, 2, 'two parallel calls');
154
- assert.equal(result.toolCalls[0].name, 'a', 'first call');
155
- assert.equal(result.toolCalls[1].name, 'b', 'second call');
156
- assert.deepEqual(result.toolCalls[1].arguments, { y: 2 }, 'second args');
157
- },
158
- },
159
-
160
- // ─── Scripted error ───
161
-
162
- {
163
- name: 'scripted-error-throws',
164
- async run({ assert }) {
165
- const provider = makeProvider();
166
- let threw = false;
167
-
168
- try {
169
- await provider.request({
170
- messages: [{ role: 'user', content: '[[error:boom]]' }],
171
- });
172
- } catch (e) {
173
- threw = true;
174
- assert.equal(e.message, 'boom', 'scripted error message');
175
- }
176
-
177
- assert.equal(threw, true, 'throws the scripted error');
178
- },
179
- },
180
-
181
- // ─── Script exhaustion ───
182
-
183
- {
184
- name: 'exhausted-script-falls-back-to-echo',
185
- async run({ assert }) {
186
- const provider = makeProvider();
187
- const script = 'hi [[tool:t1]]';
188
-
189
- const second = await provider.request({
190
- messages: [
191
- { role: 'user', content: script },
192
- { role: 'assistant', toolCalls: [{ id: 'c', name: 't1', arguments: {} }] },
193
- { role: 'tool', toolCallId: 'c', content: 'r' },
194
- ],
195
- });
196
-
197
- assert.equal(second.stopReason, 'end', 'falls back to a final turn');
198
- assert.equal(String(second.content).startsWith('Echo:'), true, 'echo fallback');
199
- },
200
- },
201
- ],
202
- };