Skip to content

fix: support versioned namespaces in CTO parser - #1084

Closed
Atharva7115 wants to merge 1 commit into
accordproject:mainfrom
Atharva7115:fix/versioned-namespace-cto
Closed

Atharva7115 wants to merge 1 commit into
accordproject:mainfrom
Atharva7115:fix/versioned-namespace-cto

Conversation

@Atharva7115

Copy link
Copy Markdown

Closes #788

This PR fixes an issue where cicero archive failed when a CTO file used a
versioned namespace (e.g. org.example@1.0.0).

Although the CTO grammar already supported versioned namespaces, the Namespace
rule returned an inconsistent AST shape for versioned namespaces, which caused
downstream consumers such as Cicero to fail. This change normalizes the namespace
AST so both versioned and unversioned namespaces behave consistently.

Changes

  • Normalize the AST returned by the Namespace grammar rule when a versioned
    namespace is used
  • Add a regression test to ensure versioned namespaces are accepted during parsing

Flags

  • No breaking changes
  • Grammar behavior is unchanged; only AST normalization is applied

Screenshots or Video

  • Not applicable (parser/grammar change)

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
  • Merging to main from fork:branchname

Signed-off-by: Atharva Chandurkar <atharvachandurkar7115@gmail.com>
@Atharva7115

Copy link
Copy Markdown
Author

Hi maintainers 👋
Thanks for taking a look at this PR.

Happy to answer any questions or make adjustments if there’s a preferred
approach for handling versioned namespaces.

Looking forward to your feedback.

@dselman

dselman commented Jan 7, 2026

Copy link
Copy Markdown
Contributor

AST changes like this are very risky. Can you provide more context on the downstream issue you are seeing that requires this change please?

@Atharva7115

Atharva7115 commented Jan 7, 2026 •

Copy link
Copy Markdown
Author

Hi @dselman — thanks for the quick response!

Let me give a bit more context about why I made this change and what issue it solves.

❗ What triggered the problem

When a CTO file uses a versioned namespace, for example:

namespace org.example@1.0.0

the parser returns an AST structure that looks slightly different from the AST produced for a normal (unversioned) namespace.

So we end up with:

Unversioned:

{ "name": "org.example" }

Versioned:

{ 
  "name": "org.example",
  "namespace": "org.example",
  "version": "1.0.0"
}

Because of this mismatch, some downstream parts of Cicero expect one format but receive the other. This leads to missing fields, unexpected shapes, or undefined errors depending on what the consumer code tries to read.

📌 Real example of the failure

When running cicero archive on a template that imports a CTO file with a versioned namespace, Cicero tries to read the namespace using the old AST shape. Since the versioned one has a different structure, it breaks with errors like:

Cannot read properties of undefined (reading 'name')

or prevents the archive from building.

So even though the grammar technically supports versioned namespaces, the AST shape wasn’t consistent — which is why the downstream code chokes on it.

✔️ What my fix changes

My change makes the parser always return a consistent AST, regardless of whether a namespace is versioned or not.

Instead of returning different shapes, the parser always returns:

{
  "name": ns.name,
  "namespace": ns.namespace
}

If a version exists, it’s still captured internally, but the external API stays predictable.

If you prefer the normalization to happen somewhere else (e.g., in the introspector instead of the parser), I can move it. Just let me know what structure you’d prefer long-term.

Thanks again — happy to refine this based on your guidance !

@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 15 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions Bot added the Stale label Jan 23, 2026
@Atharva7115

Atharva7115 commented Jan 23, 2026 •

Copy link
Copy Markdown
Author

@dselman Could you please re-review this PR?

@github-actions github-actions Bot removed the Stale label Jan 24, 2026
@github-actions

github-actions Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 15 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions Bot added Stale and removed Stale labels Feb 8, 2026
@github-actions

github-actions Bot commented Mar 1, 2026

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 15 days with no activity. Remove stale label or comment or this will be closed in 10 days.

Copilot AI 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.

Pull request overview

This PR aims to fix downstream failures (e.g., cicero archive) when parsing CTO files that declare a versioned namespace like org.example@1.0.0, by normalizing the AST returned from the Namespace grammar rule.

Changes:

  • Updates the Namespace rule action to “normalize” versioned namespace output.
  • Updates the generated parser (lib/parser.js) to reflect the grammar change.
  • Includes unrelated package-lock.json churn (removal of multiple "peer": true fields).

Reviewed changes

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

File Description
packages/concerto-cto/lib/parser.pegjs Adds conditional logic in the Namespace rule intended to normalize versioned namespace AST shape.
packages/concerto-cto/lib/parser.js Updates the generated parser action (peg$f104) corresponding to the Namespace rule change.
package-lock.json Removes multiple "peer": true entries; appears unrelated to the parser/AST change.

Comment on lines +1702 to +1707
if (ns.version) {
return {
name: ns.name,
namespace: ns.namespace
};
}

Copilot AI Mar 1, 2026

Copy link

Choose a reason for hiding this comment

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

QualifiedNamespaceDeclaration (both versioned and unversioned) currently returns a string (see QualifiedName / VersionedQualifiedNamespace). Because of that, ns.version is always undefined here, so the new normalization branch is unreachable and the rule behavior is effectively unchanged. If the goal is to normalize versioned vs unversioned namespaces, the change likely needs to happen in the VersionedQualifiedNamespace / QualifiedNamespaceDeclaration rules (or normalize the returned string explicitly), rather than checking ns.version on a string.

Suggested change
if (ns.version) {
return {
name: ns.name,
namespace: ns.namespace
};
}

Copilot uses AI. Check for mistakes.
Comment on lines +1205 to +1210
if (ns.version) {
return {
name: ns.name,
namespace: ns.namespace
};
}

Copilot AI Mar 1, 2026

Copy link

Choose a reason for hiding this comment

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

This generated action (peg$f104) checks ns.version, but QualifiedNamespaceDeclaration returns a string in the current grammar, so this condition will never be true and the intended normalization won’t run. After fixing the grammar, please re-run the peggy generation step so lib/parser.js reflects the actual (working) logic.

Suggested change
if (ns.version) {
return {
name: ns.name,
namespace: ns.namespace
};
}

Copilot uses AI. Check for mistakes.
Comment on lines 1701 to +1709
= NamespaceToken __ ns:QualifiedNamespaceDeclaration __ {
return ns;
}
if (ns.version) {
return {
name: ns.name,
namespace: ns.namespace
};
}
return ns;
}

Copilot AI Mar 1, 2026

Copy link

Choose a reason for hiding this comment

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

The PR description calls out adding a regression test for versioned namespaces, but this PR’s changed files don’t include any test updates/additions. Please add/adjust a test case that would have failed before this fix (e.g., a CTO file using namespace org.example@1.0.0 in the scenario that broke cicero archive) so the behavior is locked in.

Copilot generated this review using guidance from repository custom instructions.
@github-actions github-actions Bot removed the Stale label Mar 2, 2026
@mttrbrts mttrbrts closed this Mar 17, 2026
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.

4 participants