crawlscope 0.11.2 → 0.12.0

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: e8f15e4f938806d9a6859dcf818302fe7f35321c360e70e1be6451d4e5af96cc
4
- data.tar.gz: 85a405a9ca3b1b25655ec3aa9c72dcc1fd3c51fc2303b3831bb7c88ea1e597de
3
+ metadata.gz: 8f9bf93433bdb0fc915c3d5f0fb241fc68d3521da6bad1fa46740c780717292c
4
+ data.tar.gz: 6960e43e1cc448d6e8c31b5794f6bef0e360d50319748bf60dbbdf5d0b9a57b1
5
5
  SHA512:
6
- metadata.gz: d3c1f8eef1e50c42f61edf897487ff3c60b071d76757bf2a0a2697c56da3e1fc8625e484f545eb42f522f44a7bf4d4b77850b8c0225e77087fb5345eeee34cd3
7
- data.tar.gz: 16a78c6d5694a3a5ea31ec2011eeec41b74fe4b74fbed9d27264d4c86f353412c688eacbb7a345cd9e88b2430889763223762fb6743cd59d8587e434261f7539
6
+ metadata.gz: 54dff98bcdf379462815ecb90dd2081218efec887c7ac99b7122ce4d8756aef45fe22ee48017f85224e809f0fb992d6b99dba2b657e3ce25c5d411693ec77a9f
7
+ data.tar.gz: 43790d06c581749e1333199f72d97ce7f9d1763fd0ee46344abbef800329279c583948a0527966da4dea1df2fbbe79c550a78bf5a43c0c1541a338dfbb223253
data/CHANGELOG.md CHANGED
@@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.12.0] - 2026-12-02
9
+
10
+
11
+ ### Added
12
+
13
+ - validate datasets and report warnings
14
+
15
+
16
+
8
17
  ## [0.11.2] - 2026-11-29
9
18
 
10
19
 
data/UPGRADE.md CHANGED
@@ -37,6 +37,20 @@ in the README; the shared workflow does not inherit another gem's permission.
37
37
 
38
38
  ## Next Release
39
39
 
40
+ ### Structured-data warnings
41
+
42
+ Direct audit JSON reports now include `validation_warnings` beside
43
+ `validation_errors`. Update consumers with strict report schemas to accept
44
+ the new field. Ruby consumers can read `Entry#warnings`; warnings do not
45
+ change `Outcome#ok?`. Sitemap reports include two new advisory issue codes:
46
+ `structured_data_unsupported_type` and
47
+ `structured_data_missing_recommended_property`.
48
+
49
+ Custom registry implementations must implement `warnings(item)` alongside
50
+ `validate(item)`, or subclass `Crawlscope::SchemaRegistry`. Custom schemas can
51
+ declare a `recommended` list to enable missing-property warnings. Hosts with
52
+ their own Dataset schema can retain stricter licensing rules.
53
+
40
54
  ### Paginated link evidence
41
55
 
42
56
  Set `config.pagination_parameters` or
data/docs/rules.md CHANGED
@@ -38,12 +38,42 @@ Checks:
38
38
  - malformed JSON-LD
39
39
  - missing required fields for supported schema types
40
40
  - schema validation failures from the configured registry
41
+ - unsupported top-level and graph schema types
42
+ - missing recommended properties in registered schemas
41
43
  - direct URL structured-data audits through `crawlscope:validate:ldjson`
42
44
 
43
45
  Sitemap and direct URL audits share the same document validator, including
44
46
  missing `@type` checks. Direct URL audits treat missing markup as a failure;
45
47
  sitemap audits retain their warning severity for structured-data findings.
46
48
 
49
+ ### Schema warnings
50
+
51
+ An unregistered type produces `structured_data_unsupported_type`. It is not
52
+ proof of invalid markup: Crawlscope has no schema to validate it against.
53
+ Missing recommended fields produce `structured_data_missing_recommended_property`.
54
+ Both are advisory findings in sitemap and direct audits. Direct audits retain
55
+ their successful exit status if only warnings are present and include them in
56
+ the console and JSON report. Missing required properties remain validation
57
+ errors.
58
+
59
+ The Dataset schema follows [Google's dataset metadata guidance](https://developers.google.com/search/docs/appearance/structured-data/dataset).
60
+ It requires a name and description and validates download URLs when distributions
61
+ are supplied. The registry also checks recommended dataset properties (including
62
+ license) and download formats. Some recommendations only apply to certain
63
+ datasets; a warning is an invitation to review applicability, not to invent
64
+ metadata. DataCatalog and DataDownload are registered independently.
65
+
66
+ Hosts can declare recommended properties in custom schemas using a
67
+ `recommended` list alongside JSON Schema's `required` list:
68
+
69
+ ```ruby
70
+ registry.register("Dataset", {
71
+ type: "object",
72
+ required: %w[name description],
73
+ recommended: %w[license creator]
74
+ })
75
+ ```
76
+
47
77
  ### Required types by URL
48
78
 
49
79
  Schema validation checks the markup a page contains. To detect a missing type
@@ -130,6 +160,9 @@ Checks:
130
160
  - `SoftwareApplication`
131
161
  - `WebApplication`
132
162
  - `WebSite`
163
+ - `Dataset`
164
+ - `DataCatalog`
165
+ - `DataDownload`
133
166
 
134
167
  The default schema definitions live in `Crawlscope::Schemas`; `Crawlscope::SchemaRegistry` owns registration and validation.
135
168
 
@@ -47,6 +47,10 @@ module Crawlscope
47
47
  type = item.is_a?(Hash) ? item["@type"] : nil
48
48
  return errors if type.nil?
49
49
 
50
+ if type.is_a?(Array)
51
+ return errors + type.flat_map { |entry| validate(item.except("@graph").merge("@type" => entry)) }
52
+ end
53
+
50
54
  schema = @schemas[type.to_s]
51
55
  return errors if schema.nil?
52
56
 
@@ -68,12 +72,47 @@ module Crawlscope
68
72
  [{field: "unknown", issue: error.message, type: type}]
69
73
  end
70
74
 
75
+ # Warnings are separate from schema errors: unsupported types and missing
76
+ # recommendations do not make the document invalid.
77
+ def warnings(item)
78
+ return item.flat_map { |entry| warnings(entry) } if item.is_a?(Array)
79
+ return [] unless item.is_a?(Hash)
80
+
81
+ findings = warnings(item["@graph"])
82
+ Array(item["@type"]).each do |type|
83
+ schema = @schemas[type.to_s]
84
+ unless schema
85
+ findings << {code: :structured_data_unsupported_type, field: "@type", type: type, issue: "has no registered validation schema"}
86
+ next
87
+ end
88
+
89
+ findings.concat(recommendation_warnings(item, schema, type))
90
+ if type == "Dataset" && item.key?("distribution") && registered?("DataDownload")
91
+ downloads = item["distribution"].is_a?(Array) ? item["distribution"] : [item["distribution"]]
92
+ downloads.grep(Hash).each do |download|
93
+ findings.concat(recommendation_warnings(download, fetch("DataDownload"), "DataDownload"))
94
+ end
95
+ end
96
+ end
97
+ findings
98
+ end
99
+
71
100
  def to_h
72
101
  @schemas.dup
73
102
  end
74
103
 
75
104
  private
76
105
 
106
+ def recommendation_warnings(item, schema, type)
107
+ Array(schema[:recommended] || schema["recommended"]).filter_map do |property|
108
+ value = item[property.to_s]
109
+ missing = value.nil? || (value.respond_to?(:empty?) && value.empty?) || (value.is_a?(String) && value.strip.empty?)
110
+ next unless missing
111
+
112
+ {code: :structured_data_missing_recommended_property, field: property.to_s, type: type, issue: "is recommended"}
113
+ end
114
+ end
115
+
77
116
  def value_at_fragment(item, fragment)
78
117
  fragment.to_s.delete_prefix("#/").split("/").reduce(item) do |value, key|
79
118
  case value
@@ -388,6 +388,39 @@ module Crawlscope
388
388
  ]
389
389
  }.freeze
390
390
 
391
+ DATA_DOWNLOAD = {
392
+ type: "object",
393
+ required: %w[contentUrl],
394
+ recommended: %w[encodingFormat],
395
+ properties: {
396
+ contentUrl: {type: "string", format: "uri"},
397
+ encodingFormat: {type: "string", minLength: 1}
398
+ }
399
+ }.freeze
400
+
401
+ DATA_CATALOG = {
402
+ type: "object",
403
+ properties: {
404
+ name: {type: "string", minLength: 1},
405
+ description: {type: "string"},
406
+ url: {type: "string", format: "uri"}
407
+ }
408
+ }.freeze
409
+
410
+ DATASET = {
411
+ type: "object",
412
+ required: %w[name description],
413
+ recommended: %w[alternateName creator citation funder identifier isAccessibleForFree keywords license measurementTechnique sameAs spatialCoverage temporalCoverage variableMeasured version url includedInDataCatalog distribution],
414
+ properties: {
415
+ name: {type: "string", minLength: 1},
416
+ description: {type: "string", minLength: 50, maxLength: 5000},
417
+ license: {anyOf: [{type: "string", format: "uri"}, {type: "object", required: ["url"], properties: {url: {type: "string", format: "uri"}}}]},
418
+ isAccessibleForFree: {type: "boolean"},
419
+ url: {type: "string", format: "uri"},
420
+ distribution: {anyOf: [DATA_DOWNLOAD, {type: "array", minItems: 1, items: DATA_DOWNLOAD}]}
421
+ }
422
+ }.freeze
423
+
391
424
  def self.schemas
392
425
  {
393
426
  "FAQPage" => FAQ_PAGE,
@@ -407,7 +440,10 @@ module Crawlscope
407
440
  "Event" => EVENT,
408
441
  "VideoObject" => VIDEO_OBJECT,
409
442
  "WebPage" => WEB_PAGE,
410
- "JobPosting" => JOB_POSTING
443
+ "JobPosting" => JOB_POSTING,
444
+ "Dataset" => DATASET,
445
+ "DataCatalog" => DATA_CATALOG,
446
+ "DataDownload" => DATA_DOWNLOAD
411
447
  }
412
448
  end
413
449
  end
@@ -36,15 +36,19 @@ module Crawlscope
36
36
  ).call
37
37
  end
38
38
 
39
- def build_validation_errors(page)
39
+ def build_validation(page)
40
40
  validation = Validator.new(schema_registry: @schema_registry).call(
41
41
  html: page.body, required_types: @required_types ? @required_types.call(page.url) : []
42
42
  )
43
43
  structured_items = validation.items.map { |item| {data: item.data, source: item.source} }
44
- errors = validation.findings.map do |finding|
44
+ warning_findings, error_findings = validation.findings.partition(&:warning?)
45
+ errors = error_findings.map do |finding|
45
46
  {errors: finding.errors, source: finding.source, type: finding.type}
46
47
  end
47
- [structured_items, errors]
48
+ warnings = warning_findings.map do |finding|
49
+ {code: finding.code, errors: finding.errors, source: finding.source, type: finding.type}
50
+ end
51
+ [structured_items, errors, warnings]
48
52
  end
49
53
 
50
54
  def validate_url(url, fetcher)
@@ -74,12 +78,13 @@ module Crawlscope
74
78
  skipped_reason: "non-html"
75
79
  )
76
80
  else
77
- structured_items, errors = build_validation_errors(page)
81
+ structured_items, errors, warnings = build_validation(page)
78
82
  Page.new(
79
83
  url: url,
80
84
  status: page.status,
81
85
  structured_items: structured_items,
82
86
  errors: errors,
87
+ warnings: warnings,
83
88
  fetch_error: nil,
84
89
  content_type: content_type,
85
90
  skipped_reason: nil
@@ -2,7 +2,11 @@
2
2
 
3
3
  module Crawlscope
4
4
  module StructuredData
5
- Entry = Data.define(:url, :status, :structured_items, :errors, :fetch_error, :content_type, :skipped_reason) do
5
+ Entry = Data.define(:url, :status, :structured_items, :errors, :fetch_error, :content_type, :skipped_reason, :warnings) do
6
+ def initialize(warnings: [], **attributes)
7
+ super(**attributes, warnings: warnings)
8
+ end
9
+
6
10
  def json_ld_count
7
11
  structured_items.count { |item| item[:source] == "json-ld" }
8
12
  end
@@ -33,6 +33,10 @@ module Crawlscope
33
33
  entries.size
34
34
  end
35
35
 
36
+ def warning_url_count
37
+ entries.count { |entry| entry.warnings.any? }
38
+ end
39
+
36
40
  def validation_errors
37
41
  entries.select { |entry| entry.failure_kind == :validation }
38
42
  end
@@ -50,6 +54,7 @@ module Crawlscope
50
54
  error: entry.fetch_error,
51
55
  structured_data_found: false,
52
56
  validation_errors: [],
57
+ validation_warnings: [],
53
58
  json_ld_count: 0
54
59
  }
55
60
  else
@@ -58,6 +63,7 @@ module Crawlscope
58
63
  error: nil,
59
64
  structured_data_found: entry.structured_data_found?,
60
65
  validation_errors: entry.errors.flat_map { |error| error[:errors] },
66
+ validation_warnings: entry.warnings,
61
67
  json_ld_count: entry.json_ld_count,
62
68
  skipped_reason: entry.skipped_reason,
63
69
  content_type: entry.content_type
@@ -19,6 +19,8 @@ module Crawlscope
19
19
  else
20
20
  report_failures(report)
21
21
  end
22
+
23
+ @io.puts("#{report.warning_url_count} of #{report.total} URLs have validation warnings.") if report.warning_url_count.positive?
22
24
  end
23
25
 
24
26
  def details(result, debug:, renderer:)
@@ -87,6 +89,10 @@ module Crawlscope
87
89
  @io.puts("Structured data found: #{entry.structured_items.size} (JSON-LD: #{entry.json_ld_count}, Microdata: #{entry.microdata_count})")
88
90
  report_debug(entry) if debug && entry.structured_items.any?
89
91
  report_validation(entry)
92
+ entry.warnings.each do |warning|
93
+ @io.puts("Warning (#{source_label(warning[:source])}):")
94
+ warning[:errors].each { |error| @io.puts(" - #{ErrorFormatter.format(error)}") }
95
+ end
90
96
  @io.puts("")
91
97
  end
92
98
 
@@ -3,7 +3,11 @@
3
3
  module Crawlscope
4
4
  module StructuredData
5
5
  class Validator
6
- Finding = Data.define(:code, :source, :type, :errors, :paths)
6
+ Finding = Data.define(:code, :source, :type, :errors, :paths) do
7
+ def warning?
8
+ %i[structured_data_unsupported_type structured_data_missing_recommended_property].include?(code)
9
+ end
10
+ end
7
11
  Validation = Data.define(:items, :findings)
8
12
 
9
13
  def initialize(schema_registry:)
@@ -41,6 +45,9 @@ module Crawlscope
41
45
  end
42
46
  errors = @schema_registry.validate(data)
43
47
  findings << finding(:structured_data_schema_error, item, errors) unless errors.empty?
48
+ @schema_registry.warnings(data).group_by { |warning| [warning.fetch(:code), warning.fetch(:type)] }.each do |(code, type), warnings|
49
+ findings << Finding.new(code: code, source: item.source, type: type, errors: warnings.map { |warning| warning.except(:code) }, paths: [])
50
+ end
44
51
  findings
45
52
  end
46
53
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Crawlscope
4
- VERSION = "0.11.2"
4
+ VERSION = "0.12.0"
5
5
  end
@@ -142,6 +142,37 @@ class CrawlscopeSchemaRegistryTest < Minitest::Test
142
142
  assert_equal "Unknown Crawlscope rules: unknown", error.message
143
143
  end
144
144
 
145
+ def test_dataset_required_properties_and_download_validation
146
+ registry = Crawlscope::SchemaRegistry.default
147
+ dataset = {"@type" => "Dataset", "name" => "Ratings", "description" => "Aggregated local business ratings and review counts."}
148
+ assert_empty registry.validate(dataset)
149
+ refute_empty registry.validate(dataset.except("name"))
150
+ refute_empty registry.validate(dataset.merge("description" => "Too short"))
151
+ refute_empty registry.validate(dataset.merge("distribution" => [{"@type" => "DataDownload"}]))
152
+ refute_empty registry.validate(dataset.merge("license" => 42))
153
+ assert_empty registry.validate(dataset.merge("license" => {"@type" => "CreativeWork", "url" => "https://example.com/license"}))
154
+ assert_empty registry.validate(dataset.merge("distribution" => [{"@type" => "DataDownload", "contentUrl" => "https://example.com/data.csv"}]))
155
+ assert_includes registry.warnings(dataset).map { |warning| warning[:field] }, "license"
156
+ refute_includes registry.warnings(dataset.merge("license" => "https://example.com/license")).map { |warning| warning[:field] }, "license"
157
+ assert_includes registry.warnings(dataset.merge("license" => "")).map { |warning| warning[:field] }, "license"
158
+ assert registry.registered?("DataCatalog")
159
+ assert registry.registered?("DataDownload")
160
+ end
161
+
162
+ def test_warnings_respect_registered_recommendations_and_multiple_types
163
+ registry = Crawlscope::SchemaRegistry.default
164
+ registry.register("CustomThing", {type: "object", recommended: %w[available name]})
165
+ data = {"@type" => ["CustomThing", "UnregisteredThing"], "available" => false}
166
+ warnings = registry.warnings(data)
167
+ assert_equal %w[name @type], warnings.map { |warning| warning[:field] }
168
+ assert_empty registry.validate(data)
169
+ assert_empty registry.warnings(data.merge("@type" => "CustomThing", "name" => "Example"))
170
+ assert_empty registry.warnings({"@type" => "WebPage"})
171
+ assert_equal warnings, registry.warnings({"@graph" => [data]})
172
+ assert_equal warnings, registry.dup.warnings(data)
173
+ refute_empty registry.validate({"@type" => ["WebPage", "Article"]})
174
+ end
175
+
145
176
  def test_validate_accepts_arrays_graphs_unknown_types_and_non_hashes
146
177
  registry = Crawlscope::SchemaRegistry.default
147
178
 
@@ -27,7 +27,9 @@ class CrawlscopeStructuredDataAuditTest < Minitest::Test
27
27
  context: {schema_registry: config.schema_registry})
28
28
 
29
29
  assert_equal expected_ok, outcome.ok?, data.inspect
30
- assert_equal expected_ok ? [] : [:structured_data_missing_required_type], issues.map(&:code), data.inspect
30
+ expected_codes = expected_ok ? [] : [:structured_data_missing_required_type]
31
+ expected_codes.unshift(:structured_data_unsupported_type) if data["@type"] == "ItemList"
32
+ assert_equal expected_codes, issues.map(&:code), data.inspect
31
33
  unless expected_ok
32
34
  assert_equal "page", outcome.entries.first.errors.first.fetch(:source)
33
35
  assert_equal "Article or BlogPosting or NewsArticle", outcome.entries.first.errors.first.fetch(:type)
@@ -63,6 +65,40 @@ class CrawlscopeStructuredDataAuditTest < Minitest::Test
63
65
  end
64
66
  end
65
67
 
68
+ def test_warnings_are_reported_without_failing_either_audit
69
+ dataset = {
70
+ "@type" => "Dataset",
71
+ "name" => "Rating dataset",
72
+ "description" => "Aggregated ratings and review counts across local businesses.",
73
+ "distribution" => {"@type" => "DataDownload", "contentUrl" => "https://example.com/data.csv"}
74
+ }
75
+ data = [dataset, {"@type" => "UnsupportedThing"}]
76
+ page = html_page(url: "https://example.com/data", body: %(<script type="application/ld+json">#{JSON.generate(data)}</script>))
77
+ config = Crawlscope::Configuration.new
78
+ config.browser_factory = -> { -> { FakeBrowser.new(page: page) } }
79
+ config.renderer = :browser
80
+ config.output = StringIO.new
81
+
82
+ outcome = Crawlscope::StructuredData::Check.new(configuration: config).call(urls: [page.url], summary: true)
83
+ assert outcome.ok?
84
+ entry = outcome.entries.first
85
+ assert_empty entry.errors
86
+ warnings = entry.warnings
87
+ assert_includes warnings.map { |warning| warning[:code] }, :structured_data_unsupported_type
88
+ assert_includes warnings.flat_map { |warning| warning[:errors].map { |error| error[:field] } }, "license"
89
+ assert_includes warnings.flat_map { |warning| warning[:errors].map { |error| error[:field] } }, "encodingFormat"
90
+ assert_includes config.output.string, "1 of 1 URLs have validation warnings."
91
+ assert_includes config.output.string, "Dataset.license: is recommended"
92
+ assert_includes config.output.string, "UnsupportedThing.@type: has no registered validation schema"
93
+ assert_equal warnings, Crawlscope::StructuredData::Report.new(outcome).results.fetch(page.url).fetch(:validation_warnings)
94
+
95
+ issues = Crawlscope::IssueCollection.new
96
+ config.rule_registry.rules_for([:structured_data]).first.call(urls: [page.url], pages: [page], issues: issues,
97
+ context: {schema_registry: config.schema_registry})
98
+ assert_equal warnings.map { |warning| warning[:code] }.sort, issues.map(&:code).sort
99
+ assert issues.all? { |issue| issue.severity == :warning }
100
+ end
101
+
66
102
  class FakeBrowser
67
103
  attr_reader :closed
68
104
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crawlscope
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.2
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paulo Fidalgo