-
Notifications
You must be signed in to change notification settings - Fork 104
test(e2e): add end-to-end tests for inference and CLI #780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+492
−1
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| name: E2E Tests | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| pull_request: | ||
| branches: [ main ] | ||
| push: | ||
| branches: [ main ] | ||
|
|
||
| jobs: | ||
| e2e-test: | ||
| runs-on: macos-latest | ||
| timeout-minutes: 20 | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd | ||
| with: | ||
| submodules: recursive | ||
|
|
||
| - name: Set up Go | ||
| uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 | ||
| with: | ||
| go-version: 1.25.8 | ||
| cache: true | ||
|
|
||
| - name: Run e2e tests | ||
| run: make e2e | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| //go:build e2e | ||
|
|
||
| package e2e | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| // TestE2E_CLI runs all CLI tests sequentially as subtests to ensure | ||
| // correct ordering (pull → list → run → remove). | ||
| func TestE2E_CLI(t *testing.T) { | ||
| t.Run("Pull", func(t *testing.T) { | ||
| out, err := runCLI(t, "pull", testModel) | ||
| if err != nil { | ||
| t.Fatalf("cli pull failed: %v\noutput: %s", err, out) | ||
| } | ||
| t.Logf("pull output: %s", out) | ||
| }) | ||
|
|
||
| t.Run("List", func(t *testing.T) { | ||
| out, err := runCLI(t, "ls") | ||
| if err != nil { | ||
| t.Fatalf("cli ls failed: %v\noutput: %s", err, out) | ||
| } | ||
|
|
||
| if !strings.Contains(out, "smollm2") { | ||
| t.Errorf("expected smollm2 in list output, got:\n%s", out) | ||
| } | ||
| t.Logf("ls output:\n%s", out) | ||
| }) | ||
|
|
||
| t.Run("Run", func(t *testing.T) { | ||
| out, err := runCLI(t, "run", testModel, "Say hi in one word.") | ||
| if err != nil { | ||
| t.Fatalf("cli run failed: %v\noutput: %s", err, out) | ||
| } | ||
|
|
||
| if strings.TrimSpace(out) == "" { | ||
| t.Fatal("cli run produced empty output") | ||
| } | ||
| t.Logf("run output: %s", out) | ||
| }) | ||
|
|
||
| t.Run("Remove", func(t *testing.T) { | ||
| out, err := runCLI(t, "rm", "-f", testModel) | ||
| if err != nil { | ||
| t.Fatalf("cli rm failed: %v\noutput: %s", err, out) | ||
| } | ||
| t.Logf("rm output: %s", out) | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| //go:build e2e | ||
|
|
||
| // Package e2e contains end-to-end tests that build and run the full | ||
| // model-runner stack (server + llama.cpp backend + CLI) from source. | ||
| // | ||
| // These tests require: | ||
| // - The llamacpp submodule to be initialised and built (make build-llamacpp) | ||
| // - A successful `make build` so that model-runner, model-cli, and dmr exist | ||
| // | ||
| // Run with: | ||
| // | ||
| // go test -v -count=1 -tags=e2e -timeout=15m ./e2e/ | ||
| package e2e | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "net" | ||
| "net/http" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "strconv" | ||
| "testing" | ||
| "time" | ||
| ) | ||
|
|
||
| const ( | ||
| // testModel is small enough to pull quickly in CI. | ||
| testModel = "ai/smollm2:135M-Q4_0" | ||
|
|
||
| serverStartTimeout = 60 * time.Second | ||
| ) | ||
|
|
||
| var ( | ||
| // serverURL is the base URL of the running model-runner instance. | ||
| serverURL string | ||
| // cliBin is the absolute path to the model-cli binary. | ||
| cliBin string | ||
| ) | ||
|
|
||
| // TestMain builds the binaries, starts the server (same pattern as dmr), | ||
| // and tears it down after all tests complete. | ||
| func TestMain(m *testing.M) { | ||
| code := run(m) | ||
| os.Exit(code) | ||
| } | ||
|
|
||
| func run(m *testing.M) int { | ||
| // go test sets cwd to the package directory (e2e/), so the repo root is ../ | ||
| root, err := filepath.Abs("..") | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "e2e: %v\n", err) | ||
| return 1 | ||
| } | ||
|
|
||
| // ── 1. Build binaries ────────────────────────────────────────────── | ||
| fmt.Fprintln(os.Stderr, "e2e: building server and CLI...") | ||
| if err := makeTarget(root, "build"); err != nil { | ||
| fmt.Fprintf(os.Stderr, "e2e: make build failed: %v\n", err) | ||
| return 1 | ||
| } | ||
|
|
||
| serverBin := filepath.Join(root, "model-runner") | ||
| cliBin = filepath.Join(root, "cmd", "cli", "model-cli") | ||
| llamaBin := filepath.Join(root, "llamacpp", "install", "bin") | ||
|
|
||
| for _, path := range []string{serverBin, cliBin, llamaBin} { | ||
| if _, err := os.Stat(path); err != nil { | ||
| fmt.Fprintf(os.Stderr, "e2e: not found: %s\n", path) | ||
| return 1 | ||
| } | ||
| } | ||
|
|
||
| // ── 2. Start model-runner (same pattern as cmd/dmr) ──────────────── | ||
| port, err := freePort() | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "e2e: %v\n", err) | ||
| return 1 | ||
| } | ||
| serverURL = "http://localhost:" + strconv.Itoa(port) | ||
| fmt.Fprintf(os.Stderr, "e2e: starting model-runner on port %d\n", port) | ||
|
|
||
| ctx, cancel := context.WithCancel(context.Background()) | ||
| defer cancel() | ||
|
|
||
| server := exec.CommandContext(ctx, serverBin) | ||
| server.Dir = root | ||
| server.Env = append(os.Environ(), | ||
| "MODEL_RUNNER_PORT="+strconv.Itoa(port), | ||
| "LLAMA_SERVER_PATH="+llamaBin, | ||
| ) | ||
| server.Stdout = os.Stderr | ||
| server.Stderr = os.Stderr | ||
|
|
||
| if err := server.Start(); err != nil { | ||
| fmt.Fprintf(os.Stderr, "e2e: failed to start server: %v\n", err) | ||
| return 1 | ||
| } | ||
| defer func() { | ||
| cancel() | ||
| _ = server.Wait() | ||
| }() | ||
|
|
||
| // ── 3. Wait for health ───────────────────────────────────────────── | ||
| if err := waitForServer(serverURL+"/models", serverStartTimeout); err != nil { | ||
| fmt.Fprintf(os.Stderr, "e2e: %v\n", err) | ||
| return 1 | ||
| } | ||
| fmt.Fprintf(os.Stderr, "e2e: server ready at %s\n", serverURL) | ||
|
|
||
| // ── 4. Run tests ─────────────────────────────────────────────────── | ||
| return m.Run() | ||
| } | ||
|
|
||
| func makeTarget(dir, target string) error { | ||
| cmd := exec.Command("make", target) | ||
| cmd.Dir = dir | ||
| cmd.Stdout = os.Stderr | ||
| cmd.Stderr = os.Stderr | ||
| return cmd.Run() | ||
| } | ||
|
|
||
| func freePort() (int, error) { | ||
| l, err := net.Listen("tcp", "127.0.0.1:0") | ||
| if err != nil { | ||
| return 0, fmt.Errorf("finding free port: %w", err) | ||
| } | ||
| defer l.Close() | ||
| return l.Addr().(*net.TCPAddr).Port, nil | ||
| } | ||
|
|
||
| func waitForServer(url string, timeout time.Duration) error { | ||
| client := &http.Client{Timeout: 2 * time.Second} | ||
| deadline := time.Now().Add(timeout) | ||
| for time.Now().Before(deadline) { | ||
| resp, err := client.Get(url) | ||
| if err == nil { | ||
| resp.Body.Close() | ||
| if resp.StatusCode == http.StatusOK { | ||
| return nil | ||
| } | ||
| } | ||
| time.Sleep(200 * time.Millisecond) | ||
| } | ||
| return fmt.Errorf("server not ready after %s", timeout) | ||
| } | ||
|
|
||
| // runCLI executes the model-cli binary with the given arguments and | ||
| // MODEL_RUNNER_HOST pointing to the test server. The subprocess is | ||
| // cancelled if the test's context expires. | ||
| func runCLI(t *testing.T, args ...string) (string, error) { | ||
| t.Helper() | ||
| cmd := exec.CommandContext(t.Context(), cliBin, args...) | ||
| cmd.Env = append(os.Environ(), "MODEL_RUNNER_HOST="+serverURL) | ||
| out, err := cmd.CombinedOutput() | ||
| return string(out), err | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium
Copilot Autofix
AI 5 days ago
In general, the fix is to explicitly declare a
permissionsblock that grants only the minimal required scopes to theGITHUB_TOKEN. Since this job only checks out repository contents and runs tests, it only needs read access to repository contents.The best fix here is to add a
permissionsblock to thee2e-testjob (or at the workflow root). To keep the change tightly scoped and avoid affecting other workflows, we will add it at the job level, immediately undere2e-test:and aligned withruns-on:. We will setcontents: read, which is sufficient foractions/checkoutand normal test execution and preserves existing functionality while constraining token capabilities.Concretely, in
.github/workflows/e2e-test.yml, modify thee2e-testjob definition so that:e2e-test:), insert:No additional methods, imports, or definitions are needed.