Repository navigation
fix: support versioned namespaces in CTO parser - #1084
Atharva7115 wants to merge 1 commit into
Conversation
Signed-off-by: Atharva Chandurkar <atharvachandurkar7115@gmail.com>
|
Hi maintainers 👋 Happy to answer any questions or make adjustments if there’s a preferred Looking forward to your feedback. |
|
AST changes like this are very risky. Can you provide more context on the downstream issue you are seeing that requires this change please? |
|
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:
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:
Versioned: 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:
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: 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 ! |
|
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. |
|
@dselman Could you please re-review this PR? |
|
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. |
|
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. |
a559323 to
2198c78
Compare
There was a problem hiding this comment.
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
Namespacerule action to “normalize” versioned namespace output. - Updates the generated parser (
lib/parser.js) to reflect the grammar change. - Includes unrelated
package-lock.jsonchurn (removal of multiple"peer": truefields).
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. |
| if (ns.version) { | ||
| return { | ||
| name: ns.name, | ||
| namespace: ns.namespace | ||
| }; | ||
| } |
There was a problem hiding this comment.
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.
| if (ns.version) { | |
| return { | |
| name: ns.name, | |
| namespace: ns.namespace | |
| }; | |
| } |
| if (ns.version) { | ||
| return { | ||
| name: ns.name, | ||
| namespace: ns.namespace | ||
| }; | ||
| } |
There was a problem hiding this comment.
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.
| if (ns.version) { | |
| return { | |
| name: ns.name, | |
| namespace: ns.namespace | |
| }; | |
| } |
| = NamespaceToken __ ns:QualifiedNamespaceDeclaration __ { | ||
| return ns; | ||
| } | ||
| if (ns.version) { | ||
| return { | ||
| name: ns.name, | ||
| namespace: ns.namespace | ||
| }; | ||
| } | ||
| return ns; | ||
| } |
There was a problem hiding this comment.
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.
Closes #788
This PR fixes an issue where
cicero archivefailed when a CTO file used aversioned namespace (e.g.
org.example@1.0.0).Although the CTO grammar already supported versioned namespaces, the
Namespacerule 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
Namespacegrammar rule when a versionednamespace is used
Flags
Screenshots or Video
Related Issues
Author Checklist
--signoffoption of git commitmainfromfork:branchname