test(mock): major mock_gemini_cli rewrite — robust is_resume detection, tool triggers
This commit is contained in:
@@ -18,6 +18,117 @@ def main() -> None:
|
|||||||
if len(sys.argv) > 1 and sys.argv[1] in ["mcp", "extensions", "skills", "hooks"]:
|
if len(sys.argv) > 1 and sys.argv[1] in ["mcp", "extensions", "skills", "hooks"]:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Check for multi-round integration test triggers
|
||||||
|
is_resume = '--resume' in " ".join(sys.argv) or '"role": "tool"' in prompt or '"tool_call_id"' in prompt
|
||||||
|
is_resume_list = is_resume and 'list_directory' in prompt
|
||||||
|
is_resume_read = is_resume and 'read_file' in prompt
|
||||||
|
is_resume_powershell = is_resume and 'run_powershell' in prompt
|
||||||
|
|
||||||
|
if 'List the files in the current directory' in prompt or 'List the files' in prompt or is_resume_list:
|
||||||
|
if not is_resume:
|
||||||
|
print(json.dumps({
|
||||||
|
"type": "message",
|
||||||
|
"role": "assistant",
|
||||||
|
"content": "I will list the files in the current directory."
|
||||||
|
}), flush=True)
|
||||||
|
print(json.dumps({
|
||||||
|
"type": "tool_use",
|
||||||
|
"name": "list_directory",
|
||||||
|
"id": "mock-list-dir-call",
|
||||||
|
"args": {"path": "."}
|
||||||
|
}), flush=True)
|
||||||
|
print(json.dumps({
|
||||||
|
"type": "result",
|
||||||
|
"status": "success",
|
||||||
|
"stats": {"total_tokens": 10, "input_tokens": 5, "output_tokens": 5},
|
||||||
|
"session_id": "mock-session-list-dir"
|
||||||
|
}), flush=True)
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
print(json.dumps({
|
||||||
|
"type": "message",
|
||||||
|
"role": "assistant",
|
||||||
|
"content": "Here are the files in the current directory: aggregate.py, ai_client.py, etc."
|
||||||
|
}), flush=True)
|
||||||
|
print(json.dumps({
|
||||||
|
"type": "result",
|
||||||
|
"status": "success",
|
||||||
|
"stats": {"total_tokens": 20, "input_tokens": 10, "output_tokens": 10},
|
||||||
|
"session_id": "mock-session-list-dir-res"
|
||||||
|
}), flush=True)
|
||||||
|
return
|
||||||
|
|
||||||
|
if 'Read the first 10 lines' in prompt or is_resume_read:
|
||||||
|
if not is_resume:
|
||||||
|
print(json.dumps({
|
||||||
|
"type": "message",
|
||||||
|
"role": "assistant",
|
||||||
|
"content": "I will read the first 10 lines of the file."
|
||||||
|
}), flush=True)
|
||||||
|
# Extract file name if present
|
||||||
|
file_path = "aggregate.py"
|
||||||
|
if "aggregate.py" in prompt: file_path = "aggregate.py"
|
||||||
|
print(json.dumps({
|
||||||
|
"type": "tool_use",
|
||||||
|
"name": "read_file",
|
||||||
|
"id": "mock-read-file-call",
|
||||||
|
"args": {"path": file_path, "start_line": 1, "end_line": 10}
|
||||||
|
}), flush=True)
|
||||||
|
print(json.dumps({
|
||||||
|
"type": "result",
|
||||||
|
"status": "success",
|
||||||
|
"stats": {"total_tokens": 10, "input_tokens": 5, "output_tokens": 5},
|
||||||
|
"session_id": "mock-session-read-file"
|
||||||
|
}), flush=True)
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
print(json.dumps({
|
||||||
|
"type": "message",
|
||||||
|
"role": "assistant",
|
||||||
|
"content": "Here are the lines from the file: [Line 1, Line 2...]"
|
||||||
|
}), flush=True)
|
||||||
|
print(json.dumps({
|
||||||
|
"type": "result",
|
||||||
|
"status": "success",
|
||||||
|
"stats": {"total_tokens": 20, "input_tokens": 10, "output_tokens": 10},
|
||||||
|
"session_id": "mock-session-read-file-res"
|
||||||
|
}), flush=True)
|
||||||
|
return
|
||||||
|
|
||||||
|
if 'Create a hello.ps1 script' in prompt or is_resume_powershell:
|
||||||
|
if not is_resume:
|
||||||
|
print(json.dumps({
|
||||||
|
"type": "message",
|
||||||
|
"role": "assistant",
|
||||||
|
"content": "I will create the hello.ps1 script."
|
||||||
|
}), flush=True)
|
||||||
|
print(json.dumps({
|
||||||
|
"type": "tool_use",
|
||||||
|
"name": "run_powershell",
|
||||||
|
"id": "mock-hello-call",
|
||||||
|
"args": {"script": "Write-Output 'Simulation Test'"}
|
||||||
|
}), flush=True)
|
||||||
|
print(json.dumps({
|
||||||
|
"type": "result",
|
||||||
|
"status": "success",
|
||||||
|
"stats": {"total_tokens": 10, "input_tokens": 5, "output_tokens": 5},
|
||||||
|
"session_id": "mock-session-hello"
|
||||||
|
}), flush=True)
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
print(json.dumps({
|
||||||
|
"type": "message",
|
||||||
|
"role": "assistant",
|
||||||
|
"content": "Script hello.ps1 created successfully. Output: Simulation Test"
|
||||||
|
}), flush=True)
|
||||||
|
print(json.dumps({
|
||||||
|
"type": "result",
|
||||||
|
"status": "success",
|
||||||
|
"stats": {"total_tokens": 20, "input_tokens": 10, "output_tokens": 10},
|
||||||
|
"session_id": "mock-session-hello-res"
|
||||||
|
}), flush=True)
|
||||||
|
return
|
||||||
|
|
||||||
# Check for specific simulation contexts
|
# Check for specific simulation contexts
|
||||||
# Use the full prompt string since context length can vary depending on history or project state
|
# Use the full prompt string since context length can vary depending on history or project state
|
||||||
if 'You are assigned to Ticket' in prompt:
|
if 'You are assigned to Ticket' in prompt:
|
||||||
@@ -60,49 +171,67 @@ def main() -> None:
|
|||||||
}), flush=True)
|
}), flush=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Check for multi-round integration test triggers
|
|
||||||
is_resume = '--resume' in " ".join(sys.argv) or 'role: tool' in prompt or 'tool_call_id' in prompt
|
|
||||||
if is_resume or 'Perform multi-round tool test' in prompt or 'Please read test.txt' in prompt or 'Deny me' in prompt:
|
if is_resume or 'Perform multi-round tool test' in prompt or 'Please read test.txt' in prompt or 'Deny me' in prompt:
|
||||||
if not is_resume:
|
if not is_resume:
|
||||||
# First round: emit tool call
|
# First round: emit tool call
|
||||||
print(json.dumps({
|
print(json.dumps({
|
||||||
"type": "message",
|
"type": "message",
|
||||||
"role": "assistant",
|
"role": "assistant",
|
||||||
"content": "I need to check the directory first."
|
"content": "I need to check the directory first."
|
||||||
}), flush=True)
|
}), flush=True)
|
||||||
print(json.dumps({
|
print(json.dumps({
|
||||||
"type": "tool_use",
|
"type": "tool_use",
|
||||||
"name": "run_powershell",
|
"name": "run_powershell",
|
||||||
"id": "mock-call-1",
|
"id": "mock-call-1",
|
||||||
"args": {"script": "Get-ChildItem"}
|
"args": {"script": "Get-ChildItem"}
|
||||||
}), flush=True)
|
}), flush=True)
|
||||||
print(json.dumps({
|
print(json.dumps({
|
||||||
"type": "result",
|
"type": "result",
|
||||||
"status": "success",
|
"status": "success",
|
||||||
"stats": {"total_tokens": 10, "input_tokens": 10, "output_tokens": 0},
|
"stats": {"total_tokens": 10, "input_tokens": 10, "output_tokens": 0},
|
||||||
"session_id": "mock-session-default"
|
"session_id": "mock-session-default"
|
||||||
}), flush=True)
|
}), flush=True)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
# Second round
|
# Second round
|
||||||
if "USER REJECTED" in prompt:
|
if "USER REJECTED" in prompt:
|
||||||
print(json.dumps({
|
print(json.dumps({
|
||||||
"type": "message",
|
"type": "message",
|
||||||
"role": "assistant",
|
"role": "assistant",
|
||||||
"content": "Tool execution was denied. I cannot proceed."
|
"content": "Tool execution was denied. I cannot proceed."
|
||||||
}), flush=True)
|
}), flush=True)
|
||||||
else:
|
else:
|
||||||
print(json.dumps({
|
print(json.dumps({
|
||||||
"type": "message",
|
"type": "message",
|
||||||
"role": "assistant",
|
"role": "assistant",
|
||||||
"content": "I have processed the tool results and here is the final answer."
|
"content": "I have processed the tool results and here is the final answer."
|
||||||
}), flush=True)
|
}), flush=True)
|
||||||
print(json.dumps({
|
print(json.dumps({
|
||||||
"type": "result",
|
"type": "result",
|
||||||
"status": "success",
|
"status": "success",
|
||||||
"stats": {"total_tokens": 100, "input_tokens": 80, "output_tokens": 20},
|
"stats": {"total_tokens": 100, "input_tokens": 80, "output_tokens": 20},
|
||||||
"session_id": "mock-session-final"
|
"session_id": "mock-session-final"
|
||||||
}), flush=True)
|
}), flush=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Default response
|
||||||
|
content = "I am a mock CLI and I have processed your request."
|
||||||
|
if 'Acknowledged' in prompt:
|
||||||
|
content = "Acknowledged."
|
||||||
|
elif 'What is the current date' in prompt:
|
||||||
|
content = "The current date is March 1, 2026."
|
||||||
|
|
||||||
|
print(json.dumps({
|
||||||
|
"type": "message",
|
||||||
|
"role": "assistant",
|
||||||
|
"content": content
|
||||||
|
}), flush=True)
|
||||||
|
print(json.dumps({
|
||||||
|
"type": "result",
|
||||||
|
"status": "success",
|
||||||
|
"stats": {"total_tokens": 50, "input_tokens": 25, "output_tokens": 25},
|
||||||
|
"session_id": "mock-session-default"
|
||||||
|
}), flush=True)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user