backend-manager 5.0.203 → 5.1.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.
Files changed (69) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/CLAUDE.md +43 -1501
  3. package/TODO-CHARGEBLAST.md +32 -0
  4. package/TODO-email-auth.md +14 -0
  5. package/docs/admin-post-route.md +24 -0
  6. package/docs/ai-library.md +23 -0
  7. package/docs/architecture.md +31 -0
  8. package/docs/auth-hooks.md +74 -0
  9. package/docs/cli-firestore-auth.md +59 -0
  10. package/docs/cli-logs.md +67 -0
  11. package/docs/code-patterns.md +67 -0
  12. package/docs/common-operations.md +64 -0
  13. package/docs/directory-structure.md +119 -0
  14. package/docs/environment-detection.md +7 -0
  15. package/docs/file-naming.md +11 -0
  16. package/docs/marketing-campaigns.md +244 -0
  17. package/docs/marketing-fields.md +25 -0
  18. package/docs/mcp.md +95 -0
  19. package/docs/payment-system.md +325 -0
  20. package/docs/response-headers.md +7 -0
  21. package/docs/routes.md +126 -0
  22. package/docs/sanitization.md +61 -0
  23. package/docs/schemas.md +39 -0
  24. package/docs/stripe-webhook-forwarding.md +18 -0
  25. package/docs/testing.md +129 -0
  26. package/docs/usage-rate-limiting.md +67 -0
  27. package/package.json +8 -4
  28. package/src/defaults/CHANGELOG.md +15 -0
  29. package/src/defaults/CLAUDE.md +8 -4
  30. package/src/defaults/docs/README.md +17 -0
  31. package/src/defaults/test/README.md +33 -0
  32. package/src/manager/events/cron/daily/marketing-newsletter-generate.js +48 -8
  33. package/src/manager/functions/core/actions/api/admin/create-post.js +3 -27
  34. package/src/manager/helpers/utilities.js +21 -0
  35. package/src/manager/index.js +1 -1
  36. package/src/manager/libraries/ai/index.js +162 -0
  37. package/src/manager/libraries/ai/providers/anthropic.js +193 -0
  38. package/src/manager/libraries/ai/providers/claude-code.js +206 -0
  39. package/src/manager/libraries/ai/providers/openai.js +934 -0
  40. package/src/manager/libraries/disposable-domains.json +2 -0
  41. package/src/manager/libraries/email/generators/lib/filter.js +179 -0
  42. package/src/manager/libraries/email/generators/lib/image-host.js +231 -0
  43. package/src/manager/libraries/email/generators/lib/mjml-template.js +83 -0
  44. package/src/manager/libraries/email/generators/lib/structure.js +278 -0
  45. package/src/manager/libraries/email/generators/lib/svg-illustrator.js +184 -0
  46. package/src/manager/libraries/email/generators/lib/templates/classic-schema.js +63 -0
  47. package/src/manager/libraries/email/generators/lib/templates/clean.js +82 -0
  48. package/src/manager/libraries/email/generators/lib/templates/editorial-helpers.js +100 -0
  49. package/src/manager/libraries/email/generators/lib/templates/editorial.js +317 -0
  50. package/src/manager/libraries/email/generators/lib/templates/field-report-helpers.js +138 -0
  51. package/src/manager/libraries/email/generators/lib/templates/field-report.js +497 -0
  52. package/src/manager/libraries/email/generators/lib/templates/index.js +28 -0
  53. package/src/manager/libraries/email/generators/lib/templates/shared.js +534 -0
  54. package/src/manager/libraries/email/generators/newsletter.js +377 -95
  55. package/src/manager/libraries/email/marketing/index.js +5 -2
  56. package/src/manager/libraries/email/providers/beehiiv.js +7 -3
  57. package/src/manager/libraries/openai.js +13 -932
  58. package/src/manager/routes/admin/post/deduplicate-image-alts.js +52 -0
  59. package/src/manager/routes/admin/post/post.js +10 -17
  60. package/templates/_.env +4 -0
  61. package/templates/_.gitignore +1 -0
  62. package/templates/backend-manager-config.json +48 -4
  63. package/test/helpers/slugify.js +394 -0
  64. package/test/marketing/fixtures/clean.json +31 -0
  65. package/test/marketing/fixtures/editorial.json +31 -0
  66. package/test/marketing/fixtures/field-report.json +54 -0
  67. package/test/marketing/newsletter-generate.js +731 -0
  68. package/test/marketing/newsletter-templates.js +512 -0
  69. package/test/routes/admin/deduplicate-image-alts.js +190 -0
@@ -0,0 +1,512 @@
1
+ /**
2
+ * Newsletter template fixture tests.
3
+ *
4
+ * Renders each template against hand-built structures covering edge cases
5
+ * (no citations, no sponsorships, no images, missing CTA, very long subject,
6
+ * empty/partial sections, missing template-specific fields) and asserts on
7
+ * the rendered HTML so we catch layout regressions WITHOUT paying for AI runs.
8
+ *
9
+ * No AI calls, no network, no Firebase — pure shape/snapshot assertions.
10
+ *
11
+ * Each template owns its own content schema (see classic-schema.js,
12
+ * field-report.js) so the fixtures here are per-template: the "classic"
13
+ * fixture covers clean + editorial; the "field-report" fixture covers
14
+ * field-report.
15
+ */
16
+ const { renderNewsletter } = require('../../src/manager/libraries/email/generators/lib/mjml-template.js');
17
+ const { listTemplates, resolveTemplate } = require('../../src/manager/libraries/email/generators/lib/templates/index.js');
18
+
19
+ const TEST_BRAND = {
20
+ id: 'testco',
21
+ name: 'TestCo',
22
+ url: 'https://testco.example',
23
+ address: {
24
+ line1: '123 Main St',
25
+ line2: 'Suite 100',
26
+ city: 'Testville',
27
+ region: 'TS',
28
+ postalCode: '12345',
29
+ country: 'United States',
30
+ },
31
+ };
32
+
33
+ const BASE_UNIVERSALS = {
34
+ subject: 'A normal subject for a normal newsletter',
35
+ preheader: 'A short, descriptive preheader.',
36
+ signoff: 'Best,\nThe TestCo Team',
37
+ citations: [
38
+ { note: 'A factual claim that needs attribution', source: 'Industry report, April 2026' },
39
+ { note: 'Another claim with hard data', source: 'Vendor announcement, March 2026' },
40
+ ],
41
+ };
42
+
43
+ // Classic content shape — used by `clean` and `editorial`.
44
+ const CLASSIC_STRUCTURE = {
45
+ ...BASE_UNIVERSALS,
46
+ intro: 'This is an intro paragraph that sets up the rest of the newsletter.',
47
+ sections: [
48
+ {
49
+ title: 'Section one',
50
+ body: 'First section body. Identity matters because trust is the new growth lever. Teams that handle this well will spend less time cleaning up later.',
51
+ cta: { label: 'Learn more', url: 'https://testco.example/one' },
52
+ image_prompt: 'abstract illustration',
53
+ },
54
+ {
55
+ title: 'Section two',
56
+ body: 'Second section body. The practical takeaway is straightforward: keep your account hygiene tight and document your processes.',
57
+ cta: { label: 'Take action', url: 'https://testco.example/two' },
58
+ image_prompt: 'abstract illustration',
59
+ },
60
+ {
61
+ title: 'Section three',
62
+ body: 'Third section body. This one has no CTA on purpose — to verify that templates handle missing CTAs gracefully.',
63
+ cta: null,
64
+ image_prompt: 'abstract illustration',
65
+ },
66
+ ],
67
+ };
68
+
69
+ // Field Report content shape — used by `field-report`.
70
+ const FIELD_REPORT_STRUCTURE = {
71
+ ...BASE_UNIVERSALS,
72
+ signoff: '— Stay sharp,\nThe TestCo Desk',
73
+ tldr: 'Platform changes are accelerating identity friction. Operators who lock down attribution this quarter will outpace the rest.',
74
+ dateline: 'LOS ANGELES',
75
+ dispatches: [
76
+ {
77
+ kicker: 'LEAD DISPATCH',
78
+ headline: 'Identity becomes the new growth lever',
79
+ byline: 'Filed by The TestCo growth desk',
80
+ location: 'OAKLAND',
81
+ lede: 'A wave of platform changes is forcing operators to rethink how attribution holds together at scale.',
82
+ dispatch: 'Trust matters because the new growth lever is identity. Teams that handle this well will spend less time cleaning up later. The practical implication is to lock in attribution now while the toolchain still tolerates ambiguity.',
83
+ dataPoints: [
84
+ { label: 'USERS REACHED', value: '12.4K' },
85
+ { label: 'WoW GROWTH', value: '+38%' },
86
+ ],
87
+ cta: { label: 'READ THE BRIEF', url: 'https://testco.example/one' },
88
+ image_prompt: 'abstract illustration',
89
+ },
90
+ {
91
+ kicker: 'FIELD NOTES',
92
+ headline: 'Operators document their hygiene',
93
+ byline: 'Filed by The TestCo platform desk',
94
+ location: 'REMOTE',
95
+ lede: 'The accounts that survive the next platform sweep are the ones with paper trails.',
96
+ dispatch: 'Account hygiene is now a documentation problem, not a tooling problem. Save your processes. The teams already running on documented playbooks are ahead.',
97
+ dataPoints: [],
98
+ cta: { label: 'SEE THE PLAYBOOK', url: 'https://testco.example/two' },
99
+ image_prompt: 'abstract illustration',
100
+ },
101
+ {
102
+ kicker: 'WATCH',
103
+ headline: 'A third dispatch with no CTA',
104
+ byline: 'Filed by The TestCo signals desk',
105
+ location: 'NEW YORK',
106
+ lede: 'Some filings just observe — no call to action attached.',
107
+ dispatch: 'This one has no CTA on purpose, to verify the template handles missing CTAs gracefully.',
108
+ dataPoints: [{ label: 'OBSERVATIONS', value: '3' }],
109
+ cta: null,
110
+ image_prompt: 'abstract illustration',
111
+ },
112
+ ],
113
+ };
114
+
115
+ const FIXTURES = {
116
+ clean: CLASSIC_STRUCTURE,
117
+ editorial: CLASSIC_STRUCTURE,
118
+ 'field-report': FIELD_REPORT_STRUCTURE,
119
+ };
120
+
121
+ const IMAGE_PATHS = [
122
+ 'https://example.com/img1.png',
123
+ 'https://example.com/img2.png',
124
+ 'https://example.com/img3.png',
125
+ ];
126
+
127
+ const SPONSORSHIPS = [
128
+ {
129
+ label: 'From the team',
130
+ headline: 'Try TestCo',
131
+ body: 'Short pitch text for in-house promo.',
132
+ url: 'https://testco.example/promo',
133
+ ctaLabel: 'Start free',
134
+ position: 'middle',
135
+ },
136
+ ];
137
+
138
+ const TEMPLATES = ['clean', 'editorial', 'field-report'];
139
+
140
+ /**
141
+ * Render a template against its native fixture (or a fixture override).
142
+ */
143
+ async function render(templateName, structureOverrides = {}, overrides = {}) {
144
+ const baseFixture = FIXTURES[templateName] || CLASSIC_STRUCTURE;
145
+ const structure = { ...baseFixture, ...structureOverrides };
146
+ const newsletterConfig = {
147
+ template: templateName,
148
+ theme: {
149
+ primaryColor: '#0072FF',
150
+ secondaryColor: '#1E1E2A',
151
+ accentColor: '#F4F6FA',
152
+ font: 'Inter, system-ui, sans-serif',
153
+ },
154
+ sponsorships: overrides.sponsorships !== undefined ? overrides.sponsorships : [],
155
+ };
156
+
157
+ return renderNewsletter({
158
+ brand: overrides.brand || TEST_BRAND,
159
+ newsletterConfig,
160
+ structure,
161
+ imagePaths: overrides.imagePaths !== undefined ? overrides.imagePaths : IMAGE_PATHS,
162
+ campaign: 'fixture',
163
+ });
164
+ }
165
+
166
+ module.exports = {
167
+ description: 'Newsletter template fixture suite',
168
+ type: 'suite',
169
+ auth: 'none',
170
+ timeout: 30000,
171
+ tests: [
172
+ {
173
+ name: 'every registered template renders without throwing',
174
+ async run({ assert }) {
175
+ for (const templateName of TEMPLATES) {
176
+ const t = resolveTemplate(templateName);
177
+ assert.ok(t, `Template "${templateName}" should resolve`);
178
+ assert.ok(typeof t.build === 'function', `Template "${templateName}" should expose build()`);
179
+ assert.ok(t.meta && t.meta.name, `Template "${templateName}" should expose meta.name`);
180
+ }
181
+
182
+ // Render the full fixture against every template
183
+ for (const templateName of TEMPLATES) {
184
+ const result = await render(templateName);
185
+ assert.ok(result.html.includes('<html'), `${templateName}: produces HTML`);
186
+ assert.equal(result.template, templateName, `${templateName}: reports correct template name`);
187
+ assert.equal(result.errors.length, 0, `${templateName}: no MJML errors`);
188
+ }
189
+ },
190
+ },
191
+ {
192
+ name: 'shell always renders the CAN-SPAM address in the footer',
193
+ async run({ assert }) {
194
+ for (const templateName of TEMPLATES) {
195
+ const result = await render(templateName);
196
+ assert.ok(
197
+ result.html.includes('123 Main St, Suite 100, Testville, TS 12345, United States'),
198
+ `${templateName}: renders the structured brand.address in the footer`
199
+ );
200
+ }
201
+ },
202
+ },
203
+ {
204
+ // Unsubscribe links are NOT rendered by BEM — both Beehiiv and SendGrid
205
+ // auto-append a CAN-SPAM-compliant unsubscribe footer to every email they
206
+ // send (with a working URL tied to the subscriber). Rendering our own
207
+ // ${brandUrl}/unsubscribe would create a dead second link.
208
+ name: 'footer renders brand link but NOT a hand-rolled unsubscribe link',
209
+ async run({ assert }) {
210
+ for (const templateName of TEMPLATES) {
211
+ const result = await render(templateName);
212
+ assert.ok(result.html.includes('TestCo'), `${templateName}: brand name renders`);
213
+ assert.ok(result.html.includes('testco.example'), `${templateName}: brand URL renders`);
214
+ assert.ok(!result.html.toLowerCase().includes('unsubscribe'),
215
+ `${templateName}: should NOT include an "unsubscribe" link (sending platform appends its own)`);
216
+ assert.ok(!result.html.includes('/unsubscribe'),
217
+ `${templateName}: should NOT include a /unsubscribe URL`);
218
+ }
219
+ },
220
+ },
221
+ {
222
+ name: 'citations render when present, omit cleanly when missing',
223
+ async run({ assert }) {
224
+ for (const templateName of TEMPLATES) {
225
+ // With citations
226
+ const withCites = await render(templateName);
227
+ assert.ok(withCites.html.toLowerCase().includes('sources'), `${templateName}: cites are rendered`);
228
+ assert.ok(withCites.html.includes('[1]'), `${templateName}: citation marker [1] is rendered`);
229
+ assert.ok(withCites.html.includes('Industry report, April 2026'), `${templateName}: citation source is rendered`);
230
+
231
+ // Without citations — shell must NOT render the "Sources & data" header
232
+ const noCites = await render(templateName, { citations: [] });
233
+ assert.ok(
234
+ !noCites.html.toLowerCase().includes('sources &amp; data')
235
+ && !noCites.html.toLowerCase().includes('sources & data'),
236
+ `${templateName}: skips Sources section when citations is empty`
237
+ );
238
+ }
239
+ },
240
+ },
241
+ {
242
+ name: 'sponsorships render when present, omit cleanly when missing',
243
+ async run({ assert }) {
244
+ for (const templateName of TEMPLATES) {
245
+ const withSponsors = await render(templateName, {}, { sponsorships: SPONSORSHIPS });
246
+ assert.ok(withSponsors.html.includes('Try TestCo'), `${templateName}: sponsor headline renders`);
247
+ assert.ok(withSponsors.html.includes('Start free'), `${templateName}: sponsor CTA renders`);
248
+ assert.ok(withSponsors.html.includes('testco.example/promo'), `${templateName}: sponsor URL renders`);
249
+
250
+ // No sponsorships — should NOT find the in-house promo content
251
+ const noSponsors = await render(templateName, {}, { sponsorships: [] });
252
+ assert.ok(!noSponsors.html.includes('Try TestCo'), `${templateName}: omits sponsor content when none configured`);
253
+ }
254
+ },
255
+ },
256
+ {
257
+ name: 'CTAs render only when both label+url present',
258
+ async run({ assert }) {
259
+ // Classic templates use section CTAs; Field Report uses dispatch CTAs.
260
+ // Either way the fixture has 2 CTAs in items 1-2 and null in item 3.
261
+ for (const templateName of ['clean', 'editorial']) {
262
+ const result = await render(templateName);
263
+ assert.ok(result.html.includes('Learn more'), `${templateName}: section 1 CTA renders`);
264
+ assert.ok(result.html.includes('Take action'), `${templateName}: section 2 CTA renders`);
265
+ }
266
+ const fr = await render('field-report');
267
+ assert.ok(fr.html.includes('READ THE BRIEF'), `field-report: dispatch 1 CTA renders`);
268
+ assert.ok(fr.html.includes('SEE THE PLAYBOOK'), `field-report: dispatch 2 CTA renders`);
269
+ },
270
+ },
271
+ {
272
+ name: 'signoff renders without dramatic dark-block treatment',
273
+ async run({ assert }) {
274
+ // Classic templates carry "Best,\nThe TestCo Team"; Field Report carries "— Stay sharp,\nThe TestCo Desk"
275
+ for (const templateName of ['clean', 'editorial']) {
276
+ const result = await render(templateName);
277
+ assert.ok(result.html.includes('Best,'), `${templateName}: signoff first line`);
278
+ assert.ok(result.html.includes('The TestCo Team'), `${templateName}: signoff second line`);
279
+ assert.ok(!result.html.includes('— Signed —'), `${templateName}: no "— Signed —" eyebrow`);
280
+ assert.ok(!result.html.includes('SIGNED'), `${templateName}: no SIGNED label`);
281
+ }
282
+ const fr = await render('field-report');
283
+ assert.ok(fr.html.includes('Stay sharp'), `field-report: correspondent signoff first line`);
284
+ assert.ok(fr.html.includes('The TestCo Desk'), `field-report: correspondent signoff second line`);
285
+ },
286
+ },
287
+ {
288
+ name: 'images render when imagePaths provided, omit cleanly when missing',
289
+ async run({ assert }) {
290
+ for (const templateName of TEMPLATES) {
291
+ const withImages = await render(templateName);
292
+ assert.ok(withImages.html.includes('https://example.com/img1.png'), `${templateName}: img1 renders`);
293
+ assert.ok(withImages.html.includes('https://example.com/img2.png'), `${templateName}: img2 renders`);
294
+
295
+ // No images — the HTML should not contain those URLs but must still render
296
+ const noImages = await render(templateName, {}, { imagePaths: [] });
297
+ assert.ok(noImages.html.includes('<html'), `${templateName}: still renders HTML with no images`);
298
+ assert.ok(!noImages.html.includes('example.com/img1.png'), `${templateName}: no image URL when imagePaths empty`);
299
+ }
300
+ },
301
+ },
302
+ {
303
+ name: 'mj-button containers always have padding 0 horizontal (no 25px default leak)',
304
+ async run({ assert }) {
305
+ for (const templateName of TEMPLATES) {
306
+ const result = await render(templateName);
307
+ // mj-button compiles to a nested table whose container <td> sits
308
+ // immediately before a `<table ... border-collapse:separate ...>` —
309
+ // that's the only place a horizontal padding leak would visually push
310
+ // the button off-axis.
311
+ const buttonContainerRe = /<td\s[^>]*?style="([^"]*?padding:[^";]+;[^"]*?)"[^>]*?>\s*<table[^>]*?border-collapse:separate/g;
312
+ let m;
313
+ const offenders = [];
314
+ while ((m = buttonContainerRe.exec(result.html)) !== null) {
315
+ if (m[1].includes('padding:10px 25px')) {
316
+ offenders.push(m[0].slice(0, 200));
317
+ }
318
+ }
319
+ assert.equal(offenders.length, 0,
320
+ `${templateName}: button-container TDs must not carry MJML's default 10px/25px padding (found ${offenders.length} offenders: ${offenders.slice(0, 2).join(' ; ')})`
321
+ );
322
+ }
323
+ },
324
+ },
325
+ {
326
+ name: 'long subject does not blow up the template',
327
+ async run({ assert }) {
328
+ const longSubject = 'A very long subject line that exceeds normal length expectations and should be rendered without breaking the layout, even when it spans multiple visual lines';
329
+ for (const templateName of TEMPLATES) {
330
+ const result = await render(templateName, { subject: longSubject });
331
+ assert.equal(result.errors.length, 0, `${templateName}: long subject produces no MJML errors`);
332
+ assert.ok(result.html.includes('A very long subject'), `${templateName}: long subject is rendered`);
333
+ }
334
+ },
335
+ },
336
+ {
337
+ name: 'minimum-viable structure renders cleanly (classic templates)',
338
+ async run({ assert }) {
339
+ const minimal = {
340
+ ...CLASSIC_STRUCTURE,
341
+ sections: [
342
+ { title: 'Only section', body: 'A very short body.', cta: null, image_prompt: '' },
343
+ ],
344
+ citations: [],
345
+ };
346
+
347
+ for (const templateName of ['clean', 'editorial']) {
348
+ const result = await render(templateName, minimal, { sponsorships: [], imagePaths: [] });
349
+ assert.equal(result.errors.length, 0, `${templateName}: minimal structure has no MJML errors`);
350
+ assert.ok(result.html.includes('Only section'), `${templateName}: renders the single section title`);
351
+ assert.ok(result.html.includes('A very short body'), `${templateName}: renders the single section body`);
352
+ }
353
+ },
354
+ },
355
+ {
356
+ name: 'minimum-viable structure renders cleanly (field-report)',
357
+ async run({ assert }) {
358
+ const minimal = {
359
+ ...FIELD_REPORT_STRUCTURE,
360
+ tldr: 'A terse one-line briefing.',
361
+ dispatches: [
362
+ {
363
+ kicker: 'BRIEF',
364
+ headline: 'Only dispatch',
365
+ byline: 'Filed by The TestCo desk',
366
+ location: 'REMOTE',
367
+ lede: 'One paragraph.',
368
+ dispatch: 'A very short dispatch body.',
369
+ dataPoints: [],
370
+ cta: null,
371
+ image_prompt: '',
372
+ },
373
+ ],
374
+ citations: [],
375
+ };
376
+
377
+ const result = await render('field-report', minimal, { sponsorships: [], imagePaths: [] });
378
+ assert.equal(result.errors.length, 0, `field-report: minimal structure has no MJML errors`);
379
+ assert.ok(result.html.includes('Only dispatch'), `field-report: renders single headline`);
380
+ assert.ok(result.html.includes('A very short dispatch'), `field-report: renders single dispatch body`);
381
+ assert.ok(result.html.includes('A terse one-line briefing'), `field-report: renders TLDR`);
382
+ },
383
+ },
384
+ {
385
+ name: 'gracefully omits missing optional fields without breaking the template',
386
+ async run({ assert }) {
387
+ // Classic templates — missing intro, missing one section body, missing all CTAs.
388
+ for (const templateName of ['clean', 'editorial']) {
389
+ const partial = {
390
+ ...CLASSIC_STRUCTURE,
391
+ intro: '',
392
+ sections: [
393
+ { title: 'Has body', body: 'Body text here.', cta: null, image_prompt: '' },
394
+ { title: 'No body', body: '', cta: null, image_prompt: '' },
395
+ { title: 'Has CTA', body: 'Body.', cta: { label: 'Go', url: 'https://testco.example/go' }, image_prompt: '' },
396
+ ],
397
+ };
398
+ const result = await render(templateName, partial);
399
+ assert.equal(result.errors.length, 0, `${templateName}: partial sections produce no MJML errors`);
400
+ assert.ok(result.html.includes('Has body'), `${templateName}: section with body renders`);
401
+ assert.ok(result.html.includes('No body'), `${templateName}: section with empty body renders title`);
402
+ assert.ok(result.html.includes('Go'), `${templateName}: third-section CTA still renders`);
403
+ }
404
+
405
+ // Field Report — missing tldr, missing one dispatch body+lede, missing dataPoints + CTAs.
406
+ const fr = await render('field-report', {
407
+ tldr: '',
408
+ dispatches: [
409
+ {
410
+ kicker: 'DISPATCH', headline: 'Only headline + body', byline: 'Filed by desk',
411
+ location: 'REMOTE', lede: '', dispatch: 'Some body text.', dataPoints: [], cta: null, image_prompt: '',
412
+ },
413
+ {
414
+ kicker: 'WATCH', headline: 'Just data, no body', byline: 'Filed by desk',
415
+ location: 'REMOTE', lede: '', dispatch: '', dataPoints: [{ label: 'STAT', value: '99%' }], cta: null, image_prompt: '',
416
+ },
417
+ ],
418
+ });
419
+ assert.equal(fr.errors.length, 0, `field-report: partial dispatches produce no MJML errors`);
420
+ assert.ok(fr.html.includes('Only headline + body'), `field-report: dispatch with body renders headline`);
421
+ assert.ok(fr.html.includes('Just data, no body'), `field-report: dispatch with only dataPoints still renders headline`);
422
+ assert.ok(fr.html.includes('99%'), `field-report: dataPoints render as fallback when no body`);
423
+ assert.ok(!fr.html.includes('// THIS ISSUE //'), `field-report: TLDR block hidden when tldr is empty`);
424
+ },
425
+ },
426
+ {
427
+ name: 'completely empty section/dispatch is dropped, not rendered as a hollow stub',
428
+ async run({ assert }) {
429
+ // Classic templates: empty section between two real ones should be dropped.
430
+ for (const templateName of ['clean', 'editorial']) {
431
+ const result = await render(templateName, {
432
+ sections: [
433
+ { title: 'Real one', body: 'Real body.', cta: null, image_prompt: '' },
434
+ { title: '', body: '', cta: null, image_prompt: '' }, // empty
435
+ { title: 'Real two', body: 'Real body 2.', cta: null, image_prompt: '' },
436
+ ],
437
+ });
438
+ assert.equal(result.errors.length, 0, `${templateName}: empty middle section produces no MJML errors`);
439
+ assert.ok(result.html.includes('Real one'), `${templateName}: first section still renders`);
440
+ assert.ok(result.html.includes('Real two'), `${templateName}: third section still renders`);
441
+ }
442
+
443
+ // Field Report: empty dispatch dropped.
444
+ const fr = await render('field-report', {
445
+ dispatches: [
446
+ { kicker: 'DISPATCH', headline: 'Real dispatch', byline: 'X', location: 'REMOTE',
447
+ lede: 'Real lede.', dispatch: 'Real body.', dataPoints: [], cta: null, image_prompt: '' },
448
+ { kicker: '', headline: '', byline: '', location: '', lede: '', dispatch: '',
449
+ dataPoints: [], cta: null, image_prompt: '' },
450
+ { kicker: 'WATCH', headline: 'Other dispatch', byline: 'Y', location: 'REMOTE',
451
+ lede: 'Other lede.', dispatch: 'Other body.', dataPoints: [], cta: null, image_prompt: '' },
452
+ ],
453
+ });
454
+ assert.equal(fr.errors.length, 0, `field-report: empty middle dispatch produces no MJML errors`);
455
+ assert.ok(fr.html.includes('Real dispatch'), `field-report: first dispatch renders`);
456
+ assert.ok(fr.html.includes('Other dispatch'), `field-report: third dispatch renders`);
457
+ },
458
+ },
459
+ {
460
+ name: 'field-report renders its identity markers (kicker, dateline, terminal block, terminator)',
461
+ async run({ assert }) {
462
+ const result = await render('field-report');
463
+ assert.ok(result.html.includes('LEAD DISPATCH'), `field-report: kicker renders`);
464
+ assert.ok(result.html.includes('FIELD NOTES'), `field-report: second kicker renders`);
465
+ assert.ok(result.html.includes('// THIS ISSUE //'), `field-report: TLDR terminal label renders`);
466
+ assert.ok(result.html.includes('// BY THE NUMBERS //'), `field-report: dataPoint terminal label renders (full-width strip)`);
467
+ assert.ok(result.html.includes('END DISPATCH'), `field-report: dispatch terminator renders`);
468
+ assert.ok(result.html.includes('OAKLAND'), `field-report: dispatch location renders`);
469
+ assert.ok(result.html.includes('VOL. '), `field-report: issue volume strap renders`);
470
+ // Body's first paragraph drop-cap rule should be present in CSS
471
+ assert.ok(result.html.includes('dispatch-body'), `field-report: dispatch body class is present`);
472
+ },
473
+ },
474
+ {
475
+ name: 'template metadata is well-formed for every registered template',
476
+ async run({ assert }) {
477
+ const all = listTemplates();
478
+ assert.ok(all.length >= 3, 'has at least 3 templates registered');
479
+
480
+ for (const meta of all) {
481
+ assert.ok(meta.name, `meta.name is set`);
482
+ assert.ok(meta.description, `meta.description is set for ${meta.name}`);
483
+ assert.ok(Array.isArray(meta.requires), `meta.requires is array for ${meta.name}`);
484
+ assert.ok(Array.isArray(meta.optional), `meta.optional is array for ${meta.name}`);
485
+ assert.ok(meta.supports, `meta.supports is set for ${meta.name}`);
486
+ }
487
+ },
488
+ },
489
+ {
490
+ name: 'template-owned schemas are exported and merged correctly',
491
+ async run({ assert }) {
492
+ for (const templateName of TEMPLATES) {
493
+ const t = resolveTemplate(templateName);
494
+ assert.ok(t.schema, `${templateName}: exports a schema`);
495
+ assert.ok(t.schema.required, `${templateName}: schema has required[]`);
496
+ assert.ok(t.schema.properties, `${templateName}: schema has properties{}`);
497
+ }
498
+
499
+ // Field Report's schema must declare dispatches; classic templates must declare sections.
500
+ assert.ok(resolveTemplate('field-report').schema.properties.dispatches, 'field-report: has dispatches in schema');
501
+ assert.ok(resolveTemplate('clean').schema.properties.sections, 'clean: has sections in schema');
502
+ assert.ok(resolveTemplate('editorial').schema.properties.sections, 'editorial: has sections in schema');
503
+ },
504
+ },
505
+ ],
506
+ };
507
+
508
+ // Exported for adhoc inspection (not used by the runner)
509
+ module.exports.CLASSIC_STRUCTURE = CLASSIC_STRUCTURE;
510
+ module.exports.FIELD_REPORT_STRUCTURE = FIELD_REPORT_STRUCTURE;
511
+ module.exports.IMAGE_PATHS = IMAGE_PATHS;
512
+ module.exports.SPONSORSHIPS = SPONSORSHIPS;