Skip to main content
Glama
SnapshotNotFoundRegressionTests.swift7.68 kB
import Foundation import PeekabooCore import Testing @testable import PeekabooCLI @Suite("Snapshot Not Found Regression Tests", .tags(.safe, .regression)) struct SnapshotNotFoundRegressionTests { @Test("click --snapshot errors when snapshot was cleaned") func clickSnapshotNotFound() async throws { let context = await MainActor.run { TestServicesFactory.makeAutomationTestContext() } let snapshotId = try await self.makeSnapshot(with: context.snapshots) try await context.snapshots.cleanSnapshot(snapshotId: snapshotId) let result = try await InProcessCommandRunner.run( ["click", "Single Click", "--snapshot", snapshotId, "--json", "--no-auto-focus"], services: context.services ) #expect(result.exitStatus != 0) let response = try ExternalCommandRunner.decodeJSONResponse(from: result, as: JSONResponse.self) #expect(response.success == false) #expect(response.error?.code == ErrorCode.SNAPSHOT_NOT_FOUND.rawValue) } @Test("move --id --snapshot errors when snapshot was cleaned") func moveSnapshotNotFound() async throws { let context = await MainActor.run { TestServicesFactory.makeAutomationTestContext() } let snapshotId = try await self.makeSnapshot(with: context.snapshots) try await context.snapshots.cleanSnapshot(snapshotId: snapshotId) let result = try await InProcessCommandRunner.run( ["move", "--id", "B1", "--snapshot", snapshotId, "--json"], services: context.services ) #expect(result.exitStatus != 0) let response = try ExternalCommandRunner.decodeJSONResponse(from: result, as: JSONResponse.self) #expect(response.success == false) #expect(response.error?.code == ErrorCode.SNAPSHOT_NOT_FOUND.rawValue) } @Test("scroll --on --snapshot errors when snapshot was cleaned") func scrollSnapshotNotFound() async throws { let context = await MainActor.run { TestServicesFactory.makeAutomationTestContext() } let snapshotId = try await self.makeSnapshot(with: context.snapshots) try await context.snapshots.cleanSnapshot(snapshotId: snapshotId) let result = try await InProcessCommandRunner.run( ["scroll", "--direction", "down", "--on", "B1", "--snapshot", snapshotId, "--json", "--no-auto-focus"], services: context.services ) #expect(result.exitStatus != 0) let response = try ExternalCommandRunner.decodeJSONResponse(from: result, as: JSONResponse.self) #expect(response.success == false) #expect(response.error?.code == ErrorCode.SNAPSHOT_NOT_FOUND.rawValue) } @Test("drag --from/--to --snapshot errors when snapshot was cleaned") func dragSnapshotNotFound() async throws { let context = await MainActor.run { TestServicesFactory.makeAutomationTestContext() } let snapshotId = try await self.makeSnapshot(with: context.snapshots) try await context.snapshots.cleanSnapshot(snapshotId: snapshotId) let result = try await InProcessCommandRunner.run( ["drag", "--from", "B1", "--to", "B1", "--snapshot", snapshotId, "--json", "--no-auto-focus"], services: context.services ) #expect(result.exitStatus != 0) let response = try ExternalCommandRunner.decodeJSONResponse(from: result, as: JSONResponse.self) #expect(response.success == false) #expect(response.error?.code == ErrorCode.SNAPSHOT_NOT_FOUND.rawValue) } @Test("swipe --from/--to --snapshot errors when snapshot was cleaned") func swipeSnapshotNotFound() async throws { let context = await MainActor.run { TestServicesFactory.makeAutomationTestContext() } let snapshotId = try await self.makeSnapshot(with: context.snapshots) try await context.snapshots.cleanSnapshot(snapshotId: snapshotId) let result = try await InProcessCommandRunner.run( ["swipe", "--from", "B1", "--to", "B1", "--snapshot", snapshotId, "--json"], services: context.services ) #expect(result.exitStatus != 0) let response = try ExternalCommandRunner.decodeJSONResponse(from: result, as: JSONResponse.self) #expect(response.success == false) #expect(response.error?.code == ErrorCode.SNAPSHOT_NOT_FOUND.rawValue) } @Test("type --snapshot errors when snapshot was cleaned") func typeSnapshotNotFound() async throws { let context = await MainActor.run { TestServicesFactory.makeAutomationTestContext() } let snapshotId = try await self.makeSnapshot(with: context.snapshots) try await context.snapshots.cleanSnapshot(snapshotId: snapshotId) let result = try await InProcessCommandRunner.run( ["type", "Hello", "--snapshot", snapshotId, "--json", "--no-auto-focus"], services: context.services ) #expect(result.exitStatus != 0) let response = try ExternalCommandRunner.decodeJSONResponse(from: result, as: JSONResponse.self) #expect(response.success == false) #expect(response.error?.code == ErrorCode.SNAPSHOT_NOT_FOUND.rawValue) } @Test("hotkey --snapshot errors when snapshot was cleaned") func hotkeySnapshotNotFound() async throws { let context = await MainActor.run { TestServicesFactory.makeAutomationTestContext() } let snapshotId = try await self.makeSnapshot(with: context.snapshots) try await context.snapshots.cleanSnapshot(snapshotId: snapshotId) let result = try await InProcessCommandRunner.run( ["hotkey", "cmd,c", "--snapshot", snapshotId, "--json", "--no-auto-focus"], services: context.services ) #expect(result.exitStatus != 0) let response = try ExternalCommandRunner.decodeJSONResponse(from: result, as: JSONResponse.self) #expect(response.success == false) #expect(response.error?.code == ErrorCode.SNAPSHOT_NOT_FOUND.rawValue) } @Test("press --snapshot errors when snapshot was cleaned") func pressSnapshotNotFound() async throws { let context = await MainActor.run { TestServicesFactory.makeAutomationTestContext() } let snapshotId = try await self.makeSnapshot(with: context.snapshots) try await context.snapshots.cleanSnapshot(snapshotId: snapshotId) let result = try await InProcessCommandRunner.run( ["press", "tab", "--snapshot", snapshotId, "--json", "--no-auto-focus"], services: context.services ) #expect(result.exitStatus != 0) let response = try ExternalCommandRunner.decodeJSONResponse(from: result, as: JSONResponse.self) #expect(response.success == false) #expect(response.error?.code == ErrorCode.SNAPSHOT_NOT_FOUND.rawValue) } private func makeSnapshot(with snapshots: StubSnapshotManager) async throws -> String { let snapshotId = try await snapshots.createSnapshot() let element = DetectedElement( id: "B1", type: .button, label: "Single Click", bounds: CGRect(x: 50, y: 70, width: 120, height: 40) ) let detection = ElementDetectionResult( snapshotId: snapshotId, screenshotPath: "/tmp/screenshot.png", elements: DetectedElements(buttons: [element]), metadata: DetectionMetadata(detectionTime: 0, elementCount: 1, method: "stub") ) try await snapshots.storeDetectionResult(snapshotId: snapshotId, result: detection) return snapshotId } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/steipete/Peekaboo'

If you have feedback or need assistance with the MCP directory API, please join our Discord server