Access node specialisation from within testScript

I would like to access the complete config of a specialisation in a NixOS VM test from within the testScript. With a node called server and a specialisation called mySpecialisation, I managed to do it like so:

testScript =
  args:
  let
    mySpecializationConfig = lib.recursiveUpdate args {
      nodes.server = nodes.server.specialisation.mySpecialisation.configuration;
    };
  in
  { };

Is there a more idiomatic way?

in caddy nixos test we are just getting the specialization from closure paths and activating in subtests

Thanks @StepBroBD, that’s the pattern found in most NixOS test using specialisation but it does not match what I want.

I have a test script that depends on options set in the node. My real use case is to define a service first with basic auth then ldap integration and I want to make sure it is possible to upgrade from one to the other and keep the same user. It looks like so:

testScript = args: {
  let
    specializations = "${nodes.server.system.build.toplevel}/specialisation";

    genericTest' = args': if nodes.server.myoption then "do something" else "do something else"
  in
  + ''
    server.succeed('${specializations}/basic/bin/switch-to-configuration basic')
  ''
  + genericTest' (
    lib.recursiveUpdate args {
      nodes.server = nodes.server.specialisation.basic.configuration;
    }
  )
  + ''
    server.succeed('${specializations}/basic/bin/switch-to-configuration ldap')
  ''
  + genericTest' (
    lib.recursiveUpdate args {
      nodes.server = nodes.server.specialisation.ldap.configuration;
    }
  )
}