Compare commits

..

1 Commits

Author SHA1 Message Date
252fde9be6 demo zoom not working 2024-10-02 08:34:56 +10:00
11 changed files with 52 additions and 204 deletions

View File

@ -183,22 +183,6 @@ jobs:
with:
name: test-results-${{ matrix.os }}-${{ matrix.shardIndex }}-${{ github.sha }}
path: test-results/
- name: Debug test-results folder
if: ${{ !cancelled() && (success() || failure()) }}
shell: bash
run: |
if [[ -d "test-results" ]]; then
echo "Contents of test-results folder:"
ls -la test-results
if [[ -f "test-results/.last-run.json" ]]; then
echo "Contents of test-results/.last-run.json:"
cat test-results/.last-run.json
else
echo "test-results/.last-run.json does not exist"
fi
else
echo "test-results folder does not exist"
fi
- name: Run playwright/chrome flow (with retries)
id: retry
if: ${{ !cancelled() && (success() || failure()) }}
@ -213,7 +197,7 @@ jobs:
fi
retry=1
max_retrys=1
max_retrys=4
# retry failed tests, doing our own retries because using inbuilt playwright retries causes connection issues
while [[ $retry -le $max_retrys ]]; do
@ -258,22 +242,6 @@ jobs:
shell: bash
run: |
node playwrightProcess.mjs | tee /tmp/github-actions.log
- name: Debug test-results folder
if: ${{ !cancelled() && (success() || failure()) }}
shell: bash
run: |
if [[ -d "test-results" ]]; then
echo "Contents of test-results folder:"
ls -la test-results
if [[ -f "test-results/.last-run.json" ]]; then
echo "Contents of test-results/.last-run.json:"
cat test-results/.last-run.json
else
echo "test-results/.last-run.json does not exist"
fi
else
echo "test-results folder does not exist"
fi
- uses: actions/upload-artifact@v4
if: always()
with:
@ -384,24 +352,8 @@ jobs:
if: ${{ !cancelled() && (success() || failure()) }}
continue-on-error: true
with:
name: test-results-electron-${{ matrix.os }}-${{ github.sha }}
name: test-results-${{ matrix.os }}-${{ github.sha }}
path: test-results/
- name: Debug test-results folder
if: ${{ !cancelled() && (success() || failure()) }}
shell: bash
run: |
if [[ -d "test-results" ]]; then
echo "Contents of test-results folder:"
ls -la test-results
if [[ -f "test-results/.last-run.json" ]]; then
echo "Contents of test-results/.last-run.json:"
cat test-results/.last-run.json
else
echo "test-results/.last-run.json does not exist"
fi
else
echo "test-results folder does not exist"
fi
- name: Run electron tests (with retries)
id: retry
if: ${{ !cancelled() && (success() || failure()) }}
@ -420,7 +372,7 @@ jobs:
fi
retry=1
max_retrys=1
max_retrys=2
# retry failed tests, doing our own retries because using inbuilt playwright retries causes connection issues
while [[ $retry -le $max_retrys ]]; do
@ -470,22 +422,6 @@ jobs:
shell: bash
run: |
node playwrightProcess.mjs | tee /tmp/github-actions.log
- name: Debug test-results folder
if: ${{ !cancelled() && (success() || failure()) }}
shell: bash
run: |
if [[ -d "test-results" ]]; then
echo "Contents of test-results folder:"
ls -la test-results
if [[ -f "test-results/.last-run.json" ]]; then
echo "Contents of test-results/.last-run.json:"
cat test-results/.last-run.json
else
echo "test-results/.last-run.json does not exist"
fi
else
echo "test-results folder does not exist"
fi
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() && (success() || failure()) }}
with:

View File

@ -72,7 +72,7 @@ export class EditorFixture {
const content = await this.diagnosticsTooltip.allTextContents()
diagnosticsContent.push(content.join(''))
}
return [...new Set(diagnosticsContent)].map((d) => sansWhitespace(d))
return [...new Set(diagnosticsContent)].map((d) => d.trim())
}
private _getHighlightedCode = async () => {
@ -108,11 +108,4 @@ export class EditorFixture {
diagnostics: expectedState.diagnostics.map(sansWhitespace),
})
}
replaceCode = async (findCode: string, replaceCode: string) => {
const lines = await this.page.locator('.cm-line').all()
let code = (await Promise.all(lines.map((c) => c.textContent()))).join('\n')
if (!lines) return
code = code.replace(findCode, replaceCode)
await this.codeContent.fill(code)
}
}

View File

@ -4,7 +4,6 @@ import { uuidv4 } from 'lib/utils'
import {
closeDebugPanel,
doAndWaitForImageDiff,
getPixelRGBs,
openAndClearDebugPanel,
sendCustomCmd,
} from '../test-utils'
@ -90,28 +89,4 @@ export class SceneFixture {
waitForExecutionDone = async () => {
await expect(this.exeIndicator).toBeVisible()
}
expectPixelColor = async (
colour: [number, number, number],
coords: { x: number; y: number },
diff: number
) => {
let finalValue = colour
await expect
.poll(async () => {
const pixel = (await getPixelRGBs(this.page)(coords, 1))[0]
if (!pixel) return null
finalValue = pixel
return pixel.every(
(channel, index) => Math.abs(channel - colour[index]) < diff
)
})
.toBeTruthy()
.catch((cause) => {
throw new Error(
`ExpectPixelColor: expecting ${colour} got ${finalValue}`,
{ cause }
)
})
}
}

View File

@ -1,5 +1,4 @@
import { test, expect, Page } from '@playwright/test'
import { test as test2, expect as expect2 } from './fixtures/fixtureSetup'
import {
getMovementUtils,
@ -1108,64 +1107,3 @@ const sketch002 = startSketchOn(extrude001, 'END')
}).toPass({ timeout: 40_000, intervals: [1_000] })
})
})
test2.describe('Sketch mode should be toleratant to syntax errors', () => {
test2(
'adding a syntax error, recovers after fixing',
{ tag: ['@skipWin'] },
async ({ app, scene, editor, toolbar }) => {
test.skip(
process.platform === 'win32',
'a codemirror error appears in this test only on windows, that causes the test to fail only because of our "no new error" logic, but it can not be replicated locally'
)
const file = await app.getInputFile('e2e-can-sketch-on-chamfer.kcl')
await app.initialise(file)
const [objClick] = scene.makeMouseHelpers(600, 250)
const arrowHeadLocation = { x: 604, y: 129 } as const
const arrowHeadWhite: [number, number, number] = [255, 255, 255]
const backgroundGray: [number, number, number] = [28, 28, 28]
const verifyArrowHeadColor = async (c: [number, number, number]) =>
scene.expectPixelColor(c, arrowHeadLocation, 15)
await test.step('check chamfer selection changes cursor positon', async () => {
await expect2(async () => {
// sometimes initial click doesn't register
await objClick()
await editor.expectActiveLinesToBe([
'|> startProfileAt([75.8, 317.2], %) // [$startCapTag, $EndCapTag]',
])
}).toPass({ timeout: 15_000, intervals: [500] })
})
await test.step('enter sketch and sanity check segments have been drawn', async () => {
await toolbar.editSketch()
// this checks sketch segments have been drawn
await verifyArrowHeadColor(arrowHeadWhite)
})
await test.step('Make typo and check the segments have Disappeared and there is a syntax error', async () => {
await editor.replaceCode('lineTo([pro', 'badBadBadFn([pro')
await editor.expectState({
activeLines: [],
diagnostics: ['memoryitemkey`badBadBadFn`isnotdefined'],
highlightedCode: '',
})
// this checks sketch segments have failed to be drawn
await verifyArrowHeadColor(backgroundGray)
})
await test.step('', async () => {
await editor.replaceCode('badBadBadFn([pro', 'lineTo([pro')
await editor.expectState({
activeLines: [],
diagnostics: [],
highlightedCode: '',
})
// this checks sketch segments have been drawn
await verifyArrowHeadColor(arrowHeadWhite)
})
await app.page.waitForTimeout(100)
}
)
})

View File

@ -438,7 +438,34 @@ export async function getUtils(page: Page, test_?: typeof test) {
}
return maxDiff
},
getPixelRGBs: getPixelRGBs(page),
getPixelRGBs: async (
coords: { x: number; y: number },
radius: number
): Promise<[number, number, number][]> => {
const buffer = await page.screenshot({
fullPage: true,
})
const screenshot = await PNG.sync.read(buffer)
const pixMultiplier: number = await page.evaluate(
'window.devicePixelRatio'
)
const allCords: [number, number][] = [[coords.x, coords.y]]
for (let i = 1; i < radius; i++) {
allCords.push([coords.x + i, coords.y])
allCords.push([coords.x - i, coords.y])
allCords.push([coords.x, coords.y + i])
allCords.push([coords.x, coords.y - i])
}
return allCords.map(([x, y]) => {
const index =
(screenshot.width * y * pixMultiplier + x * pixMultiplier) * 4 // rbga is 4 channels
return [
screenshot.data[index],
screenshot.data[index + 1],
screenshot.data[index + 2],
]
})
},
doAndWaitForImageDiff: (fn: () => Promise<unknown>, diffCount = 200) =>
doAndWaitForImageDiff(page, fn, diffCount),
emulateNetworkConditions: async (
@ -1043,32 +1070,3 @@ export async function openAndClearDebugPanel(page: Page) {
export function sansWhitespace(str: string) {
return str.replace(/\s+/g, '').trim()
}
export function getPixelRGBs(page: Page) {
return async (
coords: { x: number; y: number },
radius: number
): Promise<[number, number, number][]> => {
const buffer = await page.screenshot({
fullPage: true,
})
const screenshot = await PNG.sync.read(buffer)
const pixMultiplier: number = await page.evaluate('window.devicePixelRatio')
const allCords: [number, number][] = [[coords.x, coords.y]]
for (let i = 1; i < radius; i++) {
allCords.push([coords.x + i, coords.y])
allCords.push([coords.x - i, coords.y])
allCords.push([coords.x, coords.y + i])
allCords.push([coords.x, coords.y - i])
}
return allCords.map(([x, y]) => {
const index =
(screenshot.width * y * pixMultiplier + x * pixMultiplier) * 4 // rbga is 4 channels
return [
screenshot.data[index],
screenshot.data[index + 1],
screenshot.data[index + 2],
]
})
}
}

View File

@ -19,7 +19,7 @@ export default defineConfig({
['dot'],
['list'],
['json', { outputFile: './test-results/report.json' }],
['html', {open: 'never'}],
['html'],
],
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {

View File

@ -306,9 +306,19 @@ export class CameraControls {
event: 'camera_drag_end',
callback: cb,
})
this.engineCommandManager.subscribeToUnreliable({
event: 'default_camera_zoom',
callback: (a) => {
console.log('zoom', a)
cb(a)
},
})
this.engineCommandManager.subscribeTo({
event: 'default_camera_zoom',
callback: cb,
callback: (a) => {
console.log('zoom', a)
cb(a)
},
})
this.engineCommandManager.subscribeTo({
event: 'default_camera_get_settings',

View File

@ -1175,7 +1175,7 @@ export class SceneEntities {
prepareTruncatedMemoryAndAst(
sketchPathToNode,
ast || kclManager.ast,
kclManager.lastSuccessfulProgramMemory,
kclManager.programMemory,
draftSegment
)
onDragSegment({

View File

@ -43,7 +43,6 @@ export class KclManager {
digest: null,
}
private _programMemory: ProgramMemory = ProgramMemory.empty()
lastSuccessfulProgramMemory: ProgramMemory = ProgramMemory.empty()
private _logs: string[] = []
private _lints: Diagnostic[] = []
private _kclErrors: KCLError[] = []
@ -298,9 +297,6 @@ export class KclManager {
// Do not add the errors since the program was interrupted and the error is not a real KCL error
this.addKclErrors(isInterrupted ? [] : errors)
this.programMemory = programMemory
if (!errors.length) {
this.lastSuccessfulProgramMemory = programMemory
}
this.ast = { ...ast }
this._executeCallback()
this.engineCommandManager.addCommandLog({
@ -346,9 +342,6 @@ export class KclManager {
this._logs = logs
this._kclErrors = errors
this._programMemory = programMemory
if (!errors.length) {
this.lastSuccessfulProgramMemory = programMemory
}
if (updates !== 'artifactRanges') return
// TODO the below seems like a work around, I wish there's a comment explaining exactly what

View File

@ -1230,7 +1230,7 @@ type ModelTypes = Models['OkModelingCmdResponse_type']['type']
type UnreliableResponses = Extract<
Models['OkModelingCmdResponse_type'],
{ type: 'highlight_set_entity' | 'camera_drag_move' }
{ type: 'highlight_set_entity' | 'camera_drag_move' | 'default_camera_zoom' }
>
export interface UnreliableSubscription<T extends UnreliableResponses['type']> {
event: T
@ -1572,9 +1572,11 @@ export class EngineCommandManager extends EventTarget {
'message',
(event: MessageEvent) => {
const result: UnreliableResponses = JSON.parse(event.data)
console.log('result', result)
Object.values(
this.unreliableSubscriptions[result.type] || {}
).forEach(
// TODO: There is only one response that uses the unreliable channel atm,
// highlight_set_entity, if there are more it's likely they will all have the same
// sequence logic, but I'm not sure if we use a single global sequence or a sequence
@ -1933,6 +1935,9 @@ export class EngineCommandManager extends EventTarget {
) {
;(cmd as any).sequence = this.outSequence
this.outSequence++
if(cmd.type === 'default_camera_zoom') {
console.log('sending zoom', cmd)
}
this.engineConnection?.unreliableSend(command)
return Promise.resolve(null)
} else if (

View File

@ -99,6 +99,6 @@ export const MAKE_TOAST_MESSAGES = {
/** The URL for the KCL samples manifest files */
export const KCL_SAMPLES_MANIFEST_URLS = {
remote:
'https://raw.githubusercontent.com/KittyCAD/kcl-samples/main/manifest.json',
'https://raw.githubusercontent.com/KittyCAD/kcl-samples/main/manifst.json',
localFallback: '/kcl-samples-manifest-fallback.json',
} as const