Repository navigation
Expand file tree
/
Copy pathcheck-library-content.test.ts
More file actions
491 lines (456 loc) · 19.8 KB
/
Copy pathcheck-library-content.test.ts
File metadata and controls
491 lines (456 loc) · 19.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import path from 'node:path'
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import {
type ContentCheckConfig,
checkContent,
checkRedirectTargets,
indexPosts,
readReservedSegments,
resolvePostArg,
} from './check-library-content'
let root: string
let config: ContentCheckConfig
const CLEAN_FRONTMATTER = {
title: 'A clean library post',
description: 'A description that is comfortably over twenty characters.',
date: '2026-09-01',
authors: '[sim]',
}
function writePost(
section: string,
slug: string,
body: string,
frontmatter: Record<string, string> = {},
includeMedia = true
) {
const fields = {
slug,
...CLEAN_FRONTMATTER,
ogImage: `/${section}/${slug}/cover.jpg`,
...(section === 'changelog' ? { ogAlt: 'A sample workflow result in Sim' } : {}),
...frontmatter,
}
const yaml = Object.entries(fields)
.map(([key, value]) => (value.startsWith('\n') ? `${key}:${value}` : `${key}: ${value}`))
.join('\n')
const dir = path.join(config.contentDir, section, slug)
mkdirSync(dir, { recursive: true })
const media =
section === 'changelog' && includeMedia
? `\n<ChangelogImage src="/${section}/${slug}/cover.jpg" alt="A sample workflow result" width="1200" height="675" caption="The result of the demonstrated workflow." />\n`
: ''
writeFileSync(path.join(dir, 'index.mdx'), `---\n${yaml}\n---\n\n${body}\n${media}`)
const imageDir = path.join(config.publicDir, section, slug)
mkdirSync(imageDir, { recursive: true })
writeFileSync(path.join(imageDir, 'cover.jpg'), '')
}
async function findingsFor(section: string, slug: string) {
const { findings } = await checkContent(config, [{ section: section as 'library', slug }])
return findings.map(({ line, rule, message }) => ({ line, rule, message }))
}
beforeEach(() => {
root = mkdtempSync(path.join(tmpdir(), 'library-content-'))
config = {
contentDir: path.join(root, 'content'),
publicDir: path.join(root, 'public'),
reservedSegments: {
blog: new Set(['tags']),
library: new Set(['tags']),
customers: new Set(),
changelog: new Set(['archive', 'preview']),
},
mergedSlugs: { 'old-guide': 'kept-guide' },
movedBlogSlugs: ['moved-post'],
customerSlugs: ['acme'],
linkedPages: new Set([
'https://www.sim.ai/integrations/you-com',
'https://docs.sim.ai/workflows/deployment',
'https://www.sim.ai/models/anthropic',
'https://www.sim.ai/models/anthropic/claude-opus-4-6',
]),
}
mkdirSync(path.join(config.contentDir, 'authors'), { recursive: true })
writeFileSync(path.join(config.contentDir, 'authors', 'sim.json'), '{"id":"sim","name":"Sim"}')
writePost('library', 'kept-guide', 'The surviving guide.')
writePost('library', 'moved-post', 'Moved from the blog.')
})
afterEach(() => {
rmSync(root, { recursive: true, force: true })
})
describe('check-library-content', () => {
it.each([
'An update with only a cover image.',
'```mdx\n<ChangelogImage src="/changelog/post/cover.jpg" alt="Example" width="1200" height="675" />\n```',
])('rejects a published changelog without rendered feature media: %s', async (body) => {
writePost('changelog', 'post', body, {}, false)
expect(await findingsFor('changelog', 'post')).toEqual([
expect.objectContaining({ rule: 'media', message: expect.stringContaining('at least one') }),
])
writePost('changelog', 'post', body, { draft: 'true' }, false)
expect(await findingsFor('changelog', 'post')).toEqual([])
})
it.each([
{ date: '2999-01-01T00:00:00Z' },
{ date: '2026-09-01T00:00:00Z', updated: '2026-08-01T00:00:00Z' },
])('rejects misleading publication dates in a changelog: %o', async (dates) => {
writePost('changelog', 'post', 'A product update.', dates)
expect(await findingsFor('changelog', 'post')).toEqual([
expect.objectContaining({ rule: 'frontmatter', message: expect.stringContaining('date') }),
])
})
it('rejects two published updates with the same RSS identity', async () => {
const release =
'\n versions: [v0.9.10]\n url: https://github.com/simstudioai/sim/releases/tag/v0.9.10'
writePost('changelog', 'first-story', 'One capability.', { release })
writePost('changelog', 'second-story', 'Another capability.', { release })
const { findings } = await checkContent(config)
expect(findings).toEqual([
expect.objectContaining({
rule: 'frontmatter',
message: expect.stringContaining('RSS identity'),
}),
])
writePost('changelog', 'second-story', 'Another capability.', { release, draft: 'true' })
expect((await checkContent(config)).findings).toEqual([])
})
it.each([
'[You.com](/integrations/youcom)',
'[Deployment guide](https://docs.sim.ai/workflows/deployments)',
'[Deployment guide][guide]\n\n[guide]: https://docs.sim.ai/workflows/deployments',
'<a href="https://docs.sim.ai/workflows/deployments">Deployment guide</a>',
'[Model provider](/models/missing-provider)',
'[Model](https://www.sim.ai/models/anthropic/missing-model)',
'[Model][model]\n\n[model]: /models/anthropic/missing-model',
'<a href="/models/anthropic/missing-model">Model</a>',
])('rejects a changelog backlink to a missing page: %s', async (invalidLink) => {
writePost(
'changelog',
'post',
[
'[You.com](/integrations/you-com)',
'[Deployment guide](https://docs.sim.ai/workflows/deployment?source=changelog#api)',
'[Anthropic](/models/anthropic/)',
'[Claude Opus](https://www.sim.ai/models/anthropic/claude-opus-4-6?source=changelog#capabilities)',
'```md',
'[Example](https://docs.sim.ai/workflows/missing-example)',
'```',
invalidLink,
].join('\n\n')
)
expect(await findingsFor('changelog', 'post')).toEqual([
expect.objectContaining({
rule: 'internal-link',
message: expect.stringContaining('does not exist'),
}),
])
})
it('rejects a changelog link to an unpublished draft', async () => {
writePost('changelog', 'draft-update', 'Draft.', { draft: 'true' })
writePost('changelog', 'post', '[Next update](/changelog/draft-update)')
expect(await findingsFor('changelog', 'post')).toEqual([
expect.objectContaining({ rule: 'internal-link', message: expect.stringContaining('draft') }),
])
})
it('rejects a changelog slug that shadows the archive route', async () => {
writePost('changelog', 'archive', 'Body.')
expect(await findingsFor('changelog', 'archive')).toEqual([
expect.objectContaining({ rule: 'slug', message: expect.stringContaining('reserved') }),
])
})
it('rejects changelog body headings that collide with the page hierarchy', async () => {
writePost('changelog', 'post', '## Improvements\n\nA clearer comparison.')
expect(await findingsFor('changelog', 'post')).toEqual([
expect.objectContaining({ rule: 'mdx', message: expect.stringContaining('heading') }),
])
})
it('accepts local media and the approved CDN and rejects a lookalike origin', async () => {
const origin = 'https://nnjgp7vypgx4myuq.public.blob.vercel-storage.com'
mkdirSync(path.join(config.publicDir, 'changelog/media'), { recursive: true })
writeFileSync(path.join(config.publicDir, 'changelog/media/demo.mp4'), 'recording')
writeFileSync(path.join(config.publicDir, 'changelog/media/demo.vtt'), 'WEBVTT\n')
for (const [slug, src] of [
['good-video', `${origin}/changelog/demo-v1.mp4`],
['local-video', '/changelog/media/demo.mp4'],
['bad-video', `${origin}.example.com/changelog/demo-v1.mp4`],
]) {
writePost(
'changelog',
slug,
`<ChangelogVideo src="${src}" poster="/changelog/${slug}/cover.jpg" caption="Compare deployments" captionsSrc="/changelog/media/demo.vtt" />`
)
}
const { findings } = await checkContent(config)
expect(findings).toEqual([
expect.objectContaining({
file: path.join(config.contentDir, 'changelog/bad-video/index.mdx'),
rule: 'media',
}),
])
})
it.each([
'<ChangelogImage src="/changelog/post/cover.jpg" alt="Review changes" width={1200} height="800" />',
'<ChangelogImage src="/changelog/post/cover.jpg" alt="Review changes" width="0" height="800" />',
'<ChangelogVideo src="/changelog/media/missing.mp4" poster="/changelog/post/cover.jpg" caption="Compare deployments" />',
'<ChangelogVideo src="https://nnjgp7vypgx4myuq.public.blob.vercel-storage.com/changelog/demo.mp4" poster="/changelog/post/cover.jpg" caption="Compare deployments" captionsSrc="/changelog/media/missing.vtt" />',
'<ChangelogVideo src="https://nnjgp7vypgx4myuq.public.blob.vercel-storage.com/changelog/demo.mp4" poster="/changelog/missing.jpg" caption="Compare deployments" />',
'<ChangelogVideo src="https://example.com/demo.mp4" poster="/changelog/post/cover.jpg" caption="Compare deployments" />',
])('rejects changelog media that cannot render or load: %s', async (body) => {
writePost('changelog', 'post', body)
expect(await findingsFor('changelog', 'post')).toEqual([
expect.objectContaining({ rule: 'media' }),
])
})
it('passes a clean post with valid internal links, assets, reserved routes, and code samples', async () => {
writePost(
'library',
'clean',
[
'## Overview',
'See [the guide](/library/kept-guide) and https://www.sim.ai/library/kept-guide#intro.',
'Read https://www.sim.ai/library/kept-guide. Then https://www.sim.ai/library/moved-post, too.',
' and [tags](/library/tags) are not posts.',
'An apex https://sim.ai/library/missing link belongs to check:site-urls.',
'| a | b |',
'| - | - |',
'| 1 | 2 |',
'```md',
'## FAQ',
'[old](/library/old-guide)',
'```',
].join('\n')
)
expect(await findingsFor('library', 'clean')).toEqual([])
})
it('rejects an unknown frontmatter key such as canonical, at its line', async () => {
writePost('library', 'post', 'Body.', { canonical: 'https://www.sim.ai/library/post' })
expect(await findingsFor('library', 'post')).toEqual([
{ line: 8, rule: 'frontmatter', message: 'Unknown frontmatter key "canonical".' },
])
})
it('rejects frontmatter that fails the schema', async () => {
writePost('library', 'post', 'Body.', { title: 'Hi' })
const findings = await findingsFor('library', 'post')
expect(findings).toHaveLength(1)
expect(findings[0]).toMatchObject({ line: 3, rule: 'frontmatter' })
})
it('rejects a published search title over 60 or description over 160 characters at the key search reads, and exempts drafts', async () => {
const long = { title: 'T'.repeat(55), description: 'D'.repeat(161) }
writePost('library', 'post', 'Body.', long)
expect(await findingsFor('library', 'post')).toEqual([
expect.objectContaining({ line: 3, rule: 'search-title' }),
expect.objectContaining({ line: 4, rule: 'search-description' }),
])
writePost('library', 'post', 'Body.', {
...long,
seoTitle: 'S'.repeat(54),
seoDescription: 'E'.repeat(160),
})
expect(await findingsFor('library', 'post')).toEqual([])
writePost('library', 'post', 'Body.', { seoTitle: 'S'.repeat(55) })
expect(await findingsFor('library', 'post')).toEqual([
expect.objectContaining({ line: 8, rule: 'search-title' }),
])
writePost('library', 'post', 'Body.', { ...long, draft: 'true' })
expect(await findingsFor('library', 'post')).toEqual([])
})
it('rejects invalid YAML', async () => {
writePost('library', 'post', 'Body.', { title: 'Broken: [unclosed' })
expect((await findingsFor('library', 'post'))[0]).toMatchObject({ rule: 'frontmatter' })
})
it('rejects an author with no profile', async () => {
writePost('library', 'post', 'Body.', { authors: '[ghost]' })
expect(await findingsFor('library', 'post')).toEqual([
{
line: 6,
rule: 'frontmatter',
message: 'Author "ghost" has no profile in apps/sim/content/authors.',
},
])
})
it('rejects a slug that differs from the folder name', async () => {
writePost('library', 'post', 'Body.', { slug: 'other' })
expect(await findingsFor('library', 'post')).toEqual([
{ line: 2, rule: 'slug', message: 'slug "other" does not match the folder name "post".' },
])
})
it('rejects a missing or remote ogImage', async () => {
writePost('library', 'missing', 'Body.', { ogImage: '/library/missing/nope.jpg' })
writePost('library', 'remote', 'Body.', { ogImage: 'https://example.com/a.jpg' })
expect(await findingsFor('library', 'missing')).toEqual([
{
line: 7,
rule: 'og-image',
message: 'ogImage "/library/missing/nope.jpg" does not exist under apps/sim/public.',
},
])
expect((await findingsFor('library', 'remote'))[0]).toMatchObject({ rule: 'og-image' })
})
it('reports an MDX compile error at its file line', async () => {
writePost('library', 'post', 'Intro.\n\nA tag <div that never closes.')
const findings = await findingsFor('library', 'post')
expect(findings).toHaveLength(1)
expect(findings[0]).toMatchObject({ line: 12, rule: 'mdx' })
})
it('rejects an FAQ heading in the body', async () => {
writePost('library', 'post', 'Intro.\n\n## FAQs\n\nQ and A.')
expect(await findingsFor('library', 'post')).toEqual([
{ line: 12, rule: 'faq', message: 'Body has a "## FAQs" heading.' },
])
})
it('rejects Markdown link syntax inside an FAQ answer, at the answer line', async () => {
writePost('library', 'post', 'Body.', {
faq: '\n - q: "Plain question?"\n a: "Plain answer."\n - q: "Linked?"\n a: "See [Sim](https://www.sim.ai)."',
})
expect(await findingsFor('library', 'post')).toEqual([
{
line: 12,
rule: 'faq',
message: 'faq[1].a contains Markdown link syntax, which renders as literal text.',
},
])
})
it('rejects links to missing, retired, and moved posts, naming the replacement', async () => {
writePost(
'library',
'post',
[
'[a](/library/missing)',
'[b](https://www.sim.ai/library/old-guide)',
'<a href="/blog/moved-post">c</a>',
'[d](/blog/kept-guide)',
'Also see https://www.sim.ai/library/gone.',
'[e](/library/kept-guide.) and <a href="https://www.sim.ai/library/kept-guide.">f</a>',
].join('\n')
)
expect(await findingsFor('library', 'post')).toEqual([
{
line: 10,
rule: 'internal-link',
message: '/library/missing does not exist (no apps/sim/content/library/missing/index.mdx).',
},
{
line: 11,
rule: 'internal-link',
message: '/library/old-guide is retired; it was merged into /library/kept-guide.',
},
{
line: 12,
rule: 'internal-link',
message: '/blog/moved-post moved to /library/moved-post.',
},
{
line: 13,
rule: 'internal-link',
message: '/blog/kept-guide does not exist (no apps/sim/content/blog/kept-guide/index.mdx).',
},
{
line: 14,
rule: 'internal-link',
message: '/library/gone does not exist (no apps/sim/content/library/gone/index.mdx).',
},
{
line: 15,
rule: 'internal-link',
message:
'/library/kept-guide. does not exist (no apps/sim/content/library/kept-guide./index.mdx).',
},
{
line: 15,
rule: 'internal-link',
message:
'/library/kept-guide. does not exist (no apps/sim/content/library/kept-guide./index.mdx).',
},
])
})
it('rejects a retired slug whose replacement no longer exists', () => {
config.mergedSlugs = { 'old-guide': 'gone-guide' }
const findings = checkRedirectTargets(config, indexPosts(config.contentDir), 'map.ts')
expect(findings.map((finding) => finding.message)).toEqual([
'/library/old-guide redirects to /library/gone-guide, which does not exist (no apps/sim/content/library/gone-guide/index.mdx).',
])
})
it('rejects a moved blog slug whose library destination is missing or a draft', () => {
config.movedBlogSlugs = ['moved-post', 'never-moved']
writePost('library', 'moved-post', 'Unpublished.', { draft: 'true' })
const findings = checkRedirectTargets(config, indexPosts(config.contentDir), 'map.ts')
expect(findings.map((finding) => finding.message)).toEqual([
'/blog/moved-post redirects to /library/moved-post, which is a draft, so it 404s.',
'/blog/never-moved redirects to /library/never-moved, which does not exist (no apps/sim/content/library/never-moved/index.mdx).',
])
})
it('rejects a link to a draft blog or library post', async () => {
writePost('library', 'unpublished', 'Draft.', { draft: 'true' })
writePost('library', 'post', '[a](/library/unpublished)')
expect(await findingsFor('library', 'post')).toEqual([
{
line: 10,
rule: 'internal-link',
message: '/library/unpublished is a draft, so it 404s.',
},
])
})
it('accepts a registered draft customer story but rejects an unregistered one', async () => {
writePost('customers', 'acme', 'Registered draft.', { draft: 'true' })
writePost('customers', 'globex', 'Folder without a CUSTOMER_STORIES entry.')
writePost('library', 'post', '[a](/customers/acme)\n[b](/customers/globex)')
expect(await findingsFor('library', 'post')).toEqual([
{
line: 11,
rule: 'internal-link',
message:
'/customers/globex is not in CUSTOMER_STORIES (apps/sim/lib/customers/data.ts), so it 404s.',
},
])
})
it('reserves only sibling folders that define a page or route handler', () => {
const appDir = path.join(root, 'app')
for (const [dir, file] of [
['tags', 'page.tsx'],
['rss.xml', 'route.ts'],
['[slug]', 'page.tsx'],
['components', 'card.tsx'],
]) {
mkdirSync(path.join(appDir, dir), { recursive: true })
writeFileSync(path.join(appDir, dir, file), '')
}
expect([...readReservedSegments(() => appDir).customers].sort()).toEqual(['rss.xml', 'tags'])
})
it('rejects an invalid author profile and does not accept its id', async () => {
writeFileSync(path.join(config.contentDir, 'authors', 'ghost.json'), '{"id":"ghost"}')
writeFileSync(path.join(config.contentDir, 'authors', 'broken.json'), '{not json')
writePost('library', 'post', 'Body.', { authors: '[ghost]' })
const findings = await findingsFor('library', 'post')
expect(findings.map(({ rule, message }) => ({ rule, message }))).toEqual([
{ rule: 'frontmatter', message: expect.stringMatching(/^Author profile is invalid/) },
{ rule: 'frontmatter', message: expect.stringMatching(/^Author profile is invalid: name/) },
{
rule: 'frontmatter',
message: 'Author "ghost" has no profile in apps/sim/content/authors.',
},
])
})
it('rejects an ogImage that resolves outside public, even when the file exists', async () => {
writeFileSync(path.join(root, 'secret.jpg'), '')
writePost('library', 'post', 'Body.', { ogImage: '/../secret.jpg' })
expect(await findingsFor('library', 'post')).toEqual([
{
line: 7,
rule: 'og-image',
message: 'ogImage "/../secret.jpg" resolves outside apps/sim/public.',
},
])
})
it('resolves a post argument by section/slug or bare slug, and rejects unknown ones', () => {
const posts = indexPosts(config.contentDir)
expect(resolvePostArg('library/kept-guide', posts)).toEqual([
{ section: 'library', slug: 'kept-guide' },
])
expect(resolvePostArg('kept-guide', posts)).toEqual([
{ section: 'library', slug: 'kept-guide' },
])
expect(typeof resolvePostArg('blog/kept-guide', posts)).toBe('string')
expect(typeof resolvePostArg('nope', posts)).toBe('string')
})
})