-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathprompt.test.ts
More file actions
72 lines (64 loc) · 2.24 KB
/
Copy pathprompt.test.ts
File metadata and controls
72 lines (64 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { describe, expect, it, vi } from 'vitest';
import { InMemoryStore } from '@mastra/core/storage';
import { EditorPromptNamespace } from './prompt';
function createPromptNamespace(storage: InMemoryStore) {
return new EditorPromptNamespace({
__mastra: {
getStorage: () => storage,
removePromptBlock: vi.fn(),
},
__logger: {
debug: vi.fn(),
},
} as any);
}
describe('EditorPromptNamespace', () => {
it('updates prompt block snapshot fields through the SDK', async () => {
const storage = new InMemoryStore();
const prompt = createPromptNamespace(storage);
await prompt.create({
id: 'sdk-updatable-block',
name: 'SDK Updatable Block',
content: 'Initial content',
});
const updated = await prompt.update({
id: 'sdk-updatable-block',
name: 'SDK Updated Block',
content: 'Updated content',
rules: {
operator: 'AND',
conditions: [{ field: 'role', operator: 'equals', value: 'admin' }],
},
requestContextSchema: {
type: 'object',
properties: {
role: { type: 'string' },
},
required: ['role'],
},
});
expect(updated.name).toBe('SDK Updated Block');
expect(updated.content).toBe('Updated content');
expect(updated.rules).toEqual({
operator: 'AND',
conditions: [{ field: 'role', operator: 'equals', value: 'admin' }],
});
expect(updated.requestContextSchema).toEqual({
type: 'object',
properties: {
role: { type: 'string' },
},
required: ['role'],
});
const persisted = await prompt.getById('sdk-updatable-block');
expect(persisted!.name).toBe('SDK Updated Block');
expect(persisted!.content).toBe('Updated content');
expect(persisted!.rules).toEqual(updated.rules);
expect(persisted!.requestContextSchema).toEqual(updated.requestContextSchema);
const promptStore = await storage.getStore('promptBlocks');
const versions = await promptStore!.listVersions({ blockId: 'sdk-updatable-block' });
expect(versions.versions).toHaveLength(2);
expect(versions.versions[0]!.changedFields).toEqual(['name', 'content', 'rules', 'requestContextSchema']);
expect(updated.activeVersionId).toBeUndefined();
});
});