Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(/dev): logic to allow customer to modify root source folder #4985

Merged
merged 1 commit into from
May 16, 2024

Conversation

sannicm
Copy link
Contributor

@sannicm sannicm commented May 14, 2024

Problem

A recent refactor (#4924) moved collectFiles to a shared file but also updated the logic to throw another error that the /dev controller was not expecting. This effectively broke the feature that allows customer to modify root source folder when the folder exceeds 200MB

Solution

  • Updated the if-else logic to check for the correct error
  • Added a unit test to make it clearer that /dev controller expects the error to be specific to avoid breaking the logic.

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@sannicm sannicm requested a review from a team as a code owner May 14, 2024 13:17
@@ -3984,7 +3984,7 @@
},
"devDependencies": {
"@aws-sdk/types": "^3.13.1",
"@aws-toolkits/telemetry": "^1.0.205",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to reviewers:

I've updated telemetry and added a new event emission to the /dev logic as the cost was very low and it was just one line in the logic. Let me know if you'd rather split this.

@sannicm sannicm force-pushed the sannicm/sendModifySourceFolderMetric branch 2 times, most recently from 9ca3187 to c49c978 Compare May 14, 2024 13:24
@@ -231,7 +232,7 @@ export class FeatureDevController {
break
}
} catch (err: any) {
if (err instanceof ContentLengthError) {
if (err instanceof ToolkitError && err.code === 'ContentLengthError') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we modify this check, how will the ContentLengthError be handled that is being thrown explicitly here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I need to handle both.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of handling both, can we not revert this change back to throwing ContentLengthError in case of repo size being greater than 200MB ?

@sannicm sannicm force-pushed the sannicm/sendModifySourceFolderMetric branch from c49c978 to 75c3fbf Compare May 14, 2024 15:11
@justinmk3 justinmk3 changed the title fix: logic to allow customer to modify root source folder fix(/dev): logic to allow customer to modify root source folder May 14, 2024
@sannicm sannicm force-pushed the sannicm/sendModifySourceFolderMetric branch 2 times, most recently from 6fd0ef7 to 96bd651 Compare May 15, 2024 08:56
@@ -55,8 +56,8 @@ export async function prepareRepoData(
}
} catch (error) {
getLogger().debug(`featureDev: Failed to prepare repo: ${error}`)
if (error instanceof ContentLengthError) {
throw error
if (error instanceof ToolkitError && error.code === 'ContentLengthError') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its better to keep existing check for ContentLengthError as well here.

@sannicm sannicm force-pushed the sannicm/sendModifySourceFolderMetric branch 2 times, most recently from eceb010 to 8650a10 Compare May 16, 2024 09:22
} catch (err) {
assert.strictEqual(err instanceof ContentLengthError, true)
}
}).timeout(120 * 1000) // Allow test to run longer than 30 seconds
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the test need to run longer than 30 seconds?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Becuase I'm trying to create files that will break the 200MB limit for repo size, this file creation and all takes more time than 30s

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm adding the test specifically to avoid any future regressions as a refactor made by another team broke our feature.

Copy link
Contributor

@hayemaxi hayemaxi May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a convoluted way of creating a large set of files. Can't you just try something like?

fs.writeFile('file', new Buffer(<some size>));

That way you can just make one big file, and it might be faster. Would like to avoid extending timeouts since tests already take a long time to run.

If so, make sure to use the fs implementation if srcShared/fs.ts

Copy link
Contributor

@hayemaxi hayemaxi May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, maybe we can stub vscode.workspace.fs.stat(file.fileUri)) or something. I think that would be better than actually allocating a bunch of space on the testing machine (which would be our machines much of the time). I think this would be the preferred solution.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That way you can just make one big file, and it might be faster. Would like to avoid extending timeouts since tests already take a long time to run.

Yes, absolutely. In fact, this should be in testInteg/, that is where slow tests live.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestions, I will take another look to this test then.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've resorted to stubbing the fsCommon.stat function. As there is no need in that case to make the test longer, by just stubbing the function I can return a value that will make the logic throw the error.

@sannicm sannicm requested a review from hayemaxi May 16, 2024 16:47
@justinmk3
Copy link
Contributor

justinmk3 commented May 16, 2024

#4977 also changed the collectFiles() call in packages/core/src/amazonqFeatureDev/session/sessionState.ts , should that be done in this PR?

@sannicm
Copy link
Contributor Author

sannicm commented May 16, 2024

#4977 also changed the collectFiles() call in packages/core/src/amazonqFeatureDev/session/sessionState.ts , should that be done in this PR?

Ahh I see @gasolima closed it, so I'll keep that feature here.

@sannicm sannicm force-pushed the sannicm/sendModifySourceFolderMetric branch from 8650a10 to eae98d1 Compare May 16, 2024 19:16
@hayemaxi hayemaxi merged commit df73086 into aws:master May 16, 2024
13 of 14 checks passed
@justinmk3
Copy link
Contributor

Does this collectFiles call need to be updated?

const files = await collectFiles(
this.config.workspaceFolders.map(f => path.join(f.uri.fsPath, './mock-data')),
this.config.workspaceFolders,
false
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants