Harden timebox validation and test ForRuntime

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-05-31 11:39:38 -04:00
parent e66fddd29f
commit 0a934bf061
2 changed files with 27 additions and 1 deletions
+1 -1
View File
@@ -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{
+26
View File
@@ -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)