fix: add missing CreatedBy in RPC path

created_by was recently added in c3ef1c3f38 but was missing support for passing in the CreatedBy through the RPC path so a create that was using the daemon was never having the created_by field set.
This commit is contained in:
Zachary Rosen
2025-12-26 20:38:14 -05:00
parent 2c7d34a4c3
commit f6eeb170ef
4 changed files with 49 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
package rpc
import (
"context"
"encoding/json"
"testing"
"time"
@@ -9,6 +10,49 @@ import (
"github.com/steveyegge/beads/internal/types"
)
// TestHandleCreate_SetsCreatedBy verifies that CreatedBy is passed through RPC and stored (GH#748)
func TestHandleCreate_SetsCreatedBy(t *testing.T) {
store := memory.New("/tmp/test.jsonl")
server := NewServer("/tmp/test.sock", store, "/tmp", "/tmp/test.db")
createArgs := CreateArgs{
Title: "Test CreatedBy Field",
IssueType: "task",
Priority: 2,
CreatedBy: "test-actor",
}
createJSON, _ := json.Marshal(createArgs)
createReq := &Request{
Operation: OpCreate,
Args: createJSON,
Actor: "test-actor",
}
resp := server.handleCreate(createReq)
if !resp.Success {
t.Fatalf("create failed: %s", resp.Error)
}
var createdIssue types.Issue
if err := json.Unmarshal(resp.Data, &createdIssue); err != nil {
t.Fatalf("failed to parse response: %v", err)
}
// Verify CreatedBy was set in the response
if createdIssue.CreatedBy != "test-actor" {
t.Errorf("expected CreatedBy 'test-actor' in response, got %q", createdIssue.CreatedBy)
}
// Verify CreatedBy was persisted to storage
storedIssue, err := store.GetIssue(context.Background(), createdIssue.ID)
if err != nil {
t.Fatalf("failed to get issue from storage: %v", err)
}
if storedIssue.CreatedBy != "test-actor" {
t.Errorf("expected CreatedBy 'test-actor' in storage, got %q", storedIssue.CreatedBy)
}
}
func TestEmitMutation(t *testing.T) {
store := memory.New("/tmp/test.jsonl")
server := NewServer("/tmp/test.sock", store, "/tmp", "/tmp/test.db")