Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/hubpublish/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func (m *Manager) Handler() http.Handler {
mux.HandleFunc("GET /akoflow-api/hub/publications/{publicationId}/", m.serveGetPublication)
mux.HandleFunc("PATCH /akoflow-api/hub/publications/{publicationId}/", m.serveUpdatePublication)
mux.HandleFunc("DELETE /akoflow-api/hub/publications/{publicationId}/", m.serveDeletePublication)
mux.HandleFunc("DELETE /akoflow-api/hub/publications/{publicationId}/versions/{version}/", m.serveRetireVersion)
mux.HandleFunc("GET /akoflow-api/hub/publications/{publicationId}/versions/", m.serveListVersions)
mux.HandleFunc("GET /akoflow-api/hub/publications/{publicationId}/results/", m.serveListResults)
mux.HandleFunc("GET /akoflow-api/hub/publications/{publicationId}/compare/", m.serveCompareVersions)
Expand Down
23 changes: 22 additions & 1 deletion internal/hubpublish/http_publication_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package hubpublish
import (
"net/http"
"net/url"
"strconv"
)

func (m *Manager) serveGetPublication(w http.ResponseWriter, r *http.Request) {
Expand All @@ -19,9 +20,29 @@ func (m *Manager) serveUpdatePublication(w http.ResponseWriter, r *http.Request)
respond(w, value, err)
}
func (m *Manager) serveDeletePublication(w http.ResponseWriter, r *http.Request) {
err := m.DeletePublication(r.Context(), r.PathValue("publicationId"))
id := r.PathValue("publicationId")
if r.URL.EscapedPath() != "/akoflow-api/hub/publications/"+url.PathEscape(id)+"/" {
http.NotFound(w, r)
return
}
err := m.DeletePublication(r.Context(), id)
respond(w, map[string]bool{"deleted": err == nil}, err)
}
func (m *Manager) serveRetireVersion(w http.ResponseWriter, r *http.Request) {
id, rawVersion := r.PathValue("publicationId"), r.PathValue("version")
if r.URL.EscapedPath() != "/akoflow-api/hub/publications/"+url.PathEscape(id)+"/versions/"+url.PathEscape(rawVersion)+"/" {
http.NotFound(w, r)
return
}
version, versionErr := strconv.Atoi(rawVersion)
replacement, replacementErr := strconv.Atoi(r.URL.Query().Get("replacement"))
if versionErr != nil || replacementErr != nil {
respond(w, nil, failure(422, "invalid_version_retirement", "Choose an older version and its verified replacement."))
return
}
err := m.RetireVersion(r.Context(), id, version, replacement)
respond(w, map[string]bool{"retired": err == nil}, err)
}
func (m *Manager) serveListVersions(w http.ResponseWriter, r *http.Request) {
value, err := m.ReadPublication(r.Context(), r.PathValue("publicationId"), "versions", nil)
respond(w, value, err)
Expand Down
32 changes: 32 additions & 0 deletions internal/hubpublish/publication_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"net/url"
"strconv"
)

type PublicationPatch struct {
Expand Down Expand Up @@ -101,6 +102,37 @@ func (m *Manager) DeletePublication(ctx context.Context, id string) error {
return nil
}

func (m *Manager) RetireVersion(ctx context.Context, id string, version, replacement int) error {
if m.options.ReadOnly {
return failure(403, "read_only", "Read-only instances cannot retire Hub workflow versions.")
}
if version < 1 || replacement <= version {
return failure(422, "invalid_version_retirement", "Choose an older version and its verified replacement.")
}
m.mu.Lock()
defer m.mu.Unlock()
if _, err := m.identityLocked(ctx); err != nil {
return err
}
publication, err := m.publicationLocked(ctx, id)
if err != nil {
return err
}
latest := 0
for _, candidate := range publication.Versions {
latest = max(latest, candidate.Number)
}
if latest != replacement {
return failure(409, "replacement_version_changed", "The verified replacement is no longer the latest version.")
}
path := "/desktop/publications/" + url.PathEscape(id) + "/versions/" + strconv.Itoa(version)
if err := m.requestLocked(ctx, "DELETE", path, nil, nil, true, nil); err != nil {
return err
}
m.invalidatePublicationPreviewsLocked(id)
return nil
}

func (m *Manager) invalidatePublicationPreviewsLocked(id string) {
for key, item := range m.previews {
if item.Publication.ID == id {
Expand Down
47 changes: 47 additions & 0 deletions internal/hubpublish/publication_management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
Expand Down Expand Up @@ -139,3 +140,49 @@ func TestHubImportPreservesImageMetadataAndDoesNotOverwriteConflicts(t *testing.
t.Fatal("conflict silently overwritten")
}
}

func TestRetireVersionUsesOnlyNumberedHubRoute(t *testing.T) {
deleted := 0
manager := testManager(t, func(w http.ResponseWriter, r *http.Request) {
switch {
case r.Method == "GET" && r.URL.Path == "/api/v1/desktop/me":
_ = json.NewEncoder(w).Encode(Identity{Username: "researcher", ProjectID: "project"})
case r.Method == "GET" && r.URL.Path == "/api/v1/desktop/publications/publication":
_ = json.NewEncoder(w).Encode(publicationInfo{Publication: Publication{ID: "publication"},
Versions: []publicationVersion{{Number: 1}, {Number: 2}}})
case r.Method == "DELETE" && r.URL.Path == "/api/v1/desktop/publications/publication/versions/1":
deleted++
w.WriteHeader(http.StatusNoContent)
default:
t.Errorf("unexpected Hub request %s %s", r.Method, r.URL.Path)
}
})
manager.state.AccessToken = "secret"
manager.state.DefaultPublicationID = "publication"
manager.previews["pending"] = preparedPublication{Publication: Publication{ID: "publication"}}
handler := manager.Handler()
for _, test := range []struct {
path string
want int
}{
{"versions/", 404},
{"versions/1/extra/?replacement=2", 404},
{"versions/1/", 422},
{"versions/1/?replacement=3", 409},
{"versions/1/?replacement=2", 200},
} {
recorder := httptest.NewRecorder()
handler.ServeHTTP(recorder, httptest.NewRequest("DELETE",
"/akoflow-api/hub/publications/publication/"+test.path, nil))
if recorder.Code != test.want {
t.Errorf("%s status %d, want %d: %s", test.path, recorder.Code, test.want, recorder.Body)
}
}
if deleted != 1 || len(manager.previews) != 0 || manager.state.DefaultPublicationID != "publication" {
t.Fatal("version retirement did not preserve the publication or clear stale previews")
}
manager.options.ReadOnly = true
if err := manager.RetireVersion(context.Background(), "publication", 1, 2); err == nil || deleted != 1 {
t.Fatal("retirement succeeded in read-only mode")
}
}
10 changes: 10 additions & 0 deletions internal/mcpbridge/catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -8962,6 +8962,16 @@
"type": "object"
}
},
{
"name": "hub_retire_workflow_version",
"method": "DELETE",
"path": "/akoflow-api/hub/publications/{publicationId}/versions/{version}/",
"handler": "serveRetireVersion",
"description": "hub retire workflow version. DELETE /akoflow-api/hub/publications/{publicationId}/versions/{version}/. Uses the daemon API and its domain validation.",
"query": [
"replacement"
]
},
{
"name": "hub_review_activity_estimates",
"method": "POST",
Expand Down
1 change: 1 addition & 0 deletions internal/mcpbridge/cataloggen/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func hubToolName(handler string) string {
"serveCreate": "hub_create_publication",
"serveGetPublication": "hub_get_publication",
"serveUpdatePublication": "hub_update_publication",
"serveRetireVersion": "hub_retire_workflow_version",
"serveDeletePublication": "hub_delete_publication",
"serveContributionDestination": "hub_get_contribution_destination",
"serveListVersions": "hub_list_versions",
Expand Down
2 changes: 1 addition & 1 deletion internal/mcpbridge/hub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestHubCatalogContractsAndPermissions(t *testing.T) {
"hub_get_workflow_definition": Read, "inspect_artifact_image": Read,
"hub_update_publication": Write, "hub_import_workflow": Write,
"hub_preview_workflow": Write, "hub_preview_execution": Write, "hub_confirm_publication": Write,
"hub_delete_publication": Admin, "hub_disconnect": Admin, "hub_update_settings": Admin,
"hub_delete_publication": Admin, "hub_retire_workflow_version": Admin, "hub_disconnect": Admin, "hub_update_settings": Admin,
"get_execution_status": Read, "get_execution_logs": Read, "get_execution_events": Read,
"get_execution_artifacts": Read, "get_execution_activity": Read,
}
Expand Down
Loading