@vibe-lang/runtime 0.2.9 → 0.2.10

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,11 +1,15 @@
1
1
  import { describe, expect, test } from 'bun:test';
2
2
  import { parse } from '../../parser/parse';
3
3
  import { SemanticAnalyzer } from '../analyzer';
4
+ import { join } from 'path';
4
5
 
5
- function analyze(source: string) {
6
+ // Test fixtures directory
7
+ const fixturesDir = join(__dirname, 'fixtures');
8
+
9
+ function analyze(source: string, basePath?: string) {
6
10
  const ast = parse(source);
7
11
  const analyzer = new SemanticAnalyzer();
8
- return analyzer.analyze(ast, source);
12
+ return analyzer.analyze(ast, source, basePath);
9
13
  }
10
14
 
11
15
  describe('Semantic Analysis - Import Declarations', () => {
@@ -146,3 +150,63 @@ describe('Semantic Analysis - TsBlock', () => {
146
150
  expect(errors).toHaveLength(3);
147
151
  });
148
152
  });
153
+
154
+ describe('Semantic Analysis - Vibe Import Validation', () => {
155
+ const mainFile = join(fixturesDir, 'main.vibe');
156
+
157
+ test('valid import of exported function from vibe file', () => {
158
+ const errors = analyze(`
159
+ import { greet } from "./exports.vibe"
160
+ let msg = greet("world")
161
+ `, mainFile);
162
+ expect(errors).toHaveLength(0);
163
+ });
164
+
165
+ test('valid import of multiple exports from vibe file', () => {
166
+ const errors = analyze(`
167
+ import { greet, add, VERSION } from "./exports.vibe"
168
+ let msg = greet("world")
169
+ `, mainFile);
170
+ expect(errors).toHaveLength(0);
171
+ });
172
+
173
+ test('valid import of exported model from vibe file', () => {
174
+ const errors = analyze(`
175
+ import { testModel } from "./exports.vibe"
176
+ let x: text = "test"
177
+ `, mainFile);
178
+ expect(errors).toHaveLength(0);
179
+ });
180
+
181
+ test('error: import non-existent function from vibe file', () => {
182
+ const errors = analyze(`
183
+ import { nonExistent } from "./exports.vibe"
184
+ `, mainFile);
185
+ expect(errors).toHaveLength(1);
186
+ expect(errors[0].message).toMatch(/'nonExistent' is not exported from/);
187
+ });
188
+
189
+ test('error: import non-exported private function from vibe file', () => {
190
+ const errors = analyze(`
191
+ import { privateHelper } from "./exports.vibe"
192
+ `, mainFile);
193
+ expect(errors).toHaveLength(1);
194
+ expect(errors[0].message).toMatch(/'privateHelper' is not exported from/);
195
+ });
196
+
197
+ test('error: import non-exported constant from vibe file', () => {
198
+ const errors = analyze(`
199
+ import { INTERNAL_SECRET } from "./exports.vibe"
200
+ `, mainFile);
201
+ expect(errors).toHaveLength(1);
202
+ expect(errors[0].message).toMatch(/'INTERNAL_SECRET' is not exported from/);
203
+ });
204
+
205
+ test('error: import mix of valid and invalid from vibe file', () => {
206
+ const errors = analyze(`
207
+ import { greet, fakeFunction, VERSION } from "./exports.vibe"
208
+ `, mainFile);
209
+ expect(errors).toHaveLength(1);
210
+ expect(errors[0].message).toMatch(/'fakeFunction' is not exported from/);
211
+ });
212
+ });
@@ -340,4 +340,48 @@ describe('Semantic Analyzer - Prompt Parameter Validation', () => {
340
340
  expect(errors).toEqual([]);
341
341
  });
342
342
  });
343
+
344
+ // ============================================================================
345
+ // Expansion syntax in prompt-returning functions
346
+ // ============================================================================
347
+
348
+ describe('expansion syntax in prompt-returning functions', () => {
349
+ test('function returning prompt can use !{} expansion', () => {
350
+ const errors = getErrors(`
351
+ function makePrompt(name: text): prompt {
352
+ return "Hello !{name}, how are you?"
353
+ }
354
+ `);
355
+ expect(errors).toEqual([]);
356
+ });
357
+
358
+ test('function returning prompt can use !{} in template literal', () => {
359
+ const errors = getErrors(`
360
+ function makePrompt(data: text): prompt {
361
+ return \`Process this: !{data}\`
362
+ }
363
+ `);
364
+ expect(errors).toEqual([]);
365
+ });
366
+
367
+ test('function returning text cannot use !{} expansion', () => {
368
+ const errors = getErrors(`
369
+ function makeText(name: text): text {
370
+ return "Hello !{name}"
371
+ }
372
+ `);
373
+ expect(errors.length).toBeGreaterThan(0);
374
+ expect(errors[0]).toContain('Expansion syntax');
375
+ });
376
+
377
+ test('function with no return type cannot use !{} expansion', () => {
378
+ const errors = getErrors(`
379
+ function noType(name: text) {
380
+ return "Hello !{name}"
381
+ }
382
+ `);
383
+ expect(errors.length).toBeGreaterThan(0);
384
+ expect(errors[0]).toContain('Expansion syntax');
385
+ });
386
+ });
343
387
  });