Skip to content

Commit 4618f39

Browse files
committed
fix: validate cached assets and substrate workers
Signed-off-by: Eitan Yarmush <[email protected]>
1 parent 88b236a commit 4618f39

4 files changed

Lines changed: 38 additions & 9 deletions

File tree

‎go/core/internal/service/system/service.go‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,15 +407,16 @@ func actorFromProto(actor *ateapipb.Actor) SubstrateActor {
407407
}
408408

409409
func workerFromProto(worker *ateapipb.Worker) SubstrateWorker {
410+
assignment := worker.GetStatus().GetAssignment()
410411
return SubstrateWorker{
411412
WorkerNamespace: worker.GetWorkerNamespace(),
412413
WorkerPool: worker.GetWorkerPool(),
413414
WorkerPod: worker.GetWorkerPod(),
414-
ActorNamespace: worker.GetAssignment().GetActorTemplate().GetNamespace(),
415-
ActorTemplate: worker.GetAssignment().GetActorTemplate().GetName(),
416-
ActorID: worker.GetAssignment().GetActor().GetName(),
415+
ActorNamespace: assignment.GetActorTemplate().GetNamespace(),
416+
ActorTemplate: assignment.GetActorTemplate().GetName(),
417+
ActorID: assignment.GetActor().GetName(),
417418
IP: worker.GetIp(),
418-
Version: worker.GetVersion(),
419+
Version: worker.GetMetadata().GetVersion(),
419420
}
420421
}
421422

‎go/core/internal/service/system/service_test.go‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,14 @@ func TestGetSubstrateStatus(t *testing.T) {
142142
ActorTemplateName: "template",
143143
}},
144144
workers: []*ateapipb.Worker{{
145+
Metadata: &ateapipb.ResourceMetadata{Version: 3},
145146
WorkerNamespace: "team",
146147
WorkerPool: "pool",
147148
WorkerPod: "worker-0",
149+
Status: &ateapipb.WorkerStatus{Assignment: &ateapipb.ActorAssignment{
150+
ActorTemplate: &ateapipb.KubeNamespacedObjectRef{Namespace: "team", Name: "template"},
151+
Actor: &ateapipb.ObjectRef{Name: "actor-1"},
152+
}},
148153
}},
149154
}
150155
service := system.NewService(system.WithInventory(kubeClient, nil, &authimpl.NoopAuthorizer{}, ateClient))
@@ -159,6 +164,9 @@ func TestGetSubstrateStatus(t *testing.T) {
159164
require.Len(t, result.Actors, 1)
160165
assert.Equal(t, "Running", result.Actors[0].Status)
161166
require.Len(t, result.Workers, 1)
167+
assert.Equal(t, "template", result.Workers[0].ActorTemplate)
168+
assert.Equal(t, "actor-1", result.Workers[0].ActorID)
169+
assert.Equal(t, int64(3), result.Workers[0].Version)
162170
})
163171

164172
t.Run("validates and authorizes", func(t *testing.T) {

‎go/core/v2/agentplugins/materialize.go‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func Materialize(ctx context.Context, config adk.AgentPluginConfig, paths Paths)
5656
var result MCPConfig
5757
for i, skill := range config.Skills {
5858
root := filepath.Join(paths.Plugins, fmt.Sprintf("standalone-%d", i))
59-
sourceRoot, err := fetchSource(ctx, skill.Source, root)
59+
sourceRoot, err := fetchSource(ctx, skill.Source, root, "SKILL.md")
6060
if err != nil {
6161
return MCPConfig{}, fmt.Errorf("materialize skill %q: %w", skill.Name, err)
6262
}
@@ -68,7 +68,7 @@ func Materialize(ctx context.Context, config adk.AgentPluginConfig, paths Paths)
6868
pluginNames := make(map[string]struct{})
6969
for i, plugin := range config.Plugins {
7070
root := filepath.Join(paths.Plugins, fmt.Sprintf("plugin-%d", i))
71-
pluginRoot, err := fetchSource(ctx, plugin.Source, root)
71+
pluginRoot, err := fetchSource(ctx, plugin.Source, root, "plugin.json")
7272
if err != nil {
7373
return MCPConfig{}, fmt.Errorf("materialize plugin %d: %w", i, err)
7474
}
@@ -94,7 +94,7 @@ func Materialize(ctx context.Context, config adk.AgentPluginConfig, paths Paths)
9494
return result, nil
9595
}
9696

97-
func fetchSource(ctx context.Context, source adk.AgentPluginSource, destination string) (string, error) {
97+
func fetchSource(ctx context.Context, source adk.AgentPluginSource, destination, requiredFile string) (string, error) {
9898
selected := 0
9999
if source.OCI != "" {
100100
selected++
@@ -112,7 +112,16 @@ func fetchSource(ctx context.Context, source adk.AgentPluginSource, destination
112112
if err := validatePackage(destination); err != nil {
113113
return "", err
114114
}
115-
return containedPath(destination, source.Path)
115+
root, err := containedPath(destination, source.Path)
116+
if err == nil {
117+
if info, err := os.Stat(filepath.Join(root, requiredFile)); err == nil && info.Mode().IsRegular() {
118+
return root, nil
119+
} else if err != nil && !os.IsNotExist(err) {
120+
return "", err
121+
}
122+
} else if !os.IsNotExist(err) {
123+
return "", err
124+
}
116125
} else if !os.IsNotExist(err) {
117126
return "", err
118127
}

‎go/core/v2/agentplugins/materialize_test.go‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func TestFetchSourceReusesExistingMaterialization(t *testing.T) {
6666

6767
root, err := fetchSource(context.Background(), adk.AgentPluginSource{Git: &adk.AgentPluginGit{
6868
URL: "does-not-exist", Commit: strings.Repeat("a", 40),
69-
}}, destination)
69+
}}, destination, "SKILL.md")
7070
if err != nil {
7171
t.Fatalf("fetchSource() redownloaded existing materialization: %v", err)
7272
}
@@ -75,6 +75,17 @@ func TestFetchSourceReusesExistingMaterialization(t *testing.T) {
7575
}
7676
}
7777

78+
func TestFetchSourceDoesNotReuseIncompleteMaterialization(t *testing.T) {
79+
destination := t.TempDir()
80+
81+
_, err := fetchSource(context.Background(), adk.AgentPluginSource{Git: &adk.AgentPluginGit{
82+
URL: "does-not-exist", Commit: strings.Repeat("a", 40),
83+
}}, destination, "SKILL.md")
84+
if err == nil {
85+
t.Fatal("fetchSource() reused incomplete materialization")
86+
}
87+
}
88+
7889
func TestLoadManifestUsesAgentPluginsV1Schema(t *testing.T) {
7990
root := t.TempDir()
8091
raw := `{

0 commit comments

Comments
 (0)