Open History to see the last commit
1import {
2 ORCHESTRATION_V2_WS_METHODS,
3 OrchestrationV2Command,
4 WS_METHODS,
5} from "@t3tools/contracts";
6import { expect, it } from "@effect/vitest";
7import * as Schema from "effect/Schema";
8
9import { commandFeatureUsage, featureUsage } from "./FeatureUsage.ts";
10
11const command = Schema.decodeUnknownSync(OrchestrationV2Command);
12const ids = { commandId: "command-private", threadId: "thread-private" };
13
14it("ignores messages, housekeeping commands, and untracked RPCs", () => {
15 expect(
16 commandFeatureUsage(
17 command({
18 ...ids,
19 type: "message.dispatch",
20 messageId: "message-private",
21 text: "secret prompt",
22 attachments: [],
23 createdBy: "user",
24 creationSource: "web",
25 dispatchMode: { type: "start_immediately" },
26 }),
27 ),
28 ).toBe(undefined);
29 expect(
30 commandFeatureUsage(
31 command({ ...ids, type: "thread.visit", visitedAt: "2026-10-24T00:00:00.000Z" }),
32 ),
33 ).toBe(undefined);
34 expect(featureUsage(WS_METHODS.terminalWrite, { data: "rm -rf" })).toBe(undefined);
35});
36
37it("leaves thread launches to client.thread.started", () => {
38 expect(
39 featureUsage(ORCHESTRATION_V2_WS_METHODS.launchThread, {
40 title: "Private title",
41 workspaceStrategy: { type: "worktree", baseRef: "main", branch: "secret-branch" },
42 }),
43 ).toBe(undefined);
44});
45
46it("tells watching a pull request apart from unwatching it", () => {
47 const watch = (watching: boolean) =>
48 commandFeatureUsage(
49 command({
50 ...ids,
51 type: "thread.pull-request.watch",
52 host: "github.com",
53 repository: "owner/private",
54 number: 7,
55 watching,
56 }),
57 );
58 expect(watch(true)).toEqual({ feature: "thread.pull_request.watch", variant: "on" });
59 expect(watch(false)).toEqual({ feature: "thread.pull_request.watch", variant: "off" });
60});
61
62it("reads RPC variants from enums, never from paths or text", () => {
63 expect(
64 featureUsage(WS_METHODS.shellOpenInEditor, { cwd: "/Users/someone/secret", editor: "cursor" }),
65 ).toEqual({ feature: "editor.open", variant: "cursor" });
66 expect(featureUsage(WS_METHODS.terminalOpen, { cwd: "/Users/someone/secret" })).toEqual({
67 feature: "terminal.open",
68 });
69});
70
71it("counts the owner's guest share actions, and only guest message sends", () => {
72 const send = (guestMessageId?: string) =>
73 commandFeatureUsage(
74 command({
75 ...ids,
76 type: "message.dispatch",
77 messageId: "message-private",
78 text: "secret prompt",
79 attachments: [],
80 createdBy: "user",
81 creationSource: "web",
82 dispatchMode: { type: "start_immediately" },
83 ...(guestMessageId === undefined ? {} : { guestMessageId }),
84 }),
85 );
86 expect(send("guest-message-private")).toEqual({ feature: "guest_message.send" });
87 expect(send()).toBe(undefined);
88 expect(
89 commandFeatureUsage(
90 command({ ...ids, type: "thread.guest-message.dismiss", guestMessageId: "guest-private" }),
91 ),
92 ).toEqual({ feature: "guest_message.dismiss" });
93 expect(commandFeatureUsage(command({ ...ids, type: "thread.guest-share.close" }))).toEqual({
94 feature: "guest_share.close",
95 });
96 expect(featureUsage(WS_METHODS.guestShareCreate, { threadId: "thread-private" })).toEqual({
97 feature: "guest_share.create",
98 });
99});