Repository navigation
fix(core): tighten component matching, diff line budget and relationship deduplication #409
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
10 commits
Select commit
Hold shift + click to select a range
e74fcc3
fix(core): match component ids as whole tokens in component selection
parse cfab14e
fix(core): raise Anthropic small output budget to 1500 tokens
parse 9910bdf
fix(core): match excludePaths on component path segments, not string …
parse a5deac8
fix(core): include kind when checking for duplicate relationships
parse b5dbf0d
fix(core): keep quoted text in Structurizr strings instead of strippi…
parse c2beac2
fix(core): enforce maxLinesPerDiff by dropping files past the line bu…
parse 3a228df
fix(core): throw when a prompt template references a missing variable
parse ff29575
refactor(core): simplify template rendering helper
parse 7f89823
fix(core): address review findings in small correctness fixes
parse 5780a2c
fix(core): address review findings on line budget and relationship kinds
parse 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 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
76 changes: 76 additions & 0 deletions
76
packages/core/src/adapters/likec4/__tests__/deduplicate-relationships.test.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,76 @@ | ||
| import { describe, it, expect } from 'vitest'; | ||
| import { LikeC4Patcher } from '../patcher.js'; | ||
| import type { PatchResult } from '../../model-patcher.js'; | ||
| import type { ModelRelationship } from '../../architecture-types.js'; | ||
|
|
||
| class TestPatcher extends LikeC4Patcher { | ||
| public dedupe( | ||
| valid: { source: string; target: string; kind?: string; description: string }[], | ||
| existing: ModelRelationship[] | ||
| ) { | ||
| const skipped: PatchResult['skipped'] = []; | ||
| return { kept: this.deduplicateRelationships(valid, existing, skipped), skipped }; | ||
| } | ||
| } | ||
|
|
||
| describe('deduplicateRelationships', () => { | ||
| const patcher = new TestPatcher(); | ||
| const rel = (kind?: string) => ({ source: 'api', target: 'db', kind, description: 'x' }); | ||
|
|
||
| it('keeps a relationship when both have a kind and the kinds differ', () => { | ||
| const { kept } = patcher.dedupe( | ||
| [rel('async')], | ||
| [ | ||
| { source: 'api', target: 'db', kind: 'sync' }, | ||
| { source: 'web', target: 'api', kind: 'async' }, | ||
| ] | ||
| ); | ||
| expect(kept).toHaveLength(1); | ||
| }); | ||
|
|
||
| it('treats a kind the model does not define as no kind, so it is a duplicate', () => { | ||
| const { kept, skipped } = patcher.dedupe( | ||
| [rel('grpc')], | ||
| [{ source: 'api', target: 'db', kind: 'sync' }] | ||
| ); | ||
| expect(kept).toHaveLength(0); | ||
| expect(skipped).toHaveLength(1); | ||
| }); | ||
|
|
||
| it('drops a relationship when the existing one has no kind', () => { | ||
| const { kept } = patcher.dedupe([rel('async')], [{ source: 'api', target: 'db' }]); | ||
| expect(kept).toHaveLength(0); | ||
| }); | ||
|
|
||
| it('applies the kind rule to bidirectional relationships too', () => { | ||
| const reverse = { source: 'db', target: 'api', kind: 'async', description: 'x' }; | ||
| const existing = { source: 'api', target: 'db', bidirectional: true }; | ||
| const asyncElsewhere = { source: 'web', target: 'api', kind: 'async' }; | ||
| expect( | ||
| patcher.dedupe([reverse], [{ ...existing, kind: 'sync' }, asyncElsewhere]).kept | ||
| ).toHaveLength(1); | ||
| expect(patcher.dedupe([reverse], [existing]).kept).toHaveLength(0); | ||
| }); | ||
|
|
||
| it('drops a relationship with the same kind', () => { | ||
| const { kept, skipped } = patcher.dedupe( | ||
| [rel('async')], | ||
| [{ source: 'api', target: 'db', kind: 'async' }] | ||
| ); | ||
| expect(kept).toHaveLength(0); | ||
| expect(skipped).toHaveLength(1); | ||
| }); | ||
|
|
||
| it('drops a kindless relationship when any relationship exists between the pair', () => { | ||
| const { kept } = patcher.dedupe([rel()], [{ source: 'api', target: 'db', kind: 'async' }]); | ||
| expect(kept).toHaveLength(0); | ||
| }); | ||
|
|
||
| it('still honours bidirectional existing relationships', () => { | ||
| const { kept } = patcher.dedupe( | ||
| [{ source: 'db', target: 'api', description: 'x' }], | ||
| [{ source: 'api', target: 'db', bidirectional: true }] | ||
| ); | ||
| expect(kept).toHaveLength(0); | ||
| }); | ||
| }); |
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
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,18 @@ | ||
| import type { ModelRelationship } from './architecture-types.js'; | ||
|
|
||
| /** Relationship kinds declared by the model's existing relationships. */ | ||
| export function knownRelationshipKinds(existing: readonly ModelRelationship[]): Set<string> { | ||
| return new Set(existing.map((r) => r.kind).filter((k): k is string => Boolean(k))); | ||
| } | ||
|
|
||
| /** | ||
| * The kind a proposed relationship is written with. A kind the model does not use is written | ||
| * as a plain relationship, so it resolves to undefined. Dedup and the writer both go through | ||
| * this so they agree on what ends up in the file. | ||
| */ | ||
| export function resolveRelationshipKind( | ||
| kind: string | undefined, | ||
| knownKinds: ReadonlySet<string> | ||
| ): string | undefined { | ||
| return kind && knownKinds.has(kind) ? kind : undefined; | ||
| } |
23 changes: 23 additions & 0 deletions
23
packages/core/src/adapters/structurizr/__tests__/deduplicate-relationships.test.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,23 @@ | ||
| import { describe, it, expect } from 'vitest'; | ||
| import { StructurizrPatcher } from '../patcher.js'; | ||
| import type { PatchResult } from '../../model-patcher.js'; | ||
|
|
||
| class TestPatcher extends StructurizrPatcher { | ||
| public dedupe( | ||
| valid: { source: string; target: string; kind?: string; description: string }[], | ||
| existing: { source: string; target: string; kind?: string }[] | ||
| ) { | ||
| const skipped: PatchResult['skipped'] = []; | ||
| return { kept: this.deduplicateRelationships(valid, existing, skipped), skipped }; | ||
| } | ||
| } | ||
|
|
||
| describe('StructurizrPatcher deduplicateRelationships', () => { | ||
| it('matches on endpoints only, ignoring free-text technology in kind', () => { | ||
| const { kept } = new TestPatcher().dedupe( | ||
| [{ source: 'api', target: 'db', kind: 'async', description: 'x' }], | ||
| [{ source: 'api', target: 'db', kind: 'HTTPS' }] | ||
| ); | ||
| expect(kept).toHaveLength(0); | ||
| }); | ||
| }); |
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.
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.