Unit tests (tests/unittests/test_ai_client.c): +50 cases on top of the
existing 50 — total 100. Covers:
- chat response parser (ai_parse_response): OpenAI content + Perplexity
text formats, escape decoding, empty/null/missing inputs, format-string
safety, multiline content
- error envelope parser (ai_parse_error_message): standard envelope,
nested escapes, missing fields, null/empty
- extended JSON escape: \b, \f, \r, all-specials, UTF-8 pass-through
- provider autocomplete cycling with >=2 matches and wrap-around
- session edge cases: NULL args, 100-message order preservation,
set_model(NULL), ref/unref(NULL)
- provider edge cases: get/remove with NULL, double-remove, survival
via session ref after ai_remove_provider
- settings: multi-key independence, missing key, cross-provider
isolation
- model parsing edges: data not array, empty data, "id" outside data,
multiple models
- prefs round-trip: set token -> shutdown -> init -> token reloaded
from disk (uses load_preferences fixture)
Functional tests:
- Tier A (test_ai.c): 15 cases for the /ai command surface that don't
need HTTP. Covers /ai help, providers list, set provider/token,
start with/without key/unknown provider, clear, remove, default
provider/model, switch without window, bad subcommand.
- Tier B (test_ai_http.c + ai_http_stub.{c,h,py}): 5 cases that
exercise the libcurl path against a local Python HTTP stub. The
stub serves canned bodies in five modes (ok, openai, 401, 500,
models) so each chat/models/error path is hit end-to-end without
network.
Infrastructure:
- TEST_GROUPS bumped to 5 in proftest.c; AI tests live in their own
Group 5 because mixing them with stabber-driven tests in Group 4
poisoned stbbr_stop() teardown.
- PROF_FUNC_TEST_AI macro in functionaltests.c registers AI tests
with ai_init_test() which wraps init_prof_test with a prof_connect()
so stabber sees a graceful disconnect at teardown.
- dist_check_DATA ships ai_http_stub.py with the source tarball.
Source-level changes to enable testing:
- src/ai/ai_client.{c,h}: dropped 'static' from _parse_ai_response
(renamed ai_parse_response) and _parse_error_response (renamed
ai_parse_error_message); declared under a "Parsing helpers (exposed
for testing)" section. Same approach as ai_parse_models_from_json.
Results in Docker (cproof-debian image):
- 595/595 unit tests pass
- 20/20 AI functional tests pass (Group 5)
29 lines
1.1 KiB
C
29 lines
1.1 KiB
C
#ifndef __H_FUNC_TEST_AI
|
|
#define __H_FUNC_TEST_AI
|
|
|
|
/*
|
|
* AI tests don't exercise the XMPP path, but the test fixture's
|
|
* stbbr_stop() hangs indefinitely when no client ever connected to
|
|
* stabber. ai_init_test wraps init_prof_test with a prof_connect()
|
|
* so stabber sees a graceful disconnect at teardown.
|
|
*/
|
|
int ai_init_test(void** state);
|
|
|
|
void ai_no_args_shows_help(void** state);
|
|
void ai_providers_lists_defaults(void** state);
|
|
void ai_providers_list_shows_key_status(void** state);
|
|
void ai_set_provider_adds_custom(void** state);
|
|
void ai_set_token_marks_key_set(void** state);
|
|
void ai_start_unknown_provider_errors(void** state);
|
|
void ai_start_without_key_errors(void** state);
|
|
void ai_start_with_key_opens_window(void** state);
|
|
void ai_clear_without_window_errors(void** state);
|
|
void ai_remove_provider_works(void** state);
|
|
void ai_remove_provider_unknown_errors(void** state);
|
|
void ai_set_default_provider_unknown_errors(void** state);
|
|
void ai_set_default_model_updates_provider(void** state);
|
|
void ai_switch_without_window_errors(void** state);
|
|
void ai_bad_subcommand_shows_usage(void** state);
|
|
|
|
#endif
|