Skip to content

Commit dde8667

Browse files
zachdunnclaude
andauthored
chore(tests): trim low-value tests (batch 2) (#608)
- Drop redundant error-branch tests in embed-releases / embed-entities (same contract is covered in embed-changelog-pipeline) - Replace local selectChangelog helper with canonical selectChangelogFile from @buildinternet/releases-core - Drop redundant cacheControl, log-search MCP, workflows-ai model-pin, and workflows-embed unobservable-clamp tests - Drop CATEGORIES dup in managed-discovery (covered in categories.test) - Drop tautological hash determinism test and a redundant isSeedRun case ~241 LOC removed across 10 files. Closes #606. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 5bd3342 commit dde8667

10 files changed

Lines changed: 35 additions & 280 deletions

packages/search/src/embed-entities.test.ts

Lines changed: 4 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ function fakeVoyageFetch() {
1919
return { fetchImpl, calls };
2020
}
2121

22-
function fakeVectorize(opts: { upsertThrows?: boolean } = {}) {
22+
function fakeVectorize() {
2323
const upserted: any[] = [];
2424
const index: VectorizeIndex = {
2525
async upsert(v: any[]) {
26-
if (opts.upsertThrows) throw new Error("vec down");
2726
upserted.push(...v);
2827
return { mutationId: "m1" };
2928
},
@@ -37,15 +36,6 @@ function fakeVectorize(opts: { upsertThrows?: boolean } = {}) {
3736
return { index, upserted };
3837
}
3938

40-
function captureLogger() {
41-
const warns: string[] = [];
42-
return {
43-
warn: (...args: unknown[]) => warns.push(args.map(String).join(" ")),
44-
error: (..._args: unknown[]) => {},
45-
warns,
46-
};
47-
}
48-
4939
describe("embedAndUpsertEntities", () => {
5040
test("empty input short-circuits", async () => {
5141
const { fetchImpl, calls } = fakeVoyageFetch();
@@ -151,56 +141,7 @@ describe("embedAndUpsertEntities", () => {
151141
expect(persisted).toEqual([["org_1", "org_2"]]);
152142
});
153143

154-
test("embed failure → logs, no upsert, no onPersisted", async () => {
155-
const fetchImpl = (async () => new Response("err", { status: 400 })) as unknown as typeof fetch;
156-
const vec = fakeVectorize();
157-
const logger = captureLogger();
158-
let persistedCalled = false;
159-
await embedAndUpsertEntities({
160-
entities: [{ id: "org_1", kind: "org", name: "x" }],
161-
vectorIndex: vec.index,
162-
embedConfig: { provider: "voyage", apiKey: "k", fetchImpl, maxRetries: 0 },
163-
onPersisted: async () => {
164-
persistedCalled = true;
165-
},
166-
logger,
167-
});
168-
expect(vec.upserted.length).toBe(0);
169-
expect(persistedCalled).toBe(false);
170-
expect(logger.warns.some((w) => w.includes("embed pipeline failed"))).toBe(true);
171-
});
172-
173-
test("upsert failure → logs, no onPersisted", async () => {
174-
const { fetchImpl } = fakeVoyageFetch();
175-
const vec = fakeVectorize({ upsertThrows: true });
176-
const logger = captureLogger();
177-
let persistedCalled = false;
178-
await embedAndUpsertEntities({
179-
entities: [{ id: "org_1", kind: "org", name: "x" }],
180-
vectorIndex: vec.index,
181-
embedConfig: { provider: "voyage", apiKey: "k", fetchImpl },
182-
onPersisted: async () => {
183-
persistedCalled = true;
184-
},
185-
logger,
186-
});
187-
expect(persistedCalled).toBe(false);
188-
expect(logger.warns.some((w) => w.includes("Vectorize upsert failed"))).toBe(true);
189-
});
190-
191-
test("onPersisted failure is caught and logged", async () => {
192-
const { fetchImpl } = fakeVoyageFetch();
193-
const vec = fakeVectorize();
194-
const logger = captureLogger();
195-
await embedAndUpsertEntities({
196-
entities: [{ id: "org_1", kind: "org", name: "x" }],
197-
vectorIndex: vec.index,
198-
embedConfig: { provider: "voyage", apiKey: "k", fetchImpl },
199-
onPersisted: async () => {
200-
throw new Error("db down");
201-
},
202-
logger,
203-
});
204-
expect(logger.warns.some((w) => w.includes("onPersisted callback failed"))).toBe(true);
205-
});
144+
// Embed/upsert/onPersisted error-branch coverage lives in
145+
// embed-changelog-pipeline.test.ts — the same swallow-and-log contract
146+
// applies across all three pipelines.
206147
});

packages/search/src/embed-releases.test.ts

Lines changed: 4 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,11 @@ function fakeVoyageFetch() {
2424
return { fetchImpl, calls };
2525
}
2626

27-
function fakeVectorize(
28-
opts: {
29-
upsertThrows?: boolean;
30-
} = {},
31-
) {
27+
function fakeVectorize() {
3228
const upserted: any[] = [];
3329
const deleted: string[] = [];
3430
const index: VectorizeIndex = {
3531
async upsert(v: any[]) {
36-
if (opts.upsertThrows) throw new Error("vectorize boom");
3732
upserted.push(...v);
3833
return { mutationId: "m1" };
3934
},
@@ -48,17 +43,6 @@ function fakeVectorize(
4843
return { index, upserted, deleted };
4944
}
5045

51-
function captureLogger() {
52-
const warns: string[] = [];
53-
const errors: string[] = [];
54-
return {
55-
warn: (...args: unknown[]) => warns.push(args.map(String).join(" ")),
56-
error: (...args: unknown[]) => errors.push(args.map(String).join(" ")),
57-
warns,
58-
errors,
59-
};
60-
}
61-
6246
const baseRelease: EmbedReleaseInput = {
6347
id: "rel_1",
6448
title: "v1.0",
@@ -160,59 +144,9 @@ describe("embedAndUpsertReleases", () => {
160144
expect(meta.release_type).toBe("feature");
161145
});
162146

163-
test("embedding failure → logs, does NOT throw, does NOT call onPersisted", async () => {
164-
const fetchImpl = (async () =>
165-
new Response("nope", { status: 400 })) as unknown as typeof fetch;
166-
const vec = fakeVectorize();
167-
const logger = captureLogger();
168-
let persistedCalled = false;
169-
await embedAndUpsertReleases({
170-
releases: [baseRelease],
171-
vectorIndex: vec.index,
172-
embedConfig: { provider: "voyage", apiKey: "k", fetchImpl, maxRetries: 0 },
173-
onPersisted: async () => {
174-
persistedCalled = true;
175-
},
176-
logger,
177-
});
178-
expect(vec.upserted.length).toBe(0);
179-
expect(persistedCalled).toBe(false);
180-
expect(logger.warns.some((w) => w.includes("embed pipeline failed"))).toBe(true);
181-
});
182-
183-
test("upsert failure → logs, does NOT throw, does NOT call onPersisted", async () => {
184-
const { fetchImpl } = fakeVoyageFetch();
185-
const vec = fakeVectorize({ upsertThrows: true });
186-
const logger = captureLogger();
187-
let persistedCalled = false;
188-
await embedAndUpsertReleases({
189-
releases: [baseRelease],
190-
vectorIndex: vec.index,
191-
embedConfig: { provider: "voyage", apiKey: "k", fetchImpl },
192-
onPersisted: async () => {
193-
persistedCalled = true;
194-
},
195-
logger,
196-
});
197-
expect(persistedCalled).toBe(false);
198-
expect(logger.warns.some((w) => w.includes("Vectorize upsert failed"))).toBe(true);
199-
});
200-
201-
test("onPersisted callback failure is caught and logged", async () => {
202-
const { fetchImpl } = fakeVoyageFetch();
203-
const vec = fakeVectorize();
204-
const logger = captureLogger();
205-
await embedAndUpsertReleases({
206-
releases: [baseRelease],
207-
vectorIndex: vec.index,
208-
embedConfig: { provider: "voyage", apiKey: "k", fetchImpl },
209-
onPersisted: async () => {
210-
throw new Error("db down");
211-
},
212-
logger,
213-
});
214-
expect(logger.warns.some((w) => w.includes("onPersisted callback failed"))).toBe(true);
215-
});
147+
// Embed/upsert/onPersisted error-branch coverage lives in
148+
// embed-changelog-pipeline.test.ts — the same swallow-and-log contract
149+
// applies across all three pipelines.
216150

217151
test("multi-release batch: ids in order, each gets its own vector slot", async () => {
218152
const { fetchImpl } = fakeVoyageFetch();

tests/api/changelog-route.test.ts

Lines changed: 23 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { describe, it, expect, beforeAll, afterAll } from "bun:test";
2-
import { buildChangelogResponse } from "@buildinternet/releases-core/changelog-slice";
2+
import {
3+
buildChangelogResponse,
4+
selectChangelogFile,
5+
} from "@buildinternet/releases-core/changelog-slice";
36
import { createTestDb, type TestDatabase } from "../db-helper.js";
47
import { eq } from "drizzle-orm";
58
import {
@@ -9,35 +12,16 @@ import {
912
type SourceChangelogFile,
1013
} from "@buildinternet/releases-core/schema";
1114

12-
// This test mirrors the server-side logic of `handleSourceChangelog`
13-
// (src/api/routes/sources.ts) and `GET /v1/sources/:slug/changelog` in
14-
// workers/api/src/routes/sources.ts without going through the getDb()
15-
// singleton — both handlers share the same resolution rules:
16-
// - omitted path → prefer root CHANGELOG.md, fall back to first by path
17-
// - unknown path → 404 sentinel
18-
// - known path → return that row
19-
// - response carries `files` index + `truncated` flag
20-
// Touching the singleton requires resetting mode.ts caches, which is
21-
// brittle across parallel test files.
15+
// This test exercises the response-building path used by both
16+
// `handleSourceChangelog` (src/api/routes/sources.ts) and
17+
// `GET /v1/sources/:slug/changelog` (workers/api/src/routes/sources.ts).
18+
// It uses the canonical `selectChangelogFile` from the core package to pick
19+
// the row, then asserts on the `buildChangelogResponse` output — the part
20+
// that's unique to the worker layer. The not-found sentinels are covered
21+
// by the core package's own tests.
2222

2323
const MB = 1024 * 1024;
2424

25-
type ChangelogSelectResult = "not_found_source" | "not_found_path" | SourceChangelogFile;
26-
27-
function selectChangelog(
28-
allRows: SourceChangelogFile[],
29-
requestedPath: string | null,
30-
): ChangelogSelectResult {
31-
if (allRows.length === 0) return "not_found_source";
32-
if (requestedPath) {
33-
const match = allRows.find((r) => r.path === requestedPath);
34-
if (!match) return "not_found_path";
35-
return match;
36-
}
37-
const root = allRows.find((r) => !r.path.includes("/"));
38-
return root ?? allRows[0];
39-
}
40-
4125
let tdb: TestDatabase;
4226
let sourceId: string;
4327

@@ -104,22 +88,24 @@ function buildFiles(rows: SourceChangelogFile[]) {
10488
}));
10589
}
10690

91+
function selectOrFail(rows: SourceChangelogFile[], path: string | null): SourceChangelogFile {
92+
const selected = selectChangelogFile(rows, path);
93+
if (!selected) throw new Error("expected row");
94+
return selected;
95+
}
96+
10797
describe("source changelog route resolution", () => {
10898
it("returns the root file when path is omitted", () => {
10999
const rows = fetchAll();
110-
const selected = selectChangelog(rows, null);
111-
expect(selected).not.toBe("not_found_source");
112-
expect(selected).not.toBe("not_found_path");
113-
if (typeof selected === "string") return;
100+
const selected = selectOrFail(rows, null);
114101
const res = buildChangelogResponse(selected, { offset: null, limit: null }, buildFiles(rows));
115102
expect(res.path).toBe("CHANGELOG.md");
116103
expect(res.truncated).toBe(false);
117104
});
118105

119106
it("includes a files index for every tracked file", () => {
120107
const rows = fetchAll();
121-
const selected = selectChangelog(rows, null);
122-
if (typeof selected === "string") throw new Error("expected row");
108+
const selected = selectOrFail(rows, null);
123109
const res = buildChangelogResponse(selected, { offset: null, limit: null }, buildFiles(rows));
124110
expect(res.files.map((f) => f.path).toSorted()).toEqual([
125111
"CHANGELOG.md",
@@ -133,36 +119,23 @@ describe("source changelog route resolution", () => {
133119

134120
it("resolves path=<known> to the requested file", () => {
135121
const rows = fetchAll();
136-
const selected = selectChangelog(rows, "packages/alpha/CHANGELOG.md");
137-
if (typeof selected === "string") throw new Error("expected row");
122+
const selected = selectOrFail(rows, "packages/alpha/CHANGELOG.md");
138123
const res = buildChangelogResponse(selected, { offset: null, limit: null }, buildFiles(rows));
139124
expect(res.path).toBe("packages/alpha/CHANGELOG.md");
140125
expect(res.content).toBe("# alpha\n");
141126
});
142127

143-
it("returns not_found_path for an unknown path", () => {
144-
const rows = fetchAll();
145-
const selected = selectChangelog(rows, "packages/missing/CHANGELOG.md");
146-
expect(selected).toBe("not_found_path");
147-
});
148-
149128
it("flags truncated=true when bytes === 1MB", () => {
150129
const rows = fetchAll();
151-
const selected = selectChangelog(rows, "packages/huge/CHANGELOG.md");
152-
if (typeof selected === "string") throw new Error("expected row");
130+
const selected = selectOrFail(rows, "packages/huge/CHANGELOG.md");
153131
const res = buildChangelogResponse(selected, { offset: null, limit: null }, buildFiles(rows));
154132
expect(res.truncated).toBe(true);
155133
expect(res.truncatedAt).toBe(MB);
156134
});
157135

158-
it("returns not_found_source for empty row set", () => {
159-
expect(selectChangelog([], null)).toBe("not_found_source");
160-
});
161-
162136
it("falls back to live encoding when row.tokens is null", () => {
163137
const rows = fetchAll();
164-
const selected = selectChangelog(rows, "CHANGELOG.md");
165-
if (typeof selected === "string") throw new Error("expected row");
138+
const selected = selectOrFail(rows, "CHANGELOG.md");
166139
const res = buildChangelogResponse(
167140
{ ...selected, tokens: null },
168141
{ offset: null, limit: null },
@@ -175,8 +148,7 @@ describe("source changelog route resolution", () => {
175148

176149
it("honors the tokens range param end-to-end through buildChangelogResponse", () => {
177150
const rows = fetchAll();
178-
const selected = selectChangelog(rows, "CHANGELOG.md");
179-
if (typeof selected === "string") throw new Error("expected row");
151+
const selected = selectOrFail(rows, "CHANGELOG.md");
180152
const res = buildChangelogResponse(
181153
selected,
182154
{ offset: null, limit: null, tokens: "100" },

tests/api/log-search.test.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,15 @@ describe("prepareSearchLogRow", () => {
8080
});
8181

8282
describe("prepareMcpSearchLogRow", () => {
83-
it("defaults the types array to the command name", () => {
83+
// Generic shape (truncation, blank check, mode validation) is covered by
84+
// prepareSearchLogRow above. The MCP variant only adds one unique branch:
85+
// the `types` array defaults to the command name when not supplied.
86+
it("defaults the types array to the command name and pins surface=mcp", () => {
8487
const row = prepareMcpSearchLogRow({
8588
command: "search",
8689
query: "vercel",
8790
});
8891
expect(row!.types).toBe(JSON.stringify(["search"]));
8992
expect(row!.surface).toBe("mcp");
9093
});
91-
92-
it("preserves an explicit types array", () => {
93-
const row = prepareMcpSearchLogRow({
94-
command: "search_releases",
95-
query: "vercel",
96-
types: ["search_releases", "releases"],
97-
});
98-
expect(row!.types).toBe(JSON.stringify(["search_releases", "releases"]));
99-
});
100-
101-
it("returns null for blank queries", () => {
102-
expect(prepareMcpSearchLogRow({ command: "search", query: " " })).toBeNull();
103-
});
10494
});

tests/api/middleware.test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,6 @@ describe("cacheControl", () => {
154154
expect(res.headers.get("Cache-Control")).toBe("public, max-age=120");
155155
});
156156

157-
it("uses private visibility by default", async () => {
158-
const { app, env } = createApp(60);
159-
const res = await app.request("/test", { method: "GET" }, env);
160-
expect(res.headers.get("Cache-Control")).toContain("private");
161-
});
162-
163157
it("skips caching when CACHE_DISABLED is set", async () => {
164158
const { app } = createApp(60);
165159
const res = await app.request("/test", { method: "GET" }, { CACHE_DISABLED: "1" });

tests/unit/hash.test.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@ describe("sha256Hex", () => {
77
expect(result).toMatch(/^[a-f0-9]{64}$/);
88
});
99

10-
it("returns deterministic results", () => {
11-
expect(sha256Hex("test")).toBe(sha256Hex("test"));
12-
});
13-
14-
it("returns different hashes for different inputs", () => {
15-
expect(sha256Hex("a")).not.toBe(sha256Hex("b"));
16-
});
17-
1810
it("handles empty string", () => {
1911
const result = sha256Hex("");
2012
expect(result).toMatch(/^[a-f0-9]{64}$/);

0 commit comments

Comments
 (0)