<commit_before>module Gen.Servers exposing (..)

import Gen.Filesystem
import Gen.Logs
import Gen.Processes
import Random.Pcg
    exposing
        ( Generator
        , constant
        , int
        , list
        , choice
        , map
        , map2
        , andThen
        )
import Random.Pcg.Extra exposing (andMap)
import Fuzz exposing (Fuzzer)
import Game.Network.Types exposing (IP)
import Game.Servers.Models exposing (..)
import Game.Servers.Shared exposing (..)
import Game.Servers.Tunnels.Models as Tunnels
import Gen.Utils exposing (..)


--------------------------------------------------------------------------------
-- Fuzzers
--------------------------------------------------------------------------------


serverID : Fuzzer ID
serverID =
    fuzzer genServerID


ip : Fuzzer IP
ip =
    fuzzer genIP


serverData : Fuzzer Server
serverData =
    fuzzer genServer


serverDataList : Fuzzer (List Server)
serverDataList =
    fuzzer genServerList


server : Fuzzer Server
server =
    fuzzer genServer


emptyModel : Fuzzer Model
emptyModel =
    fuzzer genEmptyModel


nonEmptyModel : Fuzzer Model
nonEmptyModel =
    fuzzer genNonEmptyModel


servers : Fuzzer Model
servers =
    fuzzer genModel


model : Fuzzer Model
model =
    fuzzer genModel



--------------------------------------------------------------------------------
-- Generators
--------------------------------------------------------------------------------


genServerID : Generator ID
genServerID =
    unique


{-| TODO: make a true IP generator
-}
genIP : Generator IP
genIP =
    unique


genOwnserhip : Generator Ownership
genOwnserhip =
    choice
        (GatewayOwnership <| GatewayData Nothing [])
        (EndpointOwnership <| EndpointData Nothing Nothing)


genServer : Generator Server
genServer =
    let
        buildServerRecord ip ownership fs logs proc =
            { name = "Dummy"
            , type_ = Desktop
            , nip = ( "::", ip )
            , nips = [ ( "::", ip ) ]
            , coordinates = Just 0
            , filesystem = fs
            , logs = logs
            , processes = proc
            , tunnels = Tunnels.initialModel
            , ownership =
                ownership
            }
    in
        genIP
            |> map buildServerRecord
            |> andMap genOwnserhip
            |> andMap Gen.Filesystem.genModel
            |> andMap Gen.Logs.genModel
            |> andMap Gen.Processes.genModel


genGatewayServer : Generator Server
genGatewayServer =
    let
        buildServerRecord ip fs logs proc =
            { name = "Dummy"
            , type_ = Desktop
            , nip = ( "::", ip )
            , nips = [ ( "::", ip ) ]
            , coordinates = Just 0
            , filesystem = fs
            , logs = logs
            , processes = proc
            , tunnels = Tunnels.initialModel
            , ownership =
                GatewayOwnership <| GatewayData Nothing []
            }
    in
        genIP
            |> map buildServerRecord
            |> andMap Gen.Filesystem.genModel
            |> andMap Gen.Logs.genModel
            |> andMap Gen.Processes.genModel


genEndpointServer : Generator Server
genEndpointServer =
    let
        buildServerRecord ip fs logs proc =
            { name = "Dummy"
            , type_ = Desktop
            , nip = ( "::", ip )
            , nips = [ ( "::", ip ) ]
            , coordinates = Just 0
            , filesystem = fs
            , logs = logs
            , processes = proc
            , tunnels = Tunnels.initialModel
            , ownership =
                GatewayOwnership <| GatewayData Nothing []
            }
    in
        genIP
            |> map buildServerRecord
            |> andMap Gen.Filesystem.genModel
            |> andMap Gen.Logs.genModel
            |> andMap Gen.Processes.genModel


genServerList : Generator (List Server)
genServerList =
    andThen (\num -> list num genServer) (int 8 10)


genEmptyModel : Generator Model
genEmptyModel =
    constant initialModel


genNonEmptyModel : Generator Model
genNonEmptyModel =
    map2 (\id -> List.foldl (insert id) initialModel)
        genServerID
        genServerList


genModel : Generator Model
genModel =
    genNonEmptyModel
<commit_msg>Notifications: fix tests<commit_after>module Gen.Servers exposing (..)

import Gen.Filesystem
import Gen.Logs
import Gen.Processes
import Random.Pcg
    exposing
        ( Generator
        , constant
        , int
        , list
        , choice
        , map
        , map2
        , andThen
        )
import Random.Pcg.Extra exposing (andMap)
import Fuzz exposing (Fuzzer)
import Game.Network.Types exposing (IP)
import Game.Servers.Models exposing (..)
import Game.Servers.Shared exposing (..)
import Game.Servers.Tunnels.Models as Tunnels
import Game.Notifications.Models as Notifications
import Gen.Utils exposing (..)


--------------------------------------------------------------------------------
-- Fuzzers
--------------------------------------------------------------------------------


serverID : Fuzzer ID
serverID =
    fuzzer genServerID


ip : Fuzzer IP
ip =
    fuzzer genIP


serverData : Fuzzer Server
serverData =
    fuzzer genServer


serverDataList : Fuzzer (List Server)
serverDataList =
    fuzzer genServerList


server : Fuzzer Server
server =
    fuzzer genServer


emptyModel : Fuzzer Model
emptyModel =
    fuzzer genEmptyModel


nonEmptyModel : Fuzzer Model
nonEmptyModel =
    fuzzer genNonEmptyModel


servers : Fuzzer Model
servers =
    fuzzer genModel


model : Fuzzer Model
model =
    fuzzer genModel



--------------------------------------------------------------------------------
-- Generators
--------------------------------------------------------------------------------


genServerID : Generator ID
genServerID =
    unique


{-| TODO: make a true IP generator
-}
genIP : Generator IP
genIP =
    unique


genOwnserhip : Generator Ownership
genOwnserhip =
    choice
        (GatewayOwnership <| GatewayData Nothing [])
        (EndpointOwnership <| EndpointData Nothing Nothing)


genServer : Generator Server
genServer =
    let
        buildServerRecord ip ownership fs logs proc =
            { name = "Dummy"
            , type_ = Desktop
            , nip = ( "::", ip )
            , nips = [ ( "::", ip ) ]
            , coordinates = Just 0
            , filesystem = fs
            , logs = logs
            , processes = proc
            , tunnels = Tunnels.initialModel
            , ownership =
                ownership
            , notifications =
                Notifications.initialModel
            }
    in
        genIP
            |> map buildServerRecord
            |> andMap genOwnserhip
            |> andMap Gen.Filesystem.genModel
            |> andMap Gen.Logs.genModel
            |> andMap Gen.Processes.genModel


genGatewayServer : Generator Server
genGatewayServer =
    let
        buildServerRecord ip fs logs proc =
            { name = "Dummy"
            , type_ = Desktop
            , nip = ( "::", ip )
            , nips = [ ( "::", ip ) ]
            , coordinates = Just 0
            , filesystem = fs
            , logs = logs
            , processes = proc
            , tunnels = Tunnels.initialModel
            , ownership =
                GatewayOwnership <| GatewayData Nothing []
            , notifications =
                Notifications.initialModel
            }
    in
        genIP
            |> map buildServerRecord
            |> andMap Gen.Filesystem.genModel
            |> andMap Gen.Logs.genModel
            |> andMap Gen.Processes.genModel


genEndpointServer : Generator Server
genEndpointServer =
    let
        buildServerRecord ip fs logs proc =
            { name = "Dummy"
            , type_ = Desktop
            , nip = ( "::", ip )
            , nips = [ ( "::", ip ) ]
            , coordinates = Just 0
            , filesystem = fs
            , logs = logs
            , processes = proc
            , tunnels = Tunnels.initialModel
            , ownership =
                GatewayOwnership <| GatewayData Nothing []
            , notifications =
                Notifications.initialModel
            }
    in
        genIP
            |> map buildServerRecord
            |> andMap Gen.Filesystem.genModel
            |> andMap Gen.Logs.genModel
            |> andMap Gen.Processes.genModel


genServerList : Generator (List Server)
genServerList =
    andThen (\num -> list num genServer) (int 8 10)


genEmptyModel : Generator Model
genEmptyModel =
    constant initialModel


genNonEmptyModel : Generator Model
genNonEmptyModel =
    map2 (\id -> List.foldl (insert id) initialModel)
        genServerID
        genServerList


genModel : Generator Model
genModel =
    genNonEmptyModel

{'fraction_non_alphanumeric': 0.14321493624772313, 'fraction_numerical': 0.0018214936247723133, 'mean_word_length': 1.4594064949608063, 'pattern_counts': {'":': 12, '<': 11, '<?xml version=': 0, '>': 33, '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': '6018876', 'n_tokens_mistral': 2388, 'n_tokens_neox': 2267, 'n_words': 604}