suma 0.5.34 → 0.5.35

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: e638f1579d2a576dbe73f8b5947f82a2b3b964200b3c534f7340c385334a9b95
4
- data.tar.gz: f2b91f20892348bcbab0b39b1d22f7a82c857c0f969a917e8ea28fcaa4f1a378
3
+ metadata.gz: 2555998b3b588d4c0d92ff306048f844051686cea1b36e17e40c6be9df389e25
4
+ data.tar.gz: e83c32dbeddc593bf5b640de88be5cbd1463a305f01bb28ad7ea4ca66e24fe30
5
5
  SHA512:
6
- metadata.gz: 574fa8226308db543725ae05f768a69a6d4a23fd6774719d8cd27518501011f09e23e7e0cad27f33d3b60b5513ef1f77a4a7e0e2567da44380e777757263d076
7
- data.tar.gz: 82c8d8d61115dadeb71dfaea93d0215c26df680b336f2f24f538738bb8173860f593ef1fde0ab2e2e5ead2851552b4f0f204e64d9d3cb134c5de1547121243f5
6
+ metadata.gz: e1091d2b9af8da12d387d0fcb8dc26db93e7d6f87481e065cc28a8c7b8b97800943b32330ff9e6ae9b2166a3eab3cafbb3d7648abd2902de71b6a2931fefdb59
7
+ data.tar.gz: 57b64f147c71de0f474be81406624611d46232440f62505cee9f2d316edcd0286230d00e806b8d57a633526823718d226972c2df14b03f82f414f666099f4ffe
data/.rubocop_todo.yml CHANGED
@@ -276,6 +276,7 @@ RSpec/ContextWording:
276
276
  # Configuration parameters: Max, CountAsOne.
277
277
  RSpec/ExampleLength:
278
278
  Exclude:
279
+ - 'spec/suma/delivery/expectations_spec.rb'
279
280
  - 'spec/suma/anchor_validator_spec.rb'
280
281
  - 'spec/suma/artifact_server_spec.rb'
281
282
  - 'spec/suma/build_plan_spec.rb'
@@ -375,6 +376,7 @@ RSpec/MessageSpies:
375
376
  # Configuration parameters: Max.
376
377
  RSpec/MultipleExpectations:
377
378
  Exclude:
379
+ - 'spec/suma/delivery/expectations_spec.rb'
378
380
  - 'spec/suma/artifact_server_spec.rb'
379
381
  - 'spec/suma/change_classification_spec.rb'
380
382
  - 'spec/suma/change_impact_spec.rb'
@@ -21,13 +21,22 @@ module Suma
21
21
  desc: "Also write the report as JSON to this path"
22
22
  option :no_fragments, type: :boolean, default: false,
23
23
  desc: "Skip fragment checking (file existence only)"
24
+ option :expectations, type: :string,
25
+ desc: "YAML manifest of site-shape thresholds " \
26
+ "(sections_min, index_pages, " \
27
+ "schema_attachments_min, schema_docs_min, " \
28
+ "missing_express_max, broken_links_max); " \
29
+ "violations fail the verify"
24
30
 
25
31
  def verify(site_dir)
26
32
  result = Suma::Delivery::SiteVerifier.new(site_dir,
27
33
  **verify_options).verify
28
34
  log_verify(result)
35
+ failures = expectation_failures(result)
29
36
  raise "broken links found (#{result.broken_count})" unless
30
37
  result.broken_count.zero?
38
+ raise "expectations violated: #{failures.join('; ')}" unless
39
+ failures.empty?
31
40
  end
32
41
 
33
42
  desc "resolve-fragments SITE_DIR",
@@ -125,14 +134,40 @@ module Suma
125
134
  { check_fragments: !options[:no_fragments] }
126
135
  end
127
136
 
137
+ def load_expectations
138
+ return unless options[:expectations]
139
+
140
+ Suma::Delivery::Expectations
141
+ .from_yaml(File.read(options[:expectations]))
142
+ end
143
+
144
+ def expectation_failures(result)
145
+ expectations = load_expectations or return []
146
+ expectations.violations(result.report["inventory"],
147
+ result.report["broken_links"])
148
+ end
149
+
128
150
  def log_verify(result)
129
- report = result.report
130
- write_report(report) if options[:out]
131
- Utils.log "Links: #{report['total_links']} total, " \
132
- "#{report['broken_links'].size} broken; " \
133
- "fragments: #{report['total_fragments']} total, " \
134
- "#{report['broken_fragments'].size} broken; " \
135
- "#{report['cross_document_links']} cross-document"
151
+ write_report(result.report) if options[:out]
152
+ Utils.log verify_summary(result)
153
+ end
154
+
155
+ def verify_summary(result)
156
+ r = result.report
157
+ "Links: #{r['total_links']} total, #{r['broken_links'].size} " \
158
+ "broken; fragments: #{r['total_fragments']} total, " \
159
+ "#{r['broken_fragments'].size} broken; " \
160
+ "#{r['cross_document_links']} cross-document; " \
161
+ "#{inventory_summary(r)}"
162
+ end
163
+
164
+ def inventory_summary(report)
165
+ inv = report["inventory"]
166
+ "site: sections=#{inv['sections']} " \
167
+ "indexes=#{inv['index_pages']} " \
168
+ "attachments=#{inv['schema_attachments']} " \
169
+ "schema_docs=#{inv['schema_docs']}; " \
170
+ "missing-express pages=#{report['missing_express_pages'].size}"
136
171
  end
137
172
 
138
173
  def write_report(report)
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Suma
4
+ module Delivery
5
+ # Corpus-side gate thresholds for `delivery verify --expectations`:
6
+ # the measured site-shape conditions as data, so the calling workflow
7
+ # states its delivery contract in one manifest instead of hand-rolled
8
+ # shell checks. Unset attributes are not checked.
9
+ class Expectations < Lutaml::Model::Serializable
10
+ attribute :sections_min, :integer
11
+ attribute :index_pages, :integer
12
+ attribute :schema_attachments_min, :integer
13
+ attribute :schema_docs_min, :integer
14
+ attribute :missing_express_max, :integer, default: -> { 0 }
15
+ attribute :broken_links_max, :integer, default: -> { 0 }
16
+
17
+ key_value do
18
+ map "sections_min", to: :sections_min
19
+ map "index_pages", to: :index_pages
20
+ map "schema_attachments_min", to: :schema_attachments_min
21
+ map "schema_docs_min", to: :schema_docs_min
22
+ map "missing_express_max", to: :missing_express_max
23
+ map "broken_links_max", to: :broken_links_max
24
+ end
25
+
26
+ # Human-readable violation lines for every threshold the +inventory+
27
+ # and +broken_links+ breach; unset thresholds stay silent. The name
28
+ # suffix is the comparison: `_min` floors, `_max` caps, a bare name
29
+ # (index_pages) is exact.
30
+ def violations(inventory, broken_links)
31
+ actuals(inventory, broken_links).filter_map do |name, actual|
32
+ limit = public_send(name) or next
33
+ relation = relation_of(name)
34
+ next if relation_met?(relation, actual, limit)
35
+
36
+ format("%<name>s: got %<actual>d, expected %<relation>s " \
37
+ "%<limit>d", name: name, actual: actual,
38
+ relation: relation, limit: limit)
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def relation_of(name)
45
+ return "at least" if name.end_with?("_min")
46
+ return "at most" if name.end_with?("_max")
47
+
48
+ "exactly"
49
+ end
50
+
51
+ def relation_met?(relation, actual, limit)
52
+ case relation
53
+ when "at least" then actual >= limit
54
+ when "at most" then actual <= limit
55
+ else actual == limit
56
+ end
57
+ end
58
+
59
+ # Every threshold's observed value, keyed by threshold name.
60
+ def actuals(inventory, broken_links)
61
+ {
62
+ "sections_min" => inventory["sections"],
63
+ "index_pages" => inventory["index_pages"],
64
+ "schema_attachments_min" => inventory["schema_attachments"],
65
+ "schema_docs_min" => inventory["schema_docs"],
66
+ "missing_express_max" => inventory["missing_express_pages"].size,
67
+ "broken_links_max" => broken_links.size,
68
+ }
69
+ end
70
+ end
71
+ end
72
+ end
@@ -18,7 +18,10 @@ module Suma
18
18
  # without making it clearer.
19
19
  # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
20
20
  SCHEME_RE = %r{\A(?:https?:|mailto:|javascript:|data:)}
21
- BARE_INTEGER_RE = /\A\d+\z/
21
+
22
+ # Metanorma's unresolved-citation rendering prefix; a page carrying
23
+ # it cites an express reference the corpus never resolved.
24
+ MISSING_EXPRESS_MARKER = "Missing:express"
22
25
 
23
26
  Report = Struct.new(:report, keyword_init: true) do
24
27
  def broken_count
@@ -40,10 +43,15 @@ module Suma
40
43
  anchor_index = build_anchor_index
41
44
  html_files.each do |html_file|
42
45
  rel_path = html_file.relative_path_from(@site_dir).to_s
43
- doc = Leptris::XML.parse_html(html_file.read)
46
+ content = html_file.read
47
+ if content.include?(MISSING_EXPRESS_MARKER)
48
+ report["missing_express_pages"] << rel_path
49
+ end
50
+ doc = Leptris::XML.parse_html(content)
44
51
  verify_intra_fragments(doc, rel_path, html_file, report)
45
52
  verify_links(doc, rel_path, html_file, anchor_index, report)
46
53
  end
54
+ report["inventory"] = site_inventory
47
55
  Report.new(report: report)
48
56
  end
49
57
 
@@ -61,6 +69,26 @@ module Suma
61
69
  "total_intra_fragments" => 0,
62
70
  "resolved_intra_fragments" => 0,
63
71
  "broken_intra_fragments" => [],
72
+ "missing_express_pages" => [],
73
+ "inventory" => {},
74
+ }
75
+ end
76
+
77
+ # The stitched site's shape: the counts the delivery contract is
78
+ # stated against (section pages, index pages, schema attachments,
79
+ # schema doc pages).
80
+ def site_inventory
81
+ {
82
+ "sections" => Dir.glob("#{@site_dir}/**/member_*.xml.*.html")
83
+ .count { |f| !f.end_with?(".err.html") },
84
+ "index_pages" => Dir.glob("#{@site_dir}/**/*_index.html").size,
85
+ "schema_attachments" =>
86
+ Dir.glob("#{@site_dir}/plain_schemas/**/*.exp").size,
87
+ "schema_docs" => if Dir.exist?("#{@site_dir}/schema_docs")
88
+ Dir.children("#{@site_dir}/schema_docs").size
89
+ else
90
+ 0
91
+ end,
64
92
  }
65
93
  end
66
94
 
@@ -104,7 +132,10 @@ module Suma
104
132
  href = a["href"].to_s.strip
105
133
  next if href.empty? || href.start_with?("#")
106
134
  next if href.match?(SCHEME_RE)
107
- next if href.match?(BARE_INTEGER_RE)
135
+
136
+ # Bare integers are counted, not skipped: an unbound svgmap
137
+ # hotspot emits its ordinal as the href, and a link to a
138
+ # nonexistent file "12" is dead whatever the key form.
108
139
 
109
140
  file_part, fragment = href.split("#", 2)
110
141
  file_part = file_part.delete_prefix("./")
data/lib/suma/delivery.rb CHANGED
@@ -6,6 +6,7 @@ module Suma
6
6
  module Delivery
7
7
  autoload :FrameNav, "suma/delivery/frame_nav"
8
8
  autoload :CrossPageFragments, "suma/delivery/cross_page_fragments"
9
+ autoload :Expectations, "suma/delivery/expectations"
9
10
  autoload :Pack, "suma/delivery/pack"
10
11
  autoload :Plan, "suma/delivery/plan"
11
12
  autoload :SiteVerifier, "suma/delivery/site_verifier"
data/lib/suma/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Suma
4
- VERSION = "0.5.34"
4
+ VERSION = "0.5.35"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: suma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.34
4
+ version: 0.5.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -243,6 +243,7 @@ files:
243
243
  - lib/suma/corpus_graph.rb
244
244
  - lib/suma/delivery.rb
245
245
  - lib/suma/delivery/cross_page_fragments.rb
246
+ - lib/suma/delivery/expectations.rb
246
247
  - lib/suma/delivery/frame_nav.rb
247
248
  - lib/suma/delivery/pack.rb
248
249
  - lib/suma/delivery/plan.rb