Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| @g1t welcomes you when you join a workspace, and that is the one introduction any agent makes. Identity now says when a person becomes a member, workspace.member_joined, by invitation, by an invite code, or by creating the workspace, and webhooks can hear it; the agents service hears it too, and for anyone who joined, never the creator, the workspace's @g1t opens your direct message and says in its own voice who it is, what to ask it, how agents answer, and where things are, once per person per workspace and charged to @g1t like any reply, with a fixed welcome when no model can be used. The agents, workspaces, authentication and webhooks guides say so. | 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; | |
| 3 | ||
| 4 | import type { G1tEvent } from "../../../packages/contracts/src/events.ts"; | |
| 5 | import { welcomeFor, welcomeMessageId } from "./welcome.ts"; | |
| 6 | ||
| 7 | const joined = (data: Record<string, unknown>, type = "workspace.member_joined") => | |
| 8 | ({ type, data }) as unknown as Pick<G1tEvent, "type" | "data">; | |
| 9 | ||
| 10 | const ada = { workspaceId: "wsp_1", workspace: "Acme", userId: "usr_ada", username: "ada", role: "member" }; | |
| 11 | ||
| 12 | test("a person who accepted an invitation or used an invite code is welcomed", () => { | |
| 13 | assert.deepEqual(welcomeFor(joined({ ...ada, how: "invitation" })), { | |
| 14 | workspace_id: "wsp_1", | |
| 15 | workspace: "acme", | |
| 16 | user_id: "usr_ada", | |
| 17 | username: "ada", | |
| 18 | }); | |
| 19 | assert.deepEqual(welcomeFor(joined({ ...ada, how: "joined", role: "owner" }))?.username, "ada"); | |
| 20 | }); | |
| 21 | ||
| 22 | test("the workspace's creator gets no welcome, and nor does anyone an event leaves unnamed", () => { | |
| 23 | assert.equal(welcomeFor(joined({ ...ada, how: "created", role: "owner" })), null, "they made it"); | |
| 24 | assert.equal(welcomeFor(joined({ ...ada })), null, "no door named"); | |
| 25 | assert.equal(welcomeFor(joined({ ...ada, how: "added" })), null, "a door this version doesn't know"); | |
| 26 | assert.equal(welcomeFor(joined({ ...ada, how: "invitation", userId: "" })), null); | |
| 27 | assert.equal(welcomeFor(joined({ ...ada, how: "invitation", workspace: " " })), null); | |
| 28 | assert.equal(welcomeFor(joined({ ...ada, how: "invitation", username: undefined })), null); | |
| 29 | assert.equal(welcomeFor(joined({ ...ada, how: "invitation" }, "team.member_added")), null, "a team is not the workspace"); | |
| 30 | assert.equal(welcomeFor(joined({ ...ada, how: "invitation" }, "workspace.updated")), null); | |
| 31 | assert.equal(welcomeFor(null), null); | |
| 32 | assert.equal(welcomeFor({ type: "workspace.member_joined", data: undefined } as unknown as Pick<G1tEvent, "type" | "data">), null); | |
| 33 | }); | |
| 34 | ||
| 35 | test("a welcome is claimed under one id per person per workspace, which names no message in chat", () => { | |
| 36 | assert.equal(welcomeMessageId("wsp_1", "usr_ada"), "welcome:wsp_1:usr_ada"); | |
| 37 | // The same event twice, or a second door into the same workspace, is the same claim. | |
| 38 | const first = welcomeFor(joined({ ...ada, how: "invitation" }))!; | |
| 39 | const again = welcomeFor(joined({ ...ada, how: "joined" }))!; | |
| 40 | assert.equal(welcomeMessageId(first.workspace_id, first.user_id), welcomeMessageId(again.workspace_id, again.user_id)); | |
| 41 | // Another workspace, or another person, is its own welcome. | |
| 42 | assert.notEqual(welcomeMessageId("wsp_2", "usr_ada"), welcomeMessageId("wsp_1", "usr_ada")); | |
| 43 | assert.notEqual(welcomeMessageId("wsp_1", "usr_bo"), welcomeMessageId("wsp_1", "usr_ada")); | |
| 44 | // The prefix surface.ts reads, so no reaction is tried on a message that does not exist. | |
| 45 | assert.ok(welcomeMessageId("wsp_1", "usr_ada").startsWith("welcome:")); | |
| 46 | }); |