improve comments

This commit is contained in:
Francesco Sansalvadore authored and GitHub committed 2026-10-07 16:38:40 +02:00
1 parent ebde4234c9
commit a3a8f5b87c
2 files changed
+6 -22

No files matched your search

@@ -51,10 +51,8 @@ describe('computeVersionFate', () => {
})
it('ignores a cap that has no expiration age alongside it', () => {
// Not a reachable policy: S3 requires NoncurrentDays on any
// NoncurrentVersionExpiration rule, so the bucket form disables the cap until
// an age is set. Pinned here so a cap arriving alone can never be read as an
// active rule and start labelling versions for removal.
// Not a reachable policy: S3 requires NoncurrentDays
// on any NoncurrentVersionExpiration rule
const base = { expiryDays: null, cap: 3, mode: 'and' as const }
expect(computeVersionFate({ ...base, daysOld: 3, chronoIndex: 2, noncurrentCount: 3 })).toEqual(
@@ -62,7 +60,7 @@ describe('computeVersionFate', () => {
type: 'retained',
}
)
// Would have been the cap boundary — still nothing to promise.
expect(
computeVersionFate({ ...base, daysOld: 216, chronoIndex: 0, noncurrentCount: 3 })
).toEqual({ type: 'retained' })
@@ -3,20 +3,12 @@ import type { ExpirationMode } from '../StorageVersioning.constants'
export type VersionFate =
| { type: 'retained' }
| { type: 'expires-in'; days: number }
/**
* The cap forces this one out before its age would, so the exact date depends
* on when the next upload happens. `daysRemaining` is the date it would have
* hit anyway had the cap not got there first.
*/
| { type: 'expires-on-next-upload'; daysRemaining: number }
| { type: 'expiring-now' }
export interface ComputeVersionFateOptions {
/** Days since this version became noncurrent. */
daysOld: number
/** 0-based position among noncurrent versions, oldest first. */
chronoIndex: number
/** Total number of noncurrent versions the object currently has. */
noncurrentCount: number
expiryDays: number | null
cap: number | null
@@ -27,12 +19,9 @@ export interface ComputeVersionFateOptions {
const toActiveBound = (value: number | null) => (value !== null && value > 0 ? value : null)
/**
* The removal-outlook label a version row shows. Governing rule: never show a
* countdown unless removal is actually guaranteed under the current policy — a
* row only gets a day count once every other condition is already satisfied. So
* Never show a countdown unless removal is actually guaranteed under the current policy —
* a row only gets a day count once every other condition is already satisfied. So
* an `and` policy shows one only once the cap is already exceeded.
*
* Each branch has a worked reference case in `VersionHistory.utils.test.ts`.
*/
export const computeVersionFate = ({
daysOld,
@@ -45,9 +34,7 @@ export const computeVersionFate = ({
const activeExpiryDays = toActiveBound(expiryDays)
const activeCap = toActiveBound(cap)
// A cap with no age isn't expressible in S3 — NoncurrentDays is required on any
// NoncurrentVersionExpiration rule, which is why the bucket form disables the
// cap until an age is set. So no age means no policy, whatever the cap says.
// A cap with no age isn't expressible in S3 — NoncurrentDays is required
if (activeExpiryDays === null) return { type: 'retained' }
const isAgeExceeded = daysOld >= activeExpiryDays
@@ -57,7 +44,6 @@ export const computeVersionFate = ({
return isAgeExceeded ? { type: 'expiring-now' } : { type: 'expires-in', days: daysRemaining }
}
// Already beyond the cap: among the oldest `noncurrentCount - cap` versions.
const isCapExceeded = chronoIndex < noncurrentCount - activeCap
const isAtCapBoundary = chronoIndex === noncurrentCount - activeCap