WorkBuddy、CodeBuddy 桌面端增强助手:签到猫猫旅行成长计划查询、多账号独立备份、点切即用;免打扰模式让 AI 无人值守跑长任务;跨账号会话迁移、异常中断自动续接;暂存/快捷提示词;毛玻璃主题与更多实用功能。
fix: ignore recycled unrelated lifecycle pids
[email protected]c43b1e1c75f5
diff --git a/scripts/windows-native/main.go b/scripts/windows-native/main.goindex 9f4e683..fec0ed9 100644--- a/scripts/windows-native/main.go+++ b/scripts/windows-native/main.go@@ -789,6 +789,13 @@ func readLockPID(path string) int {return owner.PID}+// A different snapshot name proves a recycled PID is unrelated. A matching or+// unavailable name never authorizes termination or bypasses exact path checks.+func processNameDiffers(actualName, expectedPath string) bool {+ return actualName != "" && expectedPath != "" &&+ !strings.EqualFold(actualName, filepath.Base(expectedPath))+}+func inspectExactProcess(pid int, expectedPath string, label string) (bool, int, error) {if pid <= 0 {return false, 0, nil@@ -809,6 +816,9 @@ func inspectExactProcess(pid int, expectedPath string, label string) (bool, int,present := falsefor _, record := range records {if record.PID == uint32(pid) {+ if processNameDiffers(record.Name, expectedPath) {+ return false, 0, nil+ }present = truebreak}diff --git a/scripts/windows-native/main_test.go b/scripts/windows-native/main_test.gonew file mode 100644index 0000000..5281436--- /dev/null+++ b/scripts/windows-native/main_test.go@@ -0,0 +1,88 @@+//go:build windows++package main++import (+ "os"+ "path/filepath"+ "testing"+)++func TestProcessNameDiffersRequiresPositiveMismatch(t *testing.T) {+ for _, test := range []struct {+ name string+ want bool+ }{+ {"svchost.exe", true},+ {"System", true},+ {"node.exe", false},+ {"NODE.EXE", false},+ {"", false},+ } {+ if got := processNameDiffers(test.name, `C:\WorkDaddy\scripts\runtime\node\node.exe`); got != test.want {+ t.Errorf("name %q: unrelated=%v, want %v", test.name, got, test.want)+ }+ }+ if processNameDiffers("node.exe", "") {+ t.Fatal("missing expected identity must stay fail-closed")+ }+}++func TestExactInspectionStillRejectsWrongPath(t *testing.T) {+ expectedPath := filepath.Join(t.TempDir(), filepath.Base(os.Args[0]))+ active, code, err := inspectExactProcess(os.Getpid(), expectedPath, "test")+ if active || code != exitIdentityMismatch || err == nil {+ t.Fatalf("wrong executable path accepted: active=%v code=%d err=%v", active, code, err)+ }+}++func TestProtectedMatchingProcessStillFailsClosed(t *testing.T) {+ active, code, err := inspectExactProcess(4, `C:\Windows\System32\System`, "test")+ if active || code != exitAccessDenied || err == nil {+ t.Fatalf("protected matching name accepted: active=%v code=%d err=%v", active, code, err)+ }+}++func TestLifecycleIgnoresRecycledSystemPID(t *testing.T) {+ // PID 4 is the protected System process, never a WorkDaddy Node process.+ // Exercise the real Windows access-denied inspection without terminating it.+ t.Setenv("APPDATA", t.TempDir())+ appDir := t.TempDir()+ dir, err := dataDir(profileCN)+ if err != nil {+ t.Fatal(err)+ }+ if err := os.MkdirAll(dir, 0700); err != nil {+ t.Fatal(err)+ }+ for name, content := range map[string]string{+ "watchdog.pid": "4",+ ".daemon.lock": `{"pid":4}`,+ "account-data-sentinel": "preserve",+ } {+ if err := os.WriteFile(filepath.Join(dir, name), []byte(content), 0600); err != nil {+ t.Fatal(err)+ }+ }+ if code := stopLifecycle(profileCN, appDir, false); code != 0 {+ t.Fatalf("stale PID for protected unrelated process blocks cleanup: %d", code)+ }+ for _, name := range []string{"watchdog.pid", ".daemon.lock"} {+ if _, err := os.Stat(filepath.Join(dir, name)); !os.IsNotExist(err) {+ t.Fatalf("stale %s remains: %v", name, err)+ }+ }+ if data, err := os.ReadFile(filepath.Join(dir, "account-data-sentinel")); err != nil || string(data) != "preserve" {+ t.Fatalf("unrelated data changed: %v", err)+ }+ if records, err := enumerateProcesses(); err != nil {+ t.Fatal(err)+ } else {+ for _, record := range records {+ if record.PID == 4 {+ return+ }+ }+ t.Fatal("System process disappeared")+ }+}diff --git a/test/windows-native-flow.test.js b/test/windows-native-flow.test.jsindex 2efed2c..0f349a9 100644--- a/test/windows-native-flow.test.js+++ b/test/windows-native-flow.test.js@@ -282,8 +282,9 @@ test('native lifecycle cleanup clears an access-denied PID that is absent from tconst deniedResult = inspect.indexOf('return false, exitAccessDenied', absent);assert.ok(denied >= 0, 'access-denied inspection must stay fail-closed');assert.ok(snapshot > denied, 'access-denied inspection must refresh the process snapshot');- assert.ok(absent > snapshot && deniedResult > absent, 'only a PID absent from the snapshot may be treated as stale');+ assert.ok(absent > snapshot && deniedResult > absent, 'absent PIDs must be treated as stale while uncertain identities remain fail-closed');assert.match(inspect.slice(snapshot, deniedResult), /record\.PID == uint32\(pid\)[\s\S]*if !present[\s\S]*return false, 0, nil/);+ assert.match(inspect.slice(snapshot, deniedResult), /processNameDiffers\(record\.Name, expectedPath\)[\s\S]*return false, 0, nil/);});test('elevated lifecycle cleanup inspects exact state before refusing active termination', () => {