|
1 | | -import { createTscircuitCoder } from "lib/tscircuit-coder/tscircuitCoder" |
2 | 1 | import { expect, test } from "bun:test" |
| 2 | +import { createTscircuitCoder } from "lib/tscircuit-coder/tscircuitCoder" |
3 | 3 | import { getPrimarySourceCodeFromVfs } from "lib/utils/get-primary-source-code-from-vfs" |
4 | 4 |
|
5 | | -test("TscircuitCoder submitPrompt streams and updates vfs", async () => { |
6 | | - const streamedChunks: string[] = [] |
7 | | - let vfsUpdated = false |
8 | | - const tscircuitCoder = createTscircuitCoder() |
9 | | - tscircuitCoder.on("streamedChunk", (chunk: string) => { |
10 | | - streamedChunks.push(chunk) |
11 | | - }) |
12 | | - tscircuitCoder.on("vfsChanged", () => { |
13 | | - vfsUpdated = true |
14 | | - }) |
15 | | - |
16 | | - await tscircuitCoder.submitPrompt({ |
17 | | - prompt: "create bridge rectifier circuit", |
18 | | - }) |
19 | | - |
20 | | - await tscircuitCoder.submitPrompt({ |
21 | | - prompt: "add a transistor component", |
22 | | - }) |
23 | | - |
24 | | - let codeWithTransistor = getPrimarySourceCodeFromVfs(tscircuitCoder.vfs) |
25 | | - expect(codeWithTransistor).toInclude("transistor") |
26 | | - |
27 | | - await tscircuitCoder.submitPrompt({ |
28 | | - prompt: "add a tssop20 chip", |
29 | | - }) |
30 | | - |
31 | | - let codeWithChip = getPrimarySourceCodeFromVfs(tscircuitCoder.vfs) |
32 | | - expect(codeWithChip).toInclude("tssop20") |
33 | | - expect(codeWithChip).toInclude("transistor") |
34 | | - |
35 | | - expect(streamedChunks.length).toBeGreaterThan(0) |
36 | | - const vfsKeys = Object.keys(tscircuitCoder.vfs) |
37 | | - expect(vfsKeys.length).toBeGreaterThan(0) |
38 | | - expect(vfsUpdated).toBe(true) |
39 | | -}) |
| 5 | +const testWithOpenAi = process.env.OPENAI_API_KEY ? test : test.skip |
| 6 | + |
| 7 | +testWithOpenAi( |
| 8 | + "TscircuitCoder submitPrompt streams and updates vfs", |
| 9 | + async () => { |
| 10 | + const streamedChunks: string[] = [] |
| 11 | + let vfsUpdated = false |
| 12 | + const tscircuitCoder = createTscircuitCoder() |
| 13 | + tscircuitCoder.on("streamedChunk", (chunk: string) => { |
| 14 | + streamedChunks.push(chunk) |
| 15 | + }) |
| 16 | + tscircuitCoder.on("vfsChanged", () => { |
| 17 | + vfsUpdated = true |
| 18 | + }) |
| 19 | + |
| 20 | + await tscircuitCoder.submitPrompt({ |
| 21 | + prompt: "create bridge rectifier circuit", |
| 22 | + }) |
| 23 | + |
| 24 | + await tscircuitCoder.submitPrompt({ |
| 25 | + prompt: "add a transistor component", |
| 26 | + }) |
| 27 | + |
| 28 | + const codeWithTransistor = getPrimarySourceCodeFromVfs(tscircuitCoder.vfs) |
| 29 | + expect(codeWithTransistor).toInclude("transistor") |
| 30 | + |
| 31 | + await tscircuitCoder.submitPrompt({ |
| 32 | + prompt: "add a tssop20 chip", |
| 33 | + }) |
| 34 | + |
| 35 | + const codeWithChip = getPrimarySourceCodeFromVfs(tscircuitCoder.vfs) |
| 36 | + expect(codeWithChip).toInclude("tssop20") |
| 37 | + expect(codeWithChip).toInclude("transistor") |
| 38 | + |
| 39 | + expect(streamedChunks.length).toBeGreaterThan(0) |
| 40 | + const vfsKeys = Object.keys(tscircuitCoder.vfs) |
| 41 | + expect(vfsKeys.length).toBeGreaterThan(0) |
| 42 | + expect(vfsUpdated).toBe(true) |
| 43 | + }, |
| 44 | +) |
0 commit comments