metanorma-ietf 3.7.17 → 3.7.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: abcc3856de061ccbe82625eec533e0d60595eac991405092b05e706b8725f1bd
4
- data.tar.gz: 44356953e5d937b8419015b0772e9beefcfc7be99c7f7fcf0506d246c01fadc7
3
+ metadata.gz: bdd11ed364d832b0a1009525118320a18eb30152a72a79e448b718fd9d449f09
4
+ data.tar.gz: 4fb93556348c99b8d7f6684b1846053e54742128606bb94cd37dea88512b90f0
5
5
  SHA512:
6
- metadata.gz: 45a5436a0a28a429670aae9537ee3e595b1dd9459709294d3ff2f0fcc86fed4edfb4a37a8c7d3701c659e831cf3be551222d0f46f7deeb4b18b769783e47e522
7
- data.tar.gz: ba8129dfac06cb1666508c5ddfe4b1f9182ce05e9a0134b72230a8cd4124e7d8bf1ba0fb82f2e2678ca763b5ae46b4136d6133124f5ffc86b084625c3afc64e1
6
+ metadata.gz: ef3c365528390eba625fc132db0469fedf416ca40e08cd7c78509c4941c0864437e9827b19bdbf5addadbff9f045e79ec46f79c6a5d24b972a9827f9ede68200
7
+ data.tar.gz: 3854871f1ee6c3c63ffd391ccb68d62360401e73644632a10b9268c184542b909dec7ab7ffa504c7a43520c37888ea01676a175a7a86ea9f0e240df5f58ee0ae
@@ -6,10 +6,54 @@ module Metanorma
6
6
  end
7
7
 
8
8
  def metadata_author(node, xml)
9
- personal_author(node, xml)
9
+ if node.attr("fullname") || node.attr("surname")
10
+ personal_author(node, xml)
11
+ else
12
+ # the AsciiDoc author line ("= Title" followed by name
13
+ # lines) is the common authoring shape; reading only
14
+ # :fullname:/:surname: produced author-less front matter,
15
+ # which RFC 7991 forbids (author+, metanorma-ietf#360)
16
+ author_line_author(node, xml)
17
+ end
10
18
  committee_contributors(node, xml, default_publisher, {})
11
19
  end
12
20
 
21
+ # Asciidoctor numbers the authors on the title line from 1
22
+ # (attribute set, plus the _1 alias) and then _2, _3...
23
+ def author_line_author(node, xml)
24
+ count = node.attr("authorcount").to_i
25
+ count = 1 if count < 1
26
+ (1..count).each do |i|
27
+ suffix = i == 1 ? "" : "_#{i}"
28
+ author_line_author1(node, xml, suffix)
29
+ end
30
+ end
31
+
32
+ def author_line_author1(node, xml, suffix)
33
+ forename = node.attr("firstname#{suffix}")
34
+ surname = node.attr("lastname#{suffix}")
35
+ full = node.attr("author#{suffix}")
36
+ return unless full || forename || surname
37
+ xml.contributor do |c|
38
+ personal_role(node, c, suffix)
39
+ c.person do |p|
40
+ p.name do |n|
41
+ if forename || surname
42
+ add_noko_elem(n, "forename", forename)
43
+ middlename = node.attr("middlename#{suffix}") and
44
+ add_noko_elem(n, "forename", middlename)
45
+ add_noko_elem(n, "initial",
46
+ node.attr("authorinitials#{suffix}"))
47
+ add_noko_elem(n, "surname", surname)
48
+ else
49
+ add_noko_elem(n, "completename", full)
50
+ end
51
+ end
52
+ add_noko_elem(p, "email", node.attr("email#{suffix}"))
53
+ end
54
+ end
55
+ end
56
+
13
57
  def org_author(node, xml); end
14
58
 
15
59
  def default_publisher
@@ -15,6 +15,92 @@ module Metanorma
15
15
  "IETF_4": { category: "Document Attributes",
16
16
  error: "IETF: unrecognised working group %s",
17
17
  severity: 1 },
18
+ # RFC XML emission validation (idnits3 submission-check
19
+ # findings on the Rfcxml model); severity 0 aborts the
20
+ # compile, 2 is an author-content warning
21
+ "IETF_5": { category: "RFC XML stream",
22
+ error: "Unknown submissionType (stream) on <rfc> " \
23
+ "element (:submission-type: %s): must be one of %s",
24
+ severity: 0 },
25
+ "IETF_6": { category: "RFC XML stream",
26
+ error: "The category of <rfc> (:intended-series: " \
27
+ "TYPE NUMBER) is invalid for the %s stream: must " \
28
+ "be one of %s, but is %s",
29
+ severity: 0 },
30
+ "IETF_7": { category: "RFC XML stream",
31
+ error: "The stream setting of <front> <seriesInfo> " \
32
+ "(%s) is inconsistent with the submissionType of " \
33
+ "<rfc> (%s)",
34
+ severity: 0 },
35
+ "IETF_8": { category: "RFC XML stream",
36
+ error: "Expected no consensus setting for the %s " \
37
+ "stream (:consensus: %s); remove the :consensus: " \
38
+ "document attribute",
39
+ severity: 0 },
40
+ "IETF_9": { category: "RFC XML stream",
41
+ error: "Expected no consensus setting for the IRTF " \
42
+ "stream with no workgroup (:consensus: %s); " \
43
+ "declare :workgroup: or remove :consensus:",
44
+ severity: 0 },
45
+ "IETF_10": { category: "RFC XML stream",
46
+ error: "The ipr attribute '%s' withholds the right " \
47
+ "to produce derivative works (RFC 5378, section " \
48
+ "3.3), so it can't be used in the IETF stream; " \
49
+ "use ipr='trust200902' (or 'pre5378Trust200902')",
50
+ severity: 0 },
51
+ "IETF_11": { category: "RFC XML stream",
52
+ error: "The document name %s implies the %s " \
53
+ "stream, but the rfc tag declares " \
54
+ "submissionType='%s' (:submission-type:); align " \
55
+ "the two",
56
+ severity: 0 },
57
+ "IETF_12": { category: "RFC XML submission",
58
+ error: "The abstract section is missing (an " \
59
+ ":abstract: block or [abstract] section): the " \
60
+ "IETF submission check requires it",
61
+ severity: 0 },
62
+ "IETF_13": { category: "RFC XML submission",
63
+ error: "The abstract section is present but " \
64
+ "contains no content (idnits3: at least 1 <t>, " \
65
+ "<ol>, <ul> or <dl> element)",
66
+ severity: 2 },
67
+ "IETF_14": { category: "RFC XML text output",
68
+ error: "The <%s> has lines wider than the 72 " \
69
+ "columns of xml2rfc's text output (widest is " \
70
+ "%s); xml2rfc will wrap or truncate them",
71
+ severity: 2 },
72
+ "IETF_15": { category: "RFC XML references",
73
+ error: "The reference %s is listed in the " \
74
+ "References section but is not mentioned in the " \
75
+ "document text",
76
+ severity: 2 },
77
+ "IETF_16": { category: "RFC XML vocabulary",
78
+ error: "The %s attribute of <%s> is deprecated " \
79
+ "(%s=\"%s\"): it must not be emitted",
80
+ severity: 1 },
81
+ "IETF_17": { category: "RFC XML vocabulary",
82
+ error: "The <%s> element is deprecated and must " \
83
+ "not be emitted",
84
+ severity: 1 },
85
+ "IETF_18": { category: "RFC XML front matter",
86
+ error: "The <author> is missing its fullname " \
87
+ "attribute",
88
+ severity: 2 },
89
+ "IETF_19": { category: "RFC XML front matter",
90
+ error: "There are more than 5 authors / editors; " \
91
+ "discuss the need with the relevant stream " \
92
+ "leadership",
93
+ severity: 3 },
94
+ "IETF_20": { category: "RFC XML text output",
95
+ error: "The <%s> contains tab characters, which " \
96
+ "xml2rfc's text output does not align; use " \
97
+ "spaces",
98
+ severity: 2 },
99
+ "IETF_21": { category: "RFC XML submission",
100
+ error: "The IETF submission check expects the " \
101
+ "submitted file to be named %s.xml; rename the " \
102
+ "output file before submitting it",
103
+ severity: 3 },
18
104
  }.freeze
19
105
  # rubocop:enable Naming/VariableNumber
20
106
 
@@ -75,19 +75,27 @@ module Metanorma
75
75
 
76
76
  # Mirror convert_forward's serialisation tail: bare-ampersand
77
77
  # escaping (#302: was present on the library API path only),
78
- # non-ASCII <u> wrapping (N11), then validation. Content errors
79
- # are stashed so the output stage can quarantine (#302: the
80
- # released leg moved invalid output to .err and halted; the
78
+ # non-ASCII <u> wrapping (N11), then validation. Findings are
79
+ # recorded in the flavor log catalog through Metanorma::Utils::Log
80
+ # (the Metanorma::Standoc::Validate shape); abort-severity
81
+ # entries are stashed so the output stage can quarantine (#302:
82
+ # the released leg moved invalid output to .err and halted; the
81
83
  # port had reduced that to warnings)
82
84
  def rfc_post_process(xml, transformer, options)
83
85
  xml = Transformer.escape_bare_ampersands(xml)
84
86
  xml = Transformer.u_cleanup(xml)
85
87
  @rfc_content_errors = []
88
+ @rfc_validator = nil
86
89
  if options[:validate]
90
+ rfc = transformer.rfc
91
+ @rfc_validator = RfcValidate.new
92
+ @fatal_rfc_errors = @rfc_validator.content_validate(rfc, transformer.doc)
93
+ @rfc_validator.content_warnings(rfc)
94
+ @rfc_validator.record_filename_hint(rfc.doc_name)
95
+ @rfc_content_errors = @fatal_rfc_errors +
96
+ transformer.content_validate(xml)
87
97
  transformer.schema_validate(xml)
88
98
  .each { |e| warn "RFC XML: #{e}" }
89
- @rfc_content_errors = transformer.content_validate(xml)
90
- @rfc_content_errors.each { |e| warn "RFC XML: #{e}" }
91
99
  end
92
100
  xml
93
101
  end
@@ -100,9 +108,12 @@ module Metanorma
100
108
  super(isodoc_node, inname, outname, format,
101
109
  options.merge(validate: true))
102
110
  if @rfc_content_errors&.any?
111
+ @rfc_validator&.write(outname)
103
112
  FileUtils.mv(outname, "#{outname}.err", force: true)
113
+ warn "FATAL ERRORS:\n\n#{@fatal_rfc_errors.join("\n\n")}" if @fatal_rfc_errors.any?
104
114
  warn "Cannot continue processing"
105
115
  else
116
+ @rfc_validator&.entries? and @rfc_validator.write(outname)
106
117
  @done_rfc = true
107
118
  end
108
119
  when :txt, :pdf, :html
@@ -39,6 +39,10 @@ module Metanorma
39
39
  title
40
40
  end
41
41
 
42
+ # No status/stream on the front seriesInfo: the idnits3
43
+ # submission check flags both as deprecated on the author's
44
+ # seriesInfo (the values live on <rfc category/submissionType>),
45
+ # and xml2rfc's preptool re-adds the stream itself (5.4.2.1)
42
46
  def build_series_info
43
47
  infos = []
44
48
  if rfc?
@@ -48,41 +52,12 @@ module Metanorma
48
52
  ascii_val = Sterile.transliterate(si.value)
49
53
  si.ascii_value = ascii_val unless ascii_val == si.value
50
54
  si.ascii_name = "RFC"
51
- # the released path passes the metadata stage through
52
- # (capitalised text; numeric stages stay as-is), defaulting
53
- # to Published (WS3, metadata_spec)
54
- stage = model_attr(bibdata, :status)
55
- stage_text = stage && ls_text(model_attr(stage, :stage) || stage)
56
- si.status = if stage_text && !stage_text.strip.empty?
57
- stage_text.strip.capitalize
58
- else
59
- "Published"
60
- end
61
- si.stream = extract_submission_type
62
55
  infos << si
63
56
  else
64
57
  si = Rfcxml::V3::SeriesInfo.new
65
58
  si.name = "Internet-Draft"
66
59
  si.value = extract_doc_name.to_s
67
60
  si.ascii_name = "Internet-Draft"
68
- si.stream = extract_submission_type
69
- # status = metadata stage, as on the RFC branch (the
70
- # released path uses the stage for both); intended-series
71
- # title only as fallback (WS3, metadata_spec)
72
- stage = model_attr(bibdata, :status)
73
- stage_text = stage && ls_text(model_attr(stage, :stage) || stage)
74
- if stage_text && !stage_text.strip.empty?
75
- si.status = stage_text.strip.capitalize
76
- else
77
- series_list = to_array(bibdata.series)
78
- series_list.each do |s|
79
- next unless s.type == "intended"
80
- title = ls_text(s.title)
81
- si.status = title&.capitalize || "Informational"
82
- break
83
- end
84
- end
85
- si.status ||= "Informational"
86
61
  infos << si
87
62
  end
88
63
 
@@ -34,7 +34,7 @@ module Metanorma
34
34
  include CleanupTransformer
35
35
  include ValidationTransformer
36
36
 
37
- attr_reader :doc, :options, :xrefs
37
+ attr_reader :doc, :options, :xrefs, :rfc
38
38
 
39
39
  def initialize(doc, options = {})
40
40
  @doc = doc
@@ -55,7 +55,7 @@ module Metanorma
55
55
  rfc.middle = build_middle
56
56
  rfc.back = build_back
57
57
  cleanup(rfc)
58
- rfc
58
+ @rfc = rfc
59
59
  end
60
60
 
61
61
 
@@ -0,0 +1,269 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metanorma
4
+ module Ietf
5
+ module Transformer
6
+ # RFC XML content checks on the Rfcxml::V3 model. The
7
+ # transformer law is model-driven: content rules walk the model
8
+ # objects, never the serialised XML (only the RelaxNG schema
9
+ # check and the released-path content transplant remain on the
10
+ # XML side). All rules here port idnits3 submission-check
11
+ # findings; they are returned as catalog-id/params pairs for
12
+ # Validate to record through the metanorma log.
13
+ module ModelValidation
14
+ RFC7841_STREAMS = %w(IETF IAB IRTF independent editorial).freeze
15
+
16
+ # RFC 7841 s2: the category each stream may carry; source of
17
+ # truth is the xml2rfc boilerplate_rfc_7841.py
18
+ # boilerplate_rfc_status_of_memo table
19
+ RFC7841_STREAM_CATEGORIES = {
20
+ "IETF" => %w(std bcp exp historic info),
21
+ "IAB" => %w(info historic),
22
+ "IRTF" => %w(exp historic info),
23
+ "independent" => %w(exp historic info),
24
+ "editorial" => %w(info),
25
+ }.freeze
26
+
27
+ module_function
28
+
29
+ def validate(rfc, doc = nil)
30
+ submission_type_findings(rfc, doc) + abstract_findings(rfc)
31
+ end
32
+
33
+ def submission_type_findings(rfc, doc = nil)
34
+ ret = []
35
+ ret += submission_type_enum_findings(rfc)
36
+ ret += stream_category_findings(rfc)
37
+ ret += series_info_stream_findings(rfc)
38
+ ret += consensus_findings(rfc, doc)
39
+ ret += ipr_stream_findings(rfc)
40
+ ret += docname_stream_findings(rfc)
41
+ ret
42
+ end
43
+
44
+ # idnits3 SUBMISSION_TYPE_INVALID
45
+ def submission_type_enum_findings(rfc)
46
+ st = rfc.submission_type or return []
47
+ RFC7841_STREAMS.include?(st) or
48
+ return [["IETF_5", [st, RFC7841_STREAMS.join(", ")]]]
49
+ []
50
+ end
51
+
52
+ def stream_category_findings(rfc)
53
+ st = rfc.submission_type || "IETF"
54
+ cat = rfc.category or return []
55
+ legal = RFC7841_STREAM_CATEGORIES[st] or return []
56
+ legal.include?(cat) or
57
+ return [["IETF_6",
58
+ [st, legal.join(", "), cat]]]
59
+ []
60
+ end
61
+
62
+ # xml2rfc preptool 5.4.2.1: the front seriesInfo stream and
63
+ # the rfc submissionType agree
64
+ def series_info_stream_findings(rfc)
65
+ st = rfc.submission_type || "IETF"
66
+ rfc.front&.series_info.to_a.each do |si|
67
+ si.stream && si.stream != st and
68
+ return [["IETF_7", [si.stream, st]]]
69
+ end
70
+ []
71
+ end
72
+
73
+ # xml2rfc preptool 5.4.2.2: the independent and editorial
74
+ # streams take no consensus setting, and the IRTF stream only
75
+ # when the document names a workgroup. The authored consensus
76
+ # comes from the input model's bibdata ext: the Rfcxml model
77
+ # default ("false") is indistinguishable from an authored
78
+ # false through the plain accessor
79
+ def consensus_findings(rfc, doc = nil)
80
+ st = rfc.submission_type || "IETF"
81
+ c = doc ? authored_consensus(doc) : authored_fallback(rfc)
82
+ return [] unless c
83
+ if %w(independent editorial).include?(st)
84
+ return [["IETF_8", [st, c]]]
85
+ end
86
+ if st == "IRTF" && rfc.front&.workgroup.to_a.empty?
87
+ return [["IETF_9", [c]]]
88
+ end
89
+ []
90
+ end
91
+
92
+ # the same source the emission reads: bibdata ext consensus
93
+ def authored_consensus(doc)
94
+ ext = doc&.bibdata&.ext and return ext.consensus
95
+ nil
96
+ end
97
+
98
+ # without the input model the Rfcxml accessor cannot
99
+ # distinguish an authored false from the model default: only a
100
+ # non-default value counts as authored
101
+ def authored_fallback(rfc)
102
+ c = rfc.consensus
103
+ c == "false" ? nil : c
104
+ end
105
+
106
+ # idnits3 FORBIDDEN_IPR_VALUE_FOR_STREAM (RFC 5378 s3.3)
107
+ RESTRICTED_IPR_VALUES = %w(noModificationTrust200902
108
+ noDerivativesTrust200902).freeze
109
+
110
+ def ipr_stream_findings(rfc)
111
+ return [] if rfc.ipr == "none"
112
+ return [] unless RESTRICTED_IPR_VALUES.include?(rfc.ipr)
113
+ return [] unless stream_of(rfc) == "ietf"
114
+
115
+ [["IETF_10", [rfc.ipr]]]
116
+ end
117
+
118
+ # idnits3 SUBMISSION_TYPE_MISMATCH: draft-iab-... and
119
+ # draft-irtf-... names imply their stream
120
+ def docname_stream_findings(rfc)
121
+ name = rfc.doc_name or return []
122
+ prefix = name.downcase.match(/\Adraft-([a-z0-9]+)-/)&.captures&.first
123
+ return [] unless %w(iab irtf).include?(prefix)
124
+ return [] if stream_of(rfc) == prefix
125
+
126
+ [["IETF_11",
127
+ [name, "#{prefix.upcase}", rfc.submission_type.to_s]]]
128
+ end
129
+
130
+ def stream_of(rfc)
131
+ rfc.submission_type&.downcase || "ietf"
132
+ end
133
+
134
+ # idnits3 MISSING_ABSTRACT_SECTION: the abstract is required
135
+ # at submission (https://authors.ietf.org/required-content)
136
+ def abstract_findings(rfc)
137
+ a = rfc.front&.abstract or return [["IETF_12", []]]
138
+ a.t.to_a.empty? && a.ol.to_a.empty? && a.ul.to_a.empty? &&
139
+ a.dl.to_a.empty? or return []
140
+ [["IETF_13", []]]
141
+ end
142
+
143
+ # idnits3 ARTWORK_TOO_WIDE: xml2rfc's text output is 72
144
+ # columns; <sourcecode> is indented by 3 of them
145
+ TEXT_LINE_WIDTH = 72
146
+ SOURCECODE_INDENT = 3
147
+
148
+ def artwork_width_findings(rfc)
149
+ walk(rfc).each_with_object([]) do |node, ret|
150
+ case node
151
+ when Rfcxml::V3::Artwork
152
+ width_findings(node, node.content.to_s, TEXT_LINE_WIDTH, ret)
153
+ when Rfcxml::V3::Sourcecode
154
+ width_findings(node, node.content.to_a.join("\n"),
155
+ TEXT_LINE_WIDTH - SOURCECODE_INDENT, ret)
156
+ end
157
+ end
158
+ end
159
+
160
+ def width_findings(node, content, budget, ret)
161
+ widest = content.to_s.lines.map(&:chomp).map(&:length).max || 0
162
+ widest > budget and
163
+ ret << ["IETF_14", [element_name_of(node), widest.to_s]]
164
+ end
165
+
166
+ # idnits3 REFERENCE_NOT_USED. Divergence from idnits3: it
167
+ # counts <xref> targets only, while our flavor renders
168
+ # eref-style citations as <relref>, so both count as uses
169
+ def references_used_findings(rfc)
170
+ anchors = walk(rfc).select { |n| n.is_a?(Rfcxml::V3::Reference) }
171
+ .map(&:anchor).compact.uniq
172
+ return [] if anchors.empty?
173
+ used = walk(rfc)
174
+ .select { |n| n.is_a?(Rfcxml::V3::Xref) || n.is_a?(Rfcxml::V3::Relref) }
175
+ .map(&:target).compact
176
+ anchors.uniq.reject { |a| used.include?(a) }
177
+ .map { |a| ["IETF_15", [a]] }
178
+ end
179
+
180
+ # The idnits3 deprecated-attribute/element tables (xml2rfc
181
+ # base.py deprecated_attributes / RFC 7991), keyed by the XML
182
+ # names the mappings emit: emission must never set them
183
+ DEPRECATED_ATTRIBUTES = {
184
+ "artwork" => %w(height width xml:space),
185
+ "figure" => %w(align alt height src suppress-title title width),
186
+ "note" => %w(title),
187
+ "references" => %w(title),
188
+ "section" => %w(title),
189
+ "seriesInfo" => %w(status stream),
190
+ "t" => %w(hangText),
191
+ "texttable" => %w(title),
192
+ "xref" => %w(pageno),
193
+ }.freeze
194
+ DEPRECATED_ELEMENTS = %w(spanx texttable ttcol vspace).freeze
195
+
196
+ def deprecated_findings(rfc)
197
+ ret = []
198
+ walk(rfc).each do |node|
199
+ tag = element_name_of(node)
200
+ DEPRECATED_ELEMENTS.include?(tag) and
201
+ ret << ["IETF_17", [tag]]
202
+ dep = DEPRECATED_ATTRIBUTES[tag] or next
203
+ node.class.mappings[:xml].attributes.each do |xml_name, rule|
204
+ next unless dep.include?(xml_name)
205
+ val = node.public_send(rule.to)
206
+ next if val.nil? || val.to_s.empty?
207
+ ret << ["IETF_16",
208
+ [xml_name, tag, xml_name, val.to_s]]
209
+ end
210
+ end
211
+ ret
212
+ end
213
+
214
+ # idnits3 MISSING_AUTHOR_FULLNAME / TOO_MANY_AUTHORS
215
+ def author_findings(rfc)
216
+ ret = []
217
+ authors = rfc.front&.author.to_a
218
+ authors.each do |a|
219
+ a.fullname.to_s.strip.empty? and
220
+ ret << ["IETF_18", []]
221
+ end
222
+ authors.size > 5 and
223
+ ret << ["IETF_19", []]
224
+ ret
225
+ end
226
+
227
+ # idnits3 TABS_IN_CODE: tabs break xml2rfc's text alignment
228
+ def tabs_findings(rfc)
229
+ walk(rfc).each_with_object([]) do |node, ret|
230
+ next unless node.is_a?(Rfcxml::V3::Artwork) ||
231
+ node.is_a?(Rfcxml::V3::Sourcecode)
232
+ content = node.is_a?(Rfcxml::V3::Sourcecode) ? node.content.to_a.join("\n") : node.content.to_s
233
+ content.include?("\t") and
234
+ ret << ["IETF_20", [element_name_of(node)]]
235
+ end
236
+ end
237
+
238
+ # Author-content findings that do not abort the compile
239
+ def warnings(rfc)
240
+ artwork_width_findings(rfc) + references_used_findings(rfc) +
241
+ deprecated_findings(rfc) + author_findings(rfc) +
242
+ tabs_findings(rfc)
243
+ end
244
+
245
+ # Depth-first walk over every model node, including models
246
+ # nested in collections
247
+ def walk(node, seen = {}.compare_by_identity, &block)
248
+ return to_enum(__method__, node) unless block
249
+ return unless node.is_a?(Lutaml::Model::Serializable)
250
+ return if seen.key?(node)
251
+ seen[node] = true
252
+ block.call(node)
253
+ node.class.attributes.each_value do |attr|
254
+ value = node.public_send(attr.name)
255
+ case value
256
+ when Array then value.each { |v| walk(v, seen, &block) }
257
+ when Lutaml::Model::Serializable then walk(value, seen, &block)
258
+ end
259
+ end
260
+ end
261
+
262
+ # The XML element name the mappings emit for this node
263
+ def element_name_of(node)
264
+ node.class.mappings[:xml].element_name
265
+ end
266
+ end
267
+ end
268
+ end
269
+ end
@@ -193,7 +193,6 @@ module Metanorma
193
193
  ret += link_check(xml)
194
194
  ret += series_info_check(xml)
195
195
  ret += ipr_check(xml)
196
- ret += submission_type_check(xml)
197
196
  ret
198
197
  end
199
198
 
@@ -244,86 +243,6 @@ module Metanorma
244
243
  []
245
244
  end
246
245
 
247
- # RFC 7991 s2.45.11: the legal submissionType (stream) values.
248
- RFC7841_STREAMS = %w(IETF IAB IRTF independent editorial).freeze
249
-
250
- # RFC 7841 s2: the category each stream may carry; source of
251
- # truth is the xml2rfc boilerplate_rfc_7841.py
252
- # boilerplate_rfc_status_of_memo table
253
- RFC7841_STREAM_CATEGORIES = {
254
- "IETF" => %w(std bcp exp historic info),
255
- "IAB" => %w(info historic),
256
- "IRTF" => %w(exp historic info),
257
- "independent" => %w(exp historic info),
258
- "editorial" => %w(info),
259
- }.freeze
260
-
261
- # Stream consistency across <rfc>, <front> <seriesInfo>,
262
- # <category> and <consensus>. The schema enum rejects unknown
263
- # stream values, but schema errors do not quarantine output;
264
- # these content checks do, with messages citing the document
265
- # attribute that produced the value. Mirrors xml2rfc preptool
266
- # 5.4.x stream checks.
267
- def submission_type_check(xml)
268
- ret = []
269
- ret += submission_type_enum_check(xml)
270
- ret += stream_category_check(xml)
271
- ret += series_info_stream_check(xml)
272
- ret += consensus_check(xml)
273
- ret
274
- end
275
-
276
- def submission_type_enum_check(xml)
277
- st = xml.root["submissionType"] or return []
278
- RFC7841_STREAMS.include?(st) or
279
- return ["Unknown submissionType (stream) on <rfc> element " \
280
- "(:submission-type: #{st}): must be one of " \
281
- "#{RFC7841_STREAMS.join(', ')}"]
282
- []
283
- end
284
-
285
- def stream_category_check(xml)
286
- st = xml.root["submissionType"] || "IETF"
287
- cat = xml.root["category"] or return []
288
- legal = RFC7841_STREAM_CATEGORIES[st] or return []
289
- legal.include?(cat) or
290
- return ["The category of <rfc> (:intended-series: TYPE " \
291
- "NUMBER) is invalid for the #{st} stream: must be " \
292
- "one of #{legal.join(', ')}, but is #{cat}"]
293
- []
294
- end
295
-
296
- # 5.4.2.1. Compare <rfc> "submissionType" and
297
- # <seriesInfo> "stream"
298
- def series_info_stream_check(xml)
299
- st = xml.root["submissionType"] || "IETF"
300
- xml.xpath("//front//seriesInfo[@stream]").each do |s|
301
- s["stream"] == st or
302
- return ["The stream setting of <front> <seriesInfo> " \
303
- "(#{s['stream']}) is inconsistent with the " \
304
- "submissionType of <rfc> (#{st})"]
305
- end
306
- []
307
- end
308
-
309
- # 5.4.2.2. "Status of This Memo" Insertion: the independent
310
- # and editorial streams take no consensus setting, and the
311
- # IRTF stream only when the document names a workgroup
312
- def consensus_check(xml)
313
- st = xml.root["submissionType"] || "IETF"
314
- c = xml.root["consensus"] or return []
315
- if %w(independent editorial).include?(st)
316
- return ["Expected no consensus setting for the #{st} " \
317
- "stream (:consensus: #{c}); remove the " \
318
- ":consensus: document attribute"]
319
- end
320
- if st == "IRTF" && xml.at("//front/workgroup").nil?
321
- return ["Expected no consensus setting for the IRTF " \
322
- "stream with no workgroup (:consensus: #{c}); " \
323
- "declare :workgroup: or remove :consensus:"]
324
- end
325
- []
326
- end
327
246
  end
328
247
  end
329
248
  end
@@ -14,6 +14,7 @@ module Metanorma
14
14
  autoload :NullObjects, "metanorma/ietf/transformer/null_objects"
15
15
  autoload :OrderTracker, "metanorma/ietf/transformer/order_tracker"
16
16
  autoload :IetfToRfcV3, "metanorma/ietf/transformer/ietf_to_rfc_v3"
17
+ autoload :ModelValidation, "metanorma/ietf/transformer/model_validation"
17
18
  autoload :RfcV3ToIetf, "metanorma/ietf/transformer/rfc_v3_to_ietf"
18
19
 
19
20
  class Error < StandardError; end
@@ -62,8 +63,13 @@ module Metanorma
62
63
  xml = u_cleanup(xml)
63
64
 
64
65
  if options[:validate]
65
- errors = transformer.validate_rfc_xml(xml)
66
- errors.each { |e| warn "RFC XML: #{e}" }
66
+ validator = RfcValidate.new
67
+ fatal = validator.content_validate(rfc, doc)
68
+ validator.content_warnings(rfc)
69
+ fatal.empty? or
70
+ raise Error, "FATAL ERRORS:\n\n#{fatal.join("\n\n")}"
71
+ transformer.validate_rfc_xml(xml)
72
+ .each { |e| warn "RFC XML: #{e}" }
67
73
  end
68
74
 
69
75
  xml
@@ -47,5 +47,60 @@ module Metanorma
47
47
  "ietf.rng"
48
48
  end
49
49
  end
50
+
51
+ # RFC XML emission validation for the processor's document-model
52
+ # leg, in the Metanorma::Standoc::Validate shape: findings are
53
+ # recorded through Metanorma::Utils::Log against the flavor
54
+ # catalog (severity 0 aborts the compile), the full report is
55
+ # rendered to the standard .err.html artifact, and the submitted
56
+ # filename hint is logged as info.
57
+ class RfcValidate
58
+ def initialize
59
+ @log = Metanorma::Utils::Log.new(Converter::IETF_LOG_MESSAGES)
60
+ end
61
+
62
+ # Returns the abort entries (clean_abort wording). doc is the
63
+ # input metanorma-document model, for findings that need the
64
+ # authored value (the Rfcxml model default is indistinguishable
65
+ # from an authored one through the plain accessor)
66
+ def content_validate(rfc, doc = nil)
67
+ Transformer::ModelValidation.validate(rfc, doc)
68
+ .each do |id, params|
69
+ @log.add(id, nil, params: params)
70
+ end
71
+ @log.abort_messages
72
+ end
73
+
74
+ def content_warnings(rfc)
75
+ Transformer::ModelValidation.warnings(rfc).each do |id, params|
76
+ @log.add(id, nil, params: params)
77
+ end
78
+ end
79
+
80
+ # idnits3 FILENAME_DOCNAME_MISMATCH / FILENAME_TOO_MANY_DOTS
81
+ # apply to the submitted file, which Datatracker requires to be
82
+ # named after the draft; our build artifact keeps the source
83
+ # base name
84
+ def record_filename_hint(doc_name)
85
+ doc_name or return
86
+ @log.add("IETF_21", nil, params: [doc_name])
87
+ end
88
+
89
+ def fatal?
90
+ !@log.abort_messages.empty?
91
+ end
92
+
93
+ def entries?
94
+ !@log.messages.empty?
95
+ end
96
+
97
+ def write(filename)
98
+ @log.save_to(filename)
99
+ @log.write
100
+ # the same name save_to computes for the report
101
+ File.join(File.dirname(filename),
102
+ "#{File.basename(filename, '.*')}.err.html")
103
+ end
104
+ end
50
105
  end
51
106
  end
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Ietf
3
- VERSION = "3.7.17".freeze
3
+ VERSION = "3.7.19".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-ietf
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.17
4
+ version: 3.7.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-11-23 00:00:00.000000000 Z
11
+ date: 2026-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64
@@ -266,6 +266,7 @@ files:
266
266
  - lib/metanorma/ietf/transformer/inline_transformer.rb
267
267
  - lib/metanorma/ietf/transformer/list_transformer.rb
268
268
  - lib/metanorma/ietf/transformer/metadata_transformer.rb
269
+ - lib/metanorma/ietf/transformer/model_validation.rb
269
270
  - lib/metanorma/ietf/transformer/null_objects.rb
270
271
  - lib/metanorma/ietf/transformer/order_tracker.rb
271
272
  - lib/metanorma/ietf/transformer/reference_transformer.rb