fix: use panel Python common catalog and track install jobs
This commit is contained in:
1 parent
248badd33e
commit
d7c007adc4
12 files changed
+202
-22
No files matched your search
@@ -430,11 +430,9 @@ func (c *Client) pythonInstallations(ctx context.Context) ([]pythonInstallation,
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (c *Client) pythonLatestAvailableVersions(ctx context.Context) ([]string, error) {
|
||||
// The legacy Python manager list contains the first patch releases of many
|
||||
// branches (for example 3.12.0) and is not updated consistently. aaPanel's
|
||||
// project SDK catalog tracks the current stable patch of each branch even
|
||||
// when its bundled installer cannot fetch that release.
|
||||
func (c *Client) pythonCommonAvailableVersions(ctx context.Context) ([]string, error) {
|
||||
// Match Websites -> Python Project -> Common Versions exactly. The full
|
||||
// archive is not a fallback: it may advertise a different patch or branch.
|
||||
body, err := c.request(ctx, http.MethodPost, "/project/python/list_py_version/stype", nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("read latest Python versions: %w", err)
|
||||
@@ -444,7 +442,6 @@ func (c *Client) pythonLatestAvailableVersions(ctx context.Context) ([]string, e
|
||||
Msg string `json:"msg"`
|
||||
SDK struct {
|
||||
Streamline []runtimeSDK `json:"streamline"`
|
||||
All []runtimeSDK `json:"all"`
|
||||
} `json:"sdk"`
|
||||
}
|
||||
if err = json.Unmarshal(body, &response); err != nil {
|
||||
@@ -453,13 +450,13 @@ func (c *Client) pythonLatestAvailableVersions(ctx context.Context) ([]string, e
|
||||
if failed(response.Status) {
|
||||
return nil, fmt.Errorf("read latest Python versions: %s", safeMessage(response.Msg))
|
||||
}
|
||||
versions := make([]string, 0, len(response.SDK.Streamline)+len(response.SDK.All))
|
||||
for _, item := range append(response.SDK.Streamline, response.SDK.All...) {
|
||||
versions := make([]string, 0, len(response.SDK.Streamline))
|
||||
for _, item := range response.SDK.Streamline {
|
||||
versions = append(versions, item.Version)
|
||||
}
|
||||
versions = latestPythonBranchVersions(versions)
|
||||
if len(versions) == 0 {
|
||||
return nil, errors.New("latest Python branch catalog is empty")
|
||||
return nil, errors.New("宝塔 Python 项目的常用版本列表为空,请在面板刷新版本后重试")
|
||||
}
|
||||
return versions, nil
|
||||
}
|
||||
@@ -813,7 +810,7 @@ func (c *Client) RuntimeEnvironments(ctx context.Context) ([]RuntimeEnvironment,
|
||||
items[2].ComponentInstallable = items[2].ComponentUpdateAvailable
|
||||
}
|
||||
installations, installedErr := c.pythonInstallations(ctx)
|
||||
available, availableErr := c.pythonLatestAvailableVersions(ctx)
|
||||
available, availableErr := c.pythonCommonAvailableVersions(ctx)
|
||||
if installedErr != nil || availableErr != nil {
|
||||
items[2].ComponentStatus, items[2].Detail = RuntimeComponentFailed, "Python 版本清单暂不可用"
|
||||
} else {
|
||||
|
||||
@@ -125,6 +125,38 @@ func TestRuntimeCatalogUsesAaPanelProjectRoutes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPythonAvailableVersionsUseCommonCatalogWithoutArchiveFallback(t *testing.T) {
|
||||
for _, test := range []struct {
|
||||
name, body string
|
||||
want []string
|
||||
}{
|
||||
{"common differs from archive", `{"status":true,"sdk":{"streamline":[{"version":"3.12.15"},{"version":"3.13.17"}],"all":[{"version":"3.12.16"},{"version":"3.16.1"}]}}`, []string{"3.13.17", "3.12.15"}},
|
||||
{"no common catalog", `{"status":true,"sdk":{"all":[{"version":"3.12.16"}]}}`, nil},
|
||||
{"empty common catalog", `{"status":true,"sdk":{"streamline":[],"all":[{"version":"3.12.16"}]}}`, nil},
|
||||
{"unsafe or prerelease entries", `{"status":true,"sdk":{"streamline":[{"version":"3.13.17"},{"version":"3.14.0rc1"},{"version":"../../../tmp"},{"version":"3.12.15;id"}]}}`, []string{"3.13.17"}},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/project/python/list_py_version/stype" || r.Method != http.MethodPost {
|
||||
t.Errorf("unexpected Python catalog request: %s %s", r.Method, r.URL.Path)
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(test.body))
|
||||
}))
|
||||
defer server.Close()
|
||||
client := NewClient(server.URL, "test-key", false, time.Second)
|
||||
got, err := client.pythonCommonAvailableVersions(context.Background())
|
||||
if test.want == nil {
|
||||
if err == nil || !strings.Contains(err.Error(), "常用版本") {
|
||||
t.Fatalf("missing common catalog was silently accepted: %v", err)
|
||||
}
|
||||
} else if err != nil || !reflect.DeepEqual(got, test.want) {
|
||||
t.Fatalf("got %v, %v; want %v", got, err, test.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRuntimeCapabilitiesDoNotFailAsAGroup(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
Reference in new issue
Block a user