fix(ui): show the PyPI release version in every version display

This commit is contained in:
2026-11-23 03:18:42 +00:00
parent f65c0cc1f3
commit bde9eebf3d
9 changed files with 195 additions and 21 deletions
+12 -4
View File
@@ -313,12 +313,12 @@ func (m *Manager) getOrFetch(ctx context.Context, registry, name, version string
// underlying transport is non-blocking. Only emitted on
// the cache-hit path — the miss-then-fetch path is
// covered by EventPackageCached emitted from store().
m.emit(string(websocket.EventPackageDownloaded), map[string]interface{}{
m.emit(string(websocket.EventPackageDownloaded), withReleaseVersion(map[string]interface{}{
"registry": registry,
"name": name,
"version": version,
"cache_hit": true,
})
}, pkg.ReleaseVersion))
// Data is intentionally nil; Get() opens a fresh reader per caller.
return &CacheEntry{
@@ -602,13 +602,13 @@ func (m *Manager) store(ctx context.Context, registry, name, version, releaseVer
scanStatus = "pending"
}
}
m.emit(string(websocket.EventPackageCached), map[string]interface{}{
m.emit(string(websocket.EventPackageCached), withReleaseVersion(map[string]interface{}{
"registry": registry,
"name": name,
"version": version,
"size": size,
"scan_status": scanStatus,
})
}, releaseVersion))
// Scan package if scanner is enabled (run in background to not block cache operations)
// Skip scanning metadata entries (index pages, lists, etc.)
@@ -853,3 +853,11 @@ func (m *Manager) Close() error {
return err
}
// withReleaseVersion adds release_version to an event payload when the cache key is not a release version.
func withReleaseVersion(payload map[string]interface{}, releaseVersion string) map[string]interface{} {
if releaseVersion != "" {
payload["release_version"] = releaseVersion
}
return payload
}
+13
View File
@@ -0,0 +1,13 @@
package cache
import "testing"
func TestWithReleaseVersion(t *testing.T) {
with := withReleaseVersion(map[string]interface{}{"version": "six-1.17.0.tar.gz"}, "1.17.0")
if with["release_version"] != "1.17.0" || with["version"] != "six-1.17.0.tar.gz" {
t.Errorf("payload = %v", with)
}
if _, ok := withReleaseVersion(map[string]interface{}{"version": "1.3.0"}, "")["release_version"]; ok {
t.Error("empty release version must not be sent")
}
}