feat(agent): add crash logs and watchdog startup

- Recover panics to disk for diagnostics
- Add 5-minute watchdog task with startup
- Add -ensure flag to start detached agent
- Add script to pull remote folder via API
This commit is contained in:
2026-09-01 20:04:20 +03:00
parent 2ce438852a
commit 36cb847f9e
11 changed files with 458 additions and 8 deletions
+38
View File
@@ -0,0 +1,38 @@
package crashlog
import (
"os"
"path/filepath"
"strings"
"testing"
"tea.chunkbyte.com/kato/go-worm/lib/config"
)
func TestWrite(t *testing.T) {
base := t.TempDir()
t.Setenv("XDG_CONFIG_HOME", base)
t.Setenv("APPDATA", base)
if err := write("test", "boom", []byte("trace")); err != nil {
t.Fatal(err)
}
dir := filepath.Join(base, config.AppDataDir, config.LogsSubdir)
entries, err := os.ReadDir(dir)
if err != nil {
t.Fatal(err)
}
if len(entries) != 1 {
t.Fatalf("entries = %d, want 1", len(entries))
}
data, err := os.ReadFile(filepath.Join(dir, entries[0].Name()))
if err != nil {
t.Fatal(err)
}
text := string(data)
for _, part := range []string{"kind: test", "detail: boom", "trace", config.Version} {
if !strings.Contains(text, part) {
t.Fatalf("log missing %q: %s", part, text)
}
}
}