Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ DAEMON_O := src/core/daemon.o
RELOAD_O := src/core/reload.o
BOOTSTRAP_O := src/core/bootstrap.o
DISPATCH_O := src/core/dispatch.o
BOOTSTRAP_DISPATCH_STUB_O := tests/stubs/bootstrap_dispatch_stub.o
# Vendor
TOML_O := vendor/tomlc99/toml.o
SQLITE3_O := vendor/sqlite3/sqlite3.o
Expand Down Expand Up @@ -162,6 +163,9 @@ $(BOOTSTRAP_O): src/core/bootstrap.c src/core/bootstrap.h src/core/config.h src/
$(DISPATCH_O): src/core/dispatch.c src/core/dispatch.h src/core/agent.h src/core/bootstrap.h src/core/memory.h src/channels/channel.h
$(CC) $(CFLAGS) $(INC) -c -o $@ src/core/dispatch.c

$(BOOTSTRAP_DISPATCH_STUB_O): tests/stubs/bootstrap_dispatch_stub.c src/core/bootstrap.h src/core/config.h src/providers/provider.h src/tools/tool.h
$(CC) $(CFLAGS) $(INC) -c -o $@ tests/stubs/bootstrap_dispatch_stub.c

$(TOML_O): vendor/tomlc99/toml.c vendor/tomlc99/toml.h
$(CC) $(VENDOR_CFLAGS) $(INC) -c -o $@ $<

Expand Down Expand Up @@ -547,6 +551,22 @@ test_rate_limit: tests/test_rate_limit.c src/gateway/rate_limit.c src/gateway/ra
$(CC) $(CFLAGS) $(LDFLAGS) $(INC) -pthread -o $(BINDIR)/$@ tests/test_rate_limit.c src/gateway/rate_limit.c -pthread
$(DSYM_SCRIPT)

RELOAD_TEST_O := $(BINDIR)/reload_test.o

$(RELOAD_TEST_O): src/core/reload.c src/core/reload.h src/core/bootstrap.h src/core/config.h src/channels/channel.h src/channels/heartbeat.h src/providers/provider.h src/tools/tool.h
@mkdir -p $(BINDIR)
$(CC) $(CFLAGS) -ffunction-sections -fdata-sections $(INC) -c -o $@ src/core/reload.c

test_reload: tests/test_reload.c $(RELOAD_TEST_O) $(CONFIG_O) $(TOML_O)
@mkdir -p $(BINDIR)
$(CC) $(CFLAGS) -ffunction-sections $(LDFLAGS) -Wl,--gc-sections $(INC) -o $(BINDIR)/$@ tests/test_reload.c $(RELOAD_TEST_O) $(CONFIG_O) $(TOML_O) $(LDLIBS)
$(DSYM_SCRIPT)

test_dispatch: tests/test_dispatch.c $(DISPATCH_O) $(BOOTSTRAP_DISPATCH_STUB_O) $(AGENT_O) $(ROUTER_O) $(STUB_O) $(ANTHROPIC_O) $(OPENAI_COMPAT_O) $(OPENAI_O) $(LOCAL_O) $(PROVIDER_COMMON_O) $(MEMORY_O) $(SQLITE3_O) $(SKILL_O) $(CONFIG_O) $(TOML_O) $(CJSON_O)
@mkdir -p $(BINDIR)
$(CC) $(CFLAGS) $(LDFLAGS) $(INC) -o $(BINDIR)/$@ tests/test_dispatch.c $(DISPATCH_O) $(BOOTSTRAP_DISPATCH_STUB_O) $(AGENT_O) $(ROUTER_O) $(STUB_O) $(ANTHROPIC_O) $(OPENAI_COMPAT_O) $(OPENAI_O) $(LOCAL_O) $(PROVIDER_COMMON_O) $(MEMORY_O) $(SQLITE3_O) $(SKILL_O) $(CONFIG_O) $(TOML_O) $(CJSON_O) $(LDLIBS) -pthread
$(DSYM_SCRIPT)

test_daemon_smoke: shellclaw
@chmod +x tests/test_daemon_smoke.sh scripts/install.sh scripts/update.sh
SHELLCLAW_TEST_BIN="$(BINDIR)/shellclaw" ./tests/test_daemon_smoke.sh
Expand Down Expand Up @@ -577,7 +597,7 @@ static:
--suppress=constParameterCallback \
-q src/

test: test_config test_memory test_skill test_provider test_anthropic test_openai test_local_provider test_router test_heartbeat test_agent test_channel test_cli test_shell test_file test_telegram test_discord_helpers test_web_search test_cron test_context test_crypto test_hardware_stub test_ws test_manifest $(ASAP_UNIT_TESTS) test_sandbox test_allowlist test_rate_limit test_daemon_smoke test_update_script test_install_script test_web_dashboard
test: test_config test_memory test_skill test_provider test_anthropic test_openai test_local_provider test_router test_heartbeat test_agent test_channel test_cli test_shell test_file test_telegram test_discord_helpers test_web_search test_cron test_context test_crypto test_hardware_stub test_ws test_manifest $(ASAP_UNIT_TESTS) test_sandbox test_allowlist test_rate_limit test_reload test_dispatch test_daemon_smoke test_update_script test_install_script test_web_dashboard
$(BINDIR)/test_config
$(BINDIR)/test_memory
$(BINDIR)/test_skill
Expand Down Expand Up @@ -605,6 +625,8 @@ test: test_config test_memory test_skill test_provider test_anthropic test_opena
$(BINDIR)/test_sandbox
$(BINDIR)/test_allowlist
$(BINDIR)/test_rate_limit
$(BINDIR)/test_reload
$(BINDIR)/test_dispatch
$(MAKE) test_install_script
$(MAKE) test_web_dashboard
$(MAKE) test_auth && $(BINDIR)/test_auth
Expand All @@ -616,7 +638,7 @@ COVERAGE_DIR := build/coverage
COVERAGE_MIN := 80

coverage: clean
$(MAKE) BUILD=coverage GATEWAY=0 test_config test_memory test_skill test_provider test_anthropic test_openai test_local_provider test_router test_heartbeat test_agent test_channel test_cli test_shell test_file test_telegram test_discord_helpers test_web_search test_cron test_context test_crypto test_hardware_stub test_ws test_manifest $(ASAP_UNIT_TESTS) test_sandbox test_allowlist test_rate_limit test_auth
$(MAKE) BUILD=coverage GATEWAY=0 test_config test_memory test_skill test_provider test_anthropic test_openai test_local_provider test_router test_heartbeat test_agent test_channel test_cli test_shell test_file test_telegram test_discord_helpers test_web_search test_cron test_context test_crypto test_hardware_stub test_ws test_manifest $(ASAP_UNIT_TESTS) test_sandbox test_allowlist test_rate_limit test_reload test_dispatch test_auth
@if [ "$(GATEWAY)" = "1" ]; then $(MAKE) BUILD=coverage GATEWAY=1 shellclaw test_gateway_http test_static; fi
@chmod +x scripts/coverage.sh
@BINDIR=$(BINDIR) COVERAGE_DIR=$(COVERAGE_DIR) COVERAGE_MIN=$(COVERAGE_MIN) GATEWAY=$(GATEWAY) ./scripts/coverage.sh
Expand All @@ -630,5 +652,5 @@ clean: clean-root-dsym
rm -f $(OBJS) $(PROVIDER_COMMON_O) $(STUB_O) $(ANTHROPIC_O) $(OPENAI_COMPAT_O) $(OPENAI_O) $(LOCAL_O) $(ROUTER_O) $(CJSON_O) $(ANTHROPIC_TEST_O) $(OPENAI_TEST_O) $(LOCAL_TEST_O) $(CONTEXT_TEST_OBJS) $(HEARTBEAT_TEST_O) $(CHANNEL_TG_TEST_O) $(CHANNEL_COMMON_O) $(CHANNEL_STUB_O) $(CHANNEL_CLI_O) $(CHANNEL_TG_O) $(CHANNEL_DISCORD_O) $(DISCORD_HELPERS_O) $(CHANNEL_HEARTBEAT_O) $(CHANNEL_WEBCHAT_O) $(AUTH_O) $(STATIC_O) $(HTTP_O) $(HTTP_LWS_O) $(ROUTES_O) $(WS_O) $(MANIFEST_O) $(ENVELOPE_O) $(ULID_O) $(CLIENT_O) $(ASAP_REGISTRY_O) $(SERVER_O) $(ASAP_LOG_O) $(RATE_LIMIT_O) $(SHELL_O) $(WEBSEARCH_O) $(FILE_O) $(REGISTRY_O) $(CONTEXT_O) $(CONTEXT_CACHE_O) $(CONTEXT_HTTP_O) $(CONTEXT_GEO_O) $(CRYPTO_O) $(HARDWARE_STUB_O) $(CRON_O) $(ASAP_INVOKE_O) $(SANDBOX_O) $(ALLOWLIST_O)
rm -f src/gateway/ui_assets.h
find . -name '*.gcno' -o -name '*.gcda' -o -name '*.gcov' | xargs rm -f 2>/dev/null || true
rm -f $(WS_TEST_O) $(BINDIR)/asap_registry_test.o $(BINDIR)/asap_invoke_test.o $(CONTEXT_TEST_OBJS) $(HEARTBEAT_TEST_O) $(BINDIR)/shellclaw $(BINDIR)/test_config $(BINDIR)/test_memory $(BINDIR)/test_skill $(BINDIR)/test_provider $(BINDIR)/test_anthropic $(BINDIR)/test_openai $(BINDIR)/test_local_provider $(BINDIR)/test_router $(BINDIR)/test_heartbeat $(BINDIR)/test_crypto $(BINDIR)/test_hardware_stub $(BINDIR)/test_ws $(BINDIR)/test_agent $(BINDIR)/test_channel $(BINDIR)/test_cli $(BINDIR)/test_shell $(BINDIR)/test_file $(BINDIR)/test_telegram $(BINDIR)/test_discord_helpers $(BINDIR)/test_web_search $(BINDIR)/test_cron $(BINDIR)/test_context $(BINDIR)/test_manifest $(BINDIR)/test_asap_envelope $(BINDIR)/test_asap_ulid $(BINDIR)/test_asap_client $(BINDIR)/test_asap_registry $(BINDIR)/test_asap_server $(BINDIR)/test_asap_invoke $(BINDIR)/test_asap_log $(BINDIR)/test_auth $(BINDIR)/test_gateway_http $(BINDIR)/test_static $(BINDIR)/test_sandbox $(BINDIR)/test_allowlist $(BINDIR)/test_rate_limit
rm -f $(WS_TEST_O) $(BINDIR)/asap_registry_test.o $(BINDIR)/asap_invoke_test.o $(CONTEXT_TEST_OBJS) $(HEARTBEAT_TEST_O) $(BINDIR)/shellclaw $(BINDIR)/test_config $(BINDIR)/test_memory $(BINDIR)/test_skill $(BINDIR)/test_provider $(BINDIR)/test_anthropic $(BINDIR)/test_openai $(BINDIR)/test_local_provider $(BINDIR)/test_router $(BINDIR)/test_heartbeat $(BINDIR)/test_crypto $(BINDIR)/test_hardware_stub $(BINDIR)/test_ws $(BINDIR)/test_agent $(BINDIR)/test_channel $(BINDIR)/test_cli $(BINDIR)/test_shell $(BINDIR)/test_file $(BINDIR)/test_telegram $(BINDIR)/test_discord_helpers $(BINDIR)/test_web_search $(BINDIR)/test_cron $(BINDIR)/test_context $(BINDIR)/test_manifest $(BINDIR)/test_asap_envelope $(BINDIR)/test_asap_ulid $(BINDIR)/test_asap_client $(BINDIR)/test_asap_registry $(BINDIR)/test_asap_server $(BINDIR)/test_asap_invoke $(BINDIR)/test_asap_log $(BINDIR)/test_auth $(BINDIR)/test_gateway_http $(BINDIR)/test_static $(BINDIR)/test_sandbox $(BINDIR)/test_allowlist $(BINDIR)/test_rate_limit $(BINDIR)/test_dispatch $(BOOTSTRAP_DISPATCH_STUB_O)
rm -rf $(BINDIR)/*.dSYM $(DSYMDIR)
75 changes: 75 additions & 0 deletions tests/stubs/bootstrap_dispatch_stub.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* @file bootstrap_dispatch_stub.c
* @brief Minimal bootstrap surface for dispatch unit tests (avoids full subsystem init).
*/
#define _POSIX_C_SOURCE 200809L

#include "core/bootstrap.h"
#include "providers/provider.h"
#include "tools/tool.h"
#include <stdio.h>
#include <string.h>

#define MAX_TOOLS 8

static config_t *g_cfg;
static const provider_t *g_provider;
static const tool_t *g_tools[MAX_TOOLS];
static size_t g_tool_count;
static char g_config_path[512];

config_t *bootstrap_get_cfg(void)
{
return g_cfg;
}

void bootstrap_set_cfg(config_t *cfg)
{
g_cfg = cfg;
}

void bootstrap_set_config_path(const char *path)
{
if (path != NULL)
snprintf(g_config_path, sizeof(g_config_path), "%s", path);
else
g_config_path[0] = '\0';
}

const char *bootstrap_get_config_path(void)
{
return (g_config_path[0] != '\0') ? g_config_path : NULL;
}

const provider_t *bootstrap_get_provider(void)
{
return g_provider;
}

void bootstrap_set_provider_for_test(const provider_t *provider)
{
g_provider = provider;
}

size_t bootstrap_tool_count(void)
{
return g_tool_count;
}

const tool_t *bootstrap_tool_at(size_t index)
{
if (index >= g_tool_count)
return NULL;
return g_tools[index];
}

void bootstrap_reset_tools_for_test(void)
{
g_tool_count = 0;
}

void bootstrap_add_tool_for_test(const tool_t *tool)
{
if (tool != NULL && g_tool_count < MAX_TOOLS)
g_tools[g_tool_count++] = tool;
}
6 changes: 6 additions & 0 deletions tests/test_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ int main(void)
tool_context_set_config(NULL);
tool_context_test_set_http_bodies(GEO_OK, WX_A, HY_OK);
CHECK(tool_context_get()->execute("{}", out1, sizeof(out1)) == 0, "snapshot priming exec");
{
char tiny[80];
CHECK(tool_context_get()->execute("{}", tiny, sizeof(tiny)) == -1,
"tiny buffer must fail");
CHECK(strstr(tiny, "too large") != NULL, "expects buffer size error");
}
{
char *snap = tool_context_snapshot_json();
CHECK(snap != NULL, "snapshot_json alloc");
Expand Down
Loading
Loading