-
Notifications
You must be signed in to change notification settings - Fork 0
feat(core-domain): GT-377 AC-3 — ESLint stateless-Core *Repository guard + CI gate #147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
beyondnetPeru
wants to merge
2
commits into
develop
Choose a base branch
from
claude/vigorous-gauss-d24b4d
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| // @ts-check | ||
| /** | ||
| * ESLint flat config for @evolith/core-domain (ESLint 9+). | ||
| * | ||
| * Migrated from the legacy `.eslintrc.js` + `--no-eslintrc` invocation, which is | ||
| * incompatible with ESLint 9 (the `--no-eslintrc` flag was removed and the legacy | ||
| * eslintrc loader broke eslint-plugin-boundaries with "Cannot set properties of | ||
| * undefined (setting defaultMeta)"). | ||
| * | ||
| * Enforces two architectural guards: | ||
| * | ||
| * 1. Layer boundaries — core-domain is a pure inner package. Imports may only | ||
| * flow inward across the layer hierarchy: | ||
| * | ||
| * common / types | ||
| * └─ domain (entities, value objects, domain services) | ||
| * └─ application (use cases) | ||
| * └─ infrastructure (adapters) | ||
| * | ||
| * 2. Stateless Core (GT-377 / ADR-0101) — Core is a stateless Evaluation Engine. | ||
| * `product` / `initiative` / `evidence` / `decision` are CONTEXT, never | ||
| * persisted entities, so a `*Repository` for any of them must NEVER appear in | ||
| * this package. The `no-restricted-syntax` rule below fails the build (and CI) | ||
| * if such an identifier is declared, imported, or referenced. | ||
| */ | ||
| import boundaries from 'eslint-plugin-boundaries'; | ||
| import tseslint from 'typescript-eslint'; | ||
| // Shared (CommonJS) so the negative regression test enforces the EXACT same rule. | ||
| import guards from './eslint.guards.cjs'; | ||
|
|
||
| const { STATELESS_CORE_REPOSITORY_BAN } = guards; | ||
|
|
||
| export default tseslint.config( | ||
| { | ||
| ignores: [ | ||
| 'dist/**', | ||
| 'coverage/**', | ||
| 'node_modules/**', | ||
| '**/*.js', | ||
| '**/*.cjs', | ||
| '**/*.mjs', | ||
| ], | ||
| }, | ||
| { | ||
| files: ['src/**/*.ts'], | ||
| plugins: { | ||
| '@typescript-eslint': tseslint.plugin, | ||
| boundaries, | ||
| }, | ||
| languageOptions: { | ||
| parser: tseslint.parser, | ||
| ecmaVersion: 2022, | ||
| sourceType: 'module', | ||
| }, | ||
| settings: { | ||
| 'boundaries/elements': [ | ||
| { type: 'common', pattern: 'src/common/**/*' }, | ||
| { type: 'domain', pattern: 'src/domain/**/*' }, | ||
| { type: 'application', pattern: 'src/application/**/*' }, | ||
| { type: 'infrastructure', pattern: 'src/infrastructure/**/*' }, | ||
| { type: 'gates', pattern: 'src/gates/**/*' }, | ||
| { type: 'phases', pattern: 'src/phases/**/*' }, | ||
| { type: 'tenancy', pattern: 'src/tenancy/**/*' }, | ||
| { type: 'providers', pattern: 'src/providers/**/*' }, | ||
| { type: 'evidence', pattern: 'src/evidence/**/*' }, | ||
| { type: 'evaluation', pattern: 'src/evaluation/**/*' }, | ||
| ], | ||
| 'boundaries/ignore': ['src/**/*.spec.ts', 'src/**/*.test.ts'], | ||
| }, | ||
| rules: { | ||
| '@typescript-eslint/no-explicit-any': 'warn', | ||
|
|
||
| 'boundaries/element-types': [ | ||
| 'error', | ||
| { | ||
| default: 'disallow', | ||
| rules: [ | ||
| // common: no internal imports | ||
| { from: 'common', allow: [] }, | ||
|
|
||
| // domain: innermost — only common | ||
| { from: 'domain', allow: ['domain', 'common'] }, | ||
|
|
||
| // application: use cases — domain + common | ||
| { from: 'application', allow: ['application', 'domain', 'common'] }, | ||
|
|
||
| // infrastructure: adapters — can use all inner layers | ||
| { | ||
| from: 'infrastructure', | ||
| allow: ['infrastructure', 'application', 'domain', 'common'], | ||
| }, | ||
|
|
||
| // gates/phases/tenancy/providers/evidence: cross-cutting within this package | ||
| { from: 'gates', allow: ['gates', 'domain', 'application', 'common'] }, | ||
| { from: 'phases', allow: ['phases', 'domain', 'application', 'common'] }, | ||
| { from: 'tenancy', allow: ['tenancy', 'domain', 'common'] }, | ||
| { | ||
| from: 'providers', | ||
| allow: ['providers', 'infrastructure', 'domain', 'common'], | ||
| }, | ||
| { from: 'evidence', allow: ['evidence', 'domain', 'application', 'common'] }, | ||
|
|
||
| // evaluation: stateless Core Evaluation Engine (GT-377/ADR-0101) — | ||
| // canonical contracts + orchestrator; composes domain + application. | ||
| { | ||
| from: 'evaluation', | ||
| allow: ['evaluation', 'domain', 'application', 'common'], | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
|
|
||
| // Stateless-Core guard (GT-377 AC-3 / ADR-0101): no business-entity repositories. | ||
| 'no-restricted-syntax': ['error', STATELESS_CORE_REPOSITORY_BAN], | ||
| }, | ||
| }, | ||
| ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| 'use strict'; | ||
|
|
||
| /** | ||
| * Architecture guards shared between the ESLint flat config (`eslint.config.mjs`) | ||
| * and the regression test (`stateless-core-repository.guard.spec.ts`), so both | ||
| * enforce the EXACT same rule — single source of truth for GT-377 AC-3. | ||
| * | ||
| * CommonJS on purpose: the `.mjs` config imports it statically and the ts-jest | ||
| * (CommonJS) test `require`s it, with no ESM/dynamic-import interop hazard. | ||
| */ | ||
|
|
||
| /** | ||
| * Bans any identifier shaped like a repository for a business entity that Core | ||
| * treats as pure context (GT-377 / ADR-0101 — Core is a stateless Evaluation | ||
| * Engine). Matches declarations, imports and type references such as | ||
| * `ProductRepository`, `IInitiativeRepository`, `EvidenceRepositoryPort`, | ||
| * `InMemoryDecisionRepository`, … while leaving legitimate infrastructure | ||
| * repositories (`AuditRepository`, `SubscriptionRepository`, `DeliveryRepository`) | ||
| * untouched. | ||
| * | ||
| * @type {{ selector: string, message: string }} | ||
| */ | ||
| const STATELESS_CORE_REPOSITORY_BAN = { | ||
| selector: 'Identifier[name=/(Product|Initiative|Evidence|Decision)Repository/]', | ||
| message: | ||
| 'GT-377/ADR-0101: Core is a stateless Evaluation Engine. product/initiative/evidence/decision are context, not entities — a *Repository for them must not appear in core-domain.', | ||
| }; | ||
|
|
||
| module.exports = { STATELESS_CORE_REPOSITORY_BAN }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
packages/core-domain/src/evaluation/stateless-core-repository.guard.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| /** | ||
| * GT-377 AC-3 — architecture guard regression test. | ||
| * | ||
| * Asserts that the stateless-Core repository ban actually fails when a | ||
| * `*Repository` for a business entity that Core treats as pure context | ||
| * (product / initiative / evidence / decision) appears — and, crucially, does | ||
| * NOT fire for legitimate infrastructure repositories. This is the negative test | ||
| * proving the guard from `gap-reference-catalog.md` "#### GT-377" AC-3 ("ESLint | ||
| * boundary guard fails CI if a `*Repository` for product/initiative/evidence/ | ||
| * decision appears") is wired and effective, not merely declared. | ||
| * | ||
| * It exercises the SAME rule object that ships in `eslint.config.mjs` by | ||
| * importing it from the shared `eslint.guards.cjs` (single source of truth), and | ||
| * runs it through ESLint's synchronous flat-config `Linter` — no config-file | ||
| * dynamic import, so it is jest/ts-jest safe. | ||
| * | ||
| * The banned identifiers below live ONLY inside string literals (lint input), | ||
| * never as real code, so this spec itself stays green under `lint:boundaries`. | ||
| */ | ||
| import { Linter } from 'eslint'; | ||
|
|
||
| // require (not import) so the runtime object matches what ESLint expects, free of | ||
| // ts-jest ESM-interop wrapping (`@typescript-eslint/parser` sets `__esModule`). | ||
| const tsParser = require('@typescript-eslint/parser') as Linter.Parser; | ||
| const { STATELESS_CORE_REPOSITORY_BAN } = require('../../eslint.guards.cjs') as { | ||
| STATELESS_CORE_REPOSITORY_BAN: { selector: string; message: string }; | ||
| }; | ||
|
|
||
| const GUARD_RULE = 'no-restricted-syntax'; | ||
|
|
||
| const linter = new Linter({ configType: 'flat' }); | ||
|
|
||
| function guardErrors(code: string): string[] { | ||
| const messages = linter.verify(code, { | ||
| languageOptions: { | ||
| parser: tsParser, | ||
| ecmaVersion: 2022, | ||
| sourceType: 'module', | ||
| }, | ||
| rules: { | ||
| [GUARD_RULE]: ['error', STATELESS_CORE_REPOSITORY_BAN], | ||
| }, | ||
| }); | ||
| return messages | ||
| .filter((m) => m.ruleId === GUARD_RULE && m.severity === 2) | ||
| .map((m) => m.message); | ||
| } | ||
|
|
||
| describe('GT-377 AC-3 — stateless-Core repository guard', () => { | ||
| const BANNED_ENTITIES = ['Product', 'Initiative', 'Evidence', 'Decision']; | ||
|
|
||
| it.each(BANNED_ENTITIES)( | ||
| 'FAILS when a %sRepository is imported and referenced', | ||
| (entity) => { | ||
| const code = [ | ||
| `import { ${entity}Repository } from '../infrastructure/persistence';`, | ||
| `export function use(repo: ${entity}Repository): void { void repo; }`, | ||
| '', | ||
| ].join('\n'); | ||
|
|
||
| const errors = guardErrors(code); | ||
|
|
||
| expect(errors.length).toBeGreaterThan(0); | ||
| expect(errors.every((m) => m.includes('GT-377'))).toBe(true); | ||
| }, | ||
| ); | ||
|
|
||
| it.each(BANNED_ENTITIES)( | ||
| 'FAILS when a %sRepository interface is declared inline', | ||
| (entity) => { | ||
| const code = `export interface ${entity}Repository { findById(id: string): unknown; }\n`; | ||
|
|
||
| const errors = guardErrors(code); | ||
|
|
||
| expect(errors.length).toBeGreaterThan(0); | ||
| }, | ||
| ); | ||
|
|
||
| it.each([ | ||
| 'AuditRepository', | ||
| 'SubscriptionRepository', | ||
| 'DeliveryRepository', | ||
| 'createRepository', | ||
| 'getRepository', | ||
| ])('does NOT flag the legitimate identifier %s (no false positive)', (ident) => { | ||
| const code = [ | ||
| `import { ${ident} } from '../infrastructure/persistence';`, | ||
| `export const ref = ${ident};`, | ||
| '', | ||
| ].join('\n'); | ||
|
|
||
| expect(guardErrors(code)).toEqual([]); | ||
| }); | ||
|
|
||
| it('produces zero guard errors for a clean evaluation module', () => { | ||
| const code = [ | ||
| "import type { EvaluationContext } from './contracts';", | ||
| 'export function evaluate(ctx: EvaluationContext): EvaluationContext { return ctx; }', | ||
| '', | ||
| ].join('\n'); | ||
|
|
||
| expect(guardErrors(code)).toEqual([]); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
@evolith/core-domainis installed or linted in isolation, this new flat config imports thetypescript-eslintmeta-package even thoughpackages/core-domain/package.jsononly declares@typescript-eslint/parser; the package is currently present only because another workspace (apps/core-api) happens to depend on it. A focused workspace install or future removal from that unrelated package will makenpm run lint:boundaries --workspace @evolith/core-domainfail withERR_MODULE_NOT_FOUNDbefore the boundary guard can run, so core-domain should declaretypescript-eslintdirectly or avoid importing it.Useful? React with 👍 / 👎.