backend-manager 5.7.6 → 5.8.0

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.
@@ -0,0 +1,399 @@
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/ghostii-auto-publisher.js');
17
+ const { parseFeed, extractArticleContent } = require('../../../src/manager/libraries/content/feed-parser.js');
18
+ const { feedItemHash, getProcessedItemIds, trackFeedItem } = 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
+ const REAL_FEEDS = [
30
+ {
31
+ name: 'Ars Technica',
32
+ url: 'https://feeds.arstechnica.com/arstechnica/technology-lab',
33
+ format: 'rss',
34
+ },
35
+ {
36
+ name: 'TechCrunch',
37
+ url: 'https://techcrunch.com/feed/',
38
+ format: 'rss',
39
+ },
40
+ {
41
+ name: 'Politico',
42
+ url: 'https://rss.politico.com/politics-news.xml',
43
+ format: 'rss',
44
+ },
45
+ ];
46
+
47
+ /**
48
+ * Save an artifact to .temp/ for post-test inspection.
49
+ */
50
+ function saveArtifact(filename, data) {
51
+ try {
52
+ const content = typeof data === 'string' ? data : JSON.stringify(data, null, 2);
53
+ jetpack.write(path.join(TEMP_DIR, filename), content);
54
+ } catch (e) {
55
+ // Non-fatal — don't break tests over file I/O
56
+ }
57
+ }
58
+
59
+ module.exports = {
60
+ description: 'content/ghostii-feed-integration',
61
+ type: 'suite',
62
+ timeout: 120000,
63
+
64
+ tests: [
65
+ // ============================
66
+ // INTEGRATION: processFeedSource pipeline with emulator
67
+ // ============================
68
+ {
69
+ name: 'processFeedSource-selects-unprocessed-item',
70
+ timeout: 15000,
71
+
72
+ async run({ assert, admin, state }) {
73
+ if (!admin) {
74
+ return assert.ok(true, 'skipped: no emulator');
75
+ }
76
+
77
+ // Pre-track one item so the pipeline has to skip it
78
+ const testFeedUrl = 'https://integration-test.example.com/feed.xml';
79
+ await trackFeedItem(admin, {
80
+ feedUrl: testFeedUrl,
81
+ item: { id: 'already-tracked', url: 'https://integration-test.example.com/old-article', title: 'Old Article' },
82
+ brandId: 'test-brand',
83
+ postUrl: null,
84
+ postSlug: null,
85
+ });
86
+
87
+ // Verify the tracked item is in the set
88
+ const processed = await getProcessedItemIds(admin, testFeedUrl);
89
+ assert.ok(processed.has('already-tracked'), 'pre-tracked item should be in processed set');
90
+ assert.ok(!processed.has('new-item'), 'new item should NOT be in processed set');
91
+
92
+ state.testFeedUrl = testFeedUrl;
93
+ },
94
+ },
95
+
96
+ {
97
+ name: 'processFeedSource-filters-tracked-from-parsed-items',
98
+ timeout: 10000,
99
+
100
+ async run({ assert, admin, state }) {
101
+ if (!admin || !state.testFeedUrl) {
102
+ return assert.ok(true, 'skipped');
103
+ }
104
+
105
+ // Simulate what processFeedSource does: parse → filter → select
106
+ const feedItems = [
107
+ { id: 'already-tracked', title: 'Old Article', url: 'https://integration-test.example.com/old-article', summary: '', content: '', publishedAt: '' },
108
+ { 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' },
109
+ { 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' },
110
+ ];
111
+
112
+ const processed = await getProcessedItemIds(admin, state.testFeedUrl);
113
+ const unprocessed = feedItems.filter((item) => !processed.has(item.id) && !processed.has(item.url));
114
+
115
+ assert.equal(unprocessed.length, 2, 'should have 2 unprocessed items');
116
+ assert.equal(unprocessed[0].id, 'new-item-1', 'first unprocessed is newest');
117
+ },
118
+ },
119
+
120
+ {
121
+ name: 'processFeedSource-tracks-after-processing',
122
+ timeout: 15000,
123
+
124
+ async run({ assert, admin, state }) {
125
+ if (!admin || !state.testFeedUrl) {
126
+ return assert.ok(true, 'skipped');
127
+ }
128
+
129
+ // Track the "newly processed" item
130
+ await trackFeedItem(admin, {
131
+ feedUrl: state.testFeedUrl,
132
+ item: { id: 'new-item-1', url: 'https://integration-test.example.com/new-1', title: 'New Article 1' },
133
+ brandId: 'test-brand',
134
+ postUrl: 'https://test-brand.com/blog/new-article-1',
135
+ postSlug: 'new-article-1',
136
+ });
137
+
138
+ // Now only new-item-2 should be unprocessed
139
+ const processed = await getProcessedItemIds(admin, state.testFeedUrl);
140
+ assert.ok(processed.has('already-tracked'), 'original tracked item still present');
141
+ assert.ok(processed.has('new-item-1'), 'newly tracked item present');
142
+ assert.ok(!processed.has('new-item-2'), 'remaining item still unprocessed');
143
+
144
+ // Verify the dedup count
145
+ const feedItems = [
146
+ { id: 'already-tracked', title: 'Old', url: 'https://integration-test.example.com/old-article' },
147
+ { id: 'new-item-1', title: 'New 1', url: 'https://integration-test.example.com/new-1' },
148
+ { id: 'new-item-2', title: 'New 2', url: 'https://integration-test.example.com/new-2' },
149
+ ];
150
+ const unprocessed = feedItems.filter((item) => !processed.has(item.id) && !processed.has(item.url));
151
+ assert.equal(unprocessed.length, 1, 'only 1 item remains after second tracking');
152
+ assert.equal(unprocessed[0].id, 'new-item-2', 'remaining item is new-item-2');
153
+ },
154
+ },
155
+
156
+ // ============================
157
+ // EXTENDED: Real RSS feed fetch + parse
158
+ // ============================
159
+ {
160
+ name: 'real-rss-feed-fetches-and-parses',
161
+ timeout: 30000,
162
+ skip: !EXTENDED ? 'TEST_EXTENDED_MODE not set' : false,
163
+
164
+ async run({ assert, state }) {
165
+ const feed = REAL_FEEDS[0];
166
+ assert.ok(feed, 'test feed config exists');
167
+
168
+ const text = await fetch(feed.url, {
169
+ timeout: 15000,
170
+ tries: 2,
171
+ response: 'text',
172
+ headers: { 'User-Agent': USER_AGENT },
173
+ });
174
+
175
+ assert.ok(text, 'feed text fetched');
176
+ assert.ok(text.length > 100, `feed text has content (${text.length} chars)`);
177
+
178
+ const result = parseFeed(text);
179
+ assert.ok(result.items.length > 0, `parsed ${result.items.length} items from ${feed.name}`);
180
+
181
+ // Verify item shape
182
+ const item = result.items[0];
183
+ assert.ok(item.title, `first item has title: "${item.title.slice(0, 60)}..."`);
184
+ assert.ok(item.url, `first item has URL: ${item.url}`);
185
+ assert.ok(item.id, 'first item has id');
186
+
187
+ // Save artifacts
188
+ saveArtifact(`feed-${feed.name.toLowerCase().replace(/\s+/g, '-')}-raw.xml`, text);
189
+ saveArtifact(`feed-${feed.name.toLowerCase().replace(/\s+/g, '-')}-parsed.json`, result.items);
190
+
191
+ state.realFeedItems = result.items;
192
+ state.realFeedName = feed.name;
193
+ state.realFeedRawText = text;
194
+ },
195
+ },
196
+
197
+ {
198
+ name: 'real-second-feed-fetches-and-parses',
199
+ timeout: 30000,
200
+ skip: !EXTENDED ? 'TEST_EXTENDED_MODE not set' : false,
201
+
202
+ async run({ assert }) {
203
+ const feed = REAL_FEEDS[1];
204
+
205
+ const text = await fetch(feed.url, {
206
+ timeout: 15000,
207
+ tries: 2,
208
+ response: 'text',
209
+ headers: { 'User-Agent': USER_AGENT },
210
+ });
211
+
212
+ assert.ok(text, 'feed text fetched');
213
+
214
+ const result = parseFeed(text);
215
+ assert.ok(result.items.length > 0, `parsed ${result.items.length} items from ${feed.name}`);
216
+
217
+ const item = result.items[0];
218
+ assert.ok(item.title, `first item has title: "${item.title.slice(0, 60)}..."`);
219
+ assert.ok(item.url, `first item has URL: ${item.url}`);
220
+
221
+ // Save artifacts
222
+ saveArtifact(`feed-${feed.name.toLowerCase().replace(/\s+/g, '-')}-raw.xml`, text);
223
+ saveArtifact(`feed-${feed.name.toLowerCase().replace(/\s+/g, '-')}-parsed.json`, result.items);
224
+ },
225
+ },
226
+
227
+ // ============================
228
+ // EXTENDED: Real article content extraction
229
+ // ============================
230
+ {
231
+ name: 'real-article-content-extraction',
232
+ timeout: 30000,
233
+ skip: !EXTENDED ? 'TEST_EXTENDED_MODE not set' : false,
234
+
235
+ async run({ assert, state }) {
236
+ if (!state.realFeedItems?.length) {
237
+ return assert.ok(true, 'skipped: no feed items from previous test');
238
+ }
239
+
240
+ // Pick the first item with a URL
241
+ const item = state.realFeedItems.find((i) => i.url);
242
+ assert.ok(item, 'have an item with a URL to extract');
243
+
244
+ const content = await extractArticleContent(item.url);
245
+
246
+ // Content extraction is best-effort — some sites block scrapers.
247
+ assert.equal(typeof content, 'string', 'extractArticleContent returns a string');
248
+
249
+ if (content.length > 0) {
250
+ assert.ok(content.length >= 50, `extracted ${content.length} chars of article content`);
251
+ assert.ok(content.length <= 1024 * 14, 'content within 14KB limit');
252
+ assert.ok(!content.includes('<script'), 'no script tags in extracted content');
253
+ assert.ok(!content.includes('<style'), 'no style tags in extracted content');
254
+ } else {
255
+ assert.ok(true, `content extraction returned empty for ${item.url} (site may block scraping)`);
256
+ }
257
+
258
+ // Save artifacts
259
+ saveArtifact('extracted-article.json', {
260
+ feedName: state.realFeedName,
261
+ sourceItem: { id: item.id, title: item.title, url: item.url },
262
+ extractedLength: content.length,
263
+ extractedPreview: content.slice(0, 2000),
264
+ });
265
+ saveArtifact('extracted-article-full.txt', content);
266
+
267
+ state.extractedContent = content;
268
+ state.extractedItem = item;
269
+ },
270
+ },
271
+
272
+ // ============================
273
+ // EXTENDED: Full pipeline — feed → parse → track → dedup (real feed + emulator)
274
+ // ============================
275
+ {
276
+ name: 'real-feed-pipeline-tracks-and-deduplicates',
277
+ timeout: 30000,
278
+ skip: !EXTENDED ? 'TEST_EXTENDED_MODE not set' : false,
279
+
280
+ async run({ assert, admin, state }) {
281
+ if (!admin || !state.realFeedItems?.length) {
282
+ return assert.ok(true, 'skipped: no emulator or feed items');
283
+ }
284
+
285
+ const realFeedUrl = REAL_FEEDS[0].url;
286
+ const firstItem = state.realFeedItems[0];
287
+
288
+ // Run 1: track the first item
289
+ await trackFeedItem(admin, {
290
+ feedUrl: realFeedUrl,
291
+ item: firstItem,
292
+ brandId: 'integration-test',
293
+ postUrl: 'https://test.com/blog/article-1',
294
+ postSlug: 'article-1',
295
+ });
296
+
297
+ // Run 2: verify it's now in the processed set
298
+ const processed = await getProcessedItemIds(admin, realFeedUrl);
299
+ assert.ok(
300
+ processed.has(firstItem.id) || processed.has(firstItem.url),
301
+ 'tracked real feed item is in processed set',
302
+ );
303
+
304
+ // Simulate selection: filter out processed items
305
+ const unprocessed = state.realFeedItems.filter(
306
+ (item) => !processed.has(item.id) && !processed.has(item.url),
307
+ );
308
+
309
+ assert.ok(
310
+ unprocessed.length < state.realFeedItems.length,
311
+ `dedup removed tracked item (${unprocessed.length} remain of ${state.realFeedItems.length})`,
312
+ );
313
+
314
+ const trackedInUnprocessed = unprocessed.find(
315
+ (item) => item.id === firstItem.id || item.url === firstItem.url,
316
+ );
317
+ assert.ok(!trackedInUnprocessed, 'tracked item correctly excluded from unprocessed list');
318
+ },
319
+ },
320
+
321
+ {
322
+ name: 'real-feed-pipeline-hash-consistency',
323
+ timeout: 5000,
324
+ skip: !EXTENDED ? 'TEST_EXTENDED_MODE not set' : false,
325
+
326
+ async run({ assert, admin, state }) {
327
+ if (!admin || !state.realFeedItems?.length) {
328
+ return assert.ok(true, 'skipped');
329
+ }
330
+
331
+ const realFeedUrl = REAL_FEEDS[0].url;
332
+ const firstItem = state.realFeedItems[0];
333
+
334
+ // Verify the doc was stored with the expected hash ID
335
+ const expectedDocId = feedItemHash(realFeedUrl, firstItem.id || firstItem.url);
336
+ const doc = await admin.firestore().doc(`ghostii-feed-items/${expectedDocId}`).get();
337
+
338
+ assert.ok(doc.exists, 'tracking doc exists at expected hash-based ID');
339
+
340
+ const data = doc.data();
341
+ assert.equal(data.feedUrl, realFeedUrl, 'stored feedUrl matches');
342
+ assert.equal(data.brandId, 'integration-test', 'stored brandId matches');
343
+ assert.ok(data.itemTitle, 'stored itemTitle is not empty');
344
+ },
345
+ },
346
+
347
+ // ============================
348
+ // EXTENDED: Multiple feed formats work end-to-end
349
+ // ============================
350
+ {
351
+ name: 'real-multiple-feed-formats-all-parse',
352
+ timeout: 60000,
353
+ skip: !EXTENDED ? 'TEST_EXTENDED_MODE not set' : false,
354
+
355
+ async run({ assert }) {
356
+ const results = [];
357
+
358
+ for (const feed of REAL_FEEDS) {
359
+ const text = await fetch(feed.url, {
360
+ timeout: 15000,
361
+ tries: 2,
362
+ response: 'text',
363
+ headers: { 'User-Agent': USER_AGENT },
364
+ }).catch((e) => e);
365
+
366
+ if (text instanceof Error) {
367
+ results.push({ name: feed.name, format: feed.format, items: 0, error: text.message });
368
+ continue;
369
+ }
370
+
371
+ const { items } = parseFeed(text);
372
+ results.push({ name: feed.name, format: feed.format, items: items.length });
373
+
374
+ // Save each feed's raw data
375
+ saveArtifact(`feed-${feed.name.toLowerCase().replace(/\s+/g, '-')}-raw.xml`, text);
376
+ }
377
+
378
+ // At least 2 of 3 feeds should parse successfully
379
+ const successful = results.filter((r) => r.items > 0);
380
+ assert.ok(
381
+ successful.length >= 2,
382
+ `at least 2 of ${REAL_FEEDS.length} real feeds parsed successfully: ${JSON.stringify(results)}`,
383
+ );
384
+
385
+ // Save summary
386
+ saveArtifact('summary.json', {
387
+ timestamp: new Date().toISOString(),
388
+ feeds: results,
389
+ totalItemsParsed: results.reduce((sum, r) => sum + r.items, 0),
390
+ });
391
+
392
+ // Log results for visibility
393
+ for (const r of results) {
394
+ assert.ok(true, `${r.name} (${r.format}): ${r.items} items${r.error ? ` [ERROR: ${r.error}]` : ''}`);
395
+ }
396
+ },
397
+ },
398
+ ],
399
+ };
@@ -0,0 +1,243 @@
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
+ };