Phase 3: move service layer, serializers and DTOs into WarpEngine + dummy-app test suite
- all catalog services (update/software/highlighted/builds/file/file-manager/ download/image + SoftwareResponseBuilder), the SoftwareUpdater platform services and their concerns, Blueprinter serializers (incl. TimestampFields) and the 4 DTOs now live in the engine under WarpEngine:: - constantize dispatch strings use absolute names (WarpEngine::SoftwareUpdater::<Platform>Service) - container paths read from WarpEngine.config everywhere (FileService, DownloadService, FileManagerService, ArchiveExtraction, ReleaseSerializer path rewriting); FileManagerService base path is now lazy - engine requires blueprinter itself; gemspec declares blueprinter + rubyzip - engine test suite: spec/dummy app (mysql warp_engine_test, catalog-only schema), rails_helper with engine-local factories; catalog model/service specs and factories moved from the host - host suite keeps TTG specs and loads catalog factories from the engine Verified: engine suite 40 green, host suite 14 green, /api/software and /api/builds byte-identical to baselines, admin OK. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe WarpEngine::BuildsService do
|
||||
describe "#index" do
|
||||
subject(:result) { described_class.new.index }
|
||||
|
||||
it "returns all supported platforms with expected kinds" do
|
||||
expect(result[:platforms]).to have_key("tic80")
|
||||
expect(result[:platforms]["tic80"][:label]).to eq("TIC-80")
|
||||
expect(result[:platforms]["tic80"][:kinds]).to include("cartridge", "html")
|
||||
end
|
||||
|
||||
it "returns c64 with only cartridge" do
|
||||
expect(result[:platforms]["c64"][:kinds]).to eq(["cartridge"])
|
||||
end
|
||||
|
||||
it "returns allKinds matching WarpEngine::ReleaseAsset::KINDS" do
|
||||
expect(result[:allKinds]).to eq(WarpEngine::ReleaseAsset::KINDS)
|
||||
end
|
||||
|
||||
it "includes all supported platforms" do
|
||||
WarpEngine::PlatformLink::SUPPORTED_PLATFORMS.each do |platform|
|
||||
expect(result[:platforms]).to have_key(platform)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#show" do
|
||||
let!(:software) { create(:software, name: "test-game", platform: "love") }
|
||||
let!(:release) { create(:release, software: software, version: "1.0.0") }
|
||||
|
||||
before do
|
||||
WarpEngine::ReleaseAsset.create!(release: release, kind: "html", path: "/test/html")
|
||||
WarpEngine::ReleaseAsset.create!(release: release, kind: "win_x64", path: "/test/win")
|
||||
end
|
||||
|
||||
it "returns expected and actual kinds per release" do
|
||||
result = described_class.new.show("test-game")
|
||||
|
||||
expect(result[:platform]).to eq("love")
|
||||
expect(result[:expected]).to match_array(%w[html win_x64 linux_x64 mac_universal])
|
||||
expect(result[:releases]["1.0.0"][:actual]).to match_array(%w[html win_x64])
|
||||
expect(result[:releases]["1.0.0"][:missing]).to match_array(%w[linux_x64 mac_universal])
|
||||
end
|
||||
|
||||
it "raises RecordNotFound for unknown software" do
|
||||
expect { described_class.new.show("nonexistent") }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,20 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe WarpEngine::SoftwareHighlightedService do
|
||||
describe "#index" do
|
||||
it "returns nil when no highlighted software" do
|
||||
create(:software, highlighted: false)
|
||||
|
||||
result = described_class.new.index
|
||||
expect(result).to be_nil
|
||||
end
|
||||
|
||||
it "returns highlighted software" do
|
||||
sw = create(:software, highlighted: true, title: "Featured")
|
||||
|
||||
result = described_class.new.index
|
||||
expect(result).not_to be_nil
|
||||
expect(result[:software][:title]).to eq("Featured")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,78 @@
|
||||
require "rails_helper"
|
||||
require "zip"
|
||||
|
||||
RSpec.describe WarpEngine::SoftwareUpdater::Tic80Service do
|
||||
let(:tmpdir) { Dir.mktmpdir }
|
||||
let(:name) { "spectic" }
|
||||
let(:version) { "9.9" }
|
||||
let(:versioned) { "#{name}-#{version}" }
|
||||
|
||||
before do
|
||||
allow(WarpEngine.config).to receive(:file_container_path).and_return(tmpdir)
|
||||
|
||||
write_zip("#{versioned}.html.zip", "index.html" => "<html></html>")
|
||||
File.write(File.join(tmpdir, "#{versioned}.tic"), "TIC!")
|
||||
File.write(File.join(tmpdir, "#{versioned}.lua"), <<~LUA)
|
||||
-- title: Spec TIC
|
||||
-- name: #{name}
|
||||
-- author: RSpec
|
||||
-- desc: spec fixture
|
||||
-- version: #{version}
|
||||
function TIC() end
|
||||
LUA
|
||||
end
|
||||
|
||||
after do
|
||||
FileUtils.remove_entry(tmpdir)
|
||||
WarpEngine::Software.unscoped.where(name: name).each do |sw|
|
||||
WarpEngine::Release.unscoped.where(software_id: sw.id).each do |r|
|
||||
WarpEngine::ReleaseAsset.unscoped.where(release_id: r.id).delete_all
|
||||
r.delete
|
||||
end
|
||||
WarpEngine::ExternalLink.unscoped.where(software_id: sw.id).delete_all
|
||||
sw.delete
|
||||
end
|
||||
end
|
||||
|
||||
def write_zip(filename, entries)
|
||||
Zip::File.open(File.join(tmpdir, filename), create: true) do |zip|
|
||||
entries.each do |entry_name, content|
|
||||
zip.get_output_stream(entry_name) { |io| io.write(content) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def asset_kinds(release)
|
||||
WarpEngine::ReleaseAsset.unscoped.where(release_id: release.id).pluck(:kind)
|
||||
end
|
||||
|
||||
it "registers the release without a docs zip" do
|
||||
release = described_class.new.update(name, version)
|
||||
|
||||
expect(asset_kinds(release)).to match_array(%w[cartridge source html])
|
||||
end
|
||||
|
||||
it "registers docs when the docs zip is present" do
|
||||
write_zip("#{versioned}-docs.zip", "index.html" => "docs")
|
||||
|
||||
release = described_class.new.update(name, version)
|
||||
|
||||
expect(asset_kinds(release)).to include("docs")
|
||||
end
|
||||
|
||||
it "registers binary assets when slug zips are present" do
|
||||
write_zip("#{versioned}-win-x64.zip", "game.exe" => "MZ")
|
||||
write_zip("#{versioned}-mac-x64.zip", "game" => "bin")
|
||||
|
||||
release = described_class.new.update(name, version)
|
||||
|
||||
expect(asset_kinds(release)).to include("win_x64", "mac_x64")
|
||||
expect(asset_kinds(release)).not_to include("linux_x64")
|
||||
end
|
||||
|
||||
it "exposes expected_kinds from included Build concerns" do
|
||||
expect(described_class.expected_kinds).to match_array(
|
||||
%w[cartridge source html docs win_x64 linux_x64 mac_x64]
|
||||
)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,59 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe WarpEngine::UpdateService do
|
||||
describe "#update" do
|
||||
it "raises ArgumentError for unsupported platform" do
|
||||
input = WarpEngine::UpdateInputDto.new(platform: "unknown", name: "game", version: "1.0")
|
||||
|
||||
expect { described_class.new.update(input) }.to raise_error(ArgumentError, /Unsupported platform/)
|
||||
end
|
||||
|
||||
it "routes to correct platform service" do
|
||||
input = WarpEngine::UpdateInputDto.new(platform: "tic80", name: "game", version: "1.0")
|
||||
mock_service = instance_double(WarpEngine::SoftwareUpdater::Tic80Service)
|
||||
|
||||
allow(WarpEngine::SoftwareUpdater::Tic80Service).to receive(:new).and_return(mock_service)
|
||||
allow(mock_service).to receive(:update)
|
||||
|
||||
described_class.new.update(input)
|
||||
|
||||
expect(mock_service).to have_received(:update).with("game", "1.0")
|
||||
end
|
||||
|
||||
it "routes godot platform to GodotService" do
|
||||
input = WarpEngine::UpdateInputDto.new(platform: "godot", name: "game", version: "1.0")
|
||||
mock_service = instance_double(WarpEngine::SoftwareUpdater::GodotService)
|
||||
|
||||
allow(WarpEngine::SoftwareUpdater::GodotService).to receive(:new).and_return(mock_service)
|
||||
allow(mock_service).to receive(:update)
|
||||
|
||||
described_class.new.update(input)
|
||||
|
||||
expect(mock_service).to have_received(:update).with("game", "1.0")
|
||||
end
|
||||
|
||||
it "routes bevy platform to BevyService" do
|
||||
input = WarpEngine::UpdateInputDto.new(platform: "bevy", name: "game", version: "1.0")
|
||||
mock_service = instance_double(WarpEngine::SoftwareUpdater::BevyService)
|
||||
|
||||
allow(WarpEngine::SoftwareUpdater::BevyService).to receive(:new).and_return(mock_service)
|
||||
allow(mock_service).to receive(:update)
|
||||
|
||||
described_class.new.update(input)
|
||||
|
||||
expect(mock_service).to have_received(:update).with("game", "1.0")
|
||||
end
|
||||
|
||||
it "routes phaser platform to PhaserService" do
|
||||
input = WarpEngine::UpdateInputDto.new(platform: "phaser", name: "game", version: "1.0")
|
||||
mock_service = instance_double(WarpEngine::SoftwareUpdater::PhaserService)
|
||||
|
||||
allow(WarpEngine::SoftwareUpdater::PhaserService).to receive(:new).and_return(mock_service)
|
||||
allow(mock_service).to receive(:update)
|
||||
|
||||
described_class.new.update(input)
|
||||
|
||||
expect(mock_service).to have_received(:update).with("game", "1.0")
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user