From b1eec6050bd4c6672bf8289b48e075759d4bfa1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=83=E5=B7=9D=E7=99=BD=E6=B5=AA?= <1679659@qq.com> Date: Tue, 1 Dec 2026 03:05:54 -0700 Subject: [PATCH] fix(runtime): keep capabilities of manifests without the field Packages published before manifest.json carried "capabilities" (up to runtime-3731afd-p4) lost every capability once inference was removed, so Win10 hosts got kernel-irqchip=off and rule hooks saw no runtime caps. When a built-in reims-vgpu manifest has no "capabilities" key, declare the patch-derived set at load time with the same mapping as pack-runtime.ps1. A declared list, including an empty one, still wins; other kinds must declare their own. Co-Authored-By: Claude Opus 5.5 --- internal/runtime/kinds.go | 42 ++++++++++++++++++++++ internal/runtime/manifest_test.go | 59 +++++++++++++++++++++++++++++++ internal/runtime/runtime.go | 13 +++++-- 3 files changed, 112 insertions(+), 2 deletions(-) diff --git a/internal/runtime/kinds.go b/internal/runtime/kinds.go index 40d67d6..7da0b23 100644 --- a/internal/runtime/kinds.go +++ b/internal/runtime/kinds.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "regexp" + "slices" "sort" "strings" "sync" @@ -154,6 +155,47 @@ func (m Manifest) EffectiveCapabilities() []string { return out } +// buggyWin32UnicodeInputPatchSHA256 is the SHA-256 of the initial +// reims-vgpu-win32-unicode-input.patch shipped in runtime-3731afd-p2/p3, which +// duplicated physical keystrokes (issue #14). Packages built with it must not +// get the "win32-unicode-input" capability. +const buggyWin32UnicodeInputPatchSHA256 = "0b34f7c0ebdf3ca537c7f4523af97967a06924aedba7058dbc978870f561b366" + +// legacyCapabilities declares capabilities for built-in packages whose +// manifest.json predates the "capabilities" field. It mirrors the mapping in +// scripts/pack-runtime.ps1 and runs once when the manifest is read, so callers +// only ever see declared capabilities. Other kinds must declare their own. +func legacyCapabilities(m Manifest) []string { + if m.EffectiveKind() != DefaultKind { + return nil + } + var out []string + for _, p := range m.Patches { + low := strings.ToLower(p.Name) + var c string + switch { + case strings.Contains(low, "nested-virt-nonfatal"): + c = "nested-virt-nonfatal" + case strings.Contains(low, "startup-ipis"): + c = "win10-startup-ipis" + case strings.Contains(low, "win10-compat"): + c = "win10-compat" + case strings.Contains(low, "coroutine-fiber"): + c = "win32-coroutine-fiber" + case strings.Contains(low, "win32-unicode-input"): + if sha := strings.TrimSpace(p.SHA256); sha != "" && !strings.EqualFold(sha, buggyWin32UnicodeInputPatchSHA256) { + c = "win32-unicode-input" + } + case strings.Contains(low, "display-fixed-mode"): + c = "display-fixed-mode" + } + if c != "" && !slices.Contains(out, c) { + out = append(out, c) + } + } + return out +} + // HasCapability reports whether manifest.json declares capability capName. func (m Manifest) HasCapability(capName string) bool { for _, c := range m.EffectiveCapabilities() { diff --git a/internal/runtime/manifest_test.go b/internal/runtime/manifest_test.go index 85219f0..d56d32d 100644 --- a/internal/runtime/manifest_test.go +++ b/internal/runtime/manifest_test.go @@ -3,6 +3,7 @@ package runtime import ( "os" "path/filepath" + "slices" "testing" ) @@ -17,3 +18,61 @@ func TestManifestAcceptsWholeNumberFloats(t *testing.T) { t.Fatalf("manifest = %+v", m) } } + +// Packages published before manifest.json carried "capabilities" (up to +// runtime-3731afd-p4) must keep the capabilities their patches provide. +func TestManifestWithoutCapabilitiesKeepsLegacyCapabilities(t *testing.T) { + const fixedSHA = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + for _, tc := range []struct { + name, body string + want []string + }{ + { + name: "published-p3", + body: `{"commit":"3731afd-p3","patches":[` + + `{"name":"reims-vgpu-win32-unicode-input.patch","sha256":"` + buggyWin32UnicodeInputPatchSHA256 + `"},` + + `{"name":"qemu-whpx-win10-compat.patch","sha256":"x"},` + + `{"name":"qemu-whpx-win10-startup-ipis.patch","sha256":"x"},` + + `{"name":"qemu-whpx-nested-virt-nonfatal.patch","sha256":"x"},` + + `{"name":"qemu-win32-coroutine-fiber-commit.patch","sha256":"x"}]}`, + want: []string{"win10-compat", "win10-startup-ipis", "nested-virt-nonfatal", "win32-coroutine-fiber"}, + }, + { + name: "fixed-unicode-input-and-fixed-mode", + body: `{"commit":"c","patches":[{"name":"reims-vgpu-win32-unicode-input.patch","sha256":"` + fixedSHA + `"},` + + `{"name":"reims-vgpu-display-fixed-mode.patch","sha256":"x"}]}`, + want: []string{"win32-unicode-input", "display-fixed-mode"}, + }, + { + name: "unicode-input-without-hash", + body: `{"commit":"c","patches":[{"name":"reims-vgpu-win32-unicode-input.patch"}]}`, + }, + { + name: "declared-empty-wins", + body: `{"commit":"c","capabilities":[],"patches":[{"name":"qemu-whpx-nested-virt-nonfatal.patch"}]}`, + }, + { + name: "declared-list-wins", + body: `{"commit":"c","capabilities":["display-fixed-mode"],"patches":[{"name":"qemu-whpx-nested-virt-nonfatal.patch"}]}`, + want: []string{"display-fixed-mode"}, + }, + { + name: "other-kind-must-declare", + body: `{"commit":"c","kind":"qemu-ovmf","patches":[{"name":"qemu-whpx-nested-virt-nonfatal.patch"}]}`, + }, + } { + t.Run(tc.name, func(t *testing.T) { + p := filepath.Join(t.TempDir(), "manifest.json") + if err := os.WriteFile(p, []byte(tc.body), 0o644); err != nil { + t.Fatal(err) + } + m, err := readManifest(p) + if err != nil { + t.Fatal(err) + } + if got := m.EffectiveCapabilities(); !slices.Equal(got, tc.want) { + t.Fatalf("capabilities = %v, want %v", got, tc.want) + } + }) + } +} diff --git a/internal/runtime/runtime.go b/internal/runtime/runtime.go index 5968957..dfcd993 100644 --- a/internal/runtime/runtime.go +++ b/internal/runtime/runtime.go @@ -451,8 +451,17 @@ func readManifest(path string) (Manifest, error) { } // Strip UTF-8 BOM if written by Windows PowerShell Set-Content -Encoding utf8. raw = []byte(strings.TrimPrefix(string(raw), "\uFEFF")) - err = json.Unmarshal(raw, &m) - return m, err + if err = json.Unmarshal(raw, &m); err != nil { + return m, err + } + var keys map[string]json.RawMessage + if err = json.Unmarshal(raw, &keys); err != nil { + return m, err + } + if _, declared := keys["capabilities"]; !declared { + m.Capabilities = legacyCapabilities(m) + } + return m, nil } func findBundleRoot(dir string) (string, error) {