Fix generated Run component identity

This commit is contained in:
npc0-hue
2026-08-29 12:38:34 +08:00
parent ac14f80306
commit 34e240dc56
8 changed files with 187 additions and 16 deletions
+49
View File
@@ -2,6 +2,7 @@ package runtime
import (
"context"
"encoding/base64"
"encoding/json"
"errors"
"os"
@@ -14,6 +15,54 @@ import (
"browser.local/run/protocol"
)
func TestMaterializeWorkspaceSeedUsesLifecycleProfileWhenRunComponentKeyIsEmpty(t *testing.T) {
cfg := workerTestConfig(t)
cfg.ServerInstanceID = "server-worker"
cfg.PluginID = "game.scum"
cfg.ComponentKind = "run"
cfg.ComponentKey = ""
plan := protocol.RunAutonomousLifecyclePlan{
SchemaVersion: "1",
ServerInstanceID: cfg.ServerInstanceID,
PluginID: "game.scum",
PluginVersion: "1.0.0",
RunEndpointID: cfg.RunEndpointID,
ProfileKey: "run-local",
TargetOS: runtime.GOOS,
TargetArch: runtime.GOARCH,
TargetRelease: "run-dist-test",
Bootstrap: &protocol.RunAutonomousLifecycleAction{Action: "start", Operation: "start", Capability: protocol.RunCapabilityProcessStart, TargetKey: "actions/start.json"},
}
planPayload, err := json.Marshal(plan)
if err != nil {
t.Fatalf("marshal plan: %v", err)
}
seedPayload, err := json.Marshal([]workspaceSeedFile{
{Path: "actions/start.json", Content: `{"version":1,"action":"start","mode":"supervised","executableKey":"bin/game-server"}`, Mode: 0o600},
{Path: "bin/game-server", Content: "plugin-owned executable", Mode: 0o700},
{Path: autonomousLifecyclePlanKey, Content: string(planPayload), Mode: 0o600},
})
if err != nil {
t.Fatalf("marshal seed: %v", err)
}
cfg.WorkspaceSeed = base64.StdEncoding.EncodeToString(seedPayload)
if err := MaterializeWorkspaceSeed(cfg); err != nil {
t.Fatalf("materialize workspace seed: %v", err)
}
profileScope, err := NewWorkspaceResolver(cfg.WorkspaceRoot).Scope(cfg.ServerInstanceID, "run-local")
if err != nil {
t.Fatalf("resolve profile scope: %v", err)
}
if _, err := os.Stat(filepath.Join(profileScope, autonomousLifecyclePlanKey)); err != nil {
t.Fatalf("expected lifecycle plan under profile scope: %v", err)
}
loaded, scope, ok, err := LoadAutonomousLifecyclePlan(cfg)
if err != nil || !ok || loaded.ProfileKey != "run-local" || scope != profileScope {
t.Fatalf("expected lifecycle plan to load from profile scope, ok=%t scope=%q plan=%+v err=%v", ok, scope, loaded, err)
}
}
func TestWorkerRunsAutonomousBootstrapFromSeededPlan(t *testing.T) {
client := newFakeWorkerClient()
cfg := workerTestConfig(t)