Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions pkg/service/provenance_contract_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package service_test

import (
"context"
"slices"
"testing"

"github.com/codefly-dev/core/agents/contract"
agentv0 "github.com/codefly-dev/core/generated/go/codefly/services/agent/v0"
"github.com/codefly-dev/core/resources"

goservice "github.com/codefly-dev/service-go/pkg/service"
)

// TestAdvertisementAdoptsDeploymentCompositionProvenance: the host requires the
// live contract capability before it trusts this agent to judge a deployment's
// dependency edges with the request's composition provenance (core#752). The
// deployment path here is core's DeployKustomize, which does; the
// advertisement must say so, and keep the base contract it extends.
func TestAdvertisementAdoptsDeploymentCompositionProvenance(t *testing.T) {
info, err := goservice.New(&resources.Agent{Kind: "codefly:service", Name: "go"}).GetAgentInformation(context.Background(), &agentv0.AgentInformationRequest{})
if err != nil {
t.Fatalf("GetAgentInformation: %v", err)
}
if !slices.Contains(info.GetContract().GetCapabilities(), contract.DeploymentCompositionProvenance) {
t.Fatalf("contract capabilities %v do not advertise %s", info.GetContract().GetCapabilities(), contract.DeploymentCompositionProvenance)
}
if err := contract.Check(info.GetContract(), contract.ContainerRecoveryScope); err != nil {
t.Fatalf("the base contract is no longer satisfied: %v", err)
}
}
11 changes: 9 additions & 2 deletions pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path/filepath"
"sync"

"github.com/codefly-dev/core/agents/contract"
"github.com/codefly-dev/core/agents/services"
agentv0 "github.com/codefly-dev/core/generated/go/codefly/services/agent/v0"
"github.com/codefly-dev/core/languages"
Expand Down Expand Up @@ -126,7 +127,7 @@ func New(agent *resources.Agent) *Service {
// package boundaries — each specialization's binary embeds and renders
// its own.
func (s *Service) GetAgentInformation(_ context.Context, _ *agentv0.AgentInformationRequest) (*agentv0.AgentInformation, error) {
return services.Advertisement{
advertisement := services.Advertisement{
Backends: runners.BackendSupport{
Local: func() bool { return languages.HasGoRuntime(nil) },
Nix: true,
Expand All @@ -137,7 +138,13 @@ func (s *Service) GetAgentInformation(_ context.Context, _ *agentv0.AgentInforma
ReadMe: "Generic Go service. Specializations add protocols.",
Validation: ValidationCapabilities(),
EffectiveInputsVersions: []uint32{1},
}.Build(), nil
}.Build()
// The deployment path is core's DeployKustomize, which judges dependency
// edges with the request's composition provenance on this core; the host
// requires the live advertisement, not the linked core version.
advertisement.Contract = contract.Current()
advertisement.Contract.Capabilities = append(advertisement.Contract.Capabilities, contract.DeploymentCompositionProvenance)
return advertisement, nil
}

// ValidationCapabilities is the authoritative operation contract inherited by
Expand Down
5 changes: 3 additions & 2 deletions qualification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ func TestSelfBootstrapAdvertisesTheRuntimeContract(t *testing.T) {
}
// Exact, not "contains": a capability gained through a Core bump reaches
// this advertisement whether or not this agent honours it, and every claim
// here is one a host is entitled to act on.
if capabilities := advertisement.GetContract().GetCapabilities(); !slices.Equal(capabilities, []string{contract.ContainerRecoveryScope}) {
// here is one a host is entitled to act on. Composition provenance is
// honoured: Deploy is core's DeployKustomize, which judges with it.
if capabilities := advertisement.GetContract().GetCapabilities(); !slices.Equal(capabilities, []string{contract.ContainerRecoveryScope, contract.DeploymentCompositionProvenance}) {
t.Fatalf("advertised capabilities %v", capabilities)
}
if acknowledgement := headers.Get(recoveryscope.Header); !slices.Equal(acknowledgement, []string{scope + ":" + namespace}) {
Expand Down
Loading