Skip to content

Dianel555/DSkills / skills/ace-tool

ace-tool

Verified

Semantic codebase search, code indexing, and prompt enhancement via standalone CLI. Use when: (1) Semantic code search with natural language queries, (2) Code indexing for remote codebase retrieval, (3) Prompt enhancement with codebase context, (4) Before grep/find/glob operations for better accuracy, (5) Complex requirements clarification, (6) Large codebase navigation. Triggers: "search context", "enhance prompt", "find code that", "index project", "clarify requirements". IMPORTANT: Always use ace-tool BEFORE grep/find/glob for semantic-level code location.

tests/test_empty_retrieval_fallback.py

View on GitHub
"""A successful but empty remote search must not suppress local results."""

import pytest
from client import AceToolClient, IndexReadinessError
from templates import NO_RELEVANT_CODE_CONTEXT

EMPTY_HEADER = "The following code sections were retrieved:"


def _client():
    return AceToolClient(base_url="https://example.invalid", token="dummy")


def _local_result(query="query"):
    return {"results": [{"file": "src/example.py", "score": 1}], "query": query, "mode": "local_fallback"}


@pytest.mark.parametrize("remote_text", ["", "   \n", None, EMPTY_HEADER, f"\n{EMPTY_HEADER}\n"])
def test_empty_remote_result_falls_back_locally(monkeypatch, remote_text):
    client = _client()
    monkeypatch.setattr(client, "_remote_search", lambda *args: {"results": remote_text, "mode": "remote"})
    local = _local_result()
    monkeypatch.setattr(client, "_local_search", lambda *args: local)
    assert client.search_context("workspace", "query") == local


@pytest.mark.parametrize("remote_text", ["matched code", f"{EMPTY_HEADER}\n\nsrc/example.py:1"])
def test_nonempty_remote_result_is_preserved(monkeypatch, remote_text):
    client = _client()
    remote = {"results": remote_text, "mode": "remote"}
    monkeypatch.setattr(client, "_remote_search", lambda *args: remote)
    monkeypatch.setattr(client, "_local_search", lambda *args: pytest.fail("nonempty result was discarded"))
    assert client.search_context("workspace", "query") == remote


def test_readiness_failure_does_not_trigger_empty_result_fallback(monkeypatch):
    client = _client()

    def fail(*args):
        raise IndexReadinessError("index timed out")

    monkeypatch.setattr(client, "_remote_search", fail)
    monkeypatch.setattr(client, "_local_search", lambda *args: pytest.fail("readiness failure was hidden"))
    with pytest.raises(IndexReadinessError, match="timed out"):
        client.search_context("workspace", "query")


def test_third_party_injection_formats_local_fallback_as_text(monkeypatch):
    client = _client()
    client.endpoint = "claude"
    monkeypatch.setattr(client, "_should_include_search_context", lambda: True)
    monkeypatch.setattr(client, "_remote_search", lambda *args: {"results": EMPTY_HEADER})
    monkeypatch.setattr(client, "_local_search", lambda *args: _local_result("original request"))
    prompt = client._maybe_inject_search_context("claude", "original request", "workspace")
    assert "<codebase_context>" in prompt
    assert "src/example.py" in prompt
    assert "<original_request>\noriginal request\n</original_request>" in prompt
    assert "'file':" not in prompt


def test_cloud_prompt_context_formats_local_fallback_as_text(monkeypatch):
    client = _client()
    monkeypatch.setattr(client, "_remote_search", lambda *args: {"results": "   "})
    monkeypatch.setattr(client, "_local_search", lambda *args: _local_result())
    context = client._get_retrieval_context("workspace", "query")
    assert "<codebase-context>" in context
    assert "src/example.py" in context
    assert "'file':" not in context


def test_empty_local_fallback_uses_injection_placeholder(monkeypatch):
    client = _client()
    client.endpoint = "claude"
    monkeypatch.setattr(client, "_should_include_search_context", lambda: True)
    monkeypatch.setattr(client, "_remote_search", lambda *args: {"results": ""})
    monkeypatch.setattr(client, "_local_search", lambda *args: {"results": [], "mode": "local_fallback"})
    prompt = client._maybe_inject_search_context("claude", "query", "workspace")
    assert NO_RELEVANT_CODE_CONTEXT in prompt
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall