expect-pty 0.9.2 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/docs/API.md +4 -0
- data/docs/COMPATIBILITY.md +2 -1
- data/lib/expect/pty.rb +6 -6
- data/lib/expect/result.rb +16 -0
- data/lib/expect/version.rb +1 -1
- data/sig/expect.rbs +4 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0742e1462f3858067396edb88d2e401ba621869882091cddee3237cedd86eaf5
|
|
4
|
+
data.tar.gz: d054194b5f0f54740d86ccdca2d684d7ee8faeae77dbbf50595cc0b3516d4308
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5a3be17c347139230dfe4395292ef7eeb58d0f432445c6d234542e3d83ac0f87e0e08d3131dc6842f4f1639a7a979868b84dd51ea9c9b206809901e232faac0d
|
|
7
|
+
data.tar.gz: e3f6508feaaa07172147b4c26bbc850e22bc918f377213ae4b1403947446cd15141f6d43860d26c28dac62a95628b72df1e09ae9ea2819781eef5cdb7fa93d54
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.9.3 - 2026-10-18
|
|
6
|
+
|
|
7
|
+
- 结果的 inspect 与 to_s 仅输出匹配序号和错误状态,避免诊断、字符串插值泄露匹配文本、捕获内容或异常消息;原始结果字段保持不变。
|
|
8
|
+
- 工厂块异常、取消或非局部退出时跳过 graceful 读尾,直接硬关闭;正常返回(包括 nil/false)仍可收取尾部输出。
|
|
9
|
+
|
|
5
10
|
## 0.9.2 - 2026-10-18
|
|
6
11
|
|
|
7
12
|
- 减少显式搜索窗口下字面量匹配的内存分配,保留原始字节偏移、声明优先级和正则窗口语义。
|
data/docs/API.md
CHANGED
|
@@ -19,6 +19,8 @@ Session 构造器不接收命令或操作参数。同一会话只能启动一次
|
|
|
19
19
|
`Expect.open(io, writer: io, own: false, graceful: false, **settings)` 适配真实可 select 的 IO,默认借用。
|
|
20
20
|
`own: true` 接管关闭责任,包括初始化中已知设置的非法值导致的失败;未知关键字在 Ruby 方法入口拒绝,此时不接管 IO。
|
|
21
21
|
`spawn`、`open` 无块时返回 Session,有块时返回块结果并确保按 `graceful:` 关闭;非局部返回也清理。
|
|
22
|
+
工厂块正常返回时才执行 graceful 读尾;异常、线程取消以及 return/break/throw 等非局部退出直接硬关闭,避免读尾延迟退出。
|
|
23
|
+
块正常返回 nil 或 false 仍属于正常完成;调用方 rescue 中已处理的异常不影响此判断。
|
|
22
24
|
清理中的 StandardError 不覆盖本次作用域已有的主异常;没有主异常时照常传播。新发生的 Interrupt/SystemExit 不会被清理包装吞掉。
|
|
23
25
|
|
|
24
26
|
`close(graceful: false)` 最终硬关闭兜底,返回 nil;`soft_close(timeout: 15, term_timeout: 1)` 收取尾部、关闭句柄并最多发送
|
|
@@ -65,6 +67,8 @@ nil 保留全缓冲扫描;指定时,字符串和正则只搜索最新的尾
|
|
|
65
67
|
固定 UTF-8 正则跳过边界切开的合法首字符,等待合法未完成尾字符;窗口内非法字节及 EOF 未完成字符仍报错。
|
|
66
68
|
二进制正则按原始字节匹配。
|
|
67
69
|
|
|
70
|
+
Result 的 `inspect` 与 `to_s` 仅显示匹配序号和错误状态,不打印原始文本、异常消息或来源对象。
|
|
71
|
+
需要原始结果时显式读取字段;`redact` 不改变这些字段。
|
|
68
72
|
Result 字段为 `number`、`error`、`match`、`before`、`after`、`session`、`captures`。对象、文本及捕获数组均不可变,未参与捕获为
|
|
69
73
|
nil。
|
|
70
74
|
错误为 nil、`:timeout`、`:eof` 或原始 IO 异常;来源会话与异常不复制、不冻结。使用 `matched?`、`timeout?`、`eof?` 查询,
|
data/docs/COMPATIBILITY.md
CHANGED
|
@@ -46,7 +46,8 @@ PID。`hard_close` 不等待输出,必要时 TERM、KILL 并回收子进程。
|
|
|
46
46
|
|
|
47
47
|
Ruby 使用关键字指定各阶段期限,关闭方法返回 `Process::Status` 或 `nil`。`close(graceful: true)` 或工厂块的
|
|
48
48
|
`graceful: true`
|
|
49
|
-
先尝试软关闭,再在 `ensure`
|
|
49
|
+
先尝试软关闭,再在 `ensure` 中硬关闭;工厂块仅正常返回时读尾,异常、取消及非局部退出直接硬关闭。
|
|
50
|
+
显式 `close(graceful: true)` 仍按调用参数读尾。`close` 返回 `nil`;GC
|
|
50
51
|
兜底直接强制清理,不阻塞等待。
|
|
51
52
|
|
|
52
53
|
## 有意采用的 Ruby 语义
|
data/lib/expect/pty.rb
CHANGED
|
@@ -66,12 +66,12 @@ module Expect
|
|
|
66
66
|
timeout: nil, write_timeout: nil, buffer_limit: nil, logger: nil, transcript: nil, outputs: [])
|
|
67
67
|
session = nil
|
|
68
68
|
spawned = false
|
|
69
|
-
cleanup = lambda do
|
|
69
|
+
cleanup = lambda do |completed|
|
|
70
70
|
if session && (block_given? || !spawned)
|
|
71
|
-
session.cleanup_session(nil, writer: nil, own: false, graceful: spawned && graceful)
|
|
71
|
+
session.cleanup_session(nil, writer: nil, own: false, graceful: spawned && graceful && completed)
|
|
72
72
|
end
|
|
73
73
|
end
|
|
74
|
-
Cleanup.always(cleanup) do
|
|
74
|
+
Cleanup.always(cleanup, report_completion: true) do
|
|
75
75
|
# 工厂在构造期间处理失败;成功对象的返回与登记不可被中断拆开。
|
|
76
76
|
Thread.handle_interrupt(Object => :never) do
|
|
77
77
|
session = SessionFactory.pty(timeout:, write_timeout:, buffer_limit:, logger:, transcript:, outputs:)
|
|
@@ -89,14 +89,14 @@ module Expect
|
|
|
89
89
|
session = nil
|
|
90
90
|
initialized = false
|
|
91
91
|
constructing = false
|
|
92
|
-
cleanup = lambda do
|
|
92
|
+
cleanup = lambda do |completed|
|
|
93
93
|
if session && (block_given? || !initialized)
|
|
94
|
-
session.cleanup_session(io, writer:, own:, graceful: initialized && graceful)
|
|
94
|
+
session.cleanup_session(io, writer:, own:, graceful: initialized && graceful && completed)
|
|
95
95
|
elsif !session && own && !constructing
|
|
96
96
|
ResourceOwner.close_handles(io, writer)
|
|
97
97
|
end
|
|
98
98
|
end
|
|
99
|
-
Cleanup.always(cleanup) do
|
|
99
|
+
Cleanup.always(cleanup, report_completion: true) do
|
|
100
100
|
Thread.handle_interrupt(Object => :never) do
|
|
101
101
|
constructing = true
|
|
102
102
|
session = SessionFactory.io(io, writer:, own:, timeout:, write_timeout:, buffer_limit:,
|
data/lib/expect/result.rb
CHANGED
|
@@ -30,6 +30,22 @@ module Expect
|
|
|
30
30
|
captures: captures.map { |value| value&.dup&.freeze }.freeze)
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
+
# 诊断只显示匹配序号和错误状态,不检查原始文本、异常或来源对象。
|
|
34
|
+
# @return [String] 不包含协议内容的结果摘要。
|
|
35
|
+
def inspect
|
|
36
|
+
state = if error.nil? then "none"
|
|
37
|
+
elsif error.equal?(:eof) then "eof"
|
|
38
|
+
elsif error.equal?(:timeout) then "timeout"
|
|
39
|
+
else "exception"
|
|
40
|
+
end
|
|
41
|
+
index = number.is_a?(Integer) ? number.to_s : "nil"
|
|
42
|
+
"#<#{self.class} number=#{index} error=#{state}>"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Data 的默认 to_s 独立于 inspect;字符串插值同样只使用安全摘要。
|
|
46
|
+
# @return [String] 与 inspect 相同的结果摘要。
|
|
47
|
+
def to_s = inspect
|
|
48
|
+
|
|
33
49
|
# 是否命中文本;EOF 和超时没有模式序号。
|
|
34
50
|
def matched? = !number.nil?
|
|
35
51
|
|
data/lib/expect/version.rb
CHANGED
data/sig/expect.rbs
CHANGED