Skip to content

Commit 5698d0b

Browse files
committed
chore(tests): Mock LLM in tests for PRs
This saves time when testing on CPU which is the only sensible thing to do on GitHub CI for PRs. For releases or once the commit is merged we could use an external runner with GPU or just wait. Signed-off-by: Richard Palethorpe <io@richiejp.com>
1 parent c23e655 commit 5698d0b

File tree

12 files changed

+429
-72
lines changed

12 files changed

+429
-72
lines changed

.github/workflows/tests.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ jobs:
4848
4949
- name: Run tests
5050
run: |
51-
make tests
51+
if [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
52+
make tests-mock
53+
else
54+
make tests
55+
fi
5256
#sudo mv coverage/coverage.txt coverage.txt
5357
#sudo chmod 777 coverage.txt
5458

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Run Fragile Go Tests
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- '**'
7+
8+
concurrency:
9+
group: ci-non-blocking-tests-${{ github.head_ref || github.ref }}-${{ github.repository }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
llm-tests:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
- run: |
19+
# Add Docker's official GPG key:
20+
sudo apt-get update
21+
sudo apt-get install -y ca-certificates curl
22+
sudo install -m 0755 -d /etc/apt/keyrings
23+
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
24+
sudo chmod a+r /etc/apt/keyrings/docker.asc
25+
26+
# Add the repository to Apt sources:
27+
echo \
28+
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
29+
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
30+
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
31+
sudo apt-get update
32+
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin make
33+
docker version
34+
35+
docker run --rm hello-world
36+
- uses: actions/setup-go@v5
37+
with:
38+
go-version: '>=1.17.0'
39+
- name: Free up disk space
40+
run: |
41+
sudo rm -rf /usr/share/dotnet
42+
sudo rm -rf /usr/local/lib/android
43+
sudo rm -rf /opt/ghc
44+
sudo apt-get clean
45+
docker system prune -af || true
46+
df -h
47+
- name: Run tests
48+
run: |
49+
make tests

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ IMAGE_NAME?=webui
33
MCPBOX_IMAGE_NAME?=mcpbox
44
ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
55

6+
.PHONY: tests tests-mock cleanup-tests
7+
68
prepare-tests: build-mcpbox
79
docker compose up -d --build
810
docker run -d -v /var/run/docker.sock:/var/run/docker.sock --privileged -p 9090:8080 --rm -ti $(MCPBOX_IMAGE_NAME)
@@ -13,6 +15,9 @@ cleanup-tests:
1315
tests: prepare-tests
1416
LOCALAGI_MCPBOX_URL="http://localhost:9090" LOCALAGI_MODEL="gemma-3-12b-it-qat" LOCALAI_API_URL="http://localhost:8081" LOCALAGI_API_URL="http://localhost:8080" $(GOCMD) run github.com/onsi/ginkgo/v2/ginkgo --fail-fast -v -r ./...
1517

18+
tests-mock: prepare-tests
19+
LOCALAGI_MCPBOX_URL="http://localhost:9090" LOCALAI_API_URL="http://localhost:8081" LOCALAGI_API_URL="http://localhost:8080" $(GOCMD) run github.com/onsi/ginkgo/v2/ginkgo --fail-fast -v -r ./...
20+
1621
run-nokb:
1722
$(MAKE) run KBDISABLEINDEX=true
1823

@@ -37,4 +42,4 @@ build-mcpbox:
3742
docker build -t $(MCPBOX_IMAGE_NAME) -f Dockerfile.mcpbox .
3843

3944
run-mcpbox:
40-
docker run -v /var/run/docker.sock:/var/run/docker.sock --privileged -p 9090:8080 -ti mcpbox
45+
docker run -v /var/run/docker.sock:/var/run/docker.sock --privileged -p 9090:8080 -ti mcpbox

core/agent/agent.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type Agent struct {
2929
sync.Mutex
3030
options *options
3131
Character Character
32-
client *openai.Client
32+
client llm.LLMClient
3333
jobQueue chan *types.Job
3434
context *types.ActionContext
3535

@@ -63,7 +63,12 @@ func New(opts ...Option) (*Agent, error) {
6363
return nil, fmt.Errorf("failed to set options: %v", err)
6464
}
6565

66-
client := llm.NewClient(options.LLMAPI.APIKey, options.LLMAPI.APIURL, options.timeout)
66+
var client llm.LLMClient
67+
if options.llmClient != nil {
68+
client = options.llmClient
69+
} else {
70+
client = llm.NewClient(options.LLMAPI.APIKey, options.LLMAPI.APIURL, options.timeout)
71+
}
6772

6873
c := context.Background()
6974
if options.context != nil {
@@ -125,6 +130,11 @@ func (a *Agent) SharedState() *types.AgentSharedState {
125130
return a.sharedState
126131
}
127132

133+
// LLMClient returns the agent's LLM client (for testing)
134+
func (a *Agent) LLMClient() llm.LLMClient {
135+
return a.client
136+
}
137+
128138
func (a *Agent) startNewConversationsConsumer() {
129139
go func() {
130140
for {

core/agent/agent_suite_test.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package agent_test
22

33
import (
4+
"net/url"
45
"os"
56
"testing"
67

@@ -13,15 +14,19 @@ func TestAgent(t *testing.T) {
1314
RunSpecs(t, "Agent test suite")
1415
}
1516

16-
var testModel = os.Getenv("LOCALAGI_MODEL")
17-
var apiURL = os.Getenv("LOCALAI_API_URL")
18-
var apiKeyURL = os.Getenv("LOCALAI_API_KEY")
17+
var (
18+
testModel = os.Getenv("LOCALAGI_MODEL")
19+
apiURL = os.Getenv("LOCALAI_API_URL")
20+
apiKey = os.Getenv("LOCALAI_API_KEY")
21+
useRealLocalAI bool
22+
clientTimeout = "10m"
23+
)
24+
25+
func isValidURL(u string) bool {
26+
parsed, err := url.ParseRequestURI(u)
27+
return err == nil && parsed.Scheme != "" && parsed.Host != ""
28+
}
1929

2030
func init() {
21-
if testModel == "" {
22-
testModel = "hermes-2-pro-mistral"
23-
}
24-
if apiURL == "" {
25-
apiURL = "http://192.168.68.113:8080"
26-
}
31+
useRealLocalAI = isValidURL(apiURL) && apiURL != "" && testModel != ""
2732
}

0 commit comments

Comments
 (0)