Files
Pulse/scripts/installtests/release_ldflags_test.go
pulse-triage[bot] d1d08f4e7d Eliminate 70s real-clock waits and parallelize slow Pulse backend tests
Address the #1 product-repo output constraint in signals/output-constraints.json
(`PR checks (Pulse)`, 19.1m median / 44.8m p90) by removing real-clock idle
waits and serial test bottlenecks across five slow backend packages on the
`Backend tests (rest-*)` and `Unified Agent Native Verification` critical paths:

- `internal/websocket/hub_test.go`: run `TestClientWriterRevalidatesIdleConnection`
  inside `testing/synctest` over an in-memory buffered `net.Conn` listener so
  the real production `client.writePump()` 30-second ping ticker and policy
  withdrawal run in virtual time (`30.00s` -> `0.00s` under `-race`). Add
  `t.Parallel()` to 87 verified global-free tests across 10 files (keeping
  `setAuditLogger`, `log.Logger`, and `SetGlobalLevel` tests serial).
- `internal/truenas/transport_test.go`: run
  `TestAuthenticatedRPCSurvivesIdleTransportTimeout` inside `testing/synctest`
  over an in-memory buffered TLS `net.Conn` listener via
  `client.outboundDialContext` so the real 30-second keepalive ticker, 35-second
  idle deadline, and 40-second idle wait run in virtual time (`40.02s` ->
  `0.02s` under `-race`). Add `t.Parallel()` to 98 verified global-free tests
  across 3 files (keeping `captureRPCCloseLogs` and `t.Setenv` tests serial).
- `internal/unifiedresources/*_test.go` (14 files): add `t.Parallel()` to 294
  verified global-free tests across the slowest serial test files so they run
  concurrently and overlap with `TestRetentionLoop_RunsInitialPrune`'s 30s
  wait (keeping `AllocsPerRun`, `mock.SetEnabled`, and `t.Setenv` files serial).
- `pkg/proxmox/*_test.go` (4 files): add `t.Parallel()` to caller-budget and
  context-cancellation tests and subtests (keeping `log.Logger` tests serial
  and leaving human-claimed `ha_status_test.go` untouched).
- `scripts/installtests/*_test.go` (17 files): add `t.Parallel()` to 110
  verified isolated tests (including `agent_url_admission_test.go` and its 8
  subtests; leaving human-claimed `build_release_assets_test.go` /
  `root_install_sh_test.go`, `guidance_recipe_runner_test.go`, and serial
  `TestInstallSHNASBootOwnersQuiesceBeforeRecoveryErasure` untouched).

Zero production code or test assertions changed.

Contract-Neutral: Test-only virtual-time (testing/synctest) and t.Parallel() execution speedups; no production behavior or subsystem contract changes.
Change-source: pulse-maintainer
2026-11-28 19:24:22 +00:00

180 lines
6.5 KiB
Go

package installtests
import (
"encoding/json"
"os"
"os/exec"
"path/filepath"
"regexp"
"slices"
"strings"
"testing"
"github.com/rcourtman/pulse-go-rewrite/internal/agentidentity"
)
func TestReleaseLdflagsServerIncludesCanonicalBuildMetadata(t *testing.T) {
t.Parallel()
cmd := exec.Command(repoFile("scripts", "release_ldflags.sh"),
"server",
"--version", "6.0.0-rc.1",
"--build-time", "2026-03-15T20:00:00Z",
"--git-commit", "abcdef1",
"--license-public-key", "ZmFrZS1saWNlbnNlLWtleQ==",
"--update-public-keys", "ZmFrZS11cGRhdGUta2V5",
)
output, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("release_ldflags.sh server failed: %v\n%s", err, string(output))
}
ldflags := strings.TrimSpace(string(output))
required := []string{
"-X main.Version=v6.0.0-rc.1",
"-X main.BuildTime=2026-03-15T20:00:00Z",
"-X main.GitCommit=abcdef1",
"-X github.com/rcourtman/pulse-go-rewrite/internal/updates.BuildVersion=v6.0.0-rc.1",
"-X github.com/rcourtman/pulse-go-rewrite/internal/dockeragent.Version=v6.0.0-rc.1",
"-X github.com/rcourtman/pulse-go-rewrite/pkg/licensing.EmbeddedPublicKey=ZmFrZS1saWNlbnNlLWtleQ==",
"-X github.com/rcourtman/pulse-go-rewrite/internal/license.EmbeddedPublicKey=ZmFrZS1saWNlbnNlLWtleQ==",
"-X github.com/rcourtman/pulse-go-rewrite/internal/updatesignature.EmbeddedTrustedPublicKeys=ZmFrZS11cGRhdGUta2V5",
}
for _, needle := range required {
if !strings.Contains(ldflags, needle) {
t.Fatalf("server ldflags missing %q in %q", needle, ldflags)
}
}
}
func TestReleaseLdflagsAgentNormalizesVersionWithoutServerFields(t *testing.T) {
t.Parallel()
cmd := exec.Command(repoFile("scripts", "release_ldflags.sh"),
"agent",
"--version", "6.0.0",
"--update-public-keys", "ZmFrZS11cGRhdGUta2V5",
)
output, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("release_ldflags.sh agent failed: %v\n%s", err, string(output))
}
ldflags := strings.TrimSpace(string(output))
if !strings.Contains(ldflags, "internal/agentidentity.ReleaseIdentity=[[pulse-agent-release:v1:v6.0.0]]") {
t.Fatalf("missing executable release stamp: %s", ldflags)
}
if !strings.Contains(ldflags, "-X main.Version=v6.0.0") {
t.Fatalf("agent ldflags missing normalized version: %q", ldflags)
}
if !strings.Contains(ldflags, "internal/updatesignature.EmbeddedTrustedPublicKeys=ZmFrZS11cGRhdGUta2V5") {
t.Fatalf("agent ldflags missing update public keys: %q", ldflags)
}
disallowed := []string{
"internal/updates.BuildVersion",
"main.BuildTime",
"main.GitCommit",
"internal/dockeragent.Version",
}
for _, needle := range disallowed {
if strings.Contains(ldflags, needle) {
t.Fatalf("agent ldflags unexpectedly contained %q in %q", needle, ldflags)
}
}
}
func TestReleaseLdflagsAgentVersionGrammar(t *testing.T) {
t.Parallel()
for _, version := range []string{"6.2.1", "v6.2.1+git.123", "6.2.0-rc.8", "0.0.0-rootful.v1.gabcdef123456", "rootful-v1.abcdef123456", "6.2", "01.2.3", strings.Repeat("1", 128) + ".2.3"} {
_, runtimeErr := agentidentity.Version(version)
out, err := exec.Command(repoFile("scripts", "release_ldflags.sh"), "agent", "--version", version).CombinedOutput()
if (err == nil) != (runtimeErr == nil) {
t.Fatalf("version %q: runtime=%v recipe=%v %s", version, runtimeErr, err, out)
}
}
}
func TestReleaseLdflagsQualificationVersionsUseRuntimeGrammar(t *testing.T) {
t.Parallel()
pattern := regexp.MustCompile(`qualification_version="([^"]+)"`)
for _, profile := range []string{"rootful", "rootless"} {
source, err := os.ReadFile(repoFile("scripts", "run-secure-runtime-"+profile+"-qualification.sh"))
if err != nil {
t.Fatal(err)
}
match := pattern.FindStringSubmatch(string(source))
if len(match) != 2 {
t.Fatal("qualification version missing")
}
version := strings.ReplaceAll(match[1], "${SOURCE_COMMIT:0:12}", "012345678901")
if _, err := agentidentity.Version(version); err != nil {
t.Fatalf("%s version %q: %v", profile, version, err)
}
if out, err := exec.Command(repoFile("scripts", "release_ldflags.sh"), "agent", "--version", version).CombinedOutput(); err != nil {
t.Fatalf("%s recipe: %v %s", profile, err, out)
}
}
}
func TestReleaseLdflagsVersionGrammarIsSealed(t *testing.T) {
t.Parallel()
for _, name := range []string{"secure_runtime_source_manifest_v6.json", "secure_runtime_source_manifest_v7.json", "secure_runtime_rootful_source_manifest_v1.json", "secure_runtime_rootless_source_manifest_v1.json"} {
data, err := os.ReadFile(repoFile("scripts", "release_control", name))
if err != nil {
t.Fatal(err)
}
var manifest struct {
ExactPaths []string `json:"exact_paths"`
RecursiveRoots []string `json:"recursive_roots"`
IncludeSuffixes []string `json:"include_suffixes"`
ExcludeSuffixes []string `json:"exclude_suffixes"`
}
if err := json.Unmarshal(data, &manifest); err != nil {
t.Fatal(err)
}
for _, required := range []string{"internal/agentidentity/version-pattern.txt", "cmd/verify-agent-release/main.go"} {
if !slices.Contains(manifest.ExactPaths, required) {
t.Fatalf("%s omits required identity input %s", name, required)
}
}
if !slices.Contains(manifest.RecursiveRoots, "internal/agentidentity") || !slices.Contains(manifest.IncludeSuffixes, ".go") {
t.Fatalf("%s does not seal the identity Go sources", name)
}
if slices.Contains(manifest.ExactPaths, "cmd/verify-agent-release/main_test.go") || !slices.Contains(manifest.ExcludeSuffixes, "_test.go") {
t.Fatalf("%s includes verifier unit tests in production provider sources", name)
}
}
}
func TestReleaseLdflagsRequiresNonemptyGrammar(t *testing.T) {
t.Parallel()
root := t.TempDir()
scripts := filepath.Join(root, "scripts")
grammarDir := filepath.Join(root, "internal", "agentidentity")
for _, dir := range []string{scripts, grammarDir} {
if err := os.MkdirAll(dir, 0700); err != nil {
t.Fatal(err)
}
}
recipe, err := os.ReadFile(repoFile("scripts", "release_ldflags.sh"))
if err != nil {
t.Fatal(err)
}
path := filepath.Join(scripts, "release_ldflags.sh")
if err := os.WriteFile(path, recipe, 0700); err != nil {
t.Fatal(err)
}
grammar := filepath.Join(grammarDir, "version-pattern.txt")
for _, content := range []string{"missing", "", "\r\n"} {
if content != "missing" {
if err := os.WriteFile(grammar, []byte(content), 0600); err != nil {
t.Fatal(err)
}
}
output, err := exec.Command(path, "agent", "--version", "6.2.1").CombinedOutput()
if err == nil || !strings.Contains(string(output), "agent version grammar") {
t.Fatalf("grammar %q: %v %s", content, err, output)
}
}
}