-
-
Notifications
You must be signed in to change notification settings - Fork 249
feat: breaking schema change detection with governance webhooks #2371
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
de25722
docs: add breaking schema change detection implementation plan
boyney123 6c30e06
chore: add .worktrees/ to .gitignore
boyney123 2e6acf8
feat(breaking-changes): scaffold package
boyney123 0fb2dd7
feat(breaking-changes): json schema differ with tests
boyney123 1afc1e1
feat(breaking-changes): breaking change rules per strategy with tests
boyney123 6e7d371
feat(breaking-changes): integration tests for public API
boyney123 c1f5844
feat(cli): add schema_breaking_change trigger type and BreakingSchema…
boyney123 2df4196
feat(cli): parse compatibility strategy from governance.yaml
boyney123 8ac0399
feat(cli): evaluate schema_breaking_change governance rules
boyney123 bf27cd3
feat(cli): enrich breaking schema changes with actual diff results
boyney123 0f14ec1
feat(cli): schema_breaking_change webhook payload with CloudEvents en…
boyney123 f81bff4
chore: format code
boyney123 ea7e4b0
fix(breaking-changes): detect root type changes and implicit nested o…
boyney123 5e3de8a
fix(cli): validate compatibility strategy and narrow catch scope
boyney123 03fb605
chore: remove implementation plan from repo
boyney123 cb74d30
chore: add changeset for breaking schema change detection
boyney123 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| "@eventcatalog/breaking-changes": minor | ||
| "@eventcatalog/cli": minor | ||
| --- | ||
|
|
||
| feat: add breaking schema change detection with governance webhooks | ||
|
|
||
| New `schema_breaking_change` governance trigger that detects breaking JSON Schema changes per compatibility strategy (BACKWARD, FORWARD, FULL, NONE). Users configure `compatibility.strategy` in governance.yaml and subscribe to breaking change webhooks with detailed diff information. |
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 |
|---|---|---|
|
|
@@ -69,4 +69,5 @@ PERFORMANCE-ANALYSIS.md | |
|
|
||
|
|
||
| .agents/skills/copy* | ||
| ec-test/ | ||
| ec-test/ | ||
| .worktrees/ | ||
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,41 @@ | ||
| { | ||
| "name": "@eventcatalog/breaking-changes", | ||
| "version": "0.1.0", | ||
| "description": "Breaking schema change detection for EventCatalog", | ||
| "main": "./dist/index.js", | ||
| "module": "./dist/index.mjs", | ||
| "types": "./dist/index.d.ts", | ||
| "exports": { | ||
| ".": { | ||
| "types": "./dist/index.d.ts", | ||
| "require": "./dist/index.js", | ||
| "import": "./dist/index.mjs" | ||
| } | ||
| }, | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "scripts": { | ||
| "build": "tsup", | ||
| "build:bin": "tsup", | ||
| "test": "vitest --run", | ||
| "test:ci": "vitest --run", | ||
| "format": "prettier --write .", | ||
| "format:diff": "prettier --list-different ." | ||
| }, | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "license": "ISC", | ||
| "devDependencies": { | ||
| "@types/node": "^20.14.10", | ||
| "prettier": "^3.3.3", | ||
| "tsup": "^8.1.0", | ||
| "typescript": "^5.5.3", | ||
| "vitest": "^3.2.4" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/event-catalog/eventcatalog" | ||
| } | ||
| } |
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,9 @@ | ||
| export type { | ||
| CompatibilityStrategy, | ||
| SchemaChange, | ||
| BreakingChange, | ||
| SchemaChangeType, | ||
| } from "./types"; | ||
|
|
||
| export { detectBreakingChanges } from "./json-schema/rules"; | ||
| export { diffJsonSchemas } from "./json-schema/differ"; |
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,122 @@ | ||
| import type { SchemaChange } from "../types"; | ||
|
|
||
| type JsonSchemaObject = { | ||
| type?: string; | ||
| properties?: Record<string, JsonSchemaObject>; | ||
| required?: string[]; | ||
| [key: string]: any; | ||
| }; | ||
|
|
||
| const hasProperties = (schema: JsonSchemaObject): boolean => | ||
| !!(schema.properties || schema.required); | ||
|
|
||
| export const diffJsonSchemas = ( | ||
| before: JsonSchemaObject, | ||
| after: JsonSchemaObject, | ||
| ): SchemaChange[] => { | ||
| const changes: SchemaChange[] = []; | ||
|
|
||
| // Detect root-level type changes | ||
| if (before.type && after.type && before.type !== after.type) { | ||
| changes.push({ | ||
| type: "TYPE_CHANGED", | ||
| field: "(root)", | ||
| message: `Root type changed from '${before.type}' to '${after.type}'`, | ||
| previousType: before.type, | ||
| currentType: after.type, | ||
| }); | ||
| } | ||
|
|
||
| compareProperties(before, after, "", changes); | ||
| return changes; | ||
| }; | ||
|
|
||
| const compareProperties = ( | ||
| before: JsonSchemaObject, | ||
| after: JsonSchemaObject, | ||
| prefix: string, | ||
| changes: SchemaChange[], | ||
| ): void => { | ||
| const beforeProps = before.properties || {}; | ||
| const afterProps = after.properties || {}; | ||
| const beforeRequired = new Set(before.required || []); | ||
| const afterRequired = new Set(after.required || []); | ||
|
|
||
| const allFields = new Set([ | ||
| ...Object.keys(beforeProps), | ||
| ...Object.keys(afterProps), | ||
| ]); | ||
|
|
||
| for (const field of allFields) { | ||
| const fullPath = prefix ? `${prefix}.${field}` : field; | ||
| const inBefore = field in beforeProps; | ||
| const inAfter = field in afterProps; | ||
|
|
||
| if (!inBefore && inAfter) { | ||
| const isRequired = afterRequired.has(field); | ||
| changes.push({ | ||
| type: isRequired ? "FIELD_ADDED_REQUIRED" : "FIELD_ADDED_OPTIONAL", | ||
| field: fullPath, | ||
| message: `${isRequired ? "Required" : "Optional"} field '${fullPath}' was added`, | ||
| }); | ||
| continue; | ||
| } | ||
|
|
||
| if (inBefore && !inAfter) { | ||
| const wasRequired = beforeRequired.has(field); | ||
| changes.push({ | ||
| type: wasRequired ? "FIELD_REMOVED_REQUIRED" : "FIELD_REMOVED_OPTIONAL", | ||
| field: fullPath, | ||
| message: `${wasRequired ? "Required" : "Optional"} field '${fullPath}' was removed`, | ||
| }); | ||
| continue; | ||
| } | ||
|
|
||
| // Field exists in both — check type | ||
| const beforeType = beforeProps[field].type; | ||
| const afterType = afterProps[field].type; | ||
|
|
||
| if (beforeType && afterType && beforeType !== afterType) { | ||
boyney123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| changes.push({ | ||
| type: "TYPE_CHANGED", | ||
| field: fullPath, | ||
| message: `Field '${fullPath}' type changed from '${beforeType}' to '${afterType}'`, | ||
| previousType: beforeType, | ||
| currentType: afterType, | ||
| }); | ||
| } | ||
|
|
||
| // Check required status change | ||
| const wasPreviouslyRequired = beforeRequired.has(field); | ||
| const isNowRequired = afterRequired.has(field); | ||
|
|
||
| if (!wasPreviouslyRequired && isNowRequired) { | ||
| changes.push({ | ||
| type: "REQUIRED_ADDED", | ||
| field: fullPath, | ||
| message: `Field '${fullPath}' was made required`, | ||
| }); | ||
| } else if (wasPreviouslyRequired && !isNowRequired) { | ||
| changes.push({ | ||
| type: "REQUIRED_REMOVED", | ||
| field: fullPath, | ||
| message: `Field '${fullPath}' was made optional`, | ||
| }); | ||
| } | ||
|
|
||
| // Recurse into nested objects (explicit type or implicit via properties/required) | ||
| if ( | ||
| beforeProps[field].type === "object" || | ||
| afterProps[field].type === "object" || | ||
| hasProperties(beforeProps[field]) || | ||
| hasProperties(afterProps[field]) | ||
| ) { | ||
| compareProperties( | ||
| beforeProps[field], | ||
| afterProps[field], | ||
| fullPath, | ||
| changes, | ||
| ); | ||
| } | ||
| } | ||
| }; | ||
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,44 @@ | ||
| import type { | ||
| CompatibilityStrategy, | ||
| SchemaChange, | ||
| BreakingChange, | ||
| SchemaChangeType, | ||
| } from "../types"; | ||
| import { diffJsonSchemas } from "./differ"; | ||
|
|
||
| const BREAKING_RULES: Record<CompatibilityStrategy, Set<SchemaChangeType>> = { | ||
| BACKWARD: new Set([ | ||
| "FIELD_ADDED_REQUIRED", | ||
| "FIELD_REMOVED_REQUIRED", | ||
| "TYPE_CHANGED", | ||
| "REQUIRED_ADDED", | ||
| ]), | ||
| FORWARD: new Set([ | ||
| "FIELD_ADDED_REQUIRED", | ||
| "FIELD_REMOVED_REQUIRED", | ||
| "TYPE_CHANGED", | ||
| "REQUIRED_ADDED", | ||
| ]), | ||
| FULL: new Set([ | ||
| "FIELD_ADDED_REQUIRED", | ||
| "FIELD_REMOVED_REQUIRED", | ||
| "TYPE_CHANGED", | ||
| "REQUIRED_ADDED", | ||
| ]), | ||
| NONE: new Set(), | ||
| }; | ||
|
|
||
| export const detectBreakingChanges = ( | ||
| before: object, | ||
| after: object, | ||
| strategy: CompatibilityStrategy, | ||
| ): BreakingChange[] => { | ||
| if (strategy === "NONE") return []; | ||
|
|
||
| const changes = diffJsonSchemas(before, after); | ||
| const breakingTypes = BREAKING_RULES[strategy]; | ||
|
|
||
| return changes | ||
| .filter((change) => breakingTypes.has(change.type)) | ||
| .map((change) => ({ ...change, breaking: true as const })); | ||
| }; |
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,73 @@ | ||
| import { describe, it, expect } from "vitest"; | ||
| import { detectBreakingChanges, diffJsonSchemas } from "../index"; | ||
|
|
||
| describe("public API", () => { | ||
| it("detectBreakingChanges returns breaking changes for a real schema evolution", () => { | ||
| const v1 = { | ||
| type: "object", | ||
| properties: { | ||
| orderId: { type: "string" }, | ||
| amount: { type: "string" }, | ||
| currency: { type: "string" }, | ||
| }, | ||
| required: ["orderId", "amount"], | ||
| }; | ||
|
|
||
| const v2 = { | ||
| type: "object", | ||
| properties: { | ||
| orderId: { type: "string" }, | ||
| amount: { type: "number" }, | ||
| currency: { type: "string" }, | ||
| region: { type: "string" }, | ||
| }, | ||
| required: ["orderId", "amount", "region"], | ||
| }; | ||
|
|
||
| const result = detectBreakingChanges(v1, v2, "BACKWARD"); | ||
|
|
||
| expect(result).toContainEqual( | ||
| expect.objectContaining({ | ||
| type: "TYPE_CHANGED", | ||
| field: "amount", | ||
| breaking: true, | ||
| }), | ||
| ); | ||
| expect(result).toContainEqual( | ||
| expect.objectContaining({ | ||
| type: "FIELD_ADDED_REQUIRED", | ||
| field: "region", | ||
| breaking: true, | ||
| }), | ||
| ); | ||
| expect(result).toHaveLength(2); | ||
| }); | ||
|
|
||
| it("diffJsonSchemas is exported and returns all changes", () => { | ||
| const before = { | ||
| type: "object", | ||
| properties: { name: { type: "string" } }, | ||
| }; | ||
| const after = { | ||
| type: "object", | ||
| properties: { name: { type: "number" } }, | ||
| }; | ||
|
|
||
| const changes = diffJsonSchemas(before, after); | ||
| expect(changes).toHaveLength(1); | ||
| expect(changes[0].type).toBe("TYPE_CHANGED"); | ||
| }); | ||
|
|
||
| it("NONE strategy always returns empty", () => { | ||
| const result = detectBreakingChanges( | ||
| { | ||
| type: "object", | ||
| properties: { a: { type: "string" } }, | ||
| required: ["a"], | ||
| }, | ||
| { type: "object" }, | ||
| "NONE", | ||
| ); | ||
| expect(result).toEqual([]); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.