test(e2e): check memory isolation between real workspaces and the chat-scoped erase (P1.5, UF-039)
- The isolation journeys (B2.4, U2.3, U2.4, U9.3) create their workspaces first. They used made-up workspace ids, which the sidecar silently turned into personal memory, so they never compared two workspaces; such writes are now refused (UF-039). - J3f follows the Memory Center on the memory contract: Erase removes every memory saved from the same chat and is offered only for memories with a chat session; the erased-sources panel is gone.
This commit is contained in:
@@ -76,6 +76,13 @@ async function saveMemory(request: APIRequestContext, content: string, workspace
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Creates a real workspace; memory writes for a workspace that does not exist are refused (UF-039). */
|
||||||
|
async function createWorkspace(request: APIRequestContext, name: string): Promise<string> {
|
||||||
|
const res = await request.post(`${API}/api/workspaces`, { data: { name, group: 'E2E' } });
|
||||||
|
expect(res.ok()).toBe(true);
|
||||||
|
return (await res.json()).id as string;
|
||||||
|
}
|
||||||
|
|
||||||
async function searchMemory(request: APIRequestContext, query: string, workspace: string, limit = 5) {
|
async function searchMemory(request: APIRequestContext, query: string, workspace: string, limit = 5) {
|
||||||
return request.get(`${API}/api/memory/search?q=${encodeURIComponent(query)}&workspace=${encodeURIComponent(workspace)}&limit=${limit}`);
|
return request.get(`${API}/api/memory/search?q=${encodeURIComponent(query)}&workspace=${encodeURIComponent(workspace)}&limit=${limit}`);
|
||||||
}
|
}
|
||||||
@@ -227,8 +234,8 @@ test.describe('B2 — Memory Persistence (vs ChatGPT / Claude Code / Hermes)', (
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('B2.4 — Memory isolation: 100% workspace separation (Hermes has no isolation)', async ({ request }) => {
|
test('B2.4 — Memory isolation: 100% workspace separation (Hermes has no isolation)', async ({ request }) => {
|
||||||
const wsA = `isolation-bench-a-${Date.now()}`;
|
const wsA = await createWorkspace(request, `isolation-bench-a-${Date.now()}`);
|
||||||
const wsB = `isolation-bench-b-${Date.now()}`;
|
const wsB = await createWorkspace(request, `isolation-bench-b-${Date.now()}`);
|
||||||
const secretData = `BENCH-SECRET-${Math.random().toString(36).slice(2)}`;
|
const secretData = `BENCH-SECRET-${Math.random().toString(36).slice(2)}`;
|
||||||
|
|
||||||
await saveMemory(request, `Confidential: ${secretData}`, wsA);
|
await saveMemory(request, `Confidential: ${secretData}`, wsA);
|
||||||
|
|||||||
@@ -60,6 +60,13 @@ async function simulateMemorySave(request: APIRequestContext, content: string, w
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Creates a real workspace; memory writes for a workspace that does not exist are refused (UF-039). */
|
||||||
|
async function createWorkspace(request: APIRequestContext, name: string): Promise<string> {
|
||||||
|
const res = await request.post(`${API}/api/workspaces`, { data: { name, group: 'E2E' } });
|
||||||
|
expect(res.ok()).toBe(true);
|
||||||
|
return (await res.json()).id as string;
|
||||||
|
}
|
||||||
|
|
||||||
async function searchMemory(request: APIRequestContext, query: string, workspace: string, limit = 5) {
|
async function searchMemory(request: APIRequestContext, query: string, workspace: string, limit = 5) {
|
||||||
return request.get(`${API}/api/memory/search?q=${encodeURIComponent(query)}&workspace=${encodeURIComponent(workspace)}&limit=${limit}`);
|
return request.get(`${API}/api/memory/search?q=${encodeURIComponent(query)}&workspace=${encodeURIComponent(workspace)}&limit=${limit}`);
|
||||||
}
|
}
|
||||||
@@ -196,7 +203,7 @@ test.describe('Act 2 — The Memory Hook: "It Remembers Me"', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('U2.3 — Multiple memories stack (no overwrite on second save)', async ({ request }) => {
|
test('U2.3 — Multiple memories stack (no overwrite on second save)', async ({ request }) => {
|
||||||
const workspace = `stacking-${Date.now()}`;
|
const workspace = await createWorkspace(request, `stacking-${Date.now()}`);
|
||||||
|
|
||||||
await simulateMemorySave(request, 'I like dark mode interfaces', workspace);
|
await simulateMemorySave(request, 'I like dark mode interfaces', workspace);
|
||||||
await simulateMemorySave(request, 'My team uses Slack for communication', workspace);
|
await simulateMemorySave(request, 'My team uses Slack for communication', workspace);
|
||||||
@@ -214,8 +221,8 @@ test.describe('Act 2 — The Memory Hook: "It Remembers Me"', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('U2.4 — Cross-workspace isolation (no memory leakage between users)', async ({ request }) => {
|
test('U2.4 — Cross-workspace isolation (no memory leakage between users)', async ({ request }) => {
|
||||||
const ws1 = `user-alice-${Date.now()}`;
|
const ws1 = await createWorkspace(request, `user-alice-${Date.now()}`);
|
||||||
const ws2 = `user-bob-${Date.now()}`;
|
const ws2 = await createWorkspace(request, `user-bob-${Date.now()}`);
|
||||||
|
|
||||||
await simulateMemorySave(request, 'Alice secret: my API key is sk-alice-private-data', ws1);
|
await simulateMemorySave(request, 'Alice secret: my API key is sk-alice-private-data', ws1);
|
||||||
|
|
||||||
@@ -820,8 +827,8 @@ test.describe('Act 9 — Workspace Identity & Ownership', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('U9.3 — Workspace memory is isolated per workspace ID', async ({ request }) => {
|
test('U9.3 — Workspace memory is isolated per workspace ID', async ({ request }) => {
|
||||||
const ws1 = `isolation-a-${Date.now()}`;
|
const ws1 = await createWorkspace(request, `isolation-a-${Date.now()}`);
|
||||||
const ws2 = `isolation-b-${Date.now()}`;
|
const ws2 = await createWorkspace(request, `isolation-b-${Date.now()}`);
|
||||||
|
|
||||||
// Save in ws1
|
// Save in ws1
|
||||||
const saveRes = await simulateMemorySave(request, 'This is workspace A exclusive data', ws1);
|
const saveRes = await simulateMemorySave(request, 'This is workspace A exclusive data', ws1);
|
||||||
@@ -833,10 +840,9 @@ test.describe('Act 9 — Workspace Identity & Ownership', () => {
|
|||||||
if (res.ok()) {
|
if (res.ok()) {
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const results = data.results ?? data.recalled ?? [];
|
const results = data.results ?? data.recalled ?? [];
|
||||||
// Personal mind frames may appear in any workspace search (current design).
|
// Personal memories may appear in any workspace search (by design); ws1's
|
||||||
// What matters: workspace-mind frames from ws1 must NOT appear in ws2 results.
|
// workspace memory must never appear in ws2's results.
|
||||||
const wsLeaked = results.some((r: RecallResultShape) =>
|
const wsLeaked = results.some((r: RecallResultShape) =>
|
||||||
r.source_mind === 'workspace' && r.mind === 'workspace' &&
|
|
||||||
JSON.stringify(r).toLowerCase().includes('workspace a exclusive')
|
JSON.stringify(r).toLowerCase().includes('workspace a exclusive')
|
||||||
);
|
);
|
||||||
expect(wsLeaked, 'Workspace-mind data leaked across workspaces').toBe(false);
|
expect(wsLeaked, 'Workspace-mind data leaked across workspaces').toBe(false);
|
||||||
|
|||||||
@@ -235,8 +235,7 @@ test.describe('User Journey Tests', () => {
|
|||||||
test('J3f: memory destructive trust actions use in-app confirmations', async ({ page }) => {
|
test('J3f: memory destructive trust actions use in-app confirmations', async ({ page }) => {
|
||||||
const nativeDialogs: string[] = [];
|
const nativeDialogs: string[] = [];
|
||||||
let deleteCalled = false;
|
let deleteCalled = false;
|
||||||
let eraseCalled = false;
|
let eraseBody: unknown = null;
|
||||||
let allowCalled = false;
|
|
||||||
const memory = {
|
const memory = {
|
||||||
id: 'memory-research-note',
|
id: 'memory-research-note',
|
||||||
kind: 'fact',
|
kind: 'fact',
|
||||||
@@ -247,21 +246,16 @@ test.describe('User Journey Tests', () => {
|
|||||||
source: 'user_stated',
|
source: 'user_stated',
|
||||||
sourceId: null,
|
sourceId: null,
|
||||||
sourceUrl: null,
|
sourceUrl: null,
|
||||||
|
// Saved from a chat, so the Memory Center offers to erase that chat's memories.
|
||||||
|
sessionId: 'chat-research-1',
|
||||||
importance: 'normal',
|
importance: 'normal',
|
||||||
status: 'active',
|
status: 'active',
|
||||||
confidence: 91,
|
|
||||||
tags: ['research'],
|
tags: ['research'],
|
||||||
evidence: [],
|
evidence: [],
|
||||||
hasOriginalSource: false,
|
hasOriginalSource: false,
|
||||||
createdAt: '2026-07-08T08:00:00.000Z',
|
createdAt: '2026-07-08T08:00:00.000Z',
|
||||||
updatedAt: '2026-07-08T09:00:00.000Z',
|
updatedAt: '2026-07-08T09:00:00.000Z',
|
||||||
};
|
};
|
||||||
const suppression = {
|
|
||||||
source: 'chatgpt',
|
|
||||||
sourceRef: 'research-export.json',
|
|
||||||
erasedAt: '2026-07-08T09:30:00.000Z',
|
|
||||||
reason: 'GDPR Art.17 erasure',
|
|
||||||
};
|
|
||||||
|
|
||||||
await page.route('**/api/memory**', route => {
|
await page.route('**/api/memory**', route => {
|
||||||
const request = route.request();
|
const request = route.request();
|
||||||
@@ -278,36 +272,11 @@ test.describe('User Journey Tests', () => {
|
|||||||
return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ ok: true }) });
|
return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ ok: true }) });
|
||||||
}
|
}
|
||||||
if (url.pathname === '/api/memory/erase' && request.method() === 'POST') {
|
if (url.pathname === '/api/memory/erase' && request.method() === 'POST') {
|
||||||
eraseCalled = true;
|
eraseBody = request.postDataJSON();
|
||||||
return route.fulfill({
|
return route.fulfill({
|
||||||
status: 200,
|
status: 200,
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({ erased: true, deleted: 2 }),
|
||||||
erased: true,
|
|
||||||
mind: 'personal',
|
|
||||||
result: {
|
|
||||||
framesDeleted: 1,
|
|
||||||
archiveRedacted: 1,
|
|
||||||
chunkVectorsPurged: 0,
|
|
||||||
entitiesErased: 1,
|
|
||||||
relationsErased: 0,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (url.pathname === '/api/memory/suppression' && request.method() === 'GET') {
|
|
||||||
return route.fulfill({
|
|
||||||
status: 200,
|
|
||||||
contentType: 'application/json',
|
|
||||||
body: JSON.stringify({ mind: 'personal', suppressed: [suppression] }),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (url.pathname === '/api/memory/suppression/allow' && request.method() === 'POST') {
|
|
||||||
allowCalled = true;
|
|
||||||
return route.fulfill({
|
|
||||||
status: 200,
|
|
||||||
contentType: 'application/json',
|
|
||||||
body: JSON.stringify({ removed: true, mind: 'personal' }),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return route.continue();
|
return route.continue();
|
||||||
@@ -331,22 +300,13 @@ test.describe('User Journey Tests', () => {
|
|||||||
await expect.poll(() => deleteCalled).toBe(true);
|
await expect.poll(() => deleteCalled).toBe(true);
|
||||||
|
|
||||||
await memoryCard.click();
|
await memoryCard.click();
|
||||||
await page.getByRole('button', { name: /^erase$/i }).click();
|
await page.getByRole('button', { name: /^erase chat memories$/i }).click();
|
||||||
expect(nativeDialogs).toEqual([]);
|
expect(nativeDialogs).toEqual([]);
|
||||||
await expect(page.getByTestId('approval-modal')).toContainText(/erase memory and derived data/i);
|
await expect(page.getByTestId('approval-modal')).toContainText(/erase everything remembered from this chat/i);
|
||||||
await expect(page.getByTestId('approval-modal')).toContainText(/cannot be undone/i);
|
await expect(page.getByTestId('approval-modal')).toContainText(/cannot be undone/i);
|
||||||
await page.getByTestId('approval-modal-approve').click();
|
await page.getByTestId('approval-modal-approve').click();
|
||||||
await expect.poll(() => eraseCalled).toBe(true);
|
await expect.poll(() => eraseBody).toMatchObject({ sessionId: 'chat-research-1' });
|
||||||
await expect(page.getByText(/erased "research note"/i)).toBeVisible({ timeout: 5_000 });
|
await expect(page.getByText(/erased 2 memories from that chat/i)).toBeVisible({ timeout: 5_000 });
|
||||||
|
|
||||||
await page.getByRole('button', { name: /erased sources/i }).click();
|
|
||||||
await expect(page.getByText('research-export.json')).toBeVisible({ timeout: 5_000 });
|
|
||||||
await page.getByRole('button', { name: /allow re-import/i }).click();
|
|
||||||
expect(nativeDialogs).toEqual([]);
|
|
||||||
await expect(page.getByTestId('approval-modal')).toContainText(/allow source to be re-imported/i);
|
|
||||||
await expect(page.getByTestId('approval-modal')).toContainText(/re-consented/i);
|
|
||||||
await page.getByTestId('approval-modal-approve').click();
|
|
||||||
await expect.poll(() => allowCalled).toBe(true);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// The wiki is hidden in v1 by the memory feature map (ADR-0002,
|
// The wiki is hidden in v1 by the memory feature map (ADR-0002,
|
||||||
|
|||||||
Reference in New Issue
Block a user