harness: documentation reads through grep count (grep prefixes stripped before matching)
This commit is contained in:
1 parent
0972ed2a5e
commit
a2d72628e0
3 files changed
+22
-2
No files matched your search
@@ -38,6 +38,9 @@ import re
|
||||
from . import util
|
||||
|
||||
_PREFIX = re.compile(r"^\s*\d+\s*[:\t→│|]\s?")
|
||||
# grep/ripgrep output and the agents' grep tools: `path:12:text`, context
|
||||
# lines `path-12-text`, and `path:text` when several files are searched.
|
||||
_GREP = re.compile(r"^(?:/docs/\S+?|\S+\.md)(?::\d+[:-]|-\d+-|:)")
|
||||
|
||||
|
||||
def _tokenizer():
|
||||
@@ -51,7 +54,7 @@ def _tokenizer():
|
||||
|
||||
|
||||
def _norm(line):
|
||||
return _PREFIX.sub("", line).strip()
|
||||
return _PREFIX.sub("", _GREP.sub("", line, count=1)).strip()
|
||||
|
||||
|
||||
def tool_events_track_a(events_path):
|
||||
|
||||
@@ -315,6 +315,23 @@ class StatusTest(unittest.TestCase):
|
||||
self.assertEqual(native.evaluation_status({"accepted": False, "infrastructure": True}), "infrastructure_failure")
|
||||
|
||||
|
||||
class GrepReadTest(unittest.TestCase):
|
||||
def test_grep_output_counts_as_read(self):
|
||||
from ajieval import context
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
os.makedirs(os.path.join(d, "language"))
|
||||
with open(os.path.join(d, "language", "syntax.md"), "w") as f:
|
||||
f.write("alpha rule one\nbeta rule two\n")
|
||||
events = [('{"command": "grep -rn rule /docs/language"}', "/docs/language/syntax.md:1:alpha rule one\n/docs/language/syntax.md-2-beta rule two"),
|
||||
('{"pattern": "x", "path": "/docs"}', "language/syntax.md:alpha rule one")]
|
||||
seen = {context._norm(l) for _, o in events for l in o.splitlines() if context._norm(l)}
|
||||
m = context.doc_metrics(events, [("", d)], {}, seen, len)
|
||||
self.assertEqual(m["coverage_by_section"]["language/syntax.md"], 1.0)
|
||||
# Ordinary text with a colon is left alone.
|
||||
self.assertEqual(context._norm("Note: keep this"), "Note: keep this")
|
||||
self.assertEqual(context._norm(" 12→text"), "text")
|
||||
|
||||
|
||||
class CyclesTest(unittest.TestCase):
|
||||
def test_repair_cycles_from_commands(self):
|
||||
from ajieval import native
|
||||
|
||||
Reference in new issue
Block a user