| 1 | # klaus (flow/): its shipping package, its unit tests, go vet, and its |
| 2 | # end-to-end suite, which drives the real binary against real git and a |
| 3 | # private tmux server. |
| 4 | { |
| 5 | pkgs, |
| 6 | lib, |
| 7 | packages, |
| 8 | ... |
| 9 | }: |
| 10 | let |
| 11 | inherit (packages) klaus version; |
| 12 | |
| 13 | # What the checks verify beside klaus's tests: the version the package |
| 14 | # reports, and that no test reached tmux by default. Its own tests run in |
| 15 | # flow-build, which builds its unit form. |
| 16 | checker = packages.goModule { |
| 17 | pname = "klaus-flow-checker"; |
| 18 | dir = ./flow-checker; |
| 19 | tests.postCheck = '' |
| 20 | go vet ./... |
| 21 | ''; |
| 22 | meta.mainProgram = "flow-checker"; |
| 23 | }; |
| 24 | |
| 25 | # The package rebuilt over the whole module, tests included, with the |
| 26 | # package's own vendored modules, running script in place of the build. |
| 27 | # It carries no version stamp: no test reads one. Test file paths stay |
| 28 | # real, as in buildGoModule's own check phase, so a test finds what it |
| 29 | # reads beside its source. |
| 30 | flowCheck = |
| 31 | name: |
| 32 | { |
| 33 | inputs ? [ ], |
| 34 | script, |
| 35 | }: |
| 36 | klaus.overrideAttrs (old: { |
| 37 | pname = "klaus-${name}"; |
| 38 | version = "0"; |
| 39 | ldflags = [ ]; |
| 40 | src = packages.flowComplete; |
| 41 | inherit (klaus) goModules; |
| 42 | nativeBuildInputs = old.nativeBuildInputs ++ inputs; |
| 43 | buildPhase = '' |
| 44 | runHook preBuild |
| 45 | export GOFLAGS=''${GOFLAGS//-trimpath/} |
| 46 | ${script} |
| 47 | runHook postBuild |
| 48 | ''; |
| 49 | doCheck = false; |
| 50 | installPhase = "touch $out"; |
| 51 | dontFixup = true; |
| 52 | }); |
| 53 | |
| 54 | # tmux finds a server through $TMUX or a socket under $TMUX_TMPDIR. Both |
| 55 | # stay inside the build's temporary directory, as do HOME and the XDG |
| 56 | # directories, the runtime one included, so no test reads or reaches |
| 57 | # anything of the builder's. Each test starts its own server on its own |
| 58 | # socket; a socket left under TMUX_TMPDIR afterwards is a server some test |
| 59 | # reached by default, and fails the check. A test that cannot find a tool |
| 60 | # it needs fails rather than skipping. |
| 61 | isolated = script: '' |
| 62 | unset TMUX TMUX_PANE |
| 63 | export TMUX_TMPDIR="$TMPDIR/tmux" HOME="$TMPDIR/home" XDG_RUNTIME_DIR="$TMPDIR/run" |
| 64 | export XDG_CONFIG_HOME="$HOME/.config" XDG_STATE_HOME="$HOME/.local/state" |
| 65 | export XDG_CACHE_HOME="$HOME/.cache" XDG_DATA_HOME="$HOME/.local/share" |
| 66 | mkdir -p "$TMUX_TMPDIR" "$HOME" |
| 67 | mkdir -m 700 "$XDG_RUNTIME_DIR" |
| 68 | export KLAUS_TEST_TOOLS=required |
| 69 | ${script} |
| 70 | flow-checker sockets "$TMUX_TMPDIR" |
| 71 | ''; |
| 72 | in |
| 73 | { |
| 74 | # The package as it ships, and the version it reports: the CLI's, |
| 75 | # stamped through the-valley/flow/internal/cmd.version. bin/klaus prints |
| 76 | # it as klaus, which an installed self-update's smoke test reads; the |
| 77 | # same binary run as bin/valley-flow names itself valley flow, and so |
| 78 | # does the valley package's `valley flow`, which runs valley-flow from |
| 79 | # PATH. |
| 80 | flow-build = |
| 81 | pkgs.runCommand "klaus-flow-build" |
| 82 | { |
| 83 | nativeBuildInputs = [ |
| 84 | klaus |
| 85 | packages.valley |
| 86 | checker.unit |
| 87 | ]; |
| 88 | } |
| 89 | '' |
| 90 | flow-checker version "klaus version ${version}" ${klaus}/bin/klaus |
| 91 | flow-checker version "valley flow version ${version}" ${klaus}/bin/valley-flow |
| 92 | flow-checker version "valley flow version ${version}" valley flow |
| 93 | touch $out |
| 94 | ''; |
| 95 | |
| 96 | # The unit tests. TestFlakeRefSurvivesNix has nix parse the flake |
| 97 | # references self-update builds, which needs no store: the dummy store |
| 98 | # serves an evaluation. It takes the newest nix, because nix 2.31, the |
| 99 | # pinned default, refuses git+git:// references. |
| 100 | flow-unit = flowCheck "unit" { |
| 101 | inputs = [ |
| 102 | checker |
| 103 | pkgs.git |
| 104 | pkgs.tmux |
| 105 | pkgs.nixVersions.latest |
| 106 | ]; |
| 107 | script = isolated '' |
| 108 | export NIX_CONFIG="store = dummy://" |
| 109 | go test ./... |
| 110 | ''; |
| 111 | }; |
| 112 | |
| 113 | flow-vet = flowCheck "vet" { |
| 114 | script = "go vet ./..."; |
| 115 | }; |
| 116 | |
| 117 | # The end-to-end suite, with the valley command its restack and landing |
| 118 | # scenarios run. It is the unstamped valley: those scenarios read no |
| 119 | # version. |
| 120 | flow-e2e = flowCheck "e2e" { |
| 121 | inputs = [ |
| 122 | checker |
| 123 | pkgs.git |
| 124 | pkgs.tmux |
| 125 | pkgs.bash |
| 126 | packages.valley-unstamped |
| 127 | ]; |
| 128 | script = isolated '' |
| 129 | go test -tags e2e ./e2e/... |
| 130 | ''; |
| 131 | }; |
| 132 | } |