-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
1,323 additions
and
204 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
cp pyproject.toml poetry.lock openhands | ||
poetry build -v |
This file contains 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 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,59 @@ | ||
import { describe, it, expect, vi, beforeEach } from "vitest"; | ||
import { handleStatusMessage } from "#/services/actions"; | ||
import store from "#/store"; | ||
import { trackError } from "#/utils/error-handler"; | ||
|
||
// Mock dependencies | ||
vi.mock("#/utils/error-handler", () => ({ | ||
trackError: vi.fn(), | ||
})); | ||
|
||
vi.mock("#/store", () => ({ | ||
default: { | ||
dispatch: vi.fn(), | ||
}, | ||
})); | ||
|
||
describe("Actions Service", () => { | ||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
describe("handleStatusMessage", () => { | ||
it("should dispatch info messages to status state", () => { | ||
const message = { | ||
type: "info", | ||
message: "Runtime is not available", | ||
id: "runtime.unavailable", | ||
status_update: true as const, | ||
}; | ||
|
||
handleStatusMessage(message); | ||
|
||
expect(store.dispatch).toHaveBeenCalledWith(expect.objectContaining({ | ||
payload: message, | ||
})); | ||
}); | ||
|
||
it("should log error messages and display them in chat", () => { | ||
const message = { | ||
type: "error", | ||
message: "Runtime connection failed", | ||
id: "runtime.connection.failed", | ||
status_update: true as const, | ||
}; | ||
|
||
handleStatusMessage(message); | ||
|
||
expect(trackError).toHaveBeenCalledWith({ | ||
message: "Runtime connection failed", | ||
source: "chat", | ||
metadata: { msgId: "runtime.connection.failed" }, | ||
}); | ||
|
||
expect(store.dispatch).toHaveBeenCalledWith(expect.objectContaining({ | ||
payload: message, | ||
})); | ||
}); | ||
}); | ||
}); |
This file contains 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,165 @@ | ||
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest"; | ||
import { trackError, showErrorToast, showChatError } from "#/utils/error-handler"; | ||
import posthog from "posthog-js"; | ||
import toast from "react-hot-toast"; | ||
import * as Actions from "#/services/actions"; | ||
|
||
vi.mock("posthog-js", () => ({ | ||
default: { | ||
captureException: vi.fn(), | ||
}, | ||
})); | ||
|
||
vi.mock("react-hot-toast", () => ({ | ||
default: { | ||
error: vi.fn(), | ||
}, | ||
})); | ||
|
||
vi.mock("#/services/actions", () => ({ | ||
handleStatusMessage: vi.fn(), | ||
})); | ||
|
||
describe("Error Handler", () => { | ||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
describe("trackError", () => { | ||
it("should send error to PostHog with basic info", () => { | ||
const error = { | ||
message: "Test error", | ||
source: "test", | ||
}; | ||
|
||
trackError(error); | ||
|
||
expect(posthog.captureException).toHaveBeenCalledWith(new Error("Test error"), { | ||
error_source: "test", | ||
}); | ||
}); | ||
|
||
it("should include additional metadata in PostHog event", () => { | ||
const error = { | ||
message: "Test error", | ||
source: "test", | ||
metadata: { | ||
extra: "info", | ||
details: { foo: "bar" }, | ||
}, | ||
}; | ||
|
||
trackError(error); | ||
|
||
expect(posthog.captureException).toHaveBeenCalledWith(new Error("Test error"), { | ||
error_source: "test", | ||
extra: "info", | ||
details: { foo: "bar" }, | ||
}); | ||
}); | ||
}); | ||
|
||
describe("showErrorToast", () => { | ||
it("should log error and show toast", () => { | ||
const error = { | ||
message: "Toast error", | ||
source: "toast-test", | ||
}; | ||
|
||
showErrorToast(error); | ||
|
||
// Verify PostHog logging | ||
expect(posthog.captureException).toHaveBeenCalledWith(new Error("Toast error"), { | ||
error_source: "toast-test", | ||
}); | ||
|
||
// Verify toast was shown | ||
expect(toast.error).toHaveBeenCalled(); | ||
}); | ||
|
||
it("should include metadata in PostHog event when showing toast", () => { | ||
const error = { | ||
message: "Toast error", | ||
source: "toast-test", | ||
metadata: { context: "testing" }, | ||
}; | ||
|
||
showErrorToast(error); | ||
|
||
expect(posthog.captureException).toHaveBeenCalledWith(new Error("Toast error"), { | ||
error_source: "toast-test", | ||
context: "testing", | ||
}); | ||
}); | ||
|
||
it("should log errors from different sources with appropriate metadata", () => { | ||
// Test agent status error | ||
showErrorToast({ | ||
message: "Agent error", | ||
source: "agent-status", | ||
metadata: { id: "error.agent" }, | ||
}); | ||
|
||
expect(posthog.captureException).toHaveBeenCalledWith(new Error("Agent error"), { | ||
error_source: "agent-status", | ||
id: "error.agent", | ||
}); | ||
|
||
showErrorToast({ | ||
message: "Server error", | ||
source: "server", | ||
metadata: { error_code: 500, details: "Internal error" }, | ||
}); | ||
|
||
expect(posthog.captureException).toHaveBeenCalledWith(new Error("Server error"), { | ||
error_source: "server", | ||
error_code: 500, | ||
details: "Internal error", | ||
}); | ||
}); | ||
|
||
it("should log feedback submission errors with conversation context", () => { | ||
const error = new Error("Feedback submission failed"); | ||
showErrorToast({ | ||
message: error.message, | ||
source: "feedback", | ||
metadata: { conversationId: "123", error }, | ||
}); | ||
|
||
expect(posthog.captureException).toHaveBeenCalledWith(new Error("Feedback submission failed"), { | ||
error_source: "feedback", | ||
conversationId: "123", | ||
error, | ||
}); | ||
}); | ||
}); | ||
|
||
describe("showChatError", () => { | ||
it("should log error and show chat error message", () => { | ||
const error = { | ||
message: "Chat error", | ||
source: "chat-test", | ||
msgId: "123", | ||
}; | ||
|
||
showChatError(error); | ||
|
||
// Verify PostHog logging | ||
expect(posthog.captureException).toHaveBeenCalledWith(new Error("Chat error"), { | ||
error_source: "chat-test", | ||
}); | ||
|
||
// Verify error message was shown in chat | ||
expect(Actions.handleStatusMessage).toHaveBeenCalledWith({ | ||
type: "error", | ||
message: "Chat error", | ||
id: "123", | ||
status_update: true, | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains 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 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 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
Oops, something went wrong.