From 2aedc008601a63519c6835bb003f1a6ecd5f8449 Mon Sep 17 00:00:00 2001 From: Matt Roberts Date: Mon, 13 Jul 2026 07:32:19 +0100 Subject: [PATCH 1/3] fix(concerto-core): serialize maps with cross-namespace concept values Map (de)serialization resolved the value concept's declaration only within the map's own model file. When the value concept is imported from another namespace the lookup returned undefined, so: - Serializer.toJSON threw "Cannot read properties of undefined (reading 'accept')", and - Serializer.fromJSON silently returned the raw JSON object instead of a populated Concept (breaking round-trips). Resolve the value declaration across all loaded models: toJSON now resolves the map's declared value type honouring imports via the ModelManager, and the populator searches declarations across every model file. Co-Authored-By: Claude Opus 4.8 Signed-off-by: Matt Roberts --- .../src/serializer/jsongenerator.ts | 11 ++- .../src/serializer/jsonpopulator.ts | 14 ++-- .../test/serializer/maptype/serializer.js | 77 +++++++++++++++++++ 3 files changed, 93 insertions(+), 9 deletions(-) diff --git a/packages/concerto-core/src/serializer/jsongenerator.ts b/packages/concerto-core/src/serializer/jsongenerator.ts index 1beefa58f1..b9b4aeeb95 100644 --- a/packages/concerto-core/src/serializer/jsongenerator.ts +++ b/packages/concerto-core/src/serializer/jsongenerator.ts @@ -103,9 +103,14 @@ class JSONGenerator { // Key is always a string, but value might be a ValidatedResource. if (typeof value === 'object') { - let decl = mapDeclaration.getModelFile() - .getAllDeclarations() - .find(decl => decl.name === value.getType()); + // Resolve the map's declared value type honouring imports. The value + // concept may be declared in another namespace, so it is not + // necessarily present in the map's own model file; resolve it by its + // fully-qualified name via the model manager instead. + const modelFile = mapDeclaration.getModelFile(); + const decl = modelFile.getModelManager().getType( + modelFile.getFullyQualifiedTypeName(mapDeclaration.getValue().getType()) + ); // convert declaration to JSON representation parameters.stack.push(value); diff --git a/packages/concerto-core/src/serializer/jsonpopulator.ts b/packages/concerto-core/src/serializer/jsonpopulator.ts index b5cc8aebde..d90286ea6a 100644 --- a/packages/concerto-core/src/serializer/jsonpopulator.ts +++ b/packages/concerto-core/src/serializer/jsonpopulator.ts @@ -245,16 +245,18 @@ class JSONPopulator { */ processMapType(mapDeclaration, parameters: JsonPopulatorParameters, value, type) { let decl; + // Search declarations across all loaded models: the map's value concept may + // be imported from another namespace and therefore is not present in the + // map's own model file. + const declarations = mapDeclaration.getModelFile().getModelManager() + .getModelFiles() + .flatMap(modelFile => modelFile.getAllDeclarations()); if (value && typeof value === 'object' && value.$class) { // Use the $class property to find the class declaration - decl = mapDeclaration.getModelFile() - .getAllDeclarations() - .find(decl => decl.getFullyQualifiedName() === value.$class); + decl = declarations.find(decl => decl.getFullyQualifiedName() === value.$class); } else { // Fallback to the original type lookup if value is not an object or doesn't have $class - decl = mapDeclaration.getModelFile() - .getAllDeclarations() - .find(decl => decl.name === type); + decl = declarations.find(decl => decl.name === type); } // if its a ClassDeclaration, populate the Concept. diff --git a/packages/concerto-core/test/serializer/maptype/serializer.js b/packages/concerto-core/test/serializer/maptype/serializer.js index 6dd4597a08..b137d1493d 100644 --- a/packages/concerto-core/test/serializer/maptype/serializer.js +++ b/packages/concerto-core/test/serializer/maptype/serializer.js @@ -1027,5 +1027,82 @@ describe('Serializer', () => { }).should.throw('Unexpected properties for type org.acme.sample@1.0.0.Concepts: stateLog'); }); }); + + describe('# cross-namespace concept values in maps', () => { + let xnsModelManager; + let xnsFactory; + let xnsSerializer; + + beforeEach(() => { + xnsModelManager = new ModelManager(); + Util.addComposerModel(xnsModelManager); + + // the value concept lives in its own namespace + xnsModelManager.addCTOModel(` + namespace org.acme.unit@1.0.0 + + concept MonetaryUnit { + o String code + o Integer scale + } + `, 'unit.cto'); + + // the map (and its container) live in a different namespace and + // import the value concept + xnsModelManager.addCTOModel(` + namespace org.acme.registry@1.0.0 + + import org.acme.unit@1.0.0.{MonetaryUnit} + + map UnitMap { + o String + o MonetaryUnit + } + + concept Registry { + o UnitMap units optional + } + `, 'registry.cto'); + + xnsFactory = new Factory(xnsModelManager); + xnsSerializer = new Serializer(xnsFactory, xnsModelManager); + }); + + it('should serialize -> deserialize a Map whose value concept is imported from another namespace', () => { + const registry = xnsFactory.newConcept('org.acme.registry@1.0.0', 'Registry'); + + const usd = xnsFactory.newConcept('org.acme.unit@1.0.0', 'MonetaryUnit'); + usd.code = 'USD'; + usd.scale = 2; + const jpy = xnsFactory.newConcept('org.acme.unit@1.0.0', 'MonetaryUnit'); + jpy.code = 'JPY'; + jpy.scale = 0; + + registry.units = new Map(); + registry.units.set('USD', usd); + registry.units.set('JPY', jpy); + + // previously threw: TypeError: Cannot read properties of undefined (reading 'accept') + // because the value declaration was looked up only in the map's own model file. + const json = xnsSerializer.toJSON(registry); + + json.should.deep.equal({ + $class: 'org.acme.registry@1.0.0.Registry', + units: { + USD: { $class: 'org.acme.unit@1.0.0.MonetaryUnit', code: 'USD', scale: 2 }, + JPY: { $class: 'org.acme.unit@1.0.0.MonetaryUnit', code: 'JPY', scale: 0 } + } + }); + + const resource = xnsSerializer.fromJSON(json); + resource.units.should.be.an.instanceOf(Map); + resource.units.get('USD').code.should.equal('USD'); + resource.units.get('USD').scale.should.equal(2); + resource.units.get('JPY').scale.should.equal(0); + + // round-trips back to the same JSON + xnsSerializer.toJSON(resource).should.deep.equal(json); + }); + }); }); From d885e904280e588dd8c90932ca8d7966fddd99c7 Mon Sep 17 00:00:00 2001 From: Matt Roberts Date: Mon, 13 Jul 2026 09:50:46 +0100 Subject: [PATCH 2/3] fix(concerto-core): address review feedback and de-flake external URL test Review feedback (Copilot): - jsongenerator: resolve the map value declaration from the instance's own fully-qualified type when available (preserving polymorphism for subclass values), falling back to the map's declared value type (honouring imports) for instances that do not expose a fully-qualified type. - jsonpopulator: resolve the key/value declaration via the model manager using the map model file's import-aware fully-qualified name, wrapped in try/catch to preserve the previous "not found => treat as scalar" behaviour, instead of scanning every declaration by short name (which could match the wrong namespace or misclassify a scalar). Build/CI fix: - modelmanager test: assert the stable failure message for a bad github:// URL with a regex instead of pinning HTTP status 400, since GitHub now returns 404 for the missing resource, causing an unrelated CI failure. Co-Authored-By: Claude Opus 4.8 Signed-off-by: Matt Roberts --- .../src/serializer/jsongenerator.ts | 19 +++++++----- .../src/serializer/jsonpopulator.ts | 29 +++++++++++-------- packages/concerto-core/test/modelmanager.js | 6 ++-- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/packages/concerto-core/src/serializer/jsongenerator.ts b/packages/concerto-core/src/serializer/jsongenerator.ts index b9b4aeeb95..3f78314b50 100644 --- a/packages/concerto-core/src/serializer/jsongenerator.ts +++ b/packages/concerto-core/src/serializer/jsongenerator.ts @@ -103,14 +103,19 @@ class JSONGenerator { // Key is always a string, but value might be a ValidatedResource. if (typeof value === 'object') { - // Resolve the map's declared value type honouring imports. The value - // concept may be declared in another namespace, so it is not - // necessarily present in the map's own model file; resolve it by its - // fully-qualified name via the model manager instead. + // Resolve the declaration for the map value. Prefer the instance's + // own fully-qualified type so that polymorphic values (subclasses of + // the map's declared value type) are serialized using their actual + // declaration. Fall back to the map's declared value type - honouring + // imports - for instances that do not expose a fully-qualified type + // (e.g. those created by the populator). Either way the value concept + // may live in another namespace, so resolve it via the model manager + // rather than the map's own model file. const modelFile = mapDeclaration.getModelFile(); - const decl = modelFile.getModelManager().getType( - modelFile.getFullyQualifiedTypeName(mapDeclaration.getValue().getType()) - ); + const valueType = typeof value.getFullyQualifiedType === 'function' + ? value.getFullyQualifiedType() + : modelFile.getFullyQualifiedTypeName(mapDeclaration.getValue().getType()); + const decl = modelFile.getModelManager().getType(valueType); // convert declaration to JSON representation parameters.stack.push(value); diff --git a/packages/concerto-core/src/serializer/jsonpopulator.ts b/packages/concerto-core/src/serializer/jsonpopulator.ts index d90286ea6a..e48380af1c 100644 --- a/packages/concerto-core/src/serializer/jsonpopulator.ts +++ b/packages/concerto-core/src/serializer/jsonpopulator.ts @@ -245,18 +245,23 @@ class JSONPopulator { */ processMapType(mapDeclaration, parameters: JsonPopulatorParameters, value, type) { let decl; - // Search declarations across all loaded models: the map's value concept may - // be imported from another namespace and therefore is not present in the - // map's own model file. - const declarations = mapDeclaration.getModelFile().getModelManager() - .getModelFiles() - .flatMap(modelFile => modelFile.getAllDeclarations()); - if (value && typeof value === 'object' && value.$class) { - // Use the $class property to find the class declaration - decl = declarations.find(decl => decl.getFullyQualifiedName() === value.$class); - } else { - // Fallback to the original type lookup if value is not an object or doesn't have $class - decl = declarations.find(decl => decl.name === type); + // The map's key/value concept may be imported from another namespace, so it + // is not necessarily present in the map's own model file. Resolve it via the + // model manager (which spans all loaded models). A failed lookup means the + // type is a scalar/primitive and the raw value is returned as-is, preserving + // the previous "not found => treat as scalar" behaviour. + const modelFile = mapDeclaration.getModelFile(); + const modelManager = modelFile.getModelManager(); + try { + if (value && typeof value === 'object' && value.$class) { + // The $class property is already fully-qualified. + decl = modelManager.getType(value.$class); + } else { + // Resolve the declared type honouring the map model file's imports. + decl = modelManager.getType(modelFile.getFullyQualifiedTypeName(type)); + } + } catch (err) { + decl = undefined; } // if its a ClassDeclaration, populate the Concept. diff --git a/packages/concerto-core/test/modelmanager.js b/packages/concerto-core/test/modelmanager.js index 8f1848f15c..5ac2e2b9d5 100644 --- a/packages/concerto-core/test/modelmanager.js +++ b/packages/concerto-core/test/modelmanager.js @@ -723,8 +723,10 @@ concept Bar { }`, 'internal.cto', true); modelManager.getModelFile('org.acme@1.0.0').should.not.be.null; - // import all external models - return modelManager.updateExternalModels().should.be.rejectedWith(Error, 'Failed to load model file. Job: github://external.cto Details: Error: HTTP request failed with status: 400'); + // import all external models. The exact HTTP status returned by GitHub + // for the bad URL can vary (e.g. 400 vs 404), so assert on the stable + // failure message rather than pinning a specific status code. + return modelManager.updateExternalModels().should.be.rejectedWith(Error, /Failed to load model file\. Job: github:\/\/external\.cto Details: Error: HTTP request failed with status: \d+/); }); it('should fail using bad protocol and default model file loader', () => { From 16e8a968f8a8c0dd2ceac8131ac251110a2a3e82 Mon Sep 17 00:00:00 2001 From: Matt Roberts Date: Mon, 13 Jul 2026 12:18:21 +0100 Subject: [PATCH 3/3] ci: don't fail Code Coverage check when Coveralls webhook is unavailable The "Coveralls Finished" (parallel-finished) step blocked PRs whenever the Coveralls webhook returned a 5xx/timeout, even though coverage was computed and uploaded successfully per-matrix. Add fail-on-error: false to match the existing per-matrix upload step so external Coveralls outages no longer block CI. Co-Authored-By: Claude Opus 4.8 Signed-off-by: Matt Roberts --- .github/workflows/build.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 03d1a272b1..583a48c786 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -79,3 +79,7 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} parallel-finished: true + # Don't block the PR when the Coveralls webhook is unavailable (e.g. + # 5xx/timeout). Coverage is still uploaded per-matrix above, which also + # uses fail-on-error: false. + fail-on-error: false