Skip to content

Conversation

m-bucher
Copy link
Contributor

@m-bucher m-bucher commented Aug 14, 2025

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?

  • Have at least one SmartProxy on a separate server
  • Sync Content onto it
  • On Smart Proxy's Detail page go to Content-tab
  • LCEnv- and ContentView-rows should have an additional Action in the Kebab-menu on the right side named 'Verify Content Checksum'. Pressing it should trigger the appropriate action.

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:

  • Add "Verify Content Checksum" action to the SmartProxy content tab for both environments and content views

Enhancements:

  • Implement repairSmartProxyContent action creator and constant and integrate it into SmartProxyContentActions, ExpandableCvDetails, and SmartProxyExpandableTable

Tests:

  • Add tests to verify that the new checksum verification action correctly triggers the API calls for both environment and content view

Copy link

sourcery-ai bot commented Aug 14, 2025

Reviewer's Guide

Adds 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 UI

sequenceDiagram
    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'
Loading

Class diagram for SmartProxyContentActions changes

classDiagram
    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
Loading

File-Level Changes

Change Details Files
Introduce repairSmartProxyContent API action and constant
  • Export SMART_PROXY_REPAIR_CONTENT_KEY in constants
  • Implement repairSmartProxyContent() to POST /capsules/:id/content/verify_checksum and show a toast on success
webpack/scenes/SmartProxy/SmartProxyContentConstants.js
webpack/scenes/SmartProxy/SmartProxyContentActions.js
Add “Verify Content Checksum” action to UI tables
  • Inject repairContentAction into SmartProxyExpandableTable for environments
  • Add repairContentAction in ExpandableCvDetails for content views
webpack/scenes/SmartProxy/SmartProxyExpandableTable.js
webpack/scenes/SmartProxy/ExpandableCvDetails.js
Expand unit tests to cover checksum verification
  • Define verify_checksum endpoint path in test fixtures
  • Add tests for environment-level and content-view–level repair calls
webpack/scenes/SmartProxy/__tests__/SmartProxyContentTest.js

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a 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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@m-bucher m-bucher force-pushed the add_capsule_content_repair_ui branch 2 times, most recently from b971432 to 3c49d88 Compare August 20, 2025 16:35
@m-bucher
Copy link
Contributor Author

Rebased and adapted the tests a little bit to match the existing ones.

@m-bucher m-bucher force-pushed the add_capsule_content_repair_ui branch from 3c49d88 to 7dfdaee Compare August 22, 2025 14:30
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.

1 participant