Két dolog volt beépítve az engine-be, ami nem az övé. A **képtár** eddig `WarpEngine::Image` volt, pedig a modell teljesen általános: a teletypegames-ben a tagok arcképét is ez hordozza, nem csak a katalógus borítóit. Az `Image` modell, a feltöltött fájlok, az `/api/image/:id` végpont és az admin oldal ezért átkerült a hosztba, az engine pedig adapteren szól hozzá (`WarpEngine::Images`): `url_for` adja a katalógus JSON `imageUrl`-jét, `select_options` a software-form képválasztóját, `build_from_upload` a "tölts fel új képet" ágat. Az alapértelmezés az `Image` osztály, tehát a default útvonal bitre a régi. A `SoftwareImage` (a katalógus-kapcsolat) maradt az engine-ben, és **az `images` tábla nem mozdult**: az engine csak abbahagyta a létrehozását, a generátor írja meg hoszt-kódként. A **CI** eddig végig Woodpecker volt: kliens, aláírás-ellenőrzés, pipeline-receptek, repo-szinkron, secret-kiosztás. Mindez egy adapter mögé került (`WarpEngine.ci`), a Woodpecker-implementáció pedig az engine-ben maradt `WarpEngine::CI::Woodpecker` néven — kliens, adapter, httpsig-ellenőrző és a platformonkénti pipeline-receptek, mert a YAML-dialektus a szolgáltatóé. Az engine saját kódja már nem nevez szolgáltatót: `CI::Repo` és `CI::Run` értékeket kap, `CI::ConnectionError`/`ApiError`/`NotConfigured` hibákat dob, a `Pipeline` pedig `remote_repo_id`-t ad a történelmi `woodpecker_repo_id` kolumna fölött (a tábla itt sem mozdult). `c.ci_adapter = :none` azt jelenti, hogy ez a hoszt nem buildel: az `/api/ci/*` 503, a `/build/config` elutasít, az admin akciók elbújnak. Mindkét seam a hoszt initializerében van kimondva, nem alapértelmezésre hagyva — a hoszt megnevezi, mi a képtára és mi a CI-ja. Törés a 0.6-hoz képest: `image_container_path`, `image_owners`, `ci_platforms`, `ci_update_server`, `ci_extension_public_key(_url)`, `woodpecker_url`, `woodpecker_api_token`, `woodpecker_repo_owner` és a `WarpEngine.woodpecker_configured?` megszűnt; a helyük `c.image_class_name` / `c.image_adapter` és `c.ci_adapter`. Az `/api/ci/*` `latest_run`/`trigger` válasza a normalizált `CI::Run` alakot adja (number, status, branch, message, createdAt, url), a `pipelines` lista pedig `repo_id`-t is közöl a megtartott `woodpecker_repo_id` mellett. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
137 lines
4.8 KiB
Ruby
137 lines
4.8 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe WarpEngine::CI do
|
|
after do
|
|
WarpEngine.config.ci_adapter = :woodpecker
|
|
WarpEngine::CI.reset!
|
|
end
|
|
|
|
describe ".adapter" do
|
|
it "drives Woodpecker unless the host says otherwise" do
|
|
expect(WarpEngine.ci).to be_a(WarpEngine::CI::Woodpecker::Adapter)
|
|
expect(WarpEngine.ci.name).to eq("Woodpecker")
|
|
end
|
|
|
|
it "answers with the null adapter for a host that runs no CI" do
|
|
WarpEngine.config.ci_adapter = :none
|
|
|
|
expect(WarpEngine.ci).to be_a(WarpEngine::CI::Null)
|
|
expect(WarpEngine.ci).not_to be_configured
|
|
end
|
|
|
|
it "hands back whatever object the host named" do
|
|
own = Class.new { def name = "Forge Runner" }.new
|
|
WarpEngine.config.ci_adapter = own
|
|
|
|
expect(WarpEngine.ci).to be(own)
|
|
end
|
|
end
|
|
|
|
describe WarpEngine::CI::Null do
|
|
let(:adapter) { described_class.new }
|
|
|
|
it "serves no platform and verifies no request" do
|
|
expect(adapter.platforms).to be_empty
|
|
expect(adapter.verify_config_request(nil)).to be(false)
|
|
expect(adapter.config_marker({})).to be_nil
|
|
expect(adapter.pipeline_config(platform: "godot", name: "x", update_server: "y")).to be_nil
|
|
end
|
|
|
|
it "raises rather than pretending to manage repositories" do
|
|
expect { adapter.repos }.to raise_error(WarpEngine::CI::NotConfigured)
|
|
expect { adapter.trigger(1) }.to raise_error(WarpEngine::CI::NotConfigured)
|
|
end
|
|
end
|
|
|
|
describe WarpEngine::CI::Woodpecker::Adapter do
|
|
let(:client) { instance_double(WarpEngine::CI::Woodpecker::Client) }
|
|
let(:adapter) do
|
|
described_class.new(url: "https://ci.test", api_token: "tok",
|
|
platforms: { "godot" => { builder: "registry.test/godot:1" } },
|
|
update_server: "https://games.test")
|
|
end
|
|
|
|
before { allow(adapter).to receive(:client).and_return(client) }
|
|
|
|
it "is inactive without a server and a token" do
|
|
expect(described_class.new(url: nil, api_token: nil)).not_to be_configured
|
|
expect(adapter).to be_configured
|
|
end
|
|
|
|
it "normalizes a repository" do
|
|
allow(client).to receive(:list_repos).and_return([
|
|
{ "id" => 7, "name" => "game", "owner" => "org", "active" => true }
|
|
])
|
|
|
|
repo = adapter.repos.first
|
|
|
|
expect(repo.id).to eq(7)
|
|
expect(repo.full_name).to eq("org/game")
|
|
expect(repo).to be_active
|
|
end
|
|
|
|
it "normalizes a run, timestamp included" do
|
|
allow(client).to receive(:trigger_pipeline).and_return(
|
|
{ "number" => 4, "status" => "success", "branch" => "main",
|
|
"message" => "ship it", "created" => 1_754_500_000 }
|
|
)
|
|
|
|
run = adapter.trigger(7, branch: "main")
|
|
|
|
expect(run.number).to eq(4)
|
|
expect(run).to be_success
|
|
expect(run.created_at).to eq(Time.zone.at(1_754_500_000))
|
|
expect(run.as_json[:createdAt]).to be_present
|
|
end
|
|
|
|
it "creates a secret the repository does not have yet" do
|
|
allow(client).to receive(:list_secrets).and_return([])
|
|
allow(client).to receive(:create_secret)
|
|
|
|
adapter.secret_set(7, name: "application_token", value: "plain")
|
|
|
|
expect(client).to have_received(:create_secret).with(
|
|
7, name: "application_token", value: "plain", events: described_class::SECRET_EVENTS
|
|
)
|
|
end
|
|
|
|
it "updates a secret the repository already has" do
|
|
allow(client).to receive(:list_secrets).and_return([ { "name" => "application_token" } ])
|
|
allow(client).to receive(:update_secret)
|
|
|
|
adapter.secret_set(7, name: "application_token", value: "plain")
|
|
|
|
expect(client).to have_received(:update_secret).with(7, "application_token", value: "plain")
|
|
end
|
|
|
|
it "reads the platform marker out of a config request" do
|
|
params = ActionController::Parameters.new(
|
|
repo: { name: "mygame" },
|
|
configuration: [ { name: ".woodpecker.yaml", data: "platform: godot\n" } ]
|
|
)
|
|
|
|
expect(adapter.config_marker(params)).to eq({ platform: "godot", name: "mygame" })
|
|
end
|
|
|
|
it "ignores a config request that is not a marker" do
|
|
params = ActionController::Parameters.new(
|
|
configuration: [ { name: ".woodpecker.yaml", data: "steps:\n - name: build\n" } ]
|
|
)
|
|
|
|
expect(adapter.config_marker(params)).to be_nil
|
|
end
|
|
|
|
it "renders only the platforms it was given" do
|
|
expect(adapter.pipeline_config(platform: "godot", name: "mygame",
|
|
update_server: "https://games.test")).to include("registry.test/godot:1")
|
|
expect(adapter.pipeline_config(platform: "amiga", name: "mygame",
|
|
update_server: "https://games.test")).to be_nil
|
|
end
|
|
|
|
it "shapes the response the way the CI server expects" do
|
|
expect(adapter.config_response(platform: "godot", config: "steps: []"))
|
|
.to eq({ configs: [ { name: "godot", data: "steps: []" } ] })
|
|
end
|
|
end
|
|
end
|