From 8ec3ba5408309de4e00c798408515ba4814df25e Mon Sep 17 00:00:00 2001 From: Ken Bannister Date: Fri, 13 Dec 2024 11:23:38 -0500 Subject: [PATCH] Eliminate '.dev' in version comparison for takeover action This variant may be appended by balena-proxy. Change-type: patch Signed-off-by: Ken Bannister --- lib/index.ts | 5 ++++- tests/01-actions.spec.ts | 44 ++++++++++++++++++++++++---------------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index 296b779..50f98db 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -179,8 +179,11 @@ export class HUPActionHelper { } if (actionName === 'balenahup' && minTakeoverVersion != null) { + const noDevVersion = currentVersion.endsWith('.dev') + ? currentVersion.substring(0, currentVersion.length - 4) + : currentVersion; if ( - bSemver.lt(currentVersion, minTakeoverVersion) && + bSemver.lt(noDevVersion, minTakeoverVersion) && bSemver.gte(targetVersion, minTakeoverVersion) ) { return 'takeover'; diff --git a/tests/01-actions.spec.ts b/tests/01-actions.spec.ts index bf58256..26bd09e 100644 --- a/tests/01-actions.spec.ts +++ b/tests/01-actions.spec.ts @@ -737,27 +737,37 @@ describe('BalenaHupActionUtils', () => { before: '6.0.0', cutoff: '6.0.38', takeover: '6.0.39', + // pre-unification version for dev mode device when called by balena-proxy + takeoverDev: '6.0.39.dev', after: '6.1.0', }, - ].forEach(({ deviceType, before, cutoff, takeover, after }) => { - it(`should return 'balenahup' if doing HUP for ${deviceType} to a version before ${takeover}`, () => { - expect( - hupActionHelper.getHUPActionType(deviceType, before, cutoff), - ).to.equal('balenahup'); - }); + ].forEach( + ({ deviceType, before, cutoff, takeover, takeoverDev, after }) => { + it(`should return 'balenahup' if doing HUP for ${deviceType} to a version before ${takeover}`, () => { + expect( + hupActionHelper.getHUPActionType(deviceType, before, cutoff), + ).to.equal('balenahup'); + }); - it(`should return 'takeover' if doing HUP for ${deviceType} to a version after ${takeover}`, () => { - expect( - hupActionHelper.getHUPActionType(deviceType, before, after), - ).to.equal('takeover'); - }); + it(`should return 'takeover' if doing HUP for ${deviceType} to a version after ${takeover}`, () => { + expect( + hupActionHelper.getHUPActionType(deviceType, before, after), + ).to.equal('takeover'); + }); - it(`should return 'balenahup' if doing HUP for ${deviceType} from a version after ${takeover}`, () => { - expect( - hupActionHelper.getHUPActionType(deviceType, takeover, after), - ).to.equal('balenahup'); - }); - }); + it(`should return 'balenahup' if doing HUP for ${deviceType} from a version after ${takeover}`, () => { + expect( + hupActionHelper.getHUPActionType(deviceType, takeover, after), + ).to.equal('balenahup'); + }); + + it(`should return 'balenahup' if doing HUP for ${deviceType} from a version after ${takeover}, for a device in dev mode`, () => { + expect( + hupActionHelper.getHUPActionType(deviceType, takeoverDev, after), + ).to.equal('balenahup'); + }); + }, + ); }); }); });