feat: 添加基础类型、工具函数和客户端测试

包含 Ptr[T] 泛型辅助函数、4 种 NoVal 类型(Uint64/Uint32/Uint16/Float64)、字符串集合类型、OpenapiMeta/Error/Warning,以及对应的序列化测试和客户端集成测试。

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
dailz
2026-04-08 18:28:46 +08:00
parent 73453ddd10
commit 5873dc5b72
5 changed files with 864 additions and 0 deletions

73
internal/slurm/types.go Normal file
View File

@@ -0,0 +1,73 @@
package slurm
// Ptr returns a pointer to the given value. Useful for optional fields.
func Ptr[T any](v T) *T { return &v }
// ---------------------------------------------------------------------------
// NoVal types — 3-field structs representing "set/infinite/number" pattern
// from the Slurm OpenAPI spec. All fields are optional (pointer).
// ---------------------------------------------------------------------------
// Uint64NoVal represents an optional uint64 that can be unset or infinite.
type Uint64NoVal struct {
Set *bool `json:"set,omitempty"`
Infinite *bool `json:"infinite,omitempty"`
Number *int64 `json:"number,omitempty"`
}
// Uint32NoVal represents an optional uint32 that can be unset or infinite.
type Uint32NoVal struct {
Set *bool `json:"set,omitempty"`
Infinite *bool `json:"infinite,omitempty"`
Number *int64 `json:"number,omitempty"`
}
// Uint16NoVal represents an optional uint16 that can be unset or infinite.
type Uint16NoVal struct {
Set *bool `json:"set,omitempty"`
Infinite *bool `json:"infinite,omitempty"`
Number *int64 `json:"number,omitempty"`
}
// Float64NoVal represents an optional float64 that can be unset or infinite.
type Float64NoVal struct {
Set *bool `json:"set,omitempty"`
Infinite *bool `json:"infinite,omitempty"`
Number *float64 `json:"number,omitempty"`
}
// ---------------------------------------------------------------------------
// String collection types — all marshal/unmarshal as JSON arrays of strings.
// ---------------------------------------------------------------------------
// CSVString is a comma-separated string collection.
type CSVString []string
// StringArray is a string array type (v0.0.40_string_array).
type StringArray []string
// StringList is a string list type (v0.0.40_string_list).
type StringList []string
// Hostlist is a hostlist type (v0.0.40_hostlist).
type Hostlist []string
// HostlistString is a hostlist string type (v0.0.40_hostlist_string).
type HostlistString []string
// ---------------------------------------------------------------------------
// Process exit types
// ---------------------------------------------------------------------------
// ProcessExitCodeVerbose represents a verbose process exit code.
type ProcessExitCodeVerbose struct {
Status []string `json:"status,omitempty"`
ReturnCode *Uint32NoVal `json:"return_code,omitempty"`
Signal *ProcessExitSignal `json:"signal,omitempty"`
}
// ProcessExitSignal represents a signal received by a process.
type ProcessExitSignal struct {
ID *Uint16NoVal `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
}