test(frontend): reject import cycles
The theme engine and the interactive UI SDK imported each other's types; the SDK now owns the types of its own interface. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7cb6d5f910
commit
5df61df5b9
5 files changed
+71
-24
No files matched your search
@@ -0,0 +1,45 @@
|
||||
// Rejects import cycles in src/, type imports included: two files that import
|
||||
// each other are one module split in the wrong place.
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import ts from 'typescript'
|
||||
|
||||
const src = path.resolve(import.meta.dirname, '..', 'src')
|
||||
const rel = (file) => path.relative(src, file).split(path.sep).join('/')
|
||||
|
||||
function importGraph() {
|
||||
const files = fs.readdirSync(src, { recursive: true })
|
||||
.filter((name) => /\.tsx?$/.test(name))
|
||||
.map((name) => path.join(src, name))
|
||||
const known = new Set(files)
|
||||
return new Map(files.map((file) => {
|
||||
const { importedFiles } = ts.preProcessFile(fs.readFileSync(file, 'utf8'), true, true)
|
||||
const targets = importedFiles
|
||||
.filter(({ fileName }) => fileName.startsWith('.'))
|
||||
.map(({ fileName }) => path.resolve(path.dirname(file), fileName))
|
||||
.map((base) => ['', '.ts', '.tsx', `${path.sep}index.ts`].map((ext) => base + ext).find((p) => known.has(p)))
|
||||
.filter(Boolean)
|
||||
return [file, targets]
|
||||
}))
|
||||
}
|
||||
|
||||
test('source modules do not import each other in a cycle', () => {
|
||||
const graph = importGraph()
|
||||
assert.ok(graph.size > 50, `expected to scan src/, found ${graph.size} files`)
|
||||
const done = new Set()
|
||||
const cycles = []
|
||||
const visit = (file, trail) => {
|
||||
const start = trail.indexOf(file)
|
||||
if (start >= 0) {
|
||||
cycles.push([...trail.slice(start), file].map(rel).join(' -> '))
|
||||
return
|
||||
}
|
||||
if (done.has(file)) return
|
||||
for (const next of graph.get(file)) visit(next, [...trail, file])
|
||||
done.add(file)
|
||||
}
|
||||
for (const file of graph.keys()) visit(file, [])
|
||||
assert.deepEqual(cycles, [])
|
||||
})
|
||||
@@ -19,7 +19,8 @@ import { resolveFullscreenHotkey } from './lib/fullscreenHotkey'
|
||||
import { LogLine, appendLog } from './lib/logs'
|
||||
import { macOSMajor } from './macos/macosRelease'
|
||||
import { currentTask, finishedTaskTTL, isActiveInstallerTask, pruneFinishedTasks, upsertTask } from './lib/tasks'
|
||||
import { applyActiveLocaleFonts, applyActiveTheme, disposeActiveThemeAndLocaleFonts, notifyInteractiveThemeState, type UIStateSnapshot } from './lib/themeEngine'
|
||||
import { applyActiveLocaleFonts, applyActiveTheme, disposeActiveThemeAndLocaleFonts, notifyInteractiveThemeState } from './lib/themeEngine'
|
||||
import type { UIStateSnapshot } from './lib/uiSdk'
|
||||
import { hasVisibleDialog } from './lib/dialogState'
|
||||
import { latestVMStats, refreshSubscribedVMStats, refreshVMStats } from './lib/vmStats'
|
||||
import { useAppearance } from './lib/useAppearance'
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
import { UI_CONTRACT_LAYOUT_OPTIONS, UI_CONTRACT_TOKENS, type UIContractSDKEvent } from '../styles/ui-contract'
|
||||
import type { ActiveThemePayload, ThemeDecoration, ThemeDecorationState, TokenDeriveRule } from '../types'
|
||||
import type { ThemeSDKHostActions, UIStateSnapshot } from './uiSdk'
|
||||
|
||||
const LEGACY_CACHE_KEY = 'reims-go-theme-tokens-v1'
|
||||
const THEME_CACHE_KEY = 'reims-go-theme-tokens-v2'
|
||||
@@ -26,27 +27,6 @@ interface ThemeTokenCache {
|
||||
dark?: Record<string, string>
|
||||
}
|
||||
|
||||
export interface UIStateSnapshot {
|
||||
appearance: 'light' | 'dark'
|
||||
motion: 'full' | 'reduced'
|
||||
locale: string
|
||||
dir: 'ltr' | 'rtl'
|
||||
view: string
|
||||
vmName: string
|
||||
vmState: string
|
||||
busy: boolean
|
||||
hasError: boolean
|
||||
sidebarCollapsed: boolean
|
||||
safeMode: boolean
|
||||
vms: Array<{ name: string; state: string }>
|
||||
}
|
||||
|
||||
export interface ThemeSDKHostActions {
|
||||
toggleSidebar: () => void
|
||||
openSettings: () => void
|
||||
focusVMWindow: (name: string) => void
|
||||
}
|
||||
|
||||
let activeUIScriptCleanup: (() => void) | null = null
|
||||
let activeUIScriptNotifier: ((snap: UIStateSnapshot) => void) | null = null
|
||||
let activeUIScriptURL = ''
|
||||
|
||||
@@ -6,7 +6,27 @@ import {
|
||||
type UIContractLayer, type UIContractPart, type UIContractSDKEvent, type UIContractSlot,
|
||||
} from '../styles/ui-contract'
|
||||
import { hideWailsGlobals } from '../wails'
|
||||
import type { ThemeSDKHostActions, UIStateSnapshot } from './themeEngine'
|
||||
|
||||
export interface UIStateSnapshot {
|
||||
appearance: 'light' | 'dark'
|
||||
motion: 'full' | 'reduced'
|
||||
locale: string
|
||||
dir: 'ltr' | 'rtl'
|
||||
view: string
|
||||
vmName: string
|
||||
vmState: string
|
||||
busy: boolean
|
||||
hasError: boolean
|
||||
sidebarCollapsed: boolean
|
||||
safeMode: boolean
|
||||
vms: Array<{ name: string; state: string }>
|
||||
}
|
||||
|
||||
export interface ThemeSDKHostActions {
|
||||
toggleSidebar: () => void
|
||||
openSettings: () => void
|
||||
focusVMWindow: (name: string) => void
|
||||
}
|
||||
|
||||
interface ReimsUISDK {
|
||||
readonly uiApi: string
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
import React, { createContext, useContext, useEffect, useMemo, useState } from 'react'
|
||||
import { createPortal } from 'react-dom'
|
||||
import { locText } from '../i18n'
|
||||
import { matchDecorationState, themeAssetURL, type UIStateSnapshot } from '../lib/themeEngine'
|
||||
import { matchDecorationState, themeAssetURL } from '../lib/themeEngine'
|
||||
import type { UIStateSnapshot } from '../lib/uiSdk'
|
||||
import { UI_CONTRACT_ICONS, UI_CONTRACT_LAYERS, UI_CONTRACT_SLOTS, type UIContractIcon } from '../styles/ui-contract'
|
||||
import type { ActiveThemePayload, Locale, ThemeDecoration } from '../types'
|
||||
|
||||
|
||||
Reference in new issue
Block a user