PORT ?= 4000
URL  ?= http://127.0.0.1:$(PORT)

.PHONY: test serve sim
test: ## run the offline test suite (no network, no DB server)
	ruby test/test_ledger.rb
	ruby test/test_context_maintainer.rb
	ruby test/test_domain.rb
	ruby test/test_commands.rb
	ruby test/test_summariser.rb
	ruby test/test_pipeline.rb
	ruby test/test_reporting.rb
	ruby wiki/test_wiki_rag.rb

serve: ## run the webrick server on $(PORT)
	PORT=$(PORT) ruby server.rb

sim: ## start the server, drive it end-to-end over HTTP, stop it
	@PORT=$(PORT) ruby server.rb & echo $$! > .srv.pid; \
	HELPDESK_URL=$(URL) ruby sim/simulator.rb; rc=$$?; \
	kill `cat .srv.pid` 2>/dev/null; rm -f .srv.pid; exit $$rc
