From 847e888145ddc100cbc1b4c45d9fa5f767a5cf83 Mon Sep 17 00:00:00 2001 From: KingKDot Date: Fri, 6 Mar 2026 11:55:16 -0600 Subject: [PATCH] more tests and make github run ALL tests. Also print default creds + add windows specific tests --- .github/workflows/tests.yml | 12 +- .../cmd/agent/handlers/screenshot.go | 14 ++- .../agent/handlers/screenshot_windows_test.go | 107 ++++++++++++++++++ Overlord-Server/src/users.ts | 3 + 4 files changed, 130 insertions(+), 6 deletions(-) create mode 100644 Overlord-Client/cmd/agent/handlers/screenshot_windows_test.go diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 212ff68..e302183 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,7 +7,11 @@ on: jobs: server-tests: - runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} defaults: run: working-directory: Overlord-Server @@ -27,7 +31,11 @@ jobs: run: bun test client-tests: - runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} defaults: run: working-directory: Overlord-Client diff --git a/Overlord-Client/cmd/agent/handlers/screenshot.go b/Overlord-Client/cmd/agent/handlers/screenshot.go index c7e114c..f9264a4 100644 --- a/Overlord-Client/cmd/agent/handlers/screenshot.go +++ b/Overlord-Client/cmd/agent/handlers/screenshot.go @@ -17,6 +17,12 @@ import ( "github.com/kbinani/screenshot" ) +var ( + monitorCountFn = capture.MonitorCount + displayBoundsFn = capture.DisplayBounds + captureDisplayRGBABitBltFn = capture.CaptureDisplayRGBABitBlt +) + func HandleScreenshot(ctx context.Context, env *rt.Env, cmdID string, allDisplays bool) error { if allDisplays { log.Printf("screenshot: capturing all displays") @@ -154,13 +160,13 @@ func captureScreenshotImage(allDisplays bool) (*image.RGBA, int, image.Rectangle } func captureScreenshotImageWindows(allDisplays bool) (*image.RGBA, int, image.Rectangle, error) { - monitorCount := capture.MonitorCount() + monitorCount := monitorCountFn() if monitorCount <= 0 { return nil, 0, image.Rectangle{}, errors.New("no active displays available") } if !allDisplays { - img, err := capture.CaptureDisplayRGBABitBlt(0) + img, err := captureDisplayRGBABitBltFn(0) if err != nil || img == nil { return nil, 0, image.Rectangle{}, err } @@ -176,8 +182,8 @@ func captureScreenshotImageWindows(allDisplays bool) (*image.RGBA, int, image.Re maxX, maxY := int(-1e9), int(-1e9) for i := 0; i < monitorCount; i++ { - bounds := capture.DisplayBounds(i) - img, err := capture.CaptureDisplayRGBABitBlt(i) + bounds := displayBoundsFn(i) + img, err := captureDisplayRGBABitBltFn(i) if err != nil || img == nil { return nil, 0, image.Rectangle{}, err } diff --git a/Overlord-Client/cmd/agent/handlers/screenshot_windows_test.go b/Overlord-Client/cmd/agent/handlers/screenshot_windows_test.go new file mode 100644 index 0000000..ecedcf8 --- /dev/null +++ b/Overlord-Client/cmd/agent/handlers/screenshot_windows_test.go @@ -0,0 +1,107 @@ +//go:build windows + +package handlers + +import ( + "image" + "image/color" + "testing" +) + +func TestCaptureScreenshotImageWindows_PrimaryOnly(t *testing.T) { + origMonitorCountFn := monitorCountFn + origCaptureFn := captureDisplayRGBABitBltFn + t.Cleanup(func() { + monitorCountFn = origMonitorCountFn + captureDisplayRGBABitBltFn = origCaptureFn + }) + + monitorCountFn = func() int { return 2 } + captureDisplayRGBABitBltFn = func(display int) (*image.RGBA, error) { + img := image.NewRGBA(image.Rect(0, 0, 3, 2)) + img.SetRGBA(0, 0, color.RGBA{R: 255, A: 255}) + return img, nil + } + + img, displayIndex, bounds, err := captureScreenshotImageWindows(false) + if err != nil { + t.Fatalf("captureScreenshotImageWindows(false) failed: %v", err) + } + if img == nil { + t.Fatal("expected image, got nil") + } + if displayIndex != 0 { + t.Fatalf("expected displayIndex 0, got %d", displayIndex) + } + if bounds.Dx() != 3 || bounds.Dy() != 2 { + t.Fatalf("expected bounds 3x2, got %dx%d", bounds.Dx(), bounds.Dy()) + } +} + +func TestCaptureScreenshotImageWindows_AllDisplaysStitched(t *testing.T) { + origMonitorCountFn := monitorCountFn + origBoundsFn := displayBoundsFn + origCaptureFn := captureDisplayRGBABitBltFn + t.Cleanup(func() { + monitorCountFn = origMonitorCountFn + displayBoundsFn = origBoundsFn + captureDisplayRGBABitBltFn = origCaptureFn + }) + + monitorCountFn = func() int { return 2 } + displayBoundsFn = func(idx int) image.Rectangle { + if idx == 0 { + return image.Rect(0, 0, 2, 2) + } + return image.Rect(2, 0, 4, 2) + } + captureDisplayRGBABitBltFn = func(display int) (*image.RGBA, error) { + img := image.NewRGBA(image.Rect(0, 0, 2, 2)) + if display == 0 { + img.SetRGBA(0, 0, color.RGBA{R: 255, A: 255}) + } else { + img.SetRGBA(0, 0, color.RGBA{G: 255, A: 255}) + } + return img, nil + } + + img, displayIndex, bounds, err := captureScreenshotImageWindows(true) + if err != nil { + t.Fatalf("captureScreenshotImageWindows(true) failed: %v", err) + } + if img == nil { + t.Fatal("expected stitched image, got nil") + } + if displayIndex != 0 { + t.Fatalf("expected displayIndex 0, got %d", displayIndex) + } + if bounds.Dx() != 4 || bounds.Dy() != 2 { + t.Fatalf("expected stitched bounds 4x2, got %dx%d", bounds.Dx(), bounds.Dy()) + } + + left := img.RGBAAt(0, 0) + right := img.RGBAAt(2, 0) + if left.R != 255 || left.G != 0 { + t.Fatalf("expected left monitor red marker, got %+v", left) + } + if right.G != 255 || right.R != 0 { + t.Fatalf("expected right monitor green marker, got %+v", right) + } +} + +func TestCaptureScreenshotImageWindows_NoDisplays(t *testing.T) { + origMonitorCountFn := monitorCountFn + t.Cleanup(func() { + monitorCountFn = origMonitorCountFn + }) + + monitorCountFn = func() int { return 0 } + + img, _, _, err := captureScreenshotImageWindows(false) + if err == nil { + t.Fatal("expected error for no displays, got nil") + } + if img != nil { + t.Fatal("expected nil image on error") + } +} diff --git a/Overlord-Server/src/users.ts b/Overlord-Server/src/users.ts index 22a8551..1249016 100644 --- a/Overlord-Server/src/users.ts +++ b/Overlord-Server/src/users.ts @@ -81,6 +81,9 @@ if (userCount.count === 0) { ); logger.info(`[users] Initial admin account created (username: ${initialUsername})`); + logger.warn( + `[users] Bootstrap login credentials -> username: ${initialUsername} | password: ${initialPassword}`, + ); logger.warn( "[users] ⚠️ SECURITY WARNING: Rotate the bootstrap password after first login. If it was auto-generated, retrieve it from data/save.json.", );