Something went wrong. Try again.
my code lab
Something went wrong. Try again.
2.6 kB 98 lines
at trunk
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899#!/usr/bin/env atf-sh
atf_init_test_cases() { atf_add_test_case prints_response atf_add_test_case empty_output atf_add_test_case inference_fails atf_add_test_case missing_agent atf_add_test_case passes_prompt atf_add_test_case model_flags_split}
setup() { HELLO="$(atf_get_srcdir)/hello-model" mk_model export MODEL="${PWD}/model-stub"}
# Write a fake model command in the current directory. It records its# argv to model.argv, then stands in for the model by printing canned# lines on standard output. Two env vars shape the run under test:## STUB_EMPTY when 1, print nothing (a model that produced no output)# STUB_FAIL when 1, exit non-zero (a failed invocation)mk_model() { cat > model-stub <<-'EOF' #!/bin/sh : > model.argv for a in "$@"; do printf '%s\n' "$a" >> model.argv; done [ "${STUB_FAIL:-0}" = 1 ] && exit 1 [ "${STUB_EMPTY:-0}" = 1 ] && exit 0 printf 'English: hello world\nFrench: bonjour le monde\n' EOF chmod +x model-stub}
atf_test_case prints_responseprints_response_head() { atf_set "descr" "the model's output is passed through to stdout"}prints_response_body() { setup atf_check -s exit:0 \ -o inline:"English: hello world\nFrench: bonjour le monde\n" \ "${HELLO}"}
atf_test_case empty_outputempty_output_head() { atf_set "descr" "an empty model response is an error"}empty_output_body() { setup export STUB_EMPTY=1 atf_check -s exit:1 -e match:"model produced no output" "${HELLO}"}
atf_test_case inference_failsinference_fails_head() { atf_set "descr" "a failed model invocation is reported and fatal"}inference_fails_body() { setup export STUB_FAIL=1 atf_check -s exit:1 -e match:"inference failed" "${HELLO}"}
atf_test_case missing_agentmissing_agent_head() { atf_set "descr" "hello-model fails when no agent.org sits beside it"}missing_agent_body() { setup mkdir bare cp "${HELLO}" bare/hello-model atf_check -s exit:1 -e match:"no agent.org" ./bare/hello-model}
atf_test_case passes_promptpasses_prompt_head() { atf_set "descr" "the agent.org instructions are handed to the model"}passes_prompt_body() { setup atf_check -s exit:0 -o ignore "${HELLO}" atf_check -o match:"^-p$" cat model.argv atf_check grep -qF "hello agent instructions" model.argv}
atf_test_case model_flags_splitmodel_flags_split_head() { atf_set "descr" "extra words in MODEL split into separate arguments"}model_flags_split_body() { setup export MODEL="${PWD}/model-stub --model x" atf_check -s exit:0 -o ignore "${HELLO}" atf_check -o match:"^--model$" -o match:"^x$" cat model.argv}