context-pack tests: glob paths, straddles, --since boundaries, spec shapes, budgets, binding env
Real git repos in scratch: a src/[a] path beside src/a, pure deletions and one-line replacements straddling either end of an anchor, edits on an anchor's first and last line under --since, a --since commit with an unreadable tree, thirteen wrong-typed spec variants with canaries, a --max-lines below the table, --only truncation at the 7 and 6 line thresholds and with a reserved not-expanded line, and the binding env block with the caller's environment overriding it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
459475f581
commit
dbcb41a046
1 changed files with 102 additions and 0 deletions
|
|
@ -383,6 +383,108 @@ grep -qF "context-pack: spec: not a cut_spec value; --spec-json reads a saved vi
|
|||
grep -qF "usage: " "$T/cp.err" || echo "ok context-pack spec error prints no usage text"
|
||||
r=$(cpo --max-lines 0); cchk "usage: no spec source" 2 "$r"
|
||||
grep -qF "context-pack: usage error" "$T/cp.err" && echo "ok context-pack usage error text" || { echo "FAIL context-pack usage text"; fail=1; }
|
||||
# glob characters in a spec path name that file only; straddling hunks; --since boundaries
|
||||
R2=$T/cp2; mkdir -p "$R2/src/[a]" "$R2/src/a"; R2w=$(wp "$R2")
|
||||
g2() { git -C "$R2" -c user.name=t -c user.email=t@t -c core.autocrlf=false "$@" >/dev/null 2>&1; }
|
||||
g2 init -q
|
||||
seqf x 30 >"$R2/src/[a]/f.txt"; seqf x 30 >"$R2/src/a/f.txt"
|
||||
for n in s t u v; do seqf x 30 >"$R2/$n.txt"; done; seqf w 12 >"$R2/w.txt"
|
||||
g2 add -A; g2 commit -q -m base; B2=$(git -C "$R2" rev-parse HEAD)
|
||||
{ printf 'new1\nnew2\n'; cat "$R2/src/a/f.txt"; } >"$R2/src/a/f.new"; mv "$R2/src/a/f.new" "$R2/src/a/f.txt"
|
||||
sed -i 8,12d "$R2/s.txt"; sed -i 15,25d "$R2/t.txt"
|
||||
sed -i '8,12c\NEW' "$R2/u.txt"; sed -i '15,25c\NEW' "$R2/v.txt"
|
||||
g2 add -A; g2 commit -q -m second; S2=$(git -C "$R2" rev-parse HEAD)
|
||||
sed -i 's/^w5$/w5-EDITED/' "$R2/w.txt"
|
||||
echo '{"base": "'$B2'", "deletes": [], "file_changes": [
|
||||
{"change": "glob path", "location": {"path": "src/[a]/f.txt", "line": 10, "end_line": 12}},
|
||||
{"change": "pure deletion above the start", "location": {"path": "s.txt", "line": 10, "end_line": 20}},
|
||||
{"change": "pure deletion past the end", "location": {"path": "t.txt", "line": 10, "end_line": 20}},
|
||||
{"change": "one-line replacement above the start", "location": {"path": "u.txt", "line": 10, "end_line": 20}},
|
||||
{"change": "one-line replacement past the end", "location": {"path": "v.txt", "line": 10, "end_line": 20}},
|
||||
{"change": "edit on the last line", "location": {"path": "w.txt", "line": 3, "end_line": 5}},
|
||||
{"change": "edit on the first line", "location": {"path": "w.txt", "line": 5, "end_line": 7}},
|
||||
{"change": "after the edit", "location": {"path": "w.txt", "line": 6, "end_line": 8}},
|
||||
{"change": "before the edit", "location": {"path": "w.txt", "line": 1, "end_line": 4}}]}' >"$T/cp-spec2.json"
|
||||
SP2=$(wp "$T/cp-spec2.json")
|
||||
cp2() { $PY "$CP" t:cut_spec:cut-x.r1 "$R2w" "$@" >"$T/cp.out" 2>"$T/cp.err"; echo $?; }
|
||||
r=$(cp2 --spec-json "$SP2"); cchk "straddle fixture" 0 "$r"
|
||||
cin "a glob path reads its own file: SAME" "[1] src/[a]/f.txt:10-12 SAME -> src/[a]/f.txt:10-12"
|
||||
cin "pure deletion starting above the anchor starts at the first survivor" "[2] s.txt:10-20 TOUCHED(+0/-5 inside) -> s.txt:8-15"
|
||||
cin "pure deletion ending past the anchor ends at the last survivor" "[3] t.txt:10-20 TOUCHED(+0/-11 inside) -> t.txt:10-14"
|
||||
cin "one-line replacement above the start begins at the replacement" "[4] u.txt:10-20 TOUCHED(+1/-5 inside) -> u.txt:8-16"
|
||||
cin "one-line replacement past the end ends at the replacement" "[5] v.txt:10-20 TOUCHED(+1/-11 inside) -> v.txt:10-15"
|
||||
cin "straddle window starts at the mapped range" "== [2] s.txt:8-15"
|
||||
r=$(cp2 --spec-json "$SP2" --since "$S2" --only 6,7,8,9)
|
||||
cin "--since: an edit on the anchor's last line is inside" "== [6] w.txt:3-5"
|
||||
cin "--since: an edit on the anchor's first line is inside" "== [7] w.txt:5-7"
|
||||
cnot "--since: an anchor after the edit has no window" "== [8] "
|
||||
cnot "--since: an anchor before the edit has no window" "== [9] "
|
||||
cin "--since keeps every anchor in the table" "[9] w.txt:1-4 SAME"
|
||||
# a --since commit whose tree is unreadable: git diff fails, so no anchor is claimed edited
|
||||
BL=$(echo only | git -C "$R2" hash-object -w --stdin); TR=$(printf '100644 blob %s\tonly.txt\n' "$BL" | git -C "$R2" mktree)
|
||||
CM=$(git -C "$R2" -c user.name=t -c user.email=t@t commit-tree "$TR" -m orphan)
|
||||
chmod u+w "$R2/.git/objects/${TR:0:2}/${TR:2}" 2>/dev/null; rm -f "$R2/.git/objects/${TR:0:2}/${TR:2}"
|
||||
r=$(cp2 --spec-json "$SP2" --since "$CM"); cchk "--since with an unreadable tree" 0 "$r"
|
||||
cnot "--since: a failed git diff claims no edited window" "== ["
|
||||
cin "--since: a failed git diff keeps the table" "[6] w.txt:3-5"
|
||||
# a spec value of the wrong type is a typed refusal naming the field, never a traceback or the value
|
||||
$PY - "$T" "$SP" <<'PYE'
|
||||
import copy, json, sys
|
||||
t, sp = sys.argv[1], sys.argv[2]
|
||||
spec = json.load(open(sp, encoding="utf-8"))
|
||||
cases = {
|
||||
"line": (lambda v: v["file_changes"][1]["location"].update(line="CANARY-line"), "file_changes[2].location.line"),
|
||||
"line-bool": (lambda v: v["file_changes"][0]["location"].update(line=True), "file_changes[1].location.line"),
|
||||
"end_line": (lambda v: v["file_changes"][2]["location"].update(end_line="CANARY-end"), "file_changes[3].location.end_line"),
|
||||
"path": (lambda v: v["file_changes"][0]["location"].update(path=["CANARY-path"]), "file_changes[1].location.path"),
|
||||
"nolocation": (lambda v: v["file_changes"][3].pop("location"), "file_changes[4].location"),
|
||||
"location-str": (lambda v: v["file_changes"][0].update(location="CANARY-loc"), "file_changes[1].location"),
|
||||
"entry-str": (lambda v: v["file_changes"].__setitem__(0, "CANARY-str"), "file_changes[1]"),
|
||||
"change": (lambda v: v["file_changes"][0].update(change={"CANARY": 1}), "file_changes[1].change"),
|
||||
"fcs-str": (lambda v: v.update(file_changes="CANARY-fcs"), "file_changes"),
|
||||
"base": (lambda v: v.update(base=12345), "base"),
|
||||
"deletes-str": (lambda v: v.update(deletes="CANARY-del"), "deletes"),
|
||||
"deletes-nopath": (lambda v: v.update(deletes=[{"note": "CANARY-note"}]), "deletes[1].path"),
|
||||
"deletes-entry-str": (lambda v: v.update(deletes=["CANARY-d"]), "deletes[1].path"),
|
||||
}
|
||||
names = []
|
||||
for name, (edit, field) in cases.items():
|
||||
d = copy.deepcopy(spec)
|
||||
edit(d["document"]["value"])
|
||||
json.dump(d, open("%s/cp-bad-%s.json" % (t, name), "w"))
|
||||
names.append("%s %s" % (name, field))
|
||||
open(t + "/cp-bad.list", "w", newline=chr(10)).write("\n".join(names) + "\n")
|
||||
PYE
|
||||
while read -r nm fld; do
|
||||
r=$(cpo --spec-json "$(wp "$T/cp-bad-$nm.json")"); cchk "wrong-typed spec: $nm" 4 "$r"
|
||||
grep -qF "context-pack: spec: $fld: InvalidInput; --spec-json reads a saved view" "$T/cp.err" && echo "ok context-pack names $fld" || { echo "FAIL context-pack message for $nm: $(cat "$T/cp.err")"; fail=1; }
|
||||
cnot "wrong-typed spec $nm: no value" "CANARY"; cnot "wrong-typed spec $nm: no traceback" "Traceback"
|
||||
done <"$T/cp-bad.list"
|
||||
# a --max-lines below the table: the table always lists every anchor and no window prints
|
||||
r=$(cpo --spec-json "$(wp "$T/cp-spec30.json")" --max-lines 5); cchk "--max-lines below the table" 0 "$r"
|
||||
[ "$(grep -c '^\[' "$T/cp.out")" = 30 ] && echo "ok context-pack a small budget keeps the full table" || { echo "FAIL context-pack small budget table"; fail=1; }
|
||||
cnot "a small budget prints no window" "== ["
|
||||
cin "a small budget lists every window as not expanded" "not expanded: --only 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"
|
||||
# --only truncates a window to the budget and says how to see the rest
|
||||
r=$(cpo --spec-json "$S1" --only 1 --max-lines 50); cchk "--only truncation" 0 "$r"
|
||||
[ "$(wc -l <"$T/cp.out" | tr -d ' ')" = 50 ] && echo "ok context-pack --only fills the budget exactly" || { echo "FAIL context-pack --only budget: $(wc -l <"$T/cp.out")"; fail=1; }
|
||||
[ "$(grep -c '^ *[0-9]* g' "$T/cp.out")" = 45 ] && echo "ok context-pack --only truncated window has 45 lines" || { echo "FAIL context-pack --only window lines"; fail=1; }
|
||||
cin "--only truncation note counts the rest" "111 more lines: --only 1 --max-lines 160"
|
||||
r=$(cpo --spec-json "$S1" --only 1 --max-lines 7); cchk "--only at the smallest truncatable budget" 0 "$r"
|
||||
[ "$(wc -l <"$T/cp.out" | tr -d ' ')" = 7 ] && [ "$(grep -c '^ *[0-9]* g' "$T/cp.out")" = 2 ] && echo "ok context-pack --only budget 7 prints 2 window lines" || { echo "FAIL context-pack --only budget 7"; fail=1; }
|
||||
r=$(cpo --spec-json "$S1" --only 1 --max-lines 6); cin "--only below the smallest truncation is not expanded" "not expanded: --only 1"
|
||||
cnot "--only below the smallest truncation prints no window" "== ["
|
||||
echo '{"base": "'$BASE'", "deletes": [], "file_changes": [
|
||||
{"change": "long", "location": {"path": "big.txt", "line": 20, "end_line": 169}},
|
||||
{"change": "short", "location": {"path": "big.txt", "line": 200, "end_line": 210}}]}' >"$T/cp-spec2w.json"
|
||||
r=$(cpo --spec-json "$(wp "$T/cp-spec2w.json")" --only 1,2 --max-lines 50); cchk "--only two windows" 0 "$r"
|
||||
[ "$(wc -l <"$T/cp.out" | tr -d ' ')" = 50 ] && echo "ok context-pack --only keeps room for the not-expanded line" || { echo "FAIL context-pack --only reserve: $(wc -l <"$T/cp.out")"; fail=1; }
|
||||
cin "--only: the window that no longer fits is listed" "not expanded: --only 2"
|
||||
# the binding env block reaches the server; the caller environment overrides it
|
||||
mcp env -u HUGINN_ENDPOINT -u EUREKA_INSTANCE FAKE_MODE=needenv FAKE_NEED=rudp://binding $PY "$CP" t:cut_spec:cut-x.r1 "$Rw" >"$T/cp.out" 2>"$T/cp.err"; r=$?
|
||||
cchk "env from the binding reaches the server" 3 "$r"; cmp -s "$T/cp.out" "$T/cp.want" && echo "ok context-pack binding env supplies the server environment" || { echo "FAIL context-pack binding env not applied"; fail=1; }
|
||||
mcp env -u EUREKA_INSTANCE HUGINN_ENDPOINT=rudp://caller FAKE_MODE=needenv FAKE_NEED=rudp://caller $PY "$CP" t:cut_spec:cut-x.r1 "$Rw" >"$T/cp.out" 2>"$T/cp.err"; r=$?
|
||||
cchk "the caller environment overrides the binding" 3 "$r"; cmp -s "$T/cp.out" "$T/cp.want" && echo "ok context-pack caller env wins over binding env" || { echo "FAIL context-pack caller env lost"; fail=1; }
|
||||
# standard library plus git only
|
||||
if grep -qE '^import (requests|yaml|tree_sitter)|^from (requests|yaml|tree_sitter)|ctags|tree-sitter|"rg"' "$CP"; then echo "FAIL context-pack: a dependency beyond git"; fail=1; else echo "ok context-pack: standard library and git only"; fi
|
||||
exit $fail
|
||||
|
|
|
|||
Loading…
Reference in a new issue