FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
evidentloop/tests/test_gitdiff_adapter.py at main · evidentloop/evidentloop · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
evidentloop
/
evidentloop
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
5
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
evidentloop
/
tests
/
test_gitdiff_adapter.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
81 lines (63 loc) · 3.15 KB
Breadcrumbs
evidentloop
/
tests
/
test_gitdiff_adapter.py
Copy path
File metadata and controls
81 lines (63 loc) · 3.15 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
"""Git diff collection and trusted hunk index tests."""
from
__future__
import
annotations
from
pathlib
import
Path
import
pytest
from
evidentloop
.
adapters
.
gitdiff
import
GitDiffCollectionError
,
collect_git_diff
from
evidentloop
.
renderers
.
hunk
import
parse_hunk
from
tests
.
git_helpers
import
git
,
initialized_repo
,
stage_simple_change
def
test_collects_added_modified_deleted_renamed_and_binary
(
tmp_path
:
Path
)
->
None
:
repo
=
initialized_repo
(
tmp_path
)
(
repo
/
"app.py"
).
write_text
(
"value = 2
\n
"
,
encoding
=
"utf-8"
)
(
repo
/
"added.py"
).
write_text
(
"added = True
\n
"
,
encoding
=
"utf-8"
)
(
repo
/
"delete.txt"
).
unlink
()
(
repo
/
"rename.txt"
).
rename
(
repo
/
"renamed.txt"
)
(
repo
/
"binary.bin"
).
write_bytes
(
bytes
(
range
(
64
,
128
)))
git
(
repo
,
"add"
,
"-A"
)
bundle
=
collect_git_diff
(
repo
,
"staged"
)
by_path
=
{
item
.
path
:
item
for
item
in
bundle
.
files
}
assert
by_path
[
"added.py"
].
change_type
==
"added"
assert
by_path
[
"app.py"
].
change_type
==
"modified"
assert
by_path
[
"delete.txt"
].
change_type
==
"deleted"
assert
by_path
[
"renamed.txt"
].
change_type
==
"renamed"
assert
by_path
[
"binary.bin"
].
change_type
==
"binary"
assert
by_path
[
"binary.bin"
].
binary
is
True
assert
"GIT binary patch"
not
in
bundle
.
diff
assert
"Binary files "
in
bundle
.
diff
assert
by_path
[
"added.py"
].
additions
==
1
assert
by_path
[
"delete.txt"
].
deletions
==
1
assert
bundle
.
hunks
assert
all
(
parse_hunk
(
item
.
snippet
).
header
==
item
.
header
for
item
in
bundle
.
hunks
)
assert
len
({
item
.
hunk_id
for
item
in
bundle
.
hunks
})
==
len
(
bundle
.
hunks
)
def
test_large_binary_keeps_metadata_without_embedding_payload
(
tmp_path
:
Path
)
->
None
:
repo
=
initialized_repo
(
tmp_path
)
(
repo
/
"binary.bin"
).
write_bytes
(
b"
\0
"
+
b"binary-data"
*
100_000
)
git
(
repo
,
"add"
,
"binary.bin"
)
bundle
=
collect_git_diff
(
repo
,
"staged"
)
binary
=
next
(
item
for
item
in
bundle
.
files
if
item
.
path
==
"binary.bin"
)
assert
binary
.
binary
is
True
assert
binary
.
change_type
==
"binary"
assert
"GIT binary patch"
not
in
bundle
.
diff
assert
"Binary files "
in
bundle
.
diff
assert
len
(
bundle
.
diff
)
<
10_000
def
test_rejects_empty_diff_and_invalid_ref
(
tmp_path
:
Path
)
->
None
:
repo
=
initialized_repo
(
tmp_path
)
with
pytest
.
raises
(
GitDiffCollectionError
,
match
=
"empty"
):
collect_git_diff
(
repo
,
"staged"
)
with
pytest
.
raises
(
GitDiffCollectionError
,
match
=
"failed"
):
collect_git_diff
(
repo
,
"missing-ref"
)
def
test_large_diff_is_indexed_without_truncation
(
tmp_path
:
Path
)
->
None
:
repo
=
initialized_repo
(
tmp_path
)
(
repo
/
"large.txt"
).
write_text
(
""
.
join
(
f"line
{
index
}
\n
"
for
index
in
range
(
5000
)),
encoding
=
"utf-8"
,
)
git
(
repo
,
"add"
,
"large.txt"
)
bundle
=
collect_git_diff
(
repo
,
"staged"
)
large
=
next
(
item
for
item
in
bundle
.
files
if
item
.
path
==
"large.txt"
)
assert
large
.
additions
==
5000
assert
len
(
bundle
.
diff
)
>
50_000
def
test_staged_prompt_injection_text_remains_plain_diff_data
(
tmp_path
:
Path
)
->
None
:
repo
=
initialized_repo
(
tmp_path
)
stage_simple_change
(
repo
,
injection
=
True
)
bundle
=
collect_git_diff
(
repo
,
"staged"
)
assert
"Ignore previous instructions"
in
bundle
.
diff
Back
|
FazBrowse Home
|
New Git URL