From c96b314a9d88df2f7db1276242c78ba48c74c22f Mon Sep 17 00:00:00 2001 From: WuYongJie <549727955@qq.com> Date: Mon, 7 Sep 2026 15:08:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9C=AC=E5=9C=B0=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E7=A8=B3=E5=AE=9A=E6=B3=A8=E5=86=8C=E4=B8=8A=E6=B8=B8=E4=B8=AD?= =?UTF-8?q?=E7=BB=A7=E4=BB=BB=E5=8A=A1=20(#111)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/install-upstream-tunnel-task.ps1 | 9 ++++++++- tests/Unit/Deployment/BusinessMirrorScheduleTest.php | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/scripts/install-upstream-tunnel-task.ps1 b/scripts/install-upstream-tunnel-task.ps1 index 0ca554e8..af85eac8 100644 --- a/scripts/install-upstream-tunnel-task.ps1 +++ b/scripts/install-upstream-tunnel-task.ps1 @@ -85,7 +85,14 @@ $argumentList = @( '-ConfigPath', (ConvertTo-TaskArgument $privateConfigPath) ) $taskArguments = $argumentList -join ' ' -$currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name +$currentUser = if ([string]::IsNullOrWhiteSpace($env:USERNAME)) { + [System.Security.Principal.WindowsIdentity]::GetCurrent().Name +} +else { + # Task Scheduler can return ERROR_FILE_NOT_FOUND when a local SAM account + # is registered with a stale or unresolvable machine-qualified prefix. + $env:USERNAME +} if ($PSCmdlet.ShouldProcess($TaskName, 'register and start the read-only upstream tunnel task')) { $privateConfigDirectory = Split-Path -Parent $privateConfigPath diff --git a/tests/Unit/Deployment/BusinessMirrorScheduleTest.php b/tests/Unit/Deployment/BusinessMirrorScheduleTest.php index 73e7075f..330a8ef2 100644 --- a/tests/Unit/Deployment/BusinessMirrorScheduleTest.php +++ b/tests/Unit/Deployment/BusinessMirrorScheduleTest.php @@ -79,4 +79,14 @@ class BusinessMirrorScheduleTest extends TestCase $this->assertStringContainsString('ClickHouse did not become healthy', $contents, $script); } } + + public function test_tunnel_task_uses_the_local_sam_account_and_hidden_powershell(): void + { + $contents = file_get_contents(dirname(__DIR__, 3) . '/scripts/install-upstream-tunnel-task.ps1'); + + $this->assertIsString($contents); + $this->assertStringContainsString('$env:USERNAME', $contents); + $this->assertStringContainsString("'-WindowStyle', 'Hidden'", $contents); + $this->assertStringContainsString('TASK_LOGON_INTERACTIVE_TOKEN', $contents); + } }