Compare commits

...

5 Commits

Author SHA1 Message Date
openhands aa5473ac04 Refactor action-suggestions.tsx to reduce duplication 2025-04-07 15:55:58 +00:00
openhands 32979a4864 Fix 'Push and create PR' button sending wrong query 2025-04-07 15:55:10 +00:00
Boxuan Li e951da7a25 Fix action execution server JSONResponse (#7721) 2025-04-07 22:49:39 +08:00
Carlos Freund f830d5814c fix(unittest): Parallel Test failure because of shared memory (#7729)
Co-authored-by: Carlos Freund <carlosfreund@gmail.com>
2025-04-07 09:29:22 -04:00
Carlos Freund 0519e9e3c2 fix(test) test_memory: initialize in fixture with new dict. (#7733)
Co-authored-by: Carlos Freund <carlosfreund@gmail.com>
2025-04-06 23:52:14 +02:00
4 changed files with 57 additions and 37 deletions
@@ -11,6 +11,14 @@ interface ActionSuggestionsProps {
onSuggestionsClick: (value: string) => void;
}
// Define button configurations to reduce duplication
interface ButtonConfig {
label: string;
value: string;
eventName: string;
callback?: () => void;
}
export function ActionSuggestions({
onSuggestionsClick,
}: ActionSuggestionsProps) {
@@ -30,16 +38,37 @@ export function ActionSuggestions({
const pr = isGitLab ? "merge request" : "pull request";
const prShort = isGitLab ? "MR" : "PR";
const terms = {
pr,
prShort,
pushToBranch: `Please push the changes to a remote branch on ${
// Define the button configurations
const PUSH_TO_BRANCH: ButtonConfig = {
label: t(I18nKey.ACTION$PUSH_TO_BRANCH),
value: `Please push the changes to a remote branch on ${
isGitLab ? "GitLab" : "GitHub"
}, but do NOT create a ${pr}. Please use the exact SAME branch name as the one you are currently on.`,
createPR: `Please push the changes to ${
eventName: "push_to_branch_button_clicked",
};
const PUSH_AND_CREATE_PR: ButtonConfig = {
label: t(I18nKey.ACTION$PUSH_CREATE_PR),
value: `Please push the changes to ${
isGitLab ? "GitLab" : "GitHub"
} and open a ${pr}. Please create a meaningful branch name that describes the changes. If a ${pr} template exists in the repository, please follow it when creating the ${prShort} description.`,
pushToPR: `Please push the latest changes to the existing ${pr}.`,
eventName: "create_pr_button_clicked",
callback: () => setHasPullRequest(true),
};
const PUSH_TO_PR: ButtonConfig = {
label: t(I18nKey.ACTION$PUSH_CHANGES_TO_PR),
value: `Please push the latest changes to the existing ${pr}.`,
eventName: "push_to_pr_button_clicked",
};
// Helper function to handle button clicks
const handleButtonClick = (config: ButtonConfig) => {
posthog.capture(config.eventName);
onSuggestionsClick(config.value);
if (config.callback) {
config.callback();
}
};
return (
@@ -50,36 +79,26 @@ export function ActionSuggestions({
<>
<SuggestionItem
suggestion={{
label: t(I18nKey.ACTION$PUSH_TO_BRANCH),
value: terms.pushToBranch,
}}
onClick={(value) => {
posthog.capture("push_to_branch_button_clicked");
onSuggestionsClick(value);
label: PUSH_TO_BRANCH.label,
value: PUSH_TO_BRANCH.value,
}}
onClick={() => handleButtonClick(PUSH_TO_BRANCH)}
/>
<SuggestionItem
suggestion={{
label: t(I18nKey.ACTION$PUSH_CREATE_PR),
value: terms.createPR,
}}
onClick={(value) => {
posthog.capture("create_pr_button_clicked");
onSuggestionsClick(value);
setHasPullRequest(true);
label: PUSH_AND_CREATE_PR.label,
value: PUSH_AND_CREATE_PR.value,
}}
onClick={() => handleButtonClick(PUSH_AND_CREATE_PR)}
/>
</>
) : (
<SuggestionItem
suggestion={{
label: t(I18nKey.ACTION$PUSH_CHANGES_TO_PR),
value: terms.pushToPR,
}}
onClick={(value) => {
posthog.capture("push_to_pr_button_clicked");
onSuggestionsClick(value);
label: PUSH_TO_PR.label,
value: PUSH_TO_PR.value,
}}
onClick={() => handleButtonClick(PUSH_TO_PR)}
/>
)}
</div>
+4 -1
View File
@@ -585,7 +585,10 @@ if __name__ == '__main__':
logger.error(f'Validation error occurred: {exc}')
return JSONResponse(
status_code=422,
content={'detail': 'Invalid request parameters', 'errors': exc.errors()},
content={
'detail': 'Invalid request parameters',
'errors': str(exc.errors()),
},
)
@app.middleware('http')
+4 -4
View File
@@ -3,14 +3,14 @@ import os
from openhands.core.logger import openhands_logger as logger
from openhands.storage.files import FileStore
IN_MEMORY_FILES: dict = {}
class InMemoryFileStore(FileStore):
files: dict[str, str]
def __init__(self, files: dict[str, str] = IN_MEMORY_FILES):
self.files = files
def __init__(self, files: dict[str, str] | None = None) -> None:
self.files = {}
if files is not None:
self.files = files
def write(self, path: str, contents: str | bytes) -> None:
if isinstance(contents, bytes):
+5 -7
View File
@@ -28,7 +28,7 @@ from openhands.storage.memory import InMemoryFileStore
@pytest.fixture
def file_store():
"""Create a temporary file store for testing."""
return InMemoryFileStore()
return InMemoryFileStore({})
@pytest.fixture
@@ -190,10 +190,9 @@ async def test_memory_with_microagents():
assert 'magic word' in observation.microagent_knowledge[0].content
def test_memory_repository_info(prompt_dir):
def test_memory_repository_info(prompt_dir, file_store):
"""Test that Memory adds repository info to RecallObservations."""
# Create an in-memory file store and real event stream
file_store = InMemoryFileStore()
# real event stream
event_stream = EventStream(sid='test-session', file_store=file_store)
# Create a test repo microagent first
@@ -321,10 +320,9 @@ async def test_memory_with_agent_microagents():
assert 'magic word' in observation.microagent_knowledge[0].content
def test_memory_multiple_repo_microagents(prompt_dir):
def test_memory_multiple_repo_microagents(prompt_dir, file_store):
"""Test that Memory loads and concatenates multiple repo microagents correctly."""
# Create an in-memory file store and real event stream
file_store = InMemoryFileStore()
# Create real event stream
event_stream = EventStream(sid='test-session', file_store=file_store)
# Create two test repo microagents