Harden timebox validation and test ForRuntime
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -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{
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user