@@ -107,18 +107,88 @@ func TestDownloadHotfix_NoHotfixFile(t *testing.T) {
107107
108108func TestDownloadHotfix_VersionMatch (t * testing.T ) {
109109 origVersion := Version
110- Version = "202603.30.0-hotfix1 "
110+ Version = "202604.01.1 "
111111 defer func () { Version = origVersion }()
112112
113113 dir := t .TempDir ()
114114 path := filepath .Join (dir , "hotfix-config.json" )
115- require .NoError (t , os .WriteFile (path , []byte (`{"version": "202603.30.0-hotfix1 "}` ), 0o644 ))
115+ require .NoError (t , os .WriteFile (path , []byte (`{"version": "202604.01.1 "}` ), 0o644 ))
116116
117117 tt := NewTestApp (t , TestAppConfig {})
118118 tt .App .hotfixVersionPath = path
119119 require .NoError (t , tt .App .downloadHotfix (context .Background ()))
120120}
121121
122+ func TestDownloadHotfix_DifferentBaseSkips (t * testing.T ) {
123+ origVersion := Version
124+ Version = "202605.01.0"
125+ defer func () { Version = origVersion }()
126+
127+ dir := t .TempDir ()
128+ path := filepath .Join (dir , "hotfix-config.json" )
129+ require .NoError (t , os .WriteFile (path , []byte (`{"version": "202604.01.1"}` ), 0o644 ))
130+
131+ installCalled := false
132+ tt := NewTestApp (t , TestAppConfig {
133+ RunFunc : func (cmd * exec.Cmd ) error {
134+ installCalled = true
135+ return nil
136+ },
137+ })
138+ tt .App .hotfixVersionPath = path
139+ require .NoError (t , tt .App .downloadHotfix (context .Background ()))
140+ assert .False (t , installCalled , "should skip when version base doesn't match" )
141+ }
142+
143+ func TestDownloadHotfix_DevVersionSkips (t * testing.T ) {
144+ origVersion := Version
145+ Version = "dev"
146+ defer func () { Version = origVersion }()
147+
148+ dir := t .TempDir ()
149+ path := filepath .Join (dir , "hotfix-config.json" )
150+ require .NoError (t , os .WriteFile (path , []byte (`{"version": "202604.01.1"}` ), 0o644 ))
151+
152+ installCalled := false
153+ tt := NewTestApp (t , TestAppConfig {
154+ RunFunc : func (cmd * exec.Cmd ) error {
155+ installCalled = true
156+ return nil
157+ },
158+ })
159+ tt .App .hotfixVersionPath = path
160+ require .NoError (t , tt .App .downloadHotfix (context .Background ()))
161+ assert .False (t , installCalled , "should skip when Version is 'dev' (parse error)" )
162+ }
163+
164+ func TestDownloadHotfix_MatchingBaseUpgrades (t * testing.T ) {
165+ origVersion := Version
166+ Version = "202604.01.0"
167+ defer func () { Version = origVersion }()
168+
169+ dir := t .TempDir ()
170+ path := filepath .Join (dir , "hotfix-config.json" )
171+ require .NoError (t , os .WriteFile (path , []byte (`{"version": "202604.01.1"}` ), 0o644 ))
172+
173+ aptDir := filepath .Join (dir , "sources.list.d" )
174+ require .NoError (t , os .MkdirAll (aptDir , 0755 ))
175+ require .NoError (t , os .WriteFile (filepath .Join (aptDir , "microsoft-prod.list" ), []byte ("deb ..." ), 0o644 ))
176+
177+ installCalled := false
178+ tt := NewTestApp (t , TestAppConfig {
179+ RunFunc : func (cmd * exec.Cmd ) error {
180+ installCalled = true
181+ return nil
182+ },
183+ })
184+ tt .App .hotfixVersionPath = path
185+ tt .App .aptSourcesDir = aptDir
186+ // Will fail at copyBinaryAlongside since pkgBinaryPath doesn't exist in test,
187+ // but install should have been called.
188+ _ = tt .App .downloadHotfix (context .Background ())
189+ assert .True (t , installCalled , "should proceed when base matches and hotfix patch is higher" )
190+ }
191+
122192func TestDownloadHotfix_UnreadableFile (t * testing.T ) {
123193 dir := t .TempDir ()
124194 path := filepath .Join (dir , "hotfix-config.json" )
@@ -254,3 +324,52 @@ func TestCopyBinaryAlongside(t *testing.T) {
254324 }
255325 })
256326}
327+
328+ func TestShouldUpgradeToHotfix (t * testing.T ) {
329+ tests := []struct {
330+ name string
331+ current string
332+ hotfix string
333+ want bool
334+ wantErr bool
335+ }{
336+ // Positive: same base, hotfix has higher patch
337+ {"base .0 → hotfix .1" , "202604.01.0" , "202604.01.1" , true , false },
338+ {"base .0 → hotfix .2" , "202604.01.0" , "202604.01.2" , true , false },
339+ {"hotfix .1 → hotfix .2" , "202604.01.1" , "202604.01.2" , true , false },
340+
341+ // Negative: same version
342+ {"same version .0" , "202604.01.0" , "202604.01.0" , false , false },
343+ {"same version .1" , "202604.01.1" , "202604.01.1" , false , false },
344+
345+ // Negative: different base (different YYYYMM)
346+ {"different month" , "202603.15.0" , "202604.01.1" , false , false },
347+ {"newer month" , "202605.01.0" , "202604.01.1" , false , false },
348+
349+ // Negative: different base (different DD)
350+ {"different day" , "202604.15.0" , "202604.01.1" , false , false },
351+
352+ // Negative: current patch higher than hotfix
353+ {"current patch higher" , "202604.01.2" , "202604.01.1" , false , false },
354+
355+ // Error cases
356+ {"dev current" , "dev" , "202604.01.1" , false , true },
357+ {"dev hotfix" , "202604.01.0" , "dev" , false , true },
358+ {"both dev" , "dev" , "dev" , false , true },
359+ {"empty current" , "" , "202604.01.1" , false , true },
360+ {"empty hotfix" , "202604.01.0" , "" , false , true },
361+
362+
363+ }
364+ for _ , tc := range tests {
365+ t .Run (tc .name , func (t * testing.T ) {
366+ got , err := shouldUpgradeToHotfix (tc .current , tc .hotfix )
367+ if tc .wantErr {
368+ assert .Error (t , err )
369+ } else {
370+ require .NoError (t , err )
371+ assert .Equal (t , tc .want , got , "current=%s hotfix=%s" , tc .current , tc .hotfix )
372+ }
373+ })
374+ }
375+ }
0 commit comments