mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-11-29 01:08:56 +01:00
Backend tests (api-0..4) finished last on post-#5350 Pulse Build and Test runs (46109093360, ~1,726 runner-seconds across 5 shards), with the slowest unclaimed internal/api tests executing isolated subtest matrices sequentially, seeding the full default public demo estate where compact mock topologies suffice, or bypassing TestMain's PULSE_TEST_BCRYPT_COST via direct bcrypt.DefaultCost calls. - Parallelize isolated subtest matrices across 14 unclaimed internal/api test files (host_agent_credential_handoff_test.go, agent_snapshot_authority_test.go, resource_read_authority_test.go, token_stream_lifetime_test.go, token_stream_shutdown_test.go, assistant_stream_lifetime_test.go, assistant_json_lifetime_test.go, agent_events_auth_test.go, reporting_boundary_test.go, docker_agents_report_size_test.go, security_setup_fixture_isolation_test.go, websocket_auth_test.go, security_token_withdrawal_test.go, and log_stream_auth_test.go), lifting shared env/session setup out of per-subtest helpers, serializing only the temporary AI alert-analysis binder swap during router construction, and caching read-only source file bytes once in reporting_boundary_test.go. - Use the existing compact 2-node mock integration fixture (newIntegrationServer) for TestStateEndpointReturnsMockData, TestConfigNodesUsesMockTopology, and TestMockModeToggleEndpoint in router_integration_test.go, while preserving newFleetIntegrationServer for multi-page recovery rollup/point tests. - Route four test fixtures (change_password_session_admin_test.go, oidc_only_admin_parity_test.go, platform_admin_session_parity_test.go, and security_status_capability_enforcement_test.go) through pkg/auth.HashPassword so they honor TestMain's PULSE_TEST_BCRYPT_COST instead of bcrypt.DefaultCost. Contract-Neutral: Test-only parallelization and fixture optimization across 19 internal/api test files with zero production code, API behavior, or assertion changes. Change-source: pulse-maintainer
50 lines
1.6 KiB
Go
50 lines
1.6 KiB
Go
package api
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"os"
|
|
"os/exec"
|
|
"regexp"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// Ordinary API shards can leave a session store initialized before reaching
|
|
// these bare-router fixtures. The release batch need not have those preceding
|
|
// tests. Reuse this test binary (including its race instrumentation), but run
|
|
// each session-creating case as the only test in a fresh process.
|
|
func TestQuickSecuritySetupFixturesInFreshProcesses(t *testing.T) {
|
|
executable, err := os.Executable()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, name := range []string{
|
|
"TestQuickSecuritySetupAcceptsSetupTokenInBody",
|
|
"TestQuickSecuritySetupRotatesWithBasicAuth",
|
|
"TestQuickSecuritySetupAllowsRecoveryTokenRotation",
|
|
} {
|
|
name := name
|
|
t.Run(name, func(t *testing.T) {
|
|
t.Parallel()
|
|
ctx, cancel := context.WithTimeout(t.Context(), 30*time.Second)
|
|
defer cancel()
|
|
cmd := exec.CommandContext(ctx, executable,
|
|
"-test.run=^"+regexp.QuoteMeta(name)+"$", "-test.v", "-test.count=1", "-test.timeout=20s")
|
|
// Own the child's temporary files even when a panic or timeout
|
|
// prevents its TestMain from cleaning up.
|
|
dir := t.TempDir()
|
|
cmd.Env = append(cmd.Environ(), "TMPDIR="+dir, "TMP="+dir, "TEMP="+dir)
|
|
output, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("fresh process failed: %v\n%s", err, output)
|
|
}
|
|
// Go can exit successfully if an exact selection matches nothing
|
|
// or the fixture skips. Require the root's own passing result.
|
|
if !bytes.Contains(output, []byte("\n--- PASS: "+name+" (")) {
|
|
t.Fatalf("fresh process did not pass the selected test:\n%s", output)
|
|
}
|
|
})
|
|
}
|
|
}
|