@wzrd_sol/eliza-plugin 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,354 +0,0 @@
1
- /**
2
- * Real E2E: load wzrdPlugin via @elizaos/core AgentRuntime (critical missing piece per plan).
3
- * Constructs minimal runtime with plugins:[wzrdPlugin]; asserts intel action names present;
4
- * invokes handlers w/ mock Memory (preflight uses seller_wallet/price/resource_name);
5
- * paid path: injected mock paying fetch that returns fake IntelTrustResponse w/ receipt;
6
- * verifies callback contains decision/score/ALLOW etc + success result.
7
- * (Uses package import to match existing tsconfig.test paths + `npm run build && npm test` runtime;
8
- * plan referenced '../src/index.js' for source-load semantics in test source.)
9
- */
10
- import assert from 'node:assert/strict';
11
- import { describe, it, before, after } from 'node:test';
12
- import { AgentRuntime } from '@elizaos/core';
13
- import wzrdPlugin, { createWzrdPlugin, wzrdPluginWithLegacyEarn, intelPreflightAction, merchantCardAction, intelTrustAction, verifyReceiptAction, setPayingFetch, clearPayingFetch, getIntelClient, resolvePayingFetch, } from '@wzrd_sol/eliza-plugin';
14
- function mockMemory(content) {
15
- return {
16
- id: '00000000-0000-0000-0000-000000000001',
17
- entityId: '00000000-0000-0000-0000-000000000002',
18
- roomId: '00000000-0000-0000-0000-000000000003',
19
- content: content,
20
- createdAt: Date.now(),
21
- };
22
- }
23
- function mockRuntime(settings = {}) {
24
- const store = new Map(Object.entries(settings));
25
- return {
26
- getSetting: (key) => store.get(key) ?? null,
27
- getService: () => null,
28
- fetch: globalThis.fetch,
29
- };
30
- }
31
- describe('wzrdPlugin intel registration + E2E (real runtime load)', () => {
32
- let runtime;
33
- before(async () => {
34
- runtime = new AgentRuntime({
35
- character: { name: 'wzrd-intel-test', bio: 'test', plugins: [] },
36
- settings: { WZRD_INTEL_URL: 'https://intel.twzrd.xyz' },
37
- });
38
- await runtime.registerPlugin(wzrdPlugin);
39
- });
40
- after(() => {
41
- clearPayingFetch();
42
- });
43
- it('constructs runtime with plugins and registers intel actions', () => {
44
- const names = runtime.actions.map((a) => a.name);
45
- assert.ok(names.includes('WZRD_INTEL_PREFLIGHT'), 'preflight must be registered');
46
- assert.ok(names.includes('WZRD_MERCHANT_CARD'), 'merchant card must be registered');
47
- assert.ok(names.includes('WZRD_INTEL_TRUST'), 'trust must be registered');
48
- assert.ok(names.includes('WZRD_VERIFY_RECEIPT'), 'verify must be registered');
49
- });
50
- it('default plugin (0.6+) does not register legacy earn actions', () => {
51
- const names = runtime.actions.map((a) => a.name);
52
- for (const legacy of ['WZRD_INFER', 'WZRD_REPORT', 'WZRD_EARN', 'WZRD_CLAIM', 'WZRD_REWARDS']) {
53
- assert.equal(names.includes(legacy), false, `${legacy} must be opt-in in 0.6+`);
54
- }
55
- });
56
- it('createWzrdPlugin({ legacyEarnActions: true }) registers earn actions', async () => {
57
- const rt = new AgentRuntime({
58
- character: { name: 'wzrd-legacy-earn-test', bio: 'test', plugins: [] },
59
- settings: {},
60
- });
61
- await rt.registerPlugin(createWzrdPlugin({ legacyEarnActions: true }));
62
- const names = rt.actions.map((a) => a.name);
63
- for (const legacy of ['WZRD_INFER', 'WZRD_REPORT', 'WZRD_EARN', 'WZRD_CLAIM', 'WZRD_REWARDS']) {
64
- assert.ok(names.includes(legacy), `${legacy} must register when legacyEarnActions is true`);
65
- }
66
- });
67
- it('wzrdPluginWithLegacyEarn matches createWzrdPlugin legacy opt-in', () => {
68
- assert.deepEqual(wzrdPluginWithLegacyEarn.actions?.map((a) => a.name), createWzrdPlugin({ legacyEarnActions: true }).actions?.map((a) => a.name));
69
- });
70
- it('preflight handler accepts seller_wallet + price + resource_name, returns success + decision/score text (live)', { timeout: 10000 }, async () => {
71
- const rt = mockRuntime({ WZRD_INTEL_URL: 'https://intel.twzrd.xyz' });
72
- const callbacks = [];
73
- const result = await intelPreflightAction.handler(rt, mockMemory({
74
- seller_wallet: '4LkEFjJdXARkKx8FBx4LBFa2SvJNmjQpgGDLoJcypZUE',
75
- price_usdc: 0.05,
76
- resource_name: 'test-resource',
77
- }), undefined, undefined, async (r) => {
78
- callbacks.push(r.text ?? '');
79
- return [];
80
- });
81
- assert.equal(result?.success, true, `preflight failed: ${result?.error}`);
82
- assert.equal(typeof result.success, 'boolean');
83
- assert.ok(callbacks.length > 0);
84
- const text = callbacks.join('\n');
85
- assert.match(text, /Decision: (ALLOW|WARN|BLOCK)/i);
86
- assert.match(text, /score|trust_score/i);
87
- if (result.data)
88
- assert.ok(result.data);
89
- });
90
- it('preflight validation rejects bad seller_wallet (non-base58)', async () => {
91
- const rt = mockRuntime({ WZRD_INTEL_URL: 'https://intel.twzrd.xyz' });
92
- const callbacks = [];
93
- const result = await intelPreflightAction.handler(rt, mockMemory({ seller_wallet: 'not-base58!!!', price_usdc: 0.05 }), undefined, undefined, async (r) => {
94
- callbacks.push(r.text ?? '');
95
- return [];
96
- });
97
- assert.equal(result?.success, false);
98
- assert.equal(typeof result.success, 'boolean');
99
- const text = callbacks.join('\n');
100
- assert.match(text, /Invalid preflight input/);
101
- assert.match(text, /seller_wallet must be 32-44 char base58/);
102
- });
103
- it('preflight validation rejects negative price_usdc', async () => {
104
- const rt = mockRuntime({ WZRD_INTEL_URL: 'https://intel.twzrd.xyz' });
105
- const callbacks = [];
106
- const result = await intelPreflightAction.handler(rt, mockMemory({ seller_wallet: '4LkEFjJdXARkKx8FBx4LBFa2SvJNmjQpgGDLoJcypZUE', price_usdc: -1 }), undefined, undefined, async (r) => {
107
- callbacks.push(r.text ?? '');
108
- return [];
109
- });
110
- assert.equal(result?.success, false);
111
- assert.equal(typeof result.success, 'boolean');
112
- const text = callbacks.join('\n');
113
- assert.match(text, /Invalid preflight input/);
114
- assert.match(text, /price_usdc must be non-negative finite number/);
115
- });
116
- it('trust handler with injected paying fetch (fake IntelTrustResponse containing receipt) succeeds + surfaces score + leaf in callback', async () => {
117
- const fakeReceipt = {
118
- version: 'v5',
119
- leaf: '0xdeadbeef',
120
- preimage: { domain: 'TWZRD:AO_REPUTATION_RECEIPT_V5', agent_id: '4LkEFjJdXARkKx8FBx4LBFa2SvJNmjQpgGDLoJcypZUE', score: 99, version: 'v5' },
121
- signature: 'sig',
122
- signing_pubkey: '11111111111111111111111111111111',
123
- };
124
- setPayingFetch(async () => ({
125
- ok: true,
126
- status: 200,
127
- json: async () => ({ pubkey: '4LkEFjJdXARkKx8FBx4LBFa2SvJNmjQpgGDLoJcypZUE', trust: { score: 88 }, paid: true, twzrd_receipt: fakeReceipt }),
128
- }));
129
- const rt = mockRuntime();
130
- const callbacks = [];
131
- const result = await intelTrustAction.handler(rt, mockMemory({ pubkey: '4LkEFjJdXARkKx8FBx4LBFa2SvJNmjQpgGDLoJcypZUE' }), undefined, undefined, async (r) => {
132
- callbacks.push(r.text ?? '');
133
- return [];
134
- });
135
- assert.equal(result?.success, true, String(result?.error));
136
- assert.equal(typeof result.success, 'boolean');
137
- assert.ok(callbacks.length > 0);
138
- const text = callbacks.join('\n');
139
- assert.match(text, /Score: 88/);
140
- assert.match(text, /leaf:/i);
141
- if (result.data)
142
- assert.ok(result.data);
143
- });
144
- it('PREFLIGHT-BEFORE-PAY: decision=block aborts the trust purchase before any payment', async () => {
145
- // preSpendGate runs FREE preflight + merchant_card via global fetch (not the
146
- // injected paying fetch). Stub both; tripwire on pay leg.
147
- const realFetch = globalThis.fetch;
148
- let payAttempted = false;
149
- setPayingFetch(async () => {
150
- payAttempted = true;
151
- return { ok: true, status: 200, json: async () => ({}) };
152
- });
153
- globalThis.fetch = (async (input) => {
154
- const url = String(input);
155
- if (url.includes('/merchant_card/')) {
156
- return {
157
- ok: true,
158
- status: 200,
159
- json: async () => ({ wash_flagged: false }),
160
- };
161
- }
162
- return {
163
- ok: true,
164
- status: 200,
165
- json: async () => ({
166
- readiness_card: { decision: 'block', trust_score: 5, can_spend: false },
167
- reason: 'seller flagged by corpus',
168
- }),
169
- };
170
- });
171
- try {
172
- const callbacks = [];
173
- const result = await intelTrustAction.handler(mockRuntime(), mockMemory({ pubkey: '4LkEFjJdXARkKx8FBx4LBFa2SvJNmjQpgGDLoJcypZUE' }), undefined, undefined, async (r) => {
174
- callbacks.push(r.text ?? '');
175
- return [];
176
- });
177
- assert.equal(result?.success, false);
178
- assert.equal(result?.error, 'preflight_block');
179
- assert.equal(payAttempted, false, 'payment must NOT be attempted after a block decision');
180
- assert.match(callbacks.join('\n'), /blocked|No payment was sent/i);
181
- }
182
- finally {
183
- globalThis.fetch = realFetch;
184
- }
185
- });
186
- it('WASH REFUSE: wash_flagged aborts trust purchase even when preflight allows', async () => {
187
- const realFetch = globalThis.fetch;
188
- let payAttempted = false;
189
- setPayingFetch(async () => {
190
- payAttempted = true;
191
- return { ok: true, status: 200, json: async () => ({}) };
192
- });
193
- globalThis.fetch = (async (input) => {
194
- const url = String(input);
195
- if (url.includes('/merchant_card/')) {
196
- return {
197
- ok: true,
198
- status: 200,
199
- json: async () => ({
200
- merchant: '4LkEFjJdXARkKx8FBx4LBFa2SvJNmjQpgGDLoJcypZUE',
201
- wash_flagged: true,
202
- wash_label: 'fleet_dominated',
203
- }),
204
- };
205
- }
206
- return {
207
- ok: true,
208
- status: 200,
209
- json: async () => ({
210
- readiness_card: { decision: 'allow', trust_score: 80, can_spend: true },
211
- reason: 'preflight decision=allow',
212
- }),
213
- };
214
- });
215
- try {
216
- const callbacks = [];
217
- const result = await intelTrustAction.handler(mockRuntime(), mockMemory({ pubkey: '4LkEFjJdXARkKx8FBx4LBFa2SvJNmjQpgGDLoJcypZUE' }), undefined, undefined, async (r) => {
218
- callbacks.push(r.text ?? '');
219
- return [];
220
- });
221
- assert.equal(result?.success, false);
222
- assert.equal(result?.error, 'wash_flagged');
223
- assert.equal(payAttempted, false, 'payment must NOT run after wash refuse');
224
- assert.match(callbacks.join('\n'), /wash|No payment was sent/i);
225
- }
226
- finally {
227
- globalThis.fetch = realFetch;
228
- }
229
- });
230
- it('merchant card handler returns wash / catalog fields (mocked)', async () => {
231
- const realFetch = globalThis.fetch;
232
- globalThis.fetch = (async () => ({
233
- ok: true,
234
- status: 200,
235
- json: async () => ({
236
- merchant: '4LkEFjJdXARkKx8FBx4LBFa2SvJNmjQpgGDLoJcypZUE',
237
- in_corpus: true,
238
- wash_flagged: false,
239
- wash_label: 'provider_organic_broad',
240
- catalog_enriched: false,
241
- offering_status: 'Offering unknown — graph only',
242
- unique_payers_90d: 12,
243
- }),
244
- }));
245
- try {
246
- const callbacks = [];
247
- const result = await merchantCardAction.handler(mockRuntime(), mockMemory({ pubkey: '4LkEFjJdXARkKx8FBx4LBFa2SvJNmjQpgGDLoJcypZUE' }), undefined, undefined, async (r) => {
248
- callbacks.push(r.text ?? '');
249
- return [];
250
- });
251
- assert.equal(result?.success, true);
252
- assert.match(callbacks.join('\n'), /Wash flagged: no/i);
253
- assert.match(callbacks.join('\n'), /graph only/i);
254
- }
255
- finally {
256
- globalThis.fetch = realFetch;
257
- }
258
- });
259
- it('VERIFY: a V6 receipt (reputation_* bound into the leaf) is accepted by the verify action path', async () => {
260
- // Live receipts are V6; the SDK selects the leaf binding from the domain, so a
261
- // V6 receipt must round-trip through WZRD_VERIFY_RECEIPT without a V5/V6 mixup.
262
- // We assert the action runs and reports the V6 domain rather than erroring.
263
- const v6Receipt = {
264
- version: 'v6',
265
- leaf: '0x4c82649d2be393b1fca2da7c5d4c7afebb189ad3f0b93b620ce2e552fe5ce558',
266
- preimage: {
267
- domain: 'TWZRD:AO_REPUTATION_RECEIPT_V6',
268
- agent_id: '11111111111111111111111111111111',
269
- score: 72,
270
- confidence_bps: 8000,
271
- timestamp_unix: 1748736000,
272
- payer: '11111111111111111111111111111111',
273
- settlement_tx: 'EXAMPLE-sample-receipt-no-real-settlement-tx-0001',
274
- reputation_score: 4242,
275
- reputation_confidence_bps: 7500,
276
- reputation_score_version: 'intel_renorm_v1',
277
- reputation_feature_window_start_unix: 1748000000,
278
- reputation_data_quality: 'high',
279
- version: 'v6',
280
- },
281
- signature: 'sig',
282
- signing_pubkey: '11111111111111111111111111111111',
283
- };
284
- const callbacks = [];
285
- const result = await verifyReceiptAction.handler(mockRuntime(), mockMemory({ receipt: v6Receipt }), undefined, undefined, async (r) => {
286
- callbacks.push(r.text ?? '');
287
- return [];
288
- });
289
- // The action ran (no exception) and exercised the SDK V6 leaf path. The
290
- // signature is a stub so it won't pass authenticity, but the leaf must
291
- // recompute against the V6 binding (not the V5 one) — proven by the SDK's
292
- // own canonical-vector tests; here we assert the action did not crash and
293
- // surfaced a verdict for the V6 domain.
294
- assert.ok(result, 'verify action returned a result for a V6 receipt');
295
- assert.ok(callbacks.length > 0, 'verify action produced output for a V6 receipt');
296
- });
297
- it('trust surfaces payment_required + x402/agentcash text on 402 from (failing) fetch (explicit IntelPaymentRequiredError branch)', async () => {
298
- setPayingFetch(async () => ({
299
- ok: false,
300
- status: 402,
301
- headers: { get: () => null },
302
- json: async () => ({ error: 'payment required' }),
303
- text: async () => '',
304
- }));
305
- const rt = mockRuntime();
306
- const callbacks = [];
307
- const result = await intelTrustAction.handler(rt, mockMemory({ pubkey: '4LkEFjJdXARkKx8FBx4LBFa2SvJNmjQpgGDLoJcypZUE' }), undefined, undefined, async (r) => {
308
- callbacks.push(r.text ?? '');
309
- return [];
310
- });
311
- assert.equal(result?.success, false);
312
- assert.equal(result?.error, 'payment_required');
313
- assert.equal(typeof result.success, 'boolean');
314
- const text = callbacks.join('\n');
315
- assert.match(text, /x402|Intel trust requires|agentcash/i);
316
- });
317
- it('verify handler runs with receipt content (exercises SDK verify path)', async () => {
318
- const rt = mockRuntime();
319
- const callbacks = [];
320
- const minimalReceipt = {
321
- version: 'v5',
322
- leaf: '0x0000000000000000000000000000000000000000000000000000000000000000',
323
- preimage: { domain: 'TWZRD:AO_REPUTATION_RECEIPT_V5', agent_id: '4LkEFjJdXARkKx8FBx4LBFa2SvJNmjQpgGDLoJcypZUE', score: 0, version: 'v5' },
324
- signature: 'AA',
325
- signing_pubkey: '11111111111111111111111111111111',
326
- };
327
- const result = await verifyReceiptAction.handler(rt, mockMemory({ receipt: minimalReceipt }), undefined, undefined, async (r) => {
328
- callbacks.push(r.text ?? '');
329
- return [];
330
- });
331
- assert.ok(result, 'verify handler must return');
332
- assert.equal(typeof result.success, 'boolean');
333
- assert.equal(result.success, false);
334
- assert.ok(callbacks.length > 0);
335
- const text = callbacks.join('\n');
336
- assert.match(text, /INVALID/);
337
- });
338
- it('getIntelClient factory + resolvePayingFetch service fallback exercised (covers factory delegates and resolve branches)', () => {
339
- clearPayingFetch(); // ensure module-level does not shadow the service fallback we want to test
340
- const mockPaying = async () => ({ ok: true, status: 200, json: async () => ({}) });
341
- const rt = {
342
- getSetting: () => null,
343
- getService: (n) => (n === 'payingFetch' ? { fetch: mockPaying } : null),
344
- fetch: globalThis.fetch,
345
- };
346
- const intel = getIntelClient(rt);
347
- assert.equal(typeof intel.preflight, 'function');
348
- assert.equal(typeof intel.trust, 'function');
349
- assert.equal(typeof intel.verify, 'function');
350
- // exercise at least one resolve fallback path (service)
351
- const resolved = resolvePayingFetch(rt);
352
- assert.equal(resolved, mockPaying);
353
- });
354
- });