mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-10-19 04:59:28 +00:00
fix(hunt): diff producer records where a push removed lines; worktree checkout is proven complete
Two instrument findings from the first access-control feature table (952 rows, 74 positive rows): 1. A fix that adds a guard is, replayed base-to-head, a push that removes it. The diff producer only kept hunks with added lines at head, so 38 of 74 positive rows had no hunk in their file at all and 69 of 74 were "not on a changed line", while 60% of ordinary rows were. The diff annotation separated the labels by construction and was blind to exactly the access-control shape. The producer (version 2) now records per file the head lines after which the push removed code; distance and on_changed_line count them, the model's hunks input renders them as removed_after_line, and diff.deletion_count is an engineered feature. 2. 150 rows (16%, every positive of one repository) read empty files from the worktree although git holds the blobs; the build ran while another process checked out from the same clone. _full_checkout now proves the checkout: git status must be clean, a dirty tree is restored once, then InstrumentFailure checkout_incomplete. The table script cross-checks every unread row against the blob size and refuses to screen a partly unread tree, and records the diff-scoped recall ceiling (positive rows a label-blind enumeration would reach). Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
60cbefec9b
commit
537b61e8d9
@@ -96,6 +96,19 @@ class Context:
|
||||
|
||||
@cached_property
|
||||
def hunks(self) -> dict[str, list[list[int]]]:
|
||||
"""Line ranges per file that the push changed or added, at head."""
|
||||
return self._patch[0]
|
||||
|
||||
@cached_property
|
||||
def deletions(self) -> dict[str, list[int]]:
|
||||
"""Per file, the head lines after which the push removed lines (0 when it removed the top of the file).
|
||||
|
||||
A fix that adds a guard is a push that removes it when replayed base-to-head, and that push has no added
|
||||
line at head: without this column the diff features are blind to exactly that shape."""
|
||||
return self._patch[1]
|
||||
|
||||
@cached_property
|
||||
def _patch(self) -> tuple[dict[str, list[list[int]]], dict[str, list[int]]]:
|
||||
self.verify_head()
|
||||
# Exclude private files before git opens the patch; only hunk coordinates become features.
|
||||
patch = _git(
|
||||
@@ -112,6 +125,7 @@ class Context:
|
||||
)
|
||||
self.diff_bytes = len(patch.encode("utf-8"))
|
||||
result: dict[str, list[list[int]]] = {}
|
||||
removed: dict[str, list[int]] = {}
|
||||
path = None
|
||||
for text in patch.splitlines():
|
||||
if text.startswith("+++ "):
|
||||
@@ -122,7 +136,9 @@ class Context:
|
||||
start, count = int(match[1]), int(match[2] or "1")
|
||||
if count:
|
||||
result.setdefault(path, []).append([start, start + count - 1])
|
||||
return result
|
||||
else:
|
||||
removed.setdefault(path, []).append(start)
|
||||
return result, removed
|
||||
|
||||
def ir(self, path: str) -> FileIR:
|
||||
if path not in self.irs:
|
||||
@@ -143,7 +159,7 @@ class Producer:
|
||||
compute: Compute
|
||||
|
||||
|
||||
def _producer(name: str, compute: Compute) -> Producer:
|
||||
def _producer(name: str, compute: Compute, version: str = "1") -> Producer:
|
||||
columns = tuple(f"feature.{name}.{column}" for column in FEATURE_NAMES[name])
|
||||
provenance = tuple(f"provenance.{name}.{column}" for column in ("ok", "reason", "version", "bytes_read"))
|
||||
|
||||
@@ -167,19 +183,22 @@ def _producer(name: str, compute: Compute) -> Producer:
|
||||
{
|
||||
f"provenance.{name}.ok": reason is None,
|
||||
f"provenance.{name}.reason": reason,
|
||||
f"provenance.{name}.version": "1",
|
||||
f"provenance.{name}.version": version,
|
||||
f"provenance.{name}.bytes_read": bytes_read,
|
||||
}
|
||||
)
|
||||
return result
|
||||
|
||||
return Producer(name, "1", columns + provenance, guarded)
|
||||
return Producer(name, version, columns + provenance, guarded)
|
||||
|
||||
|
||||
def _diff(root: Path, change: Change, path: str, line: int, ctx: Context) -> dict[str, object]:
|
||||
hunks = ctx.hunks.get(path, [])
|
||||
distance = min((max(start - line, 0, line - end) for start, end in hunks), default=None)
|
||||
return {"hunks": hunks, "on_changed_line": distance == 0, "distance": distance}
|
||||
deletions = ctx.deletions.get(path, [])
|
||||
# A removal sits between head lines `after` and `after + 1`; both lines count as touched.
|
||||
ranges = hunks + [[max(after, 1), max(after, 1) + 1] for after in deletions]
|
||||
distance = min((max(start - line, 0, line - end) for start, end in ranges), default=None)
|
||||
return {"hunks": hunks, "deletions": deletions, "on_changed_line": distance == 0, "distance": distance}
|
||||
|
||||
|
||||
def _source(root: Path, change: Change, path: str, line: int, ctx: Context) -> dict[str, object]:
|
||||
@@ -279,7 +298,12 @@ def _taxonomy(root: Path, change: Change, path: str, line: int, ctx: Context) ->
|
||||
return {"families": [{"id": f.id, "definition": " ".join(f.description.split())} for f in load_families().families]}
|
||||
|
||||
|
||||
PRODUCERS = (_producer("diff", _diff), _producer("source", _source), _producer("semantic", _semantic), _producer("taxonomy", _taxonomy))
|
||||
PRODUCERS = (
|
||||
_producer("diff", _diff, version="2"),
|
||||
_producer("source", _source),
|
||||
_producer("semantic", _semantic),
|
||||
_producer("taxonomy", _taxonomy),
|
||||
)
|
||||
|
||||
|
||||
def _candidates(root: Path, change: Change, ctx: Context) -> list[dict[str, Any]]:
|
||||
|
||||
Reference in New Issue
Block a user