website refactor
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,25 +0,0 @@
|
||||
/**
|
||||
* Guardrail violation representation
|
||||
*/
|
||||
|
||||
export class GuardrailViolation {
|
||||
constructor(
|
||||
public readonly ruleName: string,
|
||||
public readonly filePath: string,
|
||||
public readonly lineNumber: number,
|
||||
public readonly description: string,
|
||||
) {}
|
||||
|
||||
toString(): string {
|
||||
return `${this.filePath}:${this.lineNumber} - ${this.ruleName}: ${this.description}`;
|
||||
}
|
||||
|
||||
toJSON(): object {
|
||||
return {
|
||||
rule: this.ruleName,
|
||||
file: this.filePath,
|
||||
line: this.lineNumber,
|
||||
description: this.description,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
/**
|
||||
* Allowlist for architecture guardrail violations
|
||||
*
|
||||
* This file contains violations that currently exist in the codebase.
|
||||
* In future slices, these should be shrunk to zero.
|
||||
*
|
||||
* Format: Each rule has an array of file paths that are allowed to violate it.
|
||||
*/
|
||||
|
||||
export interface GuardrailAllowlist {
|
||||
[ruleName: string]: string[];
|
||||
}
|
||||
|
||||
export const ALLOWED_VIOLATIONS: GuardrailAllowlist = {
|
||||
// Rule 1: ContainerManager usage in server page queries
|
||||
'no-container-manager-in-server': [],
|
||||
|
||||
// Rule 2: PageDataFetcher.fetch() usage in server page queries
|
||||
'no-page-data-fetcher-fetch-in-server': [],
|
||||
|
||||
// Rule 3: ViewModels imported in forbidden paths
|
||||
'no-view-models-in-server': [],
|
||||
|
||||
// Rule 4: Templates importing view-models or display-objects
|
||||
'no-view-models-in-templates': [],
|
||||
|
||||
// Rule 5: Intl.* or toLocale* in presentation paths
|
||||
'no-intl-in-presentation': [],
|
||||
|
||||
// Rule 6: Client-side fetch with write methods
|
||||
'no-client-write-fetch': [
|
||||
'apps/website/app/sponsor/signup/page.tsx',
|
||||
],
|
||||
|
||||
// Rule 7: *Template.tsx files under app/
|
||||
'no-templates-in-app': [],
|
||||
|
||||
// Rule 8: 'as any' usage - ZERO TOLERANCE
|
||||
// Hard fail - no allowlist entries allowed
|
||||
'no-as-any': [],
|
||||
|
||||
// New Rule 1: RSC boundary - additional checks
|
||||
'no-presenters-in-server': [],
|
||||
'no-sorting-filtering-in-server': [],
|
||||
'no-display-objects-in-server': [],
|
||||
'no-unsafe-services-in-server': [],
|
||||
'no-di-in-server': [],
|
||||
'no-local-helpers-in-server': [],
|
||||
'no-object-construction-in-server': [],
|
||||
'no-container-manager-calls-in-server': [],
|
||||
|
||||
// New Rule 2: Template purity - additional checks
|
||||
'no-state-hooks-in-templates': [],
|
||||
'no-computations-in-templates': [],
|
||||
'no-restricted-imports-in-templates': [],
|
||||
'no-invalid-template-signature': [],
|
||||
'no-template-helper-exports': [],
|
||||
'invalid-template-filename': [],
|
||||
|
||||
// New Rule 3: Display Object guardrails
|
||||
'no-io-in-display-objects': [],
|
||||
'no-non-class-display-exports': [],
|
||||
|
||||
// New Rule 4: Page Query guardrails
|
||||
'no-null-returns-in-page-queries': [],
|
||||
'invalid-page-query-filename': [],
|
||||
|
||||
// New Rule 5: Services guardrails
|
||||
'no-service-state': [],
|
||||
'no-blockers-in-services': [],
|
||||
'no-dto-variable-name': [],
|
||||
|
||||
// New Rule 6: Client-only guardrails
|
||||
'no-use-client-directive': [],
|
||||
'no-viewmodel-imports-from-server': [],
|
||||
'no-http-in-presenters': [],
|
||||
|
||||
// New Rule 7: Write boundary guardrails
|
||||
'no-server-action-imports-from-client': [],
|
||||
'no-server-action-viewmodel-returns': [],
|
||||
|
||||
// New Rule 10: Generated DTO isolation
|
||||
'no-generated-dto-in-ui': [],
|
||||
'no-types-in-templates': [],
|
||||
|
||||
// New Rule 11: Filename rules
|
||||
'invalid-app-filename': [],
|
||||
};
|
||||
@@ -1,180 +0,0 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { ArchitectureGuardrails } from './ArchitectureGuardrails';
|
||||
|
||||
/**
|
||||
* Architecture Guardrail Tests
|
||||
*
|
||||
* These tests enforce the architectural contract for the website.
|
||||
* They use an allowlist to permit existing violations while preventing new ones.
|
||||
*
|
||||
* The goal is to shrink the allowlist slice-by-slice until zero violations remain.
|
||||
*/
|
||||
describe('Architecture Guardrails', () => {
|
||||
const guardrails = new ArchitectureGuardrails();
|
||||
|
||||
it('should detect all violations in the codebase', () => {
|
||||
const allViolations = guardrails.scan();
|
||||
|
||||
// This test documents the current state
|
||||
// It will always pass but shows what violations exist
|
||||
console.log(`\n📊 Total violations found: ${allViolations.length}`);
|
||||
|
||||
if (allViolations.length > 0) {
|
||||
console.log('\n📋 Violations by rule:');
|
||||
const byRule = allViolations.reduce((acc, v) => {
|
||||
acc[v.ruleName] = (acc[v.ruleName] || 0) + 1;
|
||||
return acc;
|
||||
}, {} as Record<string, number>);
|
||||
|
||||
Object.entries(byRule).forEach(([rule, count]) => {
|
||||
console.log(` - ${rule}: ${count}`);
|
||||
});
|
||||
}
|
||||
|
||||
// We expect violations to exist initially
|
||||
expect(allViolations.length).toBeGreaterThanOrEqual(0);
|
||||
});
|
||||
|
||||
it('should have no violations after filtering by allowlist', () => {
|
||||
const filteredViolations = guardrails.getFilteredViolations();
|
||||
|
||||
console.log(`\n🔍 Filtered violations (after allowlist): ${filteredViolations.length}`);
|
||||
|
||||
if (filteredViolations.length > 0) {
|
||||
console.log('\n❌ New violations not in allowlist:');
|
||||
filteredViolations.forEach(v => {
|
||||
console.log(` - ${v.toString()}`);
|
||||
});
|
||||
}
|
||||
|
||||
// This is the main assertion - no new violations allowed
|
||||
expect(filteredViolations.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should not have stale allowlist entries', () => {
|
||||
const staleEntries = guardrails.findStaleAllowlistEntries();
|
||||
|
||||
console.log(`\n🧹 Stale allowlist entries: ${staleEntries.length}`);
|
||||
|
||||
if (staleEntries.length > 0) {
|
||||
console.log('\n⚠️ These allowlist entries no longer match any violations:');
|
||||
staleEntries.forEach(entry => {
|
||||
console.log(` - ${entry}`);
|
||||
});
|
||||
console.log('\n💡 Consider removing them from allowed-violations.ts');
|
||||
}
|
||||
|
||||
// Stale entries should be removed to keep allowlist clean
|
||||
expect(staleEntries.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should enforce: no ContainerManager in server page queries', () => {
|
||||
const violations = guardrails.getFilteredViolations().filter(
|
||||
v => v.ruleName === 'no-container-manager-in-server'
|
||||
);
|
||||
|
||||
expect(violations.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should enforce: no PageDataFetcher.fetch() in server page queries', () => {
|
||||
const violations = guardrails.getFilteredViolations().filter(
|
||||
v => v.ruleName === 'no-page-data-fetcher-fetch-in-server'
|
||||
);
|
||||
|
||||
expect(violations.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should enforce: no view-models imports in server code', () => {
|
||||
const violations = guardrails.getFilteredViolations().filter(
|
||||
v => v.ruleName === 'no-view-models-in-server'
|
||||
);
|
||||
|
||||
expect(violations.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should enforce: no view-models/display-objects in templates', () => {
|
||||
const violations = guardrails.getFilteredViolations().filter(
|
||||
v => v.ruleName === 'no-view-models-in-templates'
|
||||
);
|
||||
|
||||
expect(violations.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should enforce: no Intl.* or toLocale* in presentation paths', () => {
|
||||
const violations = guardrails.getFilteredViolations().filter(
|
||||
v => v.ruleName === 'no-intl-in-presentation'
|
||||
);
|
||||
|
||||
expect(violations.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should enforce: no client-side write fetch', () => {
|
||||
const violations = guardrails.getFilteredViolations().filter(
|
||||
v => v.ruleName === 'no-client-write-fetch'
|
||||
);
|
||||
|
||||
expect(violations.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should enforce: no *Template.tsx under app/', () => {
|
||||
const violations = guardrails.getFilteredViolations().filter(
|
||||
v => v.ruleName === 'no-templates-in-app'
|
||||
);
|
||||
|
||||
expect(violations.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should enforce: no hooks directory in apps/website/', () => {
|
||||
const violations = guardrails.getFilteredViolations().filter(
|
||||
v => v.ruleName === 'no-hooks-directory'
|
||||
);
|
||||
|
||||
expect(violations.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should enforce: no as any usage', () => {
|
||||
const violations = guardrails.getFilteredViolations().filter(
|
||||
v => v.ruleName === 'no-as-any'
|
||||
);
|
||||
|
||||
expect(violations.length).toBe(0);
|
||||
});
|
||||
|
||||
// NEW: Contract enforcement tests
|
||||
it('should enforce: PageQuery classes must implement PageQuery contract', () => {
|
||||
const violations = guardrails.getFilteredViolations().filter(
|
||||
v => v.ruleName === 'pagequery-must-implement-contract' ||
|
||||
v.ruleName === 'pagequery-must-have-execute' ||
|
||||
v.ruleName === 'pagequery-execute-return-type'
|
||||
);
|
||||
|
||||
expect(violations.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should enforce: Presenter classes must implement Presenter contract', () => {
|
||||
const violations = guardrails.getFilteredViolations().filter(
|
||||
v => v.ruleName === 'presenter-must-implement-contract' ||
|
||||
v.ruleName === 'presenter-must-have-present' ||
|
||||
v.ruleName === 'presenter-must-be-client'
|
||||
);
|
||||
|
||||
expect(violations.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should enforce: ViewModel classes must extend ViewModel contract', () => {
|
||||
const violations = guardrails.getFilteredViolations().filter(
|
||||
v => v.ruleName === 'viewmodel-must-extend-contract' ||
|
||||
v.ruleName === 'viewmodel-must-be-client'
|
||||
);
|
||||
|
||||
expect(violations.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should enforce: DisplayObject files must export only classes', () => {
|
||||
const violations = guardrails.getFilteredViolations().filter(
|
||||
v => v.ruleName === 'no-non-class-display-exports'
|
||||
);
|
||||
|
||||
expect(violations.length).toBe(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user