Skip to content

fix(codegen): update references to Category class in code generation …#241

Merged
mttrbrts merged 1 commit into
accordproject:mainfrom
apoorv7g:fix-#237
Jun 1, 2026
Merged

fix(codegen): update references to Category class in code generation …#241
mttrbrts merged 1 commit into
accordproject:mainfrom
apoorv7g:fix-#237

Conversation

@apoorv7g
Copy link
Copy Markdown
Contributor

@apoorv7g apoorv7g commented Jun 1, 2026

fix(test): resolve duplicate ICategory in HR fixture models

Closes #237

Fixes TypeScript compile failures for the canonical HR integration fixtures (hr_base.cto + hr.cto) by removing a duplicate Category concept in the hr namespace. Both models previously emitted ICategory, which caused tsc to fail with duplicate identifier errors in concerto@1.0.0.ts.

Changes

  • Import Category from org.acme.hr.base@1.0.0 in hr.cto instead of defining a local concept Category {}
  • Update codegen and graph test snapshots to reflect the single shared Category type across both namespaces

How to Test

const fs = require('fs');
const path = require('path');
const { execFileSync } = require('child_process');
const { ModelManager } = require('@accordproject/concerto-core');
const { FileWriter } = require('@accordproject/concerto-util');
const TypescriptVisitor = require('./lib/codegen/fromcto/typescript/typescriptvisitor.js');
process.env.ENABLE_MAP_TYPE = 'true';
process.env.IMPORT_ALIASING = 'true';
const out = path.join(__dirname, 'tmp-ts-repro');
fs.rmSync(out, { recursive: true, force: true });
fs.mkdirSync(out, { recursive: true });
const dir = './test/codegen/fromcto/data/model';
const mm = new ModelManager();
mm.addCTOModel(fs.readFileSync(dir + '/hr_base.cto', 'utf8'), 'hr_base.cto');
mm.addCTOModel(fs.readFileSync(dir + '/hr.cto', 'utf8'), 'hr.cto');
mm.accept(new TypescriptVisitor(), { fileWriter: new FileWriter(out), showCompositionRelationships: true });
fs.writeFileSync(path.join(out, 'tsconfig.json'), JSON.stringify({
  compilerOptions: { target: 'es2016', module: 'commonjs', strict: true, skipLibCheck: true, noEmit: true, esModuleInterop: true },
  include: ['**/*.ts']
}));
execFileSync(process.execPath, [path.join(__dirname, 'node_modules/typescript/bin/tsc'), '-p', out], { stdio: 'inherit' });
console.log('TypeScript compile succeeded');

This shall output -> TypeScript compile succeeded
Also run Targeted tests

npm run mocha -- test/codegen/codegen.js
npm run mocha -- test/common/graph.js
npm run mocha -- test/codegen/fromcto/typescript/typescriptvisitor.js

Flags

Screenshots or Video

Before (tsc failure):

concerto@1.0.0.ts(8,2): error TS2300: Duplicate identifier 'ICategory'.
concerto@1.0.0.ts(15,2): error TS2300: Duplicate identifier 'ICategory'.

After: the repro script exits 0 and npm test passes (586 tests).

Related Issues

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 [ not necessary , skipped ]
  • Merging to main from fork:branchname [ shall be done from future PRs ]

Copilot AI review requested due to automatic review settings June 1, 2026 05:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates the HR test model to reuse Category from the org.acme.hr.base@1.0.0 namespace (instead of defining a local Category concept), and refreshes expected snapshots to reflect the updated type ownership and dependency graph edges.

Changes:

  • Import Category from org.acme.hr.base@1.0.0 and remove the local Category concept from the HR CTO fixture.
  • Update graph visitor snapshots to point pii/Info relationships to org.acme.hr.base@1.0.0.Category.
  • Update codegen snapshots across formats to remove the generated org.acme.hr@1.0.0.Category artifacts and reference the base Category instead.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
test/common/snapshots/graph.js.snap Updates expected dependency graph edges to reference org.acme.hr.base@1.0.0.Category.
test/codegen/fromcto/data/model/hr.cto Switches Category to an imported base type and removes the local Category concept fixture.
test/codegen/snapshots/codegen.js.snap Refreshes multi-format codegen expectations to reflect Category coming from the base namespace.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…and model files

Signed-off-by: Apoorv <130035517+APOORV7G@users.noreply.github.com>
@apoorv7g apoorv7g closed this Jun 1, 2026
@apoorv7g apoorv7g deleted the fix-#237 branch June 1, 2026 05:50
@apoorv7g apoorv7g restored the fix-#237 branch June 1, 2026 05:50
@apoorv7g apoorv7g reopened this Jun 1, 2026
@apoorv7g
Copy link
Copy Markdown
Contributor Author

apoorv7g commented Jun 1, 2026

@mttrbrts Can you look into it once and approve the workflows?

@mttrbrts
Copy link
Copy Markdown
Member

mttrbrts commented Jun 1, 2026

Approved to unblock the build. But this is an edge case that we should have a test for.

Can you / @muhabdulkadir create a ticket to track?

@mttrbrts mttrbrts enabled auto-merge (squash) June 1, 2026 10:30
@mttrbrts mttrbrts merged commit 0e03293 into accordproject:main Jun 1, 2026
11 checks passed
@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 98.237%. remained the same — apoorv7g:fix-#237 into accordproject:main

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.

bug: generated TypeScript for hr_base.cto + hr.cto fails tsc (blocks compile verification) [ gsoc 2026, code-gen compilation ]

4 participants