-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathpump-fun-skill.test.js
More file actions
137 lines (124 loc) · 4.48 KB
/
Copy pathpump-fun-skill.test.js
File metadata and controls
137 lines (124 loc) · 4.48 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Validates the pump-fun skill bundle is internally consistent: manifest tools
// list, tools.json schemas, and handlers.js exports all match.
import { describe, it, expect } from 'vitest';
import { readFile } from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
import { dirname, resolve } from 'node:path';
const __dirname = dirname(fileURLToPath(import.meta.url));
const BUNDLE = resolve(__dirname, '../../public/skills/pump-fun');
async function readJSON(rel) {
return JSON.parse(await readFile(resolve(BUNDLE, rel), 'utf8'));
}
describe('pump-fun skill bundle', () => {
it('manifest declares 10 tools and matches tools.json', async () => {
const manifest = await readJSON('manifest.json');
const toolsJSON = await readJSON('tools.json');
expect(manifest.name).toBe('pump-fun');
expect(manifest.spec).toBe('skill/0.1');
expect(manifest.provides.tools).toHaveLength(10);
const declared = new Set(manifest.provides.tools);
const defined = new Set(toolsJSON.tools.map((t) => t.name));
expect(defined).toEqual(declared);
});
it('every tool has an input schema', async () => {
const { tools } = await readJSON('tools.json');
for (const t of tools) {
expect(t.description).toBeTruthy();
expect(t.input_schema?.type).toBe('object');
}
});
it('handlers.js exports every declared tool', async () => {
const handlers = await import(resolve(BUNDLE, 'handlers.js'));
const manifest = await readJSON('manifest.json');
for (const tool of manifest.provides.tools) {
expect(typeof handlers[tool]).toBe('function');
}
});
it('skill is listed in the public skills index', async () => {
const indexPath = resolve(__dirname, '../../public/skills-index.json');
const index = JSON.parse(await readFile(indexPath, 'utf8'));
const entry = index.find((s) => s.id === 'pump-fun');
expect(entry).toBeDefined();
expect(entry.uri).toBe('skills/pump-fun/');
});
it('handlers proxy through ctx.fetch with JSON-RPC tools/call shape', async () => {
const handlers = await import(resolve(BUNDLE, 'handlers.js'));
let captured;
const ctx = {
fetch: async (url, opts) => {
captured = { url, body: JSON.parse(opts.body) };
return {
ok: true,
json: async () => ({
jsonrpc: '2.0',
id: captured.body.id,
result: { content: [{ type: 'text', text: '{"hits":[]}' }] },
}),
};
},
memory: { note: () => {} },
};
const result = await handlers.searchTokens({ query: 'pepe', limit: 3 }, ctx);
expect(result.ok).toBe(true);
expect(result.data).toEqual({ hits: [] });
expect(captured.body.method).toBe('tools/call');
expect(captured.body.params.name).toBe('searchTokens');
expect(captured.body.params.arguments).toEqual({ query: 'pepe', limit: 3 });
// Endpoint must resolve against the page origin (or the same-origin
// fallback) and target our in-house MCP route, never an external host.
expect(captured.url.endsWith('/api/pump-fun-mcp')).toBe(true);
});
it('getCreatorProfile returns negative sentiment when rug flags present', async () => {
const handlers = await import(resolve(BUNDLE, 'handlers.js'));
const ctx = {
fetch: async () => ({
ok: true,
json: async () => ({
jsonrpc: '2.0',
id: 1,
result: {
content: [{
type: 'text',
text: JSON.stringify({ rugFlags: ['mintAuthorityNotRevoked', 'topHolderConcentration'] }),
}],
},
}),
}),
memory: { note: () => {} },
};
const result = await handlers.getCreatorProfile({ creator: 'x' }, ctx);
expect(result.ok).toBe(true);
expect(result.sentiment).toBeLessThan(-0.5);
});
it('getBondingCurve returns positive sentiment near graduation', async () => {
const handlers = await import(resolve(BUNDLE, 'handlers.js'));
const ctx = {
fetch: async () => ({
ok: true,
json: async () => ({
jsonrpc: '2.0',
id: 1,
result: {
content: [{
type: 'text',
text: JSON.stringify({ graduationPercent: 92 }),
}],
},
}),
}),
memory: { note: () => {} },
};
const result = await handlers.getBondingCurve({ mint: 'x' }, ctx);
expect(result.sentiment).toBeGreaterThan(0.5);
});
it('handlers return { ok:false } on non-2xx responses', async () => {
const handlers = await import(resolve(BUNDLE, 'handlers.js'));
const ctx = {
fetch: async () => ({ ok: false, status: 502, json: async () => ({}) }),
memory: { note: () => {} },
};
const result = await handlers.getTrendingTokens({}, ctx);
expect(result.ok).toBe(false);
expect(result.error).toMatch(/502/);
});
});