Compare commits
11 Commits
achalmers/
...
jtran/json
Author | SHA1 | Date | |
---|---|---|---|
4a5ef17c92 | |||
83220a7255 | |||
a0f3f0f50e | |||
dad0d5488f | |||
77773fb052 | |||
1240ca6f21 | |||
ce3a6ad286 | |||
a20f420a55 | |||
03c4121ab7 | |||
8c2c877817 | |||
c77bb92da9 |
@ -1,3 +1,3 @@
|
||||
[codespell]
|
||||
ignore-words-list: crate,everytime,inout,co-ordinate,ot,nwo,atleast,ue,afterall,ser,fromM,FromM
|
||||
skip: **/target,node_modules,build,dist,./out,**/Cargo.lock,./docs/kcl/*.md,.package-lock.json,**/package-lock.json,./openapi/*.json,./packages/codemirror-lang-kcl/test/all.test.ts,./public/kcl-samples,./rust/kcl-lib/tests/kcl_samples,tsconfig.tsbuildinfo,./src/lib/machine-api.d.ts
|
||||
skip: **/target,node_modules,build,dist,./out,**/Cargo.lock,./docs/kcl/*.md,./e2e/playwright/lib/console-error-whitelist.ts,.package-lock.json,**/package-lock.json,./openapi/*.json,./packages/codemirror-lang-kcl/test/all.test.ts,./public/kcl-samples,./rust/kcl-lib/tests/kcl_samples,tsconfig.tsbuildinfo,./src/lib/machine-api.d.ts
|
||||
|
4
.github/workflows/e2e-tests.yml
vendored
4
.github/workflows/e2e-tests.yml
vendored
@ -226,8 +226,8 @@ jobs:
|
||||
with:
|
||||
shell: bash
|
||||
command: npm run test:snapshots
|
||||
timeout_minutes: 30
|
||||
max_attempts: 3
|
||||
timeout_minutes: 5
|
||||
max_attempts: 5
|
||||
env:
|
||||
token: ${{ secrets.KITTYCAD_API_TOKEN_DEV }}
|
||||
snapshottoken: ${{ secrets.KITTYCAD_API_TOKEN }}
|
||||
|
4
Makefile
4
Makefile
@ -15,8 +15,8 @@ ifdef WINDOWS
|
||||
CARGO ?= $(USERPROFILE)/.cargo/bin/cargo.exe
|
||||
WASM_PACK ?= $(USERPROFILE)/.cargo/bin/wasm-pack.exe
|
||||
else
|
||||
CARGO ?= ~/.cargo/bin/cargo
|
||||
WASM_PACK ?= ~/.cargo/bin/wasm-pack
|
||||
CARGO ?= $(shell which cargo || echo ~/.cargo/bin/cargo)
|
||||
WASM_PACK ?= $(shell which wasm-pack || echo ~/.cargo/bin/wasm-pack)
|
||||
endif
|
||||
|
||||
.PHONY: install
|
||||
|
@ -5,7 +5,10 @@ import type { Locator, Page } from '@playwright/test'
|
||||
import type { EditorFixture } from '@e2e/playwright/fixtures/editorFixture'
|
||||
import type { SceneFixture } from '@e2e/playwright/fixtures/sceneFixture'
|
||||
import type { ToolbarFixture } from '@e2e/playwright/fixtures/toolbarFixture'
|
||||
import { orRunWhenFullSuiteEnabled } from '@e2e/playwright/test-utils'
|
||||
import {
|
||||
orRunWhenFullSuiteEnabled,
|
||||
runningOnWindows,
|
||||
} from '@e2e/playwright/test-utils'
|
||||
import { expect, test } from '@e2e/playwright/zoo-test'
|
||||
|
||||
// test file is for testing point an click code gen functionality that's not sketch mode related
|
||||
@ -3544,6 +3547,9 @@ tag=$rectangleSegmentC002,
|
||||
toolbar,
|
||||
cmdBar,
|
||||
}) => {
|
||||
if (runningOnWindows()) {
|
||||
test.fixme(orRunWhenFullSuiteEnabled())
|
||||
}
|
||||
const initialCode = `sketch001 = startSketchOn(XZ)
|
||||
|> startProfileAt([-102.57, 101.72], %)
|
||||
|> angledLine(angle = 0, length = 202.6, tag = $rectangleSegmentA001)
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { expect, test } from '@e2e/playwright/zoo-test'
|
||||
import { orRunWhenFullSuiteEnabled } from '@e2e/playwright/test-utils'
|
||||
|
||||
/* eslint-disable jest/no-conditional-expect */
|
||||
|
||||
@ -57,6 +58,7 @@ test.describe('edit with AI example snapshots', () => {
|
||||
`change colour`,
|
||||
{ tag: '@snapshot' },
|
||||
async ({ context, homePage, cmdBar, editor, page, scene }) => {
|
||||
test.fixme(orRunWhenFullSuiteEnabled())
|
||||
await context.addInitScript((file) => {
|
||||
localStorage.setItem('persistCode', file)
|
||||
}, file)
|
||||
|
@ -377,8 +377,7 @@ test.describe(
|
||||
'extrude on default planes should be stable',
|
||||
{ tag: '@snapshot' },
|
||||
() => {
|
||||
// FIXME: Skip on macos its being weird.
|
||||
test.skip(process.platform === 'darwin', 'Skip on macos')
|
||||
test.fixme(orRunWhenFullSuiteEnabled())
|
||||
|
||||
test('XY', async ({ page, context, cmdBar, scene }) => {
|
||||
await extrudeDefaultPlane(context, page, cmdBar, scene, 'XY')
|
||||
@ -410,6 +409,7 @@ test(
|
||||
'Draft segments should look right',
|
||||
{ tag: '@snapshot' },
|
||||
async ({ page, scene, toolbar }) => {
|
||||
test.fixme(orRunWhenFullSuiteEnabled())
|
||||
const u = await getUtils(page)
|
||||
await page.setViewportSize({ width: 1200, height: 500 })
|
||||
const PUR = 400 / 37.5 //pixeltoUnitRatio
|
||||
@ -534,8 +534,7 @@ test(
|
||||
'Draft rectangles should look right',
|
||||
{ tag: '@snapshot' },
|
||||
async ({ page, context, cmdBar, scene }) => {
|
||||
// FIXME: Skip on macos its being weird.
|
||||
test.skip(process.platform === 'darwin', 'Skip on macos')
|
||||
test.fixme(orRunWhenFullSuiteEnabled())
|
||||
|
||||
const u = await getUtils(page)
|
||||
await page.setViewportSize({ width: 1200, height: 500 })
|
||||
@ -629,8 +628,7 @@ test.describe(
|
||||
'Client side scene scale should match engine scale',
|
||||
{ tag: '@snapshot' },
|
||||
() => {
|
||||
// FIXME: Skip on macos its being weird.
|
||||
test.skip(process.platform === 'darwin', 'Skip on macos')
|
||||
test.fixme(orRunWhenFullSuiteEnabled())
|
||||
|
||||
test('Inch scale', async ({ page, cmdBar, scene }) => {
|
||||
const u = await getUtils(page)
|
||||
@ -807,8 +805,7 @@ test(
|
||||
'Sketch on face with none z-up',
|
||||
{ tag: '@snapshot' },
|
||||
async ({ page, context, cmdBar, scene }) => {
|
||||
// FIXME: Skip on macos its being weird.
|
||||
test.skip(process.platform === 'darwin', 'Skip on macos')
|
||||
test.fixme(orRunWhenFullSuiteEnabled())
|
||||
|
||||
const u = await getUtils(page)
|
||||
await context.addInitScript(async (KCL_DEFAULT_LENGTH) => {
|
||||
@ -868,8 +865,7 @@ test(
|
||||
'Zoom to fit on load - solid 2d',
|
||||
{ tag: '@snapshot' },
|
||||
async ({ page, context, cmdBar, scene }) => {
|
||||
// FIXME: Skip on macos its being weird.
|
||||
test.skip(process.platform === 'darwin', 'Skip on macos')
|
||||
test.fixme(orRunWhenFullSuiteEnabled())
|
||||
|
||||
const u = await getUtils(page)
|
||||
await context.addInitScript(async () => {
|
||||
@ -907,8 +903,7 @@ test(
|
||||
'Zoom to fit on load - solid 3d',
|
||||
{ tag: '@snapshot' },
|
||||
async ({ page, context, cmdBar, scene }) => {
|
||||
// FIXME: Skip on macos its being weird.
|
||||
test.skip(process.platform === 'darwin', 'Skip on macos')
|
||||
test.fixme(orRunWhenFullSuiteEnabled())
|
||||
|
||||
const u = await getUtils(page)
|
||||
await context.addInitScript(async () => {
|
||||
@ -949,6 +944,7 @@ test.describe('Grid visibility', { tag: '@snapshot' }, () => {
|
||||
cmdBar,
|
||||
scene,
|
||||
}) => {
|
||||
test.fixme(orRunWhenFullSuiteEnabled())
|
||||
const u = await getUtils(page)
|
||||
const stream = page.getByTestId('stream')
|
||||
|
||||
@ -1008,6 +1004,7 @@ test.describe('Grid visibility', { tag: '@snapshot' }, () => {
|
||||
})
|
||||
|
||||
test('Grid turned off', async ({ page, cmdBar, scene }) => {
|
||||
test.fixme(orRunWhenFullSuiteEnabled())
|
||||
const u = await getUtils(page)
|
||||
const stream = page.getByTestId('stream')
|
||||
|
||||
@ -1029,6 +1026,7 @@ test.describe('Grid visibility', { tag: '@snapshot' }, () => {
|
||||
})
|
||||
|
||||
test('Grid turned on', async ({ page, context, cmdBar, scene }) => {
|
||||
test.fixme(orRunWhenFullSuiteEnabled())
|
||||
await context.addInitScript(
|
||||
async ({ settingsKey, settings }) => {
|
||||
localStorage.setItem(settingsKey, settings)
|
||||
@ -1138,6 +1136,7 @@ test('theme persists', async ({ page, context }) => {
|
||||
|
||||
test.describe('code color goober', { tag: '@snapshot' }, () => {
|
||||
test('code color goober', async ({ page, context, scene, cmdBar }) => {
|
||||
test.fixme(orRunWhenFullSuiteEnabled())
|
||||
const u = await getUtils(page)
|
||||
await context.addInitScript(async () => {
|
||||
localStorage.setItem(
|
||||
|
4
rust/Cargo.lock
generated
4
rust/Cargo.lock
generated
@ -665,9 +665,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-channel"
|
||||
version = "0.5.14"
|
||||
version = "0.5.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06ba6d68e24814cb8de6bb986db8222d3a027d15872cabc0d18817bc3c0e4471"
|
||||
checksum = "82b8f8f868b36967f9606790d1903570de9ceaf870a7bf9fbbd3016d636a2cb2"
|
||||
dependencies = [
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
@ -3,6 +3,7 @@ import { useEffect, useState } from 'react'
|
||||
import type { CommandLog } from '@src/lang/std/commandLog'
|
||||
import { engineCommandManager } from '@src/lib/singletons'
|
||||
import { reportRejection } from '@src/lib/trap'
|
||||
import { parseJson } from '@src/lib/utils'
|
||||
|
||||
export function useEngineCommands(): [CommandLog[], () => void] {
|
||||
const [engineCommands, setEngineCommands] = useState<CommandLog[]>(
|
||||
@ -84,7 +85,7 @@ export const EngineCommands = () => {
|
||||
data-testid="custom-cmd-send-button"
|
||||
onClick={() => {
|
||||
engineCommandManager
|
||||
.sendSceneCommand(JSON.parse(customCmd))
|
||||
.sendSceneCommand(parseJson(customCmd))
|
||||
.catch(reportRejection)
|
||||
}}
|
||||
>
|
||||
|
@ -37,7 +37,7 @@ export class KCLError extends Error {
|
||||
filenames: { [x: number]: ModulePath | undefined },
|
||||
defaultPlanes: DefaultPlanes | null
|
||||
) {
|
||||
super()
|
||||
super(`${kind}: ${msg}`)
|
||||
this.kind = kind
|
||||
this.msg = msg
|
||||
this.sourceRange = sourceRange
|
||||
|
@ -4,6 +4,7 @@ import path from 'node:path'
|
||||
import { assertParse } from '@src/lang/wasm'
|
||||
import { initPromise } from '@src/lang/wasmUtils'
|
||||
import { enginelessExecutor } from '@src/lib/testHelpers'
|
||||
import { parseJson } from '@src/lib/utils'
|
||||
|
||||
// The purpose of these tests is to act as a first line of defense
|
||||
// if something gets real screwy with our KCL ecosystem.
|
||||
@ -27,7 +28,7 @@ const manifestJsonStr = await fs.readFile(
|
||||
path.resolve(DIR_KCL_SAMPLES, 'manifest.json'),
|
||||
'utf-8'
|
||||
)
|
||||
const manifest = JSON.parse(manifestJsonStr)
|
||||
const manifest: KclSampleFile[] = parseJson(manifestJsonStr)
|
||||
|
||||
process.chdir(DIR_KCL_SAMPLES)
|
||||
|
||||
|
@ -23,7 +23,7 @@ import {
|
||||
getThemeColorForEngine,
|
||||
} from '@src/lib/theme'
|
||||
import { reportRejection } from '@src/lib/trap'
|
||||
import { binaryToUuid, uuidv4 } from '@src/lib/utils'
|
||||
import { binaryToUuid, parseJson, uuidv4 } from '@src/lib/utils'
|
||||
|
||||
const pingIntervalMs = 1_000
|
||||
|
||||
@ -390,7 +390,7 @@ class EngineConnection extends EventTarget {
|
||||
this.websocket.addEventListener('open', this.onWebSocketOpen)
|
||||
|
||||
this.websocket?.addEventListener('message', ((event: MessageEvent) => {
|
||||
const message: Models['WebSocketResponse_type'] = JSON.parse(event.data)
|
||||
const message: Models['WebSocketResponse_type'] = parseJson(event.data)
|
||||
const pending =
|
||||
this.engineCommandManager.pendingCommands[message.request_id || '']
|
||||
if (!('resp' in message)) return
|
||||
@ -862,7 +862,7 @@ class EngineConnection extends EventTarget {
|
||||
)
|
||||
|
||||
this.onDataChannelMessage = (event) => {
|
||||
const result: UnreliableResponses = JSON.parse(event.data)
|
||||
const result: UnreliableResponses = parseJson(event.data)
|
||||
Object.values(
|
||||
this.engineCommandManager.unreliableSubscriptions[result.type] ||
|
||||
{}
|
||||
@ -976,7 +976,7 @@ class EngineConnection extends EventTarget {
|
||||
return
|
||||
}
|
||||
|
||||
const message: Models['WebSocketResponse_type'] = JSON.parse(
|
||||
const message: Models['WebSocketResponse_type'] = parseJson(
|
||||
event.data
|
||||
)
|
||||
|
||||
@ -1564,7 +1564,7 @@ export class EngineCommandManager extends EventTarget {
|
||||
unreliableDataChannel.addEventListener(
|
||||
'message',
|
||||
(event: MessageEvent) => {
|
||||
const result: UnreliableResponses = JSON.parse(event.data)
|
||||
const result: UnreliableResponses = parseJson(event.data)
|
||||
Object.values(
|
||||
this.unreliableSubscriptions[result.type] || {}
|
||||
).forEach(
|
||||
@ -1608,7 +1608,7 @@ export class EngineCommandManager extends EventTarget {
|
||||
message.request_id = binaryToUuid(message.request_id)
|
||||
}
|
||||
} else {
|
||||
message = JSON.parse(event.data)
|
||||
message = parseJson(event.data)
|
||||
}
|
||||
|
||||
if (message === null) {
|
||||
|
@ -40,7 +40,7 @@ import type { CoreDumpManager } from '@src/lib/coredump'
|
||||
import openWindow from '@src/lib/openWindow'
|
||||
import { Reason, err } from '@src/lib/trap'
|
||||
import type { DeepPartial } from '@src/lib/types'
|
||||
import { isArray } from '@src/lib/utils'
|
||||
import { isArray, parseJson } from '@src/lib/utils'
|
||||
import {
|
||||
base64_decode,
|
||||
change_kcl_settings,
|
||||
@ -217,9 +217,7 @@ export const parse = (code: string | Error): ParseResult | Error => {
|
||||
let errs = splitErrors(parsed[1])
|
||||
return new ParseResult(parsed[0], errs.errors, errs.warnings)
|
||||
} catch (e: any) {
|
||||
// throw e
|
||||
console.error(e.toString())
|
||||
const parsed: RustKclError = JSON.parse(e.toString())
|
||||
const parsed: RustKclError = parseJson(e.toString())
|
||||
return new KCLError(
|
||||
parsed.kind,
|
||||
parsed.msg,
|
||||
@ -381,7 +379,7 @@ export function sketchFromKclValue(
|
||||
}
|
||||
|
||||
export const errFromErrWithOutputs = (e: any): KCLError => {
|
||||
const parsed: KclErrorWithOutputs = JSON.parse(e.toString())
|
||||
const parsed: KclErrorWithOutputs = parseJson(e.toString())
|
||||
return new KCLError(
|
||||
parsed.error.kind,
|
||||
parsed.error.msg,
|
||||
|
@ -3,7 +3,7 @@ import type { ApiError_type } from '@kittycad/lib/dist/types/src/models'
|
||||
|
||||
import type { Selections } from '@src/lib/selections'
|
||||
import { engineCommandManager, kclManager } from '@src/lib/singletons'
|
||||
import { uuidv4 } from '@src/lib/utils'
|
||||
import { parseJson, uuidv4 } from '@src/lib/utils'
|
||||
import type { CommandBarContext } from '@src/machines/commandBarMachine'
|
||||
|
||||
export const disableDryRunWithRetry = async (numberOfRetries = 3) => {
|
||||
@ -54,7 +54,7 @@ export function parseEngineErrorMessage(engineError: string) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
const errors = JSON.parse(parts[1]) as ApiError_type[]
|
||||
const errors = parseJson<ApiError_type[]>(parts[1])
|
||||
if (!errors[0]) {
|
||||
return undefined
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import type { DeepPartial } from '@src/lib/types'
|
||||
import type { ModuleType } from '@src/lib/wasm_lib_wrapper'
|
||||
import { getModule } from '@src/lib/wasm_lib_wrapper'
|
||||
import type { Models } from '@kittycad/lib/dist/types/src'
|
||||
import { parseJson } from '@src/lib/utils'
|
||||
|
||||
export default class RustContext {
|
||||
private wasmInitFailed: boolean = true
|
||||
@ -140,7 +141,7 @@ export default class RustContext {
|
||||
JSON.stringify(settings)
|
||||
)
|
||||
} catch (e: any) {
|
||||
const parsed: RustKclError = JSON.parse(e.toString())
|
||||
const parsed: RustKclError = parseJson(e.toString())
|
||||
toast.error(parsed.msg, { id: toastId })
|
||||
return
|
||||
}
|
||||
|
@ -60,6 +60,26 @@ export function isNonNullable<T>(val: T): val is NonNullable<T> {
|
||||
return val !== null && val !== undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as JSON.parse() but if it fails, includes the string that was attempted
|
||||
* to be parsed in the error message. This is useful since a lot of times this
|
||||
* is called on a string that isn't actually JSON, like another error message.
|
||||
*
|
||||
* You can also use the type parameter to assert the expected type of the parsed
|
||||
* object.
|
||||
*/
|
||||
export function parseJson<T>(
|
||||
text: string,
|
||||
reviver?: (this: any, key: string, value: any) => any
|
||||
): T {
|
||||
try {
|
||||
return JSON.parse(text, reviver)
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line suggest-no-throw/suggest-no-throw
|
||||
throw new Error(`Failed to parse JSON: ${text}`, { cause: e })
|
||||
}
|
||||
}
|
||||
|
||||
export function isOverlap(a: SourceRange, b: SourceRange) {
|
||||
const [startingRange, secondRange] = a[0] < b[0] ? [a, b] : [b, a]
|
||||
const [lastOfFirst, firstOfSecond] = [startingRange[1], secondRange[0]]
|
||||
|
Reference in New Issue
Block a user