mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-07-13 00:13:33 +08:00
- 安装成功且 relaunch 发出后再删除下载包,失败保留 latest 包便于手动安装 - macOS open 使用路径形式,避免 -a 传完整路径导致重启失败 - 明确覆盖「当前运行的 .app」(桌面 dev 包),避免误以为只更新了 Applications - Windows 同样先启动目标再删 SOURCE,防止重启失败时只剩旧包
69 lines
2.2 KiB
Go
69 lines
2.2 KiB
Go
package app
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestBuildMacScriptContainsHardeningGuards(t *testing.T) {
|
|
script := buildMacScript(
|
|
"/tmp/GoNavi-1.2.3-MacOS-Arm64.dmg",
|
|
"/Applications/GoNavi.app",
|
|
"/tmp/stage",
|
|
"/tmp/stage/mnt",
|
|
"/tmp/gonavi-update-macos.log",
|
|
4242,
|
|
)
|
|
|
|
mustContain := []string{
|
|
"MAX_WAIT_PID_SECONDS=120",
|
|
"hdiutil attach",
|
|
"prepare_app_source_from_package",
|
|
"resolve_app_binary_rel",
|
|
"replace_app_direct",
|
|
"run_admin_replace",
|
|
"relaunch_app",
|
|
`open -n "$TARGET_APP"`,
|
|
// 安装包扩展名分支
|
|
"dmg)",
|
|
"zip)",
|
|
// relaunch 成功后再删安装包,失败则保留
|
|
"package kept for manual install",
|
|
`/bin/rm -f "$PACKAGE"`,
|
|
}
|
|
for _, token := range mustContain {
|
|
if !strings.Contains(script, token) {
|
|
t.Fatalf("mac update script missing required token %q\nscript:\n%s", token, script)
|
|
}
|
|
}
|
|
if strings.Contains(script, `rm -rf "$MOUNT_DIR" "$DMG" "$STAGED"`) {
|
|
t.Fatal("mac update script must not delete STAGED while the script may still be running from it")
|
|
}
|
|
// 确保不会在 relaunch 之前无条件删除安装包
|
|
rmIdx := strings.Index(script, `/bin/rm -f "$PACKAGE"`)
|
|
relaunchIdx := strings.Index(script, "if ! relaunch_app; then")
|
|
if rmIdx < 0 || relaunchIdx < 0 || rmIdx < relaunchIdx {
|
|
t.Fatalf("package cleanup must happen only after relaunch attempt (rmIdx=%d relaunchIdx=%d)", rmIdx, relaunchIdx)
|
|
}
|
|
if !strings.Contains(script, "/tmp/GoNavi-1.2.3-MacOS-Arm64.dmg") {
|
|
t.Fatal("expected package path embedded in script")
|
|
}
|
|
if !strings.Contains(script, "/Applications/GoNavi.app") {
|
|
t.Fatal("expected target app path embedded in script")
|
|
}
|
|
if !strings.Contains(script, "PID=4242") {
|
|
t.Fatal("expected host pid embedded in script")
|
|
}
|
|
}
|
|
|
|
func TestResolveMacUpdateTargetFallsBackFromAppTranslocation(t *testing.T) {
|
|
got := resolveMacUpdateTarget("/private/var/folders/xx/AppTranslocation/ABC/d/GoNavi.app/Contents/MacOS/GoNavi")
|
|
if got != "/Applications/GoNavi.app" {
|
|
t.Fatalf("expected AppTranslocation fallback, got %q", got)
|
|
}
|
|
got = resolveMacUpdateTarget("/Applications/GoNavi.app/Contents/MacOS/GoNavi")
|
|
if got != "/Applications/GoNavi.app" {
|
|
t.Fatalf("expected normal app bundle path, got %q", got)
|
|
}
|
|
}
|