Skip to content

Commit 8bf0566

Browse files
authored
Merge pull request #256 from LoopPerfect/feat/245-upgrade-by-packagelist
Feat/245 upgrade by packagelist
2 parents 54db4f3 + 8f17007 commit 8bf0566

File tree

9 files changed

+309
-115
lines changed

9 files changed

+309
-115
lines changed

buckaroo-tests/Solver.fs

Lines changed: 140 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ open FSharp.Control
66

77
open Buckaroo.Console
88
open Buckaroo.Tasks
9+
open Buckaroo.Tests
910

1011
type CookBook = List<PackageIdentifier * Set<Version> * Manifest>
1112
type LockBookEntries = List<(string*int) * List<string*int*Set<Version>>>
@@ -119,7 +120,7 @@ type TestingSourceExplorer (cookBook : CookBook, lockBook : LockBook) =
119120
}
120121

121122

122-
let solve (cookBook : CookBook) (lockBookEntries : LockBookEntries) root style =
123+
let solve (partial : Solution) (cookBook : CookBook) (lockBookEntries : LockBookEntries) root style =
123124
let lockBook = lockBookOf lockBookEntries
124125
let console = new ConsoleManager(LoggingLevel.Silent);
125126
let context : TaskContext = {
@@ -130,7 +131,8 @@ let solve (cookBook : CookBook) (lockBookEntries : LockBookEntries) root style =
130131
}
131132

132133
Buckaroo.Solver.solve
133-
context root style
134+
context partial
135+
root style
134136
(lockBook |> Map.tryFind (packageLock ("root", 0)))
135137

136138
let getLockedRev (p : string) (r: Resolution) =
@@ -164,7 +166,7 @@ let ``Solver handles simple case`` () =
164166

165167
let root = manifest [("a", Exactly (br "a") )]
166168
let solution =
167-
solve
169+
solve Solution.empty
168170
cookBook [] root
169171
ResolutionStyle.Quick
170172
|> Async.RunSynchronously
@@ -189,7 +191,8 @@ let ``Solver can backtrack to resolve simple conflicts`` () =
189191

190192
let root = manifest [("a", Exactly (br "a") )]
191193
let solution =
192-
solve cookBook [] root ResolutionStyle.Quick
194+
solve Solution.empty
195+
cookBook [] root ResolutionStyle.Quick
193196
|> Async.RunSynchronously
194197

195198
Assert.Equal ("1", getLockedRev "a" solution)
@@ -214,7 +217,9 @@ let ``Solver can compute version intersections`` () =
214217
]
215218

216219
let solution =
217-
solve spec [] root ResolutionStyle.Quick
220+
solve
221+
Solution.empty
222+
spec [] root ResolutionStyle.Quick
218223
|> Async.RunSynchronously
219224

220225
Assert.Equal ("1", getLockedRev "a" solution)
@@ -241,7 +246,8 @@ let ``Solver can compute intersection of branches`` () =
241246
]
242247

243248
let solution =
244-
solve spec [] root ResolutionStyle.Quick
249+
solve Solution.empty
250+
spec [] root ResolutionStyle.Quick
245251
|> Async.RunSynchronously
246252

247253
Assert.Equal ("3", getLockedRev "a" solution)
@@ -268,7 +274,8 @@ let ``Solver fails if package cant satisfy all constraints`` () =
268274
]
269275

270276
let solution =
271-
solve spec [] root ResolutionStyle.Quick
277+
solve Solution.empty
278+
spec [] root ResolutionStyle.Quick
272279
|> Async.RunSynchronously
273280

274281
Assert.False (isOk solution)
@@ -299,7 +306,8 @@ let ``Solver picks package that satisfies all constraints`` () =
299306
]
300307

301308
let solution =
302-
solve spec [] root ResolutionStyle.Quick
309+
solve Solution.empty
310+
spec [] root ResolutionStyle.Quick
303311
|> Async.RunSynchronously
304312

305313
Assert.Equal ("3", getLockedRev "b" solution)
@@ -327,7 +335,8 @@ let ``Solver deduces that a package can satisfy multiple constraints`` () =
327335
]
328336

329337
let solution =
330-
solve spec [] root ResolutionStyle.Quick
338+
solve Solution.empty
339+
spec [] root ResolutionStyle.Quick
331340
|> Async.RunSynchronously
332341

333342
Assert.Equal ("2", getLockedRev "b" solution)
@@ -361,7 +370,8 @@ let ``Solver handles negated constraints also`` () =
361370
]
362371

363372
let solution =
364-
solve spec [] root ResolutionStyle.Quick
373+
solve Solution.empty
374+
spec [] root ResolutionStyle.Quick
365375
|> Async.RunSynchronously
366376

367377
Assert.Equal ("4", getLockedRev "b" solution)
@@ -396,6 +406,7 @@ let ``Solver uses lockfile as hint in Quick`` () =
396406
let root = manifest [("a", Exactly (br "a") )]
397407
let solution =
398408
solve
409+
Solution.empty
399410
cookBook lockBook root
400411
ResolutionStyle.Quick
401412
|> Async.RunSynchronously
@@ -433,10 +444,129 @@ let ``Solver doesnt use lockfile as hint in Upgrade`` () =
433444
let root = manifest [("a", Exactly (br "a") )]
434445
let solution =
435446
solve
447+
Solution.empty
436448
cookBook lockBook root
437449
ResolutionStyle.Upgrading
438450
|> Async.RunSynchronously
439451

440452
Assert.Equal ("2", getLockedRev "a" solution)
441453
Assert.Equal ("2", getLockedRev "b" solution)
442454
()
455+
456+
[<Fact>]
457+
let ``Solver does not upgrade if a complete solution is supplied`` () =
458+
let cookBook = [
459+
(package "a",
460+
Set[ver 2; br "a"],
461+
manifest [])
462+
(package "a",
463+
Set[ver 1; br "a"],
464+
manifest [])
465+
(package "b",
466+
Set[ver 2; br "a"],
467+
manifest [])
468+
(package "b",
469+
Set[ver 1; br "a"],
470+
manifest [])
471+
(package "c",
472+
Set[ver 2; br "a"],
473+
manifest [])
474+
(package "c",
475+
Set[ver 1; br "a"],
476+
manifest [])
477+
]
478+
479+
let lockBookSpec = [
480+
(("root", 0), [
481+
("a", 1, Set[ver 1; br "a"])
482+
("b", 1, Set[ver 1; br "a"])
483+
("c", 1, Set[ver 1; br "a"])
484+
])
485+
]
486+
487+
let root = manifest [
488+
("a", Exactly (br "a") )
489+
("b", Exactly (br "a") )
490+
("c", Exactly (br "a") )
491+
]
492+
493+
let lockBook = lockBookOf lockBookSpec
494+
495+
let rootLock = lockBook |> Map.find (packageLock ("root", 0))
496+
let explorer = TestingSourceExplorer(cookBook, lockBook)
497+
498+
let completeSolution =
499+
Solver.fromLock explorer rootLock
500+
|> Async.RunSynchronously
501+
502+
503+
let solution =
504+
solve
505+
completeSolution
506+
cookBook lockBookSpec root
507+
ResolutionStyle.Upgrading
508+
|> Async.RunSynchronously
509+
510+
Assert.Equal ("1", getLockedRev "a" solution)
511+
Assert.Equal ("1", getLockedRev "b" solution)
512+
Assert.Equal ("1", getLockedRev "c" solution)
513+
()
514+
515+
[<Fact>]
516+
let ``Solver upgrades completes partial solution with latest packages`` () =
517+
let cookBook = [
518+
(package "a",
519+
Set[ver 2; br "a"],
520+
manifest [])
521+
(package "a",
522+
Set[ver 1; br "a"],
523+
manifest [])
524+
(package "b",
525+
Set[ver 2; br "a"],
526+
manifest [])
527+
(package "b",
528+
Set[ver 1; br "a"],
529+
manifest [])
530+
(package "c",
531+
Set[ver 2; br "a"],
532+
manifest [])
533+
(package "c",
534+
Set[ver 1; br "a"],
535+
manifest [])
536+
]
537+
538+
let lockBookSpec = [
539+
(("root", 0), [
540+
("a", 1, Set[ver 1; br "a"])
541+
("b", 1, Set[ver 1; br "a"])
542+
("c", 1, Set[ver 1; br "a"])
543+
])
544+
]
545+
546+
let root = manifest [
547+
("a", Exactly (br "a") )
548+
("b", Exactly (br "a") )
549+
("c", Exactly (br "a") )
550+
]
551+
552+
let lockBook = lockBookOf lockBookSpec
553+
let rootLock = lockBook |> Map.find (packageLock ("root", 0))
554+
555+
let explorer = TestingSourceExplorer(cookBook, lockBook)
556+
let completeSolution =
557+
Solver.fromLock explorer rootLock
558+
|> Async.RunSynchronously
559+
560+
let partialSolution = Set[package "b"] |> Solver.unlock completeSolution
561+
562+
let solution =
563+
solve
564+
partialSolution
565+
cookBook lockBookSpec root
566+
ResolutionStyle.Upgrading
567+
|> Async.RunSynchronously
568+
569+
Assert.Equal ("1", getLockedRev "a" solution)
570+
Assert.Equal ("2", getLockedRev "b" solution)
571+
Assert.Equal ("1", getLockedRev "c" solution)
572+
()

buckaroo/AddCommand.fs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,27 @@ open Buckaroo
77

88
let task (context : Tasks.TaskContext) dependencies = async {
99
context.Console.Write (
10-
(text "Adding ") +
10+
(text "Adding ") +
1111
(
12-
dependencies
13-
|> Seq.map Dependency.showRich
12+
dependencies
13+
|> Seq.map Dependency.showRich
1414
|> RichOutput.concat (text " ")
1515
)
1616
)
1717

1818
let! manifest = Tasks.readManifest "."
19-
let newManifest = {
20-
manifest with
21-
Dependencies =
22-
manifest.Dependencies
23-
|> Seq.append dependencies
19+
let newManifest = {
20+
manifest with
21+
Dependencies =
22+
manifest.Dependencies
23+
|> Seq.append dependencies
2424
|> Set.ofSeq;
2525
}
2626

27-
if manifest = newManifest
28-
then
27+
if manifest = newManifest
28+
then
2929
return ()
30-
else
30+
else
3131
let! maybeLock = async {
3232
if File.Exists(Constants.LockFileName)
3333
then
@@ -37,15 +37,15 @@ let task (context : Tasks.TaskContext) dependencies = async {
3737
return None
3838
}
3939

40-
let! resolution = Solver.solve context newManifest ResolutionStyle.Quick maybeLock
41-
40+
let! resolution = Solver.solve context Solution.empty newManifest ResolutionStyle.Quick maybeLock
41+
4242
match resolution with
43-
| Resolution.Ok solution ->
43+
| Resolution.Ok solution ->
4444
do! Tasks.writeManifest newManifest
4545
do! Tasks.writeLock (Lock.fromManifestAndSolution newManifest solution)
4646
do! InstallCommand.task context
47-
| _ ->
47+
| _ ->
4848
()
49-
49+
5050
context.Console.Write ("Success. " |> text |> foreground ConsoleColor.Green)
5151
}

0 commit comments

Comments
 (0)