40 lines
1.5 KiB
Go
40 lines
1.5 KiB
Go
package agent_execution_test
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"git.cin.su/m/Assistant/contracts/work"
|
|
workdomain "git.cin.su/m/Assistant/modules/work/domain"
|
|
)
|
|
|
|
func TestBuildDryRunDispatchProducesDeterministicCallbacks(t *testing.T) {
|
|
now := time.UnixMilli(1_700_000_000_000)
|
|
intent := work.AgentDispatchIntent{
|
|
DispatchID: "dispatch-1", IdempotencyKey: "idem-1", DelegationID: "delegation-1", RunID: "run-1",
|
|
ImplementationID: "fake-worker", ImplementationRevision: 1, SourceRevision: "source-1",
|
|
WorktreeID: "worktree-1", VerificationPlanRef: "verify-1", CreatedAtUnixMillis: now.UnixMilli(),
|
|
}
|
|
first, err := workdomain.BuildDryRunDispatch(intent, "worker-1", 7, now, 15*time.Minute)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
second, err := workdomain.BuildDryRunDispatch(intent, "worker-1", 7, now, 15*time.Minute)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if first.CallbackCount() != 2 || first.Lease != second.Lease || first.Callbacks[0] != second.Callbacks[0] || first.Callbacks[1] != second.Callbacks[1] {
|
|
t.Fatal("dry-run dispatch is not deterministic")
|
|
}
|
|
if first.Callbacks[1].Sequence != 2 || !first.LastObservedAt().Before(first.Lease.ExpiresAt) {
|
|
t.Fatal("callback sequence or lease window is invalid")
|
|
}
|
|
}
|
|
|
|
func TestBuildDryRunDispatchRejectsInvalidIntent(t *testing.T) {
|
|
_, err := workdomain.BuildDryRunDispatch(work.AgentDispatchIntent{}, "worker-1", 1, time.UnixMilli(1_700_000_000_000), time.Minute)
|
|
if err != workdomain.ErrDryRunDispatchRejected {
|
|
t.Fatalf("expected rejection, got %v", err)
|
|
}
|
|
}
|