Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 66 additions & 1 deletion e2e/playwright/code-pane-and-errors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
import fsp from 'fs/promises'

import { TEST_CODE_LONG_WITH_ERROR_OUT_OF_VIEW } from '@e2e/playwright/storageStates'
import { executorInputPath, getUtils } from '@e2e/playwright/test-utils'
import {
executorInputPath,
getUtils,
checkIfPaneIsOpen,
} from '@e2e/playwright/test-utils'
import { expect, test } from '@e2e/playwright/zoo-test'
import { DefaultLayoutPaneID } from '@src/lib/layout/configs/default'

Expand Down Expand Up @@ -208,6 +212,67 @@
// There should be one hint inside middle() and one at the top level.
await expect(page.getByText('Part of the error backtrace')).toHaveCount(2)
})

test(
'Opening a project with KCL syntax error shows error when code pane is opened',
{ tag: '@desktop' },
async ({ context, page, homePage, scene, cmdBar, toolbar }) => {
// Create a project with a file containing a syntax error
await context.folderSetupFn(async (dir) => {
const errorProjectDir = join(dir, 'syntax-error-project')

Check warning on line 222 in e2e/playwright/code-pane-and-errors.spec.ts

View workflow job for this annotation

GitHub Actions / semgrep-oss/scan

path-join-resolve-traversal

Detected possible user input going into a path.join or path.resolve function. This could possibly lead to a path traversal vulnerability where the attacker can access arbitrary files stored in the file system. Instead be sure to sanitize or validate user input first.
await fsp.mkdir(errorProjectDir, { recursive: true })

Check warning on line 223 in e2e/playwright/code-pane-and-errors.spec.ts

View workflow job for this annotation

GitHub Actions / semgrep-oss/scan

detect-non-literal-fs-filename

Detected that function argument dir has entered the fs module. An attacker could potentially control the location of this file to include going backwards in the directory with ... To address this ensure that usercontrolled variables in file paths are validated.
// Create a file with a syntax error (missing equals sign)
await fsp.writeFile(
join(errorProjectDir, 'main.kcl'),

Check warning on line 226 in e2e/playwright/code-pane-and-errors.spec.ts

View workflow job for this annotation

GitHub Actions / semgrep-oss/scan

path-join-resolve-traversal

Detected possible user input going into a path.join or path.resolve function. This could possibly lead to a path traversal vulnerability where the attacker can access arbitrary files stored in the file system. Instead be sure to sanitize or validate user input first.

Check warning on line 226 in e2e/playwright/code-pane-and-errors.spec.ts

View workflow job for this annotation

GitHub Actions / semgrep-oss/scan

detect-non-literal-fs-filename

Detected that function argument dir has entered the fs module. An attacker could potentially control the location of this file to include going backwards in the directory with ... To address this ensure that usercontrolled variables in file paths are validated.
`sketch001 = startSketchOn(XZ)
profile001 = startProfile(sketch001, at = [-2.7, -2.76])
|> line(entttt = [7.54, 5.4])
`
)
})

const u = await getUtils(page)
await page.setBodyDimensions({ width: 1200, height: 500 })

await test.step('Create a new project and close the code pane', async () => {
await homePage.goToModelingScene()
await scene.settled(cmdBar)
await u.closeKclCodePanel()
})

await test.step('Exit the project and go back to home', async () => {
await toolbar.logoLink.click()
await expect(page.getByText('Create project')).toBeVisible()
})

await test.step('Open the project with syntax error', async () => {
await expect(page.getByText('syntax-error-project')).toBeVisible()
await page.getByText('syntax-error-project').click()
await u.waitForPageLoad()
await scene.settled(cmdBar, { expectError: true })
})

await test.step('Verify code pane is not open', async () => {
const isCodePaneOpen = await checkIfPaneIsOpen(page, 'code-pane-button')
await expect(isCodePaneOpen).toBe(false)
await expect(page.locator('#code-pane')).not.toBeVisible()
})

///await page.waitForTimeout(99999)

await test.step('Open the code pane', async () => {
await u.openKclCodePanel()
await expect(page.locator('#code-pane')).toBeVisible()
})

await test.step('Verify syntax error is shown', async () => {
// Wait for the error to appear in the gutter
await expect(page.locator('.cm-lint-marker-error')).toBeVisible({
timeout: 10_000,
})
})
}
)
})

test(
Expand Down
5 changes: 5 additions & 0 deletions src/components/layout/areas/KclEditorPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ export const KclEditorPaneContents = () => {

if (!_editorView) return

// This doesn't really work instead of safeParse because it messes up the initial setup
// when opening a project.
// kclManager.executeCode().then(() => {
// }).catch(reportRejection)

// Update diagnostics as they are cleared when the editor is unmounted.
// Without this, errors would not be shown when closing and reopening the editor.
kclManager
Expand Down
Loading