Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/core/native-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { computeDecayFactor, applyDecay } from '../intelligence/ebbinghaus.js';
import { createEmbeddingsFromEnv } from '../integrations/embeddings/factory.js';
import { createLLMFromEnv } from '../integrations/llm/factory.js';
import { getDefaultHomeDir } from '../utils/platform.js';
import { PowerMemError } from '../errors/index.js';

export interface NativeProviderOptions {
embeddings?: Embeddings;
Expand Down Expand Up @@ -348,7 +349,7 @@ export class NativeProvider implements MemoryProvider {

async update(memoryId: string, params: UpdateParams): Promise<MemoryRecord> {
const existing = await this.store.getById(memoryId);
if (!existing) throw new Error(`Memory not found: ${memoryId}`);
if (!existing) throw new PowerMemError(`Memory not found: ${memoryId}`, 'NOT_FOUND');

const content = params.content ?? existing.content;
const metadata = params.metadata ?? existing.metadata;
Expand Down
5 changes: 5 additions & 0 deletions tests/integration/coverage-gaps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { describe, it, expect, afterEach, beforeEach } from 'vitest';
import { Memory } from '../../src/core/memory.js';
import { NativeProvider } from '../../src/core/native-provider.js';
import { SQLiteStore } from '../../src/storage/sqlite/sqlite.js';
import { PowerMemError } from '../../src/errors/index.js';
import { MockEmbeddings, MockLLM } from '../mocks.js';

// ── memory.ts:41-42 — HttpProvider (serverUrl) path ──────────────────────
Expand Down Expand Up @@ -120,6 +121,10 @@ describe('NativeProvider edge cases', () => {
await expect(
provider.update('999999', { content: 'nope' })
).rejects.toThrow('Memory not found');

await expect(
provider.update('999999', { content: 'nope' })
).rejects.toBeInstanceOf(PowerMemError);
});

it('update metadata only (no content change) does not re-embed', async () => {
Expand Down
9 changes: 7 additions & 2 deletions tests/regression/edge-cases.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { NativeProvider } from '../../src/core/native-provider.js';
import { PowerMemError } from '../../src/errors/index.js';
import { MockEmbeddings } from '../mocks.js';

describe('edge cases and boundary conditions', () => {
Expand Down Expand Up @@ -50,14 +51,18 @@ describe('edge cases and boundary conditions', () => {
// ── update() with invalid IDs ───────────────────────────────────────

describe('update — invalid IDs', () => {
it('nonexistent ID throws', async () => {
it('nonexistent ID throws PowerMemError', async () => {
await expect(provider.update('999999999', { content: 'x' }))
.rejects.toThrow('Memory not found');
await expect(provider.update('999999999', { content: 'x' }))
.rejects.toBeInstanceOf(PowerMemError);
});

it('empty string ID throws', async () => {
it('empty string ID throws PowerMemError', async () => {
await expect(provider.update('', { content: 'x' }))
.rejects.toThrow('Memory not found');
await expect(provider.update('', { content: 'x' }))
.rejects.toBeInstanceOf(PowerMemError);
});
});

Expand Down
Loading