test: add cleanup hooks and refactor integration test helpers
This commit is contained in:
@@ -2,8 +2,6 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
...require("./jest.config"),
|
...require("./jest.config"),
|
||||||
testMatch: ["**/integration/**/*.test.ts"],
|
testMatch: ["**/integration/**/*.test.ts"],
|
||||||
globalSetup:
|
globalSetup: "<rootDir>/src/client/tests/integration/global-setup.ts",
|
||||||
"<rootDir>/src/client/tests/integration/global-setup.ts",
|
globalTeardown: "<rootDir>/src/client/tests/integration/global-teardown.ts",
|
||||||
globalTeardown:
|
|
||||||
"<rootDir>/src/client/tests/integration/global-teardown.ts",
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -200,7 +200,10 @@ describeIntegration("MemoryClient Integration — CRUD", () => {
|
|||||||
const result = await client.add(
|
const result = await client.add(
|
||||||
[
|
[
|
||||||
{ role: "user" as const, content: "I prefer dark mode in all apps." },
|
{ role: "user" as const, content: "I prefer dark mode in all apps." },
|
||||||
{ role: "assistant" as const, content: "Noted, dark mode preference saved!" },
|
{
|
||||||
|
role: "assistant" as const,
|
||||||
|
content: "Noted, dark mode preference saved!",
|
||||||
|
},
|
||||||
],
|
],
|
||||||
{
|
{
|
||||||
user_id: TEST_USER_ID,
|
user_id: TEST_USER_ID,
|
||||||
|
|||||||
@@ -60,9 +60,7 @@ export async function waitForMemories(
|
|||||||
): Promise<Memory[]> {
|
): Promise<Memory[]> {
|
||||||
const start = Date.now();
|
const start = Date.now();
|
||||||
while (Date.now() - start < maxWaitMs) {
|
while (Date.now() - start < maxWaitMs) {
|
||||||
const memories = await withRetry(() =>
|
const memories = await withRetry(() => client.getAll({ user_id: userId }));
|
||||||
client.getAll({ user_id: userId }),
|
|
||||||
);
|
|
||||||
if (Array.isArray(memories) && memories.length >= minCount) {
|
if (Array.isArray(memories) && memories.length >= minCount) {
|
||||||
return memories;
|
return memories;
|
||||||
}
|
}
|
||||||
@@ -133,8 +131,7 @@ export async function seedTestMemories(
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
role: "user" as const,
|
role: "user" as const,
|
||||||
content:
|
content: "Hi, I'm integration-test-user. My favorite color is blue.",
|
||||||
"Hi, I'm integration-test-user. My favorite color is blue.",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
role: "assistant" as const,
|
role: "assistant" as const,
|
||||||
@@ -193,9 +190,7 @@ export async function cleanupTestUser(
|
|||||||
* Used as cleanup before and after integration test runs so tests
|
* Used as cleanup before and after integration test runs so tests
|
||||||
* start from a clean slate and don't leave data behind.
|
* start from a clean slate and don't leave data behind.
|
||||||
*/
|
*/
|
||||||
export async function fullProjectCleanup(
|
export async function fullProjectCleanup(client: MemoryClient): Promise<void> {
|
||||||
client: MemoryClient,
|
|
||||||
): Promise<void> {
|
|
||||||
// Delete all memories — all four filters set explicitly
|
// Delete all memories — all four filters set explicitly
|
||||||
try {
|
try {
|
||||||
await client.deleteAll({
|
await client.deleteAll({
|
||||||
|
|||||||
@@ -23,9 +23,7 @@ jest.setTimeout(120_000);
|
|||||||
|
|
||||||
const TEST_USER_ID = `integration-mgmt-${randomUUID()}`;
|
const TEST_USER_ID = `integration-mgmt-${randomUUID()}`;
|
||||||
|
|
||||||
describeIntegration(
|
describeIntegration("MemoryClient Integration — Users & Project", () => {
|
||||||
"MemoryClient Integration — Users & Project",
|
|
||||||
() => {
|
|
||||||
let client: MemoryClient;
|
let client: MemoryClient;
|
||||||
let cleanup: () => void;
|
let cleanup: () => void;
|
||||||
|
|
||||||
@@ -97,5 +95,4 @@ describeIntegration(
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
});
|
||||||
);
|
|
||||||
|
|||||||
Reference in New Issue
Block a user