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

useWorkspaceMutationRefresh.test.ts

62 lines2.0 KB

1import { EventId, type OrchestrationThreadActivity } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3​
4import {
5 latestWorkspaceMutationId,
6 workspaceMutationRefreshToken,
7} from "./useWorkspaceMutationRefresh";
8​
9function activity(
10 id: string,
11 kind: string,
12 itemType: string,
13 status?: string,
14): OrchestrationThreadActivity {
15 return {
16 id: EventId.make(id),
17 kind,
18 tone: "tool",
19 summary: "Tool activity",
20 payload: { itemType, ...(status ? { status } : {}) },
21 turnId: null,
22 createdAt: "2026-08-30T00:00:00.000Z",
23 };
25​
26describe("workspace mutation refresh", () => {
27 it("tracks the latest completed file change or command", () => {
28 expect(
29 latestWorkspaceMutationId([
30 activity("file-started", "tool.started", "file_change"),
31 activity("search-completed", "tool.completed", "web_search"),
32 activity("file-completed", "tool.completed", "file_change"),
33 activity("command-completed", "tool.completed", "command_execution"),
34 ]),
35 ).toBe("command-completed");
36 });
37​
38 it("ignores read-only and in-progress tools", () => {
39 expect(
40 latestWorkspaceMutationId([
41 activity("command-updated", "tool.updated", "command_execution", "inProgress"),
42 activity("legacy-command-updated", "tool.updated", "command_execution", "in_progress"),
43 activity("image-completed", "tool.completed", "image_view"),
44 ]),
45 ).toBeNull();
46 });
47​
48 it("accepts providers that report terminal state on an update", () => {
49 expect(
50 latestWorkspaceMutationId([
51 activity("file-updated", "tool.updated", "file_change", "completed"),
52 ]),
53 ).toBe("file-updated");
54 });
55​
56 it("scopes the same mutation to each preview resource", () => {
57 expect(workspaceMutationRefreshToken("file:/repo/README.md", "event-1")).not.toBe(
58 workspaceMutationRefreshToken("diff:/repo", "event-1"),
59 );
60 expect(workspaceMutationRefreshToken("file:/repo/README.md", null)).toBeNull();
61 });
62});