fix(export): load sysml-toolkit API JSON exports and accept JSON model files - #876
Merged
Merged
Conversation
Co-Authored-By: jason.han <hanhuijun@gmail.com>
Co-Authored-By: jason.han <hanhuijun@gmail.com>
Co-Authored-By: jason.han <hanhuijun@gmail.com>
Co-Authored-By: jason.han <hanhuijun@gmail.com>
Contributor
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Co-Authored-By: jason.han <hanhuijun@gmail.com>
Co-Authored-By: jason.han <hanhuijun@gmail.com>
Co-Authored-By: jason.han <hanhuijun@gmail.com>
Co-Authored-By: jason.han <hanhuijun@gmail.com>
Co-Authored-By: jason.han <hanhuijun@gmail.com>
Co-Authored-By: jason.han <hanhuijun@gmail.com>
Merged
6 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
API element-form JSON exported by sysml-toolkit v0.10.0 (
sysmlv2 convert … --to full-json) failed to load throughsysml -convert sysml -from api-json. This change fixes the three measured failures, cuts the cost of a large import, and lets a.jsonmodel be loaded anywhere a model file is accepted.FlowEndowned throughEndFeatureMembershipis now folded into the owning flow'sfrom … to …head and is never written as a standalone declaration. The toolkit's shape, a FlowFeatureReferenceUsageowned through aFeatureMembershipwith one implied redefinition, is accepted alongside the existing forms. A flow end that declares a name or annotations, or owns content the head cannot carry, is refused. Other flow-related metaclasses in the exports were checked:FlowUsage,PayloadFeature,EndFeatureMembershipandReferenceSubsetting. The exports contain noItemFlow,ItemFlowEndorSuccessionItemFlow.… accept Pumps::Boost do in attribute then …: the toolkit's implicit parameters (transitionLinkSource, the trigger payload) were read as the transition's effect. Trigger, guard and effect are now read by theirTransitionFeatureMembershipkind. AParameterMembershipis never an effect. The source parameter is recognised by its implied redefinition ofActions::TransitionAction::transitionLinkSource. Guards stated through aguardmembership orsysml:guardExpressionare written asif …; before this change they were silently dropped. Names written inside a trigger resolve from the transition's scope.CoSMAPackageand two other packages are Apollo's ownlibrary packages. Removing the toolkit's synthetic root namespace left them unowned, and they were then mistaken for standard-library reference stubs. Alibrary packagethat owns content is now a declaration. For real stubs whose id is not in the bundled catalog, the reader falls back to the statedqualifiedName, then todeclaredNameplus the owner chain the graph states, then to an imported membership's target. The match's metaclass must be compatible. A fallback match is written by its bundled identity and reports a warning naming both ids. An unmatched stub is refused with its id and name. Across the three exports, 205 of the 221 element ids that are referenced but not contained already match the bundled catalog by id; the rest are derivedresultlinks and one membership import.satisfy … by a.bsubject is written back asby a.b. Its value is theFeatureReferenceExpressionwhose referent is an owned chain feature (SysML.xtextSatisfactionReferenceExpression). A toolkitreturn :> x = …, which is aReferenceUsage, is no longer written asreturn attribute ….GraphBuilder, which de-duplicates once at build time. The import's own graph is rewritten in place (Graph.RewriteTriples) instead of copied at each normalisation step, andrdf.Graphcaches subject order and indexes objects by triple position. Publicexport.ToSysML/ToSysMLWarnstill convert a copy and leave the caller's graph unchanged; only the newexport.APIJSONToSysML, which owns the graph it reads, rewrites in place..jsonfile is converted to SysML before parsing insysml -validate,sysmlfile loading and the REPL, and gRPCParseFile/ParseSourcesfile paths. This covers Pythonopensysml.load("x.json"), which goes throughParseFile. Conversion warnings are printed on the CLI and REPL. Over gRPC they are returned as warning diagnostics tagged with the JSON path and no range. Directory and glob expansion still collect only.sysml/.kerml.source.KindOfis unchanged; the converting call sites set the SysML kind themselves.Overlap with #865 (metamodel regeneration to 20250201): this branch merges develop after #865 and does not touch
internal/translate/rdf/ontology/table.goor its generator. Every metaclass and predicate name it hard-codes (the flow constants ininternal/translate/export/rdf_normative.go,transitionLinkSource, and the rest) exists in the regenerated table.Measurements
The command is
sysml -convert sysml -from api-json <file>, measured with/usr/bin/time -v. The "After" column was measured on the head merged with develop after #865. The exports were made by sysml-toolkit v0.10.0 with--lib internal/workspace/libs/stdlib.drones.sysmlFlowEndhas no notation)pumps.sysmlApollo's validation reports no errors and three warnings that come from the model itself: an incommensurable-quantity addition, an unbound
naturalLogarithmparameter, and a variable multiplicity onsubfunctions[*].Fidelity was checked by re-exporting the converted notation with the toolkit and comparing it with the original export. Drones (739 elements) and pumps (475) match in element count, count per
@typeand the set of qualified names. Apollo matches all 2,335 qualified names and every per-type count exceptNamespace28 → 1. That difference comes from writing one document instead of 28 files: the toolkit run over the 28 files concatenated into one shows the same single difference. The 92 MB Apollo export is not committed.Specification basis
FlowEnd/FlowFeature(SysML.xtextFlowEnd,FlowEndMember); a flow end is written in the flow head'sfrom … to ….TransitionFeatureMembershipkindtrigger/guard/effect (SysML v2 § 8.3.17.9, SysML.xtextTriggerActionMember,GuardExpressionMember,EffectBehaviorMember).SatisfactionSubjectMember/SatisfactionReferenceExpression/FeatureChainMember.returnUsageElement with no kind keyword is aReferenceUsage(SysML-textual-bnfDefaultReferenceUsage).No row in
docs/project/spec-compliance.mdmoves.docs/reference/rdf-mapping.mddocuments the library-identity fallback, flow-end folding, transition guard/effect reading, satisfy-subject chains and JSON model loading.How it was verified
tests/export/testdata/interchange/(flow_ends,transitions,library_identity,library_unmatched,successions,satisfy_by), each a small.sysmlsource, its toolkitfull.jsonand the expected notation. They are exercised bytests/export/toolkit_json_import_test.go, with unit tests ininternal/translate/exportandinternal/translate/convert.cmd/sysml(-validate,-convertwarning on stderr),internal/frontend/repl(explicit.jsonloads with its warning; a directory ignores.json) andinternal/frontend/grpc(ParseFilereturns the root and a path-tagged warning that is also served from the cache; an unconvertible file isInvalidArgument).ToSysMLleaves a Turtle-read graph's triples unchanged..jsondocuments keep the SysML source kind through workspace indexing, analysis, records,Updateand REPL reparses (tests ininternal/workspace/modelandinternal/frontend/repl). A named flow end is refused rather than folded.go build ./...,go vet ./...,gofmt -l .,make lint,go test ./...,go test -race ./internal/translate/... ./tests/export/...,go testforcmd/sysml,internal/frontend/grpcandinternal/frontend/repl,make docs-check, andpython3 scripts/changelog.py check.Checklist
make testandmake lintpass locally (the packages touched are listed above; CI runs the full suite)changes/unreleased/<slug>.<section>.md, not as an edit toCHANGELOG.mdmake docs-countsrun if a gate count moved (no gate count moved)F4,K5) in the body, docs, or changelog