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
13 changes: 9 additions & 4 deletions internal/lab/agentstest.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,15 @@ func AgentsTest(cfg *config.Config, email string, opts AgentsTestOptions) error
logCtx, cancelLogs := context.WithTimeout(context.Background(), 60*time.Second)
events, _ := podLogs(logCtx, platformNamespace, "deploy/"+agentManagerMCPServer, agentManagerMCPServer, 5*time.Minute)
cancelLogs()
if !strings.Contains(events, "caller="+user.Email) {
return fmt.Errorf("agent-manager's log carries no `caller=%s` line for the create", user.Email)
claims, err := decodeJWTClaims(token)
if err != nil {
return err
}
issuer, subject := stringAt(claims, "iss"), stringAt(claims, claimSubject)
if !managerLogNamesUser(events, user.Email, issuer, subject) {
return fmt.Errorf("agent-manager's log carries no line naming %s (user.issuer=%s user.subject=%s, or caller=%s) for the create", user.Email, issuer, subject, user.Email)
}
note("HelmRelease managers %q, chartRef OCIRepository/%s, serviceAccountName %q, values.toolset %v, agent.harness %s, skill %s @ %.12s; OCIRepository %s -> %s @ %s (managers %q); agent-manager logged the write with caller=%s",
note("HelmRelease managers %q, chartRef OCIRepository/%s, serviceAccountName %q, values.toolset %v, agent.harness %s, skill %s @ %.12s; OCIRepository %s -> %s @ %s (managers %q); agent-manager logged the write as %s",
release.managers, release.Spec.ChartRef.Name, release.Spec.ServiceAccountName, toolset, kagentHarness, fixture.name(), fixture.Commit, agentChartOCIRepository, chartURL, chartRange, sourceManagers, user.Email)

step("The render: AgentTemplate %s with the display-name and icon-url annotations, Agent %s pairing it with Harness %s, its RemoteMCPServer %s carrying %s", agentsTestAgent, agentsTestAgent, kagentHarness, agentsTestAgent, toolsetHeader)
Expand Down Expand Up @@ -491,7 +496,7 @@ func AgentsTest(cfg *config.Config, email string, opts AgentsTestOptions) error

fmt.Println()
fmt.Printf("PASS: muster aggregates %s* and agent-manager reports identity caller on the agent chart %s (Harness %s)\n", agentManagerToolPrefix, chartLine, kagentHarness)
fmt.Printf("PASS: create_agent without a toolset is refused naming the presets; with [%s] %s created -> Ready on Harness %s -> a turn as the person -> updated -> deleted %s through call_tool, every write requestedBy=%s and logged with caller=\n", agentsTestToolset, user.Email, kagentHarness, agentsTestAgent, user.Email)
fmt.Printf("PASS: create_agent without a toolset is refused naming the presets; with [%s] %s created -> Ready on Harness %s -> a turn as the person -> updated -> deleted %s through call_tool, every write requestedBy=%s and logged as the person\n", agentsTestToolset, user.Email, kagentHarness, agentsTestAgent, user.Email)
fmt.Printf("PASS: the HelmRelease carries the %s field manager, values.toolset [%s], agent.harness %s and the skill %s pinned to a commit next to OCIRepository %s at %s; its render is the AgentTemplate with %s and %s and the skill entry, the Agent referencing Harness %s, and RemoteMCPServer %s carrying %s=%s (%s=%s); delete_agent removes the release and the render\n",
agentManagerFieldManager, agentsTestToolset, kagentHarness, fixture.name(), agentChartOCIRepository, chartLine, displayNameAnnotation, iconURLAnnotation, kagentHarness, agentsTestAgent, toolsetHeader, agentsTestToolset, discoveryLabel, discoveryDisabledValue)
fmt.Printf("PASS: get_agent_status agrees with the Agent's status — ready on revision %.12s, and failed with the reason for an Agent on Harness %q\n", harness.LatestSuccessfulRevision, agentsTestNoHarness)
Expand Down
12 changes: 6 additions & 6 deletions internal/lab/backstagetest_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,15 @@ func portalAgentStatus(ps *portalSession, name, want string, timeout time.Durati
// agentManagerLoggedCaller checks agent-manager's log for a write it attributed
// to the person since the given duration — the identity the muster hop
// forwarded, as the service logs it.
func agentManagerLoggedCaller(email string, since time.Duration) error {
func agentManagerLoggedCaller(email, issuer, subject string, since time.Duration) error {
ctx, cancel := context.WithTimeout(context.Background(), kubeReadTimeout)
defer cancel()
events, err := podLogs(ctx, platformNamespace, "deploy/"+agentManagerMCPServer, agentManagerMCPServer, since+5*time.Second)
if err != nil {
return fmt.Errorf("reading agent-manager's log: %w", err)
}
if !strings.Contains(events, "caller="+email) {
return fmt.Errorf("agent-manager's log carries no `caller=%s` line for the write", email)
if !managerLogNamesUser(events, email, issuer, subject) {
return fmt.Errorf("agent-manager's log carries no line naming %s (user.issuer=%s user.subject=%s, or caller=%s) for the write", email, issuer, subject, email)
}
return nil
}
Expand Down Expand Up @@ -428,7 +428,7 @@ func proveCreatePath(primary, viewer *portalSession) (agentSpec, *agentTemplate,
if !slices.Contains(release.managers, agentManagerFieldManager) {
return fail(fmt.Errorf("HelmRelease %s has no %s field manager: %q", spec.Name, agentManagerFieldManager, release.managers))
}
if err := agentManagerLoggedCaller(email, time.Since(started)); err != nil {
if err := agentManagerLoggedCaller(email, stringAt(primary.claims, "iss"), stringAt(primary.claims, claimSubject), time.Since(started)); err != nil {
return fail(err)
}
template := readiness.template
Expand All @@ -440,9 +440,9 @@ func proveCreatePath(primary, viewer *portalSession) (agentSpec, *agentTemplate,
return fail(fmt.Errorf("AgentTemplate %s carries skill %s as %+v, wanted {git: {%s, %s}, path %s}", spec.Name, skill.Name, rendered, skill.RepoURL, skill.Commit, skill.Path))
}
harness := readiness.agent.Status
note("requestedBy=%s (OCIRepository created: %v); HelmRelease managers %q, serviceAccountName %s, values == the dry run's; OCIRepository %s at %s; agent-manager logged caller=%s; Agent Ready on Harness %s at revision %.12s, AgentTemplate with %s=%q, skill %s @ %.12s; RemoteMCPServer %s carries %s=%s",
note("requestedBy=%s (OCIRepository created: %v); HelmRelease managers %q, serviceAccountName %s, values == the dry run's; OCIRepository %s at %s; agent-manager logged the write as %s; Agent Ready on Harness %s at revision %.12s, AgentTemplate with %s=%q, skill %s @ %.12s; RemoteMCPServer %s carries %s=%s",
written.RequestedBy, written.OCIRepository, release.managers, release.Spec.ServiceAccountName, agentChartOCIRepository, info.Chart.Semver, email, kagentHarness, harness.LatestSuccessfulRevision, displayNameAnnotation, spec.DisplayName, skill.Name, skill.Commit, spec.Name, toolsetHeader, backstageTestToolset)
verdicts = append(verdicts, fmt.Sprintf("PASS: Deploy through the portal (POST /api/muster/call %screate_agent as %s) lands HelmRelease %s with exactly the dry run's values as %s next to OCIRepository %s at %s (requestedBy=%s, agent-manager logged caller=%s); the render is the AgentTemplate (%s, %s, skill %s @ %.12s), the Agent on Harness %s and RemoteMCPServer %s with %s=%s, Ready in %s",
verdicts = append(verdicts, fmt.Sprintf("PASS: Deploy through the portal (POST /api/muster/call %screate_agent as %s) lands HelmRelease %s with exactly the dry run's values as %s next to OCIRepository %s at %s (requestedBy=%s, agent-manager logged the write as %s); the render is the AgentTemplate (%s, %s, skill %s @ %.12s), the Agent on Harness %s and RemoteMCPServer %s with %s=%s, Ready in %s",
agentManagerToolPrefix, email, spec.Name, kagentFluxServiceAccount, agentChartOCIRepository, info.Chart.Semver, written.RequestedBy, email, displayNameAnnotation, iconURLAnnotation, skill.Name, skill.Commit, kagentHarness, spec.Name, toolsetHeader, backstageTestToolset, time.Since(started).Round(time.Second)))

step("The detail page's poll: %sget_agent_status through the portal says ready on Harness %s", agentManagerToolPrefix, kagentHarness)
Expand Down
24 changes: 12 additions & 12 deletions internal/lab/backstagetest_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
// modelManagerToolPrefix is the aggregated prefix of model-manager's tools.
const modelManagerToolPrefix = "x_" + modelManagerMCPServer + "_"

// model-manager's log messages for a load and an unload; each line carries
// caller=<email> for a call made as a person.
// model-manager's log messages for a load and an unload; each line names the
// person of a call made as a person (managerLoggedUser).
const (
modelManagerLoggedLoad = `msg="model loaded"`
modelManagerLoggedUnload = `msg="model unloaded"`
Expand Down Expand Up @@ -115,11 +115,11 @@ func proveModelsPage(cfg *config.Config, primary, viewer *portalSession) ([]stri
if err := musterAttributes(started, email, subject, len(order)); err != nil {
return verdicts, err
}
if err := modelManagerLoggedWrites(started, email, model.Name); err != nil {
if err := modelManagerLoggedWrites(started, email, stringAt(primary.claims, "iss"), subject, model.Name); err != nil {
return verdicts, err
}
note("muster attributes the calls to %s; model-manager logged the load and the unload with caller=%s", email, email)
verdicts = append(verdicts, fmt.Sprintf("PASS: the Models page's write (POST /api/muster/call %s of %s on %s as %s) answers, attributed at muster and in model-manager's log (caller=%s); the model is left %s",
note("muster attributes the calls to %s; model-manager logged the load and the unload as %s", email, email)
verdicts = append(verdicts, fmt.Sprintf("PASS: the Models page's write (POST /api/muster/call %s of %s on %s as %s) answers, attributed at muster and in model-manager's log (as %s); the model is left %s",
strings.Join(order, " + "), model.Name, backend, email, email, loadedWord(model.Loaded)))

if viewer == nil {
Expand Down Expand Up @@ -217,26 +217,26 @@ func musterAttributes(since time.Time, email, subject string, n int) error {

// modelManagerLoggedWrites checks model-manager's log for the load and the
// unload of the model attributed to the person since the instant.
func modelManagerLoggedWrites(since time.Time, email, model string) error {
func modelManagerLoggedWrites(since time.Time, email, issuer, subject, model string) error {
ctx, cancel := context.WithTimeout(context.Background(), kubeReadTimeout)
defer cancel()
logs, err := podLogs(ctx, platformNamespace, "deploy/"+modelManagerMCPServer, modelManagerMCPServer, time.Since(since)+5*time.Second)
if err != nil {
return fmt.Errorf("reading model-manager's log: %w", err)
}
for _, msg := range []string{modelManagerLoggedLoad, modelManagerLoggedUnload} {
if !loggedFor(logs, msg, model, email) {
return fmt.Errorf("model-manager's log carries no `%s model=%s … caller=%s` line", msg, model, email)
if !loggedFor(logs, msg, model, email, issuer, subject) {
return fmt.Errorf("model-manager's log carries no `%s model=%s` line naming %s (user.issuer=%s user.subject=%s, or caller=%s)", msg, model, email, issuer, subject, email)
}
}
return nil
}

// loggedFor reports whether a line of a text-format log carries the message,
// the model and the caller.
func loggedFor(logs, msg, model, email string) bool {
for _, line := range strings.Split(logs, "\n") {
if strings.Contains(line, msg) && strings.Contains(line, " model="+model+" ") && strings.Contains(line, " caller="+email) {
// the model and the person.
func loggedFor(logs, msg, model, email, issuer, subject string) bool {
for line := range strings.SplitSeq(logs, "\n") {
if strings.Contains(line, msg) && strings.Contains(line, " model="+model+" ") && managerLoggedUser(line, email, issuer, subject) {
return true
}
}
Expand Down
13 changes: 9 additions & 4 deletions internal/lab/backstagetest_models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,27 @@ func TestProofModelOf(t *testing.T) {
}

// TestLoggedFor: model-manager's text log line names the message, the model
// and the caller; another model's or another caller's line does not count.
// and the person, by user.subject or by caller; another model's or another
// person's line does not count.
func TestLoggedFor(t *testing.T) {
logs := strings.Join([]string{
`time=2026-10-02T04:00:00Z level=INFO msg="model loaded" backend=ollama model=smollm2:135m keepAlive="" preset="" node="" caller=admin@lab.local`,
`time=2026-10-02T04:00:01Z level=INFO msg="model unloaded" backend=ollama model=smollm2:135m caller=dev@lab.local`,
`time=2026-10-02T04:00:02Z level=INFO msg="model loaded" backend=ollama model=smollm2:135m-x caller=viewer@lab.local`,
`time=2026-10-02T04:00:03Z level=INFO msg="model unloaded" backend=ollama model=smollm2:135m user.issuer=https://dex.lab user.subject=sub-viewer`,
}, "\n")
if !loggedFor(logs, modelManagerLoggedLoad, "smollm2:135m", testPortalUser) {
if !loggedFor(logs, modelManagerLoggedLoad, "smollm2:135m", testPortalUser, "https://dex.lab", "sub-admin") {
t.Error("the admin's load is not found")
}
if loggedFor(logs, modelManagerLoggedUnload, "smollm2:135m", testPortalUser) {
if loggedFor(logs, modelManagerLoggedUnload, "smollm2:135m", testPortalUser, "https://dex.lab", "sub-admin") {
t.Error("another caller's unload counted")
}
if loggedFor(logs, modelManagerLoggedLoad, "smollm2:135m", testPortalViewer) {
if loggedFor(logs, modelManagerLoggedLoad, "smollm2:135m", testPortalViewer, "https://dex.lab", "sub-viewer") {
t.Error("another model's load counted")
}
if !loggedFor(logs, modelManagerLoggedUnload, "smollm2:135m", testPortalViewer, "https://dex.lab", "sub-viewer") {
t.Error("the viewer's unload, logged by user.subject, is not found")
}
}

// TestWriteTools: both tools named in full, the model left as found.
Expand Down
25 changes: 25 additions & 0 deletions internal/lab/managerlog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package lab

import "strings"

// managerLoggedUser matches the issuer and subject together. The caller
// field identifies the person only when structured identity is absent.
func managerLoggedUser(line, email, issuer, subject string) bool {
fields := logfmtFields(line)
_, hasIssuer := fields["user.issuer"]
_, hasSubject := fields["user.subject"]
if hasIssuer || hasSubject {
return issuer != "" && subject != "" && fields["user.issuer"] == issuer && fields["user.subject"] == subject
}
return email != "" && fields["caller"] == email
}

// managerLogNamesUser reports whether any line of the log names the person.
func managerLogNamesUser(logs, email, issuer, subject string) bool {
for line := range strings.SplitSeq(logs, "\n") {
if managerLoggedUser(line, email, issuer, subject) {
return true
}
}
return false
}
35 changes: 35 additions & 0 deletions internal/lab/managerlog_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package lab

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestManagerLoggedUser(t *testing.T) {
const email, subject = "admin@lab.local", "CiQwOGE4Njg0Yi1kYjg4LTRiNzMtOTBhOS0zY2QxNjYxZjU0NjYSBWxvY2Fs"
const issuer = "https://dex.lab"
for _, tc := range []struct {
name string
line string
want bool
}{
{"user subject", `level=INFO msg="agent created" user.issuer=https://dex.lab user.subject=` + subject + ` namespace=a`, true},
{"quoted identity", `level=INFO msg="agent created" user.issuer="https://dex.lab" user.subject="` + subject + `"`, true},
{"caller email", `level=INFO msg="agent created" caller=` + email + ` namespace=a`, true},
{"another subject", `level=INFO msg="agent created" user.subject=other`, false},
{"subject prefix only", `level=INFO msg="agent created" user.subject=` + subject[:10], false},
{"longer subject", `level=INFO msg="agent created" user.subject=` + subject + `x`, false},
{"another issuer", `level=INFO msg="agent created" user.issuer=https://other.lab user.subject=` + subject, false},
{"missing issuer", `level=INFO msg="agent created" user.subject=` + subject, false},
{"missing subject", `level=INFO msg="agent created" user.issuer=https://dex.lab`, false},
{"contradictory caller", `level=INFO msg="agent created" user.issuer=https://other.lab user.subject=` + subject + ` caller=` + email, false},
{"identity in message", `level=INFO msg="user.issuer=https://dex.lab user.subject=` + subject + `"`, false},
{"caller prefix", `level=INFO msg="agent created" caller=` + email + `.other`, false},
{"no user", `level=INFO msg="agent created" namespace=a`, false},
} {
t.Run(tc.name, func(t *testing.T) {
require.Equal(t, tc.want, managerLoggedUser(tc.line, email, issuer, subject))
})
}
}
Loading