accordproject/concerto

Incorrect Validation of Type Reference for Decorators

Closed this issue ยท 1 comments

Bug Report ๐Ÿ›

Type reference decorators are validated incorrectly, causing errors during parsing by the model manager. The error observed indicates that the type is unable to be fetched

The observed error indicates that the type is incorrectly flagged as undeclared within the model file, even though it is actually an imported type reference.

 IllegalModelException: Undeclared type "Level" in "Decorator level on manager". File 'hr.cto': 
      at ModelFile.resolveType (node_modules/@accordproject/concerto-core/lib/introspect/modelfile.js:318:27)
      at /Users/runner/work/concerto-codegen/concerto-codegen/node_modules/@accordproject/concerto-core/lib/introspect/decorator.js:103:16
      at Array.forEach (<anonymous>)
      at Decorator.validate (node_modules/@accordproject/concerto-core/lib/introspect/decorator.js:101:18)
      at RelationshipDeclaration.validate (node_modules/@accordproject/concerto-core/lib/introspect/decorated.js:114:36)
      at RelationshipDeclaration.validate (node_modules/@accordproject/concerto-core/lib/introspect/property.js:139:15)
      at RelationshipDeclaration.validate (node_modules/@accordproject/concerto-core/lib/introspect/relationshipdeclaration.js:55:15)
      at ParticipantDeclaration.validate (node_modules/@accordproject/concerto-core/lib/introspect/classdeclaration.js:285:23)
      at ModelFile.validate (node_modules/@accordproject/concerto-core/lib/introspect/modelfile.js:294:30)
      at BaseModelManager.validateModelFiles (node_modules/@accordproject/concerto-core/lib/basemodelmanager.js:411:33)
      at BaseModelManager.addModelFiles (node_modules/@accordproject/concerto-core/lib/basemodelmanager.js:392:22)
      at ModelManager.filter (node_modules/@accordproject/concerto-core/lib/basemodelmanager.js:863:22)
      at Context.<anonymous> (test/common/graph.js:86:55)
      at process.processImmediate (node:internal/timers:476:21)

Expected Behavior

A type reference should be recognized as a valid type, correctly linked to its imported model, without triggering validation errors.

Current Behavior

The type reference decorator fails to pass the validation process, causing an IllegalModelException to be thrown.

Possible Solution

Steps to Reproduce

  1. Apply a type reference decorator to a model.
  2. Attempt to process the model using a model manager.
  3. Observe the decorator validation process.
  4. An IllegalModelException is thrown during validation.

Context (Environment)

Desktop

  • OS: [e.g. macOS] macOS
  • Browser: [e.g. Chrome, Safari]
  • Version: [e.g. 0.22.15] 3.19.2

Detailed Description

Possible Implementation

The cause of this bug appears to be that we filter the model manager using the dependency graph, but the dependency graph doesn't contain the edge from the decorator to the Level enum - so I think the root cause is in the dependency graph construction. We therefore throw away the Level enum but it is being used by the decorator.

I have updated concerto codegen tests here: accordproject/concerto-codegen#145 and they now pass.

I will open a new issue for the bug in the graph construction.