Skip to content

Commit 528f820

Browse files
feat: enable webforms to blazor transformation via validation bypass (#1929)
* feat: enable webforms to blazor transformation via validation bypass * feat: add unit tests for webforms validation bypass
1 parent 2980dab commit 528f820

File tree

2 files changed

+82
-5
lines changed

2 files changed

+82
-5
lines changed

server/aws-lsp-codewhisperer/src/language-server/netTransform/tests/validation.test.ts

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from 'chai'
22
import { StartTransformRequest, TransformProjectMetadata } from '../models'
3-
import { isProject, isSolution, validateProject } from '../validation'
3+
import { isProject, isSolution, validateProject, validateSolution } from '../validation'
44
import { supportedProjects, unsupportedViewComponents } from '../resources/SupportedProjects'
55
import mock = require('mock-fs')
66
import { Logging } from '@aws/language-server-runtimes/server-interface'
@@ -96,4 +96,72 @@ describe('Test validation functionality', () => {
9696

9797
expect(validateProject(mockStartTransformationRequest, mockedLogging)).to.equal(false)
9898
})
99+
100+
// New tests for AspNetWebForms validation
101+
it('should return true when project is AspNetWebForms type', () => {
102+
let mockStartTransformationRequest: StartTransformRequest = sampleStartTransformRequest
103+
const mockProjectMeta = {
104+
Name: '',
105+
ProjectTargetFramework: '',
106+
ProjectPath: 'test.csproj',
107+
SourceCodeFilePaths: [],
108+
ProjectLanguage: '',
109+
ProjectType: 'AspNetWebForms',
110+
ExternalReferences: [],
111+
}
112+
mockStartTransformationRequest.ProjectMetadata = []
113+
mockStartTransformationRequest.ProjectMetadata.push(mockProjectMeta)
114+
115+
expect(validateProject(mockStartTransformationRequest, mockedLogging)).to.equal(true)
116+
})
117+
118+
it('should not include AspNetWebForms in unsupported projects list', () => {
119+
let mockStartTransformationRequest: StartTransformRequest = sampleStartTransformRequest
120+
121+
// Add a supported project
122+
const supportedProjectMeta = {
123+
Name: 'Supported',
124+
ProjectTargetFramework: '',
125+
ProjectPath: 'supported.csproj',
126+
SourceCodeFilePaths: [],
127+
ProjectLanguage: '',
128+
ProjectType: 'AspNetCoreMvc',
129+
ExternalReferences: [],
130+
}
131+
132+
// Add an unsupported project
133+
const unsupportedProjectMeta = {
134+
Name: 'Unsupported',
135+
ProjectTargetFramework: '',
136+
ProjectPath: 'unsupported.csproj',
137+
SourceCodeFilePaths: [],
138+
ProjectLanguage: '',
139+
ProjectType: 'UnsupportedType',
140+
ExternalReferences: [],
141+
}
142+
143+
// Add an AspNetWebForms project
144+
const webFormsProjectMeta = {
145+
Name: 'WebForms',
146+
ProjectTargetFramework: '',
147+
ProjectPath: 'webforms.csproj',
148+
SourceCodeFilePaths: [],
149+
ProjectLanguage: '',
150+
ProjectType: 'AspNetWebForms',
151+
ExternalReferences: [],
152+
}
153+
154+
mockStartTransformationRequest.ProjectMetadata = [
155+
supportedProjectMeta,
156+
unsupportedProjectMeta,
157+
webFormsProjectMeta,
158+
]
159+
160+
const unsupportedProjects = validateSolution(mockStartTransformationRequest)
161+
162+
// Should only contain the unsupported project, not the AspNetWebForms project
163+
expect(unsupportedProjects).to.have.lengthOf(1)
164+
expect(unsupportedProjects[0]).to.equal('unsupported.csproj')
165+
expect(unsupportedProjects).to.not.include('webforms.csproj')
166+
})
99167
})

server/aws-lsp-codewhisperer/src/language-server/netTransform/validation.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ import { Logging } from '@aws/language-server-runtimes/server-interface'
55
import { TransformationJob } from '../../client/token/codewhispererbearertokenclient'
66
import { TransformationErrorCode } from './models'
77

8+
/**
9+
* TEMPORARY HACK: AspNetWebForms project type is allowed in validateProject and validateSolution
10+
* functions without being added to the supportedProjects array. This is to enable WebForms to Blazor
11+
* transformation without officially supporting it yet.
12+
*/
13+
814
export function isProject(userInputrequest: StartTransformRequest): boolean {
915
return userInputrequest.SelectedProjectPath.endsWith('.csproj')
1016
}
@@ -19,7 +25,10 @@ export function validateProject(userInputrequest: StartTransformRequest, logging
1925
)
2026

2127
if (selectedProject) {
22-
var isValid = supportedProjects.includes(selectedProject?.ProjectType)
28+
// Temporary hack: Allow AspNetWebForms project type without adding it to supportedProjects
29+
var isValid =
30+
supportedProjects.includes(selectedProject?.ProjectType) ||
31+
selectedProject?.ProjectType === 'AspNetWebForms'
2332
logging.log(
2433
`Selected project ${userInputrequest?.SelectedProjectPath} has project type ${selectedProject.ProjectType}` +
2534
(isValid ? '' : ' that is not supported')
@@ -31,9 +40,9 @@ export function validateProject(userInputrequest: StartTransformRequest, logging
3140
}
3241

3342
export function validateSolution(userInputrequest: StartTransformRequest): string[] {
34-
return userInputrequest.ProjectMetadata.filter(project => !supportedProjects.includes(project.ProjectType)).map(
35-
project => project.ProjectPath
36-
)
43+
return userInputrequest.ProjectMetadata.filter(
44+
project => !supportedProjects.includes(project.ProjectType) && project.ProjectType !== 'AspNetWebForms'
45+
).map(project => project.ProjectPath)
3746
}
3847

3948
export async function checkForUnsupportedViews(

0 commit comments

Comments
 (0)