From b067d0df6e6441fd47ce51ff44aa57301decf4ab Mon Sep 17 00:00:00 2001 From: forgejo-backport-action Date: Fri, 25 Apr 2025 12:38:14 +0000 Subject: [PATCH] [v11.0/forgejo] fix: display the list of tasks in the runner edit page (#7652) **Backport:** https://codeberg.org/forgejo/forgejo/pulls/7650 A regression was introduced in Forgejo v11.0 that caused the edit page of a runner (e.g. https://example.org/admin/actions/runners/434) to no longer display the tasks associated with the runner. Fixes https://codeberg.org/forgejo/forgejo/issues/7643 --- When the fix is absent, the tests fail like so: ``` --- FAIL: TestRunnerDetails (0.03s) --- FAIL: TestRunnerDetails/first_page (0.00s) runners_test.go:36: Error Trace: /home/earl-warren/software/forgejo/routers/web/shared/actions/runners_test.go:36 Error: "[]" should have 30 item(s), but has 0 Test: TestRunnerDetails/first_page --- FAIL: TestRunnerDetails/second_and_last_page (0.00s) runners_test.go:43: Error Trace: /home/earl-warren/software/forgejo/routers/web/shared/actions/runners_test.go:43 Error: "[]" should have 10 item(s), but has 0 Test: TestRunnerDetails/second_and_last_page FAIL FAIL forgejo.org/routers/web/shared/actions 0.170s ``` ## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org). ### Tests - I added test coverage for Go changes... - [x] in their respective `*_test.go` for unit tests. - [ ] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I added test coverage for JavaScript changes... - [ ] in `web_src/js/*.test.js` if it can be unit tested. - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)). ### Documentation - [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [x] I did not document these changes and I do not expect someone else to do it. ### Release notes - [ ] I do not want this change to show in the release notes. - [x] I want the title to show in the release notes with a link to this pull request. - [ ] I want the content of the `release-notes/.md` to be be used for the release notes instead of the title. ## Release notes - User Interface bug fixes - [PR](https://codeberg.org/forgejo/forgejo/pulls/7650): display the list of tasks in the runner edit page ## Release notes - User Interface bug fixes - [PR](https://codeberg.org/forgejo/forgejo/pulls/7650): display the list of tasks in the runner edit page Co-authored-by: Earl Warren Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7652 Reviewed-by: Earl Warren Co-authored-by: forgejo-backport-action Co-committed-by: forgejo-backport-action --- .../TestRunnerDetails/action_runner.yml | 7 + .../TestRunnerDetails/action_task.yml | 160 ++++++++++++++++++ routers/web/shared/actions/main_test.go | 17 ++ routers/web/shared/actions/runners.go | 1 - routers/web/shared/actions/runners_test.go | 47 +++++ 5 files changed, 231 insertions(+), 1 deletion(-) create mode 100644 routers/web/shared/actions/fixtures/TestRunnerDetails/action_runner.yml create mode 100644 routers/web/shared/actions/fixtures/TestRunnerDetails/action_task.yml create mode 100644 routers/web/shared/actions/main_test.go create mode 100644 routers/web/shared/actions/runners_test.go diff --git a/routers/web/shared/actions/fixtures/TestRunnerDetails/action_runner.yml b/routers/web/shared/actions/fixtures/TestRunnerDetails/action_runner.yml new file mode 100644 index 0000000000..d783f83110 --- /dev/null +++ b/routers/web/shared/actions/fixtures/TestRunnerDetails/action_runner.yml @@ -0,0 +1,7 @@ +- + id: 1004 + uuid: "fb857e63-c0ce-4571-a6c9-fde26c128073" + name: "Global runner" + owner_id: 0 + repo_id: 0 + deleted: 0 diff --git a/routers/web/shared/actions/fixtures/TestRunnerDetails/action_task.yml b/routers/web/shared/actions/fixtures/TestRunnerDetails/action_task.yml new file mode 100644 index 0000000000..63a2d30deb --- /dev/null +++ b/routers/web/shared/actions/fixtures/TestRunnerDetails/action_task.yml @@ -0,0 +1,160 @@ +- + id: 1 + runner_id: 1004 + token_hash: a1 +- + id: 2 + runner_id: 1004 + token_hash: a2 +- + id: 3 + runner_id: 1004 + token_hash: a3 +- + id: 4 + runner_id: 1004 + token_hash: a4 +- + id: 5 + runner_id: 1004 + token_hash: a5 +- + id: 6 + runner_id: 1004 + token_hash: a6 +- + id: 7 + runner_id: 1004 + token_hash: a7 +- + id: 8 + runner_id: 1004 + token_hash: a8 +- + id: 9 + runner_id: 1004 + token_hash: a9 +- + id: 10 + runner_id: 1004 + token_hash: a10 +- + id: 11 + runner_id: 1004 + token_hash: a11 +- + id: 12 + runner_id: 1004 + token_hash: a12 +- + id: 13 + runner_id: 1004 + token_hash: a13 +- + id: 14 + runner_id: 1004 + token_hash: a14 +- + id: 15 + runner_id: 1004 + token_hash: a15 +- + id: 16 + runner_id: 1004 + token_hash: a16 +- + id: 17 + runner_id: 1004 + token_hash: a17 +- + id: 18 + runner_id: 1004 + token_hash: a18 +- + id: 19 + runner_id: 1004 + token_hash: a19 +- + id: 20 + runner_id: 1004 + token_hash: a20 +- + id: 21 + runner_id: 1004 + token_hash: a21 +- + id: 22 + runner_id: 1004 + token_hash: a22 +- + id: 23 + runner_id: 1004 + token_hash: a23 +- + id: 24 + runner_id: 1004 + token_hash: a24 +- + id: 25 + runner_id: 1004 + token_hash: a25 +- + id: 26 + runner_id: 1004 + token_hash: a26 +- + id: 27 + runner_id: 1004 + token_hash: a27 +- + id: 28 + runner_id: 1004 + token_hash: a28 +- + id: 29 + runner_id: 1004 + token_hash: a29 +- + id: 30 + runner_id: 1004 + token_hash: a30 +- + id: 31 + runner_id: 1004 + token_hash: a31 +- + id: 32 + runner_id: 1004 + token_hash: a32 +- + id: 33 + runner_id: 1004 + token_hash: a33 +- + id: 34 + runner_id: 1004 + token_hash: a34 +- + id: 35 + runner_id: 1004 + token_hash: a35 +- + id: 36 + runner_id: 1004 + token_hash: a36 +- + id: 37 + runner_id: 1004 + token_hash: a37 +- + id: 38 + runner_id: 1004 + token_hash: a38 +- + id: 39 + runner_id: 1004 + token_hash: a39 +- + id: 40 + runner_id: 1004 + token_hash: a40 diff --git a/routers/web/shared/actions/main_test.go b/routers/web/shared/actions/main_test.go new file mode 100644 index 0000000000..056f48b98d --- /dev/null +++ b/routers/web/shared/actions/main_test.go @@ -0,0 +1,17 @@ +// Copyright 2025 The Forgejo Authors. +// SPDX-License-Identifier: GPL-3.0-or-later + +package actions + +import ( + "testing" + + "forgejo.org/models/unittest" + + _ "forgejo.org/models" + _ "forgejo.org/models/forgefed" +) + +func TestMain(m *testing.M) { + unittest.MainTest(m) +} diff --git a/routers/web/shared/actions/runners.go b/routers/web/shared/actions/runners.go index 98a649d1d8..2ab6b2dadd 100644 --- a/routers/web/shared/actions/runners.go +++ b/routers/web/shared/actions/runners.go @@ -79,7 +79,6 @@ func RunnerDetails(ctx *context.Context, page int, runnerID, ownerID, repoID int Page: page, PageSize: 30, }, - Status: []actions_model.Status{actions_model.StatusUnknown}, // Unknown means all RunnerID: runner.ID, } diff --git a/routers/web/shared/actions/runners_test.go b/routers/web/shared/actions/runners_test.go new file mode 100644 index 0000000000..ad75d34ee6 --- /dev/null +++ b/routers/web/shared/actions/runners_test.go @@ -0,0 +1,47 @@ +// Copyright 2025 The Forgejo Authors. +// SPDX-License-Identifier: GPL-3.0-or-later + +package actions + +import ( + "net/http" + "testing" + + actions_model "forgejo.org/models/actions" + "forgejo.org/models/unittest" + user_model "forgejo.org/models/user" + "forgejo.org/services/contexttest" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestRunnerDetails(t *testing.T) { + defer unittest.OverrideFixtures("routers/web/shared/actions/fixtures/TestRunnerDetails")() + require.NoError(t, unittest.PrepareTestDatabase()) + + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) + runner := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRunner{ID: 1004}) + + t.Run("permission denied", func(t *testing.T) { + ctx, resp := contexttest.MockContext(t, "/admin/actions/runners") + RunnerDetails(ctx, 1, runner.ID, user.ID, 0) + assert.Equal(t, http.StatusNotFound, resp.Code) + }) + + t.Run("first page", func(t *testing.T) { + ctx, resp := contexttest.MockContext(t, "/admin/actions/runners") + page := 1 + RunnerDetails(ctx, page, runner.ID, 0, 0) + require.Equal(t, http.StatusOK, resp.Code) + assert.Len(t, ctx.GetData()["Tasks"], 30) + }) + + t.Run("second and last page", func(t *testing.T) { + ctx, resp := contexttest.MockContext(t, "/admin/actions/runners") + page := 2 + RunnerDetails(ctx, page, runner.ID, 0, 0) + require.Equal(t, http.StatusOK, resp.Code) + assert.Len(t, ctx.GetData()["Tasks"], 10) + }) +}