backend-manager 5.9.4 → 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 (251) hide show
  1. package/CLAUDE.md +6 -0
  2. package/package.json +8 -1
  3. package/src/cli/commands/install.js +4 -3
  4. package/src/cli/commands/setup-tests/backend-manager.js +2 -1
  5. package/src/cli/commands/setup-tests/firebase-admin.js +2 -1
  6. package/src/cli/commands/setup-tests/firebase-functions.js +2 -1
  7. package/src/cli/utils/safe-install.js +13 -0
  8. package/src/manager/routes/payments/cancel/post.js +22 -2
  9. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/metadata.json +14 -0
  10. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/newsletter.html +486 -0
  11. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/newsletter.md +41 -0
  12. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/newsletter.mjml +97 -0
  13. package/{test/email/fixtures/clean.json → src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/structure.json} +16 -4
  14. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/summary.md +1 -0
  15. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/metadata.json +14 -0
  16. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/newsletter.html +486 -0
  17. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/newsletter.md +41 -0
  18. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/newsletter.mjml +97 -0
  19. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/structure.json +42 -0
  20. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/summary.md +1 -0
  21. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/metadata.json +14 -0
  22. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/newsletter.html +486 -0
  23. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/newsletter.md +41 -0
  24. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/newsletter.mjml +97 -0
  25. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/structure.json +42 -0
  26. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/summary.md +1 -0
  27. package/src/test/fixtures/firebase-project/.temp/test-mode.json +6 -0
  28. package/src/test/fixtures/firebase-project/database-debug.log +12 -0
  29. package/src/test/fixtures/firebase-project/firestore-debug.log +136 -0
  30. package/src/test/fixtures/firebase-project/pubsub-debug.log +17 -0
  31. package/src/test/test-accounts.js +9 -0
  32. package/.codeclimate.yml +0 -32
  33. package/.nvmrc +0 -1
  34. package/CHANGELOG.md +0 -1432
  35. package/PROGRESS.md +0 -86
  36. package/TODO-2.md +0 -121
  37. package/TODO-CHARGEBLAST.md +0 -32
  38. package/TODO-WEBHOOK-KEY-LEGACY-REMOVAL.md +0 -15
  39. package/TODO-WEBHOOK-KEY-UPGRADE.md +0 -138
  40. package/TODO-email-auth.md +0 -14
  41. package/TODO.md +0 -187
  42. package/plans/mcp2.md +0 -247
  43. package/scripts/test-helper-providers.js +0 -162
  44. package/scripts/update-disposable-domains.js +0 -44
  45. package/templates/_.env +0 -42
  46. package/templates/_.gitignore +0 -60
  47. package/templates/backend-manager-config.json +0 -249
  48. package/templates/database.rules.json +0 -83
  49. package/templates/firebase.json +0 -66
  50. package/templates/firestore.indexes.json +0 -4
  51. package/templates/firestore.rules +0 -112
  52. package/templates/public/404.html +0 -26
  53. package/templates/public/index.html +0 -24
  54. package/templates/remoteconfig.template.json +0 -1
  55. package/templates/storage-lifecycle-config-1-day.json +0 -9
  56. package/templates/storage-lifecycle-config-30-days.json +0 -9
  57. package/templates/storage.rules +0 -8
  58. package/test/_init/accounts-validation.js +0 -58
  59. package/test/_legacy/ai/index.js +0 -231
  60. package/test/_legacy/ai/test.jpg +0 -0
  61. package/test/_legacy/ai/test.pdf +0 -0
  62. package/test/_legacy/index.js +0 -31
  63. package/test/_legacy/payment-resolver/chargebee/orders/refunded.json +0 -0
  64. package/test/_legacy/payment-resolver/chargebee/orders/unpaid.json +0 -98
  65. package/test/_legacy/payment-resolver/chargebee/subscriptions/active.json +0 -578
  66. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-in-trial.json +0 -38
  67. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-skipped-to-active.json +0 -135
  68. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-active-to-cancelled.json +0 -42
  69. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-active.json +0 -44
  70. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-cancelled.json +0 -39
  71. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-refund.json +0 -143
  72. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-suspended.json +0 -48
  73. package/test/_legacy/payment-resolver/coinbase/orders/regular.json +0 -204
  74. package/test/_legacy/payment-resolver/coinbase/subscriptions/cancelled.json +0 -204
  75. package/test/_legacy/payment-resolver/coinbase/subscriptions/paid-2.json +0 -125
  76. package/test/_legacy/payment-resolver/index.js +0 -1558
  77. package/test/_legacy/payment-resolver/paypal/orders/refunded.json +0 -0
  78. package/test/_legacy/payment-resolver/paypal/orders/regular.json +0 -120
  79. package/test/_legacy/payment-resolver/paypal/subscriptions/active-refund-previous-stmnt.json +0 -323
  80. package/test/_legacy/payment-resolver/paypal/subscriptions/active.json +0 -192
  81. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-in-trial.json +0 -125
  82. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-not-complete.json +0 -76
  83. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-overdue-2.json +0 -114
  84. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-overdue.json +0 -114
  85. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-active-to-cancelled.json +0 -111
  86. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-active.json +0 -132
  87. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-cancelled.json +0 -107
  88. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-expired.json +0 -91
  89. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-refund.json +0 -147
  90. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-suspended.json +0 -120
  91. package/test/_legacy/payment-resolver/stripe/orders/refunded.json +0 -0
  92. package/test/_legacy/payment-resolver/stripe/orders/regular.json +0 -91
  93. package/test/_legacy/payment-resolver/stripe/subscriptions/active.json +0 -421
  94. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-in-trial.json +0 -349
  95. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-active-failed-authorization.json +0 -430
  96. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-active.json +0 -319
  97. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-cancelled.json +0 -319
  98. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-refund.json +0 -414
  99. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-suspended.json +0 -319
  100. package/test/_legacy/payment-resolver/stripe/subscriptions/unsure.json +0 -339
  101. package/test/_legacy/test-new +0 -1178
  102. package/test/_legacy/test.md +0 -89
  103. package/test/_legacy/usage.js +0 -175
  104. package/test/_legacy/user.js +0 -31
  105. package/test/ai/tools-live.js +0 -170
  106. package/test/boot/emulator-boots.js +0 -37
  107. package/test/content/blog-generate.js +0 -160
  108. package/test/email/campaign-send.js +0 -45
  109. package/test/email/consent-lifecycle.js +0 -257
  110. package/test/email/feedback-and-plain-send.js +0 -52
  111. package/test/email/fixtures/editorial.json +0 -30
  112. package/test/email/fixtures/field-report.json +0 -53
  113. package/test/email/marketing-lifecycle.js +0 -132
  114. package/test/email/newsletter-generate.js +0 -819
  115. package/test/email/newsletter-templates.js +0 -491
  116. package/test/email/templates.js +0 -207
  117. package/test/email/transactional-send.js +0 -34
  118. package/test/email/transactional.js +0 -560
  119. package/test/email/validation.js +0 -710
  120. package/test/events/auth-delete-race.js +0 -201
  121. package/test/events/payments/journey-payments-cancel-endpoint.js +0 -100
  122. package/test/events/payments/journey-payments-cancel.js +0 -182
  123. package/test/events/payments/journey-payments-discount.js +0 -89
  124. package/test/events/payments/journey-payments-failure.js +0 -146
  125. package/test/events/payments/journey-payments-legacy-product.js +0 -149
  126. package/test/events/payments/journey-payments-one-time-failure.js +0 -111
  127. package/test/events/payments/journey-payments-one-time.js +0 -136
  128. package/test/events/payments/journey-payments-plan-change.js +0 -144
  129. package/test/events/payments/journey-payments-refund-webhook.js +0 -180
  130. package/test/events/payments/journey-payments-suspend.js +0 -181
  131. package/test/events/payments/journey-payments-trial-cancel.js +0 -130
  132. package/test/events/payments/journey-payments-trial.js +0 -171
  133. package/test/events/payments/journey-payments-uid-resolution.js +0 -132
  134. package/test/events/payments/journey-payments-upgrade.js +0 -135
  135. package/test/fixtures/chargebee/invoice-one-time.json +0 -27
  136. package/test/fixtures/chargebee/subscription-active.json +0 -44
  137. package/test/fixtures/chargebee/subscription-cancelled.json +0 -42
  138. package/test/fixtures/chargebee/subscription-in-trial.json +0 -41
  139. package/test/fixtures/chargebee/subscription-legacy-plan.json +0 -41
  140. package/test/fixtures/chargebee/subscription-non-renewing.json +0 -41
  141. package/test/fixtures/chargebee/subscription-paused.json +0 -42
  142. package/test/fixtures/chargebee/webhook-payment-failed.json +0 -51
  143. package/test/fixtures/chargebee/webhook-subscription-created.json +0 -47
  144. package/test/fixtures/paypal/order-approved.json +0 -62
  145. package/test/fixtures/paypal/order-completed.json +0 -110
  146. package/test/fixtures/paypal/subscription-active.json +0 -76
  147. package/test/fixtures/paypal/subscription-cancelled.json +0 -50
  148. package/test/fixtures/paypal/subscription-suspended.json +0 -65
  149. package/test/fixtures/stripe/checkout-session-completed.json +0 -130
  150. package/test/fixtures/stripe/invoice-payment-failed.json +0 -148
  151. package/test/fixtures/stripe/invoice-subscription-payment-failed.json +0 -28
  152. package/test/fixtures/stripe/subscription-active.json +0 -161
  153. package/test/fixtures/stripe/subscription-canceled.json +0 -161
  154. package/test/fixtures/stripe/subscription-trialing.json +0 -161
  155. package/test/functions/admin/database-read.js +0 -134
  156. package/test/functions/admin/database-write.js +0 -159
  157. package/test/functions/admin/edit-post.js +0 -366
  158. package/test/functions/admin/firestore-query.js +0 -207
  159. package/test/functions/admin/firestore-read.js +0 -129
  160. package/test/functions/admin/firestore-write.js +0 -105
  161. package/test/functions/admin/get-stats.js +0 -115
  162. package/test/functions/admin/send-email.js +0 -119
  163. package/test/functions/admin/send-notification.js +0 -208
  164. package/test/functions/admin/write-repo-content.js +0 -223
  165. package/test/functions/general/add-marketing-contact.js +0 -335
  166. package/test/functions/general/fetch-post.js +0 -54
  167. package/test/functions/general/generate-uuid.js +0 -114
  168. package/test/functions/test/authenticate.js +0 -64
  169. package/test/functions/user/create-custom-token.js +0 -73
  170. package/test/functions/user/delete.js +0 -135
  171. package/test/functions/user/get-active-sessions.js +0 -111
  172. package/test/functions/user/get-subscription-info.js +0 -99
  173. package/test/functions/user/regenerate-api-keys.js +0 -156
  174. package/test/functions/user/resolve.js +0 -52
  175. package/test/functions/user/sign-out-all-sessions.js +0 -94
  176. package/test/functions/user/sign-up.js +0 -252
  177. package/test/functions/user/submit-feedback.js +0 -104
  178. package/test/functions/user/validate-settings.js +0 -82
  179. package/test/helpers/ai-request-payload.js +0 -300
  180. package/test/helpers/ai-test-provider.js +0 -202
  181. package/test/helpers/ai-tools-format.js +0 -383
  182. package/test/helpers/content/blog-auto-publisher.js +0 -484
  183. package/test/helpers/content/feed-parser.js +0 -528
  184. package/test/helpers/content/ghostii-blocks.js +0 -134
  185. package/test/helpers/content/ghostii-feed-integration.js +0 -404
  186. package/test/helpers/content/ghostii-write-article.js +0 -243
  187. package/test/helpers/environment.js +0 -230
  188. package/test/helpers/infer-contact.js +0 -113
  189. package/test/helpers/merge-line-files.js +0 -271
  190. package/test/helpers/payment/chargebee/parse-webhook.js +0 -413
  191. package/test/helpers/payment/chargebee/to-unified-one-time.js +0 -147
  192. package/test/helpers/payment/chargebee/to-unified-subscription.js +0 -648
  193. package/test/helpers/payment/paypal/parse-webhook.js +0 -539
  194. package/test/helpers/payment/paypal/to-unified-one-time.js +0 -382
  195. package/test/helpers/payment/paypal/to-unified-subscription.js +0 -820
  196. package/test/helpers/payment/stripe/parse-webhook.js +0 -447
  197. package/test/helpers/payment/stripe/to-unified-one-time.js +0 -306
  198. package/test/helpers/payment/stripe/to-unified-subscription.js +0 -708
  199. package/test/helpers/sanitize.js +0 -222
  200. package/test/helpers/slugify.js +0 -394
  201. package/test/helpers/storage.js +0 -194
  202. package/test/helpers/user.js +0 -755
  203. package/test/helpers/webhook-forward.js +0 -418
  204. package/test/mcp/discovery.js +0 -53
  205. package/test/mcp/oauth.js +0 -161
  206. package/test/mcp/protocol.js +0 -268
  207. package/test/mcp/roles.js +0 -188
  208. package/test/mcp/utils.js +0 -245
  209. package/test/routes/admin/create-post.js +0 -364
  210. package/test/routes/admin/database.js +0 -131
  211. package/test/routes/admin/deduplicate-image-alts.js +0 -190
  212. package/test/routes/admin/email.js +0 -114
  213. package/test/routes/admin/firestore-query.js +0 -204
  214. package/test/routes/admin/firestore.js +0 -127
  215. package/test/routes/admin/infer-contact.js +0 -218
  216. package/test/routes/admin/notification.js +0 -198
  217. package/test/routes/admin/post-resize-image.js +0 -184
  218. package/test/routes/admin/post.js +0 -368
  219. package/test/routes/admin/repo-content.js +0 -223
  220. package/test/routes/admin/stats.js +0 -112
  221. package/test/routes/content/post.js +0 -54
  222. package/test/routes/general/uuid.js +0 -115
  223. package/test/routes/marketing/campaign.js +0 -125
  224. package/test/routes/marketing/contact.js +0 -370
  225. package/test/routes/marketing/email-preferences.js +0 -292
  226. package/test/routes/marketing/push-send.js +0 -32
  227. package/test/routes/marketing/webhook-forward.js +0 -61
  228. package/test/routes/marketing/webhook.js +0 -639
  229. package/test/routes/payments/cancel.js +0 -140
  230. package/test/routes/payments/discount.js +0 -80
  231. package/test/routes/payments/dispute-alert.js +0 -320
  232. package/test/routes/payments/intent.js +0 -336
  233. package/test/routes/payments/portal.js +0 -92
  234. package/test/routes/payments/refund.js +0 -179
  235. package/test/routes/payments/trial-eligibility.js +0 -71
  236. package/test/routes/payments/webhook.js +0 -107
  237. package/test/routes/test/authenticate.js +0 -59
  238. package/test/routes/test/schema.js +0 -554
  239. package/test/routes/test/usage.js +0 -342
  240. package/test/routes/user/api-keys.js +0 -156
  241. package/test/routes/user/delete.js +0 -136
  242. package/test/routes/user/feedback.js +0 -104
  243. package/test/routes/user/sessions.js +0 -199
  244. package/test/routes/user/settings-validate.js +0 -82
  245. package/test/routes/user/signup.js +0 -542
  246. package/test/routes/user/subscription.js +0 -99
  247. package/test/routes/user/token.js +0 -73
  248. package/test/routes/user/user.js +0 -157
  249. package/test/rules/notifications.js +0 -410
  250. package/test/rules/payments-carts.js +0 -371
  251. package/test/rules/user.js +0 -396
@@ -1,404 +0,0 @@
1
- /**
2
- * Test: content/ghostii-feed-integration
3
- * Integration + extended-mode tests for the feed-based article pipeline.
4
- *
5
- * Run: npx mgr test --extended helpers/content/ghostii-feed-integration
6
- *
7
- * Standard tests: processFeedSource() with inline feed data against the emulator.
8
- * Extended tests: fetch real RSS/Atom feeds, parse, extract article content,
9
- * verify Firestore dedup across multiple runs.
10
- *
11
- * Extended test artifacts saved to: .temp/ghostii-feed/run-{timestamp}/
12
- */
13
- const path = require('path');
14
- const jetpack = require('fs-jetpack');
15
- const fetch = require('wonderful-fetch');
16
- const publisherPath = path.resolve(__dirname, '../../../src/manager/events/cron/daily/blog-auto-publisher.js');
17
- const { parseFeed, extractArticleContent } = require('../../../src/manager/libraries/content/feed-parser.js');
18
- const { contentSourceHash, getProcessedItemIds, trackContentSource } = require(publisherPath);
19
-
20
- const EXTENDED = !!process.env.TEST_EXTENDED_MODE;
21
- const USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36';
22
-
23
- // Resolve .temp/ relative to BEM repo root (3 dirs up from test/helpers/content/)
24
- const BEM_ROOT = path.resolve(__dirname, '..', '..', '..');
25
- const TEMP_DIR = path.join(BEM_ROOT, '.temp', 'ghostii-feed', `run-${new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19)}`);
26
-
27
- // --- Real feed URLs for extended tests ---
28
- // Chosen for stability and confirmed to work with wonderful-fetch.
29
- // Includes generic tech feeds + marketing/social feeds used by OMEGA consumers.
30
- const REAL_FEEDS = [
31
- { name: 'Ars Technica', url: 'https://feeds.arstechnica.com/arstechnica/technology-lab', format: 'rss' },
32
- { name: 'TechCrunch', url: 'https://techcrunch.com/feed/', format: 'rss' },
33
- { name: 'Social Media Examiner', url: 'https://www.socialmediaexaminer.com/feed/', format: 'rss' },
34
- { name: 'Hootsuite Blog', url: 'https://blog.hootsuite.com/feed/', format: 'rss' },
35
- { name: 'Sprout Social Insights', url: 'https://sproutsocial.com/insights/feed/', format: 'rss' },
36
- { name: 'Buffer Resources', url: 'https://buffer.com/resources/feed/', format: 'rss' },
37
- { name: 'Digiday', url: 'https://digiday.com/feed/', format: 'rss' },
38
- ];
39
-
40
- /**
41
- * Save an artifact to .temp/ for post-test inspection.
42
- */
43
- function saveArtifact(filename, data) {
44
- try {
45
- const content = typeof data === 'string' ? data : JSON.stringify(data, null, 2);
46
- jetpack.write(path.join(TEMP_DIR, filename), content);
47
- } catch (e) {
48
- // Non-fatal — don't break tests over file I/O
49
- }
50
- }
51
-
52
- module.exports = {
53
- description: 'content/ghostii-feed-integration',
54
- type: 'suite',
55
- timeout: 120000,
56
-
57
- tests: [
58
- // ============================
59
- // INTEGRATION: processFeedSource pipeline with emulator
60
- // ============================
61
- {
62
- name: 'processFeedSource-selects-unprocessed-item',
63
- timeout: 15000,
64
-
65
- async run({ assert, admin, state }) {
66
- if (!admin) {
67
- return assert.ok(true, 'skipped: no emulator');
68
- }
69
-
70
- // Pre-track one item so the pipeline has to skip it
71
- const testFeedUrl = 'https://integration-test.example.com/feed.xml';
72
- await trackContentSource(admin, {
73
- url: 'https://integration-test.example.com/old-article',
74
- origin: `$feed:${testFeedUrl}`,
75
- feedUrl: testFeedUrl,
76
- itemId: 'already-tracked',
77
- itemTitle: 'Old Article',
78
- usedBy: 'blog',
79
- brandId: 'test-brand',
80
- postUrl: null,
81
- postSlug: null,
82
- });
83
-
84
- // Verify the tracked item is in the set
85
- const processed = await getProcessedItemIds(admin, testFeedUrl);
86
- assert.ok(processed.has('already-tracked'), 'pre-tracked item should be in processed set');
87
- assert.ok(!processed.has('new-item'), 'new item should NOT be in processed set');
88
-
89
- state.testFeedUrl = testFeedUrl;
90
- },
91
- },
92
-
93
- {
94
- name: 'processFeedSource-filters-tracked-from-parsed-items',
95
- timeout: 10000,
96
-
97
- async run({ assert, admin, state }) {
98
- if (!admin || !state.testFeedUrl) {
99
- return assert.ok(true, 'skipped');
100
- }
101
-
102
- // Simulate what processFeedSource does: parse → filter → select
103
- const feedItems = [
104
- { id: 'already-tracked', title: 'Old Article', url: 'https://integration-test.example.com/old-article', summary: '', content: '', publishedAt: '' },
105
- { id: 'new-item-1', title: 'New Article 1', url: 'https://integration-test.example.com/new-1', summary: 'Summary 1', content: 'Content 1', publishedAt: '2025-06-18' },
106
- { id: 'new-item-2', title: 'New Article 2', url: 'https://integration-test.example.com/new-2', summary: 'Summary 2', content: 'Content 2', publishedAt: '2025-06-17' },
107
- ];
108
-
109
- const processed = await getProcessedItemIds(admin, state.testFeedUrl);
110
- const unprocessed = feedItems.filter((item) => !processed.has(item.id) && !processed.has(item.url));
111
-
112
- assert.equal(unprocessed.length, 2, 'should have 2 unprocessed items');
113
- assert.equal(unprocessed[0].id, 'new-item-1', 'first unprocessed is newest');
114
- },
115
- },
116
-
117
- {
118
- name: 'processFeedSource-tracks-after-processing',
119
- timeout: 15000,
120
-
121
- async run({ assert, admin, state }) {
122
- if (!admin || !state.testFeedUrl) {
123
- return assert.ok(true, 'skipped');
124
- }
125
-
126
- // Track the "newly processed" item
127
- await trackContentSource(admin, {
128
- url: 'https://integration-test.example.com/new-1',
129
- origin: `$feed:${state.testFeedUrl}`,
130
- feedUrl: state.testFeedUrl,
131
- itemId: 'new-item-1',
132
- itemTitle: 'New Article 1',
133
- usedBy: 'blog',
134
- brandId: 'test-brand',
135
- postUrl: 'https://test-brand.com/blog/new-article-1',
136
- postSlug: 'new-article-1',
137
- });
138
-
139
- // Now only new-item-2 should be unprocessed
140
- const processed = await getProcessedItemIds(admin, state.testFeedUrl);
141
- assert.ok(processed.has('already-tracked'), 'original tracked item still present');
142
- assert.ok(processed.has('new-item-1'), 'newly tracked item present');
143
- assert.ok(!processed.has('new-item-2'), 'remaining item still unprocessed');
144
-
145
- // Verify the dedup count
146
- const feedItems = [
147
- { id: 'already-tracked', title: 'Old', url: 'https://integration-test.example.com/old-article' },
148
- { id: 'new-item-1', title: 'New 1', url: 'https://integration-test.example.com/new-1' },
149
- { id: 'new-item-2', title: 'New 2', url: 'https://integration-test.example.com/new-2' },
150
- ];
151
- const unprocessed = feedItems.filter((item) => !processed.has(item.id) && !processed.has(item.url));
152
- assert.equal(unprocessed.length, 1, 'only 1 item remains after second tracking');
153
- assert.equal(unprocessed[0].id, 'new-item-2', 'remaining item is new-item-2');
154
- },
155
- },
156
-
157
- // ============================
158
- // EXTENDED: Real RSS feed fetch + parse
159
- // ============================
160
- {
161
- name: 'real-rss-feed-fetches-and-parses',
162
- timeout: 30000,
163
- skip: !EXTENDED ? 'TEST_EXTENDED_MODE not set' : false,
164
-
165
- async run({ assert, state }) {
166
- const feed = REAL_FEEDS[0];
167
- assert.ok(feed, 'test feed config exists');
168
-
169
- const text = await fetch(feed.url, {
170
- timeout: 15000,
171
- tries: 2,
172
- response: 'text',
173
- headers: { 'User-Agent': USER_AGENT },
174
- });
175
-
176
- assert.ok(text, 'feed text fetched');
177
- assert.ok(text.length > 100, `feed text has content (${text.length} chars)`);
178
-
179
- const result = parseFeed(text);
180
- assert.ok(result.items.length > 0, `parsed ${result.items.length} items from ${feed.name}`);
181
-
182
- // Verify item shape
183
- const item = result.items[0];
184
- assert.ok(item.title, `first item has title: "${item.title.slice(0, 60)}..."`);
185
- assert.ok(item.url, `first item has URL: ${item.url}`);
186
- assert.ok(item.id, 'first item has id');
187
-
188
- // Save artifacts
189
- saveArtifact(`feed-${feed.name.toLowerCase().replace(/\s+/g, '-')}-raw.xml`, text);
190
- saveArtifact(`feed-${feed.name.toLowerCase().replace(/\s+/g, '-')}-parsed.json`, result.items);
191
-
192
- state.realFeedItems = result.items;
193
- state.realFeedName = feed.name;
194
- state.realFeedRawText = text;
195
- },
196
- },
197
-
198
- {
199
- name: 'real-second-feed-fetches-and-parses',
200
- timeout: 30000,
201
- skip: !EXTENDED ? 'TEST_EXTENDED_MODE not set' : false,
202
-
203
- async run({ assert }) {
204
- const feed = REAL_FEEDS[1];
205
-
206
- const text = await fetch(feed.url, {
207
- timeout: 15000,
208
- tries: 2,
209
- response: 'text',
210
- headers: { 'User-Agent': USER_AGENT },
211
- });
212
-
213
- assert.ok(text, 'feed text fetched');
214
-
215
- const result = parseFeed(text);
216
- assert.ok(result.items.length > 0, `parsed ${result.items.length} items from ${feed.name}`);
217
-
218
- const item = result.items[0];
219
- assert.ok(item.title, `first item has title: "${item.title.slice(0, 60)}..."`);
220
- assert.ok(item.url, `first item has URL: ${item.url}`);
221
-
222
- // Save artifacts
223
- saveArtifact(`feed-${feed.name.toLowerCase().replace(/\s+/g, '-')}-raw.xml`, text);
224
- saveArtifact(`feed-${feed.name.toLowerCase().replace(/\s+/g, '-')}-parsed.json`, result.items);
225
- },
226
- },
227
-
228
- // ============================
229
- // EXTENDED: Real article content extraction
230
- // ============================
231
- {
232
- name: 'real-article-content-extraction',
233
- timeout: 30000,
234
- skip: !EXTENDED ? 'TEST_EXTENDED_MODE not set' : false,
235
-
236
- async run({ assert, state }) {
237
- if (!state.realFeedItems?.length) {
238
- return assert.ok(true, 'skipped: no feed items from previous test');
239
- }
240
-
241
- // Pick the first item with a URL
242
- const item = state.realFeedItems.find((i) => i.url);
243
- assert.ok(item, 'have an item with a URL to extract');
244
-
245
- const content = await extractArticleContent(item.url);
246
-
247
- // Content extraction is best-effort — some sites block scrapers.
248
- assert.equal(typeof content, 'string', 'extractArticleContent returns a string');
249
-
250
- if (content.length > 0) {
251
- assert.ok(content.length >= 50, `extracted ${content.length} chars of article content`);
252
- assert.ok(content.length <= 1024 * 14, 'content within 14KB limit');
253
- assert.ok(!content.includes('<script'), 'no script tags in extracted content');
254
- assert.ok(!content.includes('<style'), 'no style tags in extracted content');
255
- } else {
256
- assert.ok(true, `content extraction returned empty for ${item.url} (site may block scraping)`);
257
- }
258
-
259
- // Save artifacts
260
- saveArtifact('extracted-article.json', {
261
- feedName: state.realFeedName,
262
- sourceItem: { id: item.id, title: item.title, url: item.url },
263
- extractedLength: content.length,
264
- extractedPreview: content.slice(0, 2000),
265
- });
266
- saveArtifact('extracted-article-full.txt', content);
267
-
268
- state.extractedContent = content;
269
- state.extractedItem = item;
270
- },
271
- },
272
-
273
- // ============================
274
- // EXTENDED: Full pipeline — feed → parse → track → dedup (real feed + emulator)
275
- // ============================
276
- {
277
- name: 'real-feed-pipeline-tracks-and-deduplicates',
278
- timeout: 30000,
279
- skip: !EXTENDED ? 'TEST_EXTENDED_MODE not set' : false,
280
-
281
- async run({ assert, admin, state }) {
282
- if (!admin || !state.realFeedItems?.length) {
283
- return assert.ok(true, 'skipped: no emulator or feed items');
284
- }
285
-
286
- const realFeedUrl = REAL_FEEDS[0].url;
287
- const firstItem = state.realFeedItems[0];
288
-
289
- // Run 1: track the first item
290
- await trackContentSource(admin, {
291
- url: firstItem.url || firstItem.id,
292
- origin: `$feed:${realFeedUrl}`,
293
- feedUrl: realFeedUrl,
294
- itemId: firstItem.id,
295
- itemTitle: firstItem.title,
296
- usedBy: 'blog',
297
- brandId: 'integration-test',
298
- postUrl: 'https://test.com/blog/article-1',
299
- postSlug: 'article-1',
300
- });
301
-
302
- // Run 2: verify it's now in the processed set
303
- const processed = await getProcessedItemIds(admin, realFeedUrl);
304
- assert.ok(
305
- processed.has(firstItem.id) || processed.has(firstItem.url),
306
- 'tracked real feed item is in processed set',
307
- );
308
-
309
- // Simulate selection: filter out processed items
310
- const unprocessed = state.realFeedItems.filter(
311
- (item) => !processed.has(item.id) && !processed.has(item.url),
312
- );
313
-
314
- assert.ok(
315
- unprocessed.length < state.realFeedItems.length,
316
- `dedup removed tracked item (${unprocessed.length} remain of ${state.realFeedItems.length})`,
317
- );
318
-
319
- const trackedInUnprocessed = unprocessed.find(
320
- (item) => item.id === firstItem.id || item.url === firstItem.url,
321
- );
322
- assert.ok(!trackedInUnprocessed, 'tracked item correctly excluded from unprocessed list');
323
- },
324
- },
325
-
326
- {
327
- name: 'real-feed-pipeline-hash-consistency',
328
- timeout: 5000,
329
- skip: !EXTENDED ? 'TEST_EXTENDED_MODE not set' : false,
330
-
331
- async run({ assert, admin, state }) {
332
- if (!admin || !state.realFeedItems?.length) {
333
- return assert.ok(true, 'skipped');
334
- }
335
-
336
- const realFeedUrl = REAL_FEEDS[0].url;
337
- const firstItem = state.realFeedItems[0];
338
-
339
- // Verify the doc was stored with the expected hash ID
340
- const expectedDocId = contentSourceHash(`$feed:${realFeedUrl}`, firstItem.url || firstItem.id);
341
- const doc = await admin.firestore().doc(`content-sources/${expectedDocId}`).get();
342
-
343
- assert.ok(doc.exists, 'tracking doc exists at expected hash-based ID');
344
-
345
- const data = doc.data();
346
- assert.equal(data.feedUrl, realFeedUrl, 'stored feedUrl matches');
347
- assert.equal(data.brandId, 'integration-test', 'stored brandId matches');
348
- assert.ok(data.itemTitle, 'stored itemTitle is not empty');
349
- },
350
- },
351
-
352
- // ============================
353
- // EXTENDED: Multiple feed formats work end-to-end
354
- // ============================
355
- {
356
- name: 'real-multiple-feed-formats-all-parse',
357
- timeout: 60000,
358
- skip: !EXTENDED ? 'TEST_EXTENDED_MODE not set' : false,
359
-
360
- async run({ assert }) {
361
- const results = [];
362
-
363
- for (const feed of REAL_FEEDS) {
364
- const text = await fetch(feed.url, {
365
- timeout: 15000,
366
- tries: 2,
367
- response: 'text',
368
- headers: { 'User-Agent': USER_AGENT },
369
- }).catch((e) => e);
370
-
371
- if (text instanceof Error) {
372
- results.push({ name: feed.name, format: feed.format, items: 0, error: text.message });
373
- continue;
374
- }
375
-
376
- const { items } = parseFeed(text);
377
- results.push({ name: feed.name, format: feed.format, items: items.length });
378
-
379
- // Save each feed's raw data
380
- saveArtifact(`feed-${feed.name.toLowerCase().replace(/\s+/g, '-')}-raw.xml`, text);
381
- }
382
-
383
- // At least 5 of 7 feeds should parse successfully
384
- const successful = results.filter((r) => r.items > 0);
385
- assert.ok(
386
- successful.length >= 5,
387
- `at least 5 of ${REAL_FEEDS.length} real feeds parsed successfully: ${JSON.stringify(results)}`,
388
- );
389
-
390
- // Save summary
391
- saveArtifact('summary.json', {
392
- timestamp: new Date().toISOString(),
393
- feeds: results,
394
- totalItemsParsed: results.reduce((sum, r) => sum + r.items, 0),
395
- });
396
-
397
- // Log results for visibility
398
- for (const r of results) {
399
- assert.ok(true, `${r.name} (${r.format}): ${r.items} items${r.error ? ` [ERROR: ${r.error}]` : ''}`);
400
- }
401
- },
402
- },
403
- ],
404
- };
@@ -1,243 +0,0 @@
1
- /**
2
- * Test: content/ghostii.writeArticle() pass-through
3
- * Verifies that writeArticle() correctly applies overrides and includes sourceContent.
4
- *
5
- * Run: npx mgr test helpers/content/ghostii-write-article
6
- *
7
- * These tests intercept the outgoing HTTP request to verify the API body shape
8
- * without calling the real Ghostii API. The `wonderful-fetch` call is replaced
9
- * with a spy that captures and returns the request body.
10
- */
11
- const path = require('path');
12
- const ghostiiPath = path.resolve(__dirname, '../../../src/manager/libraries/content/ghostii.js');
13
-
14
- // Capture the request body that writeArticle would send
15
- let capturedBody = null;
16
-
17
- function mockFetch(url, opts) {
18
- capturedBody = opts.body;
19
- return Promise.resolve(capturedBody);
20
- }
21
-
22
- function loadModuleWithMock() {
23
- // Clear require cache so we get a fresh module
24
- delete require.cache[ghostiiPath];
25
-
26
- // Temporarily replace wonderful-fetch in the require cache
27
- const fetchPath = require.resolve('wonderful-fetch');
28
- const originalFetch = require.cache[fetchPath];
29
- require.cache[fetchPath] = { id: fetchPath, exports: mockFetch, loaded: true };
30
-
31
- const mod = require(ghostiiPath);
32
-
33
- // Restore original
34
- if (originalFetch) {
35
- require.cache[fetchPath] = originalFetch;
36
- } else {
37
- delete require.cache[fetchPath];
38
- }
39
-
40
- return mod;
41
- }
42
-
43
- const MOCK_BRAND = {
44
- brand: { url: 'https://example.com', name: 'TestBrand', id: 'test' },
45
- github: { user: 'test-user', repo: 'test-repo' },
46
- };
47
-
48
- module.exports = {
49
- description: 'content/ghostii.writeArticle() pass-through',
50
- type: 'group',
51
-
52
- tests: [
53
- {
54
- name: 'defaults-when-no-overrides',
55
- async run({ assert }) {
56
- const { writeArticle } = loadModuleWithMock();
57
- await writeArticle({ brand: MOCK_BRAND, description: 'Test prompt', links: ['https://link.com'] });
58
-
59
- assert.ok(capturedBody, 'request body captured');
60
- assert.deepEqual(capturedBody.keywords, [], 'default keywords');
61
- assert.equal(capturedBody.length, 'long', 'default length');
62
- assert.equal(capturedBody.research, true, 'default research');
63
- assert.equal(capturedBody.insertImages, true, 'default insertImages');
64
- assert.equal(capturedBody.headerImageUrl, 'unsplash', 'default headerImageUrl');
65
- assert.equal(capturedBody.maxLinks, 6, 'default maxLinks');
66
- assert.ok(capturedBody.sectionQuantity >= 3 && capturedBody.sectionQuantity <= 6, 'default sectionQuantity in range');
67
- assert.equal(capturedBody.description, 'Test prompt', 'description passed through');
68
- assert.deepEqual(capturedBody.links, ['https://link.com'], 'links passed through');
69
- assert.equal(capturedBody.sourceContent, undefined, 'no sourceContent by default');
70
- },
71
- },
72
-
73
- {
74
- name: 'override-keywords',
75
- async run({ assert }) {
76
- const { writeArticle } = loadModuleWithMock();
77
- await writeArticle({
78
- brand: MOCK_BRAND, description: 'Test', links: [],
79
- overrides: { keywords: ['AI', 'tech'] },
80
- });
81
- assert.deepEqual(capturedBody.keywords, ['AI', 'tech']);
82
- },
83
- },
84
-
85
- {
86
- name: 'override-length',
87
- async run({ assert }) {
88
- const { writeArticle } = loadModuleWithMock();
89
- await writeArticle({
90
- brand: MOCK_BRAND, description: 'Test', links: [],
91
- overrides: { length: 'comprehensive' },
92
- });
93
- assert.equal(capturedBody.length, 'comprehensive');
94
- },
95
- },
96
-
97
- {
98
- name: 'override-research-false',
99
- async run({ assert }) {
100
- const { writeArticle } = loadModuleWithMock();
101
- await writeArticle({
102
- brand: MOCK_BRAND, description: 'Test', links: [],
103
- overrides: { research: false },
104
- });
105
- assert.equal(capturedBody.research, false);
106
- },
107
- },
108
-
109
- {
110
- name: 'override-insertImages-false',
111
- async run({ assert }) {
112
- const { writeArticle } = loadModuleWithMock();
113
- await writeArticle({
114
- brand: MOCK_BRAND, description: 'Test', links: [],
115
- overrides: { insertImages: false },
116
- });
117
- assert.equal(capturedBody.insertImages, false);
118
- },
119
- },
120
-
121
- {
122
- name: 'override-insertLinks-false',
123
- async run({ assert }) {
124
- const { writeArticle } = loadModuleWithMock();
125
- await writeArticle({
126
- brand: MOCK_BRAND, description: 'Test', links: [],
127
- overrides: { insertLinks: false },
128
- });
129
- assert.equal(capturedBody.insertLinks, false);
130
- },
131
- },
132
-
133
- {
134
- name: 'override-headerImageUrl',
135
- async run({ assert }) {
136
- const { writeArticle } = loadModuleWithMock();
137
- await writeArticle({
138
- brand: MOCK_BRAND, description: 'Test', links: [],
139
- overrides: { headerImageUrl: 'generate' },
140
- });
141
- assert.equal(capturedBody.headerImageUrl, 'generate');
142
- },
143
- },
144
-
145
- {
146
- name: 'override-maxLinks',
147
- async run({ assert }) {
148
- const { writeArticle } = loadModuleWithMock();
149
- await writeArticle({
150
- brand: MOCK_BRAND, description: 'Test', links: [],
151
- overrides: { maxLinks: 12 },
152
- });
153
- assert.equal(capturedBody.maxLinks, 12);
154
- },
155
- },
156
-
157
- {
158
- name: 'override-sectionQuantity',
159
- async run({ assert }) {
160
- const { writeArticle } = loadModuleWithMock();
161
- await writeArticle({
162
- brand: MOCK_BRAND, description: 'Test', links: [],
163
- overrides: { sectionQuantity: 8 },
164
- });
165
- assert.equal(capturedBody.sectionQuantity, 8);
166
- },
167
- },
168
-
169
- {
170
- name: 'override-feedUrl',
171
- async run({ assert }) {
172
- const { writeArticle } = loadModuleWithMock();
173
- await writeArticle({
174
- brand: MOCK_BRAND, description: 'Test', links: [],
175
- overrides: { feedUrl: 'https://myblog.com/feed.json' },
176
- });
177
- assert.equal(capturedBody.feedUrl, 'https://myblog.com/feed.json');
178
- },
179
- },
180
-
181
- {
182
- name: 'sourceContent-included-when-provided',
183
- async run({ assert }) {
184
- const { writeArticle } = loadModuleWithMock();
185
- await writeArticle({
186
- brand: MOCK_BRAND, description: 'Test', links: [],
187
- sourceContent: 'This is the source article text for rewriting.',
188
- });
189
- assert.equal(capturedBody.sourceContent, 'This is the source article text for rewriting.');
190
- },
191
- },
192
-
193
- {
194
- name: 'sourceContent-omitted-when-empty',
195
- async run({ assert }) {
196
- const { writeArticle } = loadModuleWithMock();
197
- await writeArticle({
198
- brand: MOCK_BRAND, description: 'Test', links: [],
199
- sourceContent: '',
200
- });
201
- assert.equal(capturedBody.sourceContent, undefined, 'empty sourceContent not sent');
202
- },
203
- },
204
-
205
- {
206
- name: 'sourceContent-omitted-when-absent',
207
- async run({ assert }) {
208
- const { writeArticle } = loadModuleWithMock();
209
- await writeArticle({
210
- brand: MOCK_BRAND, description: 'Test', links: [],
211
- });
212
- assert.equal(capturedBody.sourceContent, undefined, 'missing sourceContent not sent');
213
- },
214
- },
215
-
216
- {
217
- name: 'partial-overrides-only-replace-specified',
218
- async run({ assert }) {
219
- const { writeArticle } = loadModuleWithMock();
220
- await writeArticle({
221
- brand: MOCK_BRAND, description: 'Test', links: [],
222
- overrides: { length: 'short' },
223
- });
224
- assert.equal(capturedBody.length, 'short', 'length overridden');
225
- assert.equal(capturedBody.maxLinks, 6, 'maxLinks keeps default');
226
- assert.equal(capturedBody.research, true, 'research keeps default');
227
- assert.equal(capturedBody.headerImageUrl, 'unsplash', 'headerImageUrl keeps default');
228
- },
229
- },
230
-
231
- {
232
- name: 'brand-url-used-in-body',
233
- async run({ assert }) {
234
- const { writeArticle } = loadModuleWithMock();
235
- await writeArticle({
236
- brand: MOCK_BRAND, description: 'Test', links: [],
237
- });
238
- assert.equal(capturedBody.url, 'https://example.com');
239
- assert.equal(capturedBody.feedUrl, 'https://example.com/feeds/posts.json');
240
- },
241
- },
242
- ],
243
- };