Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,15 @@ require "rubocop/rake_task"

RuboCop::RakeTask.new

namespace :corpus do
desc "Regenerate committed golden reports for the vendored GitLab corpus"
task :regenerate_golden_reports do
require_relative "lib/code_keeper"
require_relative "spec/support/corpus_report_runner"
require_relative "spec/support/corpus_golden_report"

CorpusGoldenReport.regenerate_all
end
end

task default: %i[spec rubocop]
45 changes: 45 additions & 0 deletions spec/code_keeper/golden_report_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

require "spec_helper"
require "support/corpus_report_runner"
require "support/corpus_golden_report"

RSpec.describe "GitLab corpus golden reports" do
it "has one snapshot per corpus file" do
expect(Dir[File.join(CorpusGoldenReport::ROOT, "**/*.json")].sort).to eq CorpusGoldenReport.snapshot_paths.sort
end

it "matches the current CodeKeeper report for every corpus file" do
CorpusReportRunner.file_paths.each do |path|
aggregate_failures path do
expect(File.read(CorpusGoldenReport.snapshot_path_for(path))).to eq CorpusGoldenReport.serialized_report_for(path)
end
end
end

it "stores repository-relative paths in snapshots" do
paths = CorpusGoldenReport.snapshot_paths.flat_map do |snapshot_path|
paths_in(JSON.parse(File.read(snapshot_path)))
end

expect(paths).to all(match(%r{\Aspec/fixtures/corpus/gitlab/}))
end

it "detects stale snapshots outside the corpus file list" do
stale_path = File.join(CorpusGoldenReport::ROOT, "obsolete.rb.json")
existing_paths = CorpusGoldenReport.snapshot_paths + [stale_path]

expect(CorpusGoldenReport.stale_snapshot_paths(existing_paths: existing_paths)).to eq [stale_path]
end

def paths_in(value)
case value
when Array
value.flat_map { |item| paths_in(item) }
when Hash
value.flat_map { |key, item| key == "path" ? [item] : paths_in(item) }
else
[]
end
end
end
15 changes: 15 additions & 0 deletions spec/fixtures/corpus/gitlab/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,18 @@ MIT Expat license notice included here.
- `app/models/concerns/from_set_operator.rb`
- `app/models/concerns/ci/partitionable.rb`
- `spec/models/ability_spec.rb`

## Golden Reports

Committed golden reports live under `spec/fixtures/golden_reports/gitlab/`.
There is one pretty-printed JSON report per corpus file, and report paths are
recorded with repository-relative corpus paths.

Regenerate them only as an explicit out-of-band maintenance task:

```bash
bundle exec rake corpus:regenerate_golden_reports
```

This regeneration task is not part of CI. Review the resulting JSON diff before
committing it.
Loading
Loading