mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
internal/vmlog owns every log a VM can drive but the proxy's own: Limit (moved from vmssh's logLimit, with Allow for the link session's warnings), Capped and Trim for ports.log and links.log while they run, and KeepVM, which the VM's proxy (proxy.IO.KeepLogs, Config.VMLogs from backend.Run.Logs) and a Lima build run on the serial consoles' and the hostagent's logs: redacted as they grow (redact.FileFrom), so a reboot in place can't leave the proxy password there, and rotated past 10 MiB, counting what a log holds past the hole its writer left (platform.DataStart). The proxy's http.Server logs through its own limited log, and its copied log counts what reached it as stderr; the build proxy's log is held as a VM's proxy's is. git-pins.jsonl has a cap. Run logs take at most 256 MiB together, never the newest or a live run's. Co-Authored-By: Claude Opus 5.5 <[email protected]>
44 lines
1.4 KiB
Go
44 lines
1.4 KiB
Go
package platform
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"testing"
|
|
)
|
|
|
|
// DataStart: 0 for a file without a hole; past a hole at a file's start,
|
|
// at most where its data starts (a file system that can't tell says 0);
|
|
// a file that's all hole, its length or 0.
|
|
func TestDataStart(t *testing.T) {
|
|
t.Parallel()
|
|
dir := t.TempDir()
|
|
open := func(name string, write func(f *os.File) error) *os.File {
|
|
t.Helper()
|
|
f, err := os.OpenFile(filepath.Join(dir, name), os.O_RDWR|os.O_CREATE, 0o600) //nolint:gosec // the test's own file
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(func() { _ = f.Close() })
|
|
if err := write(f); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return f
|
|
}
|
|
plain := open("plain.log", func(f *os.File) error { _, err := f.WriteString("boot\n"); return err })
|
|
if n := DataStart(plain); n != 0 {
|
|
t.Errorf("a file without a hole: %d", n)
|
|
}
|
|
const at = 4 << 20
|
|
holed := open("holed.log", func(f *os.File) error { _, err := f.WriteAt([]byte("later\n"), at); return err })
|
|
// macOS's and Linux's file systems that devvm's folders are on have
|
|
// holes, and say where data starts past one.
|
|
if n := DataStart(holed); n <= 0 && (runtime.GOOS == "darwin" || runtime.GOOS == "linux") || n < 0 || n > at {
|
|
t.Errorf("past a hole: %d", n)
|
|
}
|
|
empty := open("empty.log", func(f *os.File) error { return f.Truncate(at) })
|
|
if n := DataStart(empty); n != 0 && n != at {
|
|
t.Errorf("all hole: %d", n)
|
|
}
|
|
}
|