[Fix] Using main.kcl for more of the workflows that generate kcl files (#7017)

* fix: when creating a t2c in a new project make the file name main.kcl

* fix: when creating a sample in a new project and there is only 1 file make the filename main.kcl

* fix: auto fixes

* fix: share links generate main.kcl

* fix: codespell typoe

* fix: fixing E2E tests

* Fix 3 more tests

* fix: share url link e2e file name fix

---------

Co-authored-by: Pierre Jacquier <pierre@zoo.dev>
Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com>
Co-authored-by: Frank Noirot <frank@zoo.dev>
This commit is contained in:
Kevin Nadro
2025-05-16 22:43:25 -05:00
committed by GitHub
parent dc8496c62e
commit d768073d17
5 changed files with 35 additions and 29 deletions

View File

@ -410,7 +410,7 @@ test.describe('Command bar tests', () => {
currentArgValue: '', currentArgValue: '',
headerArguments: { headerArguments: {
Method: '', Method: '',
Name: 'test', Name: 'main.kcl',
Code: '1 line', Code: '1 line',
}, },
highlightedHeaderArg: 'method', highlightedHeaderArg: 'method',
@ -421,7 +421,7 @@ test.describe('Command bar tests', () => {
commandName: 'Import file from URL', commandName: 'Import file from URL',
headerArguments: { headerArguments: {
Method: 'New project', Method: 'New project',
Name: 'test', Name: 'main.kcl',
Code: '1 line', Code: '1 line',
}, },
}) })
@ -474,7 +474,7 @@ test.describe('Command bar tests', () => {
currentArgValue: '', currentArgValue: '',
headerArguments: { headerArguments: {
Method: '', Method: '',
Name: 'test', Name: 'main.kcl',
Code: '1 line', Code: '1 line',
}, },
highlightedHeaderArg: 'method', highlightedHeaderArg: 'method',
@ -487,7 +487,7 @@ test.describe('Command bar tests', () => {
currentArgValue: '', currentArgValue: '',
headerArguments: { headerArguments: {
Method: 'Existing project', Method: 'Existing project',
Name: 'test', Name: 'main.kcl',
ProjectName: '', ProjectName: '',
Code: '1 line', Code: '1 line',
}, },
@ -500,7 +500,7 @@ test.describe('Command bar tests', () => {
headerArguments: { headerArguments: {
Method: 'Existing project', Method: 'Existing project',
ProjectName: 'testProjectDir', ProjectName: 'testProjectDir',
Name: 'test', Name: 'main.kcl',
Code: '1 line', Code: '1 line',
}, },
}) })
@ -510,7 +510,7 @@ test.describe('Command bar tests', () => {
await test.step(`Ensure we created the project and are in the modeling scene`, async () => { await test.step(`Ensure we created the project and are in the modeling scene`, async () => {
await editor.expectEditor.toContain('extrusionDistance = 12') await editor.expectEditor.toContain('extrusionDistance = 12')
await toolbar.openPane('files') await toolbar.openPane('files')
await toolbar.expectFileTreeState(['main.kcl', 'test.kcl']) await toolbar.expectFileTreeState(['main-1.kcl', 'main.kcl'])
}) })
}) })

View File

@ -773,12 +773,12 @@ test.describe('Mocked Text-to-CAD API tests', { tag: ['@skipWin'] }, () => {
) )
await expect(page.getByTestId('app-header-file-name')).toBeVisible() await expect(page.getByTestId('app-header-file-name')).toBeVisible()
await expect(page.getByTestId('app-header-file-name')).toContainText( await expect(page.getByTestId('app-header-file-name')).toContainText(
'2x2x2-cube.kcl' 'main.kcl'
) )
await u.openFilePanel() await u.openFilePanel()
await expect( await expect(
page.getByTestId('file-tree-item').getByText('2x2x2-cube.kcl') page.getByTestId('file-tree-item').getByText('main.kcl')
).toBeVisible() ).toBeVisible()
} }
) )
@ -913,7 +913,7 @@ test.describe('Mocked Text-to-CAD API tests', { tag: ['@skipWin'] }, () => {
) )
await expect(page.getByTestId('app-header-file-name')).toBeVisible() await expect(page.getByTestId('app-header-file-name')).toBeVisible()
await expect(page.getByTestId('app-header-file-name')).toContainText( await expect(page.getByTestId('app-header-file-name')).toContainText(
'2x2x2-cube.kcl' 'main.kcl'
) )
await page.getByRole('button', { name: 'Reject' }).click() await page.getByRole('button', { name: 'Reject' }).click()
@ -961,7 +961,7 @@ test.describe('Mocked Text-to-CAD API tests', { tag: ['@skipWin'] }, () => {
) )
await expect(page.getByTestId('app-header-file-name')).toBeVisible() await expect(page.getByTestId('app-header-file-name')).toBeVisible()
await expect(page.getByTestId('app-header-file-name')).toContainText( await expect(page.getByTestId('app-header-file-name')).toContainText(
'2x2x2-cube.kcl' 'main.kcl'
) )
} }
) )
@ -1213,18 +1213,14 @@ test.describe('Mocked Text-to-CAD API tests', { tag: ['@skipWin'] }, () => {
) )
await expect(page.getByTestId('app-header-file-name')).toBeVisible() await expect(page.getByTestId('app-header-file-name')).toBeVisible()
await expect(page.getByTestId('app-header-file-name')).toContainText( await expect(page.getByTestId('app-header-file-name')).toContainText(
'2x2x2-cube.kcl' 'main.kcl'
) )
// Check file is created // Check file is created
await u.openFilePanel() await u.openFilePanel()
await expect(
page.getByTestId('file-tree-item').getByText('2x2x2-cube.kcl')
).toBeVisible()
await expect( await expect(
page.getByTestId('file-tree-item').getByText('main.kcl') page.getByTestId('file-tree-item').getByText('main.kcl')
).not.toBeVisible() ).toBeVisible()
} }
) )

View File

@ -5,11 +5,14 @@ import { useNetworkContext } from '@src/hooks/useNetworkContext'
import { EngineConnectionStateType } from '@src/lang/std/engineConnection' import { EngineConnectionStateType } from '@src/lang/std/engineConnection'
import { base64ToString } from '@src/lib/base64' import { base64ToString } from '@src/lib/base64'
import type { ProjectsCommandSchema } from '@src/lib/commandBarConfigs/projectsCommandConfig' import type { ProjectsCommandSchema } from '@src/lib/commandBarConfigs/projectsCommandConfig'
import { CREATE_FILE_URL_PARAM, DEFAULT_FILE_NAME } from '@src/lib/constants' import {
CREATE_FILE_URL_PARAM,
DEFAULT_FILE_NAME,
PROJECT_ENTRYPOINT,
} from '@src/lib/constants'
import { isDesktop } from '@src/lib/isDesktop' import { isDesktop } from '@src/lib/isDesktop'
import type { FileLinkParams } from '@src/lib/links' import type { FileLinkParams } from '@src/lib/links'
import { PATHS } from '@src/lib/paths' import { PATHS } from '@src/lib/paths'
import { useSettings } from '@src/lib/singletons'
// For initializing the command arguments, we actually want `method` to be undefined // For initializing the command arguments, we actually want `method` to be undefined
// so that we don't skip it in the command palette. // so that we don't skip it in the command palette.
@ -32,7 +35,6 @@ export function useCreateFileLinkQuery(
const { immediateState } = useNetworkContext() const { immediateState } = useNetworkContext()
const { pathname } = useLocation() const { pathname } = useLocation()
const [searchParams] = useSearchParams() const [searchParams] = useSearchParams()
const settings = useSettings()
useEffect(() => { useEffect(() => {
const isHome = pathname === PATHS.HOME const isHome = pathname === PATHS.HOME
@ -53,13 +55,7 @@ export function useCreateFileLinkQuery(
} }
const argDefaultValues: CreateFileSchemaMethodOptional = { const argDefaultValues: CreateFileSchemaMethodOptional = {
name: params.name name: PROJECT_ENTRYPOINT,
? isDesktop()
? params.name.replace('.kcl', '')
: params.name
: isDesktop()
? settings.projects.defaultProjectName.current
: DEFAULT_FILE_NAME,
code: params.code || '', code: params.code || '',
method: isDesktop() ? undefined : 'existingProject', method: isDesktop() ? undefined : 'existingProject',
} }

View File

@ -10,7 +10,7 @@ import {
kclSamplesManifestWithNoMultipleFiles, kclSamplesManifestWithNoMultipleFiles,
} from '@src/lib/kclSamples' } from '@src/lib/kclSamples'
import { getUniqueProjectName } from '@src/lib/desktopFS' import { getUniqueProjectName } from '@src/lib/desktopFS'
import { IS_ML_EXPERIMENTAL } from '@src/lib/constants' import { IS_ML_EXPERIMENTAL, PROJECT_ENTRYPOINT } from '@src/lib/constants'
import toast from 'react-hot-toast' import toast from 'react-hot-toast'
import { reportRejection } from '@src/lib/trap' import { reportRejection } from '@src/lib/trap'
import { relevantFileExtensions } from '@src/lang/wasmUtils' import { relevantFileExtensions } from '@src/lang/wasmUtils'
@ -22,11 +22,13 @@ function onSubmitKCLSampleCreation({
kclSample, kclSample,
uniqueNameIfNeeded, uniqueNameIfNeeded,
systemIOActor, systemIOActor,
isProjectNew,
}: { }: {
sample: any sample: any
kclSample: ReturnType<typeof findKclSample> kclSample: ReturnType<typeof findKclSample>
uniqueNameIfNeeded: any uniqueNameIfNeeded: any
systemIOActor: ActorRefFrom<typeof systemIOMachine> systemIOActor: ActorRefFrom<typeof systemIOMachine>
isProjectNew: boolean
}) { }) {
if (!kclSample) { if (!kclSample) {
toast.error('The command could not be submitted, unable to find Zoo sample') toast.error('The command could not be submitted, unable to find Zoo sample')
@ -72,11 +74,15 @@ function onSubmitKCLSampleCreation({
* Navigates to the single file that could be renamed on disk for duplicates * Navigates to the single file that could be renamed on disk for duplicates
*/ */
const folderNameBecomesKCLFileName = projectPathPart + FILE_EXT const folderNameBecomesKCLFileName = projectPathPart + FILE_EXT
// If the project is new create the single file as main.kcl
const requestedFileNameWithExtension = isProjectNew
? PROJECT_ENTRYPOINT
: folderNameBecomesKCLFileName
systemIOActor.send({ systemIOActor.send({
type: SystemIOMachineEvents.importFileFromURL, type: SystemIOMachineEvents.importFileFromURL,
data: { data: {
requestedProjectName: requestedFiles[0].requestedProjectName, requestedProjectName: requestedFiles[0].requestedProjectName,
requestedFileNameWithExtension: folderNameBecomesKCLFileName, requestedFileNameWithExtension: requestedFileNameWithExtension,
requestedCode: requestedFiles[0].requestedCode, requestedCode: requestedFiles[0].requestedCode,
}, },
}) })
@ -206,6 +212,7 @@ export function createApplicationCommands({
kclSample, kclSample,
uniqueNameIfNeeded, uniqueNameIfNeeded,
systemIOActor, systemIOActor,
isProjectNew,
}) })
} else if (data.source === 'local' && data.path) { } else if (data.source === 'local' && data.path) {
const clonePath = data.path const clonePath = data.path
@ -396,6 +403,7 @@ export function createApplicationCommands({
kclSample, kclSample,
uniqueNameIfNeeded, uniqueNameIfNeeded,
systemIOActor, systemIOActor,
isProjectNew: true,
}) })
} }
}, },

View File

@ -6,7 +6,7 @@ import {
ToastTextToCadError, ToastTextToCadError,
ToastTextToCadSuccess, ToastTextToCadSuccess,
} from '@src/components/ToastTextToCad' } from '@src/components/ToastTextToCad'
import { FILE_EXT } from '@src/lib/constants' import { FILE_EXT, PROJECT_ENTRYPOINT } from '@src/lib/constants'
import crossPlatformFetch from '@src/lib/crossPlatformFetch' import crossPlatformFetch from '@src/lib/crossPlatformFetch'
import { getNextFileName } from '@src/lib/desktopFS' import { getNextFileName } from '@src/lib/desktopFS'
import { isDesktop } from '@src/lib/isDesktop' import { isDesktop } from '@src/lib/isDesktop'
@ -196,12 +196,18 @@ export async function submitAndAwaitTextToKclSystemIO({
} }
const TRUNCATED_PROMPT_LENGTH = 24 const TRUNCATED_PROMPT_LENGTH = 24
// Only add the prompt name if it is a preexisting project
newFileName = `${value.prompt newFileName = `${value.prompt
.slice(0, TRUNCATED_PROMPT_LENGTH) .slice(0, TRUNCATED_PROMPT_LENGTH)
.replace(/\s/gi, '-') .replace(/\s/gi, '-')
.replace(/\W/gi, '-') .replace(/\W/gi, '-')
.toLowerCase()}${FILE_EXT}` .toLowerCase()}${FILE_EXT}`
// If the project is new generate a main.kcl
if (isProjectNew) {
newFileName = PROJECT_ENTRYPOINT
}
if (isDesktop()) { if (isDesktop()) {
// We have to preemptively run our unique file name logic, // We have to preemptively run our unique file name logic,
// so that we can pass the unique file name to the toast, // so that we can pass the unique file name to the toast,