Skip to content

fix: send missing multipart form data fields in create endpoints#16

Merged
devRael1 merged 3 commits into
masterfrom
copilot/code-quality-analysis-csharp-sdk
Apr 14, 2026
Merged

fix: send missing multipart form data fields in create endpoints#16
devRael1 merged 3 commits into
masterfrom
copilot/code-quality-analysis-csharp-sdk

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 14, 2026

  • Fix 1: TorrentsClient.CreateTorrentAsync — add missing add_only_if_cached field to multipart content
  • Fix 2: TorrentsClient.AsyncCreateTorrentAsync — add missing add_only_if_cached field to multipart content
  • Fix 3: UsenetClient.CreateUsenetDownloadAsync — add missing as_queued and add_only_if_cached fields to multipart content
  • Fix 4: UsenetClient.AsyncCreateUsenetDownloadAsync — add missing as_queued and add_only_if_cached fields to multipart content
  • Fix 5: Add unit tests verifying these fields are included (Theory with InlineData for true/false)
  • Build and test verification (0 warnings, 345 tests pass on net8.0 + net10.0)
  • Code review and CodeQL validation passed
  • Review feedback 1: Move CreateTorrentAsync_WithAddOnlyIfCached test next to other CreateTorrentAsync tests
  • Review feedback 2: UsenetClientTests — verify actual multipart values (not just field names) for CreateUsenetDownloadAsync
  • Review feedback 3: UsenetClientTests — verify actual multipart values (not just field names) for AsyncCreateUsenetDownloadAsync

Copilot AI and others added 2 commits April 14, 2026 17:36
TorrentsClient.CreateTorrentAsync and AsyncCreateTorrentAsync were
not sending AddOnlyIfCached.

UsenetClient.CreateUsenetDownloadAsync and
AsyncCreateUsenetDownloadAsync were not sending AsQueued or
AddOnlyIfCached.

All four fields are defined on the request models but were silently
dropped when building the multipart content.

Adds 4 unit tests to verify these fields are included.

Agent-Logs-Url: https://github.com/devRael1/TorBoxSDK/sessions/7ba06d25-78c9-4732-a6c2-e40dd7145ac6

Co-authored-by: devRael1 <91017912+devRael1@users.noreply.github.com>
Cover both true/false values for AddOnlyIfCached and AsQueued fields
as suggested by code review.

Agent-Logs-Url: https://github.com/devRael1/TorBoxSDK/sessions/7ba06d25-78c9-4732-a6c2-e40dd7145ac6

Co-authored-by: devRael1 <91017912+devRael1@users.noreply.github.com>
@devRael1 devRael1 marked this pull request as ready for review April 14, 2026 18:26
Copilot AI review requested due to automatic review settings April 14, 2026 18:26
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes missing multipart form-data fields so TorBox “create” endpoints actually receive add_only_if_cached (torrents + usenet) and as_queued (usenet), aligning the request models with what gets sent over the wire.

Changes:

  • Add add_only_if_cached to multipart content in TorrentsClient.CreateTorrentAsync and TorrentsClient.AsyncCreateTorrentAsync.
  • Add as_queued and add_only_if_cached to multipart content in UsenetClient.CreateUsenetDownloadAsync and UsenetClient.AsyncCreateUsenetDownloadAsync.
  • Add unit tests asserting the new multipart fields are present.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/TorBoxSDK/Main/Torrents/TorrentsClient.cs Sends add_only_if_cached in multipart for both torrent create endpoints.
src/TorBoxSDK/Main/Usenet/UsenetClient.cs Sends as_queued + add_only_if_cached in multipart for both usenet create endpoints.
tests/TorboxSDK.UnitTests/Main/Torrents/TorrentsClientTests.cs Adds coverage for add_only_if_cached being included in multipart requests.
tests/TorboxSDK.UnitTests/Main/Usenet/UsenetClientTests.cs Adds coverage for as_queued/add_only_if_cached being included in multipart requests.

Comment on lines +148 to +149
Assert.Contains("as_queued", handler.LastRequestContent);
Assert.Contains("add_only_if_cached", handler.LastRequestContent);
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

These assertions only check that the multipart body contains the field names, but don't verify that the serialized values match the asQueued / addOnlyIfCached inputs. Adding value assertions (ideally tied to each field name) would better protect against regressions like hardcoding the value or swapping the two fields.

Suggested change
Assert.Contains("as_queued", handler.LastRequestContent);
Assert.Contains("add_only_if_cached", handler.LastRequestContent);
string multipartContent = handler.LastRequestContent;
System.Text.RegularExpressions.Match asQueuedMatch = System.Text.RegularExpressions.Regex.Match(
multipartContent,
"name=\"as_queued\"\\r\\n\\r\\n(?<value>[^\\r\\n]+)");
System.Text.RegularExpressions.Match addOnlyIfCachedMatch = System.Text.RegularExpressions.Regex.Match(
multipartContent,
"name=\"add_only_if_cached\"\\r\\n\\r\\n(?<value>[^\\r\\n]+)");
Assert.True(asQueuedMatch.Success);
Assert.True(addOnlyIfCachedMatch.Success);
Assert.Equal(asQueued.ToString().ToLowerInvariant(), asQueuedMatch.Groups["value"].Value.ToLowerInvariant());
Assert.Equal(addOnlyIfCached.ToString().ToLowerInvariant(), addOnlyIfCachedMatch.Groups["value"].Value.ToLowerInvariant());

Copilot uses AI. Check for mistakes.
Comment on lines +446 to +447
Assert.Contains("as_queued", handler.LastRequestContent);
Assert.Contains("add_only_if_cached", handler.LastRequestContent);
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

These assertions only check that the multipart body contains the field names, but don't verify that the serialized values match the asQueued / addOnlyIfCached inputs. Adding value assertions (ideally tied to each field name) would better protect against regressions like hardcoding the value or swapping the two fields.

Suggested change
Assert.Contains("as_queued", handler.LastRequestContent);
Assert.Contains("add_only_if_cached", handler.LastRequestContent);
string expectedAsQueuedContent = $"name=\"as_queued\"\r\n\r\n{asQueued.ToString().ToLowerInvariant()}";
string expectedAddOnlyIfCachedContent = $"name=\"add_only_if_cached\"\r\n\r\n{addOnlyIfCached.ToString().ToLowerInvariant()}";
Assert.Contains(expectedAsQueuedContent, handler.LastRequestContent);
Assert.Contains(expectedAddOnlyIfCachedContent, handler.LastRequestContent);

Copilot uses AI. Check for mistakes.
Comment on lines +564 to +570
// --- AsyncCreateTorrentAsync ---

[Theory]
[InlineData(true)]
[InlineData(false)]
public async Task CreateTorrentAsync_WithAddOnlyIfCached_IncludesInMultipartContent(bool addOnlyIfCached)
{
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

This new CreateTorrentAsync_* test is placed under the // --- AsyncCreateTorrentAsync --- section header, which makes the file harder to navigate (the other CreateTorrentAsync_* tests are earlier in the file). Consider moving this test next to the existing CreateTorrentAsync tests and/or introducing a // --- CreateTorrentAsync --- section header so the grouping matches the method under test.

Copilot uses AI. Check for mistakes.
@devRael1
Copy link
Copy Markdown
Owner

@copilot apply changes based on the comments in this thread

- Move CreateTorrentAsync_WithAddOnlyIfCached test next to other
  CreateTorrentAsync tests (was under AsyncCreateTorrentAsync section)
- Verify actual multipart field values (name + value) instead of
  just checking field names are present

Agent-Logs-Url: https://github.com/devRael1/TorBoxSDK/sessions/d2932ac3-0ee5-49bf-a81f-2af39c1fcdf8

Co-authored-by: devRael1 <91017912+devRael1@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 14, 2026

@copilot apply changes based on the comments in this thread

Applied all three review comments in 8ce0f58:

  1. Test placement: Moved CreateTorrentAsync_WithAddOnlyIfCached test next to the other CreateTorrentAsync tests (before ControlTorrentAsync section).
  2. Usenet value assertions: Both CreateUsenetDownloadAsync and AsyncCreateUsenetDownloadAsync tests now verify the actual multipart field values (e.g. name=as_queued\r\n\r\ntrue) instead of just checking field names are present.
  3. Torrent value assertions: Applied the same value-checking pattern to both torrent AddOnlyIfCached tests for consistency.

Copilot AI requested a review from devRael1 April 14, 2026 18:41
@devRael1 devRael1 merged commit df4bb8f into master Apr 14, 2026
@devRael1 devRael1 deleted the copilot/code-quality-analysis-csharp-sdk branch April 14, 2026 18:44
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.

3 participants