Skip to content

feat(codegen-verification) :Add cross-format verification tests for four targets (TypeScript, JSON Schema, GraphQL and Protobuf)#244

Open
apoorv7g wants to merge 5 commits into
accordproject:mainfrom
apoorv7g:fork-main
Open

feat(codegen-verification) :Add cross-format verification tests for four targets (TypeScript, JSON Schema, GraphQL and Protobuf)#244
apoorv7g wants to merge 5 commits into
accordproject:mainfrom
apoorv7g:fork-main

Conversation

@apoorv7g

@apoorv7g apoorv7g commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Adds end-to-end verification tests that generate output from real Concerto models and validate it with format-specific tooling (Ajv, GraphQL parser, protobufjs, tsc). Fixes GraphQL and Protobuf visitors so models with empty enums and abstract types

Changes

  • Add a shared verification test harness (test/verification/cases.js) with reusable model fixtures (metamodel, hr_base, hr_integration, stringlength, model-base, agreement, circular) and a test:verify npm script
  • Add format-specific verification suites that generate code and assert it compiles or parses:
    • JSON Schema → Ajv (jsonschema.validate.test.js)
    • GraphQL → graphql parser (graphql.parse.test.js)
    • Protobuf → protobufjs (protobuf.parse.test.js)
    • TypeScript → tsc (typescript.compile.test.js)
  • Fix GraphQLVisitor to emit distinct placeholders for empty types vs. empty enums (_: Boolean for object types, _ for enums) so generated SDL satisfies the GraphQL spec ref: The ability to represent empty objects graphql/graphql-spec#568 (comment)
  • Enhance ProtobufVisitor to emit marker messages for abstract types, handle map fields with map<key, value> syntax, and improve enum/empty-type generation
  • Add and extend unit tests for GraphQL and Protobuf visitors; update expected .proto fixtures and codegen snapshots

Flags

  • Empty Concerto enums are valid CTO but have no direct equivalent in JSON Schema, GraphQL, or Protobuf, each visitor uses a format-specific workaround (JSON Schema: not: {}; GraphQL: placeholder enum member _; Protobuf: empty enum / marker message)
  • Verification tests enable ENABLE_MAP_TYPE and IMPORT_ALIASING to match real-world codegen usage; some fixtures previously required skips that are no longer needed after these fixes
  • Protobuf map key types remain constrained by Proto3 (e.g. scalar map keys like SSN may still need follow-up if used as map keys in user models, the current workaround in this PR being changing to type string)

Testing

run npm run test:verify to confirm all 28 verification cases pass.

Author Checklist

  • Ensure you provide a DCO sign-off for your commits using the --signoff option of git commit.
  • Vital features and changes captured in unit and/or integration tests
  • Commits messages follow AP format
  • Extend the documentation, if necessary
  • Merging to main from fork:branchname

apoorv7g added 5 commits June 4, 2026 08:38
… schema generation

- Added 'NONE' value to the Level enum in the model definition.
- Removed $id assignment for inlined map schemas to prevent conflicts in JSON schema generation.
- Updated related test snapshots to reflect changes in the Level enum.

Signed-off-by:  Apoorv <130035517+APOORV7G@users.noreply.github.com>
Signed-off-by: Apoorv <130035517+APOORV7G@users.noreply.github.com>
…N schema generation

- Introduced tests to verify the correct handling of non-empty enums, ensuring they emit valid values and compile with Ajv.
- Added a test to confirm that schemas with empty enums fail Ajv compilation as expected.
- Updated the JSON schema visitor to accommodate these new test cases.

Signed-off-by: Apoorv <130035517+APOORV7G@users.noreply.github.com>
- Updated the JSONSchemaVisitor to correctly handle empty enums by using the 'not' keyword instead of an empty 'enum' array.
- rewrote tests to verify that schemas with empty enums compile successfully with Ajv.

Signed-off-by: Apoorv <130035517+APOORV7G@users.noreply.github.com>
…ss multiple formats

- Introduced new test files for GraphQL, JSON Schema, Protobuf, and TypeScript to verify the correctness of model generation.
- Each test case checks that the generated output compiles and parses correctly, ensuring robust verification of the code generation process.
- Implemented a shared utility for managing test cases and environment setup.

Signed-off-by: Apoorv <130035517+APOORV7G@users.noreply.github.com>
…and enums

- Updated GraphQLVisitor to write placeholder members for empty enums and types, ensuring compliance with GraphQL specifications.
- Enhanced ProtobufVisitor to emit empty marker messages for abstract types and correctly handle map types in generated Protobuf definitions.
- Added tests to verify the correct behavior of these enhancements, ensuring robust code generation across formats.

Signed-off-by: Apoorv <130035517+APOORV7G@users.noreply.github.com>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this problem a bit more? Why would this break Ajv? shouldn't all nextOfKin FQNs be the same?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are correct. All nextOfKin FQNs are same as they are inherited fields. When the previous visitor was building the JSON Schema , it gave $id to all of these four ( Person and the three inherited - > Employee, Contractor and Manager ). Ajv uses $id for $ref resolution and this will break with with same $id being repeated multiple times as FQNs is used to build the IDs. So that fix is workable as they are inline and not top level definitions.

@ekarademir ekarademir left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove the protobuf changes at least. Maybe even JSONSchema changes as well. Le'ts also add the actual CI with just the targets you've created tests for so that this PR starts the actual verification.


let key = ModelUtil.isPrimitiveType(keyType) ? this.concertoToProto3PrimitiveType(keyType) : keyType;
let value = ModelUtil.isPrimitiveType(valueType) ? this.concertoToProto3PrimitiveType(valueType) : valueType;
const key = this.concertoToProto3MapType(mapDeclaration.getKey(), mapDeclaration, true);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic change is not 1:1. It's converting the DateTime to string, but the previous logic would convert that to google.protobuf.Timestamp

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will read more about this.

Comment thread lib/codegen/fromcto/protobuf/protobufvisitor.js
}

describe('verification', function () {
this.timeout(60000);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need 10 mins? I think 2 mins would be more than generous.

@apoorv7g apoorv7g Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I just wanted to be safe. We will stick to 2 mins.
Edit : That is 1 minute. Do you want me to extend it to 2 mins?

@apoorv7g

apoorv7g commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

@ekarademir I will create a new PR with 2 Targets with the CI checks so actual verification starts happening. I will create issues and resolve those issues for Protobuf and GraphQL and then add them to the checks.

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.

2 participants