more org
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
"""Minimal reproducer for the auto_switch_sim GUI crash."""
|
||||
import sys
|
||||
import time
|
||||
import os
|
||||
sys.path.insert(0, 'C:/projects/manual_slop')
|
||||
sys.path.insert(0, 'C:/projects/manual_slop/src')
|
||||
|
||||
from src.api_hook_client import ApiHookClient
|
||||
client = ApiHookClient()
|
||||
if not client.wait_for_server(timeout=15):
|
||||
print('FAIL: server not up')
|
||||
sys.exit(1)
|
||||
print('OK: server up')
|
||||
|
||||
print('Step 1: click btn_reset')
|
||||
client.click('btn_reset')
|
||||
time.sleep(1.0)
|
||||
print('Step 1 done, status=', client.get_value('ai_status'))
|
||||
|
||||
print('Step 2: set_value current_provider gemini_cli')
|
||||
client.set_value('current_provider', 'gemini_cli')
|
||||
time.sleep(1.0)
|
||||
print('Step 2 done')
|
||||
|
||||
print('Step 3: set_value gcli_path')
|
||||
mock_path = os.path.abspath('tests/mock_concurrent_mma.py')
|
||||
client.set_value('gcli_path', '"' + sys.executable + '" "' + mock_path + '"')
|
||||
time.sleep(1.0)
|
||||
print('Step 3 done')
|
||||
+28
-34
@@ -1,3 +1,4 @@
|
||||
import difflib
|
||||
import shutil
|
||||
import os
|
||||
|
||||
@@ -8,8 +9,8 @@ from typing import List, Dict, Optional, Tuple
|
||||
|
||||
@dataclass
|
||||
class DiffHunk:
|
||||
header: str
|
||||
lines: List[str]
|
||||
header: str
|
||||
lines: List[str]
|
||||
old_start: int
|
||||
old_count: int
|
||||
new_start: int
|
||||
@@ -19,18 +20,16 @@ class DiffHunk:
|
||||
class DiffFile:
|
||||
old_path: str
|
||||
new_path: str
|
||||
hunks: List[DiffHunk]
|
||||
hunks: List[DiffHunk]
|
||||
|
||||
def parse_hunk_header(line: str) -> Optional[tuple[int, int, int, int]]:
|
||||
"""
|
||||
[C: tests/test_diff_viewer.py:test_parse_hunk_header]
|
||||
[C: tests/test_diff_viewer.py:test_parse_hunk_header]
|
||||
"""
|
||||
if not line.startswith("@@"):
|
||||
return None
|
||||
if not line.startswith("@@"): return None
|
||||
|
||||
parts = line.split()
|
||||
if len(parts) < 2:
|
||||
return None
|
||||
if len(parts) < 2: return None
|
||||
|
||||
old_part = parts[1][1:]
|
||||
new_part = parts[2][1:]
|
||||
@@ -52,7 +51,7 @@ def parse_diff(diff_text: str) -> List[DiffFile]:
|
||||
if not diff_text or not diff_text.strip():
|
||||
return []
|
||||
|
||||
files: List[DiffFile] = []
|
||||
files: List[DiffFile] = []
|
||||
current_file: Optional[DiffFile] = None
|
||||
current_hunk: Optional[DiffHunk] = None
|
||||
|
||||
@@ -83,21 +82,21 @@ def parse_diff(diff_text: str) -> List[DiffFile]:
|
||||
if hunk_info:
|
||||
old_start, old_count, new_start, new_count = hunk_info
|
||||
current_hunk = DiffHunk(
|
||||
header=line,
|
||||
lines=[],
|
||||
old_start=old_start,
|
||||
old_count=old_count,
|
||||
new_start=new_start,
|
||||
new_count=new_count
|
||||
header = line,
|
||||
lines = [],
|
||||
old_start = old_start,
|
||||
old_count = old_count,
|
||||
new_start = new_start,
|
||||
new_count = new_count
|
||||
)
|
||||
else:
|
||||
current_hunk = DiffHunk(
|
||||
header=line,
|
||||
lines=[],
|
||||
old_start=0,
|
||||
old_count=0,
|
||||
new_start=0,
|
||||
new_count=0
|
||||
header = line,
|
||||
lines = [],
|
||||
old_start = 0,
|
||||
old_count = 0,
|
||||
new_start = 0,
|
||||
new_count = 0
|
||||
)
|
||||
|
||||
elif current_hunk is not None:
|
||||
@@ -115,22 +114,17 @@ def parse_diff(diff_text: str) -> List[DiffFile]:
|
||||
|
||||
def get_line_color(line: str) -> Optional[str]:
|
||||
"""
|
||||
[C: tests/test_diff_viewer.py:test_get_line_color]
|
||||
[C: tests/test_diff_viewer.py:test_get_line_color]
|
||||
"""
|
||||
if line.startswith("+"):
|
||||
return "green"
|
||||
elif line.startswith("-"):
|
||||
return "red"
|
||||
elif line.startswith("@@"):
|
||||
return "cyan"
|
||||
if line.startswith("+"): return "green"
|
||||
elif line.startswith("-"): return "red"
|
||||
elif line.startswith("@@"): return "cyan"
|
||||
return None
|
||||
|
||||
def apply_patch_to_file(patch_text: str, base_dir: str = ".") -> Tuple[bool, str]:
|
||||
"""
|
||||
[C: src/gui_2.py:App._apply_pending_patch, tests/test_diff_viewer.py:test_apply_patch_simple, tests/test_diff_viewer.py:test_apply_patch_with_context]
|
||||
[C: src/gui_2.py:App._apply_pending_patch, tests/test_diff_viewer.py:test_apply_patch_simple, tests/test_diff_viewer.py:test_apply_patch_with_context]
|
||||
"""
|
||||
import difflib
|
||||
|
||||
diff_files = parse_diff(patch_text)
|
||||
if not diff_files:
|
||||
return False, "No valid diff found"
|
||||
@@ -147,7 +141,7 @@ def apply_patch_to_file(patch_text: str, base_dir: str = ".") -> Tuple[bool, str
|
||||
original_lines = f.read().splitlines(keepends=True)
|
||||
|
||||
new_lines = original_lines.copy()
|
||||
offset = 0
|
||||
offset = 0
|
||||
|
||||
for hunk in df.hunks:
|
||||
hunk_old_start = hunk.old_start - 1
|
||||
@@ -158,13 +152,13 @@ def apply_patch_to_file(patch_text: str, base_dir: str = ".") -> Tuple[bool, str
|
||||
|
||||
hunk_new_content: List[str] = []
|
||||
for line in hunk.lines:
|
||||
if line.startswith("+") and not line.startswith("+++"):
|
||||
if line.startswith("+") and not line.startswith("+++"):
|
||||
hunk_new_content.append(line[1:] + "\n")
|
||||
elif line.startswith(" ") or (line and not line.startswith(("-", "+", "@@"))):
|
||||
hunk_new_content.append(line + "\n")
|
||||
|
||||
new_lines = new_lines[:replace_start] + hunk_new_content + new_lines[replace_start + replace_count:]
|
||||
offset += len(hunk_new_content) - replace_count
|
||||
offset += len(hunk_new_content) - replace_count
|
||||
|
||||
with open(file_path, "w", encoding="utf-8", newline="") as f:
|
||||
f.writelines(new_lines)
|
||||
|
||||
+24
-29
File diff suppressed because one or more lines are too long
+2
-2
@@ -20,14 +20,14 @@ class FuzzyAnchor:
|
||||
def create_slice(cls, text: str, start_line: int, end_line: int) -> dict:
|
||||
"""
|
||||
start_line and end_line are 1-based.
|
||||
[C: src/gui_2.py:App._populate_auto_slices, src/gui_2.py:App._render_text_viewer_window, tests/test_fuzzy_anchor.py:TestFuzzyAnchor.test_create_slice_basic, tests/test_fuzzy_anchor.py:TestFuzzyAnchor.test_resolve_slice_anchor_mismatch_returns_none, tests/test_fuzzy_anchor.py:TestFuzzyAnchor.test_resolve_slice_exact_match, tests/test_fuzzy_anchor.py:TestFuzzyAnchor.test_resolve_slice_line_deleted_before_returns_none, tests/test_fuzzy_anchor.py:TestFuzzyAnchor.test_resolve_slice_line_inserted_before, tests/test_fuzzy_anchor.py:TestFuzzyAnchor.test_resolve_slice_multiple_lines_changed, tests/test_slice_editor_behavior.py:test_add_slice_with_annotations]
|
||||
[C: src/gui_2.py:App._populate_auto_slices, src/gui_2.py:App._render_text_viewer_window, tests/test_fuzzy_anchor.py:TestFuzzyAnchor.test_create_slice_basic, tests/test_fuzzy_anchor.py:TestFuzzyAnchor.test_resolve_slice_anchor_mismatch_returns_none, tests/test_fuzzy_anchor.py:TestFuzzyAnchor.test_resolve_slice_exact_match, tests/test_fuzzy_anchor.py:TestFuzzyAnchor.test_resolve_slice_line_deleted_before_returns_none, tests/test_fuzzy_anchor.py:TestFuzzyAnchor.test_resolve_slice_line_inserted_before, tests/test_fuzzy_anchor.py:TestFuzzyAnchor.test_resolve_slice_multiple_lines_changed, tests/test_slice_editor_behavior.py:test_add_slice_with_annotations]
|
||||
"""
|
||||
lines = text.splitlines()
|
||||
s_idx = max(0, start_line - 1)
|
||||
e_idx = min(len(lines), end_line)
|
||||
slice_lines = lines[s_idx:e_idx]
|
||||
slice_text = "\n".join(slice_lines)
|
||||
|
||||
|
||||
return {
|
||||
"start_line": start_line,
|
||||
"end_line": end_line,
|
||||
|
||||
@@ -189,18 +189,16 @@ class GeminiCliAdapter:
|
||||
self.last_latency = current_latency
|
||||
|
||||
return {
|
||||
"text": accumulated_text,
|
||||
"text": accumulated_text,
|
||||
"tool_calls": tool_calls,
|
||||
"stderr": stderr_final
|
||||
"stderr": stderr_final
|
||||
}
|
||||
|
||||
def count_tokens(self, contents: list[str]) -> int:
|
||||
"""
|
||||
|
||||
|
||||
Provides a character-based token estimation for the Gemini CLI.
|
||||
Uses 4 chars/token as a conservative average.
|
||||
[C: tests/test_gemini_cli_adapter_parity.py:TestGeminiCliAdapterParity.test_count_tokens_fallback]
|
||||
Provides a character-based token estimation for the Gemini CLI.
|
||||
Uses 4 chars/token as a conservative average.
|
||||
[C: tests/test_gemini_cli_adapter_parity.py:TestGeminiCliAdapterParity.test_count_tokens_fallback]
|
||||
"""
|
||||
total_chars = len("\n".join(contents))
|
||||
return total_chars // 4
|
||||
+1
-1
@@ -67,4 +67,4 @@ class HotReloader:
|
||||
for name in cls.HOT_MODULES:
|
||||
if not cls.reload(name, app):
|
||||
success = False
|
||||
return success
|
||||
return success
|
||||
|
||||
Reference in New Issue
Block a user