Preliminary theoretical analysis + illustrations for why test-driven localization (issue $\rightarrow$ tests $\rightarrow$ trace-constrained code) reduces localization uncertainty vs direct issue-to-code matching.
Given an issue description $d$ and repository $R$, let $L$ be the universe of candidate locations (e.g., all functions/methods) with $N = |L|$. Let $\mathcal{G}\subseteq L$ be the ground-truth edit set. Any localization system returns a ranked list of locations under a budget $k_{\text{ret}}$; the returned set is $L_{\text{ret}}$ with $|L_{\text{ret}}|=k_{\text{ret}}$.
In the test-driven pipeline, we retrieve a fixed-size set of tests $\hat{\mathcal{T}}_d$, $|\hat{\mathcal{T}}_d|=k_{\text{test}}$. Each test $t$ has a dynamic coverage set $\text{Cov}(t) \subseteq L$. The trace-constrained subspace is their union:
$$L_{\text{cov}} = \bigcup_{t\in \hat{\mathcal{T}}_d}\text{Cov}(t), \qquad N_{\text{cov}} = |L_{\text{cov}}|.$$
We approximate uncertainty with Hartley entropy: $$H(\mathcal{C}) \approx \log_2|\mathcal{C}|,$$ capturing the ambiguity of selecting correct edits from a candidate set. We do not estimate the intractable distribution $P(L\mid d)$; instead, we quantify relative uncertainty reduction induced by hierarchical retrieval and trace constraints.
A direct method ranks the entire space $L$ and returns $L_{\text{ret}}$. Let $g_{\text{ret}} = |\mathcal{G}\cap L_{\text{ret}}|$ denote how many ground-truth edits fall inside the returned set. We use a partition-based proxy that explicitly accounts for whether true edits fall inside or outside $L_{\text{ret}}$:
$$ \begin{aligned} H_{\text{direct}} ={}& 1[g_{\text{ret}} > 0]\cdot \Big(-\log_2 \frac{g_{\text{ret}}}{|L_{\text{ret}}|}\Big) + 1[|\mathcal{G}|-g_{\text{ret}} > 0]\cdot \Big(-\log_2 \frac{|\mathcal{G}|-g_{\text{ret}}}{N-|L_{\text{ret}}|}\Big). \end{aligned} $$
Test-driven localization decomposes the search into two stages: (i) retrieving requirement-relevant tests, and (ii) localizing within a trace-constrained subspace. We model uncertainty as the sum of stage-wise entropies, making realistic failure modes explicit.
A retrieved test is effective if it covers at least one ground-truth location: $\text{Cov}(t)\cap \mathcal{G}\neq\emptyset$. Let $n$ be the number of effective tests in $\hat{\mathcal{T}}_d$.
$$H_{\text{stage1}} = 1[n>0]\cdot \Big(-\log_2 \frac{n}{k_{\text{test}}}\Big).$$
We partition the global space into three disjoint regions induced by the trace subspace and the returned top-$k_{\text{ret}}$ locations. Critically, in the test-driven pipeline, $L_{\text{ret}}\subseteq L_{\text{cov}}$.
$$S_{\text{ret}} = L_{\text{ret}}, \quad S_{\text{cov}} = L_{\text{cov}} \setminus L_{\text{ret}}, \quad S_{\text{excl}} = L\setminus L_{\text{cov}}.$$
Let $N_i=|S_i|$ and $g_i=|\mathcal{G}\cap S_i|$ for $i\in\{\text{ret},\text{cov},\text{excl}\}$. Define:
$$H_{\text{stage2}} = \sum_{i\in\{\text{ret},\text{cov},\text{excl}\},\, g_i>0} \Big(-\log_2 \frac{g_i}{N_i}\Big).$$
The hierarchical uncertainty is: $$H_{\text{indirect}} = H_{\text{stage1}} + H_{\text{stage2}}.$$
For each issue, define empirical uncertainty reduction: $$\Delta H = H_{\text{direct}} - H_{\text{indirect}}.$$ A positive $\Delta H$ indicates that introducing tests and traces reduces localization ambiguity compared to direct matching under the same return budget $k_{\text{ret}}$.
This page prioritizes case-driven interpretability. We provide representative mini cases with intermediate quantities (set sizes and overlaps) to illustrate how $\Delta H$ is computed and why it becomes positive/negative. Full narratives and raw artifacts are linked from each case.
Instance: sympy-Issues-19747
· Budgets: k_test=5, k_ret=10, gt_threshold=1.0
· Gain: ΔH = 15.46 bits
· External failure: No
N=28222 shrinks to N_cov=626 (~45.1× smaller),
and all GT edits are covered (g_ext=0), so indirect uncertainty is tiny.
| Item | Value | Notes |
|---|---|---|
| Full case page | case_sympy.html | Inspectable artifacts (tests, top-k, GT) + computed terms. |
| Global space | N = 28222 | All candidate code locations. |
| Trace subspace | N_cov = 626 | Union coverage of selected tests. |
| GT size | |G| = 2 | Two GT edit locations. |
| Direct hits | g_ret_direct = 1 | Direct top-10 includes 1 GT. |
| Indirect hits | g_ret_indirect = 2 | Indirect top-10 includes both GT. |
| Effective tests | n_effective = 4 / 5 | Stage1 is small. |
| Coverage gap | g_ext = 0 | No GT outside trace coverage. |
H_direct = 18.105949419261542
H_stage1 = 0.3219280948873623
H_stage2 = 2.321928094887362
H_indirect = 2.6438561897747244
ΔH = 15.462093229486818
Instance: xarray-Issues-3992
· Budgets: k_test=5, k_ret=10, gt_threshold=1.0
· Gain: ΔH = -1.55 bits
· External failure: Yes
N=2011 → N_cov=271, ~7.4× smaller),
two GT edits are outside trace coverage (g_ext=2), and only 1/5 retrieved tests is effective,
so indirect uncertainty becomes larger than direct.
| Item | Value | Notes |
|---|---|---|
| Full case page | case_pydata__xarray.html | Inspectable artifacts (tests, top-k, GT) + computed terms. |
| Global space | N = 2011 |
All candidate code locations. |
| Trace subspace | N_cov = 271 |
Union coverage of selected tests (L_sub_size). |
| GT size | |G| = 4 |
Four GT edit locations. |
| Direct hits | g_ret_direct = 1 |
Direct top-10 includes 1 GT. |
| Indirect hits | g_ret_indirect = 2 |
Indirect (trace-constrained) top-10 includes 2 GT. |
| Effective tests | n_effective = 1 / 5 |
Stage1 is large: H_stage1 = -log2(1/5) = 2.3219. |
| Coverage gap | g_ext = 2 |
Two GT locations fall outside trace coverage (external penalty). |
| Outcome | ΔH = -1.553 (negative) | H_direct=12.703, H_indirect=14.257. |
H_direct = 12.703471046071947
H_stage1 = 2.321928094887362
H_stage2 = 11.934796592178403
H_indirect = 14.256724687065764
ΔH = -1.5532536409938178
- Selected tests (k_test=5):
xarray/tests/test_dataset.py::test_differentiate
xarray/tests/test_dataset.py::test_integrate
xarray/tests/test_dataset.py::TestDataset.test_expand_dims_mixed_int_and_coords
xarray/tests/test_concat.py::test_concat_merge_single_non_dim_coord
xarray/tests/test_dataset.py::TestDataset.test_dataset_diff_n2
- Union coverage size:
N_cov = 271 (L_sub_size)
- GT locations (|G|=4):
xarray/core/dataarray.py::DataArray.integrate
xarray/core/dataset.py::Dataset.integrate
xarray/core/dataarray.py::DataArray.map_blocks
xarray/core/dataarray.py::DataArray.unify_chunks
- Uncovered GT (g_ext=2):
xarray/core/dataarray.py::DataArray.map_blocks
xarray/core/dataarray.py::DataArray.unify_chunks