Files
opencode-compat/test/matrix_json_test.rb
Ajay Krishnan 3dfecb72c6
Some checks failed
Candidate compatibility / prepare (push) Failing after 32s
Candidate compatibility / fixture-contract (push) Has been skipped
Candidate compatibility / lockstep clients Ruby 3.2 (push) Has been skipped
Candidate compatibility / lockstep clients Ruby 3.3 (push) Has been skipped
Candidate compatibility / lockstep clients Ruby 3.4 (push) Has been skipped
Candidate compatibility / lockstep clients Ruby 4.0 (push) Has been skipped
Candidate compatibility / image ${{ matrix.id }} (push) Has been skipped
Candidate compatibility / repository (push) Successful in 37s
Watch upstream OpenCode / open-compatibility-pr (push) Failing after 11s
Test alpha8 commit candidates before publication
2026-07-19 22:43:44 -07:00

98 lines
2.9 KiB
Ruby

# frozen_string_literal: true
require "fileutils"
require "json"
require "minitest/autorun"
require "open3"
require "rbconfig"
require "tmpdir"
class MatrixJsonTest < Minitest::Test
ROOT = File.expand_path("..", __dir__)
def setup
@tmp = Dir.mktmpdir("opencode-matrix-json")
FileUtils.mkdir_p(File.join(@tmp, "lib/opencode_compat"))
FileUtils.mkdir_p(File.join(@tmp, "scripts"))
FileUtils.mkdir_p(File.join(@tmp, "manifests"))
FileUtils.cp(File.join(ROOT, "scripts/matrix_json.rb"), File.join(@tmp, "scripts"))
FileUtils.cp(
File.join(ROOT, "lib/opencode_compat/client_candidate.rb"),
File.join(@tmp, "lib/opencode_compat")
)
FileUtils.cp(
File.join(ROOT, "manifests/client-candidate.json"),
File.join(@tmp, "manifests")
)
@manifest = JSON.parse(File.read(File.join(ROOT, "manifests/image-matrix.json")))
end
def teardown
FileUtils.remove_entry(@tmp)
end
def test_emits_only_the_actual_shared_client_contract_profile
output, error, status = run_matrix(@manifest)
assert status.success?, error
JSON.parse(output).fetch("include").each do |target|
assert_equal ["ruby-rest-sse"], target.fetch("profiles")
assert_equal "shared-client-contract-only", target.fetch("certification_scope")
end
end
def test_rejects_a_manifest_that_overstates_the_executed_profile
@manifest.fetch("public_ci").first["profiles"] = ["rails-persisted-turn"]
_output, error, status = run_matrix(@manifest)
refute status.success?
assert_match(/executes exactly ruby-rest-sse/, error)
end
def test_rejects_a_manifest_that_overstates_the_certification_scope
@manifest.fetch("public_ci").first["certification_scope"] = "consumer-runtime"
_output, error, status = run_matrix(@manifest)
refute status.success?
assert_match(/certification_scope must be shared-client-contract-only/, error)
end
def test_rejects_a_matrix_bound_to_another_client_candidate
@manifest.fetch("client_candidate")["opencode_ruby_commit"] = "f" * 40
_output, error, status = run_matrix(@manifest)
refute status.success?
assert_match(/must equal the exact client candidate/, error)
end
def test_allows_reviewed_candidate_certification_without_changing_coordinates
@manifest.fetch("client_candidate")["certification_status"] = "certified"
_output, error, status = run_matrix(@manifest)
assert status.success?, error
end
def test_rejects_unknown_candidate_certification_status
@manifest.fetch("client_candidate")["certification_status"] = "deployed"
_output, error, status = run_matrix(@manifest)
refute status.success?
assert_match(/certification_status must be pending or certified/, error)
end
private
def run_matrix(manifest)
File.write(
File.join(@tmp, "manifests/image-matrix.json"),
JSON.pretty_generate(manifest) + "\n"
)
Open3.capture3(RbConfig.ruby, File.join(@tmp, "scripts/matrix_json.rb"))
end
end