<commit_before>import ./make-test-python.nix ({ pkgs, ...}:

let
  client = {pkgs, ...}:{
    environment.systemPackages = [ pkgs.upterm ];
  };
in
{
  name = "uptermd";
  meta = with pkgs.lib.maintainers; {
    maintainers = [ fleaz ];
  };

  nodes = {
    server = {config, ...}: {
      services.uptermd = {
        enable = true;
        openFirewall = true;
        port = 1337;
      };
    };
    client1 = client;
    client2 = client;
  };


  testScript = ''
    start_all()

    server.wait_for_unit("uptermd.service")
    server.wait_for_unit("network-online.target")

    # Add SSH hostkeys from the server to both clients
    # uptermd needs an '@cert-authority entry so we need to modify the known_hosts file
    client1.execute("sleep 3; mkdir -p ~/.ssh && ssh -o StrictHostKeyChecking=no -p 1337 server ls")
    client1.execute("echo @cert-authority $(cat ~/.ssh/known_hosts) > ~/.ssh/known_hosts")
    client2.execute("sleep 3; mkdir -p ~/.ssh && ssh -o StrictHostKeyChecking=no -p 1337 server ls")
    client2.execute("echo @cert-authority $(cat ~/.ssh/known_hosts) > ~/.ssh/known_hosts")

    client1.wait_for_unit("multi-user.target")
    client1.wait_until_succeeds("pgrep -f 'agetty.*tty1'")
    client1.wait_until_tty_matches(1, "login: ")
    client1.send_chars("root\n")
    client1.wait_until_succeeds("pgrep -u root bash")

    client1.execute("ssh-keygen -t ed25519 -N \"\" -f /root/.ssh/id_ed25519")
    client1.send_chars("TERM=xterm upterm host --server ssh://server:1337 --force-command hostname -- bash > /tmp/session-details\n")<commit_msg>nixos/upterm: fix race condition in test<commit_after>import ./make-test-python.nix ({ pkgs, ...}:

let
  client = {pkgs, ...}:{
    environment.systemPackages = [ pkgs.upterm ];
  };
in
{
  name = "uptermd";
  meta = with pkgs.lib.maintainers; {
    maintainers = [ fleaz ];
  };

  nodes = {
    server = {config, ...}: {
      services.uptermd = {
        enable = true;
        openFirewall = true;
        port = 1337;
      };
    };
    client1 = client;
    client2 = client;
  };


  testScript = ''
    start_all()

    server.wait_for_unit("uptermd.service")
    server.wait_for_unit("network-online.target")

    # wait for upterm port to be reachable
    client1.wait_until_succeeds("nc -z -v server 1337")

    # Add SSH hostkeys from the server to both clients
    # uptermd needs an '@cert-authority entry so we need to modify the known_hosts file
    client1.execute("mkdir -p ~/.ssh && ssh -o StrictHostKeyChecking=no -p 1337 server ls")
    client1.execute("echo @cert-authority $(cat ~/.ssh/known_hosts) > ~/.ssh/known_hosts")
    client2.execute("mkdir -p ~/.ssh && ssh -o StrictHostKeyChecking=no -p 1337 server ls")
    client2.execute("echo @cert-authority $(cat ~/.ssh/known_hosts) > ~/.ssh/known_hosts")

    client1.wait_for_unit("multi-user.target")
    client1.wait_until_succeeds("pgrep -f 'agetty.*tty1'")
    client1.wait_until_tty_matches(1, "login: ")
    client1.send_chars("root\n")
    client1.wait_until_succeeds("pgrep -u root bash")

    client1.execute("ssh-keygen -t ed25519 -N \"\" -f /root/.ssh/id_ed25519")
    client1.send_chars("TERM=xterm upterm host --server ssh://server:1337 --force-command hostname -- bash > /tmp/session-details\n")
{'fraction_non_alphanumeric': 0.15271389144434222, 'fraction_numerical': 0.027292241643667586, 'mean_word_length': 2.9877750611246943, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7522189', 'n_tokens_mistral': 1251, 'n_tokens_neox': 1136, 'n_words': 244}