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 * as fsp from 'fs/promises'
|
|
|
|
import * as path from 'path'
|
2024-12-20 13:39:06 +11:00
|
|
|
|
|
|
|
/* eslint-disable jest/no-conditional-expect */
|
|
|
|
|
2025-03-21 22:39:12 +13:00
|
|
|
const file = `sketch001 = startSketchOn(XZ)
|
2025-04-25 16:01:35 -05:00
|
|
|
profile001 = startProfile(sketch001, at = [57.81, 250.51])
|
KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
line\(([^=]*), %\)
line(end = $1)
line\((.*), %, (.*)\)
line(end = $1, tag = $2)
lineTo\((.*), %\)
line(endAbsolute = $1)
lineTo\((.*), %, (.*)\)
line(endAbsolute = $1, tag = $2)
extrude\((.*), %\)
extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
close\(%, (.*)\)
close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
- Make a lineTo helper
- Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
- Test was looking for the old style of `line` call to choose an offset
for pathToNode
- Test assumed that the `tag` param was always the third one, but in
a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
2025-02-04 08:31:43 -06: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 = [-114, 85.52])
|
2025-03-07 22:07:16 -06:00
|
|
|
|> xLine(length = 265.36)
|
2025-02-28 16:26:11 -05:00
|
|
|
|> line(end = [33.17, -261.22])
|
2025-03-07 22:07:16 -06:00
|
|
|
|> xLine(length = -297.25)
|
KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
line\(([^=]*), %\)
line(end = $1)
line\((.*), %, (.*)\)
line(end = $1, tag = $2)
lineTo\((.*), %\)
line(endAbsolute = $1)
lineTo\((.*), %, (.*)\)
line(endAbsolute = $1, tag = $2)
extrude\((.*), %\)
extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
close\(%, (.*)\)
close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
- Make a lineTo helper
- Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
- Test was looking for the old style of `line` call to choose an offset
for pathToNode
- Test assumed that the `tag` param was always the third one, but in
a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
2025-02-04 08:31:43 -06:00
|
|
|
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
|
|
|
|> close()
|
|
|
|
extrude002 = extrude(sketch002, length = 50)
|
2025-03-21 22:39:12 +13:00
|
|
|
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)
|
KCL: Use keyword arguments for line, lineTo, extrude and close (#5249)
Part of #4600.
PR: https://github.com/KittyCAD/modeling-app/pull/4826
# Changes to KCL stdlib
- `line(point, sketch, tag)` and `lineTo(point, sketch, tag)` are combined into `line(@sketch, end?, endAbsolute?, tag?)`
- `close(sketch, tag?)` is now `close(@sketch, tag?)`
- `extrude(length, sketch)` is now `extrude(@sketch, length)`
Note that if a parameter starts with `@` like `@sketch`, it doesn't have any label when called, so you call it like this:
```
sketch = startSketchAt([0, 0])
line(sketch, end = [3, 3], tag = $hi)
```
Note also that if you're using a `|>` pipeline, you can omit the `@` argument and it will be assumed to be the LHS of the `|>`. So the above could be written as
```
sketch = startSketchAt([0, 0])
|> line(end = [3, 3], tag = $hi)
```
Also changes frontend tests to use KittyCAD/kcl-samples#139 instead of its main
The regex find-and-replace I use for migrating code (note these don't work with multi-line expressions) are:
```
line\(([^=]*), %\)
line(end = $1)
line\((.*), %, (.*)\)
line(end = $1, tag = $2)
lineTo\((.*), %\)
line(endAbsolute = $1)
lineTo\((.*), %, (.*)\)
line(endAbsolute = $1, tag = $2)
extrude\((.*), %\)
extrude(length = $1)
extrude\(([^=]*), ([a-zA-Z0-9]+)\)
extrude($2, length = $1)
close\(%, (.*)\)
close(tag = $1)
```
# Selected notes from commits before I squash them all
* Fix test 'yRelative to horizontal distance'
Fixes:
- Make a lineTo helper
- Fix pathToNode to go through the labeled arg .arg property
* Fix test by changing lookups into transformMap
Parts of the code assumed that `line` is always a relative call. But
actually now it might be absolute, if it's got an `endAbsolute` parameter.
So, change whether to look up `line` or `lineTo` and the relevant absolute
or relative line types based on that parameter.
* Stop asserting on exact source ranges
When I changed line to kwargs, all the source ranges we assert on became
slightly different. I find these assertions to be very very low value.
So I'm removing them.
* Fix more tests: getConstraintType calls weren't checking if the
'line' fn was absolute or relative.
* Fixed another queryAst test
There were 2 problems:
- Test was looking for the old style of `line` call to choose an offset
for pathToNode
- Test assumed that the `tag` param was always the third one, but in
a kwarg call, you have to look it up by label
* Fix test: traverse was not handling CallExpressionKw
* Fix another test, addTagKw
addTag helper was not aware of kw args.
* Convert close from positional to kwargs
If the close() call has 0 args, or a single unlabeled arg, the parser
interprets it as a CallExpression (positional) not a CallExpressionKw.
But then if a codemod wants to add a tag to it, it tries adding a kwarg
called 'tag', which fails because the CallExpression doesn't need
kwargs inserted into it.
The fix is: change the node from CallExpression to CallExpressionKw, and
update getNodeFromPath to take a 'replacement' arg, so we can replace
the old node with the new node in the AST.
* Fix the last test
Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.
Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
* Fix many bad regex find-replaces
I wrote a regex find-and-replace which converted `line` calls from
positional to keyword calls. But it was accidentally applied to more
places than it should be, for example, angledLine, xLine and yLine calls.
Fixes this.
* Fixes test 'Basic sketch › code pane closed at start'
Problem was, the getNodeFromPath call might not actually find a callExpressionKw,
it might find a callExpression. So the `giveSketchFnCallTag` thought
it was modifying a kwargs call, but it was actually modifying a positional
call.
This meant it tried to push a labeled argument in, rather than a normal
arg, and a lot of other problems. Fixed by doing runtime typechecking.
* Fix: Optional args given with wrong type were silently ignored
Optional args don't have to be given. But if the user gives them, they
should be the right type.
Bug: if the KCL interpreter found an optional arg, which was given, but
was the wrong type, it would ignore it and pretend the arg was never
given at all. This was confusing for users.
Fix: Now if you give an optional arg, but it's the wrong type, KCL will
emit a type error just like it would for a mandatory argument.
---------
Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Frank Noirot <frank@kittycad.io>
Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
2025-02-04 08:31:43 -06:00
|
|
|
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
|
|
|
|> close()
|
|
|
|
extrude003 = extrude(sketch003, length = 20)
|
2024-12-20 13:39:06 +11:00
|
|
|
`
|
|
|
|
|
2025-04-24 20:50:26 -04:00
|
|
|
test.describe('Prompt-to-edit tests', () => {
|
2025-02-26 14:06:51 +11:00
|
|
|
test.describe('Check the happy path, for basic changing color', () => {
|
2025-02-06 09:45:12 -05:00
|
|
|
const cases = [
|
|
|
|
{
|
|
|
|
desc: 'User accepts change',
|
|
|
|
shouldReject: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: 'User rejects change',
|
|
|
|
shouldReject: true,
|
|
|
|
},
|
|
|
|
] as const
|
|
|
|
for (const { desc, shouldReject } of cases) {
|
|
|
|
test(`${desc}`, async ({
|
|
|
|
context,
|
|
|
|
homePage,
|
|
|
|
cmdBar,
|
|
|
|
editor,
|
|
|
|
page,
|
|
|
|
scene,
|
|
|
|
}) => {
|
2025-05-08 03:54:40 +10:00
|
|
|
await context.folderSetupFn(async (dir) => {
|
|
|
|
const projectDir = path.join(dir, 'test-project')
|
|
|
|
await fsp.mkdir(projectDir, { recursive: true })
|
|
|
|
await fsp.writeFile(path.join(projectDir, 'main.kcl'), file)
|
|
|
|
})
|
|
|
|
await homePage.openProject('test-project')
|
2025-04-07 07:08:31 -04:00
|
|
|
await scene.settled(cmdBar)
|
2024-12-20 13:39:06 +11:00
|
|
|
|
2025-02-28 16:26:11 -05:00
|
|
|
const body1CapCoords = { x: 571, y: 311 }
|
2025-02-06 09:45:12 -05:00
|
|
|
const [clickBody1Cap] = scene.makeMouseHelpers(
|
|
|
|
body1CapCoords.x,
|
|
|
|
body1CapCoords.y
|
|
|
|
)
|
|
|
|
const yellow: [number, number, number] = [179, 179, 131]
|
|
|
|
const submittingToast = page.getByText(
|
|
|
|
'Submitting to Text-to-CAD API...'
|
|
|
|
)
|
|
|
|
const successToast = page.getByText('Prompt to edit successful')
|
2025-02-11 11:13:25 -06:00
|
|
|
const acceptBtn = page.getByRole('button', {
|
2025-05-08 03:54:40 +10:00
|
|
|
name: 'checkmark Continue',
|
2025-02-11 11:13:25 -06:00
|
|
|
})
|
2025-05-08 03:54:40 +10:00
|
|
|
const rejectBtn = page.getByRole('button', { name: 'close Revert' })
|
2024-12-20 13:39:06 +11:00
|
|
|
|
2025-02-06 09:45:12 -05:00
|
|
|
await test.step('wait for scene to load select body and check selection came through', async () => {
|
|
|
|
await scene.expectPixelColor([134, 134, 134], body1CapCoords, 15)
|
|
|
|
await clickBody1Cap()
|
|
|
|
await scene.expectPixelColor(yellow, body1CapCoords, 20)
|
|
|
|
await editor.expectState({
|
|
|
|
highlightedCode: '',
|
2025-04-25 16:01:35 -05:00
|
|
|
activeLines: ['|>startProfile(at=[-114,85.52])'],
|
2025-02-06 09:45:12 -05:00
|
|
|
diagnostics: [],
|
|
|
|
})
|
2024-12-20 13:39:06 +11:00
|
|
|
})
|
|
|
|
|
2025-02-06 09:45:12 -05:00
|
|
|
await test.step('fire off edit prompt', async () => {
|
|
|
|
await cmdBar.openCmdBar('promptToEdit')
|
|
|
|
// 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()
|
2025-02-11 11:13:25 -06:00
|
|
|
await expect(submittingToast).not.toBeVisible({
|
|
|
|
timeout: 2 * 60_000,
|
|
|
|
}) // can take a while
|
2025-02-06 09:45:12 -05:00
|
|
|
await expect(successToast).toBeVisible()
|
|
|
|
})
|
2024-12-20 13:39:06 +11:00
|
|
|
|
2025-02-06 09:45:12 -05:00
|
|
|
await test.step('verify initial change', async () => {
|
2025-02-07 16:36:51 -06:00
|
|
|
await editor.expectEditor.toContain('appearance(')
|
2024-12-20 13:39:06 +11:00
|
|
|
})
|
|
|
|
|
2025-02-06 09:45:12 -05:00
|
|
|
if (!shouldReject) {
|
2025-05-08 03:54:40 +10:00
|
|
|
await test.step('check accept works', async () => {
|
2025-02-06 09:45:12 -05:00
|
|
|
await acceptBtn.click()
|
|
|
|
await expect(successToast).not.toBeVisible()
|
|
|
|
|
2025-02-07 16:36:51 -06:00
|
|
|
await editor.expectEditor.toContain('appearance(')
|
2025-02-06 09:45:12 -05:00
|
|
|
})
|
|
|
|
} else {
|
|
|
|
await test.step('check reject works', async () => {
|
|
|
|
await rejectBtn.click()
|
|
|
|
await expect(successToast).not.toBeVisible()
|
|
|
|
|
2025-02-07 16:36:51 -06:00
|
|
|
await editor.expectEditor.not.toContain('appearance(')
|
2025-02-06 09:45:12 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2024-12-20 13:39:06 +11:00
|
|
|
|
2025-02-26 14:06:51 +11:00
|
|
|
test('bad edit prompt', async ({
|
2024-12-20 13:39:06 +11:00
|
|
|
context,
|
|
|
|
homePage,
|
|
|
|
cmdBar,
|
|
|
|
editor,
|
|
|
|
toolbar,
|
|
|
|
page,
|
|
|
|
scene,
|
|
|
|
}) => {
|
|
|
|
await context.addInitScript((file) => {
|
|
|
|
localStorage.setItem('persistCode', file)
|
|
|
|
}, file)
|
|
|
|
await homePage.goToModelingScene()
|
2025-04-07 07:08:31 -04:00
|
|
|
await scene.settled(cmdBar)
|
2024-12-20 13:39:06 +11:00
|
|
|
|
2025-02-28 16:26:11 -05:00
|
|
|
const body1CapCoords = { x: 571, y: 311 }
|
2024-12-20 13:39:06 +11:00
|
|
|
const [clickBody1Cap] = scene.makeMouseHelpers(
|
|
|
|
body1CapCoords.x,
|
|
|
|
body1CapCoords.y
|
|
|
|
)
|
|
|
|
const yellow: [number, number, number] = [179, 179, 131]
|
2024-12-20 14:52:07 +11:00
|
|
|
const submittingToast = page.getByText('Submitting to Text-to-CAD API...')
|
2024-12-20 13:39:06 +11:00
|
|
|
const failToast = page.getByText(
|
|
|
|
'Failed to edit your KCL code, please try again with a different prompt or selection'
|
|
|
|
)
|
|
|
|
|
|
|
|
await test.step('wait for scene to load and select body', async () => {
|
|
|
|
await scene.expectPixelColor([134, 134, 134], body1CapCoords, 15)
|
|
|
|
|
|
|
|
await clickBody1Cap()
|
|
|
|
await scene.expectPixelColor(yellow, body1CapCoords, 20)
|
|
|
|
|
|
|
|
await editor.expectState({
|
|
|
|
highlightedCode: '',
|
2025-04-25 16:01:35 -05:00
|
|
|
activeLines: ['|>startProfile(at=[-114,85.52])'],
|
2024-12-20 13:39:06 +11:00
|
|
|
diagnostics: [],
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
await test.step('fire of bad prompt', async () => {
|
|
|
|
await cmdBar.openCmdBar('promptToEdit')
|
|
|
|
await page
|
|
|
|
.getByTestId('cmd-bar-arg-value')
|
|
|
|
.fill('ansheusha asnthuatshoeuhtaoetuhthaeu laughs in dvorak')
|
|
|
|
await page.waitForTimeout(100)
|
|
|
|
await cmdBar.progressCmdBar()
|
|
|
|
await expect(submittingToast).toBeVisible()
|
|
|
|
})
|
|
|
|
await test.step('check fail toast appeared', async () => {
|
|
|
|
await expect(submittingToast).not.toBeVisible({ timeout: 2 * 60_000 }) // can take a while
|
|
|
|
await expect(failToast).toBeVisible()
|
|
|
|
})
|
|
|
|
})
|
2025-02-26 14:06:51 +11:00
|
|
|
|
2025-03-20 16:28:08 -04:00
|
|
|
test(`manual code selection rename`, async ({
|
|
|
|
context,
|
|
|
|
homePage,
|
|
|
|
cmdBar,
|
|
|
|
editor,
|
|
|
|
page,
|
|
|
|
scene,
|
|
|
|
}) => {
|
|
|
|
const body1CapCoords = { x: 571, y: 311 }
|
2025-02-26 14:06:51 +11:00
|
|
|
|
2025-03-20 16:28:08 -04:00
|
|
|
await context.addInitScript((file) => {
|
|
|
|
localStorage.setItem('persistCode', file)
|
|
|
|
}, file)
|
|
|
|
await homePage.goToModelingScene()
|
2025-04-07 07:08:31 -04:00
|
|
|
await scene.settled(cmdBar)
|
2025-02-26 14:06:51 +11:00
|
|
|
|
2025-03-20 16:28:08 -04:00
|
|
|
const submittingToast = page.getByText('Submitting to Text-to-CAD API...')
|
|
|
|
const successToast = page.getByText('Prompt to edit successful')
|
2025-05-08 03:54:40 +10:00
|
|
|
const acceptBtn = page.getByRole('button', { name: 'checkmark Continue' })
|
2025-02-26 14:06:51 +11:00
|
|
|
|
2025-03-20 16:28:08 -04:00
|
|
|
await test.step('wait for scene to load and select code in editor', async () => {
|
|
|
|
// Find and select the text "sketch002" in the editor
|
|
|
|
await editor.selectText('sketch002')
|
2025-02-26 14:06:51 +11:00
|
|
|
|
2025-03-20 16:28:08 -04:00
|
|
|
// Verify the selection was made
|
|
|
|
await editor.expectState({
|
|
|
|
highlightedCode: '',
|
2025-03-21 22:39:12 +13:00
|
|
|
activeLines: ['sketch002 = startSketchOn(XZ)'],
|
2025-03-20 16:28:08 -04:00
|
|
|
diagnostics: [],
|
2025-02-26 14:06:51 +11:00
|
|
|
})
|
2025-03-20 16:28:08 -04:00
|
|
|
})
|
2025-02-26 14:06:51 +11:00
|
|
|
|
2025-03-20 16:28:08 -04:00
|
|
|
await test.step('fire off edit prompt', async () => {
|
|
|
|
await scene.expectPixelColor([134, 134, 134], body1CapCoords, 15)
|
|
|
|
await cmdBar.openCmdBar('promptToEdit')
|
|
|
|
await page
|
|
|
|
.getByTestId('cmd-bar-arg-value')
|
|
|
|
.fill('Please rename to mySketch001')
|
|
|
|
await page.waitForTimeout(100)
|
|
|
|
await cmdBar.progressCmdBar()
|
|
|
|
await expect(submittingToast).toBeVisible()
|
|
|
|
await expect(submittingToast).not.toBeVisible({
|
|
|
|
timeout: 2 * 60_000,
|
2025-02-26 14:06:51 +11:00
|
|
|
})
|
2025-03-20 16:28:08 -04:00
|
|
|
await expect(successToast).toBeVisible()
|
|
|
|
})
|
2025-02-26 14:06:51 +11:00
|
|
|
|
2025-03-20 16:28:08 -04:00
|
|
|
await test.step('verify rename change and accept it', async () => {
|
|
|
|
await editor.expectEditor.toContain('mySketch001 = startSketchOn')
|
|
|
|
await editor.expectEditor.not.toContain('sketch002 = startSketchOn')
|
|
|
|
await editor.expectEditor.toContain(
|
|
|
|
'extrude002 = extrude(mySketch001, length = 50)'
|
|
|
|
)
|
2025-02-26 14:06:51 +11:00
|
|
|
|
2025-03-20 16:28:08 -04:00
|
|
|
await acceptBtn.click()
|
|
|
|
await expect(successToast).not.toBeVisible()
|
|
|
|
})
|
|
|
|
})
|
2025-02-26 14:06:51 +11:00
|
|
|
|
|
|
|
test('multiple body selections', async ({
|
|
|
|
context,
|
|
|
|
homePage,
|
|
|
|
cmdBar,
|
|
|
|
editor,
|
|
|
|
page,
|
|
|
|
scene,
|
|
|
|
}) => {
|
2025-02-28 16:26:11 -05:00
|
|
|
const body1CapCoords = { x: 571, y: 311 }
|
2025-02-26 14:06:51 +11:00
|
|
|
const body2WallCoords = { x: 620, y: 152 }
|
|
|
|
const [clickBody1Cap] = scene.makeMouseHelpers(
|
|
|
|
body1CapCoords.x,
|
|
|
|
body1CapCoords.y
|
|
|
|
)
|
|
|
|
const [clickBody2Cap] = scene.makeMouseHelpers(
|
|
|
|
body2WallCoords.x,
|
|
|
|
body2WallCoords.y
|
|
|
|
)
|
|
|
|
const grey: [number, number, number] = [132, 132, 132]
|
|
|
|
|
|
|
|
await context.addInitScript((file) => {
|
|
|
|
localStorage.setItem('persistCode', file)
|
|
|
|
}, file)
|
|
|
|
await homePage.goToModelingScene()
|
2025-04-07 07:08:31 -04:00
|
|
|
await scene.settled(cmdBar)
|
2025-02-26 14:06:51 +11:00
|
|
|
|
|
|
|
const submittingToast = page.getByText('Submitting to Text-to-CAD API...')
|
|
|
|
const successToast = page.getByText('Prompt to edit successful')
|
2025-05-08 03:54:40 +10:00
|
|
|
const acceptBtn = page.getByRole('button', { name: 'checkmark Continue' })
|
2025-02-26 14:06:51 +11:00
|
|
|
|
|
|
|
await test.step('select multiple bodies and fire prompt', async () => {
|
|
|
|
// Initial color check
|
|
|
|
await scene.expectPixelColor(grey, body1CapCoords, 15)
|
|
|
|
|
|
|
|
// Open command bar first (without selection)
|
|
|
|
await cmdBar.openCmdBar('promptToEdit')
|
|
|
|
|
|
|
|
// Select first body
|
|
|
|
await page.waitForTimeout(100)
|
|
|
|
await clickBody1Cap()
|
|
|
|
|
|
|
|
// Hold shift and select second body
|
|
|
|
await editor.expectState({
|
|
|
|
highlightedCode: '',
|
2025-04-25 16:01:35 -05:00
|
|
|
activeLines: ['|>startProfile(at=[-114,85.52])'],
|
2025-02-26 14:06:51 +11:00
|
|
|
diagnostics: [],
|
|
|
|
})
|
|
|
|
await page.keyboard.down('Shift')
|
|
|
|
await page.waitForTimeout(100)
|
|
|
|
await clickBody2Cap()
|
|
|
|
await editor.expectState({
|
|
|
|
highlightedCode:
|
|
|
|
'line(end=[121.13,56.63],tag=$seg02)extrude(profile001,length=200)',
|
|
|
|
activeLines: [
|
|
|
|
'|>line(end=[121.13,56.63],tag=$seg02)',
|
2025-04-25 16:01:35 -05:00
|
|
|
'|>startProfile(at=[-114,85.52])',
|
2025-02-26 14:06:51 +11:00
|
|
|
],
|
|
|
|
diagnostics: [],
|
|
|
|
})
|
|
|
|
await page.keyboard.up('Shift')
|
|
|
|
await page.waitForTimeout(100)
|
|
|
|
await cmdBar.progressCmdBar()
|
|
|
|
|
|
|
|
// Enter prompt and submit
|
|
|
|
await page
|
|
|
|
.getByTestId('cmd-bar-arg-value')
|
|
|
|
.fill('make these neon green please, use #39FF14')
|
|
|
|
await page.waitForTimeout(100)
|
|
|
|
await cmdBar.progressCmdBar()
|
|
|
|
|
|
|
|
// Wait for API response
|
|
|
|
await expect(submittingToast).toBeVisible()
|
|
|
|
await expect(submittingToast).not.toBeVisible({
|
|
|
|
timeout: 2 * 60_000,
|
|
|
|
})
|
|
|
|
await expect(successToast).toBeVisible()
|
|
|
|
})
|
|
|
|
|
|
|
|
await test.step('verify code changed', async () => {
|
|
|
|
await editor.expectEditor.toContain('appearance(')
|
|
|
|
|
|
|
|
// Accept changes
|
|
|
|
await acceptBtn.click()
|
|
|
|
await expect(successToast).not.toBeVisible()
|
|
|
|
})
|
|
|
|
})
|
2024-12-20 13:39:06 +11:00
|
|
|
})
|