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
+58 -1
View File
@@ -51,7 +51,7 @@ func MaterializeWorkspaceSeed(cfg config.Config) error {
log.Printf("RUN phase=workspace_seed status=failed reason=missing_server workspace=%s", safeOptional(cfg.WorkspaceRoot))
return fmt.Errorf("workspace seed requires a server instance id")
}
scope, err := seededWorkspaceScope(cfg)
scope, err := seededWorkspaceScopeForFiles(cfg, files)
if err != nil {
log.Printf("RUN phase=workspace_seed status=scope_failed workspace=%s server=%s componentKey=%s error=%s", safeOptional(cfg.WorkspaceRoot), safeOptional(cfg.ServerInstanceID), safeOptional(cfg.ComponentKey), RedactText(err.Error()))
return err
@@ -71,12 +71,69 @@ func MaterializeWorkspaceSeed(cfg config.Config) error {
}
func seededWorkspaceScope(cfg config.Config) (string, error) {
return seededWorkspaceScopeForFiles(cfg, nil)
}
func seededWorkspaceScopeForFiles(cfg config.Config, files []workspaceSeedFile) (string, error) {
if strings.TrimSpace(cfg.ComponentKey) != "" {
return NewWorkspaceResolver(cfg.WorkspaceRoot).Scope(cfg.ServerInstanceID, cfg.ComponentKey)
}
profileKey, err := workspaceSeedProfileKey(cfg, files)
if err != nil {
return "", err
}
if profileKey != "" {
return NewWorkspaceResolver(cfg.WorkspaceRoot).Scope(cfg.ServerInstanceID, profileKey)
}
return scopedServerWorkspace(cfg.WorkspaceRoot, cfg.ServerInstanceID)
}
func workspaceSeedProfileKey(cfg config.Config, files []workspaceSeedFile) (string, error) {
var err error
if len(files) == 0 && strings.TrimSpace(cfg.WorkspaceSeed) != "" {
files, err = decodeWorkspaceSeedFiles(cfg.WorkspaceSeed)
if err != nil {
return "", err
}
}
for _, file := range files {
if filepath.ToSlash(strings.TrimSpace(file.Path)) != autonomousLifecyclePlanKey {
continue
}
body, err := workspaceSeedFileContent(file)
if err != nil {
return "", err
}
var plan struct {
ProfileKey string `json:"profileKey,omitempty"`
}
if err := json.Unmarshal(body, &plan); err != nil {
return "", fmt.Errorf("decode workspace seed lifecycle profile: %w", err)
}
profileKey := strings.TrimSpace(plan.ProfileKey)
if profileKey == "" {
return "", nil
}
if !protocol.ValidLogicalFileKey(profileKey) {
return "", fmt.Errorf("workspace seed lifecycle profile is unsafe")
}
return profileKey, nil
}
return "", nil
}
func decodeWorkspaceSeedFiles(encoded string) ([]workspaceSeedFile, error) {
payload, err := base64.StdEncoding.DecodeString(strings.TrimSpace(encoded))
if err != nil {
return nil, fmt.Errorf("decode workspace seed: %w", err)
}
var files []workspaceSeedFile
if err := json.Unmarshal(payload, &files); err != nil {
return nil, fmt.Errorf("decode workspace seed manifest: %w", err)
}
return files, nil
}
func writeWorkspaceSeedFile(scope string, file workspaceSeedFile, index int, total int) (int, error) {
target, err := workspaceSeedTarget(scope, file.Path)
if err != nil {