Fix partial execution

This commit is contained in:
49lf
2025-01-10 15:39:25 -05:00
parent 30397ba7ab
commit 5fe3023be9
11 changed files with 53 additions and 37 deletions

View File

@ -1399,7 +1399,9 @@ test.describe('multi-profile sketching', () => {
await endLineStartTanArc({ delay: 544 }) await endLineStartTanArc({ delay: 544 })
await endArcStartLine() await endArcStartLine()
await editor.expectEditor.toContain(`|> tangentialArcTo([16.61, 4.14], %)`) await editor.expectEditor.toContain(
`|> tangentialArcTo([16.61, 4.14], %)`
)
await toolbar.lineBtn.click() await toolbar.lineBtn.click()
await page.waitForTimeout(300) await page.waitForTimeout(300)
await endArcStartLine() await endArcStartLine()
@ -1461,15 +1463,16 @@ test.describe('multi-profile sketching', () => {
`profile005 = startProfileAt([5.63, 3.05], sketch001)` `profile005 = startProfileAt([5.63, 3.05], sketch001)`
) )
await crnRect1point2() await crnRect1point2()
await editor.expectEditor await editor.expectEditor.toContain(
.toContain(`|> angledLine([0, 2.37], %, $rectangleSegmentA001) `|> angledLine([0, 2.37], %, $rectangleSegmentA001)
|> angledLine([segAng(rectangleSegmentA001) - 90, 7.8], %) |> angledLine([segAng(rectangleSegmentA001) - 90, 7.8], %)
|> angledLine([ |> angledLine([
segAng(rectangleSegmentA001), segAng(rectangleSegmentA001),
-segLen(rectangleSegmentA001) -segLen(rectangleSegmentA001)
], %) ], %)
|> lineTo([profileStartX(%), profileStartY(%)], %) |> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)`.replaceAll("\n", "")) |> close(%)`.replaceAll('\n', '')
)
await crnRect2point1() await crnRect2point1()
await page.waitForTimeout(300) await page.waitForTimeout(300)
@ -1478,8 +1481,8 @@ test.describe('multi-profile sketching', () => {
) )
await crnRect2point2() await crnRect2point2()
await page.waitForTimeout(300) await page.waitForTimeout(300)
await editor.expectEditor await editor.expectEditor.toContain(
.toContain(`|> angledLine([0, 5.49], %, $rectangleSegmentA002) `|> angledLine([0, 5.49], %, $rectangleSegmentA002)
|> angledLine([ |> angledLine([
segAng(rectangleSegmentA002) - 90, segAng(rectangleSegmentA002) - 90,
4.14 4.14
@ -1489,7 +1492,8 @@ test.describe('multi-profile sketching', () => {
-segLen(rectangleSegmentA002) -segLen(rectangleSegmentA002)
], %) ], %)
|> lineTo([profileStartX(%), profileStartY(%)], %) |> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)`.replaceAll("\n", "")) |> close(%)`.replaceAll('\n', '')
)
}) })
await test.step('create two center rectangles in a row without unequip', async () => { await test.step('create two center rectangles in a row without unequip', async () => {
@ -1502,8 +1506,8 @@ test.describe('multi-profile sketching', () => {
) )
await cntrRect1point2() await cntrRect1point2()
await page.waitForTimeout(300) await page.waitForTimeout(300)
await editor.expectEditor await editor.expectEditor.toContain(
.toContain(`|> angledLine([0, 7.06], %, $rectangleSegmentA003) `|> angledLine([0, 7.06], %, $rectangleSegmentA003)
|> angledLine([ |> angledLine([
segAng(rectangleSegmentA003) + 90, segAng(rectangleSegmentA003) + 90,
4.34 4.34
@ -1513,7 +1517,8 @@ test.describe('multi-profile sketching', () => {
-segLen(rectangleSegmentA003) -segLen(rectangleSegmentA003)
], %) ], %)
|> lineTo([profileStartX(%), profileStartY(%)], %) |> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)`.replaceAll("\n", "")) |> close(%)`.replaceAll('\n', '')
)
await page.waitForTimeout(300) await page.waitForTimeout(300)
await cntrRect2point1() await cntrRect2point1()
@ -1523,8 +1528,8 @@ test.describe('multi-profile sketching', () => {
) )
await cntrRect2point2() await cntrRect2point2()
await page.waitForTimeout(300) await page.waitForTimeout(300)
await editor.expectEditor await editor.expectEditor.toContain(
.toContain(`|> angledLine([0, 3.12], %, $rectangleSegmentA004) `|> angledLine([0, 3.12], %, $rectangleSegmentA004)
|> angledLine([ |> angledLine([
segAng(rectangleSegmentA004) + 90, segAng(rectangleSegmentA004) + 90,
6.24 6.24
@ -1534,7 +1539,8 @@ test.describe('multi-profile sketching', () => {
-segLen(rectangleSegmentA004) -segLen(rectangleSegmentA004)
], %) ], %)
|> lineTo([profileStartX(%), profileStartY(%)], %) |> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)`.replaceAll("\n", "")) |> close(%)`.replaceAll('\n', '')
)
}) })
}) })
@ -1593,11 +1599,11 @@ profile003 = circle({ center = [6.92, -4.2], radius = 3.16 }, sketch001)
const [rectEnd] = scene.makeMouseHelpers(757, 395) const [rectEnd] = scene.makeMouseHelpers(757, 395)
await test.step('enter sketch and setup', async () => { await test.step('enter sketch and setup', async () => {
await page.screenshot({ path: "toolbar1.png" }) await page.screenshot({ path: 'toolbar1.png' })
await pointOnSegment({ shouldDbClick: true }) await pointOnSegment({ shouldDbClick: true })
await page.waitForTimeout(600) await page.waitForTimeout(600)
await page.screenshot({ path: "toolbar2.png" }) await page.screenshot({ path: 'toolbar2.png' })
await toolbar.lineBtn.click() await toolbar.lineBtn.click()
await page.waitForTimeout(100) await page.waitForTimeout(100)
}) })
@ -1648,8 +1654,8 @@ profile003 = circle({ center = [6.92, -4.2], radius = 3.16 }, sketch001)
) )
await page.waitForTimeout(100) await page.waitForTimeout(100)
await rectEnd() await rectEnd()
await editor.expectEditor await editor.expectEditor.toContain(
.toContain(`|> angledLine([180, 1.97], %, $rectangleSegmentA002) `|> angledLine([180, 1.97], %, $rectangleSegmentA002)
|> angledLine([ |> angledLine([
segAng(rectangleSegmentA002) + 90, segAng(rectangleSegmentA002) + 90,
3.88 3.88
@ -1659,7 +1665,8 @@ profile003 = circle({ center = [6.92, -4.2], radius = 3.16 }, sketch001)
-segLen(rectangleSegmentA002) -segLen(rectangleSegmentA002)
], %) ], %)
|> lineTo([profileStartX(%), profileStartY(%)], %) |> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)`.replaceAll("\n", "")) |> close(%)`.replaceAll('\n', '')
)
}) })
}) })
test('Can delete a profile in the editor while is sketch mode, and sketch mode does not break, can ctrl+z to undo after constraint with variable was added', async ({ test('Can delete a profile in the editor while is sketch mode, and sketch mode does not break, can ctrl+z to undo after constraint with variable was added', async ({
@ -1952,7 +1959,9 @@ extrude001 = extrude(75, thePart)
}) })
await test.step('expect code to match initial conditions still', async () => { await test.step('expect code to match initial conditions still', async () => {
await editor.expectEditor.toContain(`thePart = startSketchOn('XZ') |> startProfileAt([7.53, 10.51], %)`) await editor.expectEditor.toContain(
`thePart = startSketchOn('XZ') |> startProfileAt([7.53, 10.51], %)`
)
}) })
await test.step('equiping the line tool should break up the pipe expression', async () => { await test.step('equiping the line tool should break up the pipe expression', async () => {
@ -2290,10 +2299,7 @@ loft([profile001, profile002])
topProfileEdgeClickCoords.x, topProfileEdgeClickCoords.x,
topProfileEdgeClickCoords.y topProfileEdgeClickCoords.y
) )
const [sideProfileEdgeClick] = scene.makeMouseHelpers( const [sideProfileEdgeClick] = scene.makeMouseHelpers(788, 188)
788,
188,
)
const [rect1Crn1] = scene.makeMouseHelpers(592, 283) const [rect1Crn1] = scene.makeMouseHelpers(592, 283)
const [rect1Crn2] = scene.makeMouseHelpers(797, 268) const [rect1Crn2] = scene.makeMouseHelpers(797, 268)

View File

@ -716,7 +716,7 @@ part002 = startSketchOn('XZ')
await editor.scrollToText('line([74.36, 130.4], %)', true) await editor.scrollToText('line([74.36, 130.4], %)', true)
await page.getByText('line([74.36, 130.4], %)').click() await page.getByText('line([74.36, 130.4], %)').click()
await page.screenshot({ path: "ok.png" }) await page.screenshot({ path: 'ok.png' })
await page.getByRole('button', { name: 'Edit Sketch' }).click() await page.getByRole('button', { name: 'Edit Sketch' }).click()
const line3 = await u.getSegmentBodyCoords( const line3 = await u.getSegmentBodyCoords(

View File

@ -261,7 +261,7 @@ const FileTreeItem = ({
await codeManager.writeToFile() await codeManager.writeToFile()
// Prevent seeing the model built one piece at a time when changing files // Prevent seeing the model built one piece at a time when changing files
await kclManager.executeCode(true) await kclManager.executeCode({ zoomToFit: true })
} else { } else {
// Let the lsp servers know we closed a file. // Let the lsp servers know we closed a file.
onFileClose(currentFile?.path || null, project?.path || null) onFileClose(currentFile?.path || null, project?.path || null)

View File

@ -195,7 +195,7 @@ export const ModelingMachineProvider = ({
store.videoElement?.pause() store.videoElement?.pause()
return kclManager return kclManager
.executeCode() .executeCode({ isPartialExecution: true })
.then(() => { .then(() => {
if (engineCommandManager.engineConnection?.idleMode) return if (engineCommandManager.engineConnection?.idleMode) return

View File

@ -188,7 +188,7 @@ export const SettingsAuthProviderBase = ({
) { ) {
// Unit changes requires a re-exec of code // Unit changes requires a re-exec of code
// eslint-disable-next-line @typescript-eslint/no-floating-promises // eslint-disable-next-line @typescript-eslint/no-floating-promises
kclManager.executeCode(true) kclManager.executeCode({ zoomToFit: true })
} else { } else {
// For any future logging we'd like to do // For any future logging we'd like to do
// console.log( // console.log(

View File

@ -59,7 +59,7 @@ export const Stream = () => {
*/ */
function executeCodeAndPlayStream() { function executeCodeAndPlayStream() {
// eslint-disable-next-line @typescript-eslint/no-floating-promises // eslint-disable-next-line @typescript-eslint/no-floating-promises
kclManager.executeCode(true).then(async () => { kclManager.executeCode({ zoomToFit: true }).then(async () => {
await videoRef.current?.play().catch((e) => { await videoRef.current?.play().catch((e) => {
console.warn('Video playing was prevented', e, videoRef.current) console.warn('Video playing was prevented', e, videoRef.current)
}) })

View File

@ -37,6 +37,7 @@ import { Operation } from 'wasm-lib/kcl/bindings/Operation'
interface ExecuteArgs { interface ExecuteArgs {
ast?: Node<Program> ast?: Node<Program>
zoomToFit?: boolean zoomToFit?: boolean
isPartialExecution?: boolean
executionId?: number executionId?: number
zoomOnRangeAndType?: { zoomOnRangeAndType?: {
range: SourceRange range: SourceRange
@ -379,7 +380,8 @@ export class KclManager {
await this.engineCommandManager.updateArtifactGraph( await this.engineCommandManager.updateArtifactGraph(
this.ast, this.ast,
execState.artifactCommands, execState.artifactCommands,
execState.artifacts execState.artifacts,
args.isPartialExecution,
) )
this._executeCallback() this._executeCallback()
if (!isInterrupted) if (!isInterrupted)
@ -483,7 +485,7 @@ export class KclManager {
this._cancelTokens.set(key, true) this._cancelTokens.set(key, true)
}) })
} }
async executeCode(zoomToFit?: boolean): Promise<void> { async executeCode(opts?: { zoomToFit?: true, isPartialExecution?: true }): Promise<void> {
const ast = await this.safeParse(codeManager.code) const ast = await this.safeParse(codeManager.code)
if (!ast) { if (!ast) {
@ -491,10 +493,10 @@ export class KclManager {
return return
} }
zoomToFit = this.tryToZoomToFitOnCodeUpdate(ast, zoomToFit) zoomToFit = this.tryToZoomToFitOnCodeUpdate(ast, opts?.zoomToFit)
this.ast = { ...ast } this.ast = { ...ast }
return this.executeAst({ zoomToFit }) return this.executeAst(opts)
} }
/** /**
* This will override the zoom to fit to zoom into the model if the previous AST was empty. * This will override the zoom to fit to zoom into the model if the previous AST was empty.

View File

@ -2090,14 +2090,22 @@ export class EngineCommandManager extends EventTarget {
updateArtifactGraph( updateArtifactGraph(
ast: Node<Program>, ast: Node<Program>,
artifactCommands: ArtifactCommand[], artifactCommands: ArtifactCommand[],
execStateArtifacts: ExecState['artifacts'] execStateArtifacts: ExecState['artifacts'],
isPartialExecution?: true,
) { ) {
this.artifactGraph = createArtifactGraph({ const newGraphArtifacts = createArtifactGraph({
artifactCommands, artifactCommands,
responseMap: this.responseMap, responseMap: this.responseMap,
ast, ast,
execStateArtifacts, execStateArtifacts,
}) })
if (isPartialExecution) {
for (let [id, artifact] of newGraphArtifacts) {
this.artifactGraph.set(id, artifact)
}
} else {
this.artifactGraph = newGraphArtifacts
}
// TODO check if these still need to be deferred once e2e tests are working again. // TODO check if these still need to be deferred once e2e tests are working again.
if (this.artifactGraph.size) { if (this.artifactGraph.size) {
this.deferredArtifactEmptied(null) this.deferredArtifactEmptied(null)

View File

@ -109,7 +109,7 @@ function OnboardingWarningWeb(props: OnboardingResetWarningProps) {
codeManager.updateCodeStateEditor(bracket) codeManager.updateCodeStateEditor(bracket)
await codeManager.writeToFile() await codeManager.writeToFile()
await kclManager.executeCode(true) await kclManager.executeCode({ zoomToFit: true })
props.setShouldShowWarning(false) props.setShouldShowWarning(false)
}, reportRejection)} }, reportRejection)}
nextText="Overwrite code and continue" nextText="Overwrite code and continue"

View File

@ -11,7 +11,7 @@ export default function Sketching() {
async function clearEditor() { async function clearEditor() {
// We do want to update both the state and editor here. // We do want to update both the state and editor here.
codeManager.updateCodeStateEditor('') codeManager.updateCodeStateEditor('')
await kclManager.executeCode(true) await kclManager.executeCode({ zoomToFit: true })
} }
// eslint-disable-next-line @typescript-eslint/no-floating-promises // eslint-disable-next-line @typescript-eslint/no-floating-promises

View File

@ -100,7 +100,7 @@ export function useDemoCode() {
setTimeout( setTimeout(
toSync(async () => { toSync(async () => {
codeManager.updateCodeStateEditor(bracket) codeManager.updateCodeStateEditor(bracket)
await kclManager.executeCode(true) await kclManager.executeCode({ zoomToFit: true })
await codeManager.writeToFile() await codeManager.writeToFile()
}, reportRejection) }, reportRejection)
) )