<commit_before>#!/bin/sh
#
# Tests in this file are separated by two blank lines. Each test is
# self-sufficient and should cleanup after itself (use the cleanup function).
# No state should be maintained between each.
#

. ./_functions.sh


cleanup


announce "unknown chatter"
test_line "irc :jimmy!<EMAIL> PRIVMSG #test :blabla"
cat > test.expected <<EOF
EOF
assert_output && pass
cleanup


announce "unhandled command (channel)"
test_line "irc :jimmy!<EMAIL> PRIVMSG #test :whygore: wtf"
cat > test.expected <<EOF
PRIVMSG #test :command not found: wtf
EOF
assert_output && pass
cleanup


announce "unhandled command (private prefixed)"
test_line "irc :jimmy!<EMAIL> PRIVMSG whygore :whygore: wtf"
cat > test.expected <<EOF
PRIVMSG jimmy :command not found: wtf
EOF
assert_output && pass
cleanup


announce "unhandled command (private no prefix)"
test_line "irc :jimmy!<EMAIL> PRIVMSG whygore :wtf"
cat > test.expected <<EOF
PRIVMSG jimmy :command not found: wtf
EOF
assert_output && pass
cleanup


announce "minion registration"
test_line "minion user_id_0123456789 register bobert-von-cheesecake https://nom.nom/super-train/"
cat > test.expected <<EOF
[SQS-SendToMinion] https://nom.nom/super-train/ register success
EOF
assert_output && pass
cleanup


announce "minions list"
test_line "minion user_id_1234567890 register bobert-von-cheesecake https://nom.nom/super-train/bobert"
test_line "minion user_id_0987654321 register jo-mac-whopper https://nom.nom/super-train/jo"
test_line "irc :jimmy!<EMAIL> PRIVMSG #test :whygore: minions"
cat > test.expected <<EOF
PRIVMSG #test :currently registered: bobert-von-cheesecake, jo-mac-whopper
EOF
assert_output && pass
cleanup


announce "ping minions (outgoing)"
test_line "minion user_id_1234567890 register pi1 https://nom.nom/super-train/bobert"
test_line "minion user_id_1234567891 register pi2 https://nom.nom/super-train/jo"
test_line "irc :jimmy!<EMAIL> PRIVMSG #test :whygore: ping"
cat > test.expected <<EOF
[SQS-SendToMinion] https://nom.nom/super-train/bobert ping 1136239445000000000
[SQS-SendToMinion] https://nom.nom/super-train/jo ping 1136239445000000000
PRIVMSG #ygor :sent to pi1: ping 1136239445000000000
PRIVMSG #ygor :sent to pi2: ping 1136239445000000000
EOF
assert_output && pass
cleanup


announce "ping minions (late response)"
test_line "minion user_id_1234567890 register pi1 https://nom.nom/super-train/bobert"
test_line "minion user_id_1234567891 register pi2 https://nom.nom/super-train/jo"
{
	sleep 0.1
	echo "irc :jimmy!<EMAIL> PRIVMSG #test :whygore: ping"
	sleep 0.1
	echo "minion user_id_1234567890 pong 1136239945000000000"
	sleep 0.2
} | test_input
cat > test.expected <<EOF
[SQS-SendToMinion] https://nom.nom/super-train/bobert ping 1136239445000000000
[SQS-SendToMinion] https://nom.nom/super-train/jo ping 1136239445000000000
PRIVMSG #ygor :sent to pi1: ping 1136239445000000000
PRIVMSG #ygor :sent to pi2: ping 1136239445000000000
PRIVMSG #ygor :pong: got old ping reponse (1136239945000000000)
EOF
assert_output && pass
cleanup


announce "ping minions (good response)"
test_line "minion user_id_1234567890 register pi1 https://nom.nom/super-train/bobert"
test_line "minion user_id_1234567891 register pi2 https://nom.nom/super-train/jo"
{
	echo "irc :jimmy!<EMAIL> PRIVMSG #test :whygore: ping"
	sleep 0.2
	echo "minion user_id_1234567890 pong 1136239445000000000"
	sleep 0.2
	echo "minion user_id_1234567891 pong 1136239445000000000"<commit_msg>Give the slow travis test machine some time...<commit_after>#!/bin/sh
#
# Tests in this file are separated by two blank lines. Each test is
# self-sufficient and should cleanup after itself (use the cleanup function).
# No state should be maintained between each.
#

. ./_functions.sh


cleanup


announce "unknown chatter"
test_line "irc :<EMAIL>my!<EMAIL> PRIVMSG #test :blabla"
cat > test.expected <<EOF
EOF
assert_output && pass
cleanup


announce "unhandled command (channel)"
test_line "irc :jimmy!<EMAIL> PRIVMSG #test :whygore: wtf"
cat > test.expected <<EOF
PRIVMSG #test :command not found: wtf
EOF
assert_output && pass
cleanup


announce "unhandled command (private prefixed)"
test_line "irc :<EMAIL>my!<EMAIL> PRIVMSG whygore :whygore: wtf"
cat > test.expected <<EOF
PRIVMSG jimmy :command not found: wtf
EOF
assert_output && pass
cleanup


announce "unhandled command (private no prefix)"
test_line "irc :jimmy!<EMAIL> PRIVMSG whygore :wtf"
cat > test.expected <<EOF
PRIVMSG jimmy :command not found: wtf
EOF
assert_output && pass
cleanup


announce "minion registration"
test_line "minion user_id_0123456789 register bobert-von-cheesecake https://nom.nom/super-train/"
cat > test.expected <<EOF
[SQS-SendToMinion] https://nom.nom/super-train/ register success
EOF
assert_output && pass
cleanup


announce "minions list"
test_line "minion user_id_1234567890 register bobert-von-cheesecake https://nom.nom/super-train/bobert"
test_line "minion user_id_0987654321 register jo-mac-whopper https://nom.nom/super-train/jo"
test_line "irc :<EMAIL>my!<EMAIL> PRIVMSG #test :whygore: minions"
cat > test.expected <<EOF
PRIVMSG #test :currently registered: bobert-von-cheesecake, jo-mac-whopper
EOF
assert_output && pass
cleanup


announce "ping minions (outgoing)"
test_line "minion user_id_1234567890 register pi1 https://nom.nom/super-train/bobert"
test_line "minion user_id_1234567891 register pi2 https://nom.nom/super-train/jo"
test_line "irc :jimmy!<EMAIL> PRIVMSG #test :whygore: ping"
cat > test.expected <<EOF
[SQS-SendToMinion] https://nom.nom/super-train/bobert ping 1136239445000000000
[SQS-SendToMinion] https://nom.nom/super-train/jo ping 1136239445000000000
PRIVMSG #ygor :sent to pi1: ping 1136239445000000000
PRIVMSG #ygor :sent to pi2: ping 1136239445000000000
EOF
assert_output && pass
cleanup


announce "ping minions (late response)"
test_line "minion user_id_1234567890 register pi1 https://nom.nom/super-train/bobert"
test_line "minion user_id_1234567891 register pi2 https://nom.nom/super-train/jo"
{
	sleep 0.1
	echo "irc :jimmy!<EMAIL> PRIVMSG #test :whygore: ping"
	sleep 0.1
	echo "minion user_id_1234567890 pong 1136239945000000000"
	sleep 0.2
} | test_input
cat > test.expected <<EOF
[SQS-SendToMinion] https://nom.nom/super-train/bobert ping 1136239445000000000
[SQS-SendToMinion] https://nom.nom/super-train/jo ping 1136239445000000000
PRIVMSG #ygor :sent to pi1: ping 1136239445000000000
PRIVMSG #ygor :sent to pi2: ping 1136239445000000000
PRIVMSG #ygor :pong: got old ping reponse (1136239945000000000)
EOF
assert_output && pass
cleanup


announce "ping minions (good response)"
test_line "minion user_id_1234567890 register pi1 https://nom.nom/super-train/bobert"
test_line "minion user_id_1234567891 register pi2 https://nom.nom/super-train/jo"
{
	echo "irc :jimmy!<EMAIL> PRIVMSG #test :whygore: ping"
	sleep 0.2
	echo "minion user_id_1234567890 pong 1136239445000000000"
	sleep 0.2
	echo "minion user_id_1234567891 pong 1136239445000000000"
	sleep 0.2
{'fraction_non_alphanumeric': 0.10294117647058823, 'fraction_numerical': 0.10640138408304499, 'mean_word_length': 5.587844254510921, 'pattern_counts': {'":': 0, '<': 54, '<?xml version=': 0, '>': 38, 'https://': 28, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 24, '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': '7278464', 'n_tokens_mistral': 3054, 'n_tokens_neox': 2493, 'n_words': 690}