| 1 | import fs from 'fs' |
| 2 | import path from 'path' |
| 3 | import { describe, expect, it } from 'vitest' |
| 4 | |
| 5 | const removedStylePaths = [ |
| 6 | 'src/main/utils/style-import.ts', |
| 7 | 'src/main/utils/style-image-import.ts', |
| 8 | 'src/main/utils/style-pptx-import.ts', |
| 9 | 'src/main/utils/style-preview-generator.ts', |
| 10 | 'src/main/utils/style-skills.ts', |
| 11 | 'src/main/ipc/config/style-handlers.ts', |
| 12 | 'src/main/ipc/config/style-preview-handlers.ts' |
| 13 | ] |
| 14 | |
| 15 | const canonicalStyleFiles = [ |
| 16 | 'src/main/styles/catalog.ts', |
| 17 | 'src/main/styles/handlers.ts', |
| 18 | 'src/main/styles/import/file.ts', |
| 19 | 'src/main/styles/import/image.ts', |
| 20 | 'src/main/styles/import/pptx.ts', |
| 21 | 'src/main/styles/preview/generator.ts', |
| 22 | 'src/main/styles/preview/handlers.ts' |
| 23 | ] |
| 24 | |
| 25 | const readTypeScriptSources = (directory: string): Array<{ filePath: string; source: string }> => { |
| 26 | const sources: Array<{ filePath: string; source: string }> = [] |
| 27 | for (const entry of fs.readdirSync(directory, { withFileTypes: true })) { |
| 28 | const filePath = path.join(directory, entry.name) |
| 29 | if (entry.isDirectory()) { |
| 30 | sources.push(...readTypeScriptSources(filePath)) |
| 31 | } else if (entry.isFile() && /\.tsx?$/.test(entry.name)) { |
| 32 | sources.push({ filePath, source: fs.readFileSync(filePath, 'utf8') }) |
| 33 | } |
| 34 | } |
| 35 | return sources |
| 36 | } |
| 37 | |
| 38 | describe('styles domain boundaries', () => { |
| 39 | it('keeps the style catalog, imports, preview, and IPC registrations in styles/', () => { |
| 40 | expect(canonicalStyleFiles.filter((filePath) => !fs.existsSync(filePath))).toEqual([]) |
| 41 | }) |
| 42 | |
| 43 | it('removes legacy style paths after every caller migrates', () => { |
| 44 | expect(removedStylePaths.filter((filePath) => fs.existsSync(filePath))).toEqual([]) |
| 45 | }) |
| 46 | |
| 47 | it('does not let application code import an old style path', () => { |
| 48 | const removedFragments = [ |
| 49 | 'utils/style-import', |
| 50 | 'utils/style-image-import', |
| 51 | 'utils/style-pptx-import', |
| 52 | 'utils/style-preview-generator', |
| 53 | 'utils/style-skills', |
| 54 | 'config/style-handlers', |
| 55 | 'config/style-preview-handlers' |
| 56 | ] |
| 57 | for (const { filePath, source } of readTypeScriptSources('src/main')) { |
| 58 | for (const fragment of removedFragments) { |
| 59 | expect(source, `${filePath}: ${fragment}`).not.toContain(fragment) |
| 60 | } |
| 61 | } |
| 62 | }) |
| 63 | }) |
| 64 |