|
1 | 1 | import { describe, test, expect } from 'bun:test' |
2 | | -import { existsSync } from 'node:fs' |
| 2 | +import { existsSync, readFileSync } from 'node:fs' |
3 | 3 | import { join } from 'node:path' |
4 | 4 |
|
5 | 5 | const contentDir = join(import.meta.dirname, '../../content/docs') |
| 6 | +const apiReferenceDir = join(contentDir, 'api-reference') |
| 7 | +const repoRoot = join(import.meta.dirname, '../../../..') |
6 | 8 |
|
7 | 9 | describe('docs content', () => { |
8 | 10 | test('content directory exists', () => { |
@@ -90,4 +92,35 @@ describe('openapi spec generation', () => { |
90 | 92 | expect(tagNames).toContain('Artifacts') |
91 | 93 | expect(tagNames).toContain('Replay') |
92 | 94 | }) |
| 95 | + |
| 96 | + test('openapi.json artifact is generated from the live openapi spec', async () => { |
| 97 | + const { spec } = await import('../../../api/src/openapi.js') |
| 98 | + const specPath = join(apiReferenceDir, 'openapi.json') |
| 99 | + |
| 100 | + expect(existsSync(specPath)).toBe(true) |
| 101 | + expect(JSON.parse(readFileSync(specPath, 'utf8'))).toEqual(spec) |
| 102 | + }) |
| 103 | + |
| 104 | + test('generated api pages live under the canonical docs tree without absolute path leakage', () => { |
| 105 | + const generatedPagePath = join(apiReferenceDir, 'health/get-health.mdx') |
| 106 | + const leakedOutputRoot = join(import.meta.dirname, '../../Users') |
| 107 | + |
| 108 | + expect(existsSync(generatedPagePath)).toBe(true) |
| 109 | + expect(existsSync(leakedOutputRoot)).toBe(false) |
| 110 | + |
| 111 | + const content = readFileSync(generatedPagePath, 'utf8') |
| 112 | + expect(content).toContain('<APIPage document={"content/docs/api-reference/openapi.json"}') |
| 113 | + expect(content.includes(repoRoot)).toBe(false) |
| 114 | + }) |
| 115 | + |
| 116 | + test('llms artifacts are generated from the live openapi spec', async () => { |
| 117 | + const { generateLlmsDocuments } = await import('../../../api/src/llms.js') |
| 118 | + const publicDir = join(import.meta.dirname, '../../public') |
| 119 | + |
| 120 | + for (const [filename, content] of Object.entries(generateLlmsDocuments())) { |
| 121 | + const filePath = join(publicDir, filename) |
| 122 | + expect(existsSync(filePath)).toBe(true) |
| 123 | + expect(readFileSync(filePath, 'utf8')).toBe(content) |
| 124 | + } |
| 125 | + }) |
93 | 126 | }) |
0 commit comments