diff --git a/internal/domain/domain.go b/internal/domain/domain.go index 92779da..48f3b1d 100644 --- a/internal/domain/domain.go +++ b/internal/domain/domain.go @@ -99,7 +99,7 @@ func NewManual(nextAction, successCondition string, timebox time.Duration) (Comm if successCondition == "" { return Commitment{}, ErrMissingSuccessCondition } - if timebox <= 0 { + if timebox < time.Second { return Commitment{}, ErrMissingTimebox } return Commitment{ diff --git a/internal/domain/domain_test.go b/internal/domain/domain_test.go index e016fd0..77db2b4 100644 --- a/internal/domain/domain_test.go +++ b/internal/domain/domain_test.go @@ -53,6 +53,32 @@ func TestNewManualPopulatesDraftCommitment(t *testing.T) { } } +func TestNewManualRejectsSubSecondTimebox(t *testing.T) { + _, err := NewManual("Refactor state", "tests pass", 500*time.Millisecond) + if err != ErrMissingTimebox { + t.Fatalf("want ErrMissingTimebox, got %v", err) + } +} + +func TestForRuntimePopulatesPolicySnapshot(t *testing.T) { + p := ForRuntime("commitment-123", RuntimeActive, EnforcementObserve) + if !strings.HasPrefix(p.ID, "policy-") { + t.Errorf("id should be prefixed, got %s", p.ID) + } + if p.CommitmentID != "commitment-123" { + t.Errorf("commitment id wrong: %s", p.CommitmentID) + } + if p.SchemaVersion != PolicySchemaVersion { + t.Errorf("schema version wrong: %d", p.SchemaVersion) + } + if p.RuntimeState != RuntimeActive { + t.Errorf("runtime state wrong: %s", p.RuntimeState) + } + if p.EnforcementLevel != EnforcementObserve { + t.Errorf("enforcement level wrong: %s", p.EnforcementLevel) + } +} + func TestCommitmentSerializesSnakeCaseEnums(t *testing.T) { c, _ := NewManual("Port domain", "domain tests pass", 25*time.Minute) data, err := json.Marshal(c)