Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
rtk/tests/read_window_bytes_test.rs at develop · rtk-ai/rtk · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
rtk-ai
rtk
Repository navigation
Code
Issues
892
(892)
Pull requests
691
(691)
Discussions
Actions
Projects
Security and quality
3
(3)
Insights
More
items
Files
Expand file tree
develop
Breadcrumbs
rtk
/
tests
/
read_window_bytes_test.rs
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
177 lines (168 loc) · 6 KB
develop
Breadcrumbs
rtk
/
tests
/
read_window_bytes_test.rs
Copy path
Top
File metadata and controls
Code
Blame
177 lines (168 loc) · 6 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
use
std
::
fs
;
use
std
::
io
::
Write
;
use
std
::
process
::
{
Output
,
Stdio
}
;
mod
common
;
fn
read_stdin
(
input
:
&
[
u8
]
,
args
:
&
[
&
str
]
)
->
Output
{
let
mut
child = common
::
rtk_command
(
)
.
args
(
[
"read"
,
"-"
]
)
.
args
(
args
)
.
stdin
(
Stdio
::
piped
(
)
)
.
stdout
(
Stdio
::
piped
(
)
)
.
stderr
(
Stdio
::
piped
(
)
)
.
spawn
(
)
.
expect
(
"run rtk read from stdin"
)
;
child
.
stdin
.
take
(
)
.
expect
(
"piped stdin"
)
.
write_all
(
input
)
.
expect
(
"write stdin"
)
;
child
.
wait_with_output
(
)
.
expect
(
"wait for rtk read"
)
}
#
[
test
]
fn
read_windows_preserve_non_utf8_files
(
)
{
let
dir = tempfile
::
tempdir
(
)
.
expect
(
"create test directory"
)
;
let
file = dir
.
path
(
)
.
join
(
"binary.log"
)
;
fs
::
write
(
&
file
,
b"
\xff
\xfe
bad
\n
line2
\n
line3
\n
"
)
.
expect
(
"write binary file"
)
;
for
(
flag
,
expected
)
in
[
(
"--head-lines"
,
b"
\xff
\xfe
bad
\n
line2
\n
"
.
as_slice
(
)
)
,
(
"--tail-lines"
,
b"line2
\n
line3
\n
"
.
as_slice
(
)
)
,
]
{
let
output = common
::
rtk_command
(
)
.
arg
(
"read"
)
.
arg
(
&
file
)
.
args
(
[
flag
,
"2"
]
)
.
output
(
)
.
expect
(
"run rtk read"
)
;
assert
!
(
output
.
status
.
success
(
)
,
"{flag}: {:?}"
,
output
.
stderr
)
;
assert_eq
!
(
output
.
stdout
,
expected
,
"{flag}"
)
;
}
}
#
[
test
]
fn
read_windows_preserve_binary_boundaries_for_files_and_stdin
(
)
{
let
dir = tempfile
::
tempdir
(
)
.
expect
(
"create test directory"
)
;
let
file = dir
.
path
(
)
.
join
(
"binary.log"
)
;
for
input
in
[
b"
\xff
\r
\n
valid
\n
\0
\xfe
"
.
as_slice
(
)
,
b"
\xff
\r
\n
valid
\n
\0
\xfe
\n
"
.
as_slice
(
)
,
]
{
fs
::
write
(
&
file
,
input
)
.
expect
(
"write binary file"
)
;
let
last =
if
input
.
ends_with
(
b"
\n
"
)
{
b"
\0
\xfe
\n
"
.
as_slice
(
)
}
else
{
b"
\0
\xfe
"
.
as_slice
(
)
}
;
for
(
flag
,
count
,
expected
)
in
[
(
"--head-lines"
,
"0"
,
b""
.
as_slice
(
)
)
,
(
"--tail-lines"
,
"0"
,
b""
.
as_slice
(
)
)
,
(
"--head-lines"
,
"1"
,
b"
\xff
\r
\n
"
.
as_slice
(
)
)
,
(
"--tail-lines"
,
"1"
,
last
)
,
(
"--head-lines"
,
"99"
,
input
)
,
(
"--tail-lines"
,
"99"
,
input
)
,
]
{
let
from_file = common
::
rtk_command
(
)
.
arg
(
"read"
)
.
arg
(
&
file
)
.
args
(
[
flag
,
count
]
)
.
output
(
)
.
expect
(
"run rtk read"
)
;
let
from_stdin =
read_stdin
(
input
,
&
[
flag
,
count
]
)
;
for
output
in
[
from_file
,
from_stdin
]
{
assert
!
(
output
.
status
.
success
(
)
,
"{flag} {count}: {:?}"
,
output
.
stderr
)
;
assert_eq
!
(
output
.
stdout
,
expected
,
"{flag} {count}"
)
;
}
}
}
}
#
[
test
]
fn
read_windows_accept_invalid_bytes_outside_the_selected_window
(
)
{
for
(
input
,
flag
)
in
[
(
b"valid
\n
\xff
\n
"
.
as_slice
(
)
,
"--head-lines"
)
,
(
b"
\xff
\n
valid
\n
"
.
as_slice
(
)
,
"--tail-lines"
)
,
]
{
let
output =
read_stdin
(
input
,
&
[
flag
,
"1"
]
)
;
assert
!
(
output
.
status
.
success
(
)
,
"{flag}: {:?}"
,
output
.
stderr
)
;
assert_eq
!
(
output
.
stdout
,
b"valid
\n
"
)
;
}
}
#
[
test
]
fn
read_windows_still_apply_text_filtering_and_line_numbers
(
)
{
let
input =
b"// comment
\n
fn alpha() {}
\n
fn beta() {}
\n
fn gamma() {}
\n
"
;
for
(
args
,
expected
)
in
[
(
[
"--head-lines"
,
"1"
,
"--level"
,
"minimal"
]
.
as_slice
(
)
,
"fn alpha() {}
\n
"
,
)
,
(
[
"--tail-lines"
,
"1"
,
"--level"
,
"minimal"
]
.
as_slice
(
)
,
"fn gamma() {}"
,
)
,
(
[
"--head-lines"
,
"1"
,
"--line-numbers"
]
.
as_slice
(
)
,
"1 │ // comment
\n
"
,
)
,
(
[
"--tail-lines"
,
"1"
,
"--line-numbers"
]
.
as_slice
(
)
,
"1 │ fn gamma() {}
\n
"
,
)
,
]
{
let
output =
read_stdin
(
input
,
args
)
;
assert
!
(
output
.
status
.
success
(
)
,
"{args:?}: {:?}"
,
output
.
stderr
)
;
assert_eq
!
(
output
.
stdout
,
expected
.
as_bytes
(
)
,
"{args:?}"
)
;
}
}
#
[
cfg
(
unix
)
]
#
[
test
]
fn
rewritten_head_spellings_match_native_on_non_utf8_files
(
)
{
let
dir = tempfile
::
tempdir
(
)
.
expect
(
"create test directory"
)
;
let
claude_dir = dir
.
path
(
)
.
join
(
".claude"
)
;
fs
::
create_dir
(
&
claude_dir
)
.
expect
(
"create isolated Claude config directory"
)
;
let
config_dir = dir
.
path
(
)
.
join
(
"config"
)
;
fs
::
create_dir
(
&
config_dir
)
.
expect
(
"create isolated rtk config directory"
)
;
let
file = dir
.
path
(
)
.
join
(
"binary.log"
)
;
fs
::
write
(
&
file
,
b"
\xff
\xfe
bad
\n
line2
\n
line3
\n
"
)
.
expect
(
"write binary file"
)
;
for
flags
in
[
"-2"
,
"-n 2"
,
"--lines 2"
,
"--lines=2"
,
""
]
{
let
command =
format
!
(
"head {flags} {}"
,
file
.
display
(
)
)
;
let
rewrite = common
::
rtk_command
(
)
.
current_dir
(
dir
.
path
(
)
)
.
env
(
"CLAUDE_CONFIG_DIR"
,
&
claude_dir
)
.
env
(
"XDG_CONFIG_HOME"
,
&
config_dir
)
.
args
(
[
"rewrite"
,
&
command
]
)
.
output
(
)
.
expect
(
"rewrite head command"
)
;
assert_eq
!
(
rewrite
.
status
.
code
(
)
,
Some
(
3
)
,
"{command}: {:?}"
,
rewrite
.
stderr
)
;
let
rewritten =
String
::
from_utf8
(
rewrite
.
stdout
)
.
expect
(
"UTF-8 command"
)
;
let
count =
if
flags
.
is_empty
(
)
{
"10"
}
else
{
"2"
}
;
assert_eq
!
(
rewritten
.
trim
(
)
,
format!
(
"rtk read {} --head-lines {count}"
,
file
.
display
(
)
)
)
;
let
actual = common
::
rtk_command
(
)
.
args
(
rewritten
.
trim
(
)
.
strip_prefix
(
"rtk "
)
.
expect
(
"rtk rewrite prefix"
)
.
split_whitespace
(
)
,
)
.
output
(
)
.
expect
(
"execute rewritten head"
)
;
let
native = common
::
native_command
(
"head"
)
.
args
(
flags
.
split_whitespace
(
)
)
.
arg
(
&
file
)
.
output
(
)
.
expect
(
"run native head"
)
;
assert
!
(
native
.
status
.
success
(
)
,
"{command}: {:?}"
,
native
.
stderr
)
;
assert_eq
!
(
actual
.
status
.
code
(
)
,
native
.
status
.
code
(
)
,
"{command}"
)
;
assert_eq
!
(
actual
.
stdout
,
native
.
stdout
,
"{command}"
)
;
}
}
You can’t perform that action at this time.