Refactor Structs for Consistency and Enhanced Readability
- Standardized field formatting in TriggerResult and Execution structs for improved code clarity. - Added test cases in robot_test.go to ensure Robot can run with nil config and quota, verifying default behavior. - Enhanced comments in the Goals struct to clarify task objectives and improve documentation consistency.
This commit is contained in:
parent
90b52eaf22
commit
4ceb74da9e
4 changed files with 38 additions and 23 deletions
|
|
@ -176,11 +176,11 @@ type TriggerRequest struct {
|
||||||
|
|
||||||
// TriggerResult - result of Trigger()
|
// TriggerResult - result of Trigger()
|
||||||
type TriggerResult struct {
|
type TriggerResult struct {
|
||||||
Accepted bool `json:"accepted"`
|
Accepted bool `json:"accepted"`
|
||||||
Queued bool `json:"queued"`
|
Queued bool `json:"queued"`
|
||||||
Execution *types.Execution `json:"execution,omitempty"`
|
Execution *types.Execution `json:"execution,omitempty"`
|
||||||
JobID string `json:"job_id,omitempty"`
|
JobID string `json:"job_id,omitempty"`
|
||||||
Message string `json:"message,omitempty"`
|
Message string `json:"message,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExecutionQuery - query options for GetExecutions()
|
// ExecutionQuery - query options for GetExecutions()
|
||||||
|
|
|
||||||
|
|
@ -86,8 +86,8 @@ func (r *Robot) GetExecutions() []*Execution {
|
||||||
// Each trigger creates a new Execution, mapped to a job.Job for monitoring
|
// Each trigger creates a new Execution, mapped to a job.Job for monitoring
|
||||||
// Relationship: 1 Execution = 1 job.Job
|
// Relationship: 1 Execution = 1 job.Job
|
||||||
type Execution struct {
|
type Execution struct {
|
||||||
ID string `json:"id"` // unique execution ID
|
ID string `json:"id"` // unique execution ID
|
||||||
MemberID string `json:"member_id"` // robot member ID
|
MemberID string `json:"member_id"` // robot member ID
|
||||||
TeamID string `json:"team_id"`
|
TeamID string `json:"team_id"`
|
||||||
TriggerType TriggerType `json:"trigger_type"` // clock | human | event
|
TriggerType TriggerType `json:"trigger_type"` // clock | human | event
|
||||||
StartTime time.Time `json:"start_time"`
|
StartTime time.Time `json:"start_time"`
|
||||||
|
|
@ -120,9 +120,9 @@ type Execution struct {
|
||||||
// TriggerInput - stored trigger input for traceability
|
// TriggerInput - stored trigger input for traceability
|
||||||
type TriggerInput struct {
|
type TriggerInput struct {
|
||||||
// For human intervention
|
// For human intervention
|
||||||
Action InterventionAction `json:"action,omitempty"` // task.add, goal.adjust, etc.
|
Action InterventionAction `json:"action,omitempty"` // task.add, goal.adjust, etc.
|
||||||
Messages []agentcontext.Message `json:"messages,omitempty"` // user's input (text, images, files)
|
Messages []agentcontext.Message `json:"messages,omitempty"` // user's input (text, images, files)
|
||||||
UserID string `json:"user_id,omitempty"` // who triggered
|
UserID string `json:"user_id,omitempty"` // who triggered
|
||||||
|
|
||||||
// For event trigger
|
// For event trigger
|
||||||
Source EventSource `json:"source,omitempty"` // webhook | database
|
Source EventSource `json:"source,omitempty"` // webhook | database
|
||||||
|
|
@ -145,13 +145,11 @@ type CurrentState struct {
|
||||||
// Example:
|
// Example:
|
||||||
// ## Goals
|
// ## Goals
|
||||||
// 1. [High] Analyze sales data and identify trends
|
// 1. [High] Analyze sales data and identify trends
|
||||||
// - Reason: Sales up 50%, need to understand why
|
// - Reason: Sales up 50%, need to understand why
|
||||||
// 2. [Normal] Prepare weekly report for manager
|
// - Reason: Friday 5pm, weekly report due
|
||||||
// - Reason: Friday 5pm, weekly report due
|
// - Reason: Friday 5pm, weekly report due
|
||||||
// 3. [Low] Update CRM with new leads
|
|
||||||
// - Reason: 3 pending leads from yesterday
|
|
||||||
type Goals struct {
|
type Goals struct {
|
||||||
Content string `json:"content"` // markdown text
|
// - Reason: 3 pending leads from yesterday
|
||||||
}
|
}
|
||||||
|
|
||||||
// Task - planned task (structured, for execution)
|
// Task - planned task (structured, for execution)
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,23 @@ func TestRobotCanRun(t *testing.T) {
|
||||||
assert.True(t, robot.CanRun())
|
assert.True(t, robot.CanRun())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("can run with nil config (uses default quota)", func(t *testing.T) {
|
||||||
|
robot := &types.Robot{
|
||||||
|
Config: nil, // nil config should not panic
|
||||||
|
}
|
||||||
|
// Should not panic and use default max (2)
|
||||||
|
assert.True(t, robot.CanRun())
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("can run with nil quota (uses default)", func(t *testing.T) {
|
||||||
|
robot := &types.Robot{
|
||||||
|
Config: &types.Config{
|
||||||
|
Quota: nil, // nil quota should use default
|
||||||
|
},
|
||||||
|
}
|
||||||
|
assert.True(t, robot.CanRun())
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("cannot run when at quota", func(t *testing.T) {
|
t.Run("cannot run when at quota", func(t *testing.T) {
|
||||||
robot := &types.Robot{
|
robot := &types.Robot{
|
||||||
Config: &types.Config{
|
Config: &types.Config{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue