Files
Reims-Go/internal/archtest/file_replace_test.go
T
NwflowerandClaude Opus 5.5 965e03ca34 fix(macos): pass the runtime QMP socket to the suspend probe
Complete the merge with main so the suspend probe and the cold-start
probe resolve the same socket, and keep the architecture tests honest
after the atomicfile refactor moved the suspend commit's os.Rename into
the platform file-operation helpers.

- startprep: query the VM status through qmp.SocketPathForVM instead of
  the VM-directory socket, so long-path VMs stop failing the probe.
- qmp: drop the uncalled QueryStatusVM wrapper; QueryStatusAt is the one
  product entry, and its test now exercises it directly.
- archtest: list the two suspend_fileops files as the rename owners that
  suspend_transaction.go handed its os.Rename calls to.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-04 03:13:55 -07:00

60 lines
2.4 KiB
Go

package archtest
import (
"go/ast"
"testing"
)
// renameOwners move something atomicfile cannot write: a directory, an image or
// download too large for memory, a rotated log, the running executable, or
// several files that must change together.
var renameOwners = map[string]bool{
"internal/app/guesttools_flow.go": true, // file copied into the shared folder
"internal/app/ui_health.go": true, // log rotation
"internal/atomicfile/atomicfile.go": true,
"internal/fetch/fetch.go": true, // download
"internal/macos/installer/accelerated.go": true, // download
"internal/macos/installer/hfs_image.go": true, // disk image
"internal/macos/installer/oc_cache.go": true, // download
"internal/macos/installer/recovery.go": true, // download
"internal/macos/installguide/progress.go": true, // macOS may not import atomicfile, see macosHostImports
"internal/macos/reims/network_record.go": true, // same
"internal/macos/opencore/image.go": true, // disk image with rollback
"internal/macos/reims/disk_import.go": true, // disk image with rollback
"internal/macos/reims/suspend_fileops_other.go": true, // state and metadata commit together
"internal/macos/reims/suspend_fileops_windows.go": true, // state and metadata commit together
"internal/plugin/broker.go": true, // log rotation
"internal/plugin/pack.go": true, // archive
"internal/plugin/package.go": true, // plugin directory
"internal/runtime/runtime.go": true, // runtime directory
"internal/selfupdate/selfupdate.go": true, // running executable
}
func TestSmallFilesAreReplacedThroughAtomicfile(t *testing.T) {
seen := map[string]bool{}
for _, s := range sources(t) {
if s.isTest() {
continue
}
ast.Inspect(s.file, func(n ast.Node) bool {
sel, ok := n.(*ast.SelectorExpr)
if !ok || sel.Sel.Name != "Rename" {
return true
}
if pkg, ok := sel.X.(*ast.Ident); !ok || pkg.Name != "os" {
return true
}
seen[s.rel] = true
if !renameOwners[s.rel] {
t.Errorf("%s calls os.Rename: write small files with atomicfile.Write or atomicfile.WriteJSON", s.rel)
}
return true
})
}
for rel := range renameOwners {
if !seen[rel] {
t.Errorf("%s no longer calls os.Rename: remove it from renameOwners", rel)
}
}
}