Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

FeatureUsage.test.ts

52 lines1.9 KB

1import { CommandId, ORCHESTRATION_V2_WS_METHODS, ThreadId, WS_METHODS } from "@t3tools/contracts";
2import { expect, it } from "@effect/vitest";
3​
4import { featureUsage } from "./FeatureUsage.ts";
5​
6const dispatch = ORCHESTRATION_V2_WS_METHODS.dispatchCommand;
7const threadId = ThreadId.make("thread-private");
8const commandId = CommandId.make("command-private");
9​
10it("names user commands with their closed-enum variant and nothing else", () => {
11 expect(
12 featureUsage(dispatch, {
13 type: "checkpoint.rollback",
14 commandId,
15 threadId,
16 scopeId: "scope-private",
17 checkpointId: "checkpoint-private",
18 restoreFiles: false,
19 }),
20 ).toEqual({ feature: "checkpoint.rollback", variant: "conversation_only" });
21 expect(
22 featureUsage(dispatch, {
23 type: "thread.runtime-mode.set",
24 commandId,
25 threadId,
26 runtimeMode: "full-access",
27 }),
28 ).toEqual({ feature: "thread.runtime_mode.set", variant: "full-access" });
29});
30​
31it("ignores messages, housekeeping commands, and untracked RPCs", () => {
32 expect(featureUsage(dispatch, { type: "message.dispatch", text: "secret prompt" })).toBe(
33 undefined,
34 );
35 expect(featureUsage(dispatch, { type: "thread.visit", threadId })).toBe(undefined);
36 expect(featureUsage(WS_METHODS.terminalWrite, { data: "rm -rf" })).toBe(undefined);
37});
38​
39it("reads RPC variants from enums, never from paths or text", () => {
40 expect(
41 featureUsage(WS_METHODS.shellOpenInEditor, { cwd: "/Users/someone/secret", editor: "cursor" }),
42 ).toEqual({ feature: "editor.open", variant: "cursor" });
43 expect(
44 featureUsage(ORCHESTRATION_V2_WS_METHODS.launchThread, {
45 title: "Private title",
46 workspaceStrategy: { type: "worktree", baseRef: "main", branch: "secret-branch" },
47 }),
48 ).toEqual({ feature: "thread.launch", variant: "worktree" });
49 expect(featureUsage(WS_METHODS.terminalOpen, { cwd: "/Users/someone/secret" })).toEqual({
50 feature: "terminal.open",
51 });
52});