ai-evaluate 2.1.8 → 2.3.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.
Files changed (74) hide show
  1. package/README.md +16 -0
  2. package/dist/evaluate.d.ts.map +1 -1
  3. package/dist/evaluate.js +10 -10
  4. package/dist/evaluate.js.map +1 -1
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/miniflare-pool.d.ts.map +1 -1
  8. package/dist/miniflare-pool.js +1 -1
  9. package/dist/miniflare-pool.js.map +1 -1
  10. package/dist/node.d.ts.map +1 -1
  11. package/dist/node.js.map +1 -1
  12. package/dist/repl.js +6 -6
  13. package/dist/repl.js.map +1 -1
  14. package/dist/shared.d.ts.map +1 -1
  15. package/dist/shared.js +5 -2
  16. package/dist/shared.js.map +1 -1
  17. package/dist/static/index.d.ts +111 -0
  18. package/dist/static/index.d.ts.map +1 -0
  19. package/dist/static/index.js +347 -0
  20. package/dist/static/index.js.map +1 -0
  21. package/dist/type-guards.d.ts.map +1 -1
  22. package/dist/type-guards.js +64 -62
  23. package/dist/type-guards.js.map +1 -1
  24. package/dist/worker-template/core.d.ts.map +1 -1
  25. package/dist/worker-template/core.js +1 -1
  26. package/dist/worker-template/core.js.map +1 -1
  27. package/package.json +19 -6
  28. package/public/capnweb.mjs +220 -0
  29. package/public/index.mjs +426 -0
  30. package/public/scaffold.mjs +198 -0
  31. package/.turbo/turbo-build.log +0 -4
  32. package/.turbo/turbo-test.log +0 -54
  33. package/.turbo/turbo-typecheck.log +0 -4
  34. package/CHANGELOG.md +0 -48
  35. package/dist/worker-template.d.ts +0 -41
  36. package/dist/worker-template.d.ts.map +0 -1
  37. package/dist/worker-template.js +0 -3748
  38. package/dist/worker-template.js.map +0 -1
  39. package/example/package.json +0 -20
  40. package/example/src/index.ts +0 -221
  41. package/example/wrangler.jsonc +0 -25
  42. package/src/capnweb-bundle.ts +0 -2596
  43. package/src/evaluate.ts +0 -329
  44. package/src/index.ts +0 -23
  45. package/src/miniflare-pool.ts +0 -395
  46. package/src/node.ts +0 -245
  47. package/src/repl.ts +0 -228
  48. package/src/shared.ts +0 -186
  49. package/src/type-guards.ts +0 -323
  50. package/src/types.ts +0 -196
  51. package/src/validation.ts +0 -120
  52. package/src/worker-template/code-transforms.ts +0 -32
  53. package/src/worker-template/core.ts +0 -557
  54. package/src/worker-template/helpers.ts +0 -90
  55. package/src/worker-template/index.ts +0 -23
  56. package/src/worker-template/sdk-generator.ts +0 -2515
  57. package/src/worker-template/test-generator.ts +0 -358
  58. package/test/evaluate-extended.test.js +0 -429
  59. package/test/evaluate-extended.test.ts +0 -469
  60. package/test/evaluate.test.js +0 -235
  61. package/test/evaluate.test.ts +0 -253
  62. package/test/index.test.js +0 -77
  63. package/test/index.test.ts +0 -95
  64. package/test/miniflare-pool.test.ts +0 -246
  65. package/test/node.test.ts +0 -467
  66. package/test/security.test.ts +0 -1009
  67. package/test/shared.test.ts +0 -105
  68. package/test/type-guards.test.ts +0 -303
  69. package/test/validation.test.ts +0 -240
  70. package/test/worker-template.test.js +0 -365
  71. package/test/worker-template.test.ts +0 -432
  72. package/tsconfig.json +0 -22
  73. package/vitest.config.js +0 -21
  74. package/vitest.config.ts +0 -28
@@ -1,365 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { generateWorkerCode, generateDevWorkerCode } from '../src/worker-template.js';
3
- describe('generateWorkerCode (production)', () => {
4
- describe('basic structure', () => {
5
- it('generates valid worker code', () => {
6
- const code = generateWorkerCode({});
7
- expect(code).toContain('export default');
8
- expect(code).toContain('async fetch(request, env)');
9
- });
10
- it('includes console capture', () => {
11
- const code = generateWorkerCode({});
12
- expect(code).toContain('captureConsole');
13
- expect(code).toContain('console.log = captureConsole');
14
- expect(code).toContain('console.warn = captureConsole');
15
- expect(code).toContain('console.error = captureConsole');
16
- });
17
- it('checks for TEST service binding', () => {
18
- const code = generateWorkerCode({});
19
- expect(code).toContain('env.TEST');
20
- expect(code).toContain('TEST service binding not available');
21
- });
22
- });
23
- describe('module embedding', () => {
24
- it('embeds module code when provided', () => {
25
- const code = generateWorkerCode({
26
- module: 'exports.foo = 42;'
27
- });
28
- expect(code).toContain('exports.foo = 42;');
29
- });
30
- it('extracts export names from exports.name pattern', () => {
31
- const code = generateWorkerCode({
32
- module: 'exports.add = (a, b) => a + b; exports.sub = (a, b) => a - b;'
33
- });
34
- expect(code).toContain('const { add, sub } = exports');
35
- });
36
- it('extracts export names from exports["name"] pattern', () => {
37
- const code = generateWorkerCode({
38
- module: 'exports["myFunc"] = () => {};'
39
- });
40
- expect(code).toContain('myFunc');
41
- });
42
- it('handles no module code', () => {
43
- const code = generateWorkerCode({});
44
- expect(code).toContain('// No module code provided');
45
- });
46
- });
47
- describe('test embedding', () => {
48
- it('embeds test code when provided', () => {
49
- const code = generateWorkerCode({
50
- tests: 'describe("test", () => {});'
51
- });
52
- expect(code).toContain('describe("test", () => {});');
53
- });
54
- it('handles no test code', () => {
55
- const code = generateWorkerCode({});
56
- expect(code).toContain('// No test code provided');
57
- });
58
- });
59
- describe('script embedding', () => {
60
- it('embeds script code when provided', () => {
61
- const code = generateWorkerCode({
62
- script: 'return 42;'
63
- });
64
- expect(code).toContain('return 42;');
65
- });
66
- it('handles no script code', () => {
67
- const code = generateWorkerCode({});
68
- expect(code).toContain('// No script code provided');
69
- });
70
- });
71
- describe('RPC setup', () => {
72
- it('connects to test service via RPC', () => {
73
- const code = generateWorkerCode({});
74
- expect(code).toContain('env.TEST.connect()');
75
- expect(code).toContain('const testService = await env.TEST.connect()');
76
- });
77
- it('sets up test functions from RPC service', () => {
78
- const code = generateWorkerCode({});
79
- expect(code).toContain('const describe = (name, fn) => testService.describe(name, fn)');
80
- expect(code).toContain('const it = (name, fn) => testService.it(name, fn)');
81
- expect(code).toContain('const expect = (value, message) => testService.expect(value, message)');
82
- });
83
- it('includes skip and only modifiers', () => {
84
- const code = generateWorkerCode({});
85
- expect(code).toContain('it.skip');
86
- expect(code).toContain('it.only');
87
- expect(code).toContain('test.skip');
88
- expect(code).toContain('test.only');
89
- });
90
- });
91
- describe('capnweb RPC', () => {
92
- it('imports capnweb', () => {
93
- const code = generateWorkerCode({});
94
- expect(code).toContain("import { RpcTarget, newWorkersRpcResponse } from 'capnweb'");
95
- });
96
- it('creates ExportsRpcTarget class', () => {
97
- const code = generateWorkerCode({});
98
- expect(code).toContain('class ExportsRpcTarget extends RpcTarget');
99
- });
100
- it('handles /rpc route', () => {
101
- const code = generateWorkerCode({});
102
- expect(code).toContain("url.pathname === '/rpc'");
103
- expect(code).toContain('newWorkersRpcResponse(request, new ExportsRpcTarget())');
104
- });
105
- it('handles GET / route for info', () => {
106
- const code = generateWorkerCode({});
107
- expect(code).toContain("url.pathname === '/'");
108
- expect(code).toContain("exports: Object.keys(exports)");
109
- });
110
- });
111
- describe('GET /:name endpoint', () => {
112
- it('handles GET requests to export names', () => {
113
- const code = generateWorkerCode({});
114
- expect(code).toContain("request.method === 'GET'");
115
- expect(code).toContain('url.pathname.slice(1)');
116
- expect(code).toContain('exports[name]');
117
- });
118
- it('returns non-function exports directly', () => {
119
- const code = generateWorkerCode({});
120
- expect(code).toContain("typeof value !== 'function'");
121
- expect(code).toContain('return Response.json({ result: value })');
122
- });
123
- it('supports args query parameter with JSON array', () => {
124
- const code = generateWorkerCode({});
125
- expect(code).toContain("url.searchParams.get('args')");
126
- expect(code).toContain('JSON.parse(argsParam)');
127
- });
128
- it('supports named query parameters as object', () => {
129
- const code = generateWorkerCode({});
130
- expect(code).toContain('Object.fromEntries(url.searchParams.entries())');
131
- });
132
- it('returns 404 for missing exports', () => {
133
- const code = generateWorkerCode({});
134
- expect(code).toContain('not found');
135
- expect(code).toContain('status: 404');
136
- });
137
- });
138
- describe('ES module syntax support', () => {
139
- it('transforms export const to CommonJS', () => {
140
- const code = generateWorkerCode({
141
- module: 'export const add = (a, b) => a + b'
142
- });
143
- expect(code).toContain('const add = exports.add =');
144
- expect(code).toContain('const { add } = exports');
145
- });
146
- it('transforms export function to CommonJS', () => {
147
- const code = generateWorkerCode({
148
- module: 'export function multiply(a, b) { return a * b }'
149
- });
150
- expect(code).toContain('function multiply');
151
- expect(code).toContain('exports.multiply = multiply');
152
- expect(code).toContain('const { multiply } = exports');
153
- });
154
- it('handles mixed ES and CommonJS exports', () => {
155
- const code = generateWorkerCode({
156
- module: `
157
- export const foo = 1
158
- exports.bar = 2
159
- `
160
- });
161
- expect(code).toContain('const foo = exports.foo =');
162
- expect(code).toContain('exports.bar = 2');
163
- expect(code).toContain('foo');
164
- expect(code).toContain('bar');
165
- });
166
- });
167
- describe('script auto-return', () => {
168
- it('auto-returns single expressions', () => {
169
- const code = generateWorkerCode({
170
- script: 'add(1, 2)'
171
- });
172
- expect(code).toContain('return add(1, 2)');
173
- });
174
- it('does not modify scripts with return', () => {
175
- const code = generateWorkerCode({
176
- script: 'return add(1, 2)'
177
- });
178
- expect(code).toContain('return add(1, 2)');
179
- expect(code).not.toContain('return return');
180
- });
181
- it('does not modify throw statements', () => {
182
- const code = generateWorkerCode({
183
- script: 'throw new Error("test")'
184
- });
185
- expect(code).toContain('throw new Error("test")');
186
- expect(code).not.toContain('return throw');
187
- });
188
- it('auto-returns last expression in multi-line scripts', () => {
189
- const code = generateWorkerCode({
190
- script: `
191
- const x = 1
192
- x + 1
193
- `
194
- });
195
- expect(code).toContain('return x + 1');
196
- });
197
- });
198
- });
199
- describe('generateDevWorkerCode (development)', () => {
200
- describe('basic structure', () => {
201
- it('generates valid worker code', () => {
202
- const code = generateDevWorkerCode({});
203
- expect(code).toContain('export default');
204
- expect(code).toContain('async fetch(request, env)');
205
- });
206
- it('includes embedded test framework', () => {
207
- const code = generateDevWorkerCode({});
208
- expect(code).toContain('const describe = (name, fn)');
209
- expect(code).toContain('const it = (name, fn)');
210
- expect(code).toContain('const expect = (actual)');
211
- });
212
- it('does not require TEST service', () => {
213
- const code = generateDevWorkerCode({});
214
- expect(code).not.toContain('env.TEST');
215
- });
216
- });
217
- describe('embedded test framework', () => {
218
- it('includes describe function', () => {
219
- const code = generateDevWorkerCode({});
220
- expect(code).toContain('const describe = (name, fn)');
221
- expect(code).toContain('currentDescribe');
222
- });
223
- it('includes it/test functions', () => {
224
- const code = generateDevWorkerCode({});
225
- expect(code).toContain('const it = (name, fn)');
226
- expect(code).toContain('const test = it');
227
- });
228
- it('includes skip and only', () => {
229
- const code = generateDevWorkerCode({});
230
- expect(code).toContain('it.skip');
231
- expect(code).toContain('it.only');
232
- });
233
- it('includes beforeEach/afterEach hooks', () => {
234
- const code = generateDevWorkerCode({});
235
- expect(code).toContain('const beforeEach = (fn)');
236
- expect(code).toContain('const afterEach = (fn)');
237
- });
238
- it('includes deep equality check', () => {
239
- const code = generateDevWorkerCode({});
240
- expect(code).toContain('const deepEqual = (a, b)');
241
- });
242
- });
243
- describe('embedded expect matchers', () => {
244
- it('includes toBe', () => {
245
- const code = generateDevWorkerCode({});
246
- expect(code).toContain('toBe:');
247
- });
248
- it('includes toEqual', () => {
249
- const code = generateDevWorkerCode({});
250
- expect(code).toContain('toEqual:');
251
- });
252
- it('includes toStrictEqual', () => {
253
- const code = generateDevWorkerCode({});
254
- expect(code).toContain('toStrictEqual:');
255
- });
256
- it('includes toBeTruthy', () => {
257
- const code = generateDevWorkerCode({});
258
- expect(code).toContain('toBeTruthy:');
259
- });
260
- it('includes toBeFalsy', () => {
261
- const code = generateDevWorkerCode({});
262
- expect(code).toContain('toBeFalsy:');
263
- });
264
- it('includes toBeNull', () => {
265
- const code = generateDevWorkerCode({});
266
- expect(code).toContain('toBeNull:');
267
- });
268
- it('includes toBeUndefined', () => {
269
- const code = generateDevWorkerCode({});
270
- expect(code).toContain('toBeUndefined:');
271
- });
272
- it('includes toBeDefined', () => {
273
- const code = generateDevWorkerCode({});
274
- expect(code).toContain('toBeDefined:');
275
- });
276
- it('includes toBeNaN', () => {
277
- const code = generateDevWorkerCode({});
278
- expect(code).toContain('toBeNaN:');
279
- });
280
- it('includes toContain', () => {
281
- const code = generateDevWorkerCode({});
282
- expect(code).toContain('toContain:');
283
- });
284
- it('includes toContainEqual', () => {
285
- const code = generateDevWorkerCode({});
286
- expect(code).toContain('toContainEqual:');
287
- });
288
- it('includes toHaveLength', () => {
289
- const code = generateDevWorkerCode({});
290
- expect(code).toContain('toHaveLength:');
291
- });
292
- it('includes toHaveProperty', () => {
293
- const code = generateDevWorkerCode({});
294
- expect(code).toContain('toHaveProperty:');
295
- });
296
- it('includes toMatchObject', () => {
297
- const code = generateDevWorkerCode({});
298
- expect(code).toContain('toMatchObject:');
299
- });
300
- it('includes toThrow', () => {
301
- const code = generateDevWorkerCode({});
302
- expect(code).toContain('toThrow:');
303
- });
304
- it('includes toBeGreaterThan', () => {
305
- const code = generateDevWorkerCode({});
306
- expect(code).toContain('toBeGreaterThan:');
307
- });
308
- it('includes toBeLessThan', () => {
309
- const code = generateDevWorkerCode({});
310
- expect(code).toContain('toBeLessThan:');
311
- });
312
- it('includes toBeCloseTo', () => {
313
- const code = generateDevWorkerCode({});
314
- expect(code).toContain('toBeCloseTo:');
315
- });
316
- it('includes toMatch', () => {
317
- const code = generateDevWorkerCode({});
318
- expect(code).toContain('toMatch:');
319
- });
320
- it('includes toBeInstanceOf', () => {
321
- const code = generateDevWorkerCode({});
322
- expect(code).toContain('toBeInstanceOf:');
323
- });
324
- it('includes toBeTypeOf', () => {
325
- const code = generateDevWorkerCode({});
326
- expect(code).toContain('toBeTypeOf:');
327
- });
328
- it('includes not matchers', () => {
329
- const code = generateDevWorkerCode({});
330
- expect(code).toContain('matchers.not = {');
331
- });
332
- it('includes resolves proxy', () => {
333
- const code = generateDevWorkerCode({});
334
- expect(code).toContain('matchers.resolves');
335
- });
336
- it('includes rejects proxy', () => {
337
- const code = generateDevWorkerCode({});
338
- expect(code).toContain('matchers.rejects');
339
- });
340
- });
341
- describe('module embedding', () => {
342
- it('embeds module code when provided', () => {
343
- const code = generateDevWorkerCode({
344
- module: 'exports.foo = 42;'
345
- });
346
- expect(code).toContain('exports.foo = 42;');
347
- });
348
- });
349
- describe('test embedding', () => {
350
- it('embeds test code when provided', () => {
351
- const code = generateDevWorkerCode({
352
- tests: 'describe("test", () => {});'
353
- });
354
- expect(code).toContain('describe("test", () => {});');
355
- });
356
- });
357
- describe('script embedding', () => {
358
- it('embeds script code when provided', () => {
359
- const code = generateDevWorkerCode({
360
- script: 'return 42;'
361
- });
362
- expect(code).toContain('return 42;');
363
- });
364
- });
365
- });