|
| 1 | +module Test.Registry.App.Server.MatrixBuilder (spec) where |
| 2 | + |
| 3 | +import Registry.App.Prelude |
| 4 | + |
| 5 | +import Data.Map as Map |
| 6 | +import Data.Set as Set |
| 7 | +import Effect.Ref as Ref |
| 8 | +import Registry.App.Server.MatrixBuilder as MatrixBuilder |
| 9 | +import Registry.ManifestIndex as ManifestIndex |
| 10 | +import Registry.PackageName as PackageName |
| 11 | +import Registry.Solver as Solver |
| 12 | +import Registry.Test.Assert.Run (runRegistryMock) |
| 13 | +import Registry.Test.Utils as Utils |
| 14 | +import Test.Spec as Spec |
| 15 | +import Test.Spec.Assertions as Assert |
| 16 | + |
| 17 | +spec :: Spec.Spec Unit |
| 18 | +spec = do |
| 19 | + Spec.describe "solveDependantsForCompiler" do |
| 20 | + Spec.it "cascades to dependant for a new compiler" do |
| 21 | + let { solverData, index, metadata } = setup [ "0.15.10" ] |
| 22 | + result <- runSolver solverData index metadata |
| 23 | + let names = Set.map _.name result |
| 24 | + unless (Set.member effectName names) do |
| 25 | + Assert.fail $ "Expected cascade to effect, but got: " |
| 26 | + <> show (Set.map PackageName.print names) |
| 27 | + |
| 28 | + Spec.it "skips dependant already tested with this compiler" do |
| 29 | + let { solverData, index, metadata } = setup [ "0.15.10", "0.15.11" ] |
| 30 | + result <- runSolver solverData index metadata |
| 31 | + unless (Set.isEmpty result) do |
| 32 | + Assert.fail "Expected empty result set when compiler already tested" |
| 33 | + |
| 34 | + where |
| 35 | + preludeName = Utils.unsafePackageName "prelude" |
| 36 | + effectName = Utils.unsafePackageName "effect" |
| 37 | + |
| 38 | + compiler_0_15_10 = Utils.unsafeVersion "0.15.10" |
| 39 | + compiler_0_15_11 = Utils.unsafeVersion "0.15.11" |
| 40 | + allCompilers = Utils.unsafeNonEmptyArray [ compiler_0_15_10, compiler_0_15_11 ] |
| 41 | + |
| 42 | + preludeVersion = Utils.unsafeVersion "6.0.0" |
| 43 | + |
| 44 | + preludeManifest = Utils.unsafeManifest "prelude" "6.0.0" [] |
| 45 | + effectManifest = Utils.unsafeManifest "effect" "4.0.0" |
| 46 | + [ Tuple "prelude" ">=6.0.0 <7.0.0" ] |
| 47 | + |
| 48 | + dummySha = Utils.unsafeSha256 "sha256-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa=" |
| 49 | + dummyTime = Utils.unsafeDateTime "2022-08-18T20:04:00.000Z" |
| 50 | + |
| 51 | + mkPublishedMeta version compilers = |
| 52 | + Map.singleton version |
| 53 | + { bytes: 1000.0 |
| 54 | + , compilers: Utils.unsafeNonEmptyArray (map Utils.unsafeVersion compilers) |
| 55 | + , hash: dummySha |
| 56 | + , publishedTime: dummyTime |
| 57 | + , ref: Nothing |
| 58 | + } |
| 59 | + |
| 60 | + -- | Set up a test scenario where prelude@6.0.0 (no deps) has completed its |
| 61 | + -- | matrix job for 0.15.11, and effect@4.0.0 (depends on prelude) has the |
| 62 | + -- | given compilers in its metadata. |
| 63 | + setup effectCompilers = do |
| 64 | + let |
| 65 | + index = Utils.fromRight "Failed to build ManifestIndex" do |
| 66 | + ManifestIndex.insert ManifestIndex.ConsiderRanges preludeManifest ManifestIndex.empty |
| 67 | + >>= ManifestIndex.insert ManifestIndex.ConsiderRanges effectManifest |
| 68 | + |
| 69 | + -- prelude must include 0.15.11 in its compilers because this test |
| 70 | + -- simulates the state AFTER prelude's own matrix job has completed. |
| 71 | + -- In the real flow: runMatrixJob writes the new compiler into the |
| 72 | + -- parent's metadata (MatrixBuilder.purs:82-91), then the executor |
| 73 | + -- rebuilds the CompilerIndex from current metadata before calling |
| 74 | + -- solveDependantsForCompiler. Without 0.15.11 here, the solver |
| 75 | + -- would compute purs >=0.15.10 <0.15.11 for prelude, excluding |
| 76 | + -- the target compiler from effect's build plan. |
| 77 | + preludeMetadata = Metadata |
| 78 | + { location: Git { url: "https://github.com/purescript/purescript-prelude.git", subdir: Nothing } |
| 79 | + , owners: Nothing |
| 80 | + , published: mkPublishedMeta preludeVersion [ "0.15.10", "0.15.11" ] |
| 81 | + , unpublished: Map.empty |
| 82 | + } |
| 83 | + |
| 84 | + effectMetadata = Metadata |
| 85 | + { location: Git { url: "https://github.com/purescript/purescript-effect.git", subdir: Nothing } |
| 86 | + , owners: Nothing |
| 87 | + , published: mkPublishedMeta (Utils.unsafeVersion "4.0.0") effectCompilers |
| 88 | + , unpublished: Map.empty |
| 89 | + } |
| 90 | + |
| 91 | + metadata = Map.fromFoldable [ Tuple preludeName preludeMetadata, Tuple effectName effectMetadata ] |
| 92 | + |
| 93 | + compilerIndex = Solver.buildCompilerIndex allCompilers index metadata |
| 94 | + |
| 95 | + solverData = |
| 96 | + { compilerIndex |
| 97 | + , compiler: compiler_0_15_11 |
| 98 | + , name: preludeName |
| 99 | + , version: preludeVersion |
| 100 | + , dependencies: Map.empty |
| 101 | + } |
| 102 | + |
| 103 | + { solverData, index, metadata } |
| 104 | + |
| 105 | + runSolver solverData index metadata = liftAff do |
| 106 | + indexRef <- liftEffect $ Ref.new index |
| 107 | + metadataRef <- liftEffect $ Ref.new metadata |
| 108 | + runRegistryMock metadataRef indexRef |
| 109 | + $ MatrixBuilder.solveDependantsForCompiler solverData |
0 commit comments