File size: 3,834 Bytes
5e5d6c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
from __future__ import annotations

from ctx.engine.observation import normalize_public_current_work
from ctx.engine.planner import BoundedCapabilityPlanner, CapabilityCandidate, WorkObservation


def test_click_task_normalizes_only_bounded_concrete_public_signals() -> None:
    observation = normalize_public_current_work(
        query="implement and review a small public Python Click output helper with focused tests",
        task=(
            "Add a public `click.echo_json(value, file=None, *, sort_keys=True, "
            "ensure_ascii=False)` helper. Serialize with `json.dumps`, use `echo`, emit one "
            "trailing newline, preserve Unicode, and keep serialization errors visible."
        ),
        language="py",
        repo_slug="pallets/click",
    )

    assert observation.languages == ("python",)
    assert observation.signals == (
        "click",
        "dumps",
        "echo",
        "json",
        "output",
        "public",
        "serialization",
        "sort",
    )
    assert observation.requested_limit == 5


def test_requests_task_preserves_repository_and_exception_boundary_concepts() -> None:
    observation = normalize_public_current_work(
        query="implement and review a small Requests Response JSON fallback API with tests",
        task=(
            "Add `Response.json_or(default, **kwargs)`. Return parsed JSON including null; "
            "return the default only for `JSONDecodeError`; forward decoder keyword arguments "
            "and do not swallow unrelated exceptions."
        ),
        language="Python",
        repo_slug="psf/requests",
    )

    assert observation.languages == ("python",)
    assert observation.signals == (
        "api",
        "decoding",
        "fallback",
        "json",
        "jsondecodeerror",
        "keyword",
        "requests",
        "response",
    )


def test_language_aliases_identifier_splitting_and_repo_facts_are_canonical() -> None:
    observation = normalize_public_current_work(
        query="repair parseHTTPResponse",
        task="Update `HTTPClient.parse_response` safely.",
        language="C++",
        repo_slug="acme/http-client",
        repo_facts=("CMake", "HTTP Client", "cmake"),
    )

    assert observation.languages == ("cpp",)
    assert observation.signals == (
        "client",
        "cmake",
        "http",
        "parse",
        "response",
    )


def test_language_without_concrete_work_abstains_before_catalog_access() -> None:
    observation = normalize_public_current_work(
        query="please implement this feature",
        task="make the requested change",
        language="typescript",
        repo_slug="",
    )

    assert observation.languages == ("typescript",)
    assert observation.signals == ()
    assert observation.requested_limit == 0

    class ForbiddenSource:
        catalog_snapshot_digest = "0" * 64

        def retrieve(self, _observation: WorkObservation) -> tuple[CapabilityCandidate, ...]:
            raise AssertionError("catalog must not be queried for generic work")

    plan = BoundedCapabilityPlanner(ForbiddenSource()).plan(observation)
    assert (plan.status, plan.abstention_code) == (
        "abstained",
        "no-relevant-capability",
    )


def test_normalizer_does_not_retain_raw_private_or_workflow_prose() -> None:
    secret = "PRIVATE_REFERENCE_PATCH_SENTINEL"
    observation = normalize_public_current_work(
        query="review the implementation",
        task=f"{secret} add `safe_decode` for Unicode decoding",
        language="python",
        repo_slug="org/repo",
    )

    serialized = repr(observation)
    assert secret not in serialized
    assert "private" not in observation.signals
    assert "reference" not in observation.signals
    assert observation.signals == ("decoding", "unicode")