suma 0.5.21 → 0.5.23

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: d57c7866a336d71b91bae0745359a3ad66a5ff465eb2f456a27d74a3d901328b
4
- data.tar.gz: 6c84fb67e536cc4df2fed9e6a75ad39700b3c6a8162d63a6f92779e370c52be7
3
+ metadata.gz: 2f7a3b500ba7ee96e9dd35a10ecee6c54d9eb2b8b84af7fb9c6bd57d60224dc0
4
+ data.tar.gz: ee63af0b650015c8389781d6378985ee2c456bcfa9c2dfe49e2b82c308138929
5
5
  SHA512:
6
- metadata.gz: 9ccc76d252726749978bceee65caf1a75fc954f80b6c17652e373c6aa6b7c263d64ccb7f3e114accc4f66a564c54c1f7a9282d9914cd11ce2319fe50925ca64d
7
- data.tar.gz: 623e14b1b637cf112bdd66d8d62ac9b54543b45498efc5117abb1f1aad2a76b5b582eaa49cc1ec66576de03d3069de05e41e1dde8d84c231ff7a1f8621247379
6
+ metadata.gz: 325df4782c320453af40b4144834656145e7b31fc64f7ddadc21088e9e5a81f5fe26a87c8b2f7b67bcf853f552ac08fa951a45056c70d9b182c73901f6352a9e
7
+ data.tar.gz: 06cad6b3ae6994ced379bb63ed0a092c3d27ba21a8bef0d46b040620a88b1beeb98c3cf7e3d48da8417e309b83217d0d517878f007acd3b5b6dbd2911bc105f7
data/.rubocop_todo.yml CHANGED
@@ -87,6 +87,9 @@ Layout/LineLength:
87
87
  - 'spec/suma/term_extractor_spec.rb'
88
88
  - 'spec/suma/urn_spec.rb'
89
89
  - 'suma.gemspec'
90
+ - 'spec/suma/srl/frame_nav_spec.rb'
91
+ - 'spec/suma/srl/site_verifier_spec.rb'
92
+ - 'spec/suma/srl/stitcher_spec.rb'
90
93
 
91
94
  # Offense count: 2
92
95
  # Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches, IgnoreDuplicateElseBranch.
@@ -116,19 +119,21 @@ Lint/UnusedMethodArgument:
116
119
  # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max.
117
120
  Metrics/AbcSize:
118
121
  Exclude:
119
- - 'lib/suma/gcr_package.rb'
120
122
  - 'bin/benchmark_corpus'
121
- - 'lib/suma/worker_pool.rb'
122
- - 'spec/suma/reproducibility_spec.rb'
123
- - 'spec/suma/cli/build_integration_spec.rb'
124
- - 'lib/suma/cli/resolve.rb'
125
- - 'lib/suma/urn_resolver.rb'
123
+ - 'lib/suma/change_manifest.rb'
126
124
  - 'lib/suma/cli/check_svg_quality.rb'
127
125
  - 'lib/suma/cli/core.rb'
126
+ - 'lib/suma/cli/export.rb'
127
+ - 'lib/suma/cli/generate_register.rb'
128
+ - 'lib/suma/cli/resolve.rb'
129
+ - 'lib/suma/closure_validator.rb'
130
+ - 'lib/suma/corpus_graph.rb'
131
+ - 'lib/suma/gcr_package.rb'
128
132
  - 'lib/suma/jsdai/figure.rb'
129
133
  - 'lib/suma/jsdai/figure_image.rb'
130
134
  - 'lib/suma/link_validator.rb'
131
135
  - 'lib/suma/manifest_traverser.rb'
136
+ - 'lib/suma/owl_projection.rb'
132
137
  - 'lib/suma/processor.rb'
133
138
  - 'lib/suma/schema_collection.rb'
134
139
  - 'lib/suma/schema_comparer.rb'
@@ -138,12 +143,11 @@ Metrics/AbcSize:
138
143
  - 'lib/suma/svg_quality/formatters/terminal_formatter.rb'
139
144
  - 'lib/suma/term_extractor.rb'
140
145
  - 'lib/suma/thor_ext.rb'
141
- - 'lib/suma/closure_validator.rb'
142
- - 'lib/suma/corpus_graph.rb'
143
- - 'lib/suma/change_manifest.rb'
144
- - 'lib/suma/cli/generate_register.rb'
145
- - 'lib/suma/owl_projection.rb'
146
- - 'lib/suma/cli/export.rb'
146
+ - 'lib/suma/urn_resolver.rb'
147
+ - 'lib/suma/worker_pool.rb'
148
+ - 'spec/suma/cli/build_integration_spec.rb'
149
+ - 'spec/suma/reproducibility_spec.rb'
150
+ - spec/suma/srl/stitcher_spec.rb
147
151
 
148
152
  # Offense count: 2
149
153
  # Configuration parameters: CountComments, Max, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode.
@@ -267,65 +271,68 @@ RSpec/ContextWording:
267
271
  # Configuration parameters: Max, CountAsOne.
268
272
  RSpec/ExampleLength:
269
273
  Exclude:
270
- - 'spec/suma/site_build_spec.rb'
271
- - 'spec/suma/output_canonicalizer_spec.rb'
272
274
  - 'spec/suma/anchor_validator_spec.rb'
273
- - 'spec/suma/translation_ingester_spec.rb'
274
- - 'spec/suma/ifc_profile_pipeline_spec.rb'
275
- - 'spec/suma/schema_manifest_generator_spec.rb'
276
- - 'spec/suma/schema_naming_spec.rb'
277
- - 'spec/suma/cli/build_integration_spec.rb'
278
275
  - 'spec/suma/artifact_server_spec.rb'
279
- - 'spec/suma/gcr_package_spec.rb'
280
- - 'spec/suma/schema_cache_spec.rb'
281
- - 'spec/suma/worker_pool_spec.rb'
282
- - 'spec/suma/schema_collection_rebuild_targets_spec.rb'
283
276
  - 'spec/suma/build_plan_spec.rb'
284
- - 'spec/suma/reproducibility_spec.rb'
285
- - 'spec/suma/provenance_spec.rb'
286
- - 'spec/suma/term_extractor_spec.rb'
287
- - 'spec/suma/cli/resolve_spec.rb'
288
- - 'spec/suma/urn_resolver_spec.rb'
277
+ - 'spec/suma/change_classification_spec.rb'
278
+ - 'spec/suma/change_impact_spec.rb'
279
+ - 'spec/suma/change_manifest_spec.rb'
280
+ - 'spec/suma/cli/build_integration_spec.rb'
289
281
  - 'spec/suma/cli/export_spec.rb'
290
282
  - 'spec/suma/cli/extract_terms_spec.rb'
291
283
  - 'spec/suma/cli/generate_register_spec.rb'
292
284
  - 'spec/suma/cli/generate_schemas_spec.rb'
293
285
  - 'spec/suma/cli/reformat_spec.rb'
286
+ - 'spec/suma/cli/resolve_spec.rb'
294
287
  - 'spec/suma/cli_spec.rb'
295
- - 'spec/suma/collection_config_spec.rb'
296
288
  - 'spec/suma/closure_validator_spec.rb'
289
+ - 'spec/suma/collection_config_spec.rb'
297
290
  - 'spec/suma/collection_manifest_spec.rb'
298
291
  - 'spec/suma/corpus_graph_spec.rb'
299
- - 'spec/suma/owl_projection_spec.rb'
300
- - 'spec/suma/schema_profile_spec.rb'
301
292
  - 'spec/suma/eengine_converter_spec.rb'
302
293
  - 'spec/suma/express_reformatter_spec.rb'
303
294
  - 'spec/suma/express_schema_spec.rb'
295
+ - 'spec/suma/gcr_package_spec.rb'
296
+ - 'spec/suma/ifc_profile_pipeline_spec.rb'
304
297
  - 'spec/suma/jsdai/figure_spec.rb'
305
298
  - 'spec/suma/link_validation_spec.rb'
306
299
  - 'spec/suma/link_validator/step_spec.rb'
307
300
  - 'spec/suma/link_validator_spec.rb'
308
301
  - 'spec/suma/manifest_traverser_spec.rb'
309
302
  - 'spec/suma/note_processor_spec.rb'
310
- - 'spec/suma/publication_spec.rb'
303
+ - 'spec/suma/output_canonicalizer_spec.rb'
304
+ - 'spec/suma/owl_projection_spec.rb'
311
305
  - 'spec/suma/owl_projection_spec.rb'
312
306
  - 'spec/suma/processor_spec.rb'
307
+ - 'spec/suma/provenance_spec.rb'
308
+ - 'spec/suma/publication_spec.rb'
313
309
  - 'spec/suma/register_manifest_generator_spec.rb'
310
+ - 'spec/suma/reproducibility_spec.rb'
311
+ - 'spec/suma/schema_cache_spec.rb'
314
312
  - 'spec/suma/schema_category_spec.rb'
313
+ - 'spec/suma/schema_collection_rebuild_targets_spec.rb'
315
314
  - 'spec/suma/schema_comparer_integration_spec.rb'
316
315
  - 'spec/suma/schema_comparer_spec.rb'
317
316
  - 'spec/suma/schema_compiler_spec.rb'
318
317
  - 'spec/suma/schema_discovery_spec.rb'
319
318
  - 'spec/suma/schema_exporter_spec.rb'
319
+ - 'spec/suma/schema_manifest_generator_spec.rb'
320
+ - 'spec/suma/schema_naming_spec.rb'
321
+ - 'spec/suma/schema_profile_spec.rb'
320
322
  - 'spec/suma/schema_template_spec.rb'
323
+ - 'spec/suma/site_build_spec.rb'
321
324
  - 'spec/suma/site_config/config_spec.rb'
322
325
  - 'spec/suma/svg_quality/scanner_spec.rb'
323
326
  - 'spec/suma/term_classification_spec.rb'
324
327
  - 'spec/suma/term_extractor_spec.rb'
328
+ - 'spec/suma/term_extractor_spec.rb'
329
+ - 'spec/suma/translation_ingester_spec.rb'
330
+ - 'spec/suma/urn_resolver_spec.rb'
325
331
  - 'spec/suma/urn_spec.rb'
326
- - 'spec/suma/change_classification_spec.rb'
327
- - 'spec/suma/change_manifest_spec.rb'
328
- - 'spec/suma/change_impact_spec.rb'
332
+ - 'spec/suma/worker_pool_spec.rb'
333
+ - 'spec/suma/srl/frame_nav_spec.rb'
334
+ - 'spec/suma/srl/site_verifier_spec.rb'
335
+ - 'spec/suma/srl/stitcher_spec.rb'
329
336
 
330
337
  # Offense count: 4
331
338
  # Configuration parameters: Max, AllowedIdentifiers, AllowedPatterns.
@@ -356,44 +363,42 @@ RSpec/MessageSpies:
356
363
  # Configuration parameters: Max.
357
364
  RSpec/MultipleExpectations:
358
365
  Exclude:
359
- - 'spec/suma/site_build_spec.rb'
360
- - 'spec/suma/output_canonicalizer_spec.rb'
361
- - 'spec/suma/cli/build_integration_spec.rb'
362
366
  - 'spec/suma/artifact_server_spec.rb'
363
- - 'spec/suma/gcr_package_spec.rb'
364
- - 'spec/suma/schema_cache_spec.rb'
365
- - 'spec/suma/worker_pool_spec.rb'
366
- - 'spec/suma/reproducibility_spec.rb'
367
- - 'spec/suma/provenance_spec.rb'
368
- - 'spec/suma/term_extractor_spec.rb'
369
- - 'spec/suma/cli/resolve_spec.rb'
370
- - 'spec/suma/urn_resolver_spec.rb'
367
+ - 'spec/suma/change_classification_spec.rb'
368
+ - 'spec/suma/change_impact_spec.rb'
369
+ - 'spec/suma/change_manifest_spec.rb'
370
+ - 'spec/suma/cli/build_integration_spec.rb'
371
371
  - 'spec/suma/cli/build_spec.rb'
372
372
  - 'spec/suma/cli/export_spec.rb'
373
373
  - 'spec/suma/cli/expressir_spec.rb'
374
374
  - 'spec/suma/cli/extract_terms_spec.rb'
375
375
  - 'spec/suma/cli/reformat_spec.rb'
376
+ - 'spec/suma/cli/resolve_spec.rb'
376
377
  - 'spec/suma/cli_spec.rb'
377
- - 'spec/suma/collection_config_spec.rb'
378
378
  - 'spec/suma/closure_validator_spec.rb'
379
+ - 'spec/suma/collection_config_spec.rb'
379
380
  - 'spec/suma/collection_manifest_spec.rb'
380
381
  - 'spec/suma/corpus_graph_spec.rb'
381
- - 'spec/suma/owl_projection_spec.rb'
382
- - 'spec/suma/schema_profile_spec.rb'
383
382
  - 'spec/suma/eengine_converter_spec.rb'
384
383
  - 'spec/suma/eengine_spec.rb'
385
384
  - 'spec/suma/express_reformatter_spec.rb'
386
385
  - 'spec/suma/express_schema_spec.rb'
386
+ - 'spec/suma/gcr_package_spec.rb'
387
387
  - 'spec/suma/jsdai/figure_spec.rb'
388
388
  - 'spec/suma/link_validation_spec.rb'
389
389
  - 'spec/suma/link_validator/step_spec.rb'
390
390
  - 'spec/suma/link_validator_spec.rb'
391
391
  - 'spec/suma/manifest_traverser_spec.rb'
392
392
  - 'spec/suma/note_processor_spec.rb'
393
- - 'spec/suma/publication_spec.rb'
393
+ - 'spec/suma/output_canonicalizer_spec.rb'
394
+ - 'spec/suma/owl_projection_spec.rb'
394
395
  - 'spec/suma/owl_projection_spec.rb'
395
396
  - 'spec/suma/processor_spec.rb'
397
+ - 'spec/suma/provenance_spec.rb'
398
+ - 'spec/suma/publication_spec.rb'
396
399
  - 'spec/suma/register_manifest_generator_spec.rb'
400
+ - 'spec/suma/reproducibility_spec.rb'
401
+ - 'spec/suma/schema_cache_spec.rb'
397
402
  - 'spec/suma/schema_category_spec.rb'
398
403
  - 'spec/suma/schema_comparer_integration_spec.rb'
399
404
  - 'spec/suma/schema_compiler_spec.rb'
@@ -401,15 +406,20 @@ RSpec/MultipleExpectations:
401
406
  - 'spec/suma/schema_exporter_spec.rb'
402
407
  - 'spec/suma/schema_index_spec.rb'
403
408
  - 'spec/suma/schema_naming_spec.rb'
409
+ - 'spec/suma/schema_profile_spec.rb'
404
410
  - 'spec/suma/schema_template_spec.rb'
411
+ - 'spec/suma/site_build_spec.rb'
405
412
  - 'spec/suma/site_config/config_spec.rb'
406
413
  - 'spec/suma/staged_collection_builder_spec.rb'
407
414
  - 'spec/suma/svg_quality/scanner_spec.rb'
408
415
  - 'spec/suma/term_classification_spec.rb'
409
416
  - 'spec/suma/term_extractor_spec.rb'
410
- - 'spec/suma/change_classification_spec.rb'
411
- - 'spec/suma/change_manifest_spec.rb'
412
- - 'spec/suma/change_impact_spec.rb'
417
+ - 'spec/suma/term_extractor_spec.rb'
418
+ - 'spec/suma/urn_resolver_spec.rb'
419
+ - 'spec/suma/worker_pool_spec.rb'
420
+ - 'spec/suma/srl/frame_nav_spec.rb'
421
+ - 'spec/suma/srl/site_verifier_spec.rb'
422
+ - 'spec/suma/srl/stitcher_spec.rb'
413
423
 
414
424
  # Offense count: 3
415
425
  # Configuration parameters: Max, AllowedGroups.
data/lib/suma/cli/core.rb CHANGED
@@ -183,6 +183,9 @@ module Suma
183
183
  desc "validate SUBCOMMAND ...ARGS", "Validate express documents"
184
184
  subcommand "validate", Cli::Validate
185
185
 
186
+ desc "srl SUBCOMMAND ...ARGS", "SRL delivery: stitch per-part bundles into one site"
187
+ subcommand "srl", Cli::Srl
188
+
186
189
  desc "resolve [URN]", "Resolve URNs to canonical JSON + HTML artifacts" # Mirrors so Core accepts the switches Cli::Resolve reparses; the
187
190
  # inner class owns their declarations.
188
191
  option :manifest, type: :string, required: true,
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "thor"
5
+
6
+ module Suma
7
+ module Cli
8
+ # SRL delivery commands (TCSC410303-2952): merge independently
9
+ # rendered per-part bundles into one stitched site with resolved
10
+ # cross-document references.
11
+ class Srl < Thor
12
+ desc "verify SITE_DIR",
13
+ "Verify every link in the stitched site resolves: cross-file " \
14
+ "hrefs to files, fragments to anchors in their target. The " \
15
+ "production gate is zero broken links; exits 1 on any break. " \
16
+ "Intra-file fragment hrefs are reported but do not fail."
17
+ option :out, type: :string,
18
+ desc: "Also write the report as JSON to this path"
19
+ option :no_fragments, type: :boolean, default: false,
20
+ desc: "Skip fragment checking (file existence only)"
21
+
22
+ def verify(site_dir)
23
+ result = Suma::Srl::SiteVerifier.new(site_dir, **verify_options).verify
24
+ log_verify(result)
25
+ raise "broken links found (#{result.broken_count})" unless
26
+ result.broken_count.zero?
27
+ end
28
+
29
+ private
30
+
31
+ def verify_options
32
+ { check_fragments: !options[:no_fragments] }
33
+ end
34
+
35
+ def log_verify(result)
36
+ report = result.report
37
+ write_report(report) if options[:out]
38
+ Utils.log "Links: #{report['total_links']} total, " \
39
+ "#{report['broken_links'].size} broken; " \
40
+ "fragments: #{report['total_fragments']} total, " \
41
+ "#{report['broken_fragments'].size} broken; " \
42
+ "#{report['cross_document_links']} cross-document"
43
+ end
44
+
45
+ def write_report(report)
46
+ File.write(options[:out], JSON.pretty_generate(report))
47
+ end
48
+
49
+ desc "stitch BUNDLES_DIR",
50
+ "Merge per-part SRL bundles (each bundle.json + site/) into one " \
51
+ "_site/, resolving every unresolved-eref span through the " \
52
+ "anchor/doc/attachment registries; writes the audit records " \
53
+ "and the merged index"
54
+ option :plan, type: :string, required: true,
55
+ desc: "plan.json (part inventory: part_dir + doc_id " \
56
+ "per part)"
57
+ option :out, type: :string, required: true,
58
+ desc: "Output merged _site directory"
59
+ option :assets, type: :string,
60
+ desc: "Directory with srl_index.html, images/, sys/ " \
61
+ "frame-navigation assets"
62
+ option :inject, type: :string, banner: "PART_DIR",
63
+ desc: "Rebuilding one part: validate the " \
64
+ "link-signature invariants before stitching"
65
+ option :source_commit, type: :string,
66
+ desc: "Commit SHA recorded in build-info.json"
67
+ option :source_branch, type: :string,
68
+ desc: "Branch recorded in build-info.json"
69
+
70
+ def stitch(bundles_dir)
71
+ result = Suma::Srl::Stitcher.new(**stitch_options(bundles_dir)).stitch
72
+ Utils.log "Stitched #{result.parts.size} into #{options[:out]}: " \
73
+ "#{result.resolved} ok, #{result.broken} broken"
74
+ end
75
+
76
+ def stitch_options(bundles_dir)
77
+ {
78
+ bundles_dir: bundles_dir,
79
+ plan_path: options[:plan],
80
+ out_dir: options[:out],
81
+ assets_dir: options[:assets],
82
+ inject: options[:inject],
83
+ source_commit: options[:source_commit],
84
+ source_branch: options[:source_branch],
85
+ }
86
+ end
87
+ end
88
+ end
89
+ end
data/lib/suma/cli.rb CHANGED
@@ -12,6 +12,7 @@ module Suma
12
12
  autoload :ExtractTerms, "suma/cli/extract_terms"
13
13
  autoload :GenerateRegister, "suma/cli/generate_register"
14
14
  autoload :GenerateSchemas, "suma/cli/generate_schemas"
15
+ autoload :Srl, "suma/cli/srl"
15
16
  autoload :IngestTranslations, "suma/cli/ingest_translations"
16
17
  autoload :PackageGcr, "suma/cli/package_gcr"
17
18
  autoload :Reformat, "suma/cli/reformat"
@@ -0,0 +1,173 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "leptris"
4
+
5
+ module Suma
6
+ module Srl
7
+ # Frame-navigation delivery postprocess (port of suma2srl.py): turns a
8
+ # stitched site into the SRL frameset presentation.
9
+ #
10
+ # - index.html: strip Attachments, unwrap collection/document nesting,
11
+ # flatten the doc list, wire onclick handlers that drive the
12
+ # index+info frames, and add the frameset redirect script.
13
+ # - every document index file: target="info" on all links.
14
+ # - every section file: inject the CSS override suppressing
15
+ # metanorma's built-in sidebar (the left frame replaces it) with
16
+ # the DRAFT watermark. Idempotent on re-runs.
17
+ class FrameNav
18
+ # A faithful port: the constants carry the Python payload verbatim
19
+ # and the metrics would fragment the pipeline without clarifying it.
20
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Layout/LineLength
21
+ FRAMESET_JS = 'if(window.self===window.top)window.location.replace("srl_index.html");else window.addEventListener("pageshow",function(){try{parent.index.location="sys/frame_toc_short.htm"}catch(e){}});'
22
+
23
+ CSS_OVERRIDE = '<style>nav{display:none !important}#toggle{display:none !important}body{margin-left:2em !important}body::after{content:"DRAFT";position:fixed;top:50%;left:50%;transform:translate(-50%,-50%) rotate(-45deg);font-size:8em;font-weight:bold;font-family:sans-serif;color:rgba(200,200,200,0.3);pointer-events:none;z-index:9999;}</style>'
24
+
25
+ PREVIOUS_OVERRIDE_RE = %r{<style>nav\{display:none !important\}.*?</style>}m
26
+ PREVIOUS_TOGGLE_RE = %r{<div id="toggle">\s*<span>[^<]*</span>\s*</div>}m
27
+
28
+ def initialize(site_dir)
29
+ @site_dir = Pathname.new(site_dir)
30
+ end
31
+
32
+ def process
33
+ top_level = process_index
34
+ add_target_attributes(top_level)
35
+ strip_metanorma_sidebar
36
+ top_level
37
+ end
38
+
39
+ private
40
+
41
+ # -- index.html ---------------------------------------------------
42
+
43
+ def process_index
44
+ path = @site_dir / "index.html"
45
+ doc = Leptris::XML.parse_html(path.read)
46
+ strip_index_chrome(doc)
47
+ top_level = build_top_level(doc)
48
+ wire_index_links(doc, top_level)
49
+ inject_frameset_script(doc)
50
+ path.write(doc.to_html)
51
+ top_level
52
+ end
53
+
54
+ def strip_index_chrome(doc)
55
+ # Decompose the element containing the "Attachments" text: the
56
+ # raw index nests the whole schema-exp attachment list inside that
57
+ # <li>, so subtree removal drops all of it (Python decompose).
58
+ doc.xpath("//text()[contains(., 'Attachments')]")
59
+ .each { |t| t.parent.remove }
60
+ # Unwrap two levels above every anchor text naming the collection
61
+ # wrappers ("ISO Collection"/"Document"), then drop the text: the
62
+ # per-document subtrees collapse into the flat list the frameset
63
+ # nav expects. (Text-substring match, doc order, exactly like the
64
+ # Python phase.)
65
+ doc.xpath("//text()[contains(., 'ISO Collection') or " \
66
+ "contains(., 'Document')]").each do |t|
67
+ unwrap(t.parent.parent) if t.parent&.parent
68
+ unwrap(t.parent) if t.parent
69
+ t.parent&.remove_child(t)
70
+ end
71
+ doc.xpath("//text()[contains(., 'STEP Resources Library')]")
72
+ .each { |t| t.parent.remove_child(t) }
73
+ doc.css("nav a").each do |a|
74
+ next unless a.parent&.parent&.name == "ul"
75
+
76
+ unwrap(a.parent.parent)
77
+ unwrap(a.parent)
78
+ end
79
+ end
80
+
81
+ # Replace the node with its children (BeautifulSoup's unwrap).
82
+ def unwrap(node)
83
+ node.children.each { |c| node.add_previous_sibling(c) }
84
+ node.parent.remove_child(node)
85
+ end
86
+
87
+ # href -> the first page of that document (for the onclick target).
88
+ # Single-file documents map to themselves; index files map to the
89
+ # first <a href> inside them, prefixed with the href's subdirectory.
90
+ def build_top_level(doc)
91
+ top_level = {}
92
+ doc.css("a").each do |a|
93
+ href = a["href"]
94
+ top_level[href] = href if href
95
+ end
96
+ top_level.each_key do |href|
97
+ next unless File.basename(href).end_with?("_index.html")
98
+
99
+ top_level[href] = first_page_of(href) || href
100
+ end
101
+ top_level
102
+ end
103
+
104
+ def first_page_of(href)
105
+ doc_path = @site_dir / href
106
+ return nil unless doc_path.exist?
107
+
108
+ first = Leptris::XML.parse_html(doc_path.read).at_css("a[href]")
109
+ return nil unless first
110
+
111
+ subdir = File.dirname(href)
112
+ subdir == "." ? first["href"] : "#{subdir}/#{first['href']}"
113
+ end
114
+
115
+ def wire_index_links(doc, top_level)
116
+ doc.css("a").each do |a|
117
+ href = a["href"]
118
+ next unless href && top_level.key?(href)
119
+
120
+ a["onclick"] =
121
+ if File.basename(href).end_with?("_index.html")
122
+ # Multi-section docs drive both frames; replace() avoids a
123
+ # second history entry so back needs one click.
124
+ "parent.index.location.replace('#{href}');" \
125
+ "parent.info.location='#{top_level[href]}';return false;"
126
+ else
127
+ "parent.info.location='#{top_level[href]}'"
128
+ end
129
+ end
130
+ end
131
+
132
+ def inject_frameset_script(doc)
133
+ # Idempotent: drop previously injected scripts first.
134
+ doc.xpath("//script").each do |s|
135
+ s.parent.remove_child(s) if s.text.include?("window.top")
136
+ end
137
+ head = doc.at_css("head") || doc.at_css("html").prepend_child("<head/>")
138
+ script = doc.create_element("script")
139
+ script.content = FRAMESET_JS
140
+ head.add_child(script)
141
+ end
142
+
143
+ # -- document index files ------------------------------------------
144
+
145
+ def add_target_attributes(top_level)
146
+ top_level.each_key do |href|
147
+ next unless File.basename(href).end_with?("_index.html")
148
+
149
+ doc_path = @site_dir / href
150
+ next unless doc_path.exist?
151
+
152
+ doc = Leptris::XML.parse_html(doc_path.read)
153
+ doc.css("a").each { |a| a["target"] = "info" }
154
+ doc_path.write(doc.to_html)
155
+ end
156
+ end
157
+
158
+ # -- section files ---------------------------------------------------
159
+
160
+ def strip_metanorma_sidebar
161
+ Dir.glob("#{@site_dir}/**/*_section_*.html").each do |file|
162
+ content = File.read(file)
163
+ updated = content
164
+ .gsub(PREVIOUS_OVERRIDE_RE, "")
165
+ .gsub(PREVIOUS_TOGGLE_RE, "")
166
+ .sub("</head>", "#{CSS_OVERRIDE}</head>")
167
+ File.write(file, updated) if updated != content
168
+ end
169
+ end
170
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Layout/LineLength
171
+ end
172
+ end
173
+ end
@@ -0,0 +1,155 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "pathname"
5
+ require "leptris"
6
+
7
+ module Suma
8
+ module Srl
9
+ # Site-wide link verification (port of site_manifest.py verify_links):
10
+ # every cross-file href in the stitched site must resolve to a file,
11
+ # and every fragment must resolve to an anchor in its target file.
12
+ # The production gate is zero broken links. Intra-file fragment hrefs
13
+ # are reported but never fail the build — metanorma emits some whose
14
+ # target is never defined (pre-existing upstream issues, not stitch
15
+ # faults).
16
+ class SiteVerifier
17
+ # A faithful port: the metrics would fragment the link walk
18
+ # without making it clearer.
19
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
20
+ SCHEME_RE = %r{\A(?:https?:|mailto:|javascript:|data:)}
21
+ BARE_INTEGER_RE = /\A\d+\z/
22
+
23
+ Report = Struct.new(:report, keyword_init: true) do
24
+ def broken_count
25
+ report["broken_links"].size + report["broken_fragments"].size
26
+ end
27
+
28
+ def to_json(*)
29
+ JSON.generate(report)
30
+ end
31
+ end
32
+
33
+ def initialize(site_dir, check_fragments: true)
34
+ @site_dir = Pathname.new(site_dir)
35
+ @check_fragments = check_fragments
36
+ end
37
+
38
+ def verify
39
+ report = empty_report
40
+ anchor_index = build_anchor_index
41
+ html_files.each do |html_file|
42
+ rel_path = html_file.relative_path_from(@site_dir).to_s
43
+ doc = Leptris::XML.parse_html(html_file.read)
44
+ verify_intra_fragments(doc, rel_path, html_file, report)
45
+ verify_links(doc, rel_path, html_file, anchor_index, report)
46
+ end
47
+ Report.new(report: report)
48
+ end
49
+
50
+ private
51
+
52
+ def empty_report
53
+ {
54
+ "total_links" => 0,
55
+ "resolved_links" => 0,
56
+ "broken_links" => [],
57
+ "total_fragments" => 0,
58
+ "resolved_fragments" => 0,
59
+ "broken_fragments" => [],
60
+ "cross_document_links" => 0,
61
+ "total_intra_fragments" => 0,
62
+ "resolved_intra_fragments" => 0,
63
+ "broken_intra_fragments" => [],
64
+ }
65
+ end
66
+
67
+ def html_files
68
+ Dir.glob("#{@site_dir}/**/*.html")
69
+ .reject { |f| f.end_with?(".err.html") }
70
+ .sort.map { |f| Pathname.new(f) }
71
+ end
72
+
73
+ def anchors_of(path)
74
+ Leptris::XML.parse_html(path.read).css("[id]").map { |n| n["id"] }.uniq
75
+ end
76
+
77
+ def build_anchor_index
78
+ html_files.to_h do |html_file|
79
+ rel = html_file.relative_path_from(@site_dir).to_s
80
+ [rel, anchors_of(html_file)]
81
+ end
82
+ end
83
+
84
+ def verify_intra_fragments(doc, rel_path, html_file, report)
85
+ own_anchors = anchors_of(html_file)
86
+ doc.css("a[href]").each do |a|
87
+ href = a["href"].to_s.strip
88
+ next unless href.start_with?("#") && href.length > 1
89
+
90
+ fragment = href[1..]
91
+ report["total_intra_fragments"] += 1
92
+ if own_anchors.include?(fragment)
93
+ report["resolved_intra_fragments"] += 1
94
+ else
95
+ report["broken_intra_fragments"] <<
96
+ { "source" => rel_path, "fragment" => fragment }
97
+ end
98
+ end
99
+ end
100
+
101
+ def verify_links(doc, rel_path, html_file, anchor_index, report)
102
+ source_dir = Pathname.new(rel_path).parent
103
+ doc.css("a[href]").each do |a|
104
+ href = a["href"].to_s.strip
105
+ next if href.empty? || href.start_with?("#")
106
+ next if href.match?(SCHEME_RE)
107
+ next if href.match?(BARE_INTEGER_RE)
108
+
109
+ file_part, fragment = href.split("#", 2)
110
+ file_part = file_part.delete_prefix("./")
111
+
112
+ report["total_links"] += 1
113
+ target = html_file.parent / file_part
114
+ unless target.exist?
115
+ report["broken_links"] << {
116
+ "source" => rel_path,
117
+ "href" => fragment ? "#{file_part}##{fragment}" : file_part,
118
+ }
119
+ next
120
+ end
121
+ report["resolved_links"] += 1
122
+ count_cross_document(source_dir, target, report)
123
+ verify_fragment(fragment, target, rel_path, anchor_index, report)
124
+ end
125
+ end
126
+
127
+ def count_cross_document(source_dir, target, report)
128
+ target_rel = target.relative_path_from(@site_dir)
129
+ return unless source_dir != target_rel.parent && source_dir.to_s != "."
130
+
131
+ report["cross_document_links"] += 1
132
+ rescue ArgumentError
133
+ nil
134
+ end
135
+
136
+ def verify_fragment(fragment, target, rel_path, anchor_index, report)
137
+ return unless fragment && @check_fragments
138
+
139
+ report["total_fragments"] += 1
140
+ target_rel = target.relative_path_from(@site_dir).to_s
141
+ if anchor_index.fetch(target_rel, Set.new).include?(fragment)
142
+ report["resolved_fragments"] += 1
143
+ else
144
+ report["broken_fragments"] << {
145
+ "source" => rel_path,
146
+ "href" => "#{target.basename}##{fragment}",
147
+ "fragment" => fragment,
148
+ "target_file" => target_rel,
149
+ }
150
+ end
151
+ end
152
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
153
+ end
154
+ end
155
+ end
@@ -0,0 +1,487 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "erb"
4
+ require "fileutils"
5
+ require "json"
6
+ require "pathname"
7
+ require "leptris"
8
+
9
+ module Suma
10
+ module Srl
11
+ # Merge independently rendered per-part sites into a single _site/,
12
+ # rewriting each part's <span class="unresolved-eref"
13
+ # data-bibitemid="…"> markers into cross-document <a href> elements
14
+ # resolved through anchor, document and attachment registries built
15
+ # from every bundle in the merge (TCSC410303-2952; port of
16
+ # scripts/suma2srl/srl_stitch.py).
17
+ #
18
+ # Correctness model (design doc §4): cross-doc bibitemids carry
19
+ # content-derived identifiers, and content-derived anchors are stable
20
+ # across per-part and full-collection build modes, so a full merge
21
+ # resolves every cross-doc reference; a broken record can only mean
22
+ # the target's bundle is absent from the merge.
23
+ #
24
+ # The stitch is atomic: everything lands in <out>.tmp, and the swap
25
+ # to <out> happens only after every step succeeded.
26
+ class Stitcher
27
+ # A faithful port of an algorithmic pipeline: the metrics would
28
+ # fragment it without making it clearer.
29
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/ParameterLists, Layout/LineLength
30
+ # `<scope>_ISO_<docid>_<year>_…`: the scope is the lowercase
31
+ # identifier prefix. For docs published as IS the suffix is
32
+ # `_ISO_10303-43_2025_…`; for DIS/TS a docstage prefix appears
33
+ # between `_ISO_` and the docid.
34
+ ANCHOR_SCOPE_RE = /\A([a-z][a-z0-9_]*(?:\.[a-z0-9_.]+)?)_ISO_(?:[A-Z]+_)?[A-Za-z0-9-]+_[0-9]+(?:_ISO_.+)?\z/
35
+
36
+ # `express_<scope>_ISO_…`: schema/entity references.
37
+ EXPRESS_BIBID_RE = /\Aexpress_([a-z][a-z0-9_]*(?:\.[a-z0-9_.]+)?)_ISO_/
38
+
39
+ # `<schema>.html_ISO_…` / `<schema>.exp_ISO_…`: attachment refs.
40
+ ATTACHMENT_BIBID_RE = /\A([a-z][a-z0-9_]*\.(?:html|exp))_ISO_/
41
+
42
+ # Document-level bibitemid, both observed forms:
43
+ # `ISO_<docid>_ISO_…` and the relaton-style `iso<docnum>-<part>_ISO_…`.
44
+ DOC_LEVEL_BIBID_RE = /\A(?:ISO_(?<a>[A-Za-z0-9-]+)|iso(?<b>\d+-\d+))_ISO_/
45
+
46
+ SHARED_DIRS = %w[schema_docs plain_schemas].freeze
47
+ FRAME_ASSETS = %w[srl_index.html].freeze
48
+ FRAME_ASSET_DIRS = %w[images sys].freeze
49
+
50
+ Registries = Struct.new(:anchors, :docs, :attachments)
51
+ Result = Struct.new(:resolved, :broken, :parts, keyword_init: true)
52
+
53
+ # (a data-declaring initializer)
54
+ def initialize(bundles_dir:, plan_path:, out_dir:, assets_dir: nil,
55
+ inject: nil, source_repo: "wg12-step",
56
+ source_commit: nil, source_branch: nil)
57
+ @bundles_dir = Pathname.new(bundles_dir)
58
+ @plan = JSON.parse(File.read(plan_path))
59
+ @out_dir = Pathname.new(out_dir)
60
+ @assets_dir = assets_dir && Pathname.new(assets_dir)
61
+ @inject = inject
62
+ @source_repo = source_repo
63
+ @source_commit = source_commit
64
+ @source_branch = source_branch
65
+ end
66
+
67
+ def stitch
68
+ bundles = load_bundles
69
+ raise "No bundles loaded — nothing to stitch" if bundles.empty?
70
+
71
+ validate_injection(@inject, bundles) if @inject
72
+ registries = build_registries(bundles)
73
+ out_tmp = stage_merged_site(bundles)
74
+ registries.attachments = build_attachment_registry(out_tmp)
75
+ counts = patch_xrefs(out_tmp, registries)
76
+ write_merged_index(out_tmp, bundles)
77
+ copy_frame_assets(out_tmp)
78
+ write_collection_errors(out_tmp, bundles, counts)
79
+ write_build_info(out_tmp, bundles)
80
+ write_stitch_summary(out_tmp, bundles, registries, counts)
81
+ atomic_swap(out_tmp)
82
+ Result.new(resolved: counts[:resolved], broken: counts[:broken],
83
+ parts: bundles.keys.sort)
84
+ end
85
+
86
+ private
87
+
88
+ def load_bundles
89
+ @plan["parts"].each_with_object({}) do |entry, h|
90
+ part_dir = entry["part_dir"]
91
+ path = @bundles_dir / part_dir / "bundle.json"
92
+ h[part_dir] = JSON.parse(path.read) if path.exist?
93
+ end
94
+ end
95
+
96
+ # -- registries --------------------------------------------------
97
+
98
+ def build_registries(bundles)
99
+ anchors = {}
100
+ docs = {}
101
+ bundles.each do |part_dir, bundle|
102
+ iso_name = bundle["iso_name"]
103
+ index_anchors(bundle).each do |file, anchor|
104
+ scope = anchor_scope(anchor)
105
+ anchors[scope] ||= [iso_name, file, anchor] if scope
106
+ end
107
+ entry = @plan["parts"].find { |p| p["part_dir"] == part_dir }
108
+ docs["ISO_#{entry['doc_id']}"] = iso_name if entry
109
+ end
110
+ Registries.new(anchors, docs, {})
111
+ end
112
+
113
+ def index_anchors(bundle)
114
+ bundle["anchors"].flat_map do |file, list|
115
+ list.map { |a| [file, a] }
116
+ end
117
+ end
118
+
119
+ def anchor_scope(anchor)
120
+ ANCHOR_SCOPE_RE.match(anchor)&.[](1)
121
+ end
122
+
123
+ def build_attachment_registry(out_dir)
124
+ registry = {}
125
+ schema_docs = out_dir / "schema_docs"
126
+ schema_docs.glob("doc_*.html").sort.each do |html|
127
+ stem = html.basename.to_s.delete_suffix(".html")
128
+ key = "#{stem.delete_prefix('doc_')}.html"
129
+ registry[key] = [nil, html.relative_path_from(out_dir).to_s, nil]
130
+ end
131
+ plain = out_dir / "plain_schemas"
132
+ plain.glob("**/*.exp").sort.each do |exp|
133
+ registry[exp.basename.to_s] =
134
+ [nil, exp.relative_path_from(out_dir).to_s, nil]
135
+ end
136
+ registry
137
+ end
138
+
139
+ def resolve_bibitemid(bibitemid, registries)
140
+ return nil if bibitemid.nil? || bibitemid.empty?
141
+
142
+ if (m = EXPRESS_BIBID_RE.match(bibitemid))
143
+ return registries.anchors[m[1]]
144
+ end
145
+ return registries.attachments[m[1]] if (m = ATTACHMENT_BIBID_RE.match(bibitemid))
146
+
147
+ doc_level_target(bibitemid, registries)
148
+ end
149
+
150
+ def doc_level_target(bibitemid, registries)
151
+ m = DOC_LEVEL_BIBID_RE.match(bibitemid) or return nil
152
+ docid_key = m[:a] ? "ISO_#{m[:a]}" : "ISO_#{m[:b]}"
153
+ iso = registries.docs[docid_key] or return nil
154
+ [iso, "#{iso}_index.html", nil]
155
+ end
156
+
157
+ # -- merge + rewrite ----------------------------------------------
158
+
159
+ def stage_merged_site(bundles)
160
+ out_tmp = out_tmp_dir
161
+ FileUtils.rm_rf(out_tmp)
162
+ FileUtils.mkdir_p(out_tmp)
163
+ bundles.each do |part_dir, bundle|
164
+ merge_bundle(part_dir, bundle, out_tmp)
165
+ end
166
+ out_tmp
167
+ end
168
+
169
+ def merge_bundle(part_dir, bundle, out_tmp)
170
+ src_site = @bundles_dir / part_dir / "site"
171
+ iso_dir = src_site / bundle["iso_name"]
172
+ FileUtils.cp_r(iso_dir, out_tmp / bundle["iso_name"]) if iso_dir.exist?
173
+ SHARED_DIRS.each do |shared|
174
+ src = src_site / shared
175
+ merge_tree(src, out_tmp / shared) if src.exist?
176
+ end
177
+ end
178
+
179
+ def patch_xrefs(out_dir, registries)
180
+ resolved = 0
181
+ broken_records = []
182
+ html_files(out_dir).each do |html_file|
183
+ dirty = patch_file_xrefs(html_file, out_dir, registries) do |record|
184
+ broken_records << record
185
+ end
186
+ resolved += dirty
187
+ end
188
+ write_broken_xrefs(out_dir, broken_records)
189
+ { resolved: resolved, broken: broken_records.size }
190
+ end
191
+
192
+ # Returns the number of resolved spans in this file; broken spans
193
+ # are yielded as audit records.
194
+ def patch_file_xrefs(html_file, out_dir, registries)
195
+ owning_iso = infer_owning_iso(html_file, out_dir)
196
+ doc = Leptris::XML.parse_html(html_file.read)
197
+ resolved = 0
198
+ doc.css("span.unresolved-eref").each do |span|
199
+ target = resolve_bibitemid(span["data-bibitemid"].to_s, registries)
200
+ if target.nil?
201
+ yield broken_record(html_file, out_dir, span)
202
+ next
203
+ end
204
+ span.replace(resolved_link(owning_iso, target, span.text))
205
+ resolved += 1
206
+ end
207
+ html_file.write(doc.to_html) if resolved.positive?
208
+ resolved
209
+ end
210
+
211
+ def broken_record(html_file, out_dir, span)
212
+ {
213
+ "source_file" => html_file.relative_path_from(out_dir).to_s,
214
+ "bibitemid" => span["data-bibitemid"].to_s,
215
+ "display_text" => span.text.strip,
216
+ }
217
+ end
218
+
219
+ def resolved_link(owning_iso, target, text)
220
+ target_iso, target_file, target_anchor = target
221
+ href = link_href(owning_iso, target_iso, target_file)
222
+ href = "#{href}##{target_anchor}" if target_anchor
223
+ "<a href=\"#{ERB::Util.html_escape(href)}\" " \
224
+ "class=\"resolved-eref\">#{ERB::Util.html_escape(text)}</a>"
225
+ end
226
+
227
+ def link_href(owning_iso, target_iso, target_file)
228
+ return "../#{target_file}" if target_iso.nil?
229
+ return target_file.to_s if owning_iso == target_iso
230
+
231
+ "../#{target_iso}/#{target_file}"
232
+ end
233
+
234
+ def html_files(out_dir)
235
+ Dir.glob("#{out_dir}/**/*.html")
236
+ .reject { |f| f.end_with?(".err.html") }
237
+ .map { |f| Pathname.new(f) }
238
+ end
239
+
240
+ def infer_owning_iso(html_file, out_dir)
241
+ first = html_file.relative_path_from(out_dir).to_s
242
+ .split(File::SEPARATOR)[0].to_s
243
+ first.start_with?("ISO_") ? first : ""
244
+ end
245
+
246
+ def merge_tree(src, dst)
247
+ FileUtils.mkdir_p(dst)
248
+ src.each_child do |entry|
249
+ target = dst / entry.basename
250
+ next if target.exist? && entry.file?
251
+
252
+ if entry.directory?
253
+ merge_tree(entry,
254
+ target)
255
+ else
256
+ FileUtils.cp(entry, target)
257
+ end
258
+ end
259
+ end
260
+
261
+ # -- synthesized artifacts ----------------------------------------
262
+
263
+ def write_merged_index(out_dir, bundles)
264
+ rows = @plan["parts"].filter_map do |entry|
265
+ bundle = bundles[entry["part_dir"]] or next
266
+ iso_name = bundle["iso_name"]
267
+ %(<li><a href="#{iso_name}/#{iso_name}_index.html">#{iso_name}</a></li>)
268
+ end
269
+ html = <<~HTML
270
+ <!DOCTYPE html>
271
+ <html><head>
272
+ <meta charset="utf-8"/>
273
+ <title>STEP Resources Library</title>
274
+ </head><body>
275
+ <h1>STEP Resources Library</h1>
276
+ <ul>
277
+ #{rows.join("\n")}
278
+ </ul>
279
+ </body></html>
280
+ HTML
281
+ (out_dir / "index.html").write(html)
282
+ end
283
+
284
+ def copy_frame_assets(out_dir)
285
+ return unless @assets_dir&.exist?
286
+
287
+ FRAME_ASSETS.each do |name|
288
+ src = @assets_dir / name
289
+ FileUtils.cp(src, out_dir / name) if src.exist?
290
+ end
291
+ FRAME_ASSET_DIRS.each do |name|
292
+ src = @assets_dir / name
293
+ next unless src.directory?
294
+
295
+ dst = out_dir / name
296
+ FileUtils.rm_rf(dst)
297
+ FileUtils.cp_r(src, dst)
298
+ end
299
+ end
300
+
301
+ def write_collection_errors(out_dir, bundles, counts)
302
+ entries = JSON.parse((out_dir / "broken_xrefs.json").read)["entries"]
303
+ warnings = bundles.values.flat_map do |bundle|
304
+ bundle.dig("errors", "build_warnings").to_a
305
+ .map { |w| [bundle["iso_name"], w] }
306
+ end
307
+ rows = entries.map { |e| xref_error_row(e) } +
308
+ warnings.map { |iso, warn| error_row(iso, "Build warning", warn) }
309
+ html = error_page_html(rows, counts, warnings.size)
310
+ (out_dir / "collection-errors.html").write(html)
311
+ end
312
+
313
+ def xref_error_row(entry)
314
+ iso = entry["source_file"].to_s.split("/", 2)[0].to_s
315
+ detail = "bibitemid=#{entry['bibitemid'].to_s[0, 140]} " \
316
+ "text=#{entry['display_text'].to_s.inspect}"
317
+ error_row(iso, "Unresolved cross-doc xref", detail)
318
+ end
319
+
320
+ def error_row(iso, klass, detail)
321
+ cell = iso.empty? ? "&nbsp;" : ERB::Util.html_escape(iso)
322
+ "<tr><td>#{cell}</td><td>#{klass}</td>" \
323
+ "<td><code>#{ERB::Util.html_escape(detail)}</code></td></tr>"
324
+ end
325
+
326
+ def error_page_html(rows, counts, warning_count)
327
+ <<~HTML
328
+ <!DOCTYPE html>
329
+ <html><head><meta charset="utf-8"/><title>SRL Collection Errors</title>
330
+ <style>body{font-family:sans-serif;margin:1em}table{border-collapse:collapse;width:100%}
331
+ th,td{border:1px solid #ccc;padding:.3em .6em;text-align:left;vertical-align:top}
332
+ th{background:#f0f0f0}code{word-break:break-all}</style>
333
+ </head><body>
334
+ <h1>SRL Collection Errors</h1>
335
+ <p>Aggregated from per-bundle build warnings and unresolved cross-document references.</p>
336
+ <p><strong>#{counts[:resolved]}</strong> cross-doc xrefs resolved, <strong>#{counts[:broken]}</strong> unresolved,
337
+ <strong>#{warning_count}</strong> build warnings.</p>
338
+ <table>
339
+ <tr><th>Document</th><th>Class</th><th>Detail</th></tr>
340
+ #{rows.join("\n")}
341
+ </table>
342
+ </body></html>
343
+ HTML
344
+ end
345
+
346
+ def write_build_info(out_dir, bundles)
347
+ info = {
348
+ "source_repo" => @source_repo,
349
+ "source_commit" => @source_commit || @plan["build_commit"] || "unknown",
350
+ "source_branch" => @source_branch || "unknown",
351
+ "build_timestamp" => Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ"),
352
+ "build_result" => "SUCCESSFUL",
353
+ "parts_count" => bundles.size,
354
+ "stitcher" => "suma srl stitch (TCSC410303-2952)",
355
+ }
356
+ (out_dir / "build-info.json").write(JSON.pretty_generate(info))
357
+ end
358
+
359
+ def write_stitch_summary(out_dir, bundles, registries, counts)
360
+ summary = {
361
+ "version" => 1,
362
+ "stitch_timestamp" => Time.now.utc.iso8601,
363
+ "build_commit" => @plan["build_commit"],
364
+ "inject_target" => @inject,
365
+ "parts_stitched" => bundles.keys.sort,
366
+ "anchor_registry_size" => registries.anchors.size,
367
+ "doc_registry_size" => registries.docs.size,
368
+ "xrefs_resolved" => counts[:resolved],
369
+ "xrefs_broken" => counts[:broken],
370
+ }
371
+ (out_dir / "stitch_summary.json").write(JSON.pretty_generate(summary))
372
+ end
373
+
374
+ def write_broken_xrefs(out_dir, broken_records)
375
+ (out_dir / "broken_xrefs.json").write(JSON.pretty_generate({
376
+ "version" => 1,
377
+ "count" => broken_records.size,
378
+ "entries" => broken_records,
379
+ }))
380
+ end
381
+
382
+ def out_tmp_dir
383
+ @out_dir.parent / "#{@out_dir.basename}.tmp"
384
+ end
385
+
386
+ def atomic_swap(out_tmp)
387
+ old = @out_dir.parent / "#{@out_dir.basename}.old"
388
+ FileUtils.rm_rf(old)
389
+ @out_dir.exist? and FileUtils.mv(@out_dir, old)
390
+ FileUtils.mv(out_tmp, @out_dir)
391
+ FileUtils.rm_rf(old)
392
+ end
393
+
394
+ # -- inject invariants (design doc §8) ----------------------------
395
+
396
+ def validate_injection(part_dir, bundles)
397
+ new_bundle = bundles[part_dir] or
398
+ raise "inject #{part_dir}: no current bundle loaded"
399
+ prev_bundle = prev_bundle_for(part_dir)
400
+ failures = injection_failures(part_dir, bundles, prev_bundle,
401
+ new_bundle)
402
+ raise "inject #{part_dir} rejected:\n#{failures.join("\n")}" if failures.any?
403
+ end
404
+
405
+ def prev_bundle_for(part_dir)
406
+ path = @bundles_dir / part_dir / "bundle.json.previous"
407
+ path.exist? ? JSON.parse(path.read) : nil
408
+ end
409
+
410
+ def injection_failures(part_dir, bundles, prev_bundle,
411
+ new_bundle)
412
+ failures = []
413
+ if prev_bundle && new_bundle["iso_name"] != prev_bundle["iso_name"]
414
+ failures << identity_failure(
415
+ prev_bundle, new_bundle
416
+ )
417
+ end
418
+ failures.concat(anchor_regression_failure(part_dir, bundles,
419
+ prev_bundle, new_bundle))
420
+ failures.concat(unresolvable_reference_failure(
421
+ bundles, new_bundle
422
+ ))
423
+ failures
424
+ end
425
+
426
+ def identity_failure(prev_bundle, new_bundle)
427
+ "identity: iso_name changed from #{prev_bundle['iso_name'].inspect} " \
428
+ "to #{new_bundle['iso_name'].inspect}; a full re-stitch is required."
429
+ end
430
+
431
+ def anchor_regression_failure(part_dir, bundles, prev_bundle, new_bundle)
432
+ return [] unless prev_bundle
433
+
434
+ consumed = consumed_scopes(part_dir, bundles, prev_bundle)
435
+ dropped = consumed - bundle_scopes(new_bundle)
436
+ return [] if dropped.empty?
437
+
438
+ ["anchor regression: #{dropped.size} scope(s) consumed by other parts " \
439
+ "are missing from the new bundle. Examples: #{dropped.sort.first(5)}"]
440
+ end
441
+
442
+ def consumed_scopes(part_dir, bundles, prev_bundle)
443
+ prev_scopes = bundle_scopes(prev_bundle)
444
+ bundles.filter_map do |other, other_bundle|
445
+ next if other == part_dir
446
+
447
+ other_bundle["unresolved_xrefs"].to_a
448
+ .map { |ux| scope_from_bibitemid(ux["bibitemid"].to_s) }
449
+ .select { |scope| scope && prev_scopes.include?(scope) }
450
+ end.flatten.uniq
451
+ end
452
+
453
+ def unresolvable_reference_failure(bundles, new_bundle)
454
+ all_scopes = bundles.values.flat_map { |b| bundle_scopes(b) }.uniq
455
+ anomalies = new_bundle["unresolved_xrefs"].to_a.filter_map do |ux|
456
+ unresolvable_scope(ux, all_scopes)
457
+ end
458
+ return [] if anomalies.empty?
459
+
460
+ sample = anomalies.first(3).map { |u| u["bibitemid"].to_s[0, 80] }
461
+ ["unresolvable new references: #{anomalies.size} bibitemid(s) target " \
462
+ "schemas not owned by any SRL part. Examples: #{sample}"]
463
+ end
464
+
465
+ def unresolvable_scope(unresolved, all_scopes)
466
+ m = EXPRESS_BIBID_RE.match(unresolved["bibitemid"].to_s) or return nil
467
+ scope = m[1]
468
+ return nil if all_scopes.include?(scope)
469
+
470
+ schema = scope.split(".", 2)[0]
471
+ return nil if all_scopes.any? { |s| s.split(".", 2)[0] == schema }
472
+
473
+ unresolved
474
+ end
475
+
476
+ def bundle_scopes(bundle)
477
+ (bundle["anchors"] || {}).values.flatten
478
+ .filter_map { |a| anchor_scope(a) }.uniq
479
+ end
480
+
481
+ def scope_from_bibitemid(bibitemid)
482
+ EXPRESS_BIBID_RE.match(bibitemid)&.[](1)
483
+ end
484
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/ParameterLists, Layout/LineLength
485
+ end
486
+ end
487
+ end
data/lib/suma/srl.rb ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Suma
4
+ # SRL delivery subsystem (TCSC410303-2952): merge independently rendered
5
+ # per-part sites and resolve their unresolved cross-document references.
6
+ module Srl
7
+ autoload :FrameNav, "suma/srl/frame_nav"
8
+ autoload :SiteVerifier, "suma/srl/site_verifier"
9
+ autoload :Stitcher, "suma/srl/stitcher"
10
+ end
11
+ end
@@ -79,7 +79,7 @@ module Suma
79
79
  stage_members(staged)
80
80
  return if @shard || @isolate
81
81
 
82
- reinflate(reinflate_selection(members))
82
+ reinflate(reinflate_selection(members), members)
83
83
  end
84
84
 
85
85
  private
@@ -367,13 +367,18 @@ module Suma
367
367
  # for its stored stub; the render resolves paths against the
368
368
  # reinflate manifest's own directory, so every path the render reads
369
369
  # is absolutized against the collection root (suma#168, suma#169).
370
- def reinflate(members)
370
+ def reinflate(render_members, all_members = render_members)
371
371
  reinf_dir = File.join(@output_directory, "_staged_reinflate")
372
372
  FileUtils.mkdir_p(reinf_dir)
373
- docrefs = stored_docrefs(members, reinf_dir)
373
+ # Stub every member: the render passes read each member's stored
374
+ # file for the anchors and cross-references, whatever this run is
375
+ # going to render. A reinflate shard additionally restricts the
376
+ # rendered members; sibling runs over the same store render the
377
+ # rest.
378
+ docrefs = stored_docrefs(all_members, reinf_dir)
374
379
  write_reinflate_manifest(docrefs, reinf_dir)
375
380
  run_render(manifest_path: File.join(reinf_dir, "reinflate.yml"),
376
- opts: reinflate_render_options)
381
+ opts: reinflate_render_options(render_members))
377
382
  end
378
383
 
379
384
  def write_reinflate_manifest(docrefs, reinf_dir)
@@ -385,14 +390,18 @@ module Suma
385
390
  "#{@output_directory}"
386
391
  end
387
392
 
388
- def reinflate_render_options
389
- {
393
+ def reinflate_render_options(render_members = nil)
394
+ opts = {
390
395
  format: @formats,
391
396
  output_folder: File.expand_path(@output_directory),
392
397
  reinflate: true,
393
398
  coverpage: @coverpage && File.expand_path(@coverpage, @config_dir),
394
399
  compile: compile_flags,
395
- }.compact
400
+ }
401
+ if @reinflate_shard && render_members
402
+ opts[:only_members] = render_members.filter_map { |m| m["identifier"] }
403
+ end
404
+ opts.compact
396
405
  end
397
406
 
398
407
  # Deep-copy the manifest tree, replacing each member entry (same
data/lib/suma/thor_ext.rb CHANGED
@@ -60,7 +60,7 @@ module Suma
60
60
  return if error.is_a?(Errno::EPIPE)
61
61
  raise if ENV["VERBOSE"] || !config.fetch(:exit_on_failure, true)
62
62
 
63
- message = error.message.to_s
63
+ message = error.message.dup
64
64
  message.prepend("[#{error.class}] ") if message.empty? || !error.is_a?(Thor::Error)
65
65
 
66
66
  config[:shell]&.say_error(message, :red)
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.21"
4
+ VERSION = "0.5.23"
5
5
  end
data/lib/suma.rb CHANGED
@@ -34,6 +34,7 @@ module Suma
34
34
  autoload :NullCache, "suma/null_cache"
35
35
  autoload :OutputCanonicalizer, "suma/output_canonicalizer"
36
36
  autoload :OwlProjection, "suma/owl_projection"
37
+ autoload :Srl, "suma/srl"
37
38
  autoload :RegisterManifestGenerator, "suma/register_manifest_generator"
38
39
  autoload :SchemaCache, "suma/schema_cache"
39
40
  autoload :SchemaCategory, "suma/schema_category"
data/suma.gemspec CHANGED
@@ -35,6 +35,7 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
35
35
 
36
36
  spec.add_dependency "expressir"
37
37
  spec.add_dependency "glossarist", "~> 2.8", ">= 2.8.7"
38
+ spec.add_dependency "leptris"
38
39
  spec.add_dependency "lutaml-model", "~> 0.8.0"
39
40
  spec.add_dependency "metanorma", "~> 2.3"
40
41
  spec.add_dependency "plurimath"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: suma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.21
4
+ version: 0.5.23
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-02 00:00:00.000000000 Z
11
+ date: 2026-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: expressir
@@ -44,6 +44,20 @@ dependencies:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: 2.8.7
47
+ - !ruby/object:Gem::Dependency
48
+ name: leptris
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: lutaml-model
49
63
  requirement: !ruby/object:Gem::Requirement
@@ -206,6 +220,7 @@ files:
206
220
  - lib/suma/cli/package_gcr.rb
207
221
  - lib/suma/cli/reformat.rb
208
222
  - lib/suma/cli/resolve.rb
223
+ - lib/suma/cli/srl.rb
209
224
  - lib/suma/cli/validate.rb
210
225
  - lib/suma/cli/validate_links.rb
211
226
  - lib/suma/closure_validator.rb
@@ -254,6 +269,10 @@ files:
254
269
  - lib/suma/schema_template/plain.rb
255
270
  - lib/suma/site_build.rb
256
271
  - lib/suma/site_config.rb
272
+ - lib/suma/srl.rb
273
+ - lib/suma/srl/frame_nav.rb
274
+ - lib/suma/srl/site_verifier.rb
275
+ - lib/suma/srl/stitcher.rb
257
276
  - lib/suma/staged_collection_builder.rb
258
277
  - lib/suma/svg_quality.rb
259
278
  - lib/suma/svg_quality/batch_report.rb