metanorma / modspec-ruby

Implementation of OGC ModSpec
2 stars 1 forks source link

Serialisation is forcing validation of conformance targets #9

Closed opoudjis closed 1 month ago

opoudjis commented 1 month ago

This is example 4 from the readme of this gem:

conformance_test = Modspec::ConformanceTest.new(
  identifier: "/conf/example/foo",
  name: "Example test",
  description: "This is an example conformance test.",
  targets: ["/req/example/foo"],
  test_method: "manual",
  abstract: false
)
conformance_test.to_yaml

This crashes, because:

eval error: undefined method `empty?' for nil
  /Users/nickn/.rbenv/versions/3.3.3/lib/ruby/gems/3.3.0/gems/modspec-0.1.1/lib/modspec/conformance_test.rb:49:in `validate_requirement_mapping'

The code is forcing validation on serialisation. I think that is premature, especially as I will be doing postprocessing on the outputs of modspec-ruby.

More importantly, this code is naively assuming that it is being invoked within a suite, that a test must always have a parent class:

    attr_accessor :corresponding_requirements, :parent_class

   def validate_requirement_mapping
      if corresponding_requirements.empty?
        ["Conformance test #{identifier} has no corresponding requirements"]
      else
        []
      end
    end

That may work with standalone YAML files. But if I am calling Modspec::ConformanceTest.new(), as in the readme example, I am not invoking it with a parent class. The assumption that I am invoking it with a parent class, and that :corresponding_requirements exists, is wrong.

If I am calling Modspec::ConformanceTest.new() to render a test within Metanorma, in a completely separate clause from its target, then modspec-ruby does not get to crash, just because I haven't gone out and fetched the target of the clause from the separate clause, in order to serialise them together. I should not be forced to do validation on serialising individual requirements in isolation.

If I'm going to validate requirements incorporated into a Metanorma document using modspec-ruby, I am going to assemble the Modspec requirements at the end of processing, generate the needed links, and validate them as a suite, to ensure the linkages are in place. Until I do, validation is wasting time: I should be able to disable it.

For now, I am going to make the test be corresponding_requirements&.empty?, to make it safe; but I may ask the validation to be optional.

opoudjis commented 1 month ago

it continues:

Conformance test /conf/series-regular/duration does not belong to its parent class

Meaning it is IMPOSSIBLE to serialise YAML containing a conformance test in isolation from any conformance class. Serialisation triggers validation in lutaml-model, and validation crashes, because of the presumptuous assumption from modspec-ruby that only tests with parent classes can be serialised. (Not validated: even just serialised.) And there is no functionality to make validation optional.

@ronaldtse @HassanAkbar I need validation in lutaml-model to be made optional on serialisation (.to_xml(valid: false)). Until that happens, I will not proceed further with integrating modspec-ruby into mn-requirements.

opoudjis commented 1 month ago

Has been resolved.