Files
kandev/apps/backend/internal/office/models/agent_alias_test.go
T
2026-05-16 20:07:57 +01:00

48 lines
1.6 KiB
Go

package models
import (
"testing"
settingsmodels "github.com/kandev/kandev/internal/agent/settings/models"
)
// TestAgentInstance_AliasIsTransparent verifies that office.AgentInstance is a
// type alias for settingsmodels.AgentProfile after ADR 0005 Wave G — the two
// names refer to the same struct, fields are accessible through either, and
// a *AgentProfile can be passed where a *AgentInstance is expected without
// any conversion.
func TestAgentInstance_AliasIsTransparent(t *testing.T) {
profile := &settingsmodels.AgentProfile{
ID: "p-1",
WorkspaceID: "ws-1",
Name: "alias-check",
Role: AgentRoleCEO,
Status: AgentStatusIdle,
}
// Direct assignment without a cast through a function param: only legal
// because AgentInstance IS settingsmodels.AgentProfile under the alias
// declaration. The compiler accepting this signature is the assertion.
instance := acceptInstance(profile)
if instance.ID != "p-1" {
t.Errorf("alias lost id: %q", instance.ID)
}
if instance.Role != AgentRoleCEO {
t.Errorf("alias lost typed role: %q", instance.Role)
}
if instance.Status != AgentStatusIdle {
t.Errorf("alias lost typed status: %q", instance.Status)
}
// Mutation through the alias is visible on the original pointer.
instance.Name = "renamed"
if profile.Name != "renamed" {
t.Errorf("alias does not share storage: profile.Name=%q", profile.Name)
}
}
// acceptInstance takes the office-named type. It compiles only because
// AgentInstance is a type alias for settingsmodels.AgentProfile.
func acceptInstance(a *AgentInstance) *AgentInstance { return a }