Skip to content

Commit 5d1bb95

Browse files
committed
chore(tests): consolidate unit tests subsumed by property tests
Remove ~620 lines of unit tests that duplicate invariants already covered by companion property-based tests. Each unit test file now has a header comment documenting which invariants are in the property file and what remains in the unit file. Files trimmed: - test/lib/dsn.test.ts: Remove extractOrgIdFromHost, parseDsn (basic), isValidDsn, createDsnFingerprint (ordering/dedup), createDetectedDsn (basic) — all covered by dsn.property.test.ts. Keep: self-hosted DSN fingerprints, trailing slash edge case, path segments, packagePath. - test/lib/promises.test.ts: Remove basic true/false/error tests — covered by promises.property.test.ts. Keep: concurrency timing tests, single-resolution guarantee. - test/lib/bspatch.test.ts: Remove offtin unit tests and parsePatchHeader rejection tests — covered by bspatch.property.test.ts. Keep: fixture- based patch application, SHA-256 verification, truncated patch. - test/lib/db/auth.test.ts: Remove priority, source tracking, refresh skip, isEnvTokenActive basics — covered by auth.property.test.ts. Keep: whitespace edge cases, isAuthenticated, getActiveEnvVarName, shape assertions. - test/lib/formatters/json.test.ts: Remove filterFields basics and parseFieldsList dedup/whitespace — covered by json.property.test.ts. Keep: dot-notation edge cases, null/undefined in objects, writeJson, writeJsonList, formatJson APIs. - test/lib/formatters/trace.test.ts: Remove redundant newline/contains checks — covered by trace.property.test.ts. Keep: specific format values, rendered vs plain mode, computeTraceSummary edge cases.
1 parent a6d62d7 commit 5d1bb95

File tree

6 files changed

+56
-620
lines changed

6 files changed

+56
-620
lines changed

test/lib/bspatch.test.ts

Lines changed: 13 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
/**
22
* Unit Tests for TRDIFF10 Binary Patch Application
33
*
4+
* Note: Core invariants (offtin sign/magnitude, parsePatchHeader rejection rules)
5+
* are tested via property-based tests in bspatch.property.test.ts. These tests
6+
* focus on real fixture-based patch application and error messages.
7+
*
48
* Tests the bspatch implementation against real TRDIFF10 patches
59
* generated by zig-bsdiff v0.1.19 (stored as test fixtures).
610
*/
@@ -9,87 +13,11 @@ import { describe, expect, test } from "bun:test";
913
import { unlinkSync } from "node:fs";
1014
import { tmpdir } from "node:os";
1115
import { join } from "node:path";
12-
import { applyPatch, offtin, parsePatchHeader } from "../../src/lib/bspatch.js";
16+
import { applyPatch, parsePatchHeader } from "../../src/lib/bspatch.js";
1317

1418
const FIXTURES_DIR = join(import.meta.dir, "../fixtures/patches");
1519

16-
describe("offtin", () => {
17-
test("reads zero", () => {
18-
const buf = new Uint8Array(8);
19-
expect(offtin(buf, 0)).toBe(0);
20-
});
21-
22-
test("reads positive value 1", () => {
23-
const buf = new Uint8Array(8);
24-
buf[0] = 1; // LE: least significant byte
25-
expect(offtin(buf, 0)).toBe(1);
26-
});
27-
28-
test("reads positive value 256", () => {
29-
const buf = new Uint8Array(8);
30-
buf[1] = 1; // 256 in LE
31-
expect(offtin(buf, 0)).toBe(256);
32-
});
33-
34-
test("reads negative value -1", () => {
35-
// zig-bsdiff sign-magnitude: magnitude=1, sign bit set in byte 7
36-
const buf = new Uint8Array(8);
37-
buf[0] = 1;
38-
buf[7] = 0x80; // Sign bit
39-
expect(offtin(buf, 0)).toBe(-1);
40-
});
41-
42-
test("reads negative value -256", () => {
43-
const buf = new Uint8Array(8);
44-
buf[1] = 1; // magnitude = 256
45-
buf[7] = 0x80;
46-
expect(offtin(buf, 0)).toBe(-256);
47-
});
48-
49-
test("reads from offset", () => {
50-
const buf = new Uint8Array(16);
51-
buf[8] = 42;
52-
expect(offtin(buf, 8)).toBe(42);
53-
});
54-
55-
test("reads large positive value", () => {
56-
const buf = new Uint8Array(8);
57-
// 0x01_00_00_00 = 16,777,216 in LE: byte 3 = 0x01
58-
buf[3] = 1;
59-
expect(offtin(buf, 0)).toBe(16_777_216);
60-
});
61-
62-
test("reads value spanning both 32-bit halves", () => {
63-
const buf = new Uint8Array(8);
64-
// Low 32 bits: 0
65-
// High 32 bits: 1 → value = 1 * 2^32 = 4,294,967,296
66-
buf[4] = 1;
67-
expect(offtin(buf, 0)).toBe(4_294_967_296);
68-
});
69-
});
70-
71-
describe("parsePatchHeader", () => {
72-
test("rejects too-small buffer", () => {
73-
expect(() => parsePatchHeader(new Uint8Array(31))).toThrow(
74-
"Patch too small"
75-
);
76-
});
77-
78-
test("rejects invalid magic", () => {
79-
const buf = new Uint8Array(32);
80-
buf.set(new TextEncoder().encode("BSDIFF40"));
81-
expect(() => parsePatchHeader(buf)).toThrow("Invalid patch format");
82-
});
83-
84-
test("rejects negative header values", () => {
85-
const buf = new Uint8Array(32);
86-
buf.set(new TextEncoder().encode("TRDIFF10"));
87-
// Set controlLen to -1 (sign bit in byte 15)
88-
buf[8] = 1;
89-
buf[15] = 0x80;
90-
expect(() => parsePatchHeader(buf)).toThrow("negative length");
91-
});
92-
20+
describe("parsePatchHeader: fixtures", () => {
9321
test("parses valid small fixture header", async () => {
9422
const patchData = new Uint8Array(
9523
await Bun.file(join(FIXTURES_DIR, "small.trdiff10")).arrayBuffer()
@@ -109,6 +37,13 @@ describe("parsePatchHeader", () => {
10937
expect(header.diffLen).toBeGreaterThanOrEqual(0);
11038
expect(header.newSize).toBe(65_536);
11139
});
40+
41+
test("rejects truncated patch (header claims more data than exists)", () => {
42+
const truncated = new Uint8Array(32);
43+
truncated.set(new TextEncoder().encode("TRDIFF10"));
44+
truncated[8] = 100; // controlLen = 100
45+
expect(() => parsePatchHeader(truncated)).toThrow("exceed file size");
46+
});
11247
});
11348

11449
describe("applyPatch", () => {
@@ -126,14 +61,12 @@ describe("applyPatch", () => {
12661
try {
12762
const sha256 = await applyPatch(oldPath, patchData, destPath);
12863

129-
// Verify output matches expected new file
13064
const expected = await Bun.file(
13165
join(FIXTURES_DIR, "small-new.bin")
13266
).arrayBuffer();
13367
const actual = await Bun.file(destPath).arrayBuffer();
13468
expect(new Uint8Array(actual)).toEqual(new Uint8Array(expected));
13569

136-
// Verify SHA-256 matches
13770
const expectedHash = new Bun.CryptoHasher("sha256")
13871
.update(new Uint8Array(expected))
13972
.digest("hex");
@@ -185,7 +118,6 @@ describe("applyPatch", () => {
185118

186119
try {
187120
const sha256 = await applyPatch(oldPath, patchData, destPath);
188-
// Known SHA-256 of "Hello, World! This is the new file content. Version 2."
189121
expect(sha256).toMatch(/^[0-9a-f]{64}$/);
190122
expect(sha256.length).toBe(64);
191123
} finally {
@@ -197,15 +129,6 @@ describe("applyPatch", () => {
197129
}
198130
});
199131

200-
test("rejects truncated patch (header claims more data than exists)", () => {
201-
// Header says controlLen=100 but patch is only 32 bytes
202-
const truncated = new Uint8Array(32);
203-
truncated.set(new TextEncoder().encode("TRDIFF10"));
204-
truncated[8] = 100; // controlLen = 100
205-
206-
expect(() => parsePatchHeader(truncated)).toThrow("exceed file size");
207-
});
208-
209132
test("rejects non-TRDIFF10 magic", async () => {
210133
const oldPath = join(FIXTURES_DIR, "small-old.bin");
211134
const buf = new Uint8Array(64);

test/lib/db/auth.test.ts

Lines changed: 8 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
/**
22
* Auth Environment Variable Tests
33
*
4-
* Tests for SENTRY_AUTH_TOKEN and SENTRY_TOKEN env var support.
5-
* Verifies priority, source tracking, and interaction with stored tokens.
4+
* Note: Core invariants (priority, source tracking, refresh skip, isEnvTokenActive)
5+
* are tested via property-based tests in auth.property.test.ts. These tests focus on
6+
* edge cases (whitespace, empty strings), shape assertions, and functions not covered
7+
* by property tests (isAuthenticated, getActiveEnvVarName).
68
*/
79

810
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
911
import {
10-
type AuthSource,
1112
getActiveEnvVarName,
1213
getAuthConfig,
1314
getAuthToken,
@@ -20,7 +21,6 @@ import { useTestConfigDir } from "../../helpers.js";
2021

2122
useTestConfigDir("auth-env-");
2223

23-
/** Save and restore env vars around each test */
2424
let savedAuthToken: string | undefined;
2525
let savedSentryToken: string | undefined;
2626

@@ -32,7 +32,6 @@ beforeEach(() => {
3232
});
3333

3434
afterEach(() => {
35-
// Restore — never leave env vars dangling
3635
if (savedAuthToken !== undefined) {
3736
process.env.SENTRY_AUTH_TOKEN = savedAuthToken;
3837
} else {
@@ -45,34 +44,7 @@ afterEach(() => {
4544
}
4645
});
4746

48-
describe("env var auth: getAuthToken", () => {
49-
test("returns SENTRY_AUTH_TOKEN when set", () => {
50-
process.env.SENTRY_AUTH_TOKEN = "sntrys_token_abc";
51-
expect(getAuthToken()).toBe("sntrys_token_abc");
52-
});
53-
54-
test("returns SENTRY_TOKEN when set", () => {
55-
process.env.SENTRY_TOKEN = "sntrys_token_xyz";
56-
expect(getAuthToken()).toBe("sntrys_token_xyz");
57-
});
58-
59-
test("SENTRY_AUTH_TOKEN takes priority over SENTRY_TOKEN", () => {
60-
process.env.SENTRY_AUTH_TOKEN = "auth_token";
61-
process.env.SENTRY_TOKEN = "sentry_token";
62-
expect(getAuthToken()).toBe("auth_token");
63-
});
64-
65-
test("env var takes priority over stored token", () => {
66-
setAuthToken("stored_token");
67-
process.env.SENTRY_AUTH_TOKEN = "env_token";
68-
expect(getAuthToken()).toBe("env_token");
69-
});
70-
71-
test("falls back to stored token when no env var", () => {
72-
setAuthToken("stored_token");
73-
expect(getAuthToken()).toBe("stored_token");
74-
});
75-
47+
describe("env var auth: getAuthToken edge cases", () => {
7648
test("ignores empty SENTRY_AUTH_TOKEN", () => {
7749
process.env.SENTRY_AUTH_TOKEN = "";
7850
setAuthToken("stored_token");
@@ -91,30 +63,7 @@ describe("env var auth: getAuthToken", () => {
9163
});
9264
});
9365

94-
describe("env var auth: getAuthConfig", () => {
95-
test("returns env source for SENTRY_AUTH_TOKEN", () => {
96-
process.env.SENTRY_AUTH_TOKEN = "test_token";
97-
const config = getAuthConfig();
98-
expect(config).toBeDefined();
99-
expect(config?.token).toBe("test_token");
100-
expect(config?.source).toBe("env:SENTRY_AUTH_TOKEN" satisfies AuthSource);
101-
});
102-
103-
test("returns env source for SENTRY_TOKEN", () => {
104-
process.env.SENTRY_TOKEN = "test_token";
105-
const config = getAuthConfig();
106-
expect(config).toBeDefined();
107-
expect(config?.token).toBe("test_token");
108-
expect(config?.source).toBe("env:SENTRY_TOKEN" satisfies AuthSource);
109-
});
110-
111-
test("returns oauth source for stored token", () => {
112-
setAuthToken("stored_token");
113-
const config = getAuthConfig();
114-
expect(config).toBeDefined();
115-
expect(config?.source).toBe("oauth" satisfies AuthSource);
116-
});
117-
66+
describe("env var auth: getAuthConfig shape", () => {
11867
test("env config has no refreshToken or expiry", () => {
11968
process.env.SENTRY_AUTH_TOKEN = "test_token";
12069
const config = getAuthConfig();
@@ -135,21 +84,7 @@ describe("env var auth: isAuthenticated", () => {
13584
});
13685
});
13786

138-
describe("env var auth: isEnvTokenActive", () => {
139-
test("returns true for SENTRY_AUTH_TOKEN", () => {
140-
process.env.SENTRY_AUTH_TOKEN = "test_token";
141-
expect(isEnvTokenActive()).toBe(true);
142-
});
143-
144-
test("returns true for SENTRY_TOKEN", () => {
145-
process.env.SENTRY_TOKEN = "test_token";
146-
expect(isEnvTokenActive()).toBe(true);
147-
});
148-
149-
test("returns false when no env var set", () => {
150-
expect(isEnvTokenActive()).toBe(false);
151-
});
152-
87+
describe("env var auth: isEnvTokenActive edge case", () => {
15388
test("returns false for empty env var", () => {
15489
process.env.SENTRY_AUTH_TOKEN = "";
15590
expect(isEnvTokenActive()).toBe(false);
@@ -178,23 +113,8 @@ describe("env var auth: getActiveEnvVarName", () => {
178113
});
179114
});
180115

181-
describe("env var auth: refreshToken", () => {
182-
test("returns env token without refreshing", async () => {
183-
process.env.SENTRY_AUTH_TOKEN = "env_token";
184-
const result = await refreshToken();
185-
expect(result.token).toBe("env_token");
186-
expect(result.refreshed).toBe(false);
187-
});
188-
189-
test("returns env token even with force=true", async () => {
190-
process.env.SENTRY_AUTH_TOKEN = "env_token";
191-
const result = await refreshToken({ force: true });
192-
expect(result.token).toBe("env_token");
193-
expect(result.refreshed).toBe(false);
194-
});
195-
116+
describe("env var auth: refreshToken edge cases", () => {
196117
test("env token skips stored token entirely", async () => {
197-
// Store a token that would require refresh (expired)
198118
setAuthToken("stored_token", -1, "refresh_token");
199119
process.env.SENTRY_AUTH_TOKEN = "env_token";
200120
const result = await refreshToken();

0 commit comments

Comments
 (0)