-
Notifications
You must be signed in to change notification settings - Fork 303
Fixes #38662 - Add Verify Content Checksum for capsule #11474
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
base: master
Are you sure you want to change the base?
Conversation
Reviewer's GuideAdds a “Verify Content Checksum” action to the SmartProxy content UI, wiring it to a new repairSmartProxyContent API call and covering both environment- and content-view–level triggers with unit tests. Sequence diagram for triggering Verify Content Checksum from UIsequenceDiagram
actor User
participant UI
participant Redux
participant API
participant SmartProxy
User->>UI: Clicks 'Verify Content Checksum' action
UI->>Redux: Dispatch repairSmartProxyContent(smartProxyId, params)
Redux->>API: POST /capsules/:id/content/verify_checksum
API->>SmartProxy: Initiate checksum verification
SmartProxy-->>API: Responds with task started
API->>UI: Return response
UI->>User: Show toast 'Smart proxy verify content checksum has started in the background'
Class diagram for SmartProxyContentActions changesclassDiagram
class SmartProxyContentActions {
+updateSmartProxyContentCounts(smartProxyId, params)
+repairSmartProxyContent(smartProxyId, params)
}
SmartProxyContentActions : +SMART_PROXY_REPAIR_CONTENT_KEY
SmartProxyContentActions : +SMART_PROXY_COUNTS_UPDATE_KEY
SmartProxyContentActions : +SMART_PROXY_KEY
SmartProxyContentActions : +SMART_PROXY_CONTENT_KEY
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `webpack/scenes/SmartProxy/SmartProxyContentActions.js:32` </location>
<code_context>
errorToast: error => __(`Something went wrong while refreshing content counts: ${getResponseErrorMsgs(error.response)}`),
});
+export const repairSmartProxyContent = (smartProxyId, params) => post({
+ type: API_OPERATIONS.POST,
+ key: SMART_PROXY_REPAIR_CONTENT_KEY,
+ url: api.getApiUrl(`/capsules/${smartProxyId}/content/verify_checksum`),
+ params,
+ handleSuccess: (response) => {
+ renderTaskStartedToast(response?.data, __('Smart proxy verify content checksum has started in the background'));
+ },
+ errorToast: error => __(`Something went wrong while verifying content checksums: ${getResponseErrorMsgs(error.response)}`),
+});
+
</code_context>
<issue_to_address>
Check error handling for edge cases in the repairSmartProxyContent action.
Handle cases where error.response is undefined to prevent runtime errors and improve error messaging.
</issue_to_address>
### Comment 2
<location> `webpack/scenes/SmartProxy/__tests__/SmartProxyContentTest.js:157` </location>
<code_context>
act(done);
});
+
+test('Can call content repair for environment', async (done) => {
+ const detailsScope = nockInstance
+ .get(smartProxyContentPath)
+ .query(true)
+ .reply(200, smartProxyContent);
+
+ const contentEnvRepairScope = nockInstance
+ .post(smartProxyRepairContentPath, {
+ environment_id: 1,
+ })
+ .reply(202);
+
+ const {
+ getByText, queryAllByLabelText,
+ } = renderWithRedux(contentTable);
+ await patientlyWaitFor(() => expect(getByText('Environment')).toBeInTheDocument());
+ const envRowActions = queryAllByLabelText('Actions')[0];
+ envRowActions.click();
+ await patientlyWaitFor(() => expect(getByText('Verify Content Checksum')).toBeInTheDocument());
+ const refreshEnv = getByText('Verify Content Checksum');
+ refreshEnv.click();
+
+ assertNockRequest(detailsScope);
+ assertNockRequest(contentEnvRepairScope, done);
+});
</code_context>
<issue_to_address>
Missing negative test for failed content repair request.
Add a test case simulating a failed API response to verify error handling and user feedback mechanisms.
Suggested implementation:
```javascript
test('Can call content repair for environment', async (done) => {
const detailsScope = nockInstance
.get(smartProxyContentPath)
.query(true)
.reply(200, smartProxyContent);
const contentEnvRepairScope = nockInstance
.post(smartProxyRepairContentPath, {
environment_id: 1,
})
.reply(202);
const {
getByText, queryAllByLabelText,
} = renderWithRedux(contentTable);
await patientlyWaitFor(() => expect(getByText('Environment')).toBeInTheDocument());
const envRowActions = queryAllByLabelText('Actions')[0];
envRowActions.click();
await patientlyWaitFor(() => expect(getByText('Verify Content Checksum')).toBeInTheDocument());
const refreshEnv = getByText('Verify Content Checksum');
refreshEnv.click();
assertNockRequest(detailsScope);
assertNockRequest(contentEnvRepairScope, done);
});
test('Shows error message when content repair for environment fails', async (done) => {
const detailsScope = nockInstance
.get(smartProxyContentPath)
.query(true)
.reply(200, smartProxyContent);
const contentEnvRepairScope = nockInstance
.post(smartProxyRepairContentPath, {
environment_id: 1,
})
.reply(500, { message: 'Internal Server Error' });
const {
getByText, queryAllByLabelText, findByText,
} = renderWithRedux(contentTable);
await patientlyWaitFor(() => expect(getByText('Environment')).toBeInTheDocument());
const envRowActions = queryAllByLabelText('Actions')[0];
envRowActions.click();
await patientlyWaitFor(() => expect(getByText('Verify Content Checksum')).toBeInTheDocument());
const refreshEnv = getByText('Verify Content Checksum');
refreshEnv.click();
assertNockRequest(detailsScope);
assertNockRequest(contentEnvRepairScope);
// Wait for error message to appear
const errorMessage = await findByText(/error|failed|internal server error/i);
expect(errorMessage).toBeInTheDocument();
act(done);
});
```
- If your error handling displays a specific error message, adjust the `findByText` regex to match the actual message.
- If the error message is shown in a custom component or via a notification system, you may need to query for that element differently.
</issue_to_address>
### Comment 3
<location> `webpack/scenes/SmartProxy/__tests__/SmartProxyContentTest.js:183` </location>
<code_context>
+test('Can call content repair for content view', async (done) => {
</code_context>
<issue_to_address>
Missing test for repair action when required parameters are missing or invalid.
Please add a test case for the repair action with missing or invalid parameters to ensure proper error handling and API behavior.
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
b971432
to
3c49d88
Compare
Rebased and adapted the tests a little bit to match the existing ones. |
3c49d88
to
7dfdaee
Compare
What are the changes introduced in this pull request?
On SmartProxy Details' Content-Tab, added new Action for LCEnv and ContentView to repair content (Verify Content Checksum).
Considerations taken when implementing this change?
Originally, I wanted to add a dropdown-element for the Synchronize-button as well. This would trigger a Verify Content Checksum on the whole SmartProxy. However, this might take a long time to run (depending on the amount of Content). I have created code for that, but we should only add it with a nice Disclaimer 😅
What are the testing steps for this pull request?
Summary by Sourcery
Add a new Verify Content Checksum action to SmartProxy content UI, wire up the corresponding action creator and API endpoint, and cover the feature with automated tests
New Features:
Enhancements:
Tests: