Skip to content

fix(concerto-analysis): route Map and Scalar declarations through dedicated comparison paths#1165

Open
yashhzd wants to merge 1 commit intoaccordproject:mainfrom
yashhzd:yashhzd/i1163/fix-compare-declaration-routing
Open

fix(concerto-analysis): route Map and Scalar declarations through dedicated comparison paths#1165
yashhzd wants to merge 1 commit intoaccordproject:mainfrom
yashhzd:yashhzd/i1163/fix-compare-declaration-routing

Conversation

@yashhzd
Copy link

@yashhzd yashhzd commented Mar 16, 2026

Summary

Fixes #1163

Compare.compareModelFiles was passing getAllDeclarations() to compareClassDeclarations, which included MapDeclaration and ScalarDeclaration instances. Since neither extends ClassDeclaration (both extend Declaration directly), this caused:

  1. Wrong finding keys — added/removed maps emitted class-declaration-added/removed instead of map-declaration-added/removed
  2. Type safety violation — custom ComparerFactory implementations received non-ClassDeclaration objects through compareClassDeclaration
  3. Unnecessary double-processing — matching map/scalar declarations were processed twice (once through the class path, once through the dedicated path)

Changes

1. compare.ts — Fix declaration routing

  • Replace a.getAllDeclarations() with a.getClassDeclarations() in compareModelFiles, so only actual ClassDeclaration subtypes are routed through compareClassDeclarations
  • Remove the instanceof MapDeclaration / instanceof ScalarDeclaration guards from compareClassDeclaration (no longer needed since these types are no longer passed in)

2. map-declarations.ts — Add missing add/remove comparers

Added mapDeclarationAdded and mapDeclarationRemoved comparer factories that emit map-declaration-added and map-declaration-removed findings respectively.

3. scalar-declarations.ts — Add missing add/remove comparers

Added scalarDeclarationAdded and scalarDeclarationRemoved comparer factories that emit scalar-declaration-added and scalar-declaration-removed findings respectively.

4. compare-config.ts — Add new rules

'map-declaration-added': CompareResult.MINOR,
'map-declaration-removed': CompareResult.MAJOR,
'scalar-declaration-added': CompareResult.MINOR,
'scalar-declaration-removed': CompareResult.MAJOR,

5. compare.test.ts — Update tests

  • Split the forEach(['asset', ..., 'map', 'scalar']) loop so that map and scalar have dedicated tests asserting the correct finding keys (map-declaration-added instead of class-declaration-added, etc.)
  • Added a test verifying that no class-declaration-* findings are emitted for map types
  • Added tests for the new config rules

Why both parts are needed

If only Part A (routing fix) were applied without Part B (new comparers), added/removed maps and scalars would produce zero findings — they'd become invisible to the comparison engine. The existing map/scalar comparers only handle type changes for matching declarations, not add/remove.

AI Disclosure

AI tools were used to assist with code analysis and drafting. All changes have been manually reviewed, verified against the codebase, and tested for correctness.

Author Checklist

  • Code follows the existing patterns in concerto-analysis
  • New comparers follow the same structure as class-declarations.ts
  • Tests updated for changed behavior
  • New tests added for new finding keys and config rules
  • Signed-off-by for DCO

…icated comparison paths

Fixes accordproject#1163

compareModelFiles was passing getAllDeclarations() to compareClassDeclarations,
which included MapDeclaration and ScalarDeclaration instances. Since neither
extends ClassDeclaration, this caused wrong finding keys (class-declaration-added
instead of map-declaration-added) and a type safety violation for custom comparers.

Changes:
- Replace getAllDeclarations() with getClassDeclarations() in compareModelFiles
- Remove instanceof MapDeclaration/ScalarDeclaration guards from
  compareClassDeclaration (no longer needed)
- Add map-declaration-added/removed comparers in map-declarations.ts
- Add scalar-declaration-added/removed comparers in scalar-declarations.ts
- Add corresponding rules in compare-config.ts
- Update tests to expect the correct finding keys for map and scalar types

Signed-off-by: Yash Goel <yashgoel553@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

concerto-analysis: Compare routes MapDeclaration and ScalarDeclaration through class-declaration comparison path

1 participant