From 68c5cb4a0c3bf343913608ca2e36338cc60b8a76 Mon Sep 17 00:00:00 2001 From: silverwind Date: Mon, 19 Oct 2026 03:49:15 +0200 Subject: [PATCH] refactor(actions): migrate the runner API to connect-go v2 Pin https://gitea.com/gitea/actionslib/pulls/28, which generates connect-go v2 code. v2 hides plain error messages from clients and caps messages at 4 MiB. Keep v1's behaviour for runners: they show the messages, and send all pending log rows in one UpdateLog. Assisted-by: Claude Code:claude-opus-5-5 --- assets/go-licenses.json | 5 - go.mod | 5 +- go.sum | 10 +- routers/api/actions/ping/ping.go | 22 ++-- routers/api/actions/ping/ping_test.go | 30 +++--- routers/api/actions/runner/interceptor.go | 40 ++++--- routers/api/actions/runner/runner.go | 100 +++++++++--------- routers/api/actions/runner/runner_test.go | 19 ++++ tests/integration/actions_job_test.go | 19 ++-- .../integration/actions_log_finalize_test.go | 15 ++- tests/integration/actions_runner_test.go | 58 +++++----- 11 files changed, 175 insertions(+), 148 deletions(-) diff --git a/assets/go-licenses.json b/assets/go-licenses.json index 071084281bc..34edbbaacd4 100644 --- a/assets/go-licenses.json +++ b/assets/go-licenses.json @@ -4,11 +4,6 @@ "path": "cloud.google.com/go/compute/metadata/LICENSE", "licenseText": "\n Apache License\n Version 2.0, January 2004\n http://www.apache.org/licenses/\n\n TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n 1. Definitions.\n\n \"License\" shall mean the terms and conditions for use, reproduction,\n and distribution as defined by Sections 1 through 9 of this document.\n\n \"Licensor\" shall mean the copyright owner or entity authorized by\n the copyright owner that is granting the License.\n\n \"Legal Entity\" shall mean the union of the acting entity and all\n other entities that control, are controlled by, or are under common\n control with that entity. For the purposes of this definition,\n \"control\" means (i) the power, direct or indirect, to cause the\n direction or management of such entity, whether by contract or\n otherwise, or (ii) ownership of fifty percent (50%) or more of the\n outstanding shares, or (iii) beneficial ownership of such entity.\n\n \"You\" (or \"Your\") shall mean an individual or Legal Entity\n exercising permissions granted by this License.\n\n \"Source\" form shall mean the preferred form for making modifications,\n including but not limited to software source code, documentation\n source, and configuration files.\n\n \"Object\" form shall mean any form resulting from mechanical\n transformation or translation of a Source form, including but\n not limited to compiled object code, generated documentation,\n and conversions to other media types.\n\n \"Work\" shall mean the work of authorship, whether in Source or\n Object form, made available under the License, as indicated by a\n copyright notice that is included in or attached to the work\n (an example is provided in the Appendix below).\n\n \"Derivative Works\" shall mean any work, whether in Source or Object\n form, that is based on (or derived from) the Work and for which the\n editorial revisions, annotations, elaborations, or other modifications\n represent, as a whole, an original work of authorship. For the purposes\n of this License, Derivative Works shall not include works that remain\n separable from, or merely link (or bind by name) to the interfaces of,\n the Work and Derivative Works thereof.\n\n \"Contribution\" shall mean any work of authorship, including\n the original version of the Work and any modifications or additions\n to that Work or Derivative Works thereof, that is intentionally\n submitted to Licensor for inclusion in the Work by the copyright owner\n or by an individual or Legal Entity authorized to submit on behalf of\n the copyright owner. For the purposes of this definition, \"submitted\"\n means any form of electronic, verbal, or written communication sent\n to the Licensor or its representatives, including but not limited to\n communication on electronic mailing lists, source code control systems,\n and issue tracking systems that are managed by, or on behalf of, the\n Licensor for the purpose of discussing and improving the Work, but\n excluding communication that is conspicuously marked or otherwise\n designated in writing by the copyright owner as \"Not a Contribution.\"\n\n \"Contributor\" shall mean Licensor and any individual or Legal Entity\n on behalf of whom a Contribution has been received by Licensor and\n subsequently incorporated within the Work.\n\n 2. Grant of Copyright License. Subject to the terms and conditions of\n this License, each Contributor hereby grants to You a perpetual,\n worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n copyright license to reproduce, prepare Derivative Works of,\n publicly display, publicly perform, sublicense, and distribute the\n Work and such Derivative Works in Source or Object form.\n\n 3. Grant of Patent License. Subject to the terms and conditions of\n this License, each Contributor hereby grants to You a perpetual,\n worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n (except as stated in this section) patent license to make, have made,\n use, offer to sell, sell, import, and otherwise transfer the Work,\n where such license applies only to those patent claims licensable\n by such Contributor that are necessarily infringed by their\n Contribution(s) alone or by combination of their Contribution(s)\n with the Work to which such Contribution(s) was submitted. If You\n institute patent litigation against any entity (including a\n cross-claim or counterclaim in a lawsuit) alleging that the Work\n or a Contribution incorporated within the Work constitutes direct\n or contributory patent infringement, then any patent licenses\n granted to You under this License for that Work shall terminate\n as of the date such litigation is filed.\n\n 4. Redistribution. You may reproduce and distribute copies of the\n Work or Derivative Works thereof in any medium, with or without\n modifications, and in Source or Object form, provided that You\n meet the following conditions:\n\n (a) You must give any other recipients of the Work or\n Derivative Works a copy of this License; and\n\n (b) You must cause any modified files to carry prominent notices\n stating that You changed the files; and\n\n (c) You must retain, in the Source form of any Derivative Works\n that You distribute, all copyright, patent, trademark, and\n attribution notices from the Source form of the Work,\n excluding those notices that do not pertain to any part of\n the Derivative Works; and\n\n (d) If the Work includes a \"NOTICE\" text file as part of its\n distribution, then any Derivative Works that You distribute must\n include a readable copy of the attribution notices contained\n within such NOTICE file, excluding those notices that do not\n pertain to any part of the Derivative Works, in at least one\n of the following places: within a NOTICE text file distributed\n as part of the Derivative Works; within the Source form or\n documentation, if provided along with the Derivative Works; or,\n within a display generated by the Derivative Works, if and\n wherever such third-party notices normally appear. The contents\n of the NOTICE file are for informational purposes only and\n do not modify the License. You may add Your own attribution\n notices within Derivative Works that You distribute, alongside\n or as an addendum to the NOTICE text from the Work, provided\n that such additional attribution notices cannot be construed\n as modifying the License.\n\n You may add Your own copyright statement to Your modifications and\n may provide additional or different license terms and conditions\n for use, reproduction, or distribution of Your modifications, or\n for any such Derivative Works as a whole, provided Your use,\n reproduction, and distribution of the Work otherwise complies with\n the conditions stated in this License.\n\n 5. Submission of Contributions. Unless You explicitly state otherwise,\n any Contribution intentionally submitted for inclusion in the Work\n by You to the Licensor shall be under the terms and conditions of\n this License, without any additional terms or conditions.\n Notwithstanding the above, nothing herein shall supersede or modify\n the terms of any separate license agreement you may have executed\n with Licensor regarding such Contributions.\n\n 6. Trademarks. This License does not grant permission to use the trade\n names, trademarks, service marks, or product names of the Licensor,\n except as required for reasonable and customary use in describing the\n origin of the Work and reproducing the content of the NOTICE file.\n\n 7. Disclaimer of Warranty. Unless required by applicable law or\n agreed to in writing, Licensor provides the Work (and each\n Contributor provides its Contributions) on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n implied, including, without limitation, any warranties or conditions\n of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n PARTICULAR PURPOSE. You are solely responsible for determining the\n appropriateness of using or redistributing the Work and assume any\n risks associated with Your exercise of permissions under this License.\n\n 8. Limitation of Liability. In no event and under no legal theory,\n whether in tort (including negligence), contract, or otherwise,\n unless required by applicable law (such as deliberate and grossly\n negligent acts) or agreed to in writing, shall any Contributor be\n liable to You for damages, including any direct, indirect, special,\n incidental, or consequential damages of any character arising as a\n result of this License or out of the use or inability to use the\n Work (including but not limited to damages for loss of goodwill,\n work stoppage, computer failure or malfunction, or any and all\n other commercial damages or losses), even if such Contributor\n has been advised of the possibility of such damages.\n\n 9. Accepting Warranty or Additional Liability. While redistributing\n the Work or Derivative Works thereof, You may choose to offer,\n and charge a fee for, acceptance of support, warranty, indemnity,\n or other liability obligations and/or rights consistent with this\n License. However, in accepting such obligations, You may act only\n on Your own behalf and on Your sole responsibility, not on behalf\n of any other Contributor, and only if You agree to indemnify,\n defend, and hold each Contributor harmless for any liability\n incurred by, or claims asserted against, such Contributor by reason\n of your accepting any such warranty or additional liability.\n\n END OF TERMS AND CONDITIONS\n\n APPENDIX: How to apply the Apache License to your work.\n\n To apply the Apache License to your work, attach the following\n boilerplate notice, with the fields enclosed by brackets \"[]\"\n replaced with your own identifying information. (Don't include\n the brackets!) The text should be enclosed in the appropriate\n comment syntax for the file format. We also recommend that a\n file or class name and description of purpose be included on the\n same \"printed page\" as the copyright notice for easier\n identification within third-party archives.\n\n Copyright [yyyy] [name of copyright owner]\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n" }, - { - "name": "connectrpc.com/connect", - "path": "connectrpc.com/connect/LICENSE", - "licenseText": " Apache License\n Version 2.0, January 2004\n http://www.apache.org/licenses/\n\n TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n 1. Definitions.\n\n \"License\" shall mean the terms and conditions for use, reproduction,\n and distribution as defined by Sections 1 through 9 of this document.\n\n \"Licensor\" shall mean the copyright owner or entity authorized by\n the copyright owner that is granting the License.\n\n \"Legal Entity\" shall mean the union of the acting entity and all\n other entities that control, are controlled by, or are under common\n control with that entity. For the purposes of this definition,\n \"control\" means (i) the power, direct or indirect, to cause the\n direction or management of such entity, whether by contract or\n otherwise, or (ii) ownership of fifty percent (50%) or more of the\n outstanding shares, or (iii) beneficial ownership of such entity.\n\n \"You\" (or \"Your\") shall mean an individual or Legal Entity\n exercising permissions granted by this License.\n\n \"Source\" form shall mean the preferred form for making modifications,\n including but not limited to software source code, documentation\n source, and configuration files.\n\n \"Object\" form shall mean any form resulting from mechanical\n transformation or translation of a Source form, including but\n not limited to compiled object code, generated documentation,\n and conversions to other media types.\n\n \"Work\" shall mean the work of authorship, whether in Source or\n Object form, made available under the License, as indicated by a\n copyright notice that is included in or attached to the work\n (an example is provided in the Appendix below).\n\n \"Derivative Works\" shall mean any work, whether in Source or Object\n form, that is based on (or derived from) the Work and for which the\n editorial revisions, annotations, elaborations, or other modifications\n represent, as a whole, an original work of authorship. For the purposes\n of this License, Derivative Works shall not include works that remain\n separable from, or merely link (or bind by name) to the interfaces of,\n the Work and Derivative Works thereof.\n\n \"Contribution\" shall mean any work of authorship, including\n the original version of the Work and any modifications or additions\n to that Work or Derivative Works thereof, that is intentionally\n submitted to Licensor for inclusion in the Work by the copyright owner\n or by an individual or Legal Entity authorized to submit on behalf of\n the copyright owner. For the purposes of this definition, \"submitted\"\n means any form of electronic, verbal, or written communication sent\n to the Licensor or its representatives, including but not limited to\n communication on electronic mailing lists, source code control systems,\n and issue tracking systems that are managed by, or on behalf of, the\n Licensor for the purpose of discussing and improving the Work, but\n excluding communication that is conspicuously marked or otherwise\n designated in writing by the copyright owner as \"Not a Contribution.\"\n\n \"Contributor\" shall mean Licensor and any individual or Legal Entity\n on behalf of whom a Contribution has been received by Licensor and\n subsequently incorporated within the Work.\n\n 2. Grant of Copyright License. Subject to the terms and conditions of\n this License, each Contributor hereby grants to You a perpetual,\n worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n copyright license to reproduce, prepare Derivative Works of,\n publicly display, publicly perform, sublicense, and distribute the\n Work and such Derivative Works in Source or Object form.\n\n 3. Grant of Patent License. Subject to the terms and conditions of\n this License, each Contributor hereby grants to You a perpetual,\n worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n (except as stated in this section) patent license to make, have made,\n use, offer to sell, sell, import, and otherwise transfer the Work,\n where such license applies only to those patent claims licensable\n by such Contributor that are necessarily infringed by their\n Contribution(s) alone or by combination of their Contribution(s)\n with the Work to which such Contribution(s) was submitted. If You\n institute patent litigation against any entity (including a\n cross-claim or counterclaim in a lawsuit) alleging that the Work\n or a Contribution incorporated within the Work constitutes direct\n or contributory patent infringement, then any patent licenses\n granted to You under this License for that Work shall terminate\n as of the date such litigation is filed.\n\n 4. Redistribution. You may reproduce and distribute copies of the\n Work or Derivative Works thereof in any medium, with or without\n modifications, and in Source or Object form, provided that You\n meet the following conditions:\n\n (a) You must give any other recipients of the Work or\n Derivative Works a copy of this License; and\n\n (b) You must cause any modified files to carry prominent notices\n stating that You changed the files; and\n\n (c) You must retain, in the Source form of any Derivative Works\n that You distribute, all copyright, patent, trademark, and\n attribution notices from the Source form of the Work,\n excluding those notices that do not pertain to any part of\n the Derivative Works; and\n\n (d) If the Work includes a \"NOTICE\" text file as part of its\n distribution, then any Derivative Works that You distribute must\n include a readable copy of the attribution notices contained\n within such NOTICE file, excluding those notices that do not\n pertain to any part of the Derivative Works, in at least one\n of the following places: within a NOTICE text file distributed\n as part of the Derivative Works; within the Source form or\n documentation, if provided along with the Derivative Works; or,\n within a display generated by the Derivative Works, if and\n wherever such third-party notices normally appear. The contents\n of the NOTICE file are for informational purposes only and\n do not modify the License. You may add Your own attribution\n notices within Derivative Works that You distribute, alongside\n or as an addendum to the NOTICE text from the Work, provided\n that such additional attribution notices cannot be construed\n as modifying the License.\n\n You may add Your own copyright statement to Your modifications and\n may provide additional or different license terms and conditions\n for use, reproduction, or distribution of Your modifications, or\n for any such Derivative Works as a whole, provided Your use,\n reproduction, and distribution of the Work otherwise complies with\n the conditions stated in this License.\n\n 5. Submission of Contributions. Unless You explicitly state otherwise,\n any Contribution intentionally submitted for inclusion in the Work\n by You to the Licensor shall be under the terms and conditions of\n this License, without any additional terms or conditions.\n Notwithstanding the above, nothing herein shall supersede or modify\n the terms of any separate license agreement you may have executed\n with Licensor regarding such Contributions.\n\n 6. Trademarks. This License does not grant permission to use the trade\n names, trademarks, service marks, or product names of the Licensor,\n except as required for reasonable and customary use in describing the\n origin of the Work and reproducing the content of the NOTICE file.\n\n 7. Disclaimer of Warranty. Unless required by applicable law or\n agreed to in writing, Licensor provides the Work (and each\n Contributor provides its Contributions) on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n implied, including, without limitation, any warranties or conditions\n of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n PARTICULAR PURPOSE. You are solely responsible for determining the\n appropriateness of using or redistributing the Work and assume any\n risks associated with Your exercise of permissions under this License.\n\n 8. Limitation of Liability. In no event and under no legal theory,\n whether in tort (including negligence), contract, or otherwise,\n unless required by applicable law (such as deliberate and grossly\n negligent acts) or agreed to in writing, shall any Contributor be\n liable to You for damages, including any direct, indirect, special,\n incidental, or consequential damages of any character arising as a\n result of this License or out of the use or inability to use the\n Work (including but not limited to damages for loss of goodwill,\n work stoppage, computer failure or malfunction, or any and all\n other commercial damages or losses), even if such Contributor\n has been advised of the possibility of such damages.\n\n 9. Accepting Warranty or Additional Liability. While redistributing\n the Work or Derivative Works thereof, You may choose to offer,\n and charge a fee for, acceptance of support, warranty, indemnity,\n or other liability obligations and/or rights consistent with this\n License. However, in accepting such obligations, You may act only\n on Your own behalf and on Your sole responsibility, not on behalf\n of any other Contributor, and only if You agree to indemnify,\n defend, and hold each Contributor harmless for any liability\n incurred by, or claims asserted against, such Contributor by reason\n of your accepting any such warranty or additional liability.\n\n END OF TERMS AND CONDITIONS\n\n APPENDIX: How to apply the Apache License to your work.\n\n To apply the Apache License to your work, attach the following\n boilerplate notice, with the fields enclosed by brackets \"[]\"\n replaced with your own identifying information. (Don't include\n the brackets!) The text should be enclosed in the appropriate\n comment syntax for the file format. We also recommend that a\n file or class name and description of purpose be included on the\n same \"printed page\" as the copyright notice for easier\n identification within third-party archives.\n\n Copyright 2021-2025 The Connect Authors\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n" - }, { "name": "connectrpc.com/connect/v2", "path": "connectrpc.com/connect/v2/LICENSE", diff --git a/go.mod b/go.mod index ac8fb27d03f..673a9510beb 100644 --- a/go.mod +++ b/go.mod @@ -5,10 +5,10 @@ go 1.27 toolchain go1.27.2 require ( - connectrpc.com/connect/v2 v2.0.0 + connectrpc.com/connect/v2 v2.0.1 gitea.com/lunny/dingtalk_webhook v0.0.0-20171025031554-e3534c89ef96 gitea.com/lunny/levelqueue v0.4.2-0.20230414023320-3c0159fe0fe4 - gitea.dev/actionslib v1.4.1 + gitea.dev/actionslib v1.4.2-0.20261019014634-1fd849368a92 gitea.dev/sdk v1.3.0 github.com/42wim/httpsig v1.3.0 github.com/42wim/sshsig v0.0.0-20260317195500-b9f38cf0d432 @@ -107,7 +107,6 @@ require ( require ( cloud.google.com/go/compute/metadata v0.9.0 // indirect - connectrpc.com/connect v1.21.0 // indirect filippo.io/edwards25519 v1.2.0 // indirect github.com/RoaringBitmap/roaring/v2 v2.18.2 // indirect github.com/STARRY-S/zip v0.2.3 // indirect diff --git a/go.sum b/go.sum index b9c2830278a..27ded4ae682 100644 --- a/go.sum +++ b/go.sum @@ -2,10 +2,8 @@ cloud.google.com/go/compute/metadata v0.9.0 h1:pDUj4QMoPejqq20dK0Pg2N4yG9zIkYGdB cloud.google.com/go/compute/metadata v0.9.0/go.mod h1:E0bWwX5wTnLPedCKqk3pJmVgCBSM6qQI1yTBdEb3C10= code.pfad.fr/check v1.1.0 h1:GWvjdzhSEgHvEHe2uJujDcpmZoySKuHQNrZMfzfO0bE= code.pfad.fr/check v1.1.0/go.mod h1:NiUH13DtYsb7xp5wll0U4SXx7KhXQVCtRgdC96IPfoM= -connectrpc.com/connect v1.21.0 h1:LhqSJt7jHf5NJBo9Jq/t/9FjcYAideif0mg+qe2jCUs= -connectrpc.com/connect v1.21.0/go.mod h1:A2ygJrukXwWy32vkCAAHNVguZrqZ+jeZ9rGRnGR4dN4= -connectrpc.com/connect/v2 v2.0.0 h1:PVVpWl2Xv9dIWN2gijs4HK40NSnPFzLqCEEmZ8fCUQ8= -connectrpc.com/connect/v2 v2.0.0/go.mod h1:N32OLrstcPUzkykFynnefFro3+xzSdOrZlK2jHmS/xo= +connectrpc.com/connect/v2 v2.0.1 h1:WTAycxe87UqxSM5oxS30d1dalZ+C5xz8Ec8O6zVYkHQ= +connectrpc.com/connect/v2 v2.0.1/go.mod h1:N32OLrstcPUzkykFynnefFro3+xzSdOrZlK2jHmS/xo= filippo.io/edwards25519 v1.2.0 h1:crnVqOiS4jqYleHd9vaKZ+HKtHfllngJIiOpNpoJsjo= filippo.io/edwards25519 v1.2.0/go.mod h1:xzAOLCNug/yB62zG1bQ8uziwrIqIuxhctzJT18Q77mc= gitea.com/lunny/dingtalk_webhook v0.0.0-20171025031554-e3534c89ef96 h1:+wWBi6Qfruqu7xJgjOIrKVQGiLUZdpKYCZewJ4clqhw= @@ -14,8 +12,8 @@ gitea.com/lunny/levelqueue v0.4.2-0.20230414023320-3c0159fe0fe4 h1:IFT+hup2xejHq gitea.com/lunny/levelqueue v0.4.2-0.20230414023320-3c0159fe0fe4/go.mod h1:HBqmLbz56JWpfEGG0prskAV97ATNRoj5LDmPicD22hU= gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s= gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU= -gitea.dev/actionslib v1.4.1 h1:DWlUnzDfuuMArQWS6yZ+vwJu9av7sZVMOox7li/kyu4= -gitea.dev/actionslib v1.4.1/go.mod h1:RbXaZudZ04YndjBBxZJF9rZAqU6SKGkaSD1sob5lQbE= +gitea.dev/actionslib v1.4.2-0.20261019014634-1fd849368a92 h1:qjj0mqRCwZ269pJo4LH8e4ePMVK/iWMA0tO6Dxiey+M= +gitea.dev/actionslib v1.4.2-0.20261019014634-1fd849368a92/go.mod h1:NWzFSnEG5EEXaq66Ql3moZ31g4H7+sAmSCyBirjj2R4= gitea.dev/sdk v1.3.0 h1:4U95+Ou6WHCQiRPDEyAzvl1Q7cxg5RUTWkqmOXr5w4I= gitea.dev/sdk v1.3.0/go.mod h1:85EBqSAqUn1KlFCk40y3sTjWjBsB/KouL3slGXMA/2o= github.com/42wim/httpsig v1.3.0 h1:HK2bieeZ99X9IvOoc1ST6yrhLek0f4MqlEGES2JCP3g= diff --git a/routers/api/actions/ping/ping.go b/routers/api/actions/ping/ping.go index 8b556f3ebf3..15343d73f94 100644 --- a/routers/api/actions/ping/ping.go +++ b/routers/api/actions/ping/ping.go @@ -13,10 +13,15 @@ import ( "gitea.dev/modules/log" "connectrpc.com/connect/v2" + "connectrpc.com/connect/v2/connecthttp" ) func NewPingServiceHandler() (string, http.Handler) { - return pingv1connect.NewPingServiceHandler(&Service{}) + server := connect.NewServer() + pingv1connect.RegisterPingServiceHandler(server, &Service{}) + mux := http.NewServeMux() + connecthttp.Mount(mux, server) + return "/" + pingv1connect.PingServiceName + "/", mux } var _ pingv1connect.PingServiceHandler = (*Service)(nil) @@ -25,12 +30,13 @@ type Service struct{} func (s *Service) Ping( ctx context.Context, - req *connect.Request[pingv1.PingRequest], -) (*connect.Response[pingv1.PingResponse], error) { - log.Trace("Content-Type: %s", req.Header().Get("Content-Type")) - log.Trace("User-Agent: %s", req.Header().Get("User-Agent")) - res := connect.NewResponse(&pingv1.PingResponse{ - Data: fmt.Sprintf("Hello, %s!", req.Msg.Data), - }) + req *pingv1.PingRequest, +) (*pingv1.PingResponse, error) { + info, _ := connect.CallInfoForServerContext(ctx) + log.Trace("Content-Type: %s", info.RequestHeader().Get("Content-Type")) + log.Trace("User-Agent: %s", info.RequestHeader().Get("User-Agent")) + res := &pingv1.PingResponse{ + Data: fmt.Sprintf("Hello, %s!", req.Data), + } return res, nil } diff --git a/routers/api/actions/ping/ping_test.go b/routers/api/actions/ping/ping_test.go index 2fdbe66f032..752292aeaf7 100644 --- a/routers/api/actions/ping/ping_test.go +++ b/routers/api/actions/ping/ping_test.go @@ -12,16 +12,14 @@ import ( "gitea.dev/actionslib/ping/v1/pingv1connect" "connectrpc.com/connect/v2" + "connectrpc.com/connect/v2/connecthttp" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestService(t *testing.T) { - mux := http.NewServeMux() - mux.Handle(pingv1connect.NewPingServiceHandler( - &Service{}, - )) - MainServiceTest(t, mux) + _, handler := NewPingServiceHandler() + MainServiceTest(t, handler) } func MainServiceTest(t *testing.T, h http.Handler) { @@ -31,31 +29,31 @@ func MainServiceTest(t *testing.T, h http.Handler) { server.StartTLS() defer server.Close() - connectClient := pingv1connect.NewPingServiceClient( + connectClient := pingv1connect.NewPingServiceClient(connect.NewClient(connecthttp.NewTransport( server.Client(), server.URL, - ) + ))) - grpcClient := pingv1connect.NewPingServiceClient( + grpcClient := pingv1connect.NewPingServiceClient(connect.NewClient(connecthttp.NewTransport( server.Client(), server.URL, - connect.WithGRPC(), - ) + connecthttp.WithGRPC(), + ))) - grpcWebClient := pingv1connect.NewPingServiceClient( + grpcWebClient := pingv1connect.NewPingServiceClient(connect.NewClient(connecthttp.NewTransport( server.Client(), server.URL, - connect.WithGRPCWeb(), - ) + connecthttp.WithGRPCWeb(), + ))) clients := []pingv1connect.PingServiceClient{connectClient, grpcClient, grpcWebClient} t.Run("ping request", func(t *testing.T) { for _, client := range clients { - result, err := client.Ping(t.Context(), connect.NewRequest(&pingv1.PingRequest{ + result, err := client.Ping(t.Context(), &pingv1.PingRequest{ Data: "foobar", - })) + }) require.NoError(t, err) - assert.Equal(t, "Hello, foobar!", result.Msg.Data) + assert.Equal(t, "Hello, foobar!", result.Data) } }) } diff --git a/routers/api/actions/runner/interceptor.go b/routers/api/actions/runner/interceptor.go index 6bf2d5d7db2..0621984aae1 100644 --- a/routers/api/actions/runner/interceptor.go +++ b/routers/api/actions/runner/interceptor.go @@ -26,27 +26,39 @@ const ( tokenHeaderKey = protocol.TokenHeader ) -var withRunner = connect.WithInterceptors(connect.UnaryInterceptorFunc(func(unaryFunc connect.UnaryFunc) connect.UnaryFunc { +// withErrorMessages sends plain errors to runners as CodeUnknown with their message, like connect v1 did. +func withErrorMessages(next connect.ServerFunc) connect.ServerFunc { + return func(ctx context.Context, spec connect.Spec, stream connect.ServerStream) error { + err := next(ctx, spec, stream) + if _, ok := errors.AsType[*connect.Error](err); err == nil || ok { + return err + } + return connect.NewError(connect.CodeUnknown, err.Error()).WithCause(err) + } +} + +func withRunner(next connect.ServerFunc) connect.ServerFunc { // A plain gRPC status.Error is treated as unknown by Connect and becomes HTTP 500 // To respond an HTTP status code, use connect.Error instead - errUnregisteredRunner := connect.NewError(connect.CodeUnauthenticated, errors.New("unregistered runner")) - return func(ctx context.Context, request connect.AnyRequest) (connect.AnyResponse, error) { - methodName := getMethodName(request) + errUnregisteredRunner := connect.NewError(connect.CodeUnauthenticated, "unregistered runner") + return func(ctx context.Context, spec connect.Spec, stream connect.ServerStream) error { + methodName := getMethodName(spec) if methodName == "Register" { - return unaryFunc(ctx, request) + return next(ctx, spec, stream) } - uuid := request.Header().Get(uuidHeaderKey) - token := request.Header().Get(tokenHeaderKey) + info, _ := connect.CallInfoForServerContext(ctx) + uuid := info.RequestHeader().Get(uuidHeaderKey) + token := info.RequestHeader().Get(tokenHeaderKey) runner, err := actions_model.GetRunnerByUUID(ctx, uuid) if err != nil { if errors.Is(err, util.ErrNotExist) { - return nil, errUnregisteredRunner + return errUnregisteredRunner } - return nil, status.Error(codes.Internal, err.Error()) + return status.Error(codes.Internal, err.Error()) } if !util.CryptoConstTimeEqual(runner.TokenHash, auth_model.HashToken(token, runner.TokenSalt)) { - return nil, errUnregisteredRunner + return errUnregisteredRunner } now := time.Now() @@ -72,12 +84,12 @@ var withRunner = connect.WithInterceptors(connect.UnaryInterceptorFunc(func(unar } ctx = context.WithValue(ctx, runnerCtxKey{}, runner) - return unaryFunc(ctx, request) + return next(ctx, spec, stream) } -})) +} -func getMethodName(req connect.AnyRequest) string { - splits := strings.Split(req.Spec().Procedure, "/") +func getMethodName(spec connect.Spec) string { + splits := strings.Split(spec.Procedure, "/") if len(splits) > 0 { return splits[len(splits)-1] } diff --git a/routers/api/actions/runner/runner.go b/routers/api/actions/runner/runner.go index e52b9c1709a..7433bd3e02f 100644 --- a/routers/api/actions/runner/runner.go +++ b/routers/api/actions/runner/runner.go @@ -21,17 +21,19 @@ import ( actions_service "gitea.dev/services/actions" "connectrpc.com/connect/v2" + "connectrpc.com/connect/v2/connecthttp" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "google.golang.org/protobuf/proto" ) func NewRunnerServiceHandler() (string, http.Handler) { - return runnerv1connect.NewRunnerServiceHandler( - &Service{}, - connect.WithCompressMinBytes(1024), - withRunner, - ) + server := connect.NewServer(withErrorMessages, withRunner) + runnerv1connect.RegisterRunnerServiceHandler(server, &Service{}) + mux := http.NewServeMux() + // runners send all pending log rows in one UpdateLog, so keep v1's unlimited message size + connecthttp.Mount(mux, server, connecthttp.WithCompressMinBytes(1024), connecthttp.WithReadMaxBytes(0)) + return "/" + runnerv1connect.RunnerServiceName + "/", mux } var _ runnerv1connect.RunnerServiceClient = (*Service)(nil) @@ -41,13 +43,13 @@ type Service struct{} // Register for new runner. func (s *Service) Register( ctx context.Context, - req *connect.Request[runnerv1.RegisterRequest], -) (*connect.Response[runnerv1.RegisterResponse], error) { - if req.Msg.Token == "" || req.Msg.Name == "" { + req *runnerv1.RegisterRequest, +) (*runnerv1.RegisterResponse, error) { + if req.Token == "" || req.Name == "" { return nil, errors.New("missing runner token, name") } - runnerToken, err := actions_model.GetRunnerToken(ctx, req.Msg.Token) + runnerToken, err := actions_model.GetRunnerToken(ctx, req.Token) if err != nil { return nil, errors.New("runner registration token not found") } @@ -68,19 +70,19 @@ func (s *Service) Register( } } - labels := req.Msg.Labels - hasCancellingSupport := slices.Contains(req.Msg.GetCapabilities(), runnerCapabilityCancelling) + labels := req.Labels + hasCancellingSupport := slices.Contains(req.GetCapabilities(), runnerCapabilityCancelling) // create new runner - name := util.EllipsisDisplayString(req.Msg.Name, 255) + name := util.EllipsisDisplayString(req.Name, 255) runner := &actions_model.ActionRunner{ UUID: uuid.New().String(), Name: name, OwnerID: runnerToken.OwnerID, RepoID: runnerToken.RepoID, - Version: req.Msg.Version, + Version: req.Version, AgentLabels: labels, - Ephemeral: req.Msg.Ephemeral, + Ephemeral: req.Ephemeral, HasCancellingSupport: hasCancellingSupport, } runner.GenerateAndFillToken() @@ -96,7 +98,7 @@ func (s *Service) Register( return nil, errors.New("can't update runner token status") } - res := connect.NewResponse(&runnerv1.RegisterResponse{ + res := &runnerv1.RegisterResponse{ Runner: &runnerv1.Runner{ Id: runner.ID, Uuid: runner.UUID, @@ -106,7 +108,7 @@ func (s *Service) Register( Labels: runner.AgentLabels, Ephemeral: runner.Ephemeral, }, - }) + } return res, nil } @@ -139,14 +141,18 @@ func applyDeclareRequestToRunner(runner *actions_model.ActionRunner, req declare func (s *Service) Declare( ctx context.Context, - req *connect.Request[runnerv1.DeclareRequest], -) (*connect.Response[runnerv1.DeclareResponse], error) { + req *runnerv1.DeclareRequest, +) (*runnerv1.DeclareResponse, error) { runner := GetRunner(ctx) - if err := actions_model.UpdateRunner(ctx, runner, applyDeclareRequestToRunner(runner, req.Msg)...); err != nil { + if err := actions_model.UpdateRunner(ctx, runner, applyDeclareRequestToRunner(runner, req)...); err != nil { return nil, status.Errorf(codes.Internal, "update runner: %v", err) } - resp := connect.NewResponse(&runnerv1.DeclareResponse{ + // Capabilities are communicated via headers to avoid a hard dependency on a proto bump. + // Older runners ignore unknown headers; newer runners can use this for feature negotiation. + info, _ := connect.CallInfoForServerContext(ctx) + info.ResponseHeader().Set("X-Gitea-Actions-Capabilities", actions_model.RunnerCapabilities()) + return &runnerv1.DeclareResponse{ Runner: &runnerv1.Runner{ Id: runner.ID, Uuid: runner.UUID, @@ -155,22 +161,18 @@ func (s *Service) Declare( Version: runner.Version, Labels: runner.AgentLabels, }, - }) - // Capabilities are communicated via headers to avoid a hard dependency on a proto bump. - // Older runners ignore unknown headers; newer runners can use this for feature negotiation. - resp.Header().Set("X-Gitea-Actions-Capabilities", actions_model.RunnerCapabilities()) - return resp, nil + }, nil } // FetchTask assigns a task to the runner func (s *Service) FetchTask( ctx context.Context, - req *connect.Request[runnerv1.FetchTaskRequest], -) (*connect.Response[runnerv1.FetchTaskResponse], error) { + req *runnerv1.FetchTaskRequest, +) (*runnerv1.FetchTaskResponse, error) { runner := GetRunner(ctx) var task *runnerv1.Task - tasksVersion := req.Msg.TasksVersion // task version from runner + tasksVersion := req.TasksVersion // task version from runner latestVersion, err := actions_model.GetTasksVersionByScope(ctx, runner.OwnerID, runner.RepoID) if err != nil { return nil, status.Errorf(codes.Internal, "query tasks version failed: %v", err) @@ -207,26 +209,26 @@ func (s *Service) FetchTask( task = t } } - res := connect.NewResponse(&runnerv1.FetchTaskResponse{ + res := &runnerv1.FetchTaskResponse{ Task: task, TasksVersion: latestVersion, - }) + } return res, nil } // UpdateTask updates the task status. func (s *Service) UpdateTask( ctx context.Context, - req *connect.Request[runnerv1.UpdateTaskRequest], -) (*connect.Response[runnerv1.UpdateTaskResponse], error) { + req *runnerv1.UpdateTaskRequest, +) (*runnerv1.UpdateTaskResponse, error) { runner := GetRunner(ctx) - task, err := actions_model.UpdateTaskByState(ctx, runner.ID, req.Msg.State) + task, err := actions_model.UpdateTaskByState(ctx, runner.ID, req.State) if err != nil { return nil, status.Errorf(codes.Internal, "update task: %v", err) } - for k, v := range req.Msg.Outputs { + for k, v := range req.Outputs { if len(k) > 255 { log.Warn("Ignore the output of task %d because the key is too long: %q", task.ID, k) continue @@ -264,7 +266,7 @@ func (s *Service) UpdateTask( actions_service.NotifyWorkflowJobStatusUpdateWithTask(ctx, task.Job, task) } - if req.Msg.State.Result != runnerv1.Result_RESULT_UNSPECIFIED { + if req.State.Result != runnerv1.Result_RESULT_UNSPECIFIED { if err := actions_service.EmitJobsIfReadyByRun(task.Job.RunID); err != nil { log.Error("Emit ready jobs of run %d: %v", task.Job.RunID, err) } @@ -273,25 +275,25 @@ func (s *Service) UpdateTask( } } - return connect.NewResponse(&runnerv1.UpdateTaskResponse{ + return &runnerv1.UpdateTaskResponse{ State: &runnerv1.TaskState{ - Id: req.Msg.State.Id, + Id: req.State.Id, Result: task.Status.AsResult(), }, SentOutputs: sentOutputs, - }), nil + }, nil } // UpdateLog uploads log of the task. func (s *Service) UpdateLog( ctx context.Context, - req *connect.Request[runnerv1.UpdateLogRequest], -) (*connect.Response[runnerv1.UpdateLogResponse], error) { + req *runnerv1.UpdateLogRequest, +) (*runnerv1.UpdateLogResponse, error) { runner := GetRunner(ctx) - res := connect.NewResponse(&runnerv1.UpdateLogResponse{}) + res := &runnerv1.UpdateLogResponse{} - task, err := actions_model.GetTaskByID(ctx, req.Msg.TaskId) + task, err := actions_model.GetTaskByID(ctx, req.TaskId) if err != nil { return nil, status.Errorf(codes.Internal, "get task: %v", err) } else if runner.ID != task.RunnerID { @@ -301,8 +303,8 @@ func (s *Service) UpdateLog( // Trim rows the runner already had acked. var rows []*runnerv1.LogRow - if req.Msg.Index <= ack && int64(len(req.Msg.Rows))+req.Msg.Index > ack { - rows = req.Msg.Rows[ack-req.Msg.Index:] + if req.Index <= ack && int64(len(req.Rows))+req.Index > ack { + rows = req.Rows[ack-req.Index:] } // Ack a re-sent finalize idempotently. Appending new rows past the seal errors. @@ -310,15 +312,15 @@ func (s *Service) UpdateLog( if len(rows) > 0 { return nil, status.Errorf(codes.AlreadyExists, "log file has been archived") } - res.Msg.AckIndex = ack + res.AckIndex = ack return res, nil } // Bail unless we have new rows or a NoMore to finalize. Even with // NoMore, bail when the runner has outrun the server — archiving a // log with a gap is worse than asking it to retry. - if len(rows) == 0 && (!req.Msg.NoMore || req.Msg.Index > ack) { - res.Msg.AckIndex = ack + if len(rows) == 0 && (!req.NoMore || req.Index > ack) { + res.AckIndex = ack return res, nil } @@ -335,10 +337,10 @@ func (s *Service) UpdateLog( task.LogSize += int64(n) } - res.Msg.AckIndex = task.LogLength + res.AckIndex = task.LogLength var remove func() - if req.Msg.NoMore { + if req.NoMore { task.LogInStorage = true remove, err = actions.TransferLogs(ctx, task.LogFilename) if err != nil { diff --git a/routers/api/actions/runner/runner_test.go b/routers/api/actions/runner/runner_test.go index 32ef6f95741..b79a09f37a9 100644 --- a/routers/api/actions/runner/runner_test.go +++ b/routers/api/actions/runner/runner_test.go @@ -4,14 +4,33 @@ package runner import ( + "errors" + "net/http/httptest" "testing" runnerv1 "gitea.dev/actionslib/runner/v1" + "gitea.dev/actionslib/runner/v1/runnerv1connect" actions_model "gitea.dev/models/actions" + "connectrpc.com/connect/v2" + "connectrpc.com/connect/v2/connecthttp" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) +func TestPlainErrorReachesRunnerAsUnknownWithMessage(t *testing.T) { + _, handler := NewRunnerServiceHandler() + server := httptest.NewServer(handler) + defer server.Close() + + client := runnerv1connect.NewRunnerServiceClient(connect.NewClient(connecthttp.NewTransport(server.Client(), server.URL))) + _, err := client.Register(t.Context(), &runnerv1.RegisterRequest{}) + connectErr, ok := errors.AsType[*connect.Error](err) + require.True(t, ok) + assert.Equal(t, connect.CodeUnknown, connectErr.Code()) + assert.Equal(t, "missing runner token, name", connectErr.Message()) +} + func TestApplyDeclareRequestToRunnerAdvertisedCapabilityEnablesCancelling(t *testing.T) { runner := &actions_model.ActionRunner{} req := &runnerv1.DeclareRequest{ diff --git a/tests/integration/actions_job_test.go b/tests/integration/actions_job_test.go index 61cc0a3e71a..b2c46d024aa 100644 --- a/tests/integration/actions_job_test.go +++ b/tests/integration/actions_job_test.go @@ -27,7 +27,6 @@ import ( "gitea.dev/modules/timeutil" actions_service "gitea.dev/services/actions" - "connectrpc.com/connect/v2" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -643,33 +642,33 @@ jobs: err = actions_service.CleanupEphemeralRunners(t.Context()) assert.NoError(t, err) - resp, err := runner.client.runnerServiceClient.FetchTask(t.Context(), connect.NewRequest(&runnerv1.FetchTaskRequest{ + resp, err := runner.client.runnerServiceClient.FetchTask(t.Context(), &runnerv1.FetchTaskRequest{ TasksVersion: 0, - })) + }) assert.NoError(t, err) - assert.Nil(t, resp.Msg.Task) + assert.Nil(t, resp.Task) // verify CleanupEphemeralRunners does not remove this runner err = actions_service.CleanupEphemeralRunners(t.Context()) assert.NoError(t, err) - _, err = runner.client.runnerServiceClient.UpdateTask(t.Context(), connect.NewRequest(&runnerv1.UpdateTaskRequest{ + _, err = runner.client.runnerServiceClient.UpdateTask(t.Context(), &runnerv1.UpdateTaskRequest{ State: &runnerv1.TaskState{ Id: actionTask.ID, Result: runnerv1.Result_RESULT_SUCCESS, }, - })) + }) assert.NoError(t, err) - resp, err = runner.client.runnerServiceClient.FetchTask(t.Context(), connect.NewRequest(&runnerv1.FetchTaskRequest{ + resp, err = runner.client.runnerServiceClient.FetchTask(t.Context(), &runnerv1.FetchTaskRequest{ TasksVersion: 0, - })) + }) assert.Error(t, err) assert.Nil(t, resp) - resp, err = runner.client.runnerServiceClient.FetchTask(t.Context(), connect.NewRequest(&runnerv1.FetchTaskRequest{ + resp, err = runner.client.runnerServiceClient.FetchTask(t.Context(), &runnerv1.FetchTaskRequest{ TasksVersion: 0, - })) + }) assert.Error(t, err) assert.Nil(t, resp) diff --git a/tests/integration/actions_log_finalize_test.go b/tests/integration/actions_log_finalize_test.go index 3f046da46f9..a5c04389dfe 100644 --- a/tests/integration/actions_log_finalize_test.go +++ b/tests/integration/actions_log_finalize_test.go @@ -19,7 +19,6 @@ import ( actions_module "gitea.dev/modules/actions" "gitea.dev/modules/storage" - "connectrpc.com/connect/v2" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -56,14 +55,14 @@ jobs: task := runner.fetchTask(t) - resp, err := runner.client.runnerServiceClient.UpdateLog(t.Context(), connect.NewRequest(&runnerv1.UpdateLogRequest{ + resp, err := runner.client.runnerServiceClient.UpdateLog(t.Context(), &runnerv1.UpdateLogRequest{ TaskId: task.Id, Index: 0, Rows: nil, NoMore: true, - })) + }) require.NoError(t, err) - assert.EqualValues(t, 0, resp.Msg.AckIndex) + assert.EqualValues(t, 0, resp.AckIndex) freshTask := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionTask{ID: task.Id}) require.True(t, freshTask.LogInStorage, "log_in_storage must flip after empty NoMore=true") @@ -78,13 +77,13 @@ jobs: // A sealed log must ack the re-send and still reject new appended rows. t.Run("re-sent finalize is idempotent", func(t *testing.T) { finalize := &runnerv1.UpdateLogRequest{TaskId: task.Id, Index: 0, Rows: nil, NoMore: true} - resp, err := runner.client.runnerServiceClient.UpdateLog(t.Context(), connect.NewRequest(finalize)) + resp, err := runner.client.runnerServiceClient.UpdateLog(t.Context(), finalize) require.NoError(t, err) - assert.EqualValues(t, 0, resp.Msg.AckIndex) + assert.EqualValues(t, 0, resp.AckIndex) - _, err = runner.client.runnerServiceClient.UpdateLog(t.Context(), connect.NewRequest(&runnerv1.UpdateLogRequest{ + _, err = runner.client.runnerServiceClient.UpdateLog(t.Context(), &runnerv1.UpdateLogRequest{ TaskId: task.Id, Index: 0, Rows: []*runnerv1.LogRow{{Content: "late"}}, NoMore: true, - })) + }) require.Error(t, err, "appending rows past the seal must be rejected") }) }) diff --git a/tests/integration/actions_runner_test.go b/tests/integration/actions_runner_test.go index 576270fe73e..7be81126ede 100644 --- a/tests/integration/actions_runner_test.go +++ b/tests/integration/actions_runner_test.go @@ -18,6 +18,7 @@ import ( "gitea.dev/modules/setting" "connectrpc.com/connect/v2" + "connectrpc.com/connect/v2/connecthttp" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "google.golang.org/protobuf/types/known/timestamppb" @@ -40,45 +41,44 @@ func newMockRunner() *mockRunner { func newMockRunnerClient(uuid, token string) *mockRunnerClient { baseURL := setting.AppURL + "api/actions" - opt := connect.WithInterceptors(connect.UnaryInterceptorFunc(func(next connect.UnaryFunc) connect.UnaryFunc { - return func(ctx context.Context, req connect.AnyRequest) (connect.AnyResponse, error) { + client := connect.NewClient(connecthttp.NewTransport(http.DefaultClient, baseURL), func(next connect.ClientFunc) connect.ClientFunc { + return func(ctx context.Context, spec connect.Spec) (connect.ClientStream, error) { + info, _ := connect.CallInfoForClientContext(ctx) if uuid != "" { - req.Header().Set("x-runner-uuid", uuid) + info.RequestHeader().Set("x-runner-uuid", uuid) } if token != "" { - req.Header().Set("x-runner-token", token) + info.RequestHeader().Set("x-runner-token", token) } - return next(ctx, req) + return next(ctx, spec) } - })) + }) - client := &mockRunnerClient{ - pingServiceClient: pingv1connect.NewPingServiceClient(http.DefaultClient, baseURL, opt), - runnerServiceClient: runnerv1connect.NewRunnerServiceClient(http.DefaultClient, baseURL, opt), + return &mockRunnerClient{ + pingServiceClient: pingv1connect.NewPingServiceClient(client), + runnerServiceClient: runnerv1connect.NewRunnerServiceClient(client), } - - return client } func (r *mockRunner) doPing(t *testing.T) { - resp, err := r.client.pingServiceClient.Ping(t.Context(), connect.NewRequest(&pingv1.PingRequest{ + resp, err := r.client.pingServiceClient.Ping(t.Context(), &pingv1.PingRequest{ Data: "mock-runner", - })) + }) assert.NoError(t, err) - assert.Equal(t, "Hello, mock-runner!", resp.Msg.Data) + assert.Equal(t, "Hello, mock-runner!", resp.Data) } func (r *mockRunner) doRegister(t *testing.T, name, token string, labels []string, ephemeral bool) { r.doPing(t) - resp, err := r.client.runnerServiceClient.Register(t.Context(), connect.NewRequest(&runnerv1.RegisterRequest{ + resp, err := r.client.runnerServiceClient.Register(t.Context(), &runnerv1.RegisterRequest{ Name: name, Token: token, Version: "mock-runner-version", Labels: labels, Ephemeral: ephemeral, - })) + }) assert.NoError(t, err) - r.client = newMockRunnerClient(resp.Msg.Runner.Uuid, resp.Msg.Runner.Token) + r.client = newMockRunnerClient(resp.Runner.Uuid, resp.Runner.Token) } func (r *mockRunner) registerAsRepoRunner(t *testing.T, ownerName, repoName, runnerName string, labels []string, ephemeral bool) { @@ -127,11 +127,11 @@ func (r *mockRunner) tryFetchTask(t *testing.T, timeout ...time.Duration) *runne // and returns the task (if any) and the TasksVersion from the response. // Used to verify the production path where the runner sends the current version. func (r *mockRunner) fetchTaskOnce(t *testing.T, tasksVersion int64) (*runnerv1.Task, int64) { - resp, err := r.client.runnerServiceClient.FetchTask(t.Context(), connect.NewRequest(&runnerv1.FetchTaskRequest{ + resp, err := r.client.runnerServiceClient.FetchTask(t.Context(), &runnerv1.FetchTaskRequest{ TasksVersion: tasksVersion, - })) + }) require.NoError(t, err) - return resp.Msg.Task, resp.Msg.TasksVersion + return resp.Task, resp.TasksVersion } type mockTaskOutcome struct { @@ -142,35 +142,35 @@ type mockTaskOutcome struct { func (r *mockRunner) execTask(t *testing.T, task *runnerv1.Task, outcome *mockTaskOutcome) { for idx, lr := range outcome.logRows { - resp, err := r.client.runnerServiceClient.UpdateLog(t.Context(), connect.NewRequest(&runnerv1.UpdateLogRequest{ + resp, err := r.client.runnerServiceClient.UpdateLog(t.Context(), &runnerv1.UpdateLogRequest{ TaskId: task.Id, Index: int64(idx), Rows: []*runnerv1.LogRow{lr}, NoMore: idx == len(outcome.logRows)-1, - })) + }) assert.NoError(t, err) - assert.EqualValues(t, idx+1, resp.Msg.AckIndex) + assert.EqualValues(t, idx+1, resp.AckIndex) } sentOutputKeys := make([]string, 0, len(outcome.outputs)) for outputKey, outputValue := range outcome.outputs { - resp, err := r.client.runnerServiceClient.UpdateTask(t.Context(), connect.NewRequest(&runnerv1.UpdateTaskRequest{ + resp, err := r.client.runnerServiceClient.UpdateTask(t.Context(), &runnerv1.UpdateTaskRequest{ State: &runnerv1.TaskState{ Id: task.Id, Result: runnerv1.Result_RESULT_UNSPECIFIED, }, Outputs: map[string]string{outputKey: outputValue}, - })) + }) assert.NoError(t, err) sentOutputKeys = append(sentOutputKeys, outputKey) - assert.ElementsMatch(t, sentOutputKeys, resp.Msg.SentOutputs) + assert.ElementsMatch(t, sentOutputKeys, resp.SentOutputs) } - resp, err := r.client.runnerServiceClient.UpdateTask(t.Context(), connect.NewRequest(&runnerv1.UpdateTaskRequest{ + resp, err := r.client.runnerServiceClient.UpdateTask(t.Context(), &runnerv1.UpdateTaskRequest{ State: &runnerv1.TaskState{ Id: task.Id, Result: outcome.result, StoppedAt: timestamppb.Now(), }, - })) + }) assert.NoError(t, err) - assert.Equal(t, outcome.result, resp.Msg.State.Result) + assert.Equal(t, outcome.result, resp.State.Result) }