Files
Reims-Go/internal/runtime/manifest_test.go
T
Nwflower aacaec535d Merge origin/main into feat/vmref-driver-start
Adapt Intel VM suspend/resume to driver.SuspendDriver and lifecycle.Service, move native VM close confirmation into internal/host, migrate vm-suspend legacy capability detection, drop moved runtime build tooling, and regenerate i18n and Wails bindings.
2026-12-01 03:47:20 -07:00

88 lines
3.2 KiB
Go

package runtime
import (
"os"
"path/filepath"
"slices"
"testing"
)
func TestManifestAcceptsWholeNumberFloats(t *testing.T) {
p := filepath.Join(t.TempDir(), "manifest.json")
os.WriteFile(p, []byte("\ufeff"+`{"schema_version":2,"commit":"3731afd","raw_bytes":962466926.0,"patches":[{"name":"a.patch","target":"vendor/qemu","sha256":"ab"}],"channel":"candidate"}`), 0o644)
m, err := readManifest(p)
if err != nil {
t.Fatal(err)
}
if m.RawBytes != 962466926 || m.Channel != "candidate" || len(m.Patches) != 1 {
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"}]}`,
},
{
name: "partial-suspend-patches",
body: `{"commit":"c","patches":[{"name":"qemu-win32-mapped-ram-io.patch"},{"name":"qemu-intel-whpx-suspend.patch"}]}`,
},
{
name: "all-suspend-patches",
body: `{"commit":"c","patches":[{"name":"qemu-win32-mapped-ram-io.patch"},{"name":"qemu-intel-whpx-suspend.patch"},{"name":"reims-vgpu-snapshot-replay.patch"}]}`,
want: []string{"vm-suspend"},
},
} {
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)
}
})
}
}