Skip to content

Commit 8f1cbf2

Browse files
test(web): prune low-value tests in web stores, lib and hooks (second pass)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent eba122e commit 8f1cbf2

75 files changed

Lines changed: 53 additions & 3329 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { describe, expect, it, vi } from "vite-plus/test";
22
import { DEFAULT_BROWSER_PROFILE_ID, INCOGNITO_BROWSER_PROFILE_ID } from "@t3tools/contracts";
33

4-
import { ensureClientSettingsHydrated } from "~/hooks/useSettings";
5-
64
const settings = vi.hoisted(() => ({ current: {} as Record<string, unknown> }));
75

86
vi.mock("~/hooks/useSettings", () => ({
@@ -11,7 +9,7 @@ vi.mock("~/hooks/useSettings", () => ({
119
ensureClientSettingsHydrated: vi.fn(async () => undefined),
1210
}));
1311

14-
const { getBrowserDefaults, resolveBrowserDefaults } = await import("./browserDefaults");
12+
const { getBrowserDefaults } = await import("./browserDefaults");
1513

1614
const withDefaultProfile = (browserDefaultProfileId: string) => {
1715
settings.current = {
@@ -32,22 +30,3 @@ describe("getBrowserDefaults profile resolution", () => {
3230
);
3331
});
3432
});
35-
36-
describe("resolveBrowserDefaults", () => {
37-
it("rejects failed reads and uses the saved profile after a successful retry", async () => {
38-
withDefaultProfile("work");
39-
settings.current.browserDefaultZoomFactor = 1.25;
40-
settings.current.browserDefaultAppearance = "dark";
41-
const failure = new Error("Settings read failed");
42-
vi.mocked(ensureClientSettingsHydrated).mockRejectedValueOnce(failure);
43-
44-
await expect(resolveBrowserDefaults()).rejects.toBe(failure);
45-
await expect(resolveBrowserDefaults()).resolves.toMatchObject({
46-
viewport: { _tag: "fill" },
47-
zoomFactor: 1.25,
48-
appearance: "dark",
49-
autoShowFloatingPreview: true,
50-
profileId: "work",
51-
});
52-
});
53-
});

‎apps/web/src/browser/browserTargetResolver.test.ts‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,20 +128,6 @@ describe("browser target resolver", () => {
128128
}
129129
});
130130

131-
it("supports private IPv6 environment hosts", async () => {
132-
readPreparedConnection.mockReturnValue({
133-
httpBaseUrl: "http://[fd7a:115c:a1e0::53]:3773",
134-
});
135-
const { resolveBrowserNavigationTarget } = await import("./browserTargetResolver");
136-
expect(
137-
resolveBrowserNavigationTarget(EnvironmentId.make("environment-1"), {
138-
kind: "environment-port",
139-
port: 5173,
140-
path: "/app?mode=test",
141-
}).resolvedUrl,
142-
).toBe("http://[fd7a:115c:a1e0::53]:5173/app?mode=test");
143-
});
144-
145131
it("classifies exact private IPv4 and IPv6 boundaries", async () => {
146132
const { isPrivateNetworkHost } = await import("./browserTargetResolver");
147133
const privateHosts = [

‎apps/web/src/browserFaviconStore.test.ts‎

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ import {
1010
lookupFavicon,
1111
recordFaviconForProject,
1212
recordFaviconForThread,
13-
registerFaviconProjectForThread,
1413
resetBrowserFaviconsForTests,
1514
resolveBrowserFaviconStorage,
1615
useBrowserFaviconStore,
1716
} from "./browserFaviconStore";
18-
import { BROWSER_FAVICON_MAX_ENTRIES } from "./browserFaviconLogic";
1917

2018
const environmentId = EnvironmentId.make("env-1");
2119
const projectRef = scopeProjectRef(environmentId, ProjectId.make("project-1"));
@@ -69,60 +67,6 @@ describe("browser favicon store", () => {
6967
).toBeNull();
7068
});
7169

72-
it("keeps exact host aliases attached to the newest canonical icon", () => {
73-
const olderPng = "data:image/png;base64,QkJCQg==";
74-
const newerPng = "data:image/png;base64,Q0NDQw==";
75-
recordFaviconForProject(
76-
projectRef,
77-
favicon("http://192.168.64.2:3000/", 10, olderPng),
78-
"192.168.64.2",
79-
);
80-
recordFaviconForProject(
81-
projectRef,
82-
favicon("http://192.168.64.3:3000/", 20, newerPng),
83-
"192.168.64.3",
84-
);
85-
recordFaviconForProject(
86-
projectRef,
87-
favicon("http://192.168.64.4:3000/", 15, olderPng),
88-
"192.168.64.4",
89-
);
90-
const byKey = useBrowserFaviconStore.getState().byKey;
91-
for (const host of ["192.168.64.2", "192.168.64.3", "192.168.64.4"]) {
92-
expect(lookupFavicon(byKey, projectRef, `http://${host}:3000/`, null)).toBe(newerPng);
93-
}
94-
expect(byKey["env-1:project-1 http://localhost:3000"]?.capturedAt).toBe(20);
95-
});
96-
97-
it("evicts an icon and its exact host aliases atomically", () => {
98-
recordFaviconForProject(projectRef, favicon("http://192.168.64.2:3000/", 100), "192.168.64.2");
99-
for (let index = 1; index < BROWSER_FAVICON_MAX_ENTRIES; index += 1) {
100-
recordFaviconForProject(
101-
projectRef,
102-
favicon(`https://example-${index}.com/`, 100 + index),
103-
null,
104-
);
105-
}
106-
expect(
107-
lookupFavicon(
108-
useBrowserFaviconStore.getState().byKey,
109-
projectRef,
110-
"http://192.168.64.2:3000/",
111-
null,
112-
),
113-
).toBe(PNG);
114-
115-
recordFaviconForProject(projectRef, favicon("https://evicts-oldest.example/", 1_000), null);
116-
expect(
117-
lookupFavicon(
118-
useBrowserFaviconStore.getState().byKey,
119-
projectRef,
120-
"http://192.168.64.2:3000/",
121-
null,
122-
),
123-
).toBeNull();
124-
});
125-
12670
it("retains multiple origins until project and connection metadata hydrate", () => {
12771
expect(
12872
recordFaviconForThread(threadRef, favicon("http://localhost:3000/", 1), null, undefined),
@@ -165,22 +109,6 @@ describe("browser favicon store", () => {
165109
expect(Object.values(useBrowserFaviconStore.getState().pendingByThreadKey)[0]).toBeDefined();
166110
});
167111

168-
it("flushes and resolves a pending draft-thread favicon after physical project registration", () => {
169-
recordFaviconForThread(threadRef, favicon("http://localhost:8025/", 10), null, undefined);
170-
registerFaviconProjectForThread(threadRef, projectRef);
171-
const registered = useBrowserFaviconStore.getState().projectRefByThreadKey["env-1:thread-1"];
172-
expect(registered).toEqual(projectRef);
173-
expect(flushPendingFaviconsForThread(threadRef, registered!, undefined)).toBe(true);
174-
expect(
175-
lookupFavicon(
176-
useBrowserFaviconStore.getState().byKey,
177-
registered!,
178-
"http://localhost:8025/",
179-
null,
180-
),
181-
).toBe(PNG);
182-
});
183-
184112
it("keeps the memory shadow authoritative after an asymmetric primary write failure", () => {
185113
vi.stubGlobal("window", {
186114
localStorage: {

‎apps/web/src/browserHistoryStore.test.ts‎

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ describe("normalizeHistoryUrl", () => {
3535
);
3636
});
3737

38-
it("normalizes bare public hosts to https", () => {
39-
expect(normalizeHistoryUrl("myapp.test")).toBe("https://myapp.test/");
40-
});
41-
4238
it("preserves hash routes and strips credentials", () => {
4339
expect(normalizeHistoryUrl("http://localhost:3000/app#/route")).toBe(
4440
"http://localhost:3000/app#/route",
@@ -54,17 +50,6 @@ describe("normalizeHistoryUrl", () => {
5450
});
5551

5652
describe("upsertHistoryEntry", () => {
57-
it("moves revisits to front, updates the timestamp, and keeps the title", () => {
58-
const existing = [
59-
entry({ url: "http://a.test/", lastVisitedAt: 500, title: "A" }),
60-
entry({ url: "http://b.test/", lastVisitedAt: 400 }),
61-
];
62-
const next = upsertHistoryEntry(existing, "http://b.test/", 3000);
63-
expect(next.map((e) => e.url)).toEqual(["http://b.test/", "http://a.test/"]);
64-
expect(next[0]?.lastVisitedAt).toBe(3000);
65-
expect(next[1]?.title).toBe("A");
66-
});
67-
6853
it("with insertOrdered, replaying an older visit for an existing entry keeps its newer timestamp", () => {
6954
const existing = [entry({ url: "http://a.test/", lastVisitedAt: 2000 })];
7055
const next = upsertHistoryEntry(existing, "http://a.test/", 1000, { insertOrdered: true });
@@ -128,14 +113,6 @@ describe("useBrowserHistoryStore", () => {
128113
resetBrowserHistoryForTests();
129114
});
130115

131-
it("records visits for registered threads under the project key", () => {
132-
useBrowserHistoryStore.getState().registerThreadProject(threadRef, "proj-a");
133-
recordVisitForThread(threadRef, "myapp.test/admin#section", 1234);
134-
expect(useBrowserHistoryStore.getState().byProjectKey["proj-a"]).toEqual([
135-
{ url: "https://myapp.test/admin#section", lastVisitedAt: 1234 },
136-
]);
137-
});
138-
139116
it("sets titles update-only via the thread helper", () => {
140117
useBrowserHistoryStore.getState().registerThreadProject(threadRef, "proj-a");
141118
setTitleForThreadUrl(threadRef, "http://a.test/", "Should not create");
@@ -187,13 +164,6 @@ describe("useBrowserHistoryStore", () => {
187164
{ url: "http://localhost:5173/app", lastVisitedAt: 5 },
188165
]);
189166
});
190-
191-
it("does not match a genuinely different path via the trailing-slash comparison", () => {
192-
useBrowserHistoryStore.getState().registerThreadProject(threadRef, "proj-a");
193-
recordVisitForThread(threadRef, "http://a.test/community", 1);
194-
setTitleForThreadUrl(threadRef, "http://a.test/community/foo", "Foo");
195-
expect(useBrowserHistoryStore.getState().byProjectKey["proj-a"]?.[0]?.title).toBeUndefined();
196-
});
197167
});
198168

199169
describe("pendingVisitsByThreadKey", () => {

‎apps/web/src/bundledDev.test.ts‎

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import react from "@vitejs/plugin-react";
1010
import { createServer } from "vite-plus";
1111
import { expect, it } from "vite-plus/test";
1212

13-
import { warmLazyEntries } from "../vite/warmBundledDev";
14-
1513
const execFile = NodeUtil.promisify(NodeChildProcess.execFile);
1614

1715
it("initializes React refresh before a shared UI chunk runs in bundled dev", async () => {
@@ -120,42 +118,3 @@ console.log("App started with React refresh ready.");`,
120118
await NodeFSP.rm(root, { recursive: true, force: true });
121119
}
122120
});
123-
124-
it("warms the wanted lazy chunk chain and nothing else", async () => {
125-
const root = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-warm-"));
126-
let server: Awaited<ReturnType<typeof createServer>> | undefined;
127-
128-
try {
129-
await NodeFSP.mkdir(NodePath.join(root, "src"));
130-
await NodeFSP.writeFile(
131-
NodePath.join(root, "index.html"),
132-
'<html><body><script type="module" src="/src/bootstrap.ts"></script></body></html>',
133-
);
134-
await NodeFSP.writeFile(NodePath.join(root, "src/bootstrap.ts"), 'void import("./main");');
135-
await NodeFSP.writeFile(
136-
NodePath.join(root, "src/main.ts"),
137-
'export const route = () => import("./route"); export const rare = () => import("./rare");',
138-
);
139-
await NodeFSP.writeFile(NodePath.join(root, "src/route.ts"), "export const route = 1;");
140-
await NodeFSP.writeFile(NodePath.join(root, "src/rare.ts"), "export const rare = 1;");
141-
142-
server = await createServer({
143-
configFile: false,
144-
root,
145-
logLevel: "silent",
146-
experimental: { bundledDev: true },
147-
server: { host: "127.0.0.1", port: 0 },
148-
});
149-
await server.listen();
150-
151-
// The route is only discoverable after main compiles, so this also covers the pass walk.
152-
const warmed = await warmLazyEntries(server, ["src/main.ts", "src/route.ts"]);
153-
expect(warmed.map((id) => NodePath.relative(root, id.split("?")[0] ?? id))).toEqual([
154-
"src/main.ts",
155-
"src/route.ts",
156-
]);
157-
} finally {
158-
await server?.close();
159-
await NodeFSP.rm(root, { recursive: true, force: true });
160-
}
161-
});

‎apps/web/src/closedViewStore.test.ts‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,6 @@ const snapshot: PreviewSessionSnapshot = {
2929
};
3030

3131
describe("closedViewStore", () => {
32-
it.each([null, {}, { entries: null }, { entries: {} }, { entries: "invalid" }])(
33-
"rehydrates malformed older history %j as empty history",
34-
async (state) => {
35-
useClosedViewStore.getState().remember(diff(refA));
36-
const { storage, name } = useClosedViewStore.persist.getOptions();
37-
await storage!.setItem(name!, {
38-
state: state as { entries: ClosedViewEntry[] },
39-
version: 0,
40-
});
41-
await useClosedViewStore.persist.rehydrate();
42-
expect(useClosedViewStore.persist.hasHydrated()).toBe(true);
43-
expect(useClosedViewStore.getState().entries).toEqual([]);
44-
expect(await storage!.getItem(name!)).toEqual({ state: { entries: [] }, version: 2 });
45-
},
46-
);
47-
4832
it.each([
4933
{ id: "bad", kind: "browser", threadRef: refA, snapshot: {} },
5034
{

‎apps/web/src/composer-code-block.test.ts‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,6 @@ describe("indentedNewlineInCodeBlock", () => {
6363
indentedNewlineInCodeBlock(editor.state, (tr) => editor.view.dispatch(tr));
6464
expect(textOf(editor)).toBe(" deep()\n \nflush()");
6565
});
66-
67-
it("does nothing outside a code block", () => {
68-
const editor = new Editor({
69-
extensions,
70-
content: {
71-
type: "doc",
72-
content: [{ type: "paragraph", content: [{ type: "text", text: " hi" }] }],
73-
},
74-
});
75-
expect(indentedNewlineInCodeBlock(editor.state, (tr) => editor.view.dispatch(tr))).toBe(false);
76-
});
7766
});
7867

7968
function pressEnter(editor: Editor) {
@@ -96,16 +85,6 @@ describe("exitCodeBlockOnTrailingBlankLines", () => {
9685
expect(editor.state.selection.$from.parent.type.name).toBe("paragraph");
9786
});
9887

99-
it("counts lines holding only carried indentation as blank", () => {
100-
const editor = codeEditor(" nested()");
101-
pressEnter(editor);
102-
pressEnter(editor);
103-
expect(editor.state.doc.childCount).toBe(1);
104-
pressEnter(editor);
105-
expect(editor.state.doc.firstChild?.textContent).toBe(" nested()");
106-
expect(editor.state.selection.$from.parent.type.name).toBe("paragraph");
107-
});
108-
10988
it("closes an unclosed fence on the way out", () => {
11089
const editor = codeEditor("flush()");
11190
editor.view.dispatch(editor.state.tr.setNodeAttribute(0, "close", ""));

‎apps/web/src/composer-editor-mentions.test.ts‎

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,6 @@ describe("splitPromptIntoComposerSegments", () => {
4949
]);
5050
});
5151

52-
it("keeps newlines around mention tokens", () => {
53-
expect(splitPromptIntoComposerSegments("one\[email protected] \ntwo")).toEqual([
54-
{ type: "text", text: "one\n" },
55-
{ type: "mention", path: "AGENTS.md", source: "@AGENTS.md" },
56-
{ type: "text", text: " \ntwo" },
57-
]);
58-
});
59-
6052
it("splits quoted mention tokens containing whitespace", () => {
6153
expect(splitPromptIntoComposerSegments('Inspect @"My File.md" please')).toEqual([
6254
{ type: "text", text: "Inspect " },
@@ -181,11 +173,6 @@ describe("splitPromptIntoComposerSegments", () => {
181173
},
182174
);
183175

184-
it("keeps IME-composed text containing a scoped package reference as text", () => {
185-
const prompt = "入力 @expo/ui を追加";
186-
expect(splitPromptIntoComposerSegments(prompt)).toEqual([{ type: "text", text: prompt }]);
187-
});
188-
189176
it("turns canonical scoped folder links into file mention segments", () => {
190177
expect(splitPromptIntoComposerSegments("Inspect [sub](@scope/pkg/sub) next")).toEqual([
191178
{ type: "text", text: "Inspect " },
@@ -256,17 +243,6 @@ describe("splitPromptIntoComposerSegments", () => {
256243
{ type: "text", text: " please" },
257244
]);
258245
});
259-
260-
it("preserves consecutive context references without dropping positions", () => {
261-
expect(splitPromptIntoComposerSegments(`${terminalReference}${terminalReference}tail`)).toEqual(
262-
[terminalSegment, terminalSegment, { type: "text", text: "tail" }],
263-
);
264-
});
265-
266-
it("leaves a context link with an unparsable href as text", () => {
267-
const prompt = "see [x](t3-context://v1/terminal/ctx 1) now";
268-
expect(splitPromptIntoComposerSegments(prompt)).toEqual([{ type: "text", text: prompt }]);
269-
});
270246
});
271247

272248
describe("selectionTouchesMentionBoundary", () => {
@@ -286,16 +262,6 @@ describe("selectionTouchesMentionBoundary", () => {
286262
).toBe(true);
287263
});
288264

289-
it("returns true when selection includes the whitespace before a mention", () => {
290-
expect(
291-
selectionTouchesMentionBoundary(
292-
"hi there @package.json later",
293-
"hi there".length,
294-
"hi there ".length,
295-
),
296-
).toBe(true);
297-
});
298-
299265
it("returns false when selection starts after the mention boundary whitespace", () => {
300266
expect(
301267
selectionTouchesMentionBoundary(
@@ -306,6 +272,7 @@ describe("selectionTouchesMentionBoundary", () => {
306272
).toBe(false);
307273
});
308274

275+
// regression: #2625 mentions with spaces are quoted; selection checks must span the quotes
309276
it("returns true when selection includes whitespace after a quoted mention", () => {
310277
expect(
311278
selectionTouchesMentionBoundary(

0 commit comments

Comments
 (0)