diff options
Diffstat (limited to '')
| -rw-r--r-- | tests/by-name/at/atuin-sync/test.nix | 158 |
1 files changed, 65 insertions, 93 deletions
diff --git a/tests/by-name/at/atuin-sync/test.nix b/tests/by-name/at/atuin-sync/test.nix index d65c216..cf8f0d8 100644 --- a/tests/by-name/at/atuin-sync/test.nix +++ b/tests/by-name/at/atuin-sync/test.nix @@ -1,67 +1,27 @@ { - nixos-lib, - pkgsUnstable, - nixpkgs-unstable, - vhackPackages, pkgs, extraModules, - nixLib, + turtle, + vhack, ... }: -nixos-lib.runTest { - hostPkgs = pkgs; +vhack.runTest { name = "atuin-sync"; - - node = { - specialArgs = {inherit pkgsUnstable vhackPackages nixpkgs-unstable nixLib;}; - - # Use the nixpkgs as constructed by the `nixpkgs.*` options - pkgs = null; - }; + serverDomains = [ + { + server = "atuin-sync.server"; + } + ]; nodes = let atuinSession = "01969ec6b8d07e30a9d2df0911fbfe2a"; + atuin = turtle.packages."${pkgs.stdenv.hostPlatform.system}".default; in { - acme = { - imports = [ - ../../../common/acme/server.nix - ../../../common/dns/client.nix - ]; - }; - name_server = {nodes, ...}: { - imports = - extraModules - ++ [ - ../../../common/acme/client.nix - ../../../common/dns/server.nix - ]; - - vhack.dns.zones = { - "atuin-sync.server" = { - SOA = { - nameServer = "ns"; - adminEmail = "admin@server.com"; - serial = 2025012301; - }; - useOrigin = false; - - A = [ - nodes.server.networking.primaryIPAddress - ]; - AAAA = [ - nodes.server.networking.primaryIPv6Address - ]; - }; - }; - }; - server = {config, ...}: { imports = extraModules ++ [ ../../../../modules - ../../../common/acme/client.nix - ../../../common/dns/client.nix ]; vhack = { @@ -75,54 +35,41 @@ nixos-lib.runTest { }; client1 = {config, ...}: { - imports = [ - ../../../common/acme/client.nix - ../../../common/dns/client.nix - ]; - environment.sessionVariables.ATUIN_SESSION = atuinSession; environment.systemPackages = [ - pkgs.atuin + atuin pkgs.sqlite-interactive ]; }; client2 = {config, ...}: { - imports = [ - ../../../common/acme/client.nix - ../../../common/dns/client.nix - ]; - environment.sessionVariables.ATUIN_SESSION = atuinSession; environment.systemPackages = [ - pkgs.atuin + atuin pkgs.sqlite-interactive ]; }; }; - testScript = {nodes, ...}: let - syncLogin = pkgs.writeShellScript "login-atuin-sync-account" '' - atuin login --username syncy --password password1234 --key "$1" - ''; - - syncRegister = pkgs.writeShellScript "register-atuin-sync-account" '' - atuin register --username syncy --email syncy@email.com --password password1234 - ''; + services = [ + {server = "turtle.service";} + ]; + testScript = {nodes, ...}: let mkSyncConfig = pkgs.writeShellScript "register-atuin-sync-account" '' - mkdir --parents ~/.config/atuin/ - cat << EOF > ~/.config/atuin/config.toml - sync_address = "https://atuin-sync.server" + mkdir --parents ~/.config/turtle/ + + cat << EOF > ~/.config/turtle/config.toml - # Use the v2 sync [sync] - records = true + address = "https://atuin-sync.server" + user_id_path = "${pkgs.writeText "user-id" "019eb88a-6b51-7e52-b12c-7d30bd8e5928"}" + encryption_key_path = "${pkgs.writeText "encryption-key" "3AAgbWsDzL7M00/Mq0LMjsyOCy3MnsypBsyQzKbMywNGzNnMrUBozIINAxdbIiDMhQ=="}" EOF ''; - runCommandAndRecordInAtuin = pkgs.writeShellScript "run-command-and-record-in-atuin" '' + runCommandAndRecordInTurtle = pkgs.writeShellScript "run-command-and-record-in-atuin" '' # SPDX-SnippetBegin # SPDX-SnippetCopyrightText: 2023 mentalisttraceur (https://github.com/mentalisttraceur) # Source: https://github.com/atuinsh/atuin/issues/1188#issuecomment-1698354107 @@ -131,49 +78,47 @@ nixos-lib.runTest { local id local status local escaped_command="$(printf '%q ' "$@")" - id="$(atuin history start -- "$escaped_command")" + id="$(turtle history start -- "$escaped_command")" "$@" status=$? - atuin history end --exit $status "$id" + turtle history end --exit $status "$id" return $status } # SPDX-SnippetEnd run_and_record_in_atuin "$@" ''; - - acme = import ../../../common/acme {inherit pkgs;}; in - acme.prepare ["server" "client1" "client2"] # Python '' - server.wait_for_unit("atuin.service") server.wait_for_open_port(443) # Wait for the server to acquire the acme certificate client1.wait_until_succeeds("curl https://atuin-sync.server") with subtest("Setup client syncing"): - # See https://docs.atuin.sh/guide/sync/ for client in [client1, client2]: client.succeed("${mkSyncConfig}") - client1.succeed("${syncRegister}") - client2.succeed(f"${syncLogin} '{client1.succeed("atuin key")}'") - - with subtest("Can import shell history"): - client1.succeed("${runCommandAndRecordInAtuin} echo hi - client 1") - client2.succeed("${runCommandAndRecordInAtuin} echo hi - client 2") + with subtest("Start turtle daemon"): + for client in [client1, client2]: + client.succeed("systemd-run turtle-daemon start") - with subtest("Can sync tasks"): for client in [client1, client2]: - client.succeed("atuin sync --force") - client1.succeed("atuin sync --force") + client.wait_until_succeeds("turtle daemon status") + with subtest("Can generate shell history"): + client1.succeed("${runCommandAndRecordInTurtle} echo hi - client 1") + client2.succeed("${runCommandAndRecordInTurtle} echo hi - client 2") + + with subtest("Can sync"): + for client in [client1, client2]: + client.succeed("turtle sync perform") + client1.succeed("turtle sync perform") with subtest("Have correct tasks"): - hist1 = client1.succeed("atuin history list --session --format '{command}'").strip().split('\n') - hist2 = client2.succeed("atuin history list --session --format '{command}'").strip().split('\n') + hist1 = client1.succeed("turtle history list --cmd-only").strip().split('\n') + hist2 = client2.succeed("turtle history list --cmd-only").strip().split('\n') hist1.sort() hist2.sort() @@ -185,5 +130,32 @@ nixos-lib.runTest { assert hist1 == hist2, f"The clients don't have the same amount of history items, client1: '{hist1}', client2: '{hist2}'" assert hist1 == canonicalHistory, f"The history is not correct: '{hist1}' vs. '{canonicalHistory}'" + + with subtest("Can sync again"): + client1.succeed("${runCommandAndRecordInTurtle} echo second try - client 1") + client2.succeed("${runCommandAndRecordInTurtle} echo second try - client 2") + + for client in [client1, client2]: + client.succeed("turtle sync perform") + client1.succeed("turtle sync perform") + + hist1 = client1.succeed("turtle history list --cmd-only").strip().split('\n') + hist2 = client2.succeed("turtle history list --cmd-only").strip().split('\n') + + hist1.sort() + hist2.sort() + + canonicalHistory = [ + # The old history + "echo hi - client 1", + "echo hi - client 2", + + # Our newly added history entries + "echo second try - client 1", + "echo second try - client 2" + ] + + assert hist1 == hist2, f"The clients don't have the same amount of history items, client1: '{hist1}', client2: '{hist2}'" + assert hist1 == canonicalHistory, f"The history is not correct, got: '{hist1}', expected: '{canonicalHistory}'" ''; } |
