Skip to content

Commit

Permalink
fix: move agent and debug package to runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
siyul-park committed Dec 21, 2024
1 parent 4ee58f0 commit ed27851
Show file tree
Hide file tree
Showing 22 changed files with 478 additions and 396 deletions.
43 changes: 21 additions & 22 deletions cmd/pkg/cli/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/siyul-park/uniflow/pkg/runtime"
"slices"
"strings"
"time"
Expand All @@ -13,8 +14,6 @@ import (
tea "github.com/charmbracelet/bubbletea"
"github.com/gofrs/uuid"
"github.com/siyul-park/uniflow/cmd/pkg/resource"
"github.com/siyul-park/uniflow/pkg/agent"
"github.com/siyul-park/uniflow/pkg/debug"
"github.com/siyul-park/uniflow/pkg/port"
"github.com/siyul-park/uniflow/pkg/process"
"github.com/siyul-park/uniflow/pkg/symbol"
Expand All @@ -23,17 +22,17 @@ import (

// Debugger manages the debugger UI using Bubble Tea.
type Debugger struct {
agent *agent.Agent
debugger *debug.Debugger
agent *runtime.Agent
debugger *runtime.Debugger
program *tea.Program
}

// debugModel represents the state and logic for the debugger UI.
type debugModel struct {
view debugView
input textinput.Model
agent *agent.Agent
debugger *debug.Debugger
agent *runtime.Agent
debugger *runtime.Debugger
}

// debugView defines an interface for different debug view types.
Expand All @@ -44,10 +43,10 @@ type debugView interface {
// Various debug view types
type (
errDebugView struct{ err error }
frameDebugView struct{ frame *agent.Frame }
framesDebugView struct{ frames []*agent.Frame }
breakpointDebugView struct{ breakpoint *debug.Breakpoint }
breakpointsDebugView struct{ breakpoints []*debug.Breakpoint }
frameDebugView struct{ frame *runtime.Frame }
framesDebugView struct{ frames []*runtime.Frame }
breakpointDebugView struct{ breakpoint *runtime.Breakpoint }
breakpointsDebugView struct{ breakpoints []*runtime.Breakpoint }
symbolDebugView struct{ symbol *symbol.Symbol }
symbolsDebugView struct{ symbols []*symbol.Symbol }
processDebugView struct{ process *process.Process }
Expand All @@ -65,12 +64,12 @@ var _ debugView = (*processDebugView)(nil)
var _ debugView = (*processesDebugView)(nil)

// NewDebugger initializes a new Debugger with an input model and UI.
func NewDebugger(agent *agent.Agent, options ...tea.ProgramOption) *Debugger {
func NewDebugger(agent *runtime.Agent, options ...tea.ProgramOption) *Debugger {
ti := textinput.New()
ti.Prompt = "(debug) "
ti.Focus()

debugger := debug.NewDebugger(agent)
debugger := runtime.NewDebugger(agent)
model := &debugModel{
input: ti,
agent: agent,
Expand Down Expand Up @@ -140,9 +139,9 @@ func (m *debugModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case "quit", "q":
return m, tea.Quit
case "break", "b":
var bps []*debug.Breakpoint
var bps []*runtime.Breakpoint
if len(args) <= 1 {
bp := debug.NewBreakpoint()
bp := runtime.NewBreakpoint()
m.debugger.AddBreakpoint(bp)

bps = append(bps, bp)
Expand All @@ -163,10 +162,10 @@ func (m *debugModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
}

bp := debug.NewBreakpoint(
debug.WithSymbol(sb),
debug.WithInPort(inPort),
debug.WithOutPort(outPort),
bp := runtime.NewBreakpoint(
runtime.WithSymbol(sb),
runtime.WithInPort(inPort),
runtime.WithOutPort(outPort),
)
m.debugger.AddBreakpoint(bp)

Expand Down Expand Up @@ -198,7 +197,7 @@ func (m *debugModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return nil
}
case "delete", "d":
var bp *debug.Breakpoint
var bp *runtime.Breakpoint
if len(args) > 1 {
bps := m.debugger.Breakpoints()
for _, b := range bps {
Expand All @@ -221,7 +220,7 @@ func (m *debugModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.view = &breakpointsDebugView{breakpoints: bps}
return m, nil
case "breakpoint", "bp":
var bp *debug.Breakpoint
var bp *runtime.Breakpoint
if len(args) > 1 {
bps := m.debugger.Breakpoints()
for _, b := range bps {
Expand Down Expand Up @@ -287,7 +286,7 @@ func (m *debugModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
proc = m.debugger.Process()
}

var frames []*agent.Frame
var frames []*runtime.Frame
if proc != nil {
frames = m.agent.Frames(proc.ID())
}
Expand All @@ -300,7 +299,7 @@ func (m *debugModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, nil
}
}
case *agent.Frame:
case *runtime.Frame:
if msg == nil {
m.view = nil
} else {
Expand Down
69 changes: 34 additions & 35 deletions cmd/pkg/cli/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/siyul-park/uniflow/pkg/runtime"
"testing"
"time"

"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
"github.com/go-faker/faker/v4"
"github.com/gofrs/uuid"
"github.com/siyul-park/uniflow/pkg/agent"
"github.com/siyul-park/uniflow/pkg/debug"
"github.com/siyul-park/uniflow/pkg/node"
"github.com/siyul-park/uniflow/pkg/packet"
"github.com/siyul-park/uniflow/pkg/port"
Expand All @@ -25,18 +24,18 @@ import (
)

func TestNewDebugger(t *testing.T) {
d := NewDebugger(agent.New())
d := NewDebugger(runtime.NewAgent())
defer d.Kill()

assert.NotNil(t, d)
}

func TestDebugModel_Update(t *testing.T) {
t.Run("break <symbol> <port>", func(t *testing.T) {
a := agent.New()
a := runtime.NewAgent()
defer a.Close()

d := debug.NewDebugger(a)
d := runtime.NewDebugger(a)
defer d.Close()

m := &debugModel{
Expand Down Expand Up @@ -66,10 +65,10 @@ func TestDebugModel_Update(t *testing.T) {
})

t.Run("break", func(t *testing.T) {
a := agent.New()
a := runtime.NewAgent()
defer a.Close()

d := debug.NewDebugger(a)
d := runtime.NewDebugger(a)
defer d.Close()

m := &debugModel{
Expand Down Expand Up @@ -99,10 +98,10 @@ func TestDebugModel_Update(t *testing.T) {
})

t.Run("continue", func(t *testing.T) {
a := agent.New()
a := runtime.NewAgent()
defer a.Close()

d := debug.NewDebugger(a)
d := runtime.NewDebugger(a)
defer d.Close()

m := &debugModel{
Expand Down Expand Up @@ -135,10 +134,10 @@ func TestDebugModel_Update(t *testing.T) {
})

t.Run("delete <breakpoint>", func(t *testing.T) {
a := agent.New()
a := runtime.NewAgent()
defer a.Close()

d := debug.NewDebugger(a)
d := runtime.NewDebugger(a)
defer d.Close()

m := &debugModel{
Expand Down Expand Up @@ -171,10 +170,10 @@ func TestDebugModel_Update(t *testing.T) {
})

t.Run("breakpoints", func(t *testing.T) {
a := agent.New()
a := runtime.NewAgent()
defer a.Close()

d := debug.NewDebugger(a)
d := runtime.NewDebugger(a)
defer d.Close()

m := &debugModel{
Expand Down Expand Up @@ -207,10 +206,10 @@ func TestDebugModel_Update(t *testing.T) {
})

t.Run("breakpoint <breakpoint>", func(t *testing.T) {
a := agent.New()
a := runtime.NewAgent()
defer a.Close()

d := debug.NewDebugger(a)
d := runtime.NewDebugger(a)
defer d.Close()

m := &debugModel{
Expand Down Expand Up @@ -246,10 +245,10 @@ func TestDebugModel_Update(t *testing.T) {
ctx, cancel := context.WithTimeout(context.TODO(), time.Second)
defer cancel()

a := agent.New()
a := runtime.NewAgent()
defer a.Close()

d := debug.NewDebugger(a)
d := runtime.NewDebugger(a)
defer d.Close()

m := &debugModel{
Expand Down Expand Up @@ -303,10 +302,10 @@ func TestDebugModel_Update(t *testing.T) {
})

t.Run("symbols", func(t *testing.T) {
a := agent.New()
a := runtime.NewAgent()
defer a.Close()

d := debug.NewDebugger(a)
d := runtime.NewDebugger(a)
defer d.Close()

m := &debugModel{
Expand Down Expand Up @@ -336,10 +335,10 @@ func TestDebugModel_Update(t *testing.T) {
})

t.Run("symbol <symbol>", func(t *testing.T) {
a := agent.New()
a := runtime.NewAgent()
defer a.Close()

d := debug.NewDebugger(a)
d := runtime.NewDebugger(a)
defer d.Close()

m := &debugModel{
Expand Down Expand Up @@ -375,10 +374,10 @@ func TestDebugModel_Update(t *testing.T) {
ctx, cancel := context.WithTimeout(context.TODO(), time.Second)
defer cancel()

a := agent.New()
a := runtime.NewAgent()
defer a.Close()

d := debug.NewDebugger(a)
d := runtime.NewDebugger(a)
defer d.Close()

m := &debugModel{
Expand Down Expand Up @@ -435,10 +434,10 @@ func TestDebugModel_Update(t *testing.T) {
ctx, cancel := context.WithTimeout(context.TODO(), time.Second)
defer cancel()

a := agent.New()
a := runtime.NewAgent()
defer a.Close()

d := debug.NewDebugger(a)
d := runtime.NewDebugger(a)
defer d.Close()

m := &debugModel{
Expand Down Expand Up @@ -496,10 +495,10 @@ func TestDebugModel_Update(t *testing.T) {
ctx, cancel := context.WithTimeout(context.TODO(), time.Second)
defer cancel()

a := agent.New()
a := runtime.NewAgent()
defer a.Close()

d := debug.NewDebugger(a)
d := runtime.NewDebugger(a)
defer d.Close()

m := &debugModel{
Expand Down Expand Up @@ -556,10 +555,10 @@ func TestDebugModel_Update(t *testing.T) {
ctx, cancel := context.WithTimeout(context.TODO(), time.Second)
defer cancel()

a := agent.New()
a := runtime.NewAgent()
defer a.Close()

d := debug.NewDebugger(a)
d := runtime.NewDebugger(a)
defer d.Close()

m := &debugModel{
Expand Down Expand Up @@ -616,10 +615,10 @@ func TestDebugModel_Update(t *testing.T) {
ctx, cancel := context.WithTimeout(context.TODO(), time.Second)
defer cancel()

a := agent.New()
a := runtime.NewAgent()
defer a.Close()

d := debug.NewDebugger(a)
d := runtime.NewDebugger(a)
defer d.Close()

m := &debugModel{
Expand Down Expand Up @@ -679,10 +678,10 @@ func TestDebugModel_Update(t *testing.T) {
ctx, cancel := context.WithTimeout(context.TODO(), time.Second)
defer cancel()

a := agent.New()
a := runtime.NewAgent()
defer a.Close()

d := debug.NewDebugger(a)
d := runtime.NewDebugger(a)
defer d.Close()

m := &debugModel{
Expand Down Expand Up @@ -742,10 +741,10 @@ func TestDebugModel_Update(t *testing.T) {
ctx, cancel := context.WithTimeout(context.TODO(), time.Second)
defer cancel()

a := agent.New()
a := runtime.NewAgent()
defer a.Close()

d := debug.NewDebugger(a)
d := runtime.NewDebugger(a)
defer d.Close()

m := &debugModel{
Expand Down
3 changes: 1 addition & 2 deletions cmd/pkg/cli/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"syscall"

tea "github.com/charmbracelet/bubbletea"
"github.com/siyul-park/uniflow/pkg/agent"
"github.com/siyul-park/uniflow/pkg/chart"
"github.com/siyul-park/uniflow/pkg/hook"
resourcebase "github.com/siyul-park/uniflow/pkg/resource"
Expand Down Expand Up @@ -108,7 +107,7 @@ func runStartCommand(config StartConfig) func(cmd *cobra.Command, args []string)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

if enableDebug {
a := agent.New()
a := runtime.NewAgent()

h.AddLoadHook(a)
h.AddUnloadHook(a)
Expand Down
4 changes: 2 additions & 2 deletions ext/pkg/language/cel/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ type adapter struct{}

var _ types.Adapter = (*adapter)(nil)

func (*adapter) SyscallToValue(value any) ref.Val {
func (*adapter) NativeToValue(value any) ref.Val {
switch v := value.(type) {
case error:
return &Error{error: v}
}
return types.DefaultTypeAdapter.SyscallToValue(value)
return types.DefaultTypeAdapter.NativeToValue(value)
}
Loading

0 comments on commit ed27851

Please sign in to comment.