<commit_before># -*- mode: Shell-script;bash -*-

VAULT_LOG="${BATS_TMPDIR}/aomi-vault-log"

function start_vault() {
    if [ -e "${HOME}/.vault-token" ] ; then
        mv "${HOME}/.vault-token" "${BATS_TMPDIR}/og-token"
    fi
    nohup vault server -dev &> "$VAULT_LOG" &
    export VAULT_PID=$!
    if ! ps $VAULT_PID | grep vault &> /dev/null ; then
        stop_vault
        start_vault
    else
        export VAULT_ADDR='http://127.0.0.1:8200'
        VAULT_TOKEN=$(grep -e 'Root Token' "$VAULT_LOG" | cut -f 3 -d ' ')
        export VAULT_TOKEN="$VAULT_TOKEN"
        vault auth-enable app-id &> /dev/null
    fi
}

function stop_vault() {
    if [ -e "${BATS_TMPDIR}/og-token" ] ; then
        mv "${BATS_TMPDIR}/og-token" "${HOME}/.vault-token"
    fi
    kill $VAULT_PID
    rm -f "$VAULT_LOG"
}

function use_fixture() {
    FIXTURE="$1"
    FIXTURE_DIR="${BATS_TMPDIR}/fixtures"
    mkdir -p "${FIXTURE_DIR}/.secrets"
    cp -r "${BATS_TEST_DIRNAME}/fixtures/${FIXTURE}/"* "$FIXTURE_DIR"
    cp -r "${BATS_TEST_DIRNAME}/fixtures/${FIXTURE}/.secrets/"* "${FIXTURE_DIR}/.secrets"
    cd "$FIXTURE_DIR" || exit 1<commit_msg>ruby some pgrep on it<commit_after># -*- mode: Shell-script;bash -*-

VAULT_LOG="${BATS_TMPDIR}/aomi-vault-log"

function start_vault() {
    if [ -e "${HOME}/.vault-token" ] ; then
        mv "${HOME}/.vault-token" "${BATS_TMPDIR}/og-token"
    fi
    nohup vault server -dev &> "$VAULT_LOG" &
    if ! pgrep vault &> /dev/null ; then
        stop_vault
        start_vault
    else
        export VAULT_PID=$(pgrep vault)
        export VAULT_ADDR='http://127.0.0.1:8200'
        VAULT_TOKEN=$(grep -e 'Root Token' "$VAULT_LOG" | cut -f 3 -d ' ')
        export VAULT_TOKEN="$VAULT_TOKEN"
        vault auth-enable app-id &> /dev/null
    fi
}

function stop_vault() {
    if [ -e "${BATS_TMPDIR}/og-token" ] ; then
        mv "${BATS_TMPDIR}/og-token" "${HOME}/.vault-token"
    fi
    kill $VAULT_PID
    rm -f "$VAULT_LOG"
}

function use_fixture() {
    FIXTURE="$1"
    FIXTURE_DIR="${BATS_TMPDIR}/fixtures"
    mkdir -p "${FIXTURE_DIR}/.secrets"
    cp -r "${BATS_TEST_DIRNAME}/fixtures/${FIXTURE}/"* "$FIXTURE_DIR"
    cp -r "${BATS_TEST_DIRNAME}/fixtures/${FIXTURE}/.secrets/"* "${FIXTURE_DIR}/.secrets"
    cd "$FIXTURE_DIR" || exit 1
{'fraction_non_alphanumeric': 0.18018412976764578, 'fraction_numerical': 0.011398509425690487, 'mean_word_length': 2.7719008264462808, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '3925716', 'n_tokens_mistral': 940, 'n_tokens_neox': 914, 'n_words': 168}