test(prime): use native config root in global fixture (#5778)
* test(prime): use native config root in global fixture The global PRIME override fixture staged Linux and macOS paths while the Windows child resolved os.UserConfigDir from inherited APPDATA. Build one isolated profile, ask the host for its native config directory, and stage the override only at that path. Production behavior is unchanged. Related to #4638. Agent-Signature: codex-gpt-5-unknown-reasoning on behalf of Ewen Cuthiell * test(prime): create advertised profiles and exercise Windows fixture Create each isolated profile directory before exporting its path. Run the global override through the shared test runner in the existing required Windows job, rejecting absent, skipped or failed selected coverage. Agent-Signature: unknown-model/unknown-reasoning --------- Co-authored-by: Bee <bee@ghosttrack.com> Co-authored-by: Eddie the Engineer <adopt-pr@gascity.local> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
11ec3a67bc
commit
448c4b8621
3 changed files with 97 additions and 26 deletions
28
.github/workflows/pr.yml
vendored
28
.github/workflows/pr.yml
vendored
|
|
@ -256,8 +256,8 @@ jobs:
|
|||
# The lingering-handle liveness regression test is //go:build windows: the
|
||||
# Ubuntu job above selects it by name but compiles it out, and main.yml's
|
||||
# Windows job runs only on pushes to main (build/smoke, no go test). Run
|
||||
# exactly the liveness pair on windows-latest so the regression guard
|
||||
# actually executes at PR time.
|
||||
# the liveness pair and native config fixture on Windows so their platform
|
||||
# regressions actually execute at PR time.
|
||||
test-windows-liveness:
|
||||
name: Test (Windows) cmd/bd liveness regression
|
||||
runs-on: windows-latest
|
||||
|
|
@ -271,6 +271,30 @@ jobs:
|
|||
go-version-file: 'go.mod'
|
||||
cache: false
|
||||
|
||||
- name: Run native Windows global Prime override
|
||||
shell: bash
|
||||
env:
|
||||
CGO_ENABLED: "1"
|
||||
run: |
|
||||
go_path=$(command -v go)
|
||||
[[ "$("$go_path" env GOHOSTOS GOOS)" == $'windows\nwindows' ]]
|
||||
test_status=0
|
||||
test_output=$(./scripts/test.sh -v -timeout 5m -run '^TestPrimeBinaryPortfolio$/^TestPrime_HookJSON_GlobalPrimeOverride$' -count=1 ./cmd/bd) || test_status=$?
|
||||
printf '%s\n' "$test_output"
|
||||
((test_status == 0))
|
||||
pass_pattern='^[[:space:]]*--- PASS: TestPrimeBinaryPortfolio/TestPrime_HookJSON_GlobalPrimeOverride \('
|
||||
nonpass_pattern='^[[:space:]]*--- (FAIL|SKIP): '
|
||||
pass_count=0
|
||||
while IFS= read -r line; do
|
||||
if [[ "$line" =~ $pass_pattern ]]; then
|
||||
((pass_count += 1))
|
||||
fi
|
||||
if [[ "$line" =~ $nonpass_pattern ]]; then
|
||||
exit 1
|
||||
fi
|
||||
done <<<"$test_output"
|
||||
((pass_count == 1))
|
||||
|
||||
- name: Run Windows liveness regression test
|
||||
run: go test -tags gms_pure_go -count=1 -run '^TestIsServerProbablyRunning' ./cmd/bd
|
||||
|
||||
|
|
|
|||
|
|
@ -222,39 +222,62 @@ func primeScenarioHookJSONStealthCompose(t *testing.T, binPath, workDir string)
|
|||
}
|
||||
}
|
||||
|
||||
// TestPrime_HookJSON_GlobalPrimeOverride: with --hook-json and a
|
||||
// ~/.config/beads/PRIME.md file present (XDG path), output is the JSON
|
||||
// envelope wrapping that file's contents. This exercises the third
|
||||
// custom-PRIME.md path through the wrapper.
|
||||
// isolatedGlobalPrimeConfigFixture creates a complete temporary user profile,
|
||||
// asks the current platform where its user config directory is, and returns a
|
||||
// child environment that resolves to the same directory.
|
||||
func isolatedGlobalPrimeConfigFixture(t *testing.T) (string, []string) {
|
||||
t.Helper()
|
||||
|
||||
profileRoot := t.TempDir()
|
||||
profileVars := []struct {
|
||||
key string
|
||||
value string
|
||||
}{
|
||||
{key: "HOME", value: filepath.Join(profileRoot, "home")},
|
||||
{key: "USERPROFILE", value: filepath.Join(profileRoot, "home")},
|
||||
{key: "APPDATA", value: filepath.Join(profileRoot, "appdata", "roaming")},
|
||||
{key: "LOCALAPPDATA", value: filepath.Join(profileRoot, "appdata", "local")},
|
||||
{key: "XDG_CONFIG_HOME", value: filepath.Join(profileRoot, "xdg-config")},
|
||||
}
|
||||
|
||||
for _, variable := range profileVars {
|
||||
if err := os.MkdirAll(variable.value, 0o755); err != nil {
|
||||
t.Fatalf("create isolated %s directory: %v", variable.key, err)
|
||||
}
|
||||
t.Setenv(variable.key, variable.value)
|
||||
}
|
||||
|
||||
configDir, err := os.UserConfigDir()
|
||||
if err != nil {
|
||||
t.Fatalf("resolve isolated user config dir: %v", err)
|
||||
}
|
||||
rel, err := filepath.Rel(profileRoot, configDir)
|
||||
if err != nil || !filepath.IsLocal(rel) {
|
||||
t.Fatalf("isolated user config dir %q escaped profile root %q", configDir, profileRoot)
|
||||
}
|
||||
|
||||
return configDir, os.Environ()
|
||||
}
|
||||
|
||||
// TestPrime_HookJSON_GlobalPrimeOverride: with --hook-json and a PRIME.md in
|
||||
// the platform-native user config directory, output is the JSON envelope
|
||||
// wrapping that file's contents. This exercises the third custom-PRIME.md path
|
||||
// through the wrapper.
|
||||
func primeScenarioHookJSONGlobalPrimeOverride(t *testing.T, binPath, workDir string) {
|
||||
const custom = "# Global PRIME override\nGreetings from XDG.\n"
|
||||
const custom = "# Global PRIME override\nGreetings from isolated config.\n"
|
||||
|
||||
// resolveGlobalPrimePath uses os.UserConfigDir, which on Linux honors
|
||||
// XDG_CONFIG_HOME. On macOS it returns ~/Library/Application Support
|
||||
// regardless of XDG, so we set HOME and also stage the macOS path to
|
||||
// be cross-platform-safe.
|
||||
xdg := t.TempDir()
|
||||
home := t.TempDir()
|
||||
|
||||
xdgBeadsDir := filepath.Join(xdg, "beads")
|
||||
if err := os.MkdirAll(xdgBeadsDir, 0o755); err != nil {
|
||||
t.Fatalf("mkdir xdg beads dir: %v", err)
|
||||
configDir, childEnv := isolatedGlobalPrimeConfigFixture(t)
|
||||
beadsConfigDir := filepath.Join(configDir, "beads")
|
||||
if err := os.MkdirAll(beadsConfigDir, 0o755); err != nil {
|
||||
t.Fatalf("mkdir global beads config dir: %v", err)
|
||||
}
|
||||
writePrimeFile(t, filepath.Join(xdgBeadsDir, "PRIME.md"), custom)
|
||||
// Cross-platform staging for macOS UserConfigDir.
|
||||
macConfigDir := filepath.Join(home, "Library", "Application Support", "beads")
|
||||
if err := os.MkdirAll(macConfigDir, 0o755); err != nil {
|
||||
t.Fatalf("mkdir mac config dir: %v", err)
|
||||
}
|
||||
writePrimeFile(t, filepath.Join(macConfigDir, "PRIME.md"), custom)
|
||||
writePrimeFile(t, filepath.Join(beadsConfigDir, "PRIME.md"), custom)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
||||
defer cancel()
|
||||
cmd := exec.CommandContext(ctx, binPath, "prime", "--hook-json")
|
||||
cmd.Dir = workDir
|
||||
cmd.Env = append(os.Environ(),
|
||||
"HOME="+home,
|
||||
"XDG_CONFIG_HOME="+xdg,
|
||||
cmd.Env = append(childEnv,
|
||||
"BEADS_TEST_IGNORE_REPO_CONFIG=1",
|
||||
"BEADS_DIR=",
|
||||
"BEADS_DB=",
|
||||
|
|
|
|||
|
|
@ -217,6 +217,30 @@ func TestPRWorkflowExercisesWindowsEnvironmentHelpers(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestPRCIGateRequiresWindowsGlobalPrimeOverride(t *testing.T) {
|
||||
workflow := readCIWorkflow(t, "pr.yml")
|
||||
job := workflow.job(t, "test-windows-liveness")
|
||||
step := job.step(t, "Run native Windows global Prime override")
|
||||
if job.If != "" || job.ContinueOnError || step.If != "" ||
|
||||
(step.ContinueOnError != nil && step.ContinueOnError != false) {
|
||||
t.Fatal("native Windows global Prime override must be unconditional and required")
|
||||
}
|
||||
if step.Shell != "bash" || step.Env["CGO_ENABLED"] != "1" {
|
||||
t.Fatal("native Windows global Prime override requires Bash and CGO")
|
||||
}
|
||||
if !strings.Contains(step.Run, "./scripts/test.sh") ||
|
||||
!strings.Contains(step.Run, "^TestPrimeBinaryPortfolio$/^TestPrime_HookJSON_GlobalPrimeOverride$") {
|
||||
t.Fatal("native Windows gate must execute the global Prime override fixture")
|
||||
}
|
||||
gate := workflow.job(t, "ci-gate")
|
||||
env := gate.step(t, "Evaluate CI gate").Env
|
||||
if !contains(gate.Needs, "test-windows-liveness") ||
|
||||
env["TEST_WINDOWS_LIVENESS"] != "${{ needs.test-windows-liveness.result }}" ||
|
||||
!contains(strings.Fields(env["CI_GATE_REQUIRED"]), "TEST_WINDOWS_LIVENESS") {
|
||||
t.Fatal("CI gate must require the native Windows result")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPRCIGateRequiresJSWasmHookExecution(t *testing.T) {
|
||||
workflow := readCIWorkflow(t, "pr.yml")
|
||||
job := workflow.job(t, "check-cmd-bd-puregeo-tests")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue