Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/cli/add_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestNewAddCommand(t *testing.T) {
// Check number flag
numberFlag := flags.Lookup("number")
assert.NotNil(t, numberFlag, "Should have 'number' flag")
assert.Equal(t, "c", numberFlag.Shorthand, "Number flag shorthand should be 'c'")
assert.Equal(t, "", numberFlag.Shorthand, "Number flag should not have shorthand (conflicts with logs -c)")

// Check name flag
nameFlag := flags.Lookup("name")
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/completions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,8 @@ func TestValidEngineNamesConsistency(t *testing.T) {
thirdCall := ValidEngineNames()

// Verify same length across calls
assert.Equal(t, len(firstCall), len(secondCall), "Engine names list length should be consistent")
assert.Equal(t, len(secondCall), len(thirdCall), "Engine names list length should be consistent")
assert.Len(t, secondCall, len(firstCall), "Engine names list length should be consistent")
assert.Len(t, thirdCall, len(secondCall), "Engine names list length should be consistent")

// Verify all expected engines are present in all calls
expectedEngines := []string{"copilot", "claude", "codex", "custom"}
Expand Down
36 changes: 18 additions & 18 deletions pkg/workflow/maintenance_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,27 @@ import (

var maintenanceLog = logger.New("workflow:maintenance_workflow")

// generateMaintenanceCron generates a cron schedule based on the minimum expires value in hours
// generateMaintenanceCron generates a cron schedule based on the minimum expires value in days
// Schedule runs at minimum required frequency to check expirations at appropriate intervals
// Returns cron expression and description.
func generateMaintenanceCron(minExpiresHours int) (string, string) {
func generateMaintenanceCron(minExpiresDays int) (string, string) {
// Use a pseudo-random but deterministic minute (37) to avoid load spikes at :00
minute := 37

// Determine frequency based on minimum expires value (in hours)
// Determine frequency based on minimum expires value (in days)
// Run at least as often as the shortest expiration would need
if minExpiresHours <= 2 {
// For 2 hours or less, run every hour
return fmt.Sprintf("%d * * * *", minute), "Every hour"
} else if minExpiresHours <= 4 {
// For 3-4 hours, run every 2 hours
if minExpiresDays <= 1 {
// For 1 day or less, run every 2 hours
return fmt.Sprintf("%d */2 * * *", minute), "Every 2 hours"
} else if minExpiresHours <= 12 {
// For 5-12 hours, run every 4 hours
return fmt.Sprintf("%d */4 * * *", minute), "Every 4 hours"
} else if minExpiresHours <= 24 {
// For 13-24 hours, run every 6 hours
} else if minExpiresDays == 2 {
// For 2 days, run every 6 hours
return fmt.Sprintf("%d */6 * * *", minute), "Every 6 hours"
} else if minExpiresHours <= 48 {
// For 25-48 hours, run every 12 hours
} else if minExpiresDays <= 4 {
// For 3-4 days, run every 12 hours
return fmt.Sprintf("%d */12 * * *", minute), "Every 12 hours"
}

// For more than 48 hours, run daily
// For more than 4 days, run daily
return fmt.Sprintf("%d %d * * *", minute, 0), "Daily"
}

Expand Down Expand Up @@ -84,8 +78,14 @@ func GenerateMaintenanceWorkflow(workflowDataList []*WorkflowData, workflowDir s

maintenanceLog.Printf("Generating maintenance workflow for expired discussions and issues (minimum expires: %d hours)", minExpires)

// Convert hours to days for cron schedule generation
minExpiresDays := minExpires / 24
if minExpires%24 > 0 {
minExpiresDays++ // Round up partial days
}

// Generate cron schedule based on minimum expires value
cronSchedule, scheduleDesc := generateMaintenanceCron(minExpires)
cronSchedule, scheduleDesc := generateMaintenanceCron(minExpiresDays)
maintenanceLog.Printf("Maintenance schedule: %s (%s)", cronSchedule, scheduleDesc)

// Create the maintenance workflow content using strings.Builder
Expand All @@ -109,7 +109,7 @@ Schedule frequency is automatically determined by the shortest expiration time.`

on:
schedule:
- cron: "` + cronSchedule + `" # ` + scheduleDesc + ` (based on minimum expires: ` + fmt.Sprintf("%d", minExpires) + ` hours)
- cron: "` + cronSchedule + `" # ` + scheduleDesc + ` (based on minimum expires: ` + fmt.Sprintf("%d", minExpiresDays) + ` days)
workflow_dispatch:

permissions: {}
Expand Down
5 changes: 5 additions & 0 deletions pkg/workflow/strict_mode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ engine: copilot
on: push
timeout-minutes: 10
engine: copilot
network:
allowed:
- "api.example.com"
tools:
github: false
---

# Test Workflow`,
Expand Down
27 changes: 9 additions & 18 deletions pkg/workflow/workflow_run_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ on:
workflows: ["build"]
types: [completed]
tools:
github:
allowed: [list_issues]
github: false
---

# Workflow Run Without Branches
Expand All @@ -52,8 +51,7 @@ on:
workflows: ["build"]
types: [completed]
tools:
github:
allowed: [list_issues]
github: false
---

# Workflow Run Without Branches Strict
Expand All @@ -75,8 +73,7 @@ on:
- main
- develop
tools:
github:
allowed: [list_issues]
github: false
---

# Workflow Run With Branches
Expand All @@ -97,8 +94,7 @@ on:
branches:
- main
tools:
github:
allowed: [list_issues]
github: false
---

# Workflow Run With Branches Strict
Expand All @@ -116,8 +112,7 @@ on:
push:
branches: [main]
tools:
github:
allowed: [list_issues]
github: false
---

# Push Workflow
Expand All @@ -138,8 +133,7 @@ on:
workflows: ["build"]
types: [completed]
tools:
github:
allowed: [list_issues]
github: false
---

# Mixed Triggers
Expand All @@ -159,8 +153,7 @@ on:
types: [completed]
branches: []
tools:
github:
allowed: [list_issues]
github: false
---

# Workflow Run With Empty Branches
Expand Down Expand Up @@ -227,8 +220,7 @@ func TestWorkflowRunBranchValidationEdgeCases(t *testing.T) {
frontmatter: `---
on: push
tools:
github:
allowed: [list_issues]
github: false
---

# No On Field
Expand All @@ -245,8 +237,7 @@ on:
workflows: ["build", "test"]
types: [completed]
tools:
github:
allowed: [list_issues]
github: false
---

# Multiple Workflows
Expand Down