Skip to content

AI-native design editor. Open-source Figma alternative.

test: cover architecture lint rules

Danila Poyarkovc80ce4c7a988
diff --git a/AGENTS.md b/AGENTS.md
index a26f7423f..701f598ce 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -238,7 +238,7 @@ Release commits are the exception: keep using `Release v0.x.y`.
## Code conventions
- Do not place code or tests ad hoc. Before adding or moving files, inspect the existing folder structure and nearby patterns, then put changes in the established domain-specific location. If no proper location exists, create one deliberately and update docs/conventions as needed.
-- Architecture boundaries are enforced by Steiger (`bun run check:arch`). App code must use public workspace package exports, workspace packages must not import app `src/` code, package-local aliases (`#core`, `#vue`, `#cli`, `#mcp`) are only for their owning package, core must stay framework-agnostic, shared UI (`src/components/ui/**`) must not import app services/stores, property-panel internals must stay inside the property panel, and canvas/editor overlay code must not import property-panel internals.
+- Architecture boundaries are enforced by Steiger (`bun run check:arch`). App code must use public workspace package exports, workspace packages must not import app `src/` code, package-local aliases (`#core`, `#vue`, `#cli`, `#mcp`) are only for their owning package, core must stay framework-agnostic, app service/domain code (`src/app/**`) must not import app component/view layers, components must not import views, shared UI (`src/components/ui/**`) must not import app services/stores, property-panel internals must stay inside the property panel, and canvas/editor overlay code must not import property-panel internals.
- Test placement is strict: E2E tests live under `tests/e2e/**` and use `*.spec.ts`; engine/unit tests live under `tests/engine/**` and use `*.test.ts`. Do not put store-only/internal-state assertions in E2E. If a test drives the UI like a user and verifies visible behavior, it can be E2E; if it creates nodes through internals and asserts graph state, it belongs in engine/unit coverage.
### File and folder naming
diff --git a/scripts/steiger-rules.ts b/scripts/steiger-rules.ts
index 7b0cd7904..f9dba3676 100644
--- a/scripts/steiger-rules.ts
+++ b/scripts/steiger-rules.ts
@@ -40,8 +40,8 @@ function normalizePath(filePath: string) {
return filePath.split(path.sep).join('/')
}
-function relativePath(filePath: string) {
- return normalizePath(path.relative(process.cwd(), filePath))
+function relativePath(rootPath: string, filePath: string) {
+ return normalizePath(path.relative(rootPath, filePath))
}
function collectFiles(entry: TreeEntry, files: string[] = []) {
@@ -97,7 +97,7 @@ function createImportRule(
check(root) {
const diagnostics: Diagnostic[] = []
for (const file of collectFiles(root)) {
- const sourceRel = relativePath(file)
+ const sourceRel = relativePath(root.path, file)
const content = readFileSync(file, 'utf8')
for (const imported of importsIn(content)) {
const resolved = resolveImport(sourceRel, imported.specifier)
@@ -168,6 +168,30 @@ const noForeignPackageLocalAliases = createImportRule(
}
)
+const noAppImportsComponentsOrViews = createImportRule(
+ 'open-pencil/no-app-imports-components-or-views',
+ (sourceRel, _specifier, resolved) => {
+ if (!sourceRel.startsWith('src/app/')) return null
+ const importsAppComponent =
+ resolved?.startsWith('src/components/') && !resolved.startsWith('src/components/ui/')
+ if (importsAppComponent || resolved?.startsWith('src/views/')) {
+ return 'App service/domain code must not import app component or view layers. Pass data/actions through app-owned entrypoints instead.'
+ }
+ return null
+ }
+)
+
+const noComponentsImportViews = createImportRule(
+ 'open-pencil/no-components-import-views',
+ (sourceRel, _specifier, resolved) => {
+ if (!sourceRel.startsWith('src/components/')) return null
+ if (resolved?.startsWith('src/views/')) {
+ return 'Components must not import views. Views assemble components, not the other way around.'
+ }
+ return null
+ }
+)
+
const noAppImportsInSharedUi = createImportRule(
'open-pencil/no-app-imports-in-shared-ui',
(sourceRel, _specifier, resolved) => {
@@ -213,6 +237,8 @@ export const openPencilArchitecturePlugin = {
noAppImportsInWorkspacePackages,
noPackageInternalsInApp,
noForeignPackageLocalAliases,
+ noAppImportsComponentsOrViews,
+ noComponentsImportViews,
noAppImportsInSharedUi,
noPropertyPanelInternalsOutsidePanel,
noUiImportsInCore
diff --git a/steiger.config.ts b/steiger.config.ts
index 1d6fb5fe8..f749782e7 100644
--- a/steiger.config.ts
+++ b/steiger.config.ts
@@ -23,6 +23,8 @@ export default defineConfig([
'open-pencil/no-app-imports-in-workspace-packages': 'error',
'open-pencil/no-package-internals-in-app': 'error',
'open-pencil/no-foreign-package-local-aliases': 'error',
+ 'open-pencil/no-app-imports-components-or-views': 'error',
+ 'open-pencil/no-components-import-views': 'error',
'open-pencil/no-app-imports-in-shared-ui': 'error',
'open-pencil/no-property-panel-internals-outside-panel': 'error',
'open-pencil/no-ui-imports-in-core': 'error'
diff --git a/tests/engine/scripts/steiger-rules.test.ts b/tests/engine/scripts/steiger-rules.test.ts
new file mode 100644
index 000000000..4f0283619
--- /dev/null
+++ b/tests/engine/scripts/steiger-rules.test.ts
@@ -0,0 +1,89 @@
+import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from 'node:fs'
+import { tmpdir } from 'node:os'
+import path from 'node:path'
+import { describe, expect, test } from 'bun:test'
+
+import { openPencilArchitecturePlugin } from '@/../scripts/steiger-rules'
+
+type TreeEntry = {
+ type: 'file' | 'folder'
+ path: string
+ children?: TreeEntry[]
+}
+
+function treeFromFiles(root: string, files: string[]): TreeEntry {
+ return {
+ type: 'folder',
+ path: root,
+ children: files.map((file) => ({ type: 'file', path: path.join(root, file) }))
+ }
+}
+
+function withFixture(files: Record<string, string>, run: (root: TreeEntry) => void) {
+ const dir = mkdtempSync(path.join(tmpdir(), 'open-pencil-arch-'))
+ try {
+ for (const [file, content] of Object.entries(files)) {
+ const fullPath = path.join(dir, file)
+ mkdirSync(path.dirname(fullPath), { recursive: true })
+ writeFileSync(fullPath, content)
+ }
+ run(treeFromFiles(dir, Object.keys(files)))
+ } finally {
+ rmSync(dir, { recursive: true, force: true })
+ }
+}
+
+function ruleNamesFor(files: Record<string, string>) {
+ let names: string[] = []
+ withFixture(files, (root) => {
+ names = openPencilArchitecturePlugin.ruleDefinitions.flatMap((rule) =>
+ rule.check(root).diagnostics.map(() => rule.name)
+ )
+ })
+ return names
+}
+
+describe('OpenPencil architecture rules', () => {
+ test('blocks app code from importing app component layers', () => {
+ const names = ruleNamesFor({
+ 'src/app/editor/service.ts': "import EditorCanvas from '@/components/EditorCanvas.vue'\n"
+ })
+
+ expect(names).toContain('open-pencil/no-app-imports-components-or-views')
+ })
+
+ test('blocks shared UI from importing app services', () => {
+ const names = ruleNamesFor({
+ 'src/components/ui/toast.ts': "import { toast } from '@/app/shell/ui'\n"
+ })
+
+ expect(names).toContain('open-pencil/no-app-imports-in-shared-ui')
+ })
+
+ test('blocks canvas overlays from importing property-panel internals', () => {
+ const names = ruleNamesFor({
+ 'src/components/EditorCanvas.vue': "import PaddingControls from '@/components/properties/LayoutSection/PaddingControls.vue'\n"
+ })
+
+ expect(names).toContain('open-pencil/no-property-panel-imports-in-canvas')
+ expect(names).toContain('open-pencil/no-property-panel-internals-outside-panel')
+ })
+
+ test('blocks package-local aliases outside their owning package', () => {
+ const names = ruleNamesFor({
+ 'packages/vue/src/canvas/use.ts': "import { SceneGraph } from '#core/scene-graph'\n"
+ })
+
+ expect(names).toContain('open-pencil/no-foreign-package-local-aliases')
+ })
+
+ test('allows app code to import public workspace package exports and shared UI', () => {
+ const names = ruleNamesFor({
+ 'src/app/editor/service.ts':
+ "import { useCanvas } from '@open-pencil/vue'\nimport type { ToastVariant } from '@/components/ui/toast'\n"
+ })
+
+ expect(names).not.toContain('open-pencil/no-package-internals-in-app')
+ expect(names).not.toContain('open-pencil/no-app-imports-components-or-views')
+ })
+})