2025-04-01 23:54:26 -07:00
|
|
|
import { expect, test } from '@e2e/playwright/zoo-test'
|
2025-05-08 03:54:40 +10:00
|
|
|
import path from 'path'
|
|
|
|
import fsp from 'fs/promises'
|
2025-04-01 23:54:26 -07:00
|
|
|
|
2025-02-27 05:44:40 +11:00
|
|
|
/* eslint-disable jest/no-conditional-expect */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Snapshot Tests for Text-to-CAD API Requests
|
|
|
|
*
|
|
|
|
* These tests are primarily designed to capture the requests sent to the Text-to-CAD API
|
|
|
|
* rather than to verify application behavior. Unlike regular tests, these tests:
|
|
|
|
*
|
|
|
|
* 1. Don't assert much about the application's response or state changes
|
|
|
|
* 2. Focus on setting up specific scenarios and triggering API requests
|
|
|
|
* 3. Use the captureTextToCadRequestSnapshot() method to save request payloads to snapshot files
|
|
|
|
*
|
|
|
|
* The main purpose is to maintain a collection of real-world API request examples that can be:
|
|
|
|
* - Used for regression testing the (AI) API
|
|
|
|
* - Referenced when making changes to the Text-to-CAD integration, particularly the meta-prompts
|
|
|
|
* the frontend adds to the user's prompt
|
|
|
|
*
|
|
|
|
* These tests intentionally don't wait for or verify responses, as we're primarily
|
|
|
|
* interested in capturing the outgoing requests for documentation and analysis.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2025-05-08 03:54:40 +10:00
|
|
|
const fileWithImport = `import "b.kcl" as b
|
|
|
|
sketch001 = startSketchOn(XZ)
|
2025-04-25 16:01:35 -05:00
|
|
|
profile001 = startProfile(sketch001, at = [57.81, 250.51])
|
2025-02-27 05:44:40 +11:00
|
|
|
|> line(end = [121.13, 56.63], tag = $seg02)
|
|
|
|
|> line(end = [83.37, -34.61], tag = $seg01)
|
|
|
|
|> line(end = [19.66, -116.4])
|
|
|
|
|> line(end = [-221.8, -41.69])
|
|
|
|
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
|
|
|
|> close()
|
|
|
|
extrude001 = extrude(profile001, length = 200)
|
2025-03-21 22:39:12 +13:00
|
|
|
sketch002 = startSketchOn(XZ)
|
2025-04-25 16:01:35 -05:00
|
|
|
|> startProfile(at = [-73.64, -42.89])
|
2025-03-07 22:07:16 -06:00
|
|
|
|> xLine(length = 173.71)
|
2025-02-27 05:44:40 +11:00
|
|
|
|> line(end = [-22.12, -94.4])
|
2025-03-07 22:07:16 -06:00
|
|
|
|> xLine(length = -156.98)
|
2025-02-27 05:44:40 +11:00
|
|
|
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
|
|
|
|> close()
|
|
|
|
extrude002 = extrude(sketch002, length = 50)
|
2025-05-08 03:54:40 +10:00
|
|
|
b
|
|
|
|
`
|
|
|
|
|
|
|
|
const importedFile = `sketch003 = startSketchOn(XY)
|
2025-04-25 16:01:35 -05:00
|
|
|
|> startProfile(at = [52.92, 157.81])
|
KCL: Angled line should use keyword args (#5803)
We continue migrating KCL stdlib functions to use keyword arguments. Next up is the `angledLine` family of functions (except `angledLineThatIntersects, which will be a quick follow-up).
Before vs. after:
`angledLine({angle = 90, length = 3}, %, $edge)`
=> `angledLine(angle = 90, length = 3, tag = $edge)`
`angledLineOfXLength({angle = 90, length = 3}, %, $edge)`
=> `angledLine(angle = 90, lengthX = 3, tag = $edge)`
`angledLineOfYLength({angle = 90, length = 3}, %, $edge)`
=> `angledLine(angle = 90, lengthY = 3, tag = $edge)`
`angledLineToX({angle = 90, length = 3}, %, $edge)`
=> `angledLine(angle = 90, endAbsoluteX = 3, tag = $edge)`
`angledLineToY({angle = 90, length = 3}, %, $edge)`
=> `angledLine(angle = 90, endAbsoluteY = 3, tag = $edge)`
2025-04-09 14:55:15 -05:00
|
|
|
|> angledLine(angle = 0, length = 176.4, tag = $rectangleSegmentA001)
|
|
|
|
|> angledLine(
|
|
|
|
angle = segAng(rectangleSegmentA001) - 90,
|
|
|
|
length = 53.4,
|
|
|
|
tag = $rectangleSegmentB001,
|
|
|
|
)
|
|
|
|
|> angledLine(angle = segAng(rectangleSegmentA001), length = -segLen(rectangleSegmentA001), tag = $rectangleSegmentC001)
|
2025-02-27 05:44:40 +11:00
|
|
|
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
|
|
|
|> close()
|
2025-05-08 03:54:40 +10:00
|
|
|
extrude(sketch003, length = 20)
|
2025-02-27 05:44:40 +11:00
|
|
|
`
|
2025-05-08 03:54:40 +10:00
|
|
|
|
2025-03-18 11:14:12 +11:00
|
|
|
test.describe('edit with AI example snapshots', () => {
|
|
|
|
test(
|
|
|
|
`change colour`,
|
2025-05-08 03:54:40 +10:00
|
|
|
// TODO this is more of a snapshot, but atm it needs to be manually run locally to update the files
|
2025-05-29 09:29:03 -04:00
|
|
|
{ tag: ['@desktop'] },
|
2025-03-18 11:14:12 +11:00
|
|
|
async ({ context, homePage, cmdBar, editor, page, scene }) => {
|
2025-05-08 03:54:40 +10:00
|
|
|
const project = 'test-dir'
|
|
|
|
await context.folderSetupFn(async (dir) => {
|
|
|
|
const projectDir = path.join(dir, project)
|
|
|
|
await fsp.mkdir(projectDir, { recursive: true })
|
|
|
|
|
|
|
|
// Create the imported file
|
|
|
|
await fsp.writeFile(path.join(projectDir, 'b.kcl'), importedFile)
|
|
|
|
|
|
|
|
// Create the main file that imports
|
|
|
|
await fsp.writeFile(path.join(projectDir, 'main.kcl'), fileWithImport)
|
|
|
|
})
|
|
|
|
|
|
|
|
await homePage.openProject(project)
|
2025-04-07 07:08:31 -04:00
|
|
|
await scene.settled(cmdBar)
|
2025-02-27 05:44:40 +11:00
|
|
|
|
2025-03-18 11:14:12 +11:00
|
|
|
const body1CapCoords = { x: 571, y: 351 }
|
|
|
|
const [clickBody1Cap] = scene.makeMouseHelpers(
|
|
|
|
body1CapCoords.x,
|
|
|
|
body1CapCoords.y
|
|
|
|
)
|
|
|
|
const submittingToast = page.getByText('Submitting to Text-to-CAD API...')
|
2025-02-27 05:44:40 +11:00
|
|
|
|
2025-03-18 11:14:12 +11:00
|
|
|
await test.step('wait for scene to load select body and check selection came through', async () => {
|
|
|
|
await clickBody1Cap()
|
|
|
|
await editor.expectState({
|
|
|
|
highlightedCode: '',
|
2025-04-25 16:01:35 -05:00
|
|
|
activeLines: ['|>startProfile(at=[-73.64,-42.89])'],
|
2025-03-18 11:14:12 +11:00
|
|
|
diagnostics: [],
|
|
|
|
})
|
2025-02-27 05:44:40 +11:00
|
|
|
})
|
|
|
|
|
2025-03-18 11:14:12 +11:00
|
|
|
await test.step('fire off edit prompt', async () => {
|
|
|
|
await cmdBar.captureTextToCadRequestSnapshot(test.info())
|
|
|
|
await cmdBar.openCmdBar('promptToEdit')
|
2025-05-16 05:15:52 -04:00
|
|
|
await page.waitForTimeout(100)
|
|
|
|
await cmdBar.progressCmdBar()
|
2025-03-18 11:14:12 +11:00
|
|
|
// being specific about the color with a hex means asserting pixel color is more stable
|
|
|
|
await page
|
|
|
|
.getByTestId('cmd-bar-arg-value')
|
|
|
|
.fill('make this neon green please, use #39FF14')
|
|
|
|
await page.waitForTimeout(100)
|
|
|
|
await cmdBar.progressCmdBar()
|
|
|
|
await expect(submittingToast).toBeVisible()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|