diff --git a/cmd/ww/shell/README.md b/cmd/ww/shell/README.md index ddf3cbb..5fa2953 100644 --- a/cmd/ww/shell/README.md +++ b/cmd/ww/shell/README.md @@ -144,7 +144,7 @@ ww shell --with-exec ``` ww> (exec /ipfs/QmHash/bytecode.wasm :timeout 30s) -/protocol/identifier +abc123def ww> ``` diff --git a/cmd/ww/shell/executor.go b/cmd/ww/shell/executor.go index cc578aa..be8f2d9 100644 --- a/cmd/ww/shell/executor.go +++ b/cmd/ww/shell/executor.go @@ -69,11 +69,11 @@ func (e Exec) Invoke(args ...core.Any) (core.Any, error) { return nil, fmt.Errorf("failed to read bytecode: %w", err) } - protocol, err := e.ExecBytes(ctx, bytecode) + procID, err := e.ExecBytes(ctx, bytecode) if err != nil { return nil, fmt.Errorf("failed to execute bytecode: %w", err) } - return protocol, nil + return builtin.String(procID), nil case files.Directory: return nil, errors.New("TODO: directory support") @@ -82,7 +82,7 @@ func (e Exec) Invoke(args ...core.Any) (core.Any, error) { } } -func (e Exec) ExecBytes(ctx context.Context, bytecode []byte) (protocol.ID, error) { +func (e Exec) ExecBytes(ctx context.Context, bytecode []byte) (string, error) { f, release := e.Session.Exec().Exec(ctx, func(p system.Executor_exec_Params) error { return p.SetBytecode(bytecode) }) @@ -94,8 +94,8 @@ func (e Exec) ExecBytes(ctx context.Context, bytecode []byte) (protocol.ID, erro return "", err } - proto, err := result.Protocol() - return protocol.ID(proto), err + procID, err := result.Protocol() + return procID, err } func (e Exec) NewContext(opts map[builtin.Keyword]core.Any) (context.Context, context.CancelFunc) { diff --git a/cmd/ww/shell/shell b/cmd/ww/shell/shell deleted file mode 100755 index 0436546..0000000 Binary files a/cmd/ww/shell/shell and /dev/null differ diff --git a/system/proc.go b/system/proc.go index d8ca6f0..ed7305f 100644 --- a/system/proc.go +++ b/system/proc.go @@ -83,8 +83,9 @@ type Proc struct { Module api.Module } -func (p *Proc) String() string { - return p.Endpoint.String() +// ID returns the process identifier (endpoint name) without the protocol prefix. +func (p *Proc) ID() string { + return p.Endpoint.Name } func (p *Proc) Close(ctx context.Context) error { diff --git a/system/proc_test.go b/system/proc_test.go index 6444e7c..013e3d6 100644 --- a/system/proc_test.go +++ b/system/proc_test.go @@ -75,7 +75,7 @@ func TestProcConfig_New(t *testing.T) { // Verify the endpoint has a valid name assert.NotEmpty(t, proc.Endpoint.Name) - assert.Contains(t, proc.String(), "/ww/0.1.0/") + assert.NotEmpty(t, proc.ID()) // Clean up proc.Close(ctx) @@ -126,16 +126,16 @@ func TestProcConfig_New(t *testing.T) { }) } -func TestProc_String(t *testing.T) { +func TestProc_ID(t *testing.T) { endpoint := system.NewEndpoint() proc := &system.Proc{ Endpoint: endpoint, } - result := proc.String() - expected := endpoint.String() + result := proc.ID() + expected := endpoint.Name assert.Equal(t, expected, result) - assert.Contains(t, result, "/ww/0.1.0/") + assert.NotEmpty(t, result) } func TestProc_Close(t *testing.T) { @@ -429,6 +429,7 @@ func TestEndpoint_String(t *testing.T) { assert.Equal(t, expected, result) assert.Contains(t, result, "/ww/0.1.0/") + assert.Contains(t, result, endpoint.Name) } func TestEndpoint_Protocol(t *testing.T) { @@ -521,7 +522,7 @@ func TestProc_Integration_WithRealWasm(t *testing.T) { assert.NotNil(t, proc.Module, "Module should be initialized") assert.NotNil(t, proc.Endpoint, "Endpoint should be initialized") assert.NotEmpty(t, proc.Endpoint.Name, "Endpoint should have a name") - assert.Contains(t, proc.String(), "/ww/0.1.0/", "String should contain protocol prefix") + assert.NotEmpty(t, proc.ID(), "String should not be empty") // Test that the poll function is exported pollFunc := proc.Module.ExportedFunction("poll") diff --git a/system/system.go b/system/system.go index 18e6b49..d58a481 100644 --- a/system/system.go +++ b/system/system.go @@ -87,7 +87,7 @@ func (d DefaultExecutor) Exec(ctx context.Context, call Executor_exec) error { }.New(ctx) if err != nil { return err - } else if err = res.SetProtocol(proc.String()); err != nil { + } else if err = res.SetProtocol(proc.ID()); err != nil { defer proc.Close(ctx) } @@ -115,11 +115,13 @@ func NewEndpoint() *Endpoint { } } +// String returns the full protocol identifier including the /ww/0.1.0/ prefix. func (e Endpoint) String() string { proto := e.Protocol() return string(proto) } +// Protocol returns the libp2p protocol ID for this endpoint. func (e Endpoint) Protocol() protocol.ID { return protocol.ID("/ww/0.1.0/" + e.Name) }