ptytestroot

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ptytestroot 为 Unix socket PTY 测试选择短且不污染 Go 包枚举的根目录。

职责:按覆盖根、/tmp、仓库根点号目录的顺序创建测试根,并在建 socket 前检查字节长度。 边界:只服务测试辅助,不参与 agentd/ptyhost 生产运行时,不创建 socket、不启动进程, 也不把非 PTY 测试的 Unix socket 纳入本决策。

Index

Constants

View Source
const SocketIDForBudget = "00000000-0000-0000-0000-000000000000"

SocketIDForBudget 是 UUID 长度的占位 ID;真实 ptyhost 客户端 ID 由 uuid.NewString 生成,hostproc 白盒测试使用的 s1 更短。用最大长度预算避免测试根选得过长。

View Source
const SocketPathLimit = sessdir.MaxSockPath

SocketPathLimit 就是 sessdir 的 bind 上限本身,不是它的副本。

这里保留一个本包的名字只为让调用点读起来是「测试根的预算」而不是「会话目录的 上限」;值必须是同一个。以前这里抄的是字面量 100,sessdir 改了上限不会让本包 编译失败、也不会让任何测试变红(B210)。

Variables

This section is empty.

Functions

This section is empty.

Types

type Candidate

type Candidate struct {
	Root   string
	Source Source
}

Candidate 是已经可创建、待做 socket 长度判断的候选根。

type Decision

type Decision struct {
	Root        string
	SocketPath  string
	SocketBytes int
	SocketLimit int
	Source      Source
	Cleanup     func()
}

Decision 是一次成功的测试根决策。

Root 是调用方传给 ptyhost 的会话根;SocketPath/SocketBytes 是用 socketID 预算出的 实测值;Cleanup 只清理 Resolve 本次生成的临时目录,调用方必须注册它。

func Choose

func Choose(candidates []Candidate, socketID string, socketLimit int) (Decision, error)

Choose 按 candidates 顺序选择第一个 socket 路径不超过 socketLimit 的根。

参数:socketID 是会话 ID 或等长预算占位;socketLimit 是字节上限。 返回:成功时返回根、完整 socket 路径和字节数;全部候选失败时返回含每个实测值的错误。 注意:Choose 是纯函数,不做文件系统访问,也不负责 Cleanup。

func Resolve

func Resolve(socketID string, socketLimit int, logger *slog.Logger) (Decision, error)

Resolve 在真实测试进程中执行根目录择位。

参数:socketID/socketLimit 定义长度预算;logger 接收入口、候选 IO、错误和成功节点, 传 nil 时使用 slog.Default。 返回:成功时返回可直接交给 PTY Host 的根和清理函数;失败时返回可供 t.Skipf 展示的 环境错误,错误文本列出每个候选的实测 socket 字节数与上限。 注意:覆盖根是调用方指定的目录,Resolve 不会在 Cleanup 中删除它。

type Source

type Source string

Source 是测试根的选择来源。

const (
	// SourceOverride 表示使用 HANDOFF_PTY_TEST_ROOT。
	SourceOverride Source = "override"
	// SourceTmp 表示使用 /tmp 下的短临时目录。
	SourceTmp Source = "tmp"
	// SourceRepoDot 表示使用仓库根下 .pty-test-root 的短临时目录。
	SourceRepoDot Source = "repo-dot"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL