simports

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 32 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 simports 为 core/internal/sim 提供无环纯内存非明文端口仿真叶包(LayerCoreSim):

  • 存储、日志与导入仿真:InventoryStore、JournalStore、FormatImporter、FileFormatImporter;
  • 签名与主机信任仿真:KeySigner、HostTrust;
  • 扩展会话与系统端口仿真:SSHAgent、ShellProbe、Forwarder、ProcessPort、RemoteSession;
  • 统一 DNS 与诊断仿真:DNSResolver、DiagnosticSink;
  • 虚拟时钟、终端与文件系统仿真:Clock、TerminalPort、OperatorReadFS、RemoteFS;
  • 多凭据库控制面路由仿真:VaultControlRouter。

架构约束:零生产可达(xopsvet/archbound)、零反向导入父包 core/internal/sim、零明文 SecretBox 消费、 零 time.Now/time.Sleep/裸 go/crypto/rand/path/filepath/nolint;零值适配器统一失败关闭返回 ErrSimNotInitialized。

Index

Constants

This section is empty.

Variables

View Source
var ErrSimNotInitialized = errors.New("sim: 仿真适配器未初始化")

ErrSimNotInitialized 表示零值或未初始化仿真适配器被调用时的规范失败关闭哨兵错误,由父包 sim 只读重导出保持指针同一性。

View Source
var ErrSimulatedENOSPC = errors.New("sim: 模拟磁盘空间不足 (ENOSPC)")

ErrSimulatedENOSPC 表示仿真磁盘空间不足(ENOSPC)故障的不可变哨兵错误,由父包 sim 只读重导出保持指针同一性。

Functions

This section is empty.

Types

type Clock added in v1.4.0

type Clock struct {
	// contains filtered or unexported fields
}

Clock 提供 100% 确定性并发安全虚拟时钟与定时器调度器(实现 ports.Clock,零 time.Sleep)。

func NewClock added in v1.4.0

func NewClock(start time.Time) *Clock

NewClock 构造从 start 起步的虚拟时钟(零值默认基准时刻由父包 sim.NewSimClock 负责补齐)。

func (*Clock) Advance added in v1.4.0

func (c *Clock) Advance(d time.Duration)

func (*Clock) AdvanceToNext added in v1.4.0

func (c *Clock) AdvanceToNext() (time.Duration, bool)

func (*Clock) Faults added in v1.4.0

func (b *Clock) Faults() *memtree.FaultInjector

Faults 返回适配器关联的并发安全确定性故障注入器;零值未初始化返回 nil。

func (*Clock) NewTimer added in v1.4.0

func (c *Clock) NewTimer(d time.Duration) ports.Timer

func (*Clock) Now added in v1.4.0

func (c *Clock) Now() time.Time

Now / Since / PendingTimers / Advance / AdvanceToNext / NewTimer / Sleep / WaitPending 驱动虚拟时钟。

func (*Clock) PendingTimers added in v1.4.0

func (c *Clock) PendingTimers() int

func (*Clock) Since added in v1.4.0

func (c *Clock) Since(t time.Time) time.Duration

func (*Clock) Sleep added in v1.4.0

func (c *Clock) Sleep(ctx context.Context, d time.Duration) error

func (*Clock) WaitPending added in v1.4.0

func (c *Clock) WaitPending(ctx context.Context, n int) error

type DNSResolver added in v1.5.0

type DNSResolver struct {
	// contains filtered or unexported fields
}

DNSResolver 实现统一网络 DNS 端口 ports.DNSResolverPort 的零网络确定性仿真器, 支持自定义 DNS 优先级(custom -> system)模拟、按域分流标记、单标签 search_domains、A/AAAA 地址族过滤、 CNAME 链与 NODATA 自返回、SSHFP 记录与虚拟时钟延迟/故障注入;零值恒失败关闭。

func NewDNSResolver added in v1.5.0

func NewDNSResolver(clk ports.Clock) *DNSResolver

NewDNSResolver 创建零网络确定性统一 DNS 仿真器(默认 customServer="10.0.0.53:53"、fallbackToSystem=true)。

func (*DNSResolver) CNAMELookupCount added in v1.5.0

func (r *DNSResolver) CNAMELookupCount() uint64

func (*DNSResolver) CNAMELookups added in v1.5.0

func (r *DNSResolver) CNAMELookups() uint64

func (*DNSResolver) Faults added in v1.5.0

func (b *DNSResolver) Faults() *memtree.FaultInjector

Faults 返回适配器关联的并发安全确定性故障注入器;零值未初始化返回 nil。

func (*DNSResolver) HostLookupCount added in v1.5.0

func (r *DNSResolver) HostLookupCount() uint64

HostLookupCount / CNAMELookupCount / LookupCount / RecordedQueries 提供零 DNS 副作用与查询序列观测。

func (*DNSResolver) IPLookups added in v1.5.0

func (r *DNSResolver) IPLookups() uint64

func (*DNSResolver) LookupCNAME added in v1.5.0

func (r *DNSResolver) LookupCNAME(ctx context.Context, host string) (z ports.DNSCNAMEResult, err error)

LookupCNAME 严格遵守端口契约:有 CNAME 返回下一跳,NODATA(主机存在但无 CNAME)返回自身,NXDOMAIN 返回 ErrNotFound。

func (*DNSResolver) LookupCount added in v1.5.0

func (r *DNSResolver) LookupCount() uint64

func (*DNSResolver) LookupIP added in v1.5.0

func (r *DNSResolver) LookupIP(ctx context.Context, host string, family option.AddressFamily) (z ports.DNSIPResult, err error)

LookupIP 按 Custom DNS -> System DNS(含单标签 search_domains)解析 IP 并严格按 family 过滤。

func (*DNSResolver) LookupSSHFP added in v1.5.0

func (r *DNSResolver) LookupSSHFP(ctx context.Context, host netaddr.CanonicalHost) (z ports.DNSSSHFPResult, err error)

LookupSSHFP 按 Custom DNS -> System DNS 查询 SSHFP 记录(IP 字面量直接返回空切片)。

func (*DNSResolver) Queries added in v1.5.0

func (r *DNSResolver) Queries() []string

Queries 与计数访问器用于测试断言解析次数与顺序。

func (*DNSResolver) RecordedQueries added in v1.5.0

func (r *DNSResolver) RecordedQueries() []string

func (*DNSResolver) SSHFPLookups added in v1.5.0

func (r *DNSResolver) SSHFPLookups() uint64

func (*DNSResolver) SetCNAME added in v1.5.0

func (r *DNSResolver) SetCNAME(host, target string)

SetCNAME 在系统 DNS 层注册单跳 CNAME 映射(等价于 SetSystemCNAME)。

func (*DNSResolver) SetCNAMEChain added in v1.5.0

func (r *DNSResolver) SetCNAMEChain(names ...string)

SetCNAMEChain 在系统 DNS 层批量注册多跳 CNAME 链(names[0] -> names[1] -> ... -> names[n-1])。

func (*DNSResolver) SetCNAMELoop added in v1.5.0

func (r *DNSResolver) SetCNAMELoop(names ...string)

SetCNAMELoop 在系统 DNS 层注册首尾闭环的 CNAME 环路,用于验证防环截断。

func (*DNSResolver) SetCustomCNAME added in v1.5.0

func (r *DNSResolver) SetCustomCNAME(host, target string)

SetCustomCNAME 与 SetSystemCNAME 分别在自定义/系统层注册单跳 CNAME。

func (*DNSResolver) SetCustomHost added in v1.5.0

func (r *DNSResolver) SetCustomHost(host string, rawAddrs ...string)

SetCustomHost 在自定义 DNS 层注册主机的 IP 列表。

func (*DNSResolver) SetCustomSSHFP added in v1.5.0

func (r *DNSResolver) SetCustomSSHFP(host string, recs ...ports.SSHFPRecord)

SetCustomSSHFP 与 SetSystemSSHFP 分别在自定义/系统层注册 SSHFP 记录。

func (*DNSResolver) SetCustomServerLabel added in v1.5.0

func (r *DNSResolver) SetCustomServerLabel(label string)

SetCustomServerLabel 配置仿真自定义 DNS 服务器标识。

func (*DNSResolver) SetError added in v1.5.0

func (r *DNSResolver) SetError(host string, err error)

SetError 为指定主机注入确定性查询错误。

func (*DNSResolver) SetFallbackToSystem added in v1.5.0

func (r *DNSResolver) SetFallbackToSystem(allow bool)

SetFallbackToSystem 控制自定义 DNS 未命中时是否回退系统 DNS 仿真表。

func (*DNSResolver) SetFollowCNAMEChain added in v1.5.0

func (r *DNSResolver) SetFollowCNAMEChain(follow bool)

SetFollowCNAMEChain 控制 LookupCNAME 是返回单跳下一规范名(false,默认)还是递归追链至终点(true)。

func (*DNSResolver) SetHost added in v1.5.0

func (r *DNSResolver) SetHost(host string, rawAddrs ...string)

SetHost 在系统 DNS 层注册主机地址(等价于 SetSystemHost),供单测与 TCK 快捷装配。

func (*DNSResolver) SetHostError added in v1.5.0

func (r *DNSResolver) SetHostError(host string, err error)

SetHostError 为指定主机注入确定性查询错误(等价于 SetError)。

func (*DNSResolver) SetLatency added in v1.5.0

func (r *DNSResolver) SetLatency(d time.Duration)

SetLatency 配置虚拟时钟查询延迟。

func (*DNSResolver) SetMaxCNAMEHops added in v1.5.0

func (r *DNSResolver) SetMaxCNAMEHops(maxHops int)

SetMaxCNAMEHops 配置解析器内部追链最大跳数上限(<= 0 恢复默认值 16)。

func (*DNSResolver) SetRecords added in v1.5.0

func (r *DNSResolver) SetRecords(host netaddr.CanonicalHost, recs ...ports.SSHFPRecord)

SetRecords 在系统 DNS 层为指定规范主机注册有效 SSHFP 记录切片。

func (*DNSResolver) SetSearchDomains added in v1.5.0

func (r *DNSResolver) SetSearchDomains(domains ...string)

SetSearchDomains 配置仅作用于单标签 LookupIP 的搜索域列表。

func (*DNSResolver) SetSystemCNAME added in v1.5.0

func (r *DNSResolver) SetSystemCNAME(host, target string)

func (*DNSResolver) SetSystemHost added in v1.5.0

func (r *DNSResolver) SetSystemHost(host string, rawAddrs ...string)

SetSystemHost 在系统 DNS 层注册主机的 IP 列表。

func (*DNSResolver) SetSystemSSHFP added in v1.5.0

func (r *DNSResolver) SetSystemSSHFP(host string, recs ...ports.SSHFPRecord)

type DiagnosticSink

type DiagnosticSink struct {
	// contains filtered or unexported fields
}

DiagnosticSink 实现 ports.DiagnosticSink 的纯内存确定性诊断接收仿真器(ADR-019 C3), 支持级别过滤、有界容量丢弃计数与记录快照观测;零值恒安全静默忽略。

func NewDiagnosticSink

func NewDiagnosticSink() *DiagnosticSink

NewDiagnosticSink 创建默认接收全部 1..3 级有效诊断记录的纯内存仿真接收器。

func (*DiagnosticSink) Count

func (s *DiagnosticSink) Count() int

Count 返回当前缓冲中的诊断记录数量。

func (*DiagnosticSink) Dropped

func (s *DiagnosticSink) Dropped() uint64

Dropped 返回因有界缓冲满载而丢弃的诊断记录总数。

func (*DiagnosticSink) Emit

Emit 接收单条脱敏诊断记录;未初始化接收器、nil/已取消 ctx、零值/无效 rec 或超级别记录均安全静默忽略。

func (*DiagnosticSink) Faults

func (b *DiagnosticSink) Faults() *memtree.FaultInjector

Faults 返回适配器关联的并发安全确定性故障注入器;零值未初始化返回 nil。

func (*DiagnosticSink) Records

func (s *DiagnosticSink) Records() []ports.DiagnosticRecord

Records 返回当前已记录的诊断快照防御性副本。

func (*DiagnosticSink) Reset

func (s *DiagnosticSink) Reset()

Reset 清空已缓冲诊断记录与丢弃计数器。

func (*DiagnosticSink) SetMaxLevel

func (s *DiagnosticSink) SetMaxLevel(level uint8)

SetMaxLevel 设置接收的最大诊断级别(1..3,越界输入静默忽略)。

func (*DiagnosticSink) SetMaxRecords

func (s *DiagnosticSink) SetMaxRecords(limit int)

SetMaxRecords 设置最大缓冲记录条数(<= 0 表示无上限;超限时新记录丢弃并累加 Dropped)。

type FileFormatImporter added in v1.5.0

type FileFormatImporter struct {
	// contains filtered or unexported fields
}

FileFormatImporter 实现 ports.FileFormatImporter(ADR-021 §5.5), 基于纯内存 OperatorReadFS 仿真离线本地文件导入、递归 include 展开(含环路/深度上限护栏)、 根同步作用域键(SourceKey)透传与实际来源子文件(OriginFile)记录;零值恒失败关闭返回 ErrSimNotInitialized。

文件行格式(跳过空行与 # 注释):

  • "include <abs-path>"(大小写不敏感):FollowIncludes==true 时递归解析目标文件;false 时记录 include_skipped 告警;
  • "alias,addr,port,user":解析为同源 Managed Host/Identity/Node,SyncSource.SourceKey 恒为根同步作用域键。

func NewFileFormatImporter added in v1.5.0

func NewFileFormatImporter(format string) *FileFormatImporter

NewFileFormatImporter 创建携带独立内存只读文件系统的离线文件导入仿真器(空格式名默认 "openssh")。

func NewFileFormatImporterWithFS added in v1.5.0

func NewFileFormatImporterWithFS(format string, readFS *OperatorReadFS) *FileFormatImporter

NewFileFormatImporterWithFS 创建绑定指定 OperatorReadFS(nil 或未初始化时自动新建)的离线文件导入仿真器。

func (*FileFormatImporter) Faults added in v1.5.0

func (b *FileFormatImporter) Faults() *memtree.FaultInjector

Faults 返回适配器关联的并发安全确定性故障注入器;零值未初始化返回 nil。

func (*FileFormatImporter) Format added in v1.5.0

func (i *FileFormatImporter) Format() string

Format 返回规范小写格式名;零值未初始化返回空字符串。

func (*FileFormatImporter) Import added in v1.5.0

func (i *FileFormatImporter) Import(ctx context.Context, sourceName string, r io.Reader) (out inventory.ImportBundle, err error)

Import 实现 ports.FormatImporter,从只读流解析资产行; 优先使用 SetSyncSourceKey 显式覆盖键,否则当 sourceName 非空时无状态地以 sourceName 作为 SyncSource.SourceKey 与 OriginFile。

func (*FileFormatImporter) ImportFile added in v1.5.0

ImportFile 实现 ports.FileFormatImporter,从内存 OperatorReadFS 读取根文件并按 opts 决定是否递归展开 include。

func (*FileFormatImporter) ImportFileCount added in v1.5.0

func (i *FileFormatImporter) ImportFileCount() int

func (*FileFormatImporter) LastOptions added in v1.5.0

func (i *FileFormatImporter) LastOptions() ports.FileImportOptions

func (*FileFormatImporter) LastPath added in v1.5.0

LastPath、LastOptions 与 ImportFileCount 返回最近一次有效 ImportFile 调用观测快照。

func (*FileFormatImporter) PutFile added in v1.5.0

func (i *FileFormatImporter) PutFile(p pathalg.LocalSourcePath, data []byte) error

PutFile 在关联的纯内存只读文件系统中写入测试源文件。

func (i *FileFormatImporter) PutSymlink(linkPath, targetPath pathalg.LocalSourcePath) error

PutSymlink 在关联的纯内存只读文件系统中注册测试符号链接夹具。

func (*FileFormatImporter) ReadFS added in v1.5.0

func (i *FileFormatImporter) ReadFS() *OperatorReadFS

ReadFS 返回关联的纯内存 OperatorReadFS;零值未初始化返回 nil。

func (*FileFormatImporter) RemoveFile added in v1.5.0

RemoveFile 从关联的纯内存只读文件系统中移除指定源文件(用于模拟 Include 子文件删除后的 --prune 同步)。

func (*FileFormatImporter) SetSyncSourceKey added in v1.5.0

func (i *FileFormatImporter) SetSyncSourceKey(sourceKey string)

SetSyncSourceKey 配置纯流 Import 时可选覆盖的根同步作用域键(留空时按 Import 入参 sourceName 无状态推导; ImportFile 始终优先使用 opts.SyncSourceKey() 或根路径)。

type FormatImporter

type FormatImporter struct {
	// contains filtered or unexported fields
}

FormatImporter 实现纯流 ports.FormatImporter(故意不实现 FileFormatImporter,供 MCP 沙箱与纯流导入验证), 将 CSV 行(alias,addr,port,user)解析为 ImportBundle:

  • 若经 SetSyncSourceKey 显式配置覆盖键,则以该键作为 SyncSource.SourceKey;
  • 否则若调用入参 sourceName 非空,直接以 sourceName 作为无状态 SyncSource.SourceKey 与 OriginFile;
  • 两者皆空时不附带 SyncSource(保持只增无作用域导入语义)。

func NewFormatImporter

func NewFormatImporter(format string) *FormatImporter

NewFormatImporter 创建纯流格式导入仿真器(空格式名默认 "csv")。

func (*FormatImporter) Faults

func (b *FormatImporter) Faults() *memtree.FaultInjector

Faults 返回适配器关联的并发安全确定性故障注入器;零值未初始化返回 nil。

func (*FormatImporter) Format

func (i *FormatImporter) Format() string

func (*FormatImporter) Import

func (i *FormatImporter) Import(ctx context.Context, sourceName string, r io.Reader) (out inventory.ImportBundle, err error)

func (*FormatImporter) SetSyncSourceKey added in v1.5.0

func (i *FormatImporter) SetSyncSourceKey(sourceKey string)

SetSyncSourceKey 配置可选测试覆盖根同步作用域键(留空时按 Import 入参 sourceName 无状态推导)。

type Forwarder

type Forwarder struct {
	// contains filtered or unexported fields
}

Forwarder 实现 ports.ForwarderPort,返回持留池钉选传输的 *memtree.ForwardHandle(满足 pool.ManagedResource)。

func NewForwarder

func NewForwarder() *Forwarder

NewForwarder 创建纯内存 SSH 隧道转发仿真器。

func (*Forwarder) Faults

func (b *Forwarder) Faults() *memtree.FaultInjector

Faults 返回适配器关联的并发安全确定性故障注入器;零值未初始化返回 nil。

func (*Forwarder) LastBindOptions

func (f *Forwarder) LastBindOptions() (out ports.ForwardBindOptions)

LastBindOptions 返回最近一次通过参数校验的 StartForward 绑定选项快照(供单测断言策略透传闭环)。

func (*Forwarder) StartForward

StartForward 启动单条受管隧道转发并持留非借用 transport 直至 ForwardHandle.Close()(支持启动后持续打开新通道)。

type HostTrust

type HostTrust struct {
	// contains filtered or unexported fields
}

HostTrust 实现按 Endpoint (Host, Port) 严格隔离的主机密钥信任库仿真器(INV-E2)。

func NewHostTrust

func NewHostTrust() *HostTrust

NewHostTrust 创建空白主机密钥信任库仿真器。

func (*HostTrust) Faults

func (b *HostTrust) Faults() *memtree.FaultInjector

Faults 返回适配器关联的并发安全确定性故障注入器;零值未初始化返回 nil。

func (*HostTrust) PreferredAlgorithms

func (t *HostTrust) PreferredAlgorithms(ctx context.Context, ep netaddr.Endpoint, _ option.KnownHostsList) ([]string, error)

func (*HostTrust) RecordHostKey

func (*HostTrust) RevokeKey

func (t *HostTrust) RevokeKey(fp inventory.KeyFingerprint)

RevokeKey 吊销指定主机公钥指纹,后续核验将返回 HostTrustRevoked。

func (*HostTrust) VerifyHostKey

func (t *HostTrust) VerifyHostKey(ctx context.Context, req ports.HostTrustRequest) (out ports.HostTrustCheck, err error)

type InventoryStore

type InventoryStore struct {
	// contains filtered or unexported fields
}

InventoryStore 实现 ports.InventoryStore,支持 CAS 并发冲突与不确定落盘结果注入。

func NewInventoryStore

func NewInventoryStore(initial inventory.Graph) (*InventoryStore, error)

NewInventoryStore 以初始资产图(无效时自动构造空有效图,有效时按值深拷贝隔离)创建存储仿真器。

func (*InventoryStore) CommitCAS

func (s *InventoryStore) CommitCAS(ctx context.Context, expected ports.Revision, next inventory.Graph) (out ports.DurabilityOutcome, err error)

func (*InventoryStore) Faults

func (b *InventoryStore) Faults() *memtree.FaultInjector

Faults 返回适配器关联的并发安全确定性故障注入器;零值未初始化返回 nil。

func (*InventoryStore) InjectNextDurability

func (s *InventoryStore) InjectNextDurability(out ports.DurabilityOutcome)

InjectNextDurability 注入下一次 CommitCAS 的持久化结果(如 Applied&&!Durable 或 Unknown)。

func (*InventoryStore) Load

func (s *InventoryStore) Load(ctx context.Context) (out ports.InventorySnapshot, err error)

type JournalStore

type JournalStore struct {
	// contains filtered or unexported fields
}

JournalStore 实现 ports.JournalStore 的纯内存确定性双代传输 WAL 仿真器(支持按代隔离与单侧损坏注入)。

func NewJournalStore

func NewJournalStore() *JournalStore

NewJournalStore 创建空白双代传输 Journal 仿真器。

func (*JournalStore) Append

func (*JournalStore) CorruptGeneration

func (s *JournalStore) CorruptGeneration(id security.OperationID, generation uint64, cause error)

CorruptGeneration 将指定 (transferID, generation) 标记为损坏态以供双代损坏隔离崩溃恢复测试。

func (*JournalStore) Delete

func (*JournalStore) Faults

func (b *JournalStore) Faults() *memtree.FaultInjector

Faults 返回适配器关联的并发安全确定性故障注入器;零值未初始化返回 nil。

func (*JournalStore) ListActive

func (s *JournalStore) ListActive(ctx context.Context) ([]security.OperationID, error)

func (*JournalStore) Load

func (*JournalStore) LoadGenerations

func (*JournalStore) PruneGeneration

func (s *JournalStore) PruneGeneration(ctx context.Context, id security.OperationID, generation uint64) error

type KeySigner

type KeySigner struct {
	// contains filtered or unexported fields
}

KeySigner 实现 ports.KeySignerPort 的确定性签名与指纹查询仿真器。

func NewKeySigner

func NewKeySigner(keys ...ports.PublicKeyInfo) *KeySigner

NewKeySigner 创建预置公钥的密钥签名仿真器。

func (*KeySigner) AddKey

func (s *KeySigner) AddKey(pub ports.PublicKeyInfo, keyPath string)

AddKey 注册公钥及其可选私钥路径映射(未注册路径查询时返回 ErrNotFound)。

func (*KeySigner) Faults

func (b *KeySigner) Faults() *memtree.FaultInjector

Faults 返回适配器关联的并发安全确定性故障注入器;零值未初始化返回 nil。

func (*KeySigner) InspectPrivateKeyFingerprint

func (s *KeySigner) InspectPrivateKeyFingerprint(ctx context.Context, keyPath inventory.KeyPathSpec, _ algebraic.Option[secret.Ref]) (out inventory.KeyFingerprint, err error)

func (*KeySigner) ListPublicKeys

func (s *KeySigner) ListPublicKeys(ctx context.Context, auth inventory.AuthMethod) ([]ports.PublicKeyInfo, error)

func (*KeySigner) Sign

func (s *KeySigner) Sign(ctx context.Context, key inventory.KeyFingerprint, algorithm string, data []byte) (out ports.Signature, err error)

type OperatorReadFS added in v1.4.0

type OperatorReadFS struct {
	// contains filtered or unexported fields
}

OperatorReadFS 实现 ports.OperatorReadFS 的人工只读源内存仿真器(复用 memtree.Tree)。

func NewOperatorReadFS added in v1.4.0

func NewOperatorReadFS() *OperatorReadFS

NewOperatorReadFS 创建空白的操作员只读源仿真器。

func (*OperatorReadFS) Faults added in v1.4.0

func (b *OperatorReadFS) Faults() *memtree.FaultInjector

Faults 返回适配器关联的并发安全确定性故障注入器;零值未初始化返回 nil。

func (*OperatorReadFS) PutFile added in v1.4.0

func (o *OperatorReadFS) PutFile(p pathalg.LocalSourcePath, data []byte) error

PutFile 与 PutSymlink 注册仿真只读常规文件与符号链接夹具。

func (o *OperatorReadFS) PutSymlink(linkPath, targetPath pathalg.LocalSourcePath) error

func (*OperatorReadFS) RemoveFile added in v1.5.0

func (o *OperatorReadFS) RemoveFile(p pathalg.LocalSourcePath) error

RemoveFile 删除指定仿真只读文件或符号链接节点(供离线同步裁剪子文件场景使用;目录或缺失路径失败关闭)。

func (*OperatorReadFS) WithOperatorRead added in v1.4.0

func (o *OperatorReadFS) WithOperatorRead(ctx context.Context, srcPath pathalg.LocalSourcePath, policy pathalg.SymlinkPolicy, fn func(r ports.BoundedReadHandle, size int64) error) error

WithOperatorRead 按 SymlinkPolicy 逐段解析并打开只读源,在同步闭包内借出受哨兵保护的随机读取句柄。

type ProcessHandler

type ProcessHandler func(ctx context.Context, spec ports.ProcessSpec, stdin []byte) (ports.ProcessResult, error)

ProcessHandler 定义 ProcessPort 的可编程命令处理回调。

type ProcessPort

type ProcessPort struct {
	// contains filtered or unexported fields
}

ProcessPort 是零 os/exec 的纯内存子进程与 stdio 管道仿真器,实现 ports.ProcessPort。

func NewProcessPort

func NewProcessPort() *ProcessPort

NewProcessPort 创建纯内存子进程仿真器("fail"/"false" 返回退出码 1,其余默认回显 stdin)。

func (*ProcessPort) DialStdio

func (p *ProcessPort) DialStdio(ctx context.Context, spec ports.ProcessSpec) (net.Conn, error)

func (*ProcessPort) Faults

func (b *ProcessPort) Faults() *memtree.FaultInjector

Faults 返回适配器关联的并发安全确定性故障注入器;零值未初始化返回 nil。

func (*ProcessPort) RegisterCommand

func (p *ProcessPort) RegisterCommand(cmd string, fn ProcessHandler)

RegisterCommand 注册或注销指定命令名的自定义处理回调。

func (*ProcessPort) Run

func (p *ProcessPort) Run(ctx context.Context, spec ports.ProcessSpec, stdin io.Reader) (out ports.ProcessResult, err error)

type RemoteFS added in v1.4.0

type RemoteFS struct {
	// contains filtered or unexported fields
}

RemoteFS 是纯内存远端 POSIX/SFTP 文件系统仿真器(ADR-016,仅使用 path 包,支持中间目录软链解析、(dev,ino) 锚点与原子子树重命名)。

func NewRemoteFS added in v1.4.0

func NewRemoteFS(clk ports.Clock) *RemoteFS

NewRemoteFS 创建预置根目录 "/" 的远端 POSIX 文件系统仿真器。

func (*RemoteFS) Chmod added in v1.4.0

func (r *RemoteFS) Chmod(ctx context.Context, p pathalg.RemotePath, perm fs.FileMode) error

Chmod 修改远端目标对象标准权限位(仅允许 0o001..0o777,拒绝零值及特殊权限位)。

func (*RemoteFS) Chtimes added in v1.4.0

func (r *RemoteFS) Chtimes(ctx context.Context, p pathalg.RemotePath, atime, mtime time.Time) error

Chtimes 修改远端目标对象访问与修改时间(拒绝零值时间戳,支撑 scp -p)。

func (*RemoteFS) Close added in v1.4.0

func (r *RemoteFS) Close() error

func (*RemoteFS) Faults added in v1.4.0

func (b *RemoteFS) Faults() *memtree.FaultInjector

Faults 返回适配器关联的并发安全确定性故障注入器;零值未初始化返回 nil。

func (*RemoteFS) Lstat added in v1.4.0

func (*RemoteFS) MkdirAll added in v1.4.0

func (r *RemoteFS) MkdirAll(ctx context.Context, dir pathalg.RemotePath, perm fs.FileMode) error
func (r *RemoteFS) PutSymlink(linkPath pathalg.RemotePath, target string) error

func (*RemoteFS) ReadChunk added in v1.4.0

func (r *RemoteFS) ReadChunk(ctx context.Context, p pathalg.RemotePath, offset int64, dst io.Writer, length int64) (int64, error)

ReadChunk 从远端常规文件 offset 处读取至多 length 字节写入 dst;读满返回 (length, nil),遇 EOF 返回 (实际字节数, io.EOF)。

func (*RemoteFS) ReadDir added in v1.4.0

func (r *RemoteFS) ReadDir(ctx context.Context, dir pathalg.RemotePath) (out []ports.RemoteDirEntry, err error)
func (r *RemoteFS) ReadLink(ctx context.Context, p pathalg.RemotePath) (target string, err error)

func (*RemoteFS) RealPath added in v1.4.0

func (r *RemoteFS) RealPath(ctx context.Context, p pathalg.RemotePath) (out pathalg.RemotePath, err error)

func (*RemoteFS) Remove added in v1.4.0

func (r *RemoteFS) Remove(ctx context.Context, p pathalg.RemotePath) error

func (*RemoteFS) RemoveDir added in v1.4.0

func (r *RemoteFS) RemoveDir(ctx context.Context, dir pathalg.RemotePath) error

func (*RemoteFS) RenameAtomic added in v1.4.0

func (r *RemoteFS) RenameAtomic(ctx context.Context, oldPath, newPath pathalg.RemotePath, spec ports.RemoteRenameSpec) error

func (*RemoteFS) SetENOSPC added in v1.4.0

func (r *RemoteFS) SetENOSPC(en bool)

SetENOSPC / PutSymlink 提供远端磁盘满故障与软链重定向夹具支持。

func (*RemoteFS) Stat added in v1.4.0

func (*RemoteFS) WithReadFile added in v1.4.0

func (r *RemoteFS) WithReadFile(ctx context.Context, p pathalg.RemotePath, limits ports.ReadLimits, fn func(rd io.Reader, size int64) error) error

WithReadFile 在 limits 上限内以同步闭包借出远端文件只读流。

func (*RemoteFS) WriteChunk added in v1.4.0

func (r *RemoteFS) WriteChunk(ctx context.Context, p pathalg.RemotePath, offset int64, src io.Reader, length int64) error

func (*RemoteFS) WriteFileAtomic added in v1.4.0

func (r *RemoteFS) WriteFileAtomic(ctx context.Context, p pathalg.RemotePath, spec ports.RemoteWriteSpec, src io.Reader) (out ports.RemoteFileStat, err error)

type RemoteSession

type RemoteSession struct {
	// contains filtered or unexported fields
}

RemoteSession 实现 ports.RemoteSession 及具名可选接口 ports.SubsystemRemoteSession、 ports.DirectTTYRemoteSession(ADR-019 A2 / C1 / D3),内部复用 memtree.RemoteSession 管道互斥与 生命周期状态机,补充 StartSubsystem、DirectNativeTTY、ForwardAgent 与 EscapeChar 观测。

func NewRemoteSession

func NewRemoteSession(aliveFn func() bool, cfg memtree.SessionFaultConfig, onClose func()) *RemoteSession

NewRemoteSession 构造绑定至底层连接探活回调、故障配置与可选关闭计数回调的纯内存远端会话。

func (*RemoteSession) BeginStartLocked

func (s *RemoteSession) BeginStartLocked(streams ports.ExecStreams) error

BeginStartLocked 委托底层 memtree.RemoteSession 执行持锁状态复核。

func (*RemoteSession) Close

func (s *RemoteSession) Close() error

func (*RemoteSession) LastEscapeChar

func (s *RemoteSession) LastEscapeChar() algebraic.Option[option.EscapeCharSpec]

LastEscapeChar 返回最近一次会话启动请求携带的可选 EscapeChar 规格(供单测断言)。

func (*RemoteSession) LastForwardAgent

func (s *RemoteSession) LastForwardAgent() algebraic.Option[inventory.AgentSpec]

LastForwardAgent 返回最近一次会话启动请求携带的可选 ForwardAgent 规格(供单测断言)。

func (*RemoteSession) LastSubsystem

func (s *RemoteSession) LastSubsystem() string

LastSubsystem 返回最近一次通过 StartSubsystem 启动的子系统名称(供单测断言)。

func (*RemoteSession) ResizePTY

func (s *RemoteSession) ResizePTY(ctx context.Context, size ports.TerminalSize) error

func (*RemoteSession) SetDirectNativeTTY

func (s *RemoteSession) SetDirectNativeTTY(enabled bool)

SetDirectNativeTTY 配置该仿真会话是否模拟原生 OpenSSH ControlMaster 控制终端 FD 直通模式(默认 false)。

func (*RemoteSession) Signal

func (s *RemoteSession) Signal(ctx context.Context, sig string) error

func (*RemoteSession) Start

func (*RemoteSession) StartShell

func (s *RemoteSession) StartShell(ctx context.Context, streams ports.ExecStreams) error

func (*RemoteSession) StartSubsystem

func (s *RemoteSession) StartSubsystem(ctx context.Context, subsystem string, streams ports.ExecStreams) error

StartSubsystem 实现 ports.SubsystemRemoteSession,校验非空合法子系统名、ForwardAgent 与 EscapeChar 规格, 保持与管道互斥及单次启动一致契约,并记录启动子系统名供仿真测试观测。

func (*RemoteSession) StderrPipe

func (s *RemoteSession) StderrPipe() (io.Reader, error)

func (*RemoteSession) StdinPipe

func (s *RemoteSession) StdinPipe() (io.WriteCloser, error)

func (*RemoteSession) StdoutPipe

func (s *RemoteSession) StdoutPipe() (io.Reader, error)

func (*RemoteSession) UsesDirectNativeTTY

func (s *RemoteSession) UsesDirectNativeTTY() bool

UsesDirectNativeTTY 实现 ports.DirectTTYRemoteSession;未初始化零值失败关闭返回 false。

func (*RemoteSession) Wait

type RevokedPrivStreamHandle added in v1.4.0

type RevokedPrivStreamHandle struct {
	// contains filtered or unexported fields
}

RevokedPrivStreamHandle 是带原子吊销哨兵的仿真提权流句柄,实现 ports.PrivilegedStreamHandle; 退出作用域后 Stdin/Stdout/Stderr 读写关闭与控制面调用均失败关闭返回 ports.ErrHandleExpired。

func NewRevokedPrivStreamHandle added in v1.4.0

func NewRevokedPrivStreamHandle(outcome execution.ExecutionOutcome) *RevokedPrivStreamHandle

NewRevokedPrivStreamHandle 构造绑定终态结果的可吊销仿真提权流句柄。

func (*RevokedPrivStreamHandle) ResizePTY added in v1.4.0

func (*RevokedPrivStreamHandle) Revoke added in v1.4.0

func (h *RevokedPrivStreamHandle) Revoke()

Revoke 不可逆吊销句柄,使后续全部读写、关闭与控制面调用均返回 ports.ErrHandleExpired。

func (*RevokedPrivStreamHandle) Signal added in v1.4.0

func (h *RevokedPrivStreamHandle) Signal(ctx context.Context, sig string) error

func (*RevokedPrivStreamHandle) Stderr added in v1.4.0

func (h *RevokedPrivStreamHandle) Stderr() io.Reader

func (*RevokedPrivStreamHandle) Stdin added in v1.4.0

func (*RevokedPrivStreamHandle) Stdout added in v1.4.0

func (h *RevokedPrivStreamHandle) Stdout() io.Reader

func (*RevokedPrivStreamHandle) Wait added in v1.4.0

type RevokedRemoteFS added in v1.4.0

type RevokedRemoteFS struct {
	// contains filtered or unexported fields
}

RevokedRemoteFS 是退出即吊销的 ports.RemoteFSPort 仿真包装视图;吊销后全量方法(含 Close)返回 ports.ErrHandleExpired。

func NewRevokedRemoteFS added in v1.4.0

func NewRevokedRemoteFS(inner ports.RemoteFSPort) *RevokedRemoteFS

NewRevokedRemoteFS 构造包装 inner 的可吊销 RemoteFSPort 仿真视图。

func (*RevokedRemoteFS) Chmod added in v1.4.0

func (*RevokedRemoteFS) Chtimes added in v1.4.0

func (r *RevokedRemoteFS) Chtimes(ctx context.Context, p pathalg.RemotePath, atime, mtime time.Time) error

func (*RevokedRemoteFS) Close added in v1.4.0

func (r *RevokedRemoteFS) Close() error

func (*RevokedRemoteFS) Lstat added in v1.4.0

func (*RevokedRemoteFS) MkdirAll added in v1.4.0

func (r *RevokedRemoteFS) MkdirAll(ctx context.Context, dir pathalg.RemotePath, perm fs.FileMode) error

func (*RevokedRemoteFS) ReadChunk added in v1.4.0

func (r *RevokedRemoteFS) ReadChunk(ctx context.Context, p pathalg.RemotePath, offset int64, dst io.Writer, length int64) (int64, error)

func (*RevokedRemoteFS) ReadDir added in v1.4.0

func (r *RevokedRemoteFS) ReadLink(ctx context.Context, p pathalg.RemotePath) (string, error)

func (*RevokedRemoteFS) RealPath added in v1.4.0

func (r *RevokedRemoteFS) RealPath(ctx context.Context, p pathalg.RemotePath) (out pathalg.RemotePath, err error)

func (*RevokedRemoteFS) Remove added in v1.4.0

func (*RevokedRemoteFS) RemoveDir added in v1.4.0

func (r *RevokedRemoteFS) RemoveDir(ctx context.Context, dir pathalg.RemotePath) error

func (*RevokedRemoteFS) RenameAtomic added in v1.4.0

func (r *RevokedRemoteFS) RenameAtomic(ctx context.Context, oldPath, newPath pathalg.RemotePath, spec ports.RemoteRenameSpec) error

func (*RevokedRemoteFS) Revoke added in v1.4.0

func (r *RevokedRemoteFS) Revoke()

Revoke 不可逆吊销视图,使后续全部 RemoteFSPort 调用返回 ports.ErrHandleExpired。

func (*RevokedRemoteFS) Stat added in v1.4.0

func (*RevokedRemoteFS) WithReadFile added in v1.4.0

func (r *RevokedRemoteFS) WithReadFile(ctx context.Context, p pathalg.RemotePath, limits ports.ReadLimits, fn func(rd io.Reader, size int64) error) error

func (*RevokedRemoteFS) WriteChunk added in v1.4.0

func (r *RevokedRemoteFS) WriteChunk(ctx context.Context, p pathalg.RemotePath, offset int64, rd io.Reader, length int64) error

func (*RevokedRemoteFS) WriteFileAtomic added in v1.4.0

func (r *RevokedRemoteFS) WriteFileAtomic(ctx context.Context, p pathalg.RemotePath, spec ports.RemoteWriteSpec, rd io.Reader) (out ports.RemoteFileStat, err error)

type SSHAgent

type SSHAgent struct {
	// contains filtered or unexported fields
}

SSHAgent 实现 ports.SSHAgentPort 的纯内存 SSH Agent 通道、公钥列举与签名仿真器。

func NewSSHAgent

func NewSSHAgent(keys ...ports.PublicKeyInfo) *SSHAgent

NewSSHAgent 创建预置公钥且默认可用的 SSH Agent 仿真器。

func (*SSHAgent) AddKey

func (a *SSHAgent) AddKey(pub ports.PublicKeyInfo)

func (*SSHAgent) DialAgent

func (a *SSHAgent) DialAgent(ctx context.Context, spec algebraic.Option[inventory.AgentSpec]) (net.Conn, error)

func (*SSHAgent) Faults

func (b *SSHAgent) Faults() *memtree.FaultInjector

Faults 返回适配器关联的并发安全确定性故障注入器;零值未初始化返回 nil。

func (*SSHAgent) ListAgentKeys

func (a *SSHAgent) ListAgentKeys(ctx context.Context, spec algebraic.Option[inventory.AgentSpec]) ([]ports.PublicKeyInfo, error)

func (*SSHAgent) SetAvailable

func (a *SSHAgent) SetAvailable(en bool)

SetAvailable / AddKey 控制 Agent 可达状态与已加载公钥。

func (*SSHAgent) SignWithAgent

func (a *SSHAgent) SignWithAgent(ctx context.Context, spec algebraic.Option[inventory.AgentSpec], key inventory.KeyFingerprint, algorithm string, data []byte) (out ports.Signature, err error)

type ShellProbe

type ShellProbe struct {
	// contains filtered or unexported fields
}

ShellProbe 实现 ports.ShellProbePort 的两阶段远端 Shell 探测仿真器。

func NewShellProbe

func NewShellProbe(result ports.ShellProbeResult) *ShellProbe

NewShellProbe 创建返回指定探测快照的仿真器(若传入零值则默认 POSIX sh 阶段 1 结果)。

func (*ShellProbe) Faults

func (b *ShellProbe) Faults() *memtree.FaultInjector

Faults 返回适配器关联的并发安全确定性故障注入器;零值未初始化返回 nil。

func (*ShellProbe) ProbeShell

func (p *ShellProbe) ProbeShell(
	ctx context.Context,

	opener ports.SessionOpener,
) (out ports.ShellProbeResult, err error)

ProbeShell 借用 SessionOpener 执行确定性远端 Shell 探测(参数级 //xops:borrowed 静态审计零逃逸)。

func (*ShellProbe) SetResult

func (p *ShellProbe) SetResult(res ports.ShellProbeResult)

SetResult 更新仿真探测返回结果。

type TerminalPort added in v1.4.0

type TerminalPort struct {
	// contains filtered or unexported fields
}

TerminalPort 实现 ports.TerminalPort 与具名可选接口 ports.NativeTTYFDProvider 的纯内存仿真器, 其 WithRawTerminal 借出句柄同时实现 ports.SuspendableTerminalHandle。

func NewTerminalPort added in v1.4.0

func NewTerminalPort(interactive bool, cols, rows uint16) *TerminalPort

NewTerminalPort 创建纯内存终端仿真器(cols/rows 为 0 时默认 80x24)。

func (*TerminalPort) CanSuspendProcessGroup added in v1.4.0

func (t *TerminalPort) CanSuspendProcessGroup() (v security.Verdict, err error)

func (*TerminalPort) Faults added in v1.4.0

func (b *TerminalPort) Faults() *memtree.FaultInjector

Faults 返回适配器关联的并发安全确定性故障注入器;零值未初始化返回 nil。

func (*TerminalPort) IsInteractive added in v1.4.0

func (t *TerminalPort) IsInteractive() bool

func (*TerminalPort) Output added in v1.4.0

func (t *TerminalPort) Output() []byte

func (*TerminalPort) QueueResize added in v1.4.0

func (t *TerminalPort) QueueResize(sizes ...ports.TerminalSize)

func (*TerminalPort) SetBlockInputAfterData added in v1.4.0

func (t *TerminalPort) SetBlockInputAfterData(block bool)

func (*TerminalPort) SetHandleSuspendErr added in v1.4.0

func (t *TerminalPort) SetHandleSuspendErr(err error)

func (*TerminalPort) SetInput added in v1.4.0

func (t *TerminalPort) SetInput(data []byte)

func (*TerminalPort) SetSuspendResult added in v1.4.0

func (t *TerminalPort) SetSuspendResult(v security.Verdict, err error)

SetSuspendResult / SetHandleSuspendErr / SuspendCount / SetInput / SetBlockInputAfterData / QueueResize / Output 配置测试夹具并观测终端状态。

func (*TerminalPort) Size added in v1.4.0

func (t *TerminalPort) Size() (out ports.TerminalSize, err error)

func (*TerminalPort) SuspendCount added in v1.4.0

func (t *TerminalPort) SuspendCount() uint64

func (*TerminalPort) WithNativeTTYFiles added in v1.4.0

func (t *TerminalPort) WithNativeTTYFiles(ctx context.Context, fn func(stdin, stdout, stderr *ports.NativeTTYFile) error) error

WithNativeTTYFiles 实现具名可选接口 ports.NativeTTYFDProvider;纯内存终端无真实 OS TTY 句柄,校验参数后失败关闭返回 ErrUnsupported。

func (*TerminalPort) WithRawTerminal added in v1.4.0

func (t *TerminalPort) WithRawTerminal(ctx context.Context, fn func(term ports.TerminalHandle) error) error

WithRawTerminal 在同步作用域内借出带失效哨兵、双向 Relay 与可挂起能力(SuspendableTerminalHandle)的 TerminalHandle,退出时关闭 ResizeEvents。

type VaultControlRouter

type VaultControlRouter struct {
	// contains filtered or unexported fields
}

VaultControlRouter 实现 ports.VaultControlRouter,按存储名路由至多个独立 VaultControlPort 仿真控制器(ADR-018)。

func NewVaultControlRouter

func NewVaultControlRouter(stores map[string]ports.VaultControlPort) (*VaultControlRouter, error)

NewVaultControlRouter 构造按存储名路由的多库控制面仿真器;可选预注册 stores 映射。

func (*VaultControlRouter) ControlFor

func (r *VaultControlRouter) ControlFor(store string) (ports.VaultControlPort, error)

ControlFor 按存储名路由并返回对应的 VaultControlPort(实现 ports.VaultControlRouter)。

func (*VaultControlRouter) ControlledStores

func (r *VaultControlRouter) ControlledStores() []string

ControlledStores 返回按字典序升序排列的已注册存储名防御性副本(实现 ports.VaultControlRouter)。

func (*VaultControlRouter) Faults

func (b *VaultControlRouter) Faults() *memtree.FaultInjector

Faults 返回适配器关联的并发安全确定性故障注入器;零值未初始化返回 nil。

func (*VaultControlRouter) Register

func (r *VaultControlRouter) Register(store string, ctrl ports.VaultControlPort) error

Register 登记或替换指定存储名对应的 VaultControlPort 控制器(拒绝非法存储名或 nil 控制器)。

Jump to

Keyboard shortcuts

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