Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
714 lines (615 loc) · 25.6 KB
/
Copy pathMakefile
File metadata and controls
714 lines (615 loc) · 25.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
# =============================================================================
# TelemetryFlow Hermes - Makefile
# =============================================================================
#
# TelemetryFlow Hermes — Self-Improving AI Agent for Observability
# Copyright (c) 2024-2026 Telemetri Data Indonesia. All rights reserved.
#
# This Makefile provides standardized commands for development, testing,
# deployment, and CI/CD of TelemetryFlow Hermes multi-agent integration.
#
# QUICK START:
# make init # First-time setup (install hermes + configure + deploy)
# make verify # Check everything is working
# make doctor # Health check + auto-fix
#
# =============================================================================
# Build variables
PACKAGE_NAME := telemetryflow-hermes
VERSION := $(shell python3 -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])" 2>/dev/null || echo "3.0.0")
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown")
BUILD_TIME := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ' 2>/dev/null || echo "unknown")
PYTHON_VERSION := $(shell python3 --version 2>&1 | cut -d ' ' -f 2)
# Paths
HERMES_HOME ?= $(HOME)/.hermes
PROJECT_DIR := $(shell pwd)
BUILD_DIR := build
DIST_DIR := dist
PLUGINS_DIR := plugins
TESTS_DIR := tests
COVERAGE_SOURCE := plugins/telemetryflow/tools
ENV_FILE := $(HERMES_HOME)/.env
# Tools
PYTHON := python3
PIP := pip3
PYTEST := pytest
RUFF := ruff
MYPY := mypy
# Colors for output
RED := \033[0;31m
GREEN := \033[0;32m
YELLOW := \033[0;33m
BLUE := \033[0;34m
NC := \033[0m
# Default target
.DEFAULT_GOAL := help
# =============================================================================
# Help
# =============================================================================
.PHONY: help
help: ## Show this help message
@echo "$(BLUE)TelemetryFlow Hermes - Makefile$(NC)"
@echo ""
@echo "$(YELLOW)Setup & Deploy:$(NC)"
@echo " $(GREEN)make init$(NC) # First-time setup (install → env → configure → deploy)"
@echo " $(GREEN)make configure$(NC) # Copy .env + install config, profiles, skills, plugins"
@echo " $(GREEN)make deploy$(NC) # Start all 4 Telegram gateways"
@echo " $(GREEN)make verify$(NC) # End-to-end verification"
@echo " $(GREEN)make doctor$(NC) # Health check + auto-fix"
@echo ""
@echo "$(YELLOW)Docker:$(NC)"
@echo " $(GREEN)make docker-build$(NC) # Build Docker image"
@echo " $(GREEN)make docker-up$(NC) # Start Hermes container"
@echo " $(GREEN)make docker-down$(NC) # Stop all containers"
@echo ""
@echo "$(YELLOW)Development:$(NC)"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " $(GREEN)%-30s$(NC) %s\n", $$1, $$2}' $(MAKEFILE_LIST)
@echo ""
@echo "$(YELLOW)Variables:$(NC)"
@echo " VERSION = $(VERSION)"
@echo " GIT_COMMIT = $(GIT_COMMIT)"
@echo " GIT_BRANCH = $(GIT_BRANCH)"
@echo " HERMES_HOME = $(HERMES_HOME)"
@echo " PYTHON = $(PYTHON_VERSION)"
@echo " PYTEST = $(shell $(PYTEST) --version 2>/dev/null | head -1 || echo 'not installed')"
@echo " RUFF = $(shell $(RUFF) --version 2>/dev/null || echo 'not installed')"
# =============================================================================
# Setup & Deploy (Main Targets)
# =============================================================================
.PHONY: init
init: install configure ## First-time setup: install hermes, configure, deploy everything
@echo ""
@echo "$(GREEN)========================================$(NC)"
@echo "$(GREEN) TelemetryFlow Hermes is ready!$(NC)"
@echo "$(GREEN)========================================$(NC)"
@echo ""
@echo "Next steps:"
@echo " 1. Edit $(ENV_FILE) with your API keys"
@echo " 2. make verify # check everything works"
@echo " 3. make deploy # start the agent gateways"
.PHONY: install
install: ## Install Hermes Agent framework
@echo "$(BLUE)Installing Hermes Agent...$(NC)"
@command -v hermes >/dev/null 2>&1 && { \
echo "$(GREEN)Hermes already installed: $$(hermes --version 2>/dev/null || echo 'unknown')$(NC)"; \
} || { \
curl -fsSL https://raw.githubusercontent.com/NousResearch/hermes-agent/main/scripts/install.sh | bash; \
echo "$(GREEN)Hermes installed. Run: source ~/.bashrc$(NC)"; \
}
.PHONY: configure
configure: env profiles skills plugins cron hooks ## Configure hermes home (env, profiles, skills, plugins, cron, hooks)
@echo "$(GREEN)Configuration complete.$(NC)"
.PHONY: env
env: ## Setup .env file from .env.example
@echo "$(BLUE)Setting up environment...$(NC)"
@mkdir -p $(HERMES_HOME)
@if [ ! -f $(ENV_FILE) ]; then \
cp .env.example $(ENV_FILE); \
echo "$(YELLOW)Created $(ENV_FILE) from .env.example$(NC)"; \
echo "$(YELLOW)Edit it with your API keys before deploying.$(NC)"; \
else \
echo "$(GREEN)$(ENV_FILE) already exists$(NC)"; \
fi
@if [ ! -f $(HERMES_HOME)/config.yaml ]; then \
cp config.yaml $(HERMES_HOME)/config.yaml; \
echo "$(GREEN)Installed config.yaml$(NC)"; \
fi
@if [ ! -f $(HERMES_HOME)/SOUL.md ]; then \
cp SOUL.md $(HERMES_HOME)/SOUL.md; \
echo "$(GREEN)Installed SOUL.md$(NC)"; \
fi
.PHONY: profiles
profiles: ## Create 4 agent profiles (triage, investigator, reviewer, remediator)
@echo "$(BLUE)Installing agent profiles...$(NC)"
@for profile in triage investigator reviewer remediator; do \
if [ -d "$(HERMES_HOME)/profiles/$$profile" ]; then \
echo " [skip] $$profile (exists)"; \
else \
mkdir -p "$(HERMES_HOME)/profiles/$$profile"/memories; \
echo " [install] $$profile"; \
fi; \
cp profiles/$$profile/SOUL.md "$(HERMES_HOME)/profiles/$$profile/SOUL.md" 2>/dev/null || true; \
cp profiles/$$profile/config.yaml "$(HERMES_HOME)/profiles/$$profile/config.yaml" 2>/dev/null || true; \
cp profiles/$$profile/memories/MEMORY.md "$(HERMES_HOME)/profiles/$$profile/memories/MEMORY.md" 2>/dev/null || true; \
cp profiles/$$profile/memories/USER.md "$(HERMES_HOME)/profiles/$$profile/memories/USER.md" 2>/dev/null || true; \
done
.PHONY: skills
skills: ## Install all 29 skills (18 categories)
@echo "$(BLUE)Installing skills...$(NC)"
@mkdir -p $(HERMES_HOME)/skills
@for dir in skills/*/; do \
category=$$(basename $$dir); \
mkdir -p "$(HERMES_HOME)/skills/$$category"; \
for skill in skills/$$category/*/; do \
skill_name=$$(basename $$skill); \
cp -r $$skill "$(HERMES_HOME)/skills/$$category/" 2>/dev/null || true; \
done; \
done
@skill_count=$$(find $(HERMES_HOME)/skills -name 'SKILL.md' | wc -l | tr -d ' '); \
echo " Installed $$skill_count skills"
.PHONY: plugins
plugins: ## Install TelemetryFlow plugin (37 tools)
@echo "$(BLUE)Installing TelemetryFlow plugin...$(NC)"
@mkdir -p $(HERMES_HOME)/plugins/telemetryflow
@cp -r plugins/telemetryflow/* $(HERMES_HOME)/plugins/telemetryflow/
@tool_count=$$(ls $(HERMES_HOME)/plugins/telemetryflow/tools/*.py 2>/dev/null | grep -v __pycache__ | wc -l | tr -d ' '); \
echo " Installed $$tool_count tools"
.PHONY: cron
cron: ## Install 6 scheduled investigation jobs
@echo "$(BLUE)Installing cron jobs...$(NC)"
@mkdir -p $(HERMES_HOME)/cron
@cp cron/jobs.json $(HERMES_HOME)/cron/jobs.json
.PHONY: hooks
hooks: ## Install 3 lifecycle hooks
@echo "$(BLUE)Installing lifecycle hooks...$(NC)"
@mkdir -p $(HERMES_HOME)/hooks
@cp hooks/*.sh $(HERMES_HOME)/hooks/
@chmod +x $(HERMES_HOME)/hooks/*.sh
.PHONY: telegram
telegram: ## Configure 4 Telegram gateway bots
@echo "$(BLUE)Setting up Telegram gateways...$(NC)"
@bash scripts/setup-telegram.sh
.PHONY: deploy
deploy: ## Start all 4 agent gateways (triage, investigator, reviewer, remediator)
@echo "$(BLUE)Starting agent gateways...$(NC)"
@hermes -p triage gateway start &
@hermes -p investigator gateway start &
@hermes -p reviewer gateway start &
@hermes -p remediator gateway start &
@echo "$(GREEN)All gateways started. Use 'make status' to check.$(NC)"
.PHONY: stop
stop: ## Stop all agent gateways
@echo "$(BLUE)Stopping agent gateways...$(NC)"
@hermes -p triage gateway stop 2>/dev/null || true
@hermes -p investigator gateway stop 2>/dev/null || true
@hermes -p reviewer gateway stop 2>/dev/null || true
@hermes -p remediator gateway stop 2>/dev/null || true
@echo "$(GREEN)All gateways stopped.$(NC)"
.PHONY: status
status: ## Check all 4 gateway statuses
@echo "$(BLUE)Gateway statuses:$(NC)"
@hermes -p triage gateway status 2>/dev/null || echo " triage: not running"
@hermes -p investigator gateway status 2>/dev/null || echo " investigator: not running"
@hermes -p reviewer gateway status 2>/dev/null || echo " reviewer: not running"
@hermes -p remediator gateway status 2>/dev/null || echo " remediator: not running"
.PHONY: verify
verify: ## End-to-end pipeline verification
@echo "$(BLUE)Verifying pipeline...$(NC)"
@bash scripts/verify-pipeline.sh
.PHONY: doctor
doctor: ## Run hermes doctor --fix
@hermes doctor --fix
.PHONY: air-gapped
air-gapped: ## Deploy with Ollama (offline, no external network)
@echo "$(BLUE)Deploying air-gapped configuration...$(NC)"
@bash scripts/deploy-air-gapped.sh
# =============================================================================
# Docker
# =============================================================================
.PHONY: docker-build
docker-build: ## Build Docker image
@echo "$(BLUE)Building Docker image...$(NC)"
docker build \
--build-arg VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
--build-arg GIT_BRANCH=$(GIT_BRANCH) \
--build-arg BUILD_TIME=$(BUILD_TIME) \
-t telemetryflow/telemetryflow-hermes:$(VERSION) \
-t telemetryflow/telemetryflow-hermes:latest \
.
.PHONY: docker-up
docker-up: ## Start Hermes container (use PROFILE=core to include platform)
@echo "$(BLUE)Starting containers...$(NC)"
docker compose --profile $${PROFILE:-} up -d
.PHONY: docker-down
docker-down: ## Stop all containers
@echo "$(BLUE)Stopping containers...$(NC)"
docker compose --profile all down
.PHONY: docker-logs
docker-logs: ## Tail Hermes container logs
docker compose logs -f tfo-hermes
.PHONY: docker-status
docker-status: ## Show container statuses
docker compose ps
# =============================================================================
# Build
# =============================================================================
.PHONY: build
build: ## Build wheel package
@echo "$(BLUE)Building $(PACKAGE_NAME)...$(NC)"
@mkdir -p $(BUILD_DIR)
$(PIP) install build
$(PYTHON) -m build
@echo "$(GREEN)Build complete: $(DIST_DIR)/$(NC)"
.PHONY: build-release
build-release: clean ## Build optimized release package
@echo "$(BLUE)Building release $(PACKAGE_NAME)...$(NC)"
$(PIP) install build
$(PYTHON) -m build
@echo "$(GREEN)Release build complete: $(DIST_DIR)/$(NC)"
# =============================================================================
# Clean
# =============================================================================
.PHONY: clean
clean: ## Remove installed components, build artifacts, and coverage files
@echo "$(BLUE)Cleaning...$(NC)"
rm -rf $(HERMES_HOME)/profiles/triage
rm -rf $(HERMES_HOME)/profiles/investigator
rm -rf $(HERMES_HOME)/profiles/reviewer
rm -rf $(HERMES_HOME)/profiles/remediator
@for dir in $$(ls -d $(HERMES_HOME)/skills/*/ 2>/dev/null); do \
rm -rf $$dir; \
done
rm -rf $(HERMES_HOME)/plugins/telemetryflow
rm -f $(HERMES_HOME)/cron/jobs.json
rm -rf $(BUILD_DIR) $(DIST_DIR)
rm -rf *.egg-info/
rm -rf .pytest_cache/ .mypy_cache/ .ruff_cache/
rm -rf htmlcov/ .coverage coverage.xml coverage-unit.xml coverage-integration.xml
rm -f junit.xml junit-unit.xml junit-integration.xml bandit-results.sarif
@find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
@find . -type f -name "*.pyc" -delete 2>/dev/null || true
@echo "$(GREEN)Clean complete$(NC)"
# =============================================================================
# Dependencies
# =============================================================================
.PHONY: deps
deps: ## Install development dependencies (pytest, ruff, bandit, mypy)
@echo "$(BLUE)Installing development dependencies...$(NC)"
$(PIP) install --upgrade pip
$(PIP) install pytest pytest-cov ruff bandit mypy
@echo "$(GREEN)Dependencies installed$(NC)"
.PHONY: deps-update
deps-update: ## Update all dependencies to latest versions
@echo "$(BLUE)Updating dependencies...$(NC)"
$(PIP) install --upgrade pip
$(PIP) install --upgrade pytest pytest-cov ruff bandit mypy
@echo "$(GREEN)Dependencies updated$(NC)"
.PHONY: deps-refresh
deps-refresh: ## Refresh all dependencies (clean and re-download)
@echo "$(BLUE)Refreshing dependencies...$(NC)"
$(PIP) cache purge 2>/dev/null || true
$(PIP) install --upgrade pip
$(PIP) install --force-reinstall pytest pytest-cov ruff bandit mypy
@echo "$(GREEN)Dependencies refreshed$(NC)"
.PHONY: deps-check
deps-check: ## Check for dependency vulnerabilities
@echo "$(BLUE)Checking dependencies for vulnerabilities...$(NC)"
@if command -v pip-audit >/dev/null 2>&1; then \
pip-audit; \
else \
echo "pip-audit not installed. Run: pip install pip-audit"; \
fi
.PHONY: deps-lock
deps-lock: ## Generate requirements lock file
@echo "$(BLUE)Generating requirements lock...$(NC)"
$(PIP) freeze > requirements.lock
@echo "$(GREEN)Lock file generated: requirements.lock$(NC)"
.PHONY: deps-tree
deps-tree: ## Show dependency tree
@echo "$(BLUE)Dependency tree...$(NC)"
@if command -v pipdeptree >/dev/null 2>&1; then \
pipdeptree; \
else \
echo "pipdeptree not installed. Run: pip install pipdeptree"; \
fi
.PHONY: deps-verify
deps-verify: ## Verify no broken dependencies
@echo "$(BLUE)Verifying dependencies...$(NC)"
$(PIP) check
@echo "$(GREEN)Dependencies verified$(NC)"
# =============================================================================
# Code Quality
# =============================================================================
.PHONY: fmt
fmt: ## Format code with ruff
@echo "$(BLUE)Formatting code...$(NC)"
$(RUFF) check --fix $(PLUGINS_DIR) $(TESTS_DIR)
$(RUFF) format $(PLUGINS_DIR) $(TESTS_DIR)
@echo "$(GREEN)Code formatted$(NC)"
.PHONY: fmt-check
fmt-check: ## Check code formatting without fixing
@echo "$(BLUE)Checking code formatting...$(NC)"
$(RUFF) format --check $(PLUGINS_DIR) $(TESTS_DIR)
@echo "$(GREEN)Format check passed$(NC)"
.PHONY: lint
lint: ## Run ruff linter on plugins and tests
@echo "$(BLUE)Running linter...$(NC)"
$(RUFF) check $(PLUGINS_DIR) $(TESTS_DIR)
@echo "$(GREEN)Lint complete$(NC)"
.PHONY: lint-fix
lint-fix: ## Run ruff linter with auto-fix
@echo "$(BLUE)Running linter with auto-fix...$(NC)"
$(RUFF) check --fix $(PLUGINS_DIR) $(TESTS_DIR)
@echo "$(GREEN)Lint fix complete$(NC)"
.PHONY: format
format: fmt ## Alias for fmt
.PHONY: typecheck
typecheck: ## Run mypy type checking on plugins
@echo "$(BLUE)Running type checker...$(NC)"
$(MYPY) $(PLUGINS_DIR)
@echo "$(GREEN)Type check complete$(NC)"
.PHONY: check
check: fmt-check lint typecheck ## Run all code quality checks (format + lint + typecheck)
@echo "$(GREEN)All checks passed$(NC)"
# =============================================================================
# Testing
# =============================================================================
.PHONY: test
test: ## Run all tests (unit + integration)
@echo "$(BLUE)Running all tests...$(NC)"
$(PYTEST) $(TESTS_DIR) -v --tb=short
@echo "$(GREEN)All tests complete$(NC)"
.PHONY: test-unit
test-unit: ## Run unit tests only
@echo "$(BLUE)Running unit tests...$(NC)"
$(PYTEST) $(TESTS_DIR)/unit -v --tb=short
@echo "$(GREEN)Unit tests complete$(NC)"
.PHONY: test-integration
test-integration: ## Run integration tests only
@echo "$(BLUE)Running integration tests...$(NC)"
$(PYTEST) $(TESTS_DIR)/integration -v --tb=short
@echo "$(GREEN)Integration tests complete$(NC)"
.PHONY: test-all
test-all: test ## Alias for test
.PHONY: test-fast
test-fast: ## Run tests without slow markers
@echo "$(BLUE)Running fast tests...$(NC)"
$(PYTEST) $(TESTS_DIR) -v -m "not slow"
@echo "$(GREEN)Fast tests complete$(NC)"
.PHONY: test-cov
test-cov: ## Run all tests with coverage report (95%+ required)
@echo "$(BLUE)Running tests with coverage...$(NC)"
@mkdir -p $(BUILD_DIR)
$(PYTEST) $(TESTS_DIR) -v --tb=short \
--cov=$(COVERAGE_SOURCE) \
--cov-report=term-missing \
--cov-report=html:$(BUILD_DIR)/htmlcov \
--cov-report=xml:$(BUILD_DIR)/coverage.xml \
--cov-fail-under=95
@echo "$(GREEN)Coverage report: $(BUILD_DIR)/htmlcov/index.html$(NC)"
.PHONY: test-cov-unit
test-cov-unit: ## Run unit tests with coverage report
@echo "$(BLUE)Running unit tests with coverage...$(NC)"
$(PYTEST) $(TESTS_DIR)/unit -v --tb=short \
--cov=$(COVERAGE_SOURCE) \
--cov-report=term-missing \
--cov-report=html:htmlcov \
--cov-report=xml:coverage-unit.xml
@echo "$(GREEN)Unit test coverage report generated$(NC)"
.PHONY: test-cov-integration
test-cov-integration: ## Run integration tests with coverage report
@echo "$(BLUE)Running integration tests with coverage...$(NC)"
$(PYTEST) $(TESTS_DIR)/integration -v --tb=short \
--cov=$(COVERAGE_SOURCE) \
--cov-append \
--cov-report=term-missing \
--cov-report=xml:coverage-integration.xml
@echo "$(GREEN)Integration test coverage report generated$(NC)"
.PHONY: test-tool
test-tool: ## Run tests for specific tool (usage: make test-tool TOOL=query_metrics)
@if [ -z "$(TOOL)" ]; then \
echo "$(RED)TOOL is required. Usage: make test-tool TOOL=query_metrics$(NC)"; \
exit 1; \
fi
@echo "$(BLUE)Running tests for tool: $(TOOL)...$(NC)"
$(PYTEST) $(TESTS_DIR)/unit/test_$(TOOL).py -v --tb=short
.PHONY: test-shared
test-shared: ## Run tests for _shared.py utilities
@echo "$(BLUE)Running shared utilities tests...$(NC)"
$(PYTEST) $(TESTS_DIR)/unit/test_shared.py -v --tb=short
.PHONY: test-watch
test-watch: ## Run all tests in watch mode
@echo "$(BLUE)Running tests in watch mode...$(NC)"
$(PYTEST) $(TESTS_DIR) -v --tb=short -f -s
.PHONY: test-unit-watch
test-unit-watch: ## Run unit tests in watch mode
@echo "$(BLUE)Running unit tests in watch mode...$(NC)"
$(PYTEST) $(TESTS_DIR)/unit -v --tb=short -f -s
# =============================================================================
# CI/CD Pipeline
# =============================================================================
.PHONY: ci-deps
ci-deps: ## CI: Install CI dependencies (pytest, pytest-cov, ruff, bandit, mypy)
@echo "$(BLUE)CI: Installing dependencies...$(NC)"
$(PIP) install --upgrade pip
$(PIP) install pytest pytest-cov ruff bandit mypy
@echo "$(GREEN)CI: Dependencies installed$(NC)"
.PHONY: ci-lint
ci-lint: ## CI: Run ruff check + format check + mypy type check
@echo "$(BLUE)CI: Running linting...$(NC)"
$(RUFF) check $(PLUGINS_DIR) $(TESTS_DIR)
$(RUFF) format --check $(PLUGINS_DIR) $(TESTS_DIR)
$(MYPY) $(PLUGINS_DIR)
@echo "$(GREEN)CI: Linting completed$(NC)"
.PHONY: ci-test-unit
ci-test-unit: ## CI: Run unit tests with coverage XML + JUnit XML
@echo "$(BLUE)CI: Running unit tests...$(NC)"
$(PYTEST) $(TESTS_DIR)/unit -v --tb=short \
--cov=$(COVERAGE_SOURCE) \
--cov-report=xml:coverage-unit.xml \
--cov-report=term-missing \
--junitxml=junit-unit.xml
@echo "$(GREEN)CI: Unit tests completed$(NC)"
.PHONY: ci-test-integration
ci-test-integration: ## CI: Run integration tests with coverage (continue-on-error)
@echo "$(BLUE)CI: Running integration tests...$(NC)"
$(PYTEST) $(TESTS_DIR)/integration -v --tb=short \
--cov=$(COVERAGE_SOURCE) \
--cov-append \
--cov-fail-under=0 \
--cov-report=xml:coverage-integration.xml \
--cov-report=term-missing \
--junitxml=junit-integration.xml || true
@echo "$(GREEN)CI: Integration tests completed$(NC)"
.PHONY: ci-test
ci-test: ci-test-unit ci-test-integration ## CI: Run all tests (unit + integration)
@echo "$(GREEN)CI: All tests completed$(NC)"
.PHONY: ci-build
ci-build: clean ## CI: Build package
@echo "$(BLUE)CI: Building package...$(NC)"
$(PIP) install build
$(PYTHON) -m build
@echo "$(GREEN)CI: Build complete$(NC)"
@ls -la $(DIST_DIR)/
.PHONY: ci-security
ci-security: ## CI: Run bandit SARIF security scan
@echo "$(BLUE)CI: Running security scan...$(NC)"
@$(PIP) install bandit bandit-sarif-formatter 2>/dev/null || true
bandit -r $(PLUGINS_DIR)/ --format sarif --output bandit-results.sarif -ll || true
@echo "$(GREEN)CI: Security scan completed$(NC)"
.PHONY: ci-coverage
ci-coverage: ## CI: Generate coverage reports (xml, html, term) with 95% threshold
@echo "$(BLUE)CI: Generating coverage reports...$(NC)"
$(PYTEST) $(TESTS_DIR) --cov=$(COVERAGE_SOURCE) \
--cov-report=xml:coverage.xml \
--cov-report=html:$(BUILD_DIR)/htmlcov \
--cov-report=term-missing \
--cov-fail-under=95 \
-q
@echo "$(GREEN)CI: Coverage reports generated$(NC)"
.PHONY: ci-validate
ci-validate: ## CI: Validate project configuration
@echo "$(BLUE)CI: Validating project...$(NC)"
$(PIP) check
@echo "$(GREEN)CI: Project validation completed$(NC)"
.PHONY: ci-pipeline
ci-pipeline: ci-deps ci-lint ci-test ci-security ## CI: Run complete pipeline (deps → lint → test → security)
@echo "$(GREEN)CI Pipeline completed successfully$(NC)"
.PHONY: ci
ci: deps fmt-check lint typecheck test ## Run CI pipeline locally
@echo "$(GREEN)CI pipeline complete$(NC)"
.PHONY: coverage-report
coverage-report: ## Generate merged coverage report
@echo "$(BLUE)Generating coverage report...$(NC)"
$(PYTEST) $(TESTS_DIR) --cov=$(COVERAGE_SOURCE) \
--cov-report=html:$(BUILD_DIR)/htmlcov \
--cov-report=term-missing \
-q
@echo "$(GREEN)Coverage report: $(BUILD_DIR)/htmlcov/index.html$(NC)"
# =============================================================================
# Security
# =============================================================================
.PHONY: security-check
security-check: ## Run security checks (bandit + pip-audit)
@echo "$(BLUE)Running security checks...$(NC)"
@if command -v bandit >/dev/null 2>&1; then \
bandit -r $(PLUGINS_DIR) -ll; \
else \
echo "bandit not installed. Run: pip install bandit"; \
fi
@if command -v pip-audit >/dev/null 2>&1; then \
pip-audit; \
else \
echo "pip-audit not installed. Run: pip install pip-audit"; \
fi
.PHONY: audit
audit: deps-check security-check ## Run full security audit
@echo "$(GREEN)Security audit complete$(NC)"
# =============================================================================
# Release
# =============================================================================
.PHONY: release-check
release-check: lint test-cov ## Pre-release checks (lint + test with coverage)
@echo "$(GREEN)Release checks passed$(NC)"
.PHONY: release
release: clean build-release ## Create release artifacts
@echo "$(BLUE)Creating release $(VERSION)...$(NC)"
@mkdir -p $(DIST_DIR)/release
@cp $(DIST_DIR)/*.whl $(DIST_DIR)/release/ 2>/dev/null || true
@cp $(DIST_DIR)/*.tar.gz $(DIST_DIR)/release/ 2>/dev/null || true
@echo "$(GREEN)Release artifacts created in $(DIST_DIR)/release$(NC)"
@ls -la $(DIST_DIR)/release/
.PHONY: publish
publish: ## Publish to PyPI
@echo "$(BLUE)Publishing to PyPI...$(NC)"
@if command -v twine >/dev/null 2>&1; then \
twine upload $(DIST_DIR)/*; \
else \
echo "twine not installed. Run: pip install twine"; \
fi
.PHONY: publish-test
publish-test: ## Publish to Test PyPI
@echo "$(BLUE)Publishing to Test PyPI...$(NC)"
@if command -v twine >/dev/null 2>&1; then \
twine upload --repository testpypi $(DIST_DIR)/*; \
else \
echo "twine not installed. Run: pip install twine"; \
fi
# =============================================================================
# Pre-commit
# =============================================================================
.PHONY: pre-commit
pre-commit: ## Run pre-commit hooks on all files
@echo "$(BLUE)Running pre-commit...$(NC)"
@if command -v pre-commit >/dev/null 2>&1; then \
pre-commit run --all-files; \
else \
echo "pre-commit not installed. Run: pip install pre-commit"; \
fi
.PHONY: pre-commit-update
pre-commit-update: ## Update pre-commit hooks
@echo "$(BLUE)Updating pre-commit hooks...$(NC)"
pre-commit autoupdate
# =============================================================================
# Utilities
# =============================================================================
.PHONY: health
health: ## Check TelemetryFlow Platform health
@echo "$(BLUE)Checking TelemetryFlow Platform health...$(NC)"
@if curl -sf "$${TELEMETRYFLOW_API_URL:-http://localhost:3000/api/v2}/../health" >/dev/null 2>&1; then \
echo "$(GREEN)TelemetryFlow Platform is healthy$(NC)"; \
else \
echo "$(RED)TelemetryFlow Platform is not responding$(NC)"; \
exit 1; \
fi
.PHONY: version
version: ## Show version information
@echo "$(BLUE)Version Information:$(NC)"
@echo " Product: TelemetryFlow Hermes"
@echo " Version: $(VERSION)"
@echo " Git Commit: $(GIT_COMMIT)"
@echo " Git Branch: $(GIT_BRANCH)"
@echo " Build Time: $(BUILD_TIME)"
@echo " Python: $(PYTHON_VERSION)"
@echo " Pytest: $(shell $(PYTEST) --version 2>/dev/null | head -1 || echo 'not installed')"
@echo " Ruff: $(shell $(RUFF) --version 2>/dev/null || echo 'not installed')"
.PHONY: info
info: version ## Alias for version
# =============================================================================
# Development Shortcuts
# =============================================================================
.PHONY: start
start: deps configure ## Install deps + deploy everything
@echo "$(GREEN)Ready for development$(NC)"
.PHONY: reset
reset: clean configure ## Clean + re-deploy all components
@echo "$(GREEN)Environment reset completed$(NC)"
# =============================================================================
# Special Targets
# =============================================================================
.PHONY: all
all: fmt lint typecheck test build ## Run full pipeline (format + lint + typecheck + test + build)
.PRECIOUS: pyproject.toml
SHELL := /bin/bash