2025-04-01 23:54:26 -07:00
|
|
|
import type { EngineCommand } from '@src/lang/std/artifactGraph'
|
|
|
|
import { uuidv4 } from '@src/lib/utils'
|
|
|
|
|
|
|
|
import {
|
|
|
|
commonPoints,
|
|
|
|
getUtils,
|
|
|
|
orRunWhenFullSuiteEnabled,
|
|
|
|
} from '@e2e/playwright/test-utils'
|
|
|
|
import { expect, test } from '@e2e/playwright/zoo-test'
|
2024-08-07 19:27:32 +10:00
|
|
|
|
2025-03-20 16:28:08 -04:00
|
|
|
test.describe('Test network and connection issues', () => {
|
2025-02-11 11:13:25 -06:00
|
|
|
test(
|
|
|
|
'simulate network down and network little widget',
|
|
|
|
{ tag: '@skipLocalEngine' },
|
|
|
|
async ({ page, homePage }) => {
|
2025-03-20 23:52:30 -04:00
|
|
|
test.fixme(orRunWhenFullSuiteEnabled())
|
2025-02-11 11:13:25 -06:00
|
|
|
const u = await getUtils(page)
|
|
|
|
await page.setBodyDimensions({ width: 1200, height: 500 })
|
|
|
|
|
|
|
|
await homePage.goToModelingScene()
|
|
|
|
|
|
|
|
const networkToggle = page.getByTestId('network-toggle')
|
|
|
|
|
|
|
|
// This is how we wait until the stream is online
|
|
|
|
await expect(
|
|
|
|
page.getByRole('button', { name: 'Start Sketch' })
|
|
|
|
).not.toBeDisabled({ timeout: 15000 })
|
|
|
|
|
|
|
|
const networkWidget = page.locator('[data-testid="network-toggle"]')
|
|
|
|
await expect(networkWidget).toBeVisible()
|
|
|
|
await networkWidget.hover()
|
|
|
|
|
|
|
|
const networkPopover = page.locator('[data-testid="network-popover"]')
|
|
|
|
await expect(networkPopover).not.toBeVisible()
|
|
|
|
|
|
|
|
// (First check) Expect the network to be up
|
|
|
|
await expect(networkToggle).toContainText('Connected')
|
|
|
|
|
|
|
|
// Click the network widget
|
|
|
|
await networkWidget.click()
|
|
|
|
|
|
|
|
// Check the modal opened.
|
|
|
|
await expect(networkPopover).toBeVisible()
|
|
|
|
|
|
|
|
// Click off the modal.
|
|
|
|
await page.mouse.click(100, 100)
|
|
|
|
await expect(networkPopover).not.toBeVisible()
|
|
|
|
|
|
|
|
// Turn off the network
|
|
|
|
await u.emulateNetworkConditions({
|
|
|
|
offline: true,
|
|
|
|
// values of 0 remove any active throttling. crbug.com/456324#c9
|
|
|
|
latency: 0,
|
|
|
|
downloadThroughput: -1,
|
|
|
|
uploadThroughput: -1,
|
|
|
|
})
|
|
|
|
|
|
|
|
// Expect the network to be down
|
|
|
|
await expect(networkToggle).toContainText('Problem')
|
|
|
|
|
|
|
|
// Click the network widget
|
|
|
|
await networkWidget.click()
|
|
|
|
|
|
|
|
// Check the modal opened.
|
|
|
|
await expect(networkPopover).toBeVisible()
|
|
|
|
|
|
|
|
// Click off the modal.
|
|
|
|
await page.mouse.click(0, 0)
|
|
|
|
await expect(networkPopover).not.toBeVisible()
|
|
|
|
|
|
|
|
// Turn back on the network
|
|
|
|
await u.emulateNetworkConditions({
|
|
|
|
offline: false,
|
|
|
|
// values of 0 remove any active throttling. crbug.com/456324#c9
|
|
|
|
latency: 0,
|
|
|
|
downloadThroughput: -1,
|
|
|
|
uploadThroughput: -1,
|
|
|
|
})
|
|
|
|
|
|
|
|
await expect(
|
|
|
|
page.getByRole('button', { name: 'Start Sketch' })
|
|
|
|
).not.toBeDisabled({ timeout: 15000 })
|
|
|
|
|
|
|
|
// (Second check) expect the network to be up
|
|
|
|
await expect(networkToggle).toContainText('Connected')
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
test(
|
|
|
|
'Engine disconnect & reconnect in sketch mode',
|
|
|
|
{ tag: '@skipLocalEngine' },
|
2025-04-07 07:08:31 -04:00
|
|
|
async ({ page, homePage, toolbar, scene, cmdBar }) => {
|
2025-03-20 23:52:30 -04:00
|
|
|
test.fixme(orRunWhenFullSuiteEnabled())
|
2025-02-11 11:13:25 -06:00
|
|
|
const networkToggle = page.getByTestId('network-toggle')
|
|
|
|
|
|
|
|
const u = await getUtils(page)
|
|
|
|
await page.setBodyDimensions({ width: 1200, height: 500 })
|
|
|
|
const PUR = 400 / 37.5 //pixeltoUnitRatio
|
|
|
|
|
|
|
|
await homePage.goToModelingScene()
|
|
|
|
await u.waitForPageLoad()
|
|
|
|
|
|
|
|
await u.openDebugPanel()
|
|
|
|
// click on "Start Sketch" button
|
|
|
|
await u.clearCommandLogs()
|
|
|
|
await page.getByRole('button', { name: 'Start Sketch' }).click()
|
|
|
|
await page.waitForTimeout(100)
|
|
|
|
|
|
|
|
// select a plane
|
|
|
|
await page.mouse.click(700, 200)
|
|
|
|
|
|
|
|
await expect(page.locator('.cm-content')).toHaveText(
|
2025-03-21 22:39:12 +13:00
|
|
|
`sketch001 = startSketchOn(XZ)`
|
2025-02-11 11:13:25 -06:00
|
|
|
)
|
|
|
|
await u.closeDebugPanel()
|
|
|
|
|
|
|
|
await page.waitForTimeout(500) // TODO detect animation ending, or disable animation
|
|
|
|
|
|
|
|
const startXPx = 600
|
|
|
|
await page.mouse.click(startXPx + PUR * 10, 500 - PUR * 10)
|
2025-02-15 00:57:04 +11:00
|
|
|
await expect(page.locator('.cm-content')).toHaveText(
|
2025-03-21 22:39:12 +13:00
|
|
|
`sketch001 = startSketchOn(XZ)profile001 = startProfileAt(${commonPoints.startAt}, sketch001)`
|
2025-02-15 00:57:04 +11:00
|
|
|
)
|
2025-02-11 11:13:25 -06:00
|
|
|
await page.waitForTimeout(100)
|
2024-08-07 19:27:32 +10:00
|
|
|
|
2025-02-11 11:13:25 -06:00
|
|
|
await page.mouse.click(startXPx + PUR * 20, 500 - PUR * 10)
|
|
|
|
await page.waitForTimeout(100)
|
2024-08-07 19:27:32 +10:00
|
|
|
|
2025-02-11 11:13:25 -06:00
|
|
|
await expect(page.locator('.cm-content'))
|
2025-03-21 22:39:12 +13:00
|
|
|
.toHaveText(`sketch001 = startSketchOn(XZ)profile001 = startProfileAt(${commonPoints.startAt}, sketch001)
|
2025-03-07 22:07:16 -06:00
|
|
|
|> xLine(length = ${commonPoints.num1})`)
|
2024-08-07 19:27:32 +10:00
|
|
|
|
2025-02-11 11:13:25 -06:00
|
|
|
// Expect the network to be up
|
|
|
|
await expect(networkToggle).toContainText('Connected')
|
|
|
|
|
|
|
|
// simulate network down
|
|
|
|
await u.emulateNetworkConditions({
|
|
|
|
offline: true,
|
|
|
|
// values of 0 remove any active throttling. crbug.com/456324#c9
|
|
|
|
latency: 0,
|
|
|
|
downloadThroughput: -1,
|
|
|
|
uploadThroughput: -1,
|
|
|
|
})
|
|
|
|
|
|
|
|
// Expect the network to be down
|
|
|
|
await expect(networkToggle).toContainText('Problem')
|
|
|
|
|
|
|
|
// Ensure we are not in sketch mode
|
|
|
|
await expect(
|
|
|
|
page.getByRole('button', { name: 'Exit Sketch' })
|
|
|
|
).not.toBeVisible()
|
|
|
|
await expect(
|
|
|
|
page.getByRole('button', { name: 'Start Sketch' })
|
|
|
|
).toBeVisible()
|
|
|
|
|
|
|
|
// simulate network up
|
|
|
|
await u.emulateNetworkConditions({
|
|
|
|
offline: false,
|
|
|
|
// values of 0 remove any active throttling. crbug.com/456324#c9
|
|
|
|
latency: 0,
|
|
|
|
downloadThroughput: -1,
|
|
|
|
uploadThroughput: -1,
|
|
|
|
})
|
|
|
|
|
|
|
|
// Wait for the app to be ready for use
|
|
|
|
await expect(
|
|
|
|
page.getByRole('button', { name: 'Start Sketch' })
|
|
|
|
).not.toBeDisabled({ timeout: 15000 })
|
|
|
|
|
|
|
|
// Expect the network to be up
|
|
|
|
await expect(networkToggle).toContainText('Connected')
|
2025-04-07 07:08:31 -04:00
|
|
|
await scene.settled(cmdBar)
|
2025-02-11 11:13:25 -06:00
|
|
|
|
|
|
|
// Click off the code pane.
|
|
|
|
await page.mouse.click(100, 100)
|
|
|
|
|
|
|
|
// select a line
|
2025-02-15 00:57:04 +11:00
|
|
|
await page
|
|
|
|
.getByText(`startProfileAt(${commonPoints.startAt}, sketch001)`)
|
|
|
|
.click()
|
2025-02-11 11:13:25 -06:00
|
|
|
|
|
|
|
// enter sketch again
|
2025-03-20 13:10:28 -04:00
|
|
|
await toolbar.editSketch()
|
2025-02-11 11:13:25 -06:00
|
|
|
|
|
|
|
// Click the line tool
|
|
|
|
await page.getByRole('button', { name: 'line Line', exact: true }).click()
|
|
|
|
|
|
|
|
await page.waitForTimeout(150)
|
|
|
|
|
2025-02-15 00:57:04 +11:00
|
|
|
const camCommand: EngineCommand = {
|
|
|
|
type: 'modeling_cmd_req',
|
|
|
|
cmd_id: uuidv4(),
|
|
|
|
cmd: {
|
|
|
|
type: 'default_camera_look_at',
|
|
|
|
center: { x: 109, y: 0, z: -152 },
|
|
|
|
vantage: { x: 115, y: -505, z: -152 },
|
|
|
|
up: { x: 0, y: 0, z: 1 },
|
|
|
|
},
|
|
|
|
}
|
|
|
|
const updateCamCommand: EngineCommand = {
|
|
|
|
type: 'modeling_cmd_req',
|
|
|
|
cmd_id: uuidv4(),
|
|
|
|
cmd: {
|
|
|
|
type: 'default_camera_get_settings',
|
|
|
|
},
|
|
|
|
}
|
2025-03-20 13:10:28 -04:00
|
|
|
await toolbar.openPane('debug')
|
2025-02-15 00:57:04 +11:00
|
|
|
await u.sendCustomCmd(camCommand)
|
|
|
|
await page.waitForTimeout(100)
|
|
|
|
await u.sendCustomCmd(updateCamCommand)
|
|
|
|
await page.waitForTimeout(100)
|
|
|
|
|
|
|
|
// click to continue profile
|
|
|
|
await page.mouse.click(1007, 400)
|
|
|
|
await page.waitForTimeout(100)
|
2025-02-11 11:13:25 -06:00
|
|
|
// Ensure we can continue sketching
|
|
|
|
await page.mouse.click(startXPx + PUR * 20, 500 - PUR * 20)
|
|
|
|
await expect.poll(u.normalisedEditorCode)
|
2025-03-21 22:39:12 +13:00
|
|
|
.toBe(`sketch001 = startSketchOn(XZ)
|
2025-02-15 00:57:04 +11:00
|
|
|
profile001 = startProfileAt([12.34, -12.34], sketch001)
|
2025-03-07 22:07:16 -06:00
|
|
|
|> xLine(length = 12.34)
|
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 = [-12.34, 12.34])
|
2024-08-12 16:09:44 +10:00
|
|
|
|
|
|
|
`)
|
2025-02-11 11:13:25 -06:00
|
|
|
await page.waitForTimeout(100)
|
|
|
|
await page.mouse.click(startXPx, 500 - PUR * 20)
|
2024-08-12 16:09:44 +10:00
|
|
|
|
2025-02-11 11:13:25 -06:00
|
|
|
await expect.poll(u.normalisedEditorCode)
|
2025-03-21 22:39:12 +13:00
|
|
|
.toBe(`sketch001 = startSketchOn(XZ)
|
2025-02-15 00:57:04 +11:00
|
|
|
profile001 = startProfileAt([12.34, -12.34], sketch001)
|
2025-03-07 22:07:16 -06:00
|
|
|
|> xLine(length = 12.34)
|
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 = [-12.34, 12.34])
|
2025-03-07 22:07:16 -06:00
|
|
|
|> xLine(length = -12.34)
|
2024-08-12 16:09:44 +10:00
|
|
|
|
|
|
|
`)
|
2024-08-07 19:27:32 +10:00
|
|
|
|
2025-02-11 11:13:25 -06:00
|
|
|
// Unequip line tool
|
|
|
|
await page.keyboard.press('Escape')
|
|
|
|
// Make sure we didn't pop out of sketch mode.
|
|
|
|
await expect(
|
|
|
|
page.getByRole('button', { name: 'Exit Sketch' })
|
|
|
|
).toBeVisible()
|
|
|
|
await expect(
|
|
|
|
page.getByRole('button', { name: 'line Line', exact: true })
|
|
|
|
).not.toHaveAttribute('aria-pressed', 'true')
|
|
|
|
|
|
|
|
// Exit sketch
|
|
|
|
await page.keyboard.press('Escape')
|
|
|
|
await expect(
|
|
|
|
page.getByRole('button', { name: 'Exit Sketch' })
|
|
|
|
).not.toBeVisible()
|
|
|
|
}
|
|
|
|
)
|
2024-08-07 19:27:32 +10:00
|
|
|
})
|