fix(stambha): report the newest unusable runtime
This commit is contained in:
1 parent
92573ce550
commit
44905aaa17
2 files changed
+62
-5
No files matched your search
@@ -204,17 +204,21 @@ func resolveStambhaRuntime(cfg *config.Config) (rt.Installed, error) {
|
||||
if err != nil {
|
||||
return rt.Installed{}, err
|
||||
}
|
||||
var lastError error
|
||||
var firstError error
|
||||
for _, inst := range list {
|
||||
if err := rt.CheckCompatibility(StambhaRuntimeKind, stambhaAPI, inst); err != nil {
|
||||
lastError = err
|
||||
if firstError == nil {
|
||||
firstError = err
|
||||
}
|
||||
continue
|
||||
}
|
||||
valid := true
|
||||
for _, rel := range StambhaRuntimeFiles() {
|
||||
info, err := os.Stat(filepath.Join(inst.Dir, filepath.FromSlash(rel)))
|
||||
if err != nil || !info.Mode().IsRegular() || info.Size() == 0 {
|
||||
lastError = fmt.Errorf("Stambha runtime %s is missing %s", inst.Commit, rel)
|
||||
if firstError == nil {
|
||||
firstError = fmt.Errorf("Stambha runtime %s is missing %s", inst.Commit, rel)
|
||||
}
|
||||
valid = false
|
||||
break
|
||||
}
|
||||
@@ -223,8 +227,8 @@ func resolveStambhaRuntime(cfg *config.Config) (rt.Installed, error) {
|
||||
return inst, nil
|
||||
}
|
||||
}
|
||||
if lastError != nil {
|
||||
return rt.Installed{}, lastError
|
||||
if firstError != nil {
|
||||
return rt.Installed{}, firstError
|
||||
}
|
||||
return rt.Installed{}, fmt.Errorf("import a Stambha ARM64 runtime before starting this VM: %w", rt.ErrNoActiveRuntime)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package stambhadriver
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
@@ -49,6 +50,58 @@ func TestResolveStambhaRuntimeUsesCompleteCompatiblePackage(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveStambhaRuntimeReportsNewestRejection(t *testing.T) {
|
||||
cfg := config.Config{DataRoot: t.TempDir(), ActiveRuntime: "intel-runtime"}
|
||||
if _, err := resolveStambhaRuntime(&cfg); !errors.Is(err, rt.ErrNoActiveRuntime) {
|
||||
t.Fatalf("empty runtime error = %v, want ErrNoActiveRuntime", err)
|
||||
}
|
||||
|
||||
install := func(commit, api, builtAt string, omit ...string) {
|
||||
t.Helper()
|
||||
dir := filepath.Join(cfg.RuntimesDir(), StambhaRuntimeKind, commit)
|
||||
if err := os.MkdirAll(dir, 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
manifest, err := json.Marshal(rt.Manifest{Commit: commit, Kind: StambhaRuntimeKind, RuntimeAPI: api, BuiltAt: builtAt})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(dir, "manifest.json"), manifest, 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, rel := range StambhaRuntimeFiles() {
|
||||
if slices.Contains(omit, rel) {
|
||||
continue
|
||||
}
|
||||
path := filepath.Join(dir, filepath.FromSlash(rel))
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(path, []byte("fixture"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
install("newest-compatible-missing-efi", stambhaAPI, "2026-12-03T00:00:00Z", stambhaEFIPath)
|
||||
install("older-incompatible", "2.0.0", "2026-12-02T00:00:00Z")
|
||||
|
||||
got, err := resolveStambhaRuntime(&cfg)
|
||||
if err == nil {
|
||||
t.Fatalf("unexpectedly resolved runtime %q", got.Commit)
|
||||
}
|
||||
if errors.Is(err, rt.ErrNoActiveRuntime) {
|
||||
t.Fatalf("error = %v, did not expect ErrNoActiveRuntime when Stambha packages exist", err)
|
||||
}
|
||||
msg := err.Error()
|
||||
if !strings.Contains(msg, "newest-compatible-missing-efi") || !strings.Contains(msg, "firmware/stambha.efi") {
|
||||
t.Fatalf("error = %q, want newest-compatible-missing-efi and firmware/stambha.efi", msg)
|
||||
}
|
||||
if strings.Contains(msg, "older-incompatible") {
|
||||
t.Fatalf("error = %q, must not report older-incompatible", msg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStambhaSocketPathUsesBoundedPerUserFallback(t *testing.T) {
|
||||
volume := filepath.VolumeName(t.TempDir())
|
||||
root := volume + string(os.PathSeparator)
|
||||
|
||||
Reference in new issue
Block a user