116 lines
5.1 KiB
Go
116 lines
5.1 KiB
Go
package domain
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"git.cin.su/m/Assistant/contracts/capability"
|
|
"git.cin.su/m/Assistant/contracts/work"
|
|
)
|
|
|
|
func TestStartDelegationPreservesCanonicalIntentAndUsesAgentImplementation(t *testing.T) {
|
|
now := time.Unix(170, 0)
|
|
bundle, err := StartDelegation(DelegationRequest{
|
|
Goal: work.Goal{
|
|
ID: "goal-1",
|
|
SourceIntentID: "intent-1",
|
|
SourceUtteranceID: "utterance-1",
|
|
ProjectID: "assistant",
|
|
ProjectDisplayName: "Assistant",
|
|
DesiredOutcome: "fix the human-facing chat wording",
|
|
Constraints: "follow architecture constitution",
|
|
},
|
|
Plan: work.WorkPlan{ID: "plan-1"},
|
|
Candidate: work.PlanCandidate{ID: "candidate-1"},
|
|
Requirement: work.CapabilityRequirement{ID: "requirement-1", CapabilityKind: capability.CapabilityKindModifyCode},
|
|
Implementation: agentImplementation("codex-impl-1", "codex://assistant"),
|
|
ConversationID: "conversation-1",
|
|
OriginalIntentText: "Исправь текст в чате Assistant.",
|
|
ContextSummary: "relevant files: creator-web chat surface",
|
|
ContextRefs: []string{"interaction:intent:intent-1", "situation:project:assistant"},
|
|
VerificationSummary: "run targeted tests and verify reply text",
|
|
DerivedInstruction: "Open the current branch, inspect chat surface, implement minimal wording fix, run tests.",
|
|
StartedAt: now,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("start delegation: %v", err)
|
|
}
|
|
if bundle.Delegation.SelectedImplementationKind != capability.ImplementationAgent {
|
|
t.Fatalf("delegation must keep AGENT implementation kind: %#v", bundle.Delegation)
|
|
}
|
|
if bundle.Delegation.SourceIntentID != "intent-1" || bundle.Delegation.SourceUtteranceID != "utterance-1" {
|
|
t.Fatalf("canonical human refs lost: %#v", bundle.Delegation)
|
|
}
|
|
if bundle.Run.Protocol != work.AgentProtocolCodexBridgeV1 {
|
|
t.Fatalf("expected codex bridge protocol, got %#v", bundle.Run.Protocol)
|
|
}
|
|
if bundle.Run.DerivedInstructionSummary == "" {
|
|
t.Fatalf("derived instruction summary must be present")
|
|
}
|
|
}
|
|
|
|
func TestCheckpointExecutionWindowExhaustionIsNotFailure(t *testing.T) {
|
|
run := work.AgentRun{
|
|
ID: "run-1",
|
|
DelegationID: "delegation-1",
|
|
ImplementationID: "impl-1",
|
|
ImplementationRevision: 1,
|
|
Protocol: work.AgentProtocolCodexBridgeV1,
|
|
State: work.AgentRunRunning,
|
|
StartedAtUnixMillis: 1,
|
|
UpdatedAtUnixMillis: 1,
|
|
}
|
|
updated, checkpoint, err := CheckpointRun(run, work.AgentBlockerExecutionWindow, "inspected files", "apply patch and run tests", "go test pending", "codex/dev-000069", "abc123", "continue with next execution window", []work.EvidenceRef{"artifact:diff:1"}, time.Unix(200, 0))
|
|
if err != nil {
|
|
t.Fatalf("checkpoint: %v", err)
|
|
}
|
|
if updated.State != work.AgentRunExecutionWindowExhausted {
|
|
t.Fatalf("execution window exhaustion must be explicit state, got %#v", updated.State)
|
|
}
|
|
if checkpoint.BlockerClass != work.AgentBlockerExecutionWindow {
|
|
t.Fatalf("checkpoint blocker mismatch: %#v", checkpoint)
|
|
}
|
|
}
|
|
|
|
func TestDifferentFutureAgentStillSatisfiesSameCapabilityContract(t *testing.T) {
|
|
now := time.Unix(170, 0)
|
|
for _, implementation := range []capability.CapabilityImplementation{
|
|
agentImplementation("codex-impl-1", "codex://assistant"),
|
|
agentImplementation("future-impl-1", "research-agent://cluster-a"),
|
|
} {
|
|
bundle, err := StartDelegation(DelegationRequest{
|
|
Goal: work.Goal{ID: "goal-1", SourceIntentID: "intent-1", SourceUtteranceID: "utterance-1", DesiredOutcome: "do the work"},
|
|
Plan: work.WorkPlan{ID: "plan-1"},
|
|
Candidate: work.PlanCandidate{ID: "candidate-1"},
|
|
Requirement: work.CapabilityRequirement{ID: "requirement-1", CapabilityKind: capability.CapabilityKindModifyCode},
|
|
Implementation: implementation,
|
|
OriginalIntentText: "Сделай безопасное изменение.",
|
|
StartedAt: now,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("start delegation for %s: %v", implementation.ID, err)
|
|
}
|
|
if bundle.Delegation.CapabilityKind != capability.CapabilityKindModifyCode {
|
|
t.Fatalf("capability contract changed for %s: %#v", implementation.ID, bundle.Delegation)
|
|
}
|
|
}
|
|
}
|
|
|
|
func agentImplementation(id, target string) capability.CapabilityImplementation {
|
|
return capability.CapabilityImplementation{
|
|
ID: capability.CapabilityImplementationID(id),
|
|
CapabilityID: "modify-code",
|
|
CapabilityKind: capability.CapabilityKindModifyCode,
|
|
OwnerPrincipalID: "domovoy-creator-principal",
|
|
Revision: 1,
|
|
Kind: capability.ImplementationAgent,
|
|
TargetRef: capability.ImplementationTargetRef(target),
|
|
Qualification: capability.QualificationValidated,
|
|
Activation: capability.ActivationCanary,
|
|
Health: capability.HealthAvailable,
|
|
AuthorityPolicyRef: capability.AuthorityPolicyCreatorDirectiveV1,
|
|
DataConstraints: []capability.DataConstraint{capability.DataConstraintLocalOnly, capability.DataConstraintNoCredentialForward},
|
|
ObservedAtUnixMillis: 1,
|
|
}
|
|
}
|