Skip to content

Commit ae581e9

Browse files
committed
fix: harden rebalance and decommission state
1 parent aa47d8a commit ae581e9

3 files changed

Lines changed: 21 additions & 11 deletions

File tree

lib/pool-operations.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,18 @@ function hasExplicitProgressPercent(record: JsonRecord): boolean {
205205

206206
function deriveRebalanceProgressPercent(status: string, pools: PoolSummary[]): number {
207207
const state = normalizeState(status)
208-
if (["completed", "complete", "success", "finished"].includes(state) && pools.every(isCompletedRebalancePool)) {
208+
const rebalancePools = participatingRebalancePools(pools)
209+
if (
210+
["completed", "complete", "success", "finished"].includes(state) &&
211+
rebalancePools.length > 0 &&
212+
rebalancePools.every(isCompletedRebalancePool)
213+
) {
209214
return 100
210215
}
211-
if (pools.length === 0) return 0
216+
if (rebalancePools.length === 0) return 0
212217

213-
const finishedPools = pools.filter(isCompletedRebalancePool).length
214-
return Math.round((finishedPools / pools.length) * 100)
218+
const finishedPools = rebalancePools.filter(isCompletedRebalancePool).length
219+
return Math.round((finishedPools / rebalancePools.length) * 100)
215220
}
216221

217222
function pickStatus(record: JsonRecord): string {
@@ -357,6 +362,10 @@ function isCompletedRebalancePool(pool: PoolSummary): boolean {
357362
return ["completed", "complete", "success", "finished"].includes(normalizeState(pool.status))
358363
}
359364

365+
function participatingRebalancePools(pools: PoolSummary[]): PoolSummary[] {
366+
return pools.filter((pool) => !isIdleRebalancePool(pool) || hasProgress(pool.progress))
367+
}
368+
360369
function deriveStatusFromPools(pools: PoolSummary[]): string {
361370
if (pools.length === 0) return ""
362371

@@ -370,7 +379,8 @@ function deriveStatusFromPools(pools: PoolSummary[]): string {
370379
) {
371380
return "running"
372381
}
373-
if (pools.every(isCompletedRebalancePool)) {
382+
const rebalancePools = participatingRebalancePools(pools)
383+
if (rebalancePools.length > 0 && rebalancePools.every(isCompletedRebalancePool)) {
374384
return "completed"
375385
}
376386
if (pools.some(isCompletedRebalancePool) && pools.some(isIdleRebalancePool)) return "running"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
},
7373
"packageManager": {
7474
"name": "pnpm",
75-
"version": "^11.4.0",
75+
"version": "11.5.0",
7676
"onFail": "error"
7777
}
7878
}

tests/lib/pool-operations.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ test("normalizeRebalanceStatus reads progress and pool details", () => {
139139
assert.equal(status.pools[0]?.cleanupWarnings.lastBucket, "test-bucket")
140140
})
141141

142-
test("normalizeRebalanceStatus does not complete mixed completed and idle pools", () => {
142+
test("normalizeRebalanceStatus completes mixed completed and non-participating pools", () => {
143143
const status = normalizeRebalanceStatus({
144144
id: "3be0831f-4315-4adb-9904-3bb0609b3bfc",
145145
pools: [
@@ -170,11 +170,11 @@ test("normalizeRebalanceStatus does not complete mixed completed and idle pools"
170170
stoppedAt: null,
171171
})
172172

173-
assert.equal(status.status, "running")
174-
assert.equal(status.progressPercent, 50)
173+
assert.equal(status.status, "completed")
174+
assert.equal(status.progressPercent, 100)
175175
assert.equal(status.pools[0]?.status, "Completed")
176176
assert.equal(status.pools[1]?.status, "None")
177-
assert.equal(deriveRebalanceDisplayState(status, "supported"), "running")
177+
assert.equal(deriveRebalanceDisplayState(status, "supported"), "completed")
178178
})
179179

180180
test("normalizeRebalanceStatus aggregates pool progress when totals are missing", () => {
@@ -248,7 +248,7 @@ test("normalizeRebalanceStatus does not infer full progress from aggregated byte
248248
})
249249

250250
assert.equal(status.status, "failed")
251-
assert.equal(status.progressPercent, 33)
251+
assert.equal(status.progressPercent, 50)
252252
})
253253

254254
test("normalizeDecommissionInfo reads nested response", () => {

0 commit comments

Comments
 (0)