Skip to content

Commit fe4a5c1

Browse files
committed
more test fixes...
1 parent 6323ae0 commit fe4a5c1

File tree

3 files changed

+45
-20
lines changed

3 files changed

+45
-20
lines changed

test/integration/api/cache-status.integration.test.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@ import { join } from "node:path"
55
import { createDocsFetcher } from "../../../src/docs-fetcher.js"
66

77
describe("Cache Status Tracking", () => {
8-
const testDbPath = join(tmpdir(), `test-cache-status-${Date.now()}.db`)
8+
let testDbPath: string
99
let fetcher: ReturnType<typeof createDocsFetcher>
1010

1111
beforeEach(() => {
12+
// Create unique database path for each test to avoid conflicts
13+
testDbPath = join(
14+
tmpdir(),
15+
`test-cache-status-${Date.now()}-${Math.random().toString(36).substring(2, 9)}.db`
16+
)
17+
1218
// Create fetcher with persistent database for testing
1319
fetcher = createDocsFetcher({
1420
dbPath: testDbPath,
@@ -47,7 +53,7 @@ describe("Cache Status Tracking", () => {
4753
expect(result.fromCache).toBe(false)
4854
expect(result.data).toBeDefined()
4955
expect(result.data.root).toBeDefined() // Basic validation of rustdoc JSON structure
50-
})
56+
}, 10000)
5157

5258
it("should return fromCache: true on subsequent fetch", async () => {
5359
// First fetch - should hit the network
@@ -60,7 +66,7 @@ describe("Cache Status Tracking", () => {
6066

6167
// Data should be identical
6268
expect(secondResult.data).toEqual(firstResult.data)
63-
})
69+
}, 10000)
6470

6571
it("should persist cache across fetcher instances", async () => {
6672
// First fetcher instance
@@ -81,7 +87,7 @@ describe("Cache Status Tracking", () => {
8187
expect(result2.data).toEqual(result1.data)
8288

8389
fetcher2.close()
84-
})
90+
}, 10000)
8591

8692
it("should handle different versions separately", async () => {
8793
// Fetch latest version
@@ -99,7 +105,7 @@ describe("Cache Status Tracking", () => {
99105
// Fetch the specific version again - should also be cached
100106
const versionAgain = await fetcher.fetchCrateJson("tinc", "0.1.6")
101107
expect(versionAgain.fromCache).toBe(true)
102-
})
108+
}, 15000)
103109

104110
it("should track cache misses for non-existent crates", async () => {
105111
try {
@@ -118,7 +124,7 @@ describe("Cache Status Tracking", () => {
118124
expect(secondError).toBeDefined()
119125
}
120126
}
121-
})
127+
}, 10000)
122128

123129
it("should work with in-memory cache", async () => {
124130
// Create fetcher with in-memory cache
@@ -135,7 +141,7 @@ describe("Cache Status Tracking", () => {
135141
expect(secondResult.fromCache).toBe(true)
136142

137143
memoryFetcher.close()
138-
})
144+
}, 10000)
139145

140146
it("should respect cache TTL", async () => {
141147
// Create fetcher with very short TTL
@@ -162,5 +168,5 @@ describe("Cache Status Tracking", () => {
162168
await new Promise((resolve) => setTimeout(resolve, 100))
163169
}
164170
rmSync(join(tmpdir(), `test-ttl-${Date.now()}.db`), { force: true })
165-
})
171+
}, 10000)
166172
})

test/integration/e2e/full-flow.integration.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ describe("Integration Tests", () => {
4444
throw error
4545
}
4646
}
47-
})
47+
}, 10000)
4848

4949
it("should handle crates without JSON docs gracefully", () => {
5050
// Try an old version that likely doesn't have JSON docs
5151
expect(fetcher.fetchCrateJson("tinc", "0.1.0")).rejects.toThrow(/not found|404/)
52-
})
52+
}, 10000)
5353

5454
it("should validate URL construction", async () => {
5555
// Mock a quick test without actual network call
@@ -70,5 +70,5 @@ describe("Integration Tests", () => {
7070
)
7171

7272
global.fetch = originalFetch
73-
})
73+
}, 10000)
7474
})

test/integration/test-resources.ts

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,19 @@ const testResources = async (options: TestOptions): Promise<void> => {
3333

3434
// Test 2: Add some data to cache
3535
console.log("\n🔄 Test 2: Populate cache with test data...")
36-
const addResult = await callTool(server, "lookup_crate_docs", { crateName: "tinc", version: "0.1.6" }, 3)
36+
const addResult = await callTool(
37+
server,
38+
"lookup_crate_docs",
39+
{ crateName: "tinc", version: "0.1.6" },
40+
3
41+
)
3742
if (addResult.result?.isError) {
3843
throw new Error(`Failed to add tinc to cache: ${addResult.result.content[0].text}`)
3944
}
4045
console.log("✅ Added tinc to cache")
41-
46+
4247
// Small delay to ensure cache write completes
43-
await new Promise(resolve => setTimeout(resolve, 100))
48+
await new Promise((resolve) => setTimeout(resolve, 100))
4449

4550
// Test 3: Read cache statistics
4651
console.log("\n📊 Test 3: Read cache statistics...")
@@ -57,12 +62,16 @@ const testResources = async (options: TestOptions): Promise<void> => {
5762

5863
// Test 4: Read cache entries
5964
console.log("\n📚 Test 4: Read cache entries...")
60-
const entriesContent = await readResource(server, "cache://entries?limit=10&offset=0", 5)
61-
65+
const entriesContent = await readResource(
66+
server,
67+
"cache://entries?limit=10&offset=0",
68+
5
69+
)
70+
6271
if (!entriesContent) {
6372
throw new Error("No content returned from cache entries resource")
6473
}
65-
74+
6675
let entries: any
6776
try {
6877
entries = JSON.parse(entriesContent)
@@ -120,8 +129,14 @@ const testResources = async (options: TestOptions): Promise<void> => {
120129
const sqlResult = JSON.parse(sqlContent)
121130

122131
const expectedCount = 1 + successCount // 1 from tinc + successCount from pagination test
123-
if (!Array.isArray(sqlResult) || sqlResult.length === 0 || sqlResult[0].count !== expectedCount) {
124-
throw new Error(`Expected ${expectedCount} cache entries, got ${sqlResult?.[0]?.count}`)
132+
if (
133+
!Array.isArray(sqlResult) ||
134+
sqlResult.length === 0 ||
135+
sqlResult[0].count !== expectedCount
136+
) {
137+
throw new Error(
138+
`Expected ${expectedCount} cache entries, got ${sqlResult?.[0]?.count}`
139+
)
125140
}
126141
console.log("✅ SQL query executed successfully")
127142

@@ -138,7 +153,11 @@ const testResources = async (options: TestOptions): Promise<void> => {
138153

139154
// The server returns a successful response with an error message in the content
140155
const dangerousContent = dangerousResponse.result?.contents?.[0]?.text || ""
141-
assertContains(dangerousContent, "Only SELECT queries are allowed", "Should reject non-SELECT query")
156+
assertContains(
157+
dangerousContent,
158+
"Only SELECT queries are allowed",
159+
"Should reject non-SELECT query"
160+
)
142161
console.log("✅ Correctly rejected non-SELECT query")
143162

144163
console.log("\n✅ All resources tests passed")

0 commit comments

Comments
 (0)