Fix queue rules upper bound to never allow 0 (#543)

This commit is contained in:
Flaminel
2026-04-03 16:11:12 +03:00
committed by GitHub
parent 81f6de03e7
commit ef280ec398
5 changed files with 32 additions and 10 deletions

View File

@@ -20,7 +20,7 @@ public abstract record QueueRuleDto
[Range(0, 100, ErrorMessage = "Minimum completion percentage must be between 0 and 100")]
public ushort MinCompletionPercentage { get; set; }
[Range(0, 100, ErrorMessage = "Maximum completion percentage must be between 0 and 100")]
[Range(1, 100, ErrorMessage = "Maximum completion percentage must be between 1 and 100")]
public ushort MaxCompletionPercentage { get; set; }
public bool DeletePrivateTorrentsFromClient { get; set; } = false;

View File

@@ -188,11 +188,26 @@ public sealed class QueueRuleTests
};
var exception = Should.Throw<ValidationException>(() => rule.Validate());
exception.Message.ShouldBe("Maximum completion percentage must be between 0 and 100");
exception.Message.ShouldBe("Maximum completion percentage must be between 1 and 100");
}
[Fact]
public void Validate_WithZeroMaxCompletionPercentage_ThrowsValidationException()
{
var rule = new StallRule
{
Name = "test-rule",
MaxStrikes = 3,
MinCompletionPercentage = 0,
MaxCompletionPercentage = 0
};
var exception = Should.Throw<ValidationException>(() => rule.Validate());
exception.Message.ShouldBe("Maximum completion percentage must be greater than 0");
}
[Theory]
[InlineData((ushort)0)]
[InlineData((ushort)1)]
[InlineData((ushort)50)]
[InlineData((ushort)100)]
public void Validate_WithValidMaxCompletionPercentage_DoesNotThrow(ushort maxCompletionPercentage)

View File

@@ -24,8 +24,8 @@ public abstract record QueueRule : IConfig, IQueueRule
public TorrentPrivacyType PrivacyType { get; init; } = TorrentPrivacyType.Public;
public ushort MinCompletionPercentage { get; init; } = 0;
public ushort MaxCompletionPercentage { get; init; }
public ushort MaxCompletionPercentage { get; init; } = 100;
public bool DeletePrivateTorrentsFromClient { get; init; } = false;
@@ -48,9 +48,14 @@ public abstract record QueueRule : IConfig, IQueueRule
throw new Cleanuparr.Domain.Exceptions.ValidationException("Minimum completion percentage must be between 0 and 100");
}
if (MaxCompletionPercentage == 0)
{
throw new Cleanuparr.Domain.Exceptions.ValidationException("Maximum completion percentage must be greater than 0");
}
if (MaxCompletionPercentage > 100)
{
throw new Cleanuparr.Domain.Exceptions.ValidationException("Maximum completion percentage must be between 0 and 100");
throw new Cleanuparr.Domain.Exceptions.ValidationException("Maximum completion percentage must be between 1 and 100");
}
if (MaxCompletionPercentage < MinCompletionPercentage)

View File

@@ -261,10 +261,10 @@
helpKey="queue-cleaner:stallRule.privacyType" />
<app-number-input label="Min Completion %" [(value)]="stallMinCompletion" [min]="0" [max]="100" suffix="%"
hint="Apply the rule once completion percentage exceeds this value (0 includes items at 0% and above)"
[error]="stallCompletionError()"
helpKey="queue-cleaner:stallRule.completionRange" />
<app-number-input label="Max Completion %" [(value)]="stallMaxCompletion" [min]="0" [max]="100" suffix="%"
<app-number-input label="Max Completion %" [(value)]="stallMaxCompletion" [min]="1" [max]="100" suffix="%"
hint="Apply the rule to items with a completion percentage less than or equal to this value"
[error]="stallCompletionError()"
helpKey="queue-cleaner:stallRule.completionRange" />
<app-toggle label="Reset Strikes on Progress" [(checked)]="stallResetOnProgress"
hint="Reset strike count when torrent shows progress"
@@ -314,10 +314,10 @@
helpKey="queue-cleaner:slowRule.privacyType" />
<app-number-input label="Min Completion %" [(value)]="slowMinCompletion" [min]="0" [max]="100" suffix="%"
hint="Apply the rule once completion percentage exceeds this value (0 still includes exactly 0%)"
[error]="slowCompletionError()"
helpKey="queue-cleaner:slowRule.completionRange" />
<app-number-input label="Max Completion %" [(value)]="slowMaxCompletion" [min]="0" [max]="100" suffix="%"
<app-number-input label="Max Completion %" [(value)]="slowMaxCompletion" [min]="1" [max]="100" suffix="%"
hint="Apply the rule up to and including this completion percentage"
[error]="slowCompletionError()"
helpKey="queue-cleaner:slowRule.completionRange" />
<app-size-input label="Ignore Above Size" [units]="sizeUnitsLarge" [(value)]="slowIgnoreAboveSize"
placeholder="e.g. 25"

View File

@@ -236,6 +236,7 @@ export class QueueCleanerComponent implements OnInit, HasPendingChanges {
readonly stallCompletionError = computed(() => {
const min = this.stallMinCompletion() ?? 0;
const max = this.stallMaxCompletion() ?? 100;
if (max <= 0) return 'Max percentage must be greater than 0';
if (max < min) return 'Max percentage must be greater than or equal to Min percentage';
return undefined;
});
@@ -256,6 +257,7 @@ export class QueueCleanerComponent implements OnInit, HasPendingChanges {
readonly slowCompletionError = computed(() => {
const min = this.slowMinCompletion() ?? 0;
const max = this.slowMaxCompletion() ?? 100;
if (max <= 0) return 'Max percentage must be greater than 0';
if (max < min) return 'Max percentage must be greater than or equal to Min percentage';
return undefined;
});