WarpEngine 0.7.0: a képtár és a CI is a hoszté, adapteren keresztül
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>
This commit is contained in:
@@ -1,31 +1,35 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe WarpEngine::PipelineService do
|
||||
let(:client) { instance_double(WarpEngine::WoodpeckerClient) }
|
||||
let(:service) { described_class.new(client: client) }
|
||||
let(:ci) { instance_double(WarpEngine::CI::Woodpecker::Adapter) }
|
||||
let(:service) { described_class.new(ci: ci) }
|
||||
|
||||
def ci_run(number:, status: "success", created_at: nil)
|
||||
WarpEngine::CI::Run.new(number: number, status: status, created_at: created_at)
|
||||
end
|
||||
|
||||
describe "#trigger" do
|
||||
it "delegates to client" do
|
||||
repo = build(:pipeline, repo_owner: "org", repo_name: "game")
|
||||
allow(client).to receive(:trigger_pipeline).and_return({ "number" => 6 })
|
||||
allow(ci).to receive(:trigger).and_return(ci_run(number: 6, status: "pending"))
|
||||
|
||||
result = service.trigger(repo, branch: "main")
|
||||
|
||||
expect(result["number"]).to eq(6)
|
||||
expect(client).to have_received(:trigger_pipeline).with(repo.woodpecker_repo_id, branch: "main")
|
||||
expect(result.number).to eq(6)
|
||||
expect(ci).to have_received(:trigger).with(repo.remote_repo_id, branch: "main")
|
||||
end
|
||||
end
|
||||
|
||||
describe "#list_pipelines" do
|
||||
it "returns paginated pipelines and refreshes the repo's cached last pipeline" do
|
||||
describe "#runs" do
|
||||
it "returns the runs and refreshes the repo's cached last run" do
|
||||
repo = create(:pipeline, repo_owner: "org", repo_name: "game")
|
||||
pipelines = [
|
||||
{ "number" => 2, "status" => "failure", "created" => 1_754_500_000 },
|
||||
{ "number" => 1, "status" => "success", "created" => 1_754_400_000 }
|
||||
runs = [
|
||||
ci_run(number: 2, status: "failure", created_at: Time.zone.at(1_754_500_000)),
|
||||
ci_run(number: 1, status: "success", created_at: Time.zone.at(1_754_400_000))
|
||||
]
|
||||
allow(client).to receive(:list_pipelines).with(repo.woodpecker_repo_id, page: 1).and_return(pipelines)
|
||||
allow(ci).to receive(:runs).with(repo.remote_repo_id, page: 1).and_return(runs)
|
||||
|
||||
expect(service.list_pipelines(repo)).to eq(pipelines)
|
||||
expect(service.runs(repo)).to eq(runs)
|
||||
|
||||
repo.reload
|
||||
expect(repo.last_pipeline_status).to eq("failure")
|
||||
@@ -35,20 +39,20 @@ RSpec.describe WarpEngine::PipelineService do
|
||||
it "does not touch the cache on later pages" do
|
||||
repo = create(:pipeline, repo_owner: "org", repo_name: "game",
|
||||
last_pipeline_status: "success")
|
||||
allow(client).to receive(:list_pipelines).with(repo.woodpecker_repo_id, page: 2)
|
||||
.and_return([{ "number" => 1, "status" => "failure", "created" => 1_754_400_000 }])
|
||||
allow(ci).to receive(:runs).with(repo.remote_repo_id, page: 2)
|
||||
.and_return([ ci_run(number: 1, status: "failure", created_at: Time.zone.at(1_754_400_000)) ])
|
||||
|
||||
service.list_pipelines(repo, page: 2)
|
||||
service.runs(repo, page: 2)
|
||||
|
||||
expect(repo.reload.last_pipeline_status).to eq("success")
|
||||
end
|
||||
|
||||
it "leaves the cache alone when the repo has no pipelines" do
|
||||
it "leaves the cache alone when the repo has no runs" do
|
||||
repo = create(:pipeline, repo_owner: "org", repo_name: "game",
|
||||
last_pipeline_status: "success")
|
||||
allow(client).to receive(:list_pipelines).and_return([])
|
||||
allow(ci).to receive(:runs).and_return([])
|
||||
|
||||
expect(service.list_pipelines(repo)).to eq([])
|
||||
expect(service.runs(repo)).to eq([])
|
||||
expect(repo.reload.last_pipeline_status).to eq("success")
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user