Skip to content

Commit

Permalink
Fixed e2e test (race condition with git)
Browse files Browse the repository at this point in the history
Signed-off-by: JonahSussman <[email protected]>
  • Loading branch information
JonahSussman committed Feb 13, 2025
1 parent 9a1995a commit 15fb23b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
4 changes: 2 additions & 2 deletions example/initialize.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ file_log_level = "DEBUG"
log_dir_path = "./logs"

[model_provider]
provider = "ChatIBMGenAI"
provider = "ChatOpenAI"

[model_provider.args]
model_id = "meta-llama/llama-3-1-70b-instruct"
model = "kai-test-generation"
15 changes: 7 additions & 8 deletions example/run_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from kai.logging.logging import get_logger, init_logging_from_log_config
from kai.rpc_server.server import (
GetCodeplanAgentSolutionParams,
GetCodeplanAgentSolutionResult,
KaiRpcApplication,
KaiRpcApplicationConfig,
)
Expand Down Expand Up @@ -91,6 +92,8 @@ def initialize_rpc_server(
env=os.environ,
)

log.info(f"RPC Server started with pid: {rpc_subprocess.pid}")

log.info(rpc_subprocess.args)

app = KaiRpcApplication()
Expand Down Expand Up @@ -149,20 +152,16 @@ def blah(
rpc_server.stop()


class CodePlanSolutionResponse(BaseModel):
diff: str
modified_files: list[str]
encountered_errors: list[str]


def apply_diff(filepath: Path, solution: CodePlanSolutionResponse) -> None:
def apply_diff(filepath: Path, solution: GetCodeplanAgentSolutionResult) -> None:
KAI_LOG.info(f"Writing updated source code to {filepath}")
try:
time.sleep(0.1) # TODO: Investigate git race condition
subprocess.run( # trunk-ignore(bandit/B603,bandit/B607)
["git", "apply"],
input=solution.diff.encode("utf-8"),
cwd=SAMPLE_APP_DIR,
check=True,
capture_output=True,
)
except Exception as e:
KAI_LOG.error(f"Failed to write updated_file @ {filepath} with error: {e}")
Expand Down Expand Up @@ -205,7 +204,7 @@ def process_file(
elif not isinstance(response, JsonRpcResponse):
return f"Failed to generate fix for file {params.file_path} - invalid response type {type(response)}"
try:
solution = CodePlanSolutionResponse.model_validate(response.result)
solution = GetCodeplanAgentSolutionResult.model_validate(response.result)
except Exception as e:
return f"Failed to parse response {params.file_path} - {e}"

Expand Down
2 changes: 2 additions & 0 deletions kai/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ def __init__(
self.stop()
raise Exception("Analyzer failed to start: process exited immediately")

logger.debug(f"analyzer rpc server started. pid: {self.rpc_server.pid}")

# trunk-ignore-end(bandit/B603)
self.excluded_paths = excluded_paths

Expand Down
10 changes: 8 additions & 2 deletions kai/reactive_codeplanner/agent/analyzer_fix/agent.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import re
from dataclasses import dataclass
from logging import DEBUG
from pathlib import Path
from typing import Optional, cast

Expand Down Expand Up @@ -215,11 +214,13 @@ def guess_language(code: str, filename: Optional[str] = None) -> str:
all_lexers = lexers.get_all_lexers()
largest_rv_lexer = None
largest_rv = 0.0
not_found_lexers: list[str] = []
for name, _, _, _ in all_lexers:
try:
lexer_found = cast(LexerMeta, lexers.get_lexer_by_name(name))
except ClassNotFound:
logger.log(DEBUG, "unable to find lexer class for name: %s", name)
# FIXME: This is adding significant time to our request
not_found_lexers.append(name)
continue
if filename:
file_path = Path(filename)
Expand All @@ -231,6 +232,11 @@ def guess_language(code: str, filename: Optional[str] = None) -> str:
largest_rv = rv
largest_rv_lexer = lexer_found

if len(not_found_lexers) > 0:
logger.debug(
"Could not find lexers for the following names: %s", not_found_lexers
)

if largest_rv_lexer:
# Remove all the extra information after the + sign
logger.debug(
Expand Down
5 changes: 3 additions & 2 deletions kai/reactive_codeplanner/vfs/git_vfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,9 @@ def diff(self, other: "RepoContextSnapshot") -> tuple[int, str, str]:
Returns the diff between the current snapshot and another snapshot.
"""
result = self.git(["diff", other.git_sha, self.git_sha])
if result[0] != 0:
raise Exception(f"Failed to get diff: {result[2]}")
if not result[1].endswith("\n"): # HACK: This may not be needed
result = result[0], result[1] + "\n", result[2]

return result


Expand Down

0 comments on commit 15fb23b

Please sign in to comment.