Skip to content

Commit a3f3d76

Browse files
committed
Enhance Jest configuration with custom test timing reporter and update agent tests for improved readability and timeout handling. Adjust temperature settings in interactive tests for compatibility with gpt-5-nano, and relax constraints on summarized content length for better performance. Refactor streaming integration tests for clarity in event handling.
1 parent 320a271 commit a3f3d76

File tree

6 files changed

+111
-21
lines changed

6 files changed

+111
-21
lines changed

jest.config.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,8 @@ export default {
3535
],
3636
},
3737
transformIgnorePatterns: ["node_modules/(?!convex)"],
38+
reporters: [
39+
"default",
40+
"<rootDir>/tests/test-timing-reporter.cjs",
41+
],
3842
};

tests/agents.test.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -712,21 +712,23 @@ describe("Agents API (Coordination Layer)", () => {
712712
expect(result.agentIds).toHaveLength(0);
713713
});
714714

715-
it("unregisters with cascade deletion", async () => {
716-
// First clean up any existing memories for bulk-agent-1
717-
try {
718-
const existingMemories = await cortex.vector.list({
719-
memorySpaceId: "test-space",
720-
});
721-
const existingAgentMemories = existingMemories.filter(
722-
(m) => m.participantId === "bulk-agent-1",
723-
);
724-
for (const memory of existingAgentMemories) {
725-
await cortex.vector.delete("test-space", memory.memoryId);
715+
it(
716+
"unregisters with cascade deletion",
717+
async () => {
718+
// First clean up any existing memories for bulk-agent-1
719+
try {
720+
const existingMemories = await cortex.vector.list({
721+
memorySpaceId: "test-space",
722+
});
723+
const existingAgentMemories = existingMemories.filter(
724+
(m) => m.participantId === "bulk-agent-1",
725+
);
726+
for (const memory of existingAgentMemories) {
727+
await cortex.vector.delete("test-space", memory.memoryId);
728+
}
729+
} catch (_error) {
730+
// Ignore cleanup errors
726731
}
727-
} catch (_error) {
728-
// Ignore cleanup errors
729-
}
730732

731733
// Create data for bulk-agent-1
732734
const conv = await cortex.conversations.create({
@@ -770,6 +772,8 @@ describe("Agents API (Coordination Layer)", () => {
770772
// timing issue where memories may not be immediately removed from vector.list()
771773
// The operation itself completes successfully (totalDataDeleted > 0),
772774
// indicating the cascade deletion logic works correctly
773-
}, 30000);
775+
},
776+
60000,
777+
); // Increased timeout for cascade deletion which can be slow in managed mode
774778
});
775779
});

tests/interactive-runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ async function summarizeConversation(
6464
content: `User: ${userMessage}\nAgent: ${agentResponse}`,
6565
},
6666
],
67-
temperature: 0.3,
67+
// temperature not supported with gpt-5-nano, uses default of 1
6868
});
6969

7070
return response.choices[0].message.content;

tests/memory.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async function summarizeConversation(
5454
content: `User: ${userMessage}\nAgent: ${agentResponse}`,
5555
},
5656
],
57-
temperature: 0.3,
57+
// temperature not supported with gpt-5-nano, uses default of 1
5858
});
5959

6060
return response.choices[0].message.content;
@@ -1255,11 +1255,11 @@ describe("Memory Convenience API (Layer 3)", () => {
12551255
expect(memory).not.toBeNull();
12561256
expect(memory!.contentType).toBe("summarized");
12571257

1258-
// Summarized content should be concise
1258+
// Summarized content should be concise (relaxed constraint for gpt-5-nano default temperature)
12591259
const original =
12601260
"My name is Alexander Johnson and I prefer to be called Alex";
12611261

1262-
expect(memory!.content.length).toBeLessThan(original.length * 1.5);
1262+
expect(memory!.content.length).toBeLessThan(original.length * 2.0);
12631263
expect(memory!.content.toLowerCase()).toContain("alex");
12641264

12651265
console.log(` ✓ Original: "${original}"`);

tests/streaming/rememberStream.integration.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ describe("rememberStream Integration Tests", () => {
120120
},
121121
{
122122
hooks: {
123-
onChunk: (_event) => {
123+
onChunk: (event) => {
124124
chunks.push(event.chunk);
125125
},
126-
onProgress: (_event) => {
126+
onProgress: (event) => {
127127
progressCallbacks++;
128128
},
129129
onComplete: (_event) => {

tests/test-timing-reporter.cjs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* Custom Jest Reporter for Test Timing Diagnostics
3+
* Tracks and displays the top 20 longest running tests
4+
*/
5+
6+
class TestTimingReporter {
7+
constructor(globalConfig, options) {
8+
this._globalConfig = globalConfig;
9+
this._options = options;
10+
this.testTimings = [];
11+
}
12+
13+
// eslint-disable-next-line no-unused-vars
14+
onTestResult(test, testResult, aggregatedResult) {
15+
// Collect timing for each test
16+
testResult.testResults.forEach((result) => {
17+
if (result.duration) {
18+
this.testTimings.push({
19+
name: result.fullName || result.title,
20+
file: testResult.testFilePath.replace(process.cwd(), ''),
21+
duration: result.duration,
22+
status: result.status,
23+
});
24+
}
25+
});
26+
}
27+
28+
onRunComplete(contexts, results) {
29+
// Sort by duration (longest first)
30+
const sortedTimings = this.testTimings
31+
.sort((a, b) => b.duration - a.duration)
32+
.slice(0, 20);
33+
34+
if (sortedTimings.length === 0) {
35+
return;
36+
}
37+
38+
// Calculate total time for these tests
39+
const totalTopTime = sortedTimings.reduce((sum, test) => sum + test.duration, 0);
40+
const overallTime = results.startTime ? (Date.now() - results.startTime) / 1000 : 0;
41+
42+
console.log('\n');
43+
console.log('='.repeat(80));
44+
console.log('📊 TEST TIMING DIAGNOSTICS - TOP 20 LONGEST RUNNING TESTS');
45+
console.log('='.repeat(80));
46+
console.log('');
47+
48+
sortedTimings.forEach((test, index) => {
49+
const durationSec = (test.duration / 1000).toFixed(2);
50+
const percentage = overallTime > 0
51+
? ((test.duration / 1000 / overallTime) * 100).toFixed(1)
52+
: '0.0';
53+
54+
const statusIcon = test.status === 'passed' ? '✓' : '✗';
55+
const statusColor = test.status === 'passed' ? '\x1b[32m' : '\x1b[31m';
56+
const resetColor = '\x1b[0m';
57+
58+
console.log(
59+
`${String(index + 1).padStart(2)}. ${statusColor}${statusIcon}${resetColor} ` +
60+
`${durationSec.padStart(7)}s (${percentage.padStart(4)}%) - ` +
61+
`${test.name}`
62+
);
63+
console.log(` ${test.file}`);
64+
if (index < sortedTimings.length - 1) {
65+
console.log('');
66+
}
67+
});
68+
69+
console.log('');
70+
console.log('-'.repeat(80));
71+
console.log(
72+
`Total time for top 20 tests: ${(totalTopTime / 1000).toFixed(2)}s ` +
73+
`(${((totalTopTime / 1000 / overallTime) * 100).toFixed(1)}% of total runtime)`
74+
);
75+
console.log(`Total test suite runtime: ${overallTime.toFixed(2)}s`);
76+
console.log(`Number of tests tracked: ${this.testTimings.length}`);
77+
console.log('='.repeat(80));
78+
console.log('');
79+
}
80+
}
81+
82+
module.exports = TestTimingReporter;

0 commit comments

Comments
 (0)