Skip to content

fix(sysml-derive): validate + fix SysML v2 output for primitive/DateTime field types - #196

Open
elasticdotventures wants to merge 6 commits into
feat/sysml-derive-spikefrom
fix/sysml-block-scalar-type-mapping
Open

fix(sysml-derive): validate + fix SysML v2 output for primitive/DateTime field types#196
elasticdotventures wants to merge 6 commits into
feat/sysml-derive-spikefrom
fix/sysml-block-scalar-type-mapping

Conversation

@elasticdotventures

Copy link
Copy Markdown
Member

What

Closes #195 (top-priority follow-up flagged in retrospective review of the
systems-modeling epic).

Investigated what SysML v2 text #[derive(SysmlBlock)] actually generates
for the field types introduced by #184 (Requirement/Decision/Cost,
which use DateTime<Utc>) and #193 (retrofit onto 8 pre-existing structs,
which additionally introduced rust_decimal::Decimal, a custom
Confidence type, bool, and usize).

Found a real bug: DateTime<Utc> fields emitted the literal text
attribute x : DateTime<Utc>;. SysML v2's textual grammar has no
angle-bracket generic-parameter syntax at all — this is not "semantically
questionable," it's syntactically invalid under any conformant SysML v2
parser. bool/usize fields emitted bare Rust keywords, which aren't
SysML v2 type names either (SysML v2's standard library scalar types live
under ScalarValues::*).

Fix

  • DateTime<_> -> ScalarValues::String (SysML v2 has no native
    date/time scalar; the generic parameter is dropped rather than rendered,
    since rendering it is what caused the invalid syntax).
  • bool -> ScalarValues::Boolean, unsigned integers -> ScalarValues::Natural,
    signed integers -> ScalarValues::Integer, floats -> ScalarValues::Rational.
  • Any other single-type-argument generic (not Vec/Option/DateTime) is
    now a compile error instead of silently emitting the same class of
    invalid Outer<Inner> text — guards against the next person adding a new
    generic field type and reintroducing this silently.
  • String and opaque domain types (NodeId, Confidence,
    rust_decimal::Decimal) intentionally still pass through as bare
    type-name references — documented in the module doc as an intentional
    modeling assumption (they're assumed to resolve to a sibling declaration
    elsewhere in the model), not a bug needing a fix.

New tests in crates/sysml-derive/tests/retrofitted_field_types.rs cover
all of the above, including an explicit assertion that the generated text
never contains </>.

Verification

  • cargo test -p sysml-derive: 6/6 pass (2 existing + 4 new).
  • cargo check --workspace --all-features: clean.
  • Manually probed the exact production field shapes (ExtractedRow,
    ModelProposal, WorkbookRow) via a throwaway test before writing the
    real regression tests, confirming the bug and the fix against real
    struct shapes, not just synthetic ones.

Stacked on feat/sysml-derive-spike (#183) since that's where
sysml-derive itself lives; will merge-forward through #184/#185/#186/
#190/#193 the same way the two generated-artifact CI-drift fixes were
propagated earlier in this epic.

…lues

DateTime<Utc> previously emitted the literal, invalid text
`DateTime<Utc>` as a SysML v2 attribute type -- SysML v2's grammar has
no angle-bracket generic-parameter syntax, so this would fail to parse
under any conformant SysML v2 tool. bool/usize/etc. also passed through
as bare Rust keywords with no corresponding SysML type.

Map DateTime<_> -> ScalarValues::String, bool -> ScalarValues::Boolean,
unsigned ints -> ScalarValues::Natural, signed ints ->
ScalarValues::Integer, floats -> ScalarValues::Rational. Any other
single-type-argument generic is now a compile error instead of a
silent invalid-syntax emission. Opaque domain types (NodeId,
Confidence, Decimal) still pass through as bare names -- documented as
an intentional modeling assumption, not a bug.

Adds regression tests for the field types introduced by #184/#193
(Decimal, Confidence, bool, usize, DateTime<Utc>) that basic.rs never
exercised. Closes ledgrrr#195.
…eal parser validation into ufo-types

Ran SysmlV2Emitter's own output through the real sysml-v2-parser crate
(docs/sysml-v2-parser-spike.md, an existing unmerged spike) and confirmed
two bugs make it non-parseable:

- The closing '}' was on the same line as a trailing '//' comment, so the
  comment swallowed it -- the block was never syntactically closed.
- The emitter used SysML v1's 'block def' keyword. SysML v2 renamed this
  construct to 'part def'; 'block' is not a SysML v2 keyword at all.

Fixed both. Added ufo_types::sysml -- a shared Constraint/Satisfies-based
SysML v2 syntax validator wired to sysml-v2-parser (pinned to =0.54.0 per
the spike's crate-health findings; not wasm32-compatible, so this must
stay out of holon-viz's runtime dependency graph -- added to holon-viz
only as a dev-dependency, used in a new round-trip test that feeds the
emitter's own output through the real parser instead of just asserting on
substrings.

This is the concrete round-trip-closed signal the existing spike (PR #187)
called out as the next step.
…yntax' into fix/sysml-block-scalar-type-mapping

# Conflicts:
#	Cargo.lock
…al SysML v2 grammar

Same bug holon-viz's SysmlV2Emitter had (ledgrrr#197): SysML v1 called
this construct Block/'block def'; SysML v2 renamed it to 'part def', and
'block' is not a SysML v2 keyword at all. Confirmed via the newly-wired
ufo_types::sysml::validate_sysml_v2 (real sysml-v2-parser crate, not a
hand-rolled heuristic) that the fixed output actually parses.

Adds tests/real_grammar_validation.rs: runs the actual generated
sysml_block_def() text for Transaction/Requirement/ExtractedRow/
ModelProposal/WorkbookRow (mirroring the real production structs from
#184/#193) through the real parser. This replaces the 'no angle brackets'
manual check used to validate the earlier DateTime/bool/usize scalar
mapping fix with genuine grammar validation, closing out ledgrrr#195.

@github-advanced-security github-advanced-security AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

clippy found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

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