Files
Reims-Go/internal/archtest/macos_boundary_test.go
T
千川白浪 107a8d73e0 refactor: 收拢核心管线、强化错误处理、优化热路径与更新体积 (#200)
* refactor: 收拢核心管线、强化错误处理、优化热路径与更新体积

* fix: preserve download recovery and bound PBZX decoding

Keep VM diagnostics available during plugin initialization failures and verify settings through the unified driver lifecycle.
2026-12-05 20:54:41 +08:00

173 lines
5.7 KiB
Go

package archtest
import (
"sort"
"strings"
"testing"
)
// macosImporter is a package outside internal/macos that may still import
// macOS code: debt to pay down before macOS leaves this repository.
type macosImporter struct {
src, test bool // which of its files may import internal/macos
why string
}
// macosImporters is the ratchet. The test fails when a package not listed
// here starts importing internal/macos, and when a listed package (or its
// source or test files) stops, so the list can only shrink.
var macosImporters = map[string]macosImporter{
"internal/app": {test: true, why: "GUI composition root tests may exercise native macOS flows"},
"internal/datamigrate": {src: true, test: true, why: "data layout v3 invokes and verifies the macOS-owned state and ledger migration"},
"internal/plugin/builtin": {src: true, why: "host Guest Tools bridge still uses reims argument helpers; guest registration moved to internal/macos/guest"},
}
// macosSourceFiles is the file-scoped native macOS boundary. plugins_flow.go
// and cli/plugin.go are the composition files; every other entry is a native
// macOS page or flow mounted through that registration. New files may not be added.
var macosSourceFiles = map[string][]string{
"internal/app": {
"internal/app/create_flow.go",
"internal/app/extras_flow.go",
"internal/app/guesttools_flow.go",
"internal/app/install_flow.go",
"internal/app/install_guide.go",
"internal/app/installer_bindings.go",
"internal/app/installer_coordinator.go",
"internal/app/macos_client.go",
"internal/app/macos_detail.go",
"internal/app/macos_lifecycle_native.go",
"internal/app/macos_settings.go",
"internal/app/opencore_flow.go",
"internal/app/plugins_flow.go",
},
"internal/cli": {
"internal/cli/installer.go",
"internal/cli/macos_native.go",
"internal/cli/plugin.go",
},
}
func TestMacOSBoundary(t *testing.T) {
type use struct{ src, test []string }
found := map[string]*use{}
for _, s := range sources(t) {
if isMacOSDir(s.dir()) {
continue
}
for _, dir := range s.imports() {
if !isMacOSDir(dir) {
continue
}
u := found[s.dir()]
if u == nil {
u = &use{}
found[s.dir()] = u
}
if s.isTest() {
u.test = append(u.test, s.rel)
} else {
u.src = append(u.src, s.rel)
}
break
}
}
var problems []string
for dir, u := range found {
if files, scoped := macosSourceFiles[dir]; scoped {
allowed := make(map[string]bool, len(files))
for _, file := range files {
allowed[file] = true
}
for _, file := range u.src {
if !allowed[file] {
problems = append(problems, "host code imports internal/macos outside the native file list: "+file)
}
}
continue
}
allowed := macosImporters[dir]
if len(u.src) > 0 && !allowed.src {
problems = append(problems, "host code imports internal/macos (go through the driver layer or a host service instead): "+strings.Join(u.src, ", "))
}
if len(u.test) > 0 && !allowed.test {
problems = append(problems, "host tests import internal/macos: "+strings.Join(u.test, ", "))
}
}
for dir, files := range macosSourceFiles {
u := found[dir]
present := map[string]bool{}
if u != nil {
for _, file := range u.src {
present[file] = true
}
}
for _, file := range files {
if !present[file] {
problems = append(problems, file+" no longer imports internal/macos: remove it from macosSourceFiles")
}
}
}
for dir, allowed := range macosImporters {
u := found[dir]
if allowed.src && (u == nil || len(u.src) == 0) {
problems = append(problems, dir+" no longer imports internal/macos from source files: set src to false (or drop the entry) in macosImporters")
}
if allowed.test && (u == nil || len(u.test) == 0) {
problems = append(problems, dir+" no longer imports internal/macos from tests: set test to false (or drop the entry) in macosImporters")
}
}
sort.Strings(problems)
for _, p := range problems {
t.Error(p)
}
}
// macosHostImports is the reverse ratchet: dependencies of internal/macos on
// private host packages. External repositories cannot import these, so the
// list must shrink to zero before macOS becomes a separate Go module.
var macosHostImports = map[string]string{
"config": "configuration paths and persisted host settings",
"downloader": "pluggable download provider contract not yet moved to pkg",
"driver": "public driver contracts not yet moved to pkg",
"filelock": "shared host file locking",
"host": "host inspection and process services",
"i18n": "host localization and coded errors",
"netproxy": "host HTTP proxy resolution",
"plugin": "plugin manifests, hooks and ledger contracts",
"plugin/builtin": "built-in callback wiring during the transition",
"qmp": "host QMP helpers",
"runtime": "host runtime kinds and child process environment",
"version": "host application version",
"vmstart": "mixed host/macOS start preparation pending step 2",
}
func TestMacOSDoesNotGainPrivateHostDependencies(t *testing.T) {
found := map[string][]string{}
for _, s := range sources(t) {
if !isMacOSDir(s.dir()) {
continue
}
for _, dir := range s.imports() {
if name, ok := strings.CutPrefix(dir, "internal/"); ok && !isMacOSDir(dir) {
found[name] = append(found[name], s.rel)
}
}
}
for name, files := range found {
if _, ok := macosHostImports[name]; !ok {
t.Errorf("internal/macos gained private host dependency internal/%s (%v)", name, files)
}
}
for name := range macosHostImports {
if len(found[name]) == 0 {
t.Errorf("internal/macos no longer imports internal/%s; remove it from macosHostImports", name)
}
}
}
func isMacOSDir(dir string) bool {
return dir == "internal/macos" || strings.HasPrefix(dir, "internal/macos/")
}