Skip to content

Commit af44c0a

Browse files
move all providers to use fasthttp even for streaming
1 parent df11c92 commit af44c0a

File tree

20 files changed

+1058
-749
lines changed

20 files changed

+1058
-749
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,7 @@ go.work.sum
3535
*.db-shm
3636
*.db-wal
3737

38+
# Test reports
39+
test-reports/
40+
3841
.claude

Makefile

Lines changed: 216 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ BLUE=\033[0;34m
1616
CYAN=\033[0;36m
1717
NC=\033[0m # No Color
1818

19-
.PHONY: all help dev build-ui build run install-air clean test install-ui setup-workspace work-init work-clean docs build-docker-image cleanup-enterprise deploy-to-fly-io
19+
# Test reporting settings
20+
TEST_REPORTS_DIR ?= test-reports
21+
GOTESTSUM_FORMAT ?= testname
22+
TEST_REPORT_FORMAT ?= html
23+
24+
.PHONY: all help dev build-ui build run install-air clean clean-test-reports generate-html-reports test test-core test-plugins test-all install-ui setup-workspace work-init work-clean docs build-docker-image cleanup-enterprise deploy-to-fly-io install-gotestsum install-junit-viewer
2025

2126
all: help
2227

@@ -30,9 +35,13 @@ help: ## Show this help message
3035
@echo " HOST Server host (default: localhost)"
3136
@echo " PORT Server port (default: 8080)"
3237
@echo " PROMETHEUS_LABELS Labels for Prometheus metrics"
33-
@echo " LOG_STYLE Logger output format: json|pretty (default: json)"
34-
@echo " LOG_LEVEL Logger level: debug|info|warn|error (default: info)"
38+
@echo " LOG_STYLE Logger output format: json|pretty (default: json)"
39+
@echo " LOG_LEVEL Logger level: debug|info|warn|error (default: info)"
3540
@echo " APP_DIR App data directory inside container (default: /app/data)"
41+
@echo ""
42+
@echo "$(YELLOW)Test Configuration:$(NC)"
43+
@echo " TEST_REPORTS_DIR Directory for HTML test reports (default: test-reports)"
44+
@echo " GOTESTSUM_FORMAT Test output format: testname|dots|pkgname|standard-verbose (default: testname)"
3645

3746
cleanup-enterprise: ## Clean up enterprise directories if present
3847
@echo "$(GREEN)Cleaning up enterprise...$(NC)"
@@ -51,6 +60,28 @@ install-air: ## Install air for hot reloading (if not already installed)
5160
@which air > /dev/null || (echo "$(YELLOW)Installing air for hot reloading...$(NC)" && go install github.com/air-verse/air@latest)
5261
@echo "$(GREEN)Air is ready$(NC)"
5362

63+
install-gotestsum: ## Install gotestsum for test reporting (if not already installed)
64+
@which gotestsum > /dev/null || (echo "$(YELLOW)Installing gotestsum for test reporting...$(NC)" && go install gotest.tools/gotestsum@latest)
65+
@echo "$(GREEN)gotestsum is ready$(NC)"
66+
67+
install-junit-viewer: ## Install junit-viewer for HTML report generation (if not already installed)
68+
@if [ -z "$$CI" ] && [ -z "$$GITHUB_ACTIONS" ] && [ -z "$$GITLAB_CI" ] && [ -z "$$CIRCLECI" ] && [ -z "$$JENKINS_HOME" ]; then \
69+
if which junit-viewer > /dev/null 2>&1; then \
70+
echo "$(GREEN)junit-viewer is already installed$(NC)"; \
71+
else \
72+
echo "$(YELLOW)Installing junit-viewer for HTML reports...$(NC)"; \
73+
if npm install -g junit-viewer 2>&1; then \
74+
echo "$(GREEN)junit-viewer installed successfully$(NC)"; \
75+
else \
76+
echo "$(RED)Failed to install junit-viewer. HTML reports will be skipped.$(NC)"; \
77+
echo "$(YELLOW)You can install it manually: npm install -g junit-viewer$(NC)"; \
78+
exit 0; \
79+
fi; \
80+
fi \
81+
else \
82+
echo "$(YELLOW)CI environment detected, skipping junit-viewer installation$(NC)"; \
83+
fi
84+
5485
dev: install-ui install-air setup-workspace ## Start complete development environment (UI + API with proxy)
5586
@echo "$(GREEN)Starting Bifrost complete development environment...$(NC)"
5687
@echo "$(YELLOW)This will start:$(NC)"
@@ -110,25 +141,201 @@ clean: ## Clean build artifacts and temporary files
110141
@rm -rf tmp/
111142
@rm -f transports/bifrost-http/build-errors.log
112143
@rm -rf transports/bifrost-http/tmp/
144+
@rm -rf $(TEST_REPORTS_DIR)/
113145
@echo "$(GREEN)Clean complete$(NC)"
114146

115-
test: ## Run tests for bifrost-http
147+
clean-test-reports: ## Clean test reports only
148+
@echo "$(YELLOW)Cleaning test reports...$(NC)"
149+
@rm -rf $(TEST_REPORTS_DIR)/
150+
@echo "$(GREEN)Test reports cleaned$(NC)"
151+
152+
generate-html-reports: ## Convert existing XML reports to HTML
153+
@if ! which junit-viewer > /dev/null 2>&1; then \
154+
echo "$(RED)Error: junit-viewer not installed$(NC)"; \
155+
echo "$(YELLOW)Install with: make install-junit-viewer$(NC)"; \
156+
exit 1; \
157+
fi
158+
@echo "$(GREEN)Converting XML reports to HTML...$(NC)"
159+
@if [ ! -d "$(TEST_REPORTS_DIR)" ] || [ -z "$$(ls -A $(TEST_REPORTS_DIR)/*.xml 2>/dev/null)" ]; then \
160+
echo "$(YELLOW)No XML reports found in $(TEST_REPORTS_DIR)$(NC)"; \
161+
echo "$(YELLOW)Run tests first: make test-all$(NC)"; \
162+
exit 0; \
163+
fi
164+
@for xml in $(TEST_REPORTS_DIR)/*.xml; do \
165+
html=$${xml%.xml}.html; \
166+
echo " Converting $$(basename $$xml) → $$(basename $$html)"; \
167+
junit-viewer --results=$$xml --save=$$html 2>/dev/null || true; \
168+
done
169+
@echo ""
170+
@echo "$(GREEN)✓ HTML reports generated$(NC)"
171+
@echo "$(CYAN)View reports:$(NC)"
172+
@ls -1 $(TEST_REPORTS_DIR)/*.html 2>/dev/null | sed 's|$(TEST_REPORTS_DIR)/| open $(TEST_REPORTS_DIR)/|' || true
173+
174+
test: install-gotestsum ## Run tests for bifrost-http
116175
@echo "$(GREEN)Running bifrost-http tests...$(NC)"
117-
@cd transports/bifrost-http && GOWORK=off go test -v ./...
176+
@mkdir -p $(TEST_REPORTS_DIR)
177+
@cd transports/bifrost-http && GOWORK=off gotestsum \
178+
--format=$(GOTESTSUM_FORMAT) \
179+
--junitfile=../../$(TEST_REPORTS_DIR)/bifrost-http.xml \
180+
-- -v ./...
181+
@if [ -z "$$CI" ] && [ -z "$$GITHUB_ACTIONS" ] && [ -z "$$GITLAB_CI" ] && [ -z "$$CIRCLECI" ] && [ -z "$$JENKINS_HOME" ]; then \
182+
if which junit-viewer > /dev/null 2>&1; then \
183+
echo "$(YELLOW)Generating HTML report...$(NC)"; \
184+
if junit-viewer --results=$(TEST_REPORTS_DIR)/bifrost-http.xml --save=$(TEST_REPORTS_DIR)/bifrost-http.html 2>/dev/null; then \
185+
echo ""; \
186+
echo "$(CYAN)HTML report: $(TEST_REPORTS_DIR)/bifrost-http.html$(NC)"; \
187+
echo "$(CYAN)Open with: open $(TEST_REPORTS_DIR)/bifrost-http.html$(NC)"; \
188+
else \
189+
echo "$(YELLOW)HTML generation failed. JUnit XML report available.$(NC)"; \
190+
echo "$(CYAN)JUnit XML report: $(TEST_REPORTS_DIR)/bifrost-http.xml$(NC)"; \
191+
fi; \
192+
else \
193+
echo ""; \
194+
echo "$(YELLOW)junit-viewer not installed. Install with: make install-junit-viewer$(NC)"; \
195+
echo "$(CYAN)JUnit XML report: $(TEST_REPORTS_DIR)/bifrost-http.xml$(NC)"; \
196+
fi \
197+
else \
198+
echo ""; \
199+
echo "$(CYAN)JUnit XML report: $(TEST_REPORTS_DIR)/bifrost-http.xml$(NC)"; \
200+
fi
118201

119-
test-core: ## Run core tests
202+
test-core: install-gotestsum ## Run core tests (Usage: make test-core PROVIDER=anthropic TESTCASE=SimpleChat)
120203
@echo "$(GREEN)Running core tests...$(NC)"
121-
@cd core && go test -v ./...
204+
@mkdir -p $(TEST_REPORTS_DIR)
205+
@if [ -n "$(PROVIDER)" ]; then \
206+
echo "$(CYAN)Running tests for provider: $(PROVIDER)$(NC)"; \
207+
if [ ! -f "tests/core-providers/$(PROVIDER)_test.go" ]; then \
208+
echo "$(RED)Error: Provider test file '$(PROVIDER)_test.go' not found$(NC)"; \
209+
echo "$(YELLOW)Available providers:$(NC)"; \
210+
ls tests/core-providers/*_test.go 2>/dev/null | grep -v cross_provider | xargs -n 1 basename | sed 's/_test\.go//' | sed 's/^/ - /'; \
211+
exit 1; \
212+
fi; \
213+
fi; \
214+
if [ -f .env ]; then \
215+
echo "$(YELLOW)Loading environment variables from .env...$(NC)"; \
216+
set -a; . ./.env; set +a; \
217+
fi; \
218+
if [ -n "$(PROVIDER)" ]; then \
219+
PROVIDER_TEST_NAME=$$(echo "$(PROVIDER)" | awk '{print toupper(substr($$0,1,1)) tolower(substr($$0,2))}' | sed 's/openai/OpenAI/i; s/sgl/SGL/i'); \
220+
if [ -n "$(TESTCASE)" ]; then \
221+
echo "$(CYAN)Running Test$${PROVIDER_TEST_NAME}/$${PROVIDER_TEST_NAME}Tests/$(TESTCASE)...$(NC)"; \
222+
cd tests/core-providers && GOWORK=off gotestsum \
223+
--format=$(GOTESTSUM_FORMAT) \
224+
--junitfile=../../$(TEST_REPORTS_DIR)/core-$(PROVIDER)-$(TESTCASE).xml \
225+
-- -v -run "^Test$${PROVIDER_TEST_NAME}$$/.*Tests/$(TESTCASE)$$"; \
226+
if [ -z "$$CI" ] && [ -z "$$GITHUB_ACTIONS" ] && [ -z "$$GITLAB_CI" ] && [ -z "$$CIRCLECI" ] && [ -z "$$JENKINS_HOME" ]; then \
227+
if which junit-viewer > /dev/null 2>&1; then \
228+
echo "$(YELLOW)Generating HTML report...$(NC)"; \
229+
junit-viewer --results=../../$(TEST_REPORTS_DIR)/core-$(PROVIDER)-$(TESTCASE).xml --save=../../$(TEST_REPORTS_DIR)/core-$(PROVIDER)-$(TESTCASE).html 2>/dev/null || true; \
230+
echo ""; \
231+
echo "$(CYAN)HTML report: $(TEST_REPORTS_DIR)/core-$(PROVIDER)-$(TESTCASE).html$(NC)"; \
232+
echo "$(CYAN)Open with: open $(TEST_REPORTS_DIR)/core-$(PROVIDER)-$(TESTCASE).html$(NC)"; \
233+
else \
234+
echo ""; \
235+
echo "$(CYAN)JUnit XML report: $(TEST_REPORTS_DIR)/core-$(PROVIDER)-$(TESTCASE).xml$(NC)"; \
236+
fi; \
237+
else \
238+
echo ""; \
239+
echo "$(CYAN)JUnit XML report: $(TEST_REPORTS_DIR)/core-$(PROVIDER)-$(TESTCASE).xml$(NC)"; \
240+
fi; \
241+
else \
242+
echo "$(CYAN)Running Test$${PROVIDER_TEST_NAME}...$(NC)"; \
243+
cd tests/core-providers && GOWORK=off gotestsum \
244+
--format=$(GOTESTSUM_FORMAT) \
245+
--junitfile=../../$(TEST_REPORTS_DIR)/core-$(PROVIDER).xml \
246+
-- -v -run "^Test$${PROVIDER_TEST_NAME}$$"; \
247+
if [ -z "$$CI" ] && [ -z "$$GITHUB_ACTIONS" ] && [ -z "$$GITLAB_CI" ] && [ -z "$$CIRCLECI" ] && [ -z "$$JENKINS_HOME" ]; then \
248+
if which junit-viewer > /dev/null 2>&1; then \
249+
echo "$(YELLOW)Generating HTML report...$(NC)"; \
250+
junit-viewer --results=../../$(TEST_REPORTS_DIR)/core-$(PROVIDER).xml --save=../../$(TEST_REPORTS_DIR)/core-$(PROVIDER).html 2>/dev/null || true; \
251+
echo ""; \
252+
echo "$(CYAN)HTML report: $(TEST_REPORTS_DIR)/core-$(PROVIDER).html$(NC)"; \
253+
echo "$(CYAN)Open with: open $(TEST_REPORTS_DIR)/core-$(PROVIDER).html$(NC)"; \
254+
else \
255+
echo ""; \
256+
echo "$(CYAN)JUnit XML report: $(TEST_REPORTS_DIR)/core-$(PROVIDER).xml$(NC)"; \
257+
fi; \
258+
else \
259+
echo ""; \
260+
echo "$(CYAN)JUnit XML report: $(TEST_REPORTS_DIR)/core-$(PROVIDER).xml$(NC)"; \
261+
fi; \
262+
fi \
263+
else \
264+
if [ -n "$(TESTCASE)" ]; then \
265+
echo "$(RED)Error: TESTCASE requires PROVIDER to be specified$(NC)"; \
266+
echo "$(YELLOW)Usage: make test-core PROVIDER=anthropic TESTCASE=SimpleChat$(NC)"; \
267+
exit 1; \
268+
fi; \
269+
cd tests/core-providers && GOWORK=off gotestsum \
270+
--format=$(GOTESTSUM_FORMAT) \
271+
--junitfile=../../$(TEST_REPORTS_DIR)/core-all.xml \
272+
-- -v ./...; \
273+
if [ -z "$$CI" ] && [ -z "$$GITHUB_ACTIONS" ] && [ -z "$$GITLAB_CI" ] && [ -z "$$CIRCLECI" ] && [ -z "$$JENKINS_HOME" ]; then \
274+
if which junit-viewer > /dev/null 2>&1; then \
275+
echo "$(YELLOW)Generating HTML report...$(NC)"; \
276+
junit-viewer --results=../../$(TEST_REPORTS_DIR)/core-all.xml --save=../../$(TEST_REPORTS_DIR)/core-all.html 2>/dev/null || true; \
277+
echo ""; \
278+
echo "$(CYAN)HTML report: $(TEST_REPORTS_DIR)/core-all.html$(NC)"; \
279+
echo "$(CYAN)Open with: open $(TEST_REPORTS_DIR)/core-all.html$(NC)"; \
280+
else \
281+
echo ""; \
282+
echo "$(CYAN)JUnit XML report: $(TEST_REPORTS_DIR)/core-all.xml$(NC)"; \
283+
fi; \
284+
else \
285+
echo ""; \
286+
echo "$(CYAN)JUnit XML report: $(TEST_REPORTS_DIR)/core-all.xml$(NC)"; \
287+
fi; \
288+
fi
122289

123-
test-plugins: ## Run plugin tests
290+
test-plugins: install-gotestsum ## Run plugin tests
124291
@echo "$(GREEN)Running plugin tests...$(NC)"
292+
@mkdir -p $(TEST_REPORTS_DIR)
125293
@cd plugins && find . -name "*.go" -path "*/tests/*" -o -name "*_test.go" | head -1 > /dev/null && \
126294
for dir in $$(find . -name "*_test.go" -exec dirname {} \; | sort -u); do \
295+
plugin_name=$$(echo $$dir | sed 's|^\./||' | sed 's|/|-|g'); \
127296
echo "Testing $$dir..."; \
128-
cd $$dir && go test -v ./... && cd - > /dev/null; \
297+
cd $$dir && gotestsum \
298+
--format=$(GOTESTSUM_FORMAT) \
299+
--junitfile=../../$(TEST_REPORTS_DIR)/plugin-$$plugin_name.xml \
300+
-- -v ./... && cd - > /dev/null; \
301+
if [ -z "$$CI" ] && [ -z "$$GITHUB_ACTIONS" ] && [ -z "$$GITLAB_CI" ] && [ -z "$$CIRCLECI" ] && [ -z "$$JENKINS_HOME" ]; then \
302+
if which junit-viewer > /dev/null 2>&1; then \
303+
echo "$(YELLOW)Generating HTML report for $$plugin_name...$(NC)"; \
304+
junit-viewer --results=../$(TEST_REPORTS_DIR)/plugin-$$plugin_name.xml --save=../$(TEST_REPORTS_DIR)/plugin-$$plugin_name.html 2>/dev/null || true; \
305+
fi; \
306+
fi; \
129307
done || echo "No plugin tests found"
308+
@echo ""
309+
@if [ -z "$$CI" ] && [ -z "$$GITHUB_ACTIONS" ] && [ -z "$$GITLAB_CI" ] && [ -z "$$CIRCLECI" ] && [ -z "$$JENKINS_HOME" ]; then \
310+
echo "$(CYAN)HTML reports saved to $(TEST_REPORTS_DIR)/plugin-*.html$(NC)"; \
311+
else \
312+
echo "$(CYAN)JUnit XML reports saved to $(TEST_REPORTS_DIR)/plugin-*.xml$(NC)"; \
313+
fi
130314

131315
test-all: test-core test-plugins test ## Run all tests
316+
@echo ""
317+
@echo "$(GREEN)═══════════════════════════════════════════════════════════$(NC)"
318+
@echo "$(GREEN) All Tests Complete - Summary $(NC)"
319+
@echo "$(GREEN)═══════════════════════════════════════════════════════════$(NC)"
320+
@echo ""
321+
@if [ -z "$$CI" ] && [ -z "$$GITHUB_ACTIONS" ] && [ -z "$$GITLAB_CI" ] && [ -z "$$CIRCLECI" ] && [ -z "$$JENKINS_HOME" ]; then \
322+
echo "$(YELLOW)Generating combined HTML report...$(NC)"; \
323+
junit-viewer --results=$(TEST_REPORTS_DIR) --save=$(TEST_REPORTS_DIR)/index.html 2>/dev/null || true; \
324+
echo ""; \
325+
echo "$(CYAN)HTML reports available in $(TEST_REPORTS_DIR)/:$(NC)"; \
326+
ls -1 $(TEST_REPORTS_DIR)/*.html 2>/dev/null | sed 's/^/ ✓ /' || echo " No reports found"; \
327+
echo ""; \
328+
echo "$(YELLOW)📊 View all test results:$(NC)"; \
329+
echo "$(CYAN) open $(TEST_REPORTS_DIR)/index.html$(NC)"; \
330+
echo ""; \
331+
echo "$(YELLOW)Or view individual reports:$(NC)"; \
332+
ls -1 $(TEST_REPORTS_DIR)/*.html 2>/dev/null | grep -v index.html | sed 's|$(TEST_REPORTS_DIR)/| open $(TEST_REPORTS_DIR)/|' || true; \
333+
echo ""; \
334+
else \
335+
echo "$(CYAN)JUnit XML reports available in $(TEST_REPORTS_DIR)/:$(NC)"; \
336+
ls -1 $(TEST_REPORTS_DIR)/*.xml 2>/dev/null | sed 's/^/ ✓ /' || echo " No reports found"; \
337+
echo ""; \
338+
fi
132339

133340
# Quick start with example config
134341
quick-start: ## Quick start with example config and maxim plugin

0 commit comments

Comments
 (0)