Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

test(teamhub): cover what a Task conversation returns and to whom

LeoXing55d0a8cdbc91
diff --git a/apps/teamhub/internal/store/queries/task_meta_inbox.sql b/apps/teamhub/internal/store/queries/task_meta_inbox.sql
index e7082895..d50feb25 100644
--- a/apps/teamhub/internal/store/queries/task_meta_inbox.sql
+++ b/apps/teamhub/internal/store/queries/task_meta_inbox.sql
@@ -22,8 +22,8 @@ SET through_seq=$4,updated_at=now()
WHERE task_id=$1 AND tenant_id=$2 AND agent_actor_id=$3 AND through_seq<$4;
-- name: ListTaskConversationInputs :many
--- Every input the Task's own Agent received in its current generation, in
--- delivery order. Other participants hold copies of the same inputs.
+-- Every input the Task's result Agent received, in delivery order. Other
+-- participants' inboxes hold their own copies, which are left out.
SELECT message.id,message.author_actor_id,author.kind AS author_kind,
author.display_name AS author_display_name,message.body,message.source,message.created_at
FROM work_items item
diff --git a/apps/teamhub/internal/store/task_meta_inbox.sql.go b/apps/teamhub/internal/store/task_meta_inbox.sql.go
index 1e51bd70..84918772 100644
--- a/apps/teamhub/internal/store/task_meta_inbox.sql.go
+++ b/apps/teamhub/internal/store/task_meta_inbox.sql.go
@@ -175,8 +175,8 @@ type ListTaskConversationInputsRow struct {
CreatedAt pgtype.Timestamptz `json:"created_at"`
}
-// Every input the Task's own Agent received in its current generation, in
-// delivery order. Other participants hold copies of the same inputs.
+// Every input the Task's result Agent received, in delivery order. Other
+// participants' inboxes hold their own copies, which are left out.
func (q *Queries) ListTaskConversationInputs(ctx context.Context, taskID string) ([]ListTaskConversationInputsRow, error) {
rows, err := q.db.Query(ctx, listTaskConversationInputs, taskID)
if err != nil {
diff --git a/apps/teamhub/tests/integration/task_conversation_test.go b/apps/teamhub/tests/integration/task_conversation_test.go
new file mode 100644
index 00000000..80343515
--- /dev/null
+++ b/apps/teamhub/tests/integration/task_conversation_test.go
@@ -0,0 +1,83 @@
+package integration_test
+
+import (
+ "encoding/json"
+ "errors"
+ "net/http"
+ "strconv"
+ "testing"
+ "time"
+
+ "github.com/simplexai-labs/linger/apps/teamhub/internal/store"
+ "github.com/simplexai-labs/linger/apps/teamhub/internal/taskexecution"
+)
+
+func TestTaskConversationShowsOnlyItsAgentsInputs(t *testing.T) {
+ allowParallelIntegrationTest(t)
+ env := newRoomMembershipEnv(t)
+ alice := env.login("alice", alicePassword)
+ suffix := "task-conversation-" + strconv.FormatInt(time.Now().UnixNano(), 36)
+ roomID := createPrivateRoom(t, env, alice, "Task conversation "+suffix, "task-conversation-room-"+suffix)
+ if status, body := putRoomMember(t, env, alice, roomID, "actor_acme_official", "member"); status != http.StatusOK {
+ t.Fatalf("add Task participant status=%d body=%s", status, body)
+ }
+ task := createManagedTaskFixture(t, env, roomID, suffix)
+ const peer = "actor_acme_conversation_peer"
+ if _, err := env.pool.Exec(t.Context(), `INSERT INTO actors(id,tenant_id,kind,display_name,handle)
+ VALUES($1,$2,'agent','Peer','conversation-peer')`, peer, acmeTenant); err != nil {
+ t.Fatal(err)
+ }
+
+ tx, err := env.pool.Begin(t.Context())
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer tx.Rollback(t.Context())
+ queries := store.New(tx)
+ if _, err := taskexecution.AppendTaskInput(t.Context(), queries, taskexecution.TaskInput{
+ TaskID: task.ID, Cause: taskexecution.TaskInputSystem, Body: "The card was approved.",
+ }); err != nil {
+ t.Fatalf("append system input: %v", err)
+ }
+ // Another participant's inbox holds its own copies; they are not the Task's.
+ if _, err := taskexecution.AppendParticipantMetaWakes(
+ t.Context(), queries, task.ID, acmeTenant, "actor_acme_alice", taskexecution.InputSourceMessage,
+ []string{peer}, taskexecution.TurnMessageInput{
+ MessageID: "peer-message-" + suffix, RawMessage: "Only the peer received this.",
+ Segments: json.RawMessage(`[{"type":"text","content":"Only the peer received this."}]`),
+ Author: &taskexecution.TurnMessageAuthor{ActorID: "actor_acme_alice", Kind: "human", DisplayName: "Alice"},
+ },
+ ); err != nil {
+ t.Fatalf("append peer input: %v", err)
+ }
+ if err := tx.Commit(t.Context()); err != nil {
+ t.Fatal(err)
+ }
+
+ status, _, body := env.request(alice, http.MethodGet, "/v0/tasks/"+task.ID+"/conversation", nil, "")
+ if status != http.StatusOK {
+ t.Fatalf("read conversation status=%d body=%s", status, body)
+ }
+ var conversation struct {
+ Inputs []struct {
+ Body string `json:"body"`
+ Source string `json:"source"`
+ } `json:"inputs"`
+ Cards []json.RawMessage `json:"cards"`
+ }
+ decode(t, body, &conversation)
+ if len(conversation.Inputs) != 2 ||
+ conversation.Inputs[0].Body != "Return a summary." || conversation.Inputs[0].Source != "message" ||
+ conversation.Inputs[1].Body != "The card was approved." || conversation.Inputs[1].Source != "system" ||
+ conversation.Cards == nil || len(conversation.Cards) != 0 {
+ t.Fatalf("conversation=%s", body)
+ }
+
+ service := taskexecution.New(env.pool)
+ if _, err := service.GetConversationForHuman(t.Context(), "account_outsider", task.ID); !errors.Is(err, taskexecution.ErrNotFound) {
+ t.Fatalf("an Account outside the tenant read the conversation: %v", err)
+ }
+ if status, _, body := env.request(alice, http.MethodGet, "/v0/tasks/workitem_missing/conversation", nil, ""); status != http.StatusNotFound {
+ t.Fatalf("missing Task status=%d body=%s", status, body)
+ }
+}