66package procmgr
77
88import (
9+ "encoding/base64"
910 "fmt"
1011 "strings"
1112 "testing"
@@ -57,6 +58,16 @@ func ensureWindowsDirPS(dir string) string {
5758 return psRemote (`New-Item -ItemType Directory -Force -Path '%s' | Out-Null` , dir )
5859}
5960
61+ // writeProcessesDYamlContent writes a processes.d YAML file as UTF-8 without a BOM.
62+ // Set-Content -Encoding utf8 adds a BOM on Windows PowerShell 5.1, which breaks dd-procmgr parsing.
63+ func writeProcessesDYamlContent (yamlPath , content string ) string {
64+ b64 := base64 .StdEncoding .EncodeToString ([]byte (content ))
65+ return psRemote (
66+ `$ErrorActionPreference='Stop'; $p='%s'; $b = [Convert]::FromBase64String('%s'); [IO.File]::WriteAllBytes($p, $b)` ,
67+ yamlPath , b64 ,
68+ )
69+ }
70+
6071// replaceProcessesDYaml applies old→new in processes.d YAML without a UTF-8 BOM.
6172// Set-Content -Encoding utf8 adds a BOM on Windows PowerShell 5.1, which breaks dd-procmgr parsing.
6273func replaceProcessesDYaml (yamlPath , old , new string ) string {
@@ -66,6 +77,24 @@ func replaceProcessesDYaml(yamlPath, old, new string) string {
6677 )
6778}
6879
80+ func windowsProcessOwnerByName (host * e2ecomponents.RemoteHost , name string ) (string , error ) {
81+ script := psRemote (
82+ `$p = Get-CimInstance Win32_Process -Filter "Name='%s'" | Select-Object -First 1; if ($null -eq $p) { exit 1 }; $o = Invoke-CimMethod -InputObject $p -MethodName GetOwner; if ($o.ReturnValue -ne 0) { exit $o.ReturnValue }; "$($o.Domain)/$($o.User)"` ,
83+ name ,
84+ )
85+ out , err := host .Execute (script )
86+ return strings .TrimSpace (out ), err
87+ }
88+
89+ func windowsProcessOwnerByPID (host * e2ecomponents.RemoteHost , pid string ) (string , error ) {
90+ script := psRemote (
91+ `$p = Get-CimInstance Win32_Process -Filter "ProcessId=%s"; if ($null -eq $p) { exit 1 }; $o = Invoke-CimMethod -InputObject $p -MethodName GetOwner; if ($o.ReturnValue -ne 0) { exit $o.ReturnValue }; "$($o.Domain)/$($o.User)"` ,
92+ pid ,
93+ )
94+ out , err := host .Execute (script )
95+ return strings .TrimSpace (out ), err
96+ }
97+
6998func waitProcmgrDescribeRunning (
7099 t * testing.T ,
71100 host * e2ecomponents.RemoteHost ,
0 commit comments