Files
archie/internal/pairing/atomic_test.go
T
sam f73b2d1c8c feat: memory manager sync/prefetch/scan/shutdown + broad in-flight epic work
Checkpoint commit covering concurrent work across several archie-core-abg
epics to avoid losing in-progress state:

- Memory manager (18.7-18.16): background sync pipeline, prefetch with
  timeout, memory-write notification, threat scanning, shutdown drain
  with abandoned-write tracking, frozen snapshot pattern. Wired
  ScanContent and NotifyMemoryToolWrite into HandleToolCall so scanning
  and notification actually apply to writes, not just exist as unused
  primitives.
- Fixed a literal unresolved merge-conflict that had been committed to
  internal/memory/scrubber/scrubber.go.
- Tool provider/registry, MCP client/transport (stdio, HTTP, SSE),
  multimodal results, disclosure.
- Pairing device auth store, rate limiting.
- Gateway compression, session store, tasks.
- Various workflow, plugin host, and agentexec updates.
2026-07-27 03:34:46 +10:00

82 lines
1.9 KiB
Go

package pairing
import (
"os"
"path/filepath"
"testing"
)
func TestWriteFileAtomicCreatesFileWithContent(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "pending.json")
if err := writeFileAtomic(path, []byte(`{"a":1}`)); err != nil {
t.Fatal(err)
}
got, err := os.ReadFile(path)
if err != nil {
t.Fatal(err)
}
if string(got) != `{"a":1}` {
t.Errorf("content = %q", got)
}
}
func TestWriteFileAtomicSetsMode0600(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "approved.json")
if err := writeFileAtomic(path, []byte(`{}`)); err != nil {
t.Fatal(err)
}
info, err := os.Stat(path)
if err != nil {
t.Fatal(err)
}
if perm := info.Mode().Perm(); perm != 0o600 {
t.Errorf("mode = %o, want 0600", perm)
}
}
func TestWriteFileAtomicOverwritesExistingFile(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "rate_limits.json")
if err := writeFileAtomic(path, []byte(`{"v":1}`)); err != nil {
t.Fatal(err)
}
if err := writeFileAtomic(path, []byte(`{"v":2}`)); err != nil {
t.Fatal(err)
}
got, err := os.ReadFile(path)
if err != nil {
t.Fatal(err)
}
if string(got) != `{"v":2}` {
t.Errorf("content = %q, want the second write's content", got)
}
}
func TestWriteFileAtomicLeavesNoTempFileBehindOnSuccess(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "pending.json")
if err := writeFileAtomic(path, []byte(`{}`)); err != nil {
t.Fatal(err)
}
entries, err := os.ReadDir(dir)
if err != nil {
t.Fatal(err)
}
if len(entries) != 1 || entries[0].Name() != "pending.json" {
t.Errorf("dir contents = %v, want exactly [pending.json] (no leftover temp file)", entries)
}
}
func TestWriteFileAtomicFailsForNonexistentDir(t *testing.T) {
path := filepath.Join(t.TempDir(), "does-not-exist", "pending.json")
if err := writeFileAtomic(path, []byte(`{}`)); err == nil {
t.Fatal("expected an error writing into a nonexistent directory")
}
}