mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-31 17:51:49 +00:00
59852479bf
* test(versioning): cover four uncovered guards - `cargo`: a converted range whose operators are already attached to their versions, so `npm2cargo` leaves the elements alone - `hashicorp`: a widen on a complex range ending in `>=`, which the underlying semver implementation refuses and returns null for - `poetry`: a version list holding an unparseable entry, for both `getSatisfyingVersion` and `minSatisfyingVersion`, plus the same widen refusal, which falls back to the current value - `swift`: an open-ended range whose bound is not a valid semver Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * refactor(versioning): drop two guards that cannot be false - `hermit`: `major` is the only mandatory group in the version regex, so the `if (major)` around the first release segment always holds; the sibling parser already pushes it unconditionally - `rpm`: after `c1 === c2` is ruled out, one of `c1 > c2` and `c1 < c2` must hold, so the second comparison becomes a ternary Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * test(versioning/gradle): cover three uncovered guards - `getMajor` on a version whose leading token is not a number - `getSatisfyingVersion` with a later match that is not greater than the one already held - `minSatisfyingVersion` with a later match that is not smaller than the one already held Two branches in `compare.ts` are still open and are looked at next. Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * test(versioning/ivy): cover a later match that is not the greatest `getSatisfyingVersion` kept every matching version it walked past, so the guard that holds on to the one already found was never taken. Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * refactor(versioning): drop three guards that cannot be false - `gradle`: `tokenCmp` compares two tokens whose only types are `Number` and `String`, so once both-numbers and both-strings are handled exactly one side is a number; the chain becomes a ternary and the unreachable `return 0` goes - `ivy`: `tokenize` always yields at least one token for a non-empty version, so the length check around the last one always holds - `ivy`: `rangeToStr` only returns null for a null range, which the `length === 1` check above it already rules out Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * test(versioning/nuget): cover a later match that is not the greatest Both loops in `getSatisfyingVersion` walked version lists that only ever climbed, so the guard that holds on to the candidate already found was never taken -- once for a bracket range, once for a bare version acting as a minimum. Also pin down that a floating range needs a major component: `-*` alone does not parse. Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * refactor(versioning): drop three more guards that cannot be false - `maven`: the interval picked for auto-extension is only picked when the new value is at or past its upper bound, and that upper bound is the lower one incremented, so the new value never sorts below the lower bound - `maven`: an interval never has both bounds open, because the parser only nulls one side when the other is a version - `nuget`: a floating range always carries a major component, so neither the parser's NaN check nor the serializer's undefined check can fail Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * refactor(versioning/pep440): drop three unreachable range paths `updateRangeValue` handles `!=`, a `.*` prefix, `~=`, `==` and `<=` itself, `handleUpperBound` handles `<`, and `parseCurrentRange` rejects `===`. Only `>` and `>=` can reach `handleLowerBound`, so its operator check always holds and it never returns null. Making it total removes the null check at the call site as well. This does drop the `logger.error` that followed, which was guarded by a comment saying it could not happen unless pep440 itself changed. `isLessThanRange` classifies the same fixed operator set, so the last check there is the only one left and its fallback was dead. `divideCompatibleReleaseRange` only ever sees a `~=` version, and pep440 requires at least two release components after that operator, so there is always a component to drop. A new test pins down that `~=7` is not a valid range. Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * test(versioning): cover three more uncovered guards - `elm`: a widen where the new version sits below the lower bound, so the upper bound is kept rather than extended - `hex`: a widen on a complex range ending in `>=`, which the underlying semver implementation refuses and returns null for - `rust-release-channel`: a concrete current version paired with a channel name as the new version, which falls through to the new version unchanged Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * refactor(versioning): drop two more guards that cannot be false - `composer`: `getNewValue` falls back to the new version whenever nothing else matched, so it never returns null and the recursive call in the or-range path always has a value to work with - `docker`: a version's prerelease is always a string, so once an empty one on either side is handled, the remaining pair is both non-empty and unequal Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * test(config,datasource): cover two more uncovered guards - `config/validation`: `hostRules[].allowInternal` nested inside a `packageRules[]` entry, which reports a plain configuration error rather than a security one, because nested host rules are never applied - `datasource/docker`: a non-list manifest whose response carries no `docker-content-digest` header, so the digest falls back to the hash of the manifest body Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * refactor(config,datasource): unwind three branches v8 could not count - `config/decrypt` and `datasource/docker/common` each picked a response with an `await` inside a ternary. v8 gives the branch that follows such a ternary a negative hit count, which the reporters read as uncovered even though both paths run. Spelling the choice as an if/else makes the count come out right; behaviour is unchanged. - `datasource/index` and `datasource/npm/npmrc` each ended an exhaustive chain with an `else if` whose implicit else v8 counts but nothing can reach: `registryStrategy` is one of three literals, and `npmrc` starts as an object and is only ever reassigned to one. Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * test(workers/global): cover seven uncovered guards The config parsers rewrite legacy boolean spellings of `dryRun`, `requireConfig` and `platformCommit`, but nothing passed a value that was already current, so the fall-through of each chain went untaken. Cover it from both the CLI and the environment. Also cover a datasource env var that names no auth field, one whose value is undefined, a default config file that cannot be read, and the error `isLimitReached` throws when asked for a concurrent limit without a branch config. That last one had an ignore hint saying it should not happen; the error message documents the contract, so it is now tested and the hint is gone. Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * refactor(workers/global): drop a guard that cannot be false `getConfig` in the additional-config-file parser returns early unless `RENOVATE_ADDITIONAL_CONFIG_FILE` is set, so by the time a parse error is being classified the variable is always present. Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * refactor(workers/repository): drop a dead changelog file lookup The gitea, gitlab and forgejo changelog sources each declared `files` as an empty array and then guarded the only assignment to it with `if (!files.length)`, which is always true one line after the declaration. Collapse it to the filter itself. Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * ci: ratchet the branch coverage threshold A full run on this branch reports 100% statements (49471/49471), 100% functions (7381/7381), 100% lines (48961/48961) and 99.73% branches (25690/25759), up from 99.53% before this branch's work. The threshold moves to 99.71, keeping the same rounding-down margin as before. Statements, functions and lines are already pinned at 100 and stay there. Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * refactor(config,datasource): say why the ternary was unwound Both sites now carry a comment explaining that the if/else is deliberate: v8 gives the branch following an `await` inside a ternary a negative hit count, which the coverage reporters read as uncovered. `apiCheckResponse` also gets an explicit `HttpResponse<unknown>` type, which is what the two branches have in common and what `isECRMaxResultsResponse` already expects. Also fix a type error in the new config file spec: the `pathExists` spy needs the same `as never` cast the surrounding tests use. Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * refactor(versioning/pep440): use a template literal in handleLowerBound The exclude-style return is the one line this branch rewrote in that function, so it now builds its string with a template literal instead of the `+` operator. Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> * test(workers/global): drop the cast from the limits throw test Calling the overload with a non-null assertion on the config argument says the same thing without retyping the whole function. Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io> --------- Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io>
482 lines
14 KiB
TypeScript
482 lines
14 KiB
TypeScript
import { logger, partial } from '~test/util.ts';
|
|
import type { BranchConfig, BranchUpgradeConfig } from '../types.ts';
|
|
import {
|
|
calcLimit,
|
|
hasMultipleLimits,
|
|
incCountValue,
|
|
incLimitedValue,
|
|
isLimitReached,
|
|
resetAllLimits,
|
|
setCount,
|
|
setMaxLimit,
|
|
} from './limits.ts';
|
|
|
|
describe('workers/global/limits', () => {
|
|
beforeEach(() => {
|
|
resetAllLimits();
|
|
});
|
|
|
|
beforeEach(() => {
|
|
resetAllLimits();
|
|
});
|
|
|
|
it('increments limited value', () => {
|
|
setMaxLimit('Commits', 3);
|
|
|
|
expect(isLimitReached('Commits')).toBeFalse();
|
|
|
|
incLimitedValue('Commits', 2);
|
|
expect(isLimitReached('Commits')).toBeFalse();
|
|
|
|
incLimitedValue('Commits');
|
|
expect(isLimitReached('Commits')).toBeTrue();
|
|
|
|
incLimitedValue('Commits');
|
|
expect(isLimitReached('Commits')).toBeTrue();
|
|
});
|
|
|
|
it('defaults to unlimited', () => {
|
|
expect(isLimitReached('Commits')).toBeFalse();
|
|
});
|
|
|
|
it('increments undefined', () => {
|
|
incLimitedValue('Commits');
|
|
expect(isLimitReached('Commits')).toBeFalse();
|
|
});
|
|
|
|
it('resets counter', () => {
|
|
setMaxLimit('Commits', 1);
|
|
incLimitedValue('Commits');
|
|
expect(isLimitReached('Commits')).toBeTrue();
|
|
setMaxLimit('Commits', 1);
|
|
expect(isLimitReached('Commits')).toBeFalse();
|
|
});
|
|
|
|
it('resets limit', () => {
|
|
setMaxLimit('Commits', 1);
|
|
incLimitedValue('Commits');
|
|
expect(isLimitReached('Commits')).toBeTrue();
|
|
setMaxLimit('Commits', null);
|
|
expect(isLimitReached('Commits')).toBeFalse();
|
|
});
|
|
|
|
it('sets non-positive limit as reached', () => {
|
|
setMaxLimit('Commits', 0);
|
|
expect(isLimitReached('Commits')).toBeTrue();
|
|
setMaxLimit('Commits', -1000);
|
|
expect(isLimitReached('Commits')).toBeTrue();
|
|
});
|
|
|
|
it('throws when a concurrent limit is asked for without a branch config', () => {
|
|
expect(() => isLimitReached('Branches', undefined!)).toThrow(
|
|
'Config is required for computing limits for Branches and PullRequests',
|
|
);
|
|
});
|
|
|
|
describe('calcLimit', () => {
|
|
it('handles single upgrade', () => {
|
|
const upgrades = partial<BranchUpgradeConfig>([
|
|
{
|
|
prHourlyLimit: 10,
|
|
branchConcurrentLimit: 11,
|
|
prConcurrentLimit: 12,
|
|
},
|
|
]);
|
|
|
|
expect(calcLimit(upgrades, 'prHourlyLimit')).toBe(10);
|
|
expect(calcLimit(upgrades, 'branchConcurrentLimit')).toBe(11);
|
|
expect(calcLimit(upgrades, 'prConcurrentLimit')).toBe(12);
|
|
});
|
|
|
|
it('inherits prConcurrentLimit if branchConcurrentLimit is null', () => {
|
|
const upgrades = partial<BranchUpgradeConfig>([
|
|
{
|
|
prHourlyLimit: 10,
|
|
branchConcurrentLimit: null,
|
|
prConcurrentLimit: 12,
|
|
},
|
|
]);
|
|
|
|
expect(calcLimit(upgrades, 'prHourlyLimit')).toBe(10);
|
|
expect(calcLimit(upgrades, 'branchConcurrentLimit')).toBe(12);
|
|
expect(calcLimit(upgrades, 'prConcurrentLimit')).toBe(12);
|
|
});
|
|
|
|
it('returns 0 if at least one upgrade has no limit in the branch', () => {
|
|
const upgrades = partial<BranchUpgradeConfig>([
|
|
{
|
|
prHourlyLimit: 10,
|
|
branchConcurrentLimit: 11,
|
|
prConcurrentLimit: 12,
|
|
},
|
|
{
|
|
prHourlyLimit: 0,
|
|
branchConcurrentLimit: 0,
|
|
prConcurrentLimit: 0,
|
|
},
|
|
{
|
|
prHourlyLimit: 1,
|
|
branchConcurrentLimit: 1,
|
|
prConcurrentLimit: 1,
|
|
},
|
|
]);
|
|
|
|
expect(calcLimit(upgrades, 'prHourlyLimit')).toBe(0);
|
|
expect(calcLimit(upgrades, 'branchConcurrentLimit')).toBe(0);
|
|
expect(calcLimit(upgrades, 'prConcurrentLimit')).toBe(0);
|
|
});
|
|
|
|
it('computes the lowest limit if multiple limits are present', () => {
|
|
const upgrades = partial<BranchUpgradeConfig>([
|
|
{
|
|
commitHourlyLimit: 5,
|
|
prHourlyLimit: 10,
|
|
branchConcurrentLimit: 11,
|
|
prConcurrentLimit: 12,
|
|
},
|
|
{
|
|
prHourlyLimit: 10,
|
|
branchConcurrentLimit: 11,
|
|
prConcurrentLimit: 12,
|
|
},
|
|
{
|
|
commitHourlyLimit: 3,
|
|
prHourlyLimit: 1,
|
|
branchConcurrentLimit: 1,
|
|
prConcurrentLimit: 1,
|
|
},
|
|
{
|
|
prHourlyLimit: 5,
|
|
branchConcurrentLimit: 6,
|
|
prConcurrentLimit: 3,
|
|
},
|
|
{
|
|
prHourlyLimit: 5,
|
|
branchConcurrentLimit: null,
|
|
prConcurrentLimit: undefined,
|
|
},
|
|
{
|
|
prHourlyLimit: 5,
|
|
branchConcurrentLimit: 6,
|
|
prConcurrentLimit: 2,
|
|
},
|
|
]);
|
|
|
|
expect(calcLimit(upgrades, 'commitHourlyLimit')).toBe(3);
|
|
expect(calcLimit(upgrades, 'prHourlyLimit')).toBe(1);
|
|
expect(calcLimit(upgrades, 'branchConcurrentLimit')).toBe(1);
|
|
expect(calcLimit(upgrades, 'prConcurrentLimit')).toBe(1);
|
|
});
|
|
|
|
it('de-duplicates upgrades by depName from debug log', () => {
|
|
const upgrades = partial<BranchUpgradeConfig>([
|
|
{
|
|
depName: 'depA',
|
|
prHourlyLimit: 10,
|
|
},
|
|
{
|
|
depName: 'depA',
|
|
prHourlyLimit: 10,
|
|
},
|
|
{
|
|
depName: 'depB',
|
|
prHourlyLimit: 1,
|
|
},
|
|
]);
|
|
|
|
expect(calcLimit(upgrades, 'prHourlyLimit')).toBe(1);
|
|
expect(logger.logger.debug).toHaveBeenCalledWith(
|
|
{
|
|
limits: [
|
|
{ depName: 'depA', prHourlyLimit: 10 },
|
|
{ depName: 'depB', prHourlyLimit: 1 },
|
|
],
|
|
},
|
|
'prHourlyLimit of the upgrades present in this branch',
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('hasMultipleLimits', () => {
|
|
it('handles single limit', () => {
|
|
const upgrades = partial<BranchUpgradeConfig>([
|
|
{
|
|
prHourlyLimit: 10,
|
|
branchConcurrentLimit: 11,
|
|
prConcurrentLimit: 12,
|
|
},
|
|
]);
|
|
expect(hasMultipleLimits(upgrades, 'prHourlyLimit')).toBe(false);
|
|
expect(hasMultipleLimits(upgrades, 'branchConcurrentLimit')).toBe(false);
|
|
expect(hasMultipleLimits(upgrades, 'prConcurrentLimit')).toBe(false);
|
|
});
|
|
|
|
it('returns false if there are multiple limits with value', () => {
|
|
const upgrades = partial<BranchUpgradeConfig>([
|
|
{
|
|
prHourlyLimit: 10,
|
|
branchConcurrentLimit: 11,
|
|
prConcurrentLimit: 12,
|
|
},
|
|
{
|
|
prHourlyLimit: 10,
|
|
branchConcurrentLimit: 11,
|
|
prConcurrentLimit: 12,
|
|
},
|
|
]);
|
|
expect(hasMultipleLimits(upgrades, 'prHourlyLimit')).toBe(false);
|
|
expect(hasMultipleLimits(upgrades, 'branchConcurrentLimit')).toBe(false);
|
|
expect(hasMultipleLimits(upgrades, 'prConcurrentLimit')).toBe(false);
|
|
});
|
|
|
|
it('handles multiple limits', () => {
|
|
const upgrades = partial<BranchUpgradeConfig>([
|
|
{
|
|
prHourlyLimit: 10,
|
|
branchConcurrentLimit: 11,
|
|
prConcurrentLimit: 12,
|
|
},
|
|
{
|
|
prHourlyLimit: 11,
|
|
branchConcurrentLimit: 12,
|
|
prConcurrentLimit: 13,
|
|
},
|
|
{
|
|
prHourlyLimit: 0,
|
|
branchConcurrentLimit: null,
|
|
prConcurrentLimit: 3,
|
|
},
|
|
]);
|
|
expect(hasMultipleLimits(upgrades, 'prHourlyLimit')).toBe(true);
|
|
expect(hasMultipleLimits(upgrades, 'branchConcurrentLimit')).toBe(true);
|
|
expect(hasMultipleLimits(upgrades, 'prConcurrentLimit')).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('isLimitReached', () => {
|
|
it('counts vulnerability alerts against their own budget', () => {
|
|
setCount('ConcurrentPRs', 5);
|
|
setCount('Branches', 5);
|
|
setCount('VulnerabilityConcurrentPRs', 1);
|
|
setCount('VulnerabilityBranches', 1);
|
|
const upgrades = partial<BranchUpgradeConfig>([
|
|
{ prConcurrentLimit: 5, branchConcurrentLimit: 5 },
|
|
]);
|
|
|
|
// the repository-wide budget is spent, but the vulnerability one is not
|
|
expect(
|
|
isLimitReached('ConcurrentPRs', partial<BranchConfig>({ upgrades })),
|
|
).toBe(true);
|
|
expect(
|
|
isLimitReached(
|
|
'ConcurrentPRs',
|
|
partial<BranchConfig>({ upgrades, isVulnerabilityAlert: true }),
|
|
),
|
|
).toBe(false);
|
|
expect(
|
|
isLimitReached('Branches', partial<BranchConfig>({ upgrades })),
|
|
).toBe(true);
|
|
expect(
|
|
isLimitReached(
|
|
'Branches',
|
|
partial<BranchConfig>({ upgrades, isVulnerabilityAlert: true }),
|
|
),
|
|
).toBe(false);
|
|
});
|
|
|
|
it('applies vulnerabilityAlerts.branchConcurrentLimit to vulnerability branches', () => {
|
|
setCount('VulnerabilityBranches', 2);
|
|
setCount('VulnerabilityConcurrentPRs', 2);
|
|
// a lower branchConcurrentLimit blocks branches while PRs are still allowed
|
|
const upgrades = partial<BranchUpgradeConfig>([
|
|
{ branchConcurrentLimit: 2, prConcurrentLimit: 10 },
|
|
]);
|
|
const config = partial<BranchConfig>({
|
|
upgrades,
|
|
isVulnerabilityAlert: true,
|
|
});
|
|
|
|
expect(isLimitReached('Branches', config)).toBe(true);
|
|
expect(isLimitReached('ConcurrentPRs', config)).toBe(false);
|
|
});
|
|
|
|
it('inherits vulnerabilityAlerts.prConcurrentLimit when branchConcurrentLimit is null', () => {
|
|
const upgrades = partial<BranchUpgradeConfig>([
|
|
{ branchConcurrentLimit: null, prConcurrentLimit: 3 },
|
|
]);
|
|
const config = partial<BranchConfig>({
|
|
upgrades,
|
|
isVulnerabilityAlert: true,
|
|
});
|
|
|
|
setCount('VulnerabilityBranches', 2);
|
|
expect(isLimitReached('Branches', config)).toBe(false);
|
|
|
|
setCount('VulnerabilityBranches', 3);
|
|
expect(isLimitReached('Branches', config)).toBe(true);
|
|
});
|
|
|
|
it('applies the vulnerability budget once it is spent', () => {
|
|
setCount('VulnerabilityConcurrentPRs', 5);
|
|
const upgrades = partial<BranchUpgradeConfig>([{ prConcurrentLimit: 5 }]);
|
|
|
|
expect(
|
|
isLimitReached(
|
|
'ConcurrentPRs',
|
|
partial<BranchConfig>({ upgrades, isVulnerabilityAlert: true }),
|
|
),
|
|
).toBe(true);
|
|
});
|
|
|
|
it('ignores the hourly PR limit for vulnerability alerts', () => {
|
|
setCount('HourlyPRs', 5);
|
|
const upgrades = partial<BranchUpgradeConfig>([
|
|
{ prHourlyLimit: 2, prConcurrentLimit: 0 },
|
|
]);
|
|
|
|
expect(
|
|
isLimitReached('ConcurrentPRs', partial<BranchConfig>({ upgrades })),
|
|
).toBe(true);
|
|
expect(
|
|
isLimitReached(
|
|
'ConcurrentPRs',
|
|
partial<BranchConfig>({ upgrades, isVulnerabilityAlert: true }),
|
|
),
|
|
).toBe(false);
|
|
});
|
|
|
|
it('returns false based on concurrent limits', () => {
|
|
setCount('ConcurrentPRs', 1);
|
|
setCount('HourlyPRs', 1);
|
|
incCountValue('Branches'); // using incCountValue so it gets test coverage
|
|
const upgrades = partial<BranchUpgradeConfig>([
|
|
{
|
|
prHourlyLimit: 10,
|
|
branchConcurrentLimit: 11,
|
|
prConcurrentLimit: 12,
|
|
},
|
|
{
|
|
prHourlyLimit: 11,
|
|
branchConcurrentLimit: 12,
|
|
prConcurrentLimit: 13,
|
|
},
|
|
{
|
|
prHourlyLimit: 0,
|
|
branchConcurrentLimit: null,
|
|
prConcurrentLimit: 3,
|
|
},
|
|
]);
|
|
expect(
|
|
isLimitReached('Branches', partial<BranchConfig>({ upgrades })),
|
|
).toBe(false);
|
|
expect(
|
|
isLimitReached('ConcurrentPRs', partial<BranchConfig>({ upgrades })),
|
|
).toBe(false);
|
|
});
|
|
|
|
it('returns true when pr hourly limit is reached', () => {
|
|
setCount('Branches', 2);
|
|
setCount('ConcurrentPRs', 2);
|
|
setCount('HourlyPRs', 2);
|
|
const upgrades = partial<BranchUpgradeConfig>([
|
|
{
|
|
prHourlyLimit: 10,
|
|
branchConcurrentLimit: 11,
|
|
prConcurrentLimit: 12,
|
|
},
|
|
{
|
|
prHourlyLimit: 11,
|
|
branchConcurrentLimit: 12,
|
|
prConcurrentLimit: 13,
|
|
},
|
|
{
|
|
prHourlyLimit: 2,
|
|
branchConcurrentLimit: null,
|
|
prConcurrentLimit: 3,
|
|
},
|
|
]);
|
|
expect(
|
|
isLimitReached('Branches', partial<BranchConfig>({ upgrades })),
|
|
).toBe(true);
|
|
expect(
|
|
isLimitReached('ConcurrentPRs', partial<BranchConfig>({ upgrades })),
|
|
).toBe(true);
|
|
});
|
|
|
|
it('returns true when concurrent limit is reached', () => {
|
|
setCount('Branches', 3);
|
|
setCount('ConcurrentPRs', 3);
|
|
setCount('HourlyPRs', 4);
|
|
const upgrades = partial<BranchUpgradeConfig>([
|
|
{
|
|
prHourlyLimit: 10,
|
|
branchConcurrentLimit: 11,
|
|
prConcurrentLimit: 12,
|
|
},
|
|
{
|
|
prHourlyLimit: 11,
|
|
branchConcurrentLimit: 12,
|
|
prConcurrentLimit: 13,
|
|
},
|
|
{
|
|
prHourlyLimit: 5,
|
|
branchConcurrentLimit: null,
|
|
prConcurrentLimit: 3,
|
|
},
|
|
]);
|
|
expect(
|
|
isLimitReached('Branches', partial<BranchConfig>({ upgrades })),
|
|
).toBe(true);
|
|
expect(
|
|
isLimitReached('ConcurrentPRs', partial<BranchConfig>({ upgrades })),
|
|
).toBe(true);
|
|
});
|
|
|
|
it('commit hourly limit only affects HourlyCommits check', () => {
|
|
setCount('HourlyCommits', 3);
|
|
const upgrades = partial<BranchUpgradeConfig>([
|
|
{
|
|
commitHourlyLimit: 3,
|
|
},
|
|
]);
|
|
// Commit hourly limit should block HourlyCommits when reached
|
|
expect(
|
|
isLimitReached('HourlyCommits', partial<BranchConfig>({ upgrades })),
|
|
).toBe(true);
|
|
// Should NOT block when limit is not reached
|
|
setCount('HourlyCommits', 2);
|
|
expect(
|
|
isLimitReached('HourlyCommits', partial<BranchConfig>({ upgrades })),
|
|
).toBe(false);
|
|
// Should be unlimited when set to 0
|
|
setCount('HourlyCommits', 100);
|
|
upgrades[0].commitHourlyLimit = 0;
|
|
expect(
|
|
isLimitReached('HourlyCommits', partial<BranchConfig>({ upgrades })),
|
|
).toBe(false);
|
|
});
|
|
|
|
it('commit hourly limit does not block branch or PR checks', () => {
|
|
setCount('Branches', 0);
|
|
setCount('ConcurrentPRs', 1);
|
|
setCount('HourlyCommits', 10); // Commit limit reached
|
|
setCount('HourlyPRs', 0);
|
|
const upgrades = partial<BranchUpgradeConfig>([
|
|
{
|
|
commitHourlyLimit: 2, // Limit reached
|
|
prHourlyLimit: 10, // Limit not reached
|
|
branchConcurrentLimit: 10,
|
|
prConcurrentLimit: 0, // Unlimited
|
|
},
|
|
]);
|
|
// Should NOT block branch or PR creation checks
|
|
expect(
|
|
isLimitReached('Branches', partial<BranchConfig>({ upgrades })),
|
|
).toBe(false);
|
|
expect(
|
|
isLimitReached('ConcurrentPRs', partial<BranchConfig>({ upgrades })),
|
|
).toBe(false);
|
|
});
|
|
});
|
|
});
|