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.
82 lines
1.8 KiB
Go
82 lines
1.8 KiB
Go
package pairing
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestGenerateCodeLength(t *testing.T) {
|
|
code, err := GenerateCode()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(code) != CodeLength {
|
|
t.Errorf("len(code) = %d, want %d", len(code), CodeLength)
|
|
}
|
|
}
|
|
|
|
func TestGenerateCodeUsesOnlyAlphabetChars(t *testing.T) {
|
|
for range 200 {
|
|
code, err := GenerateCode()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, r := range code {
|
|
if !strings.ContainsRune(Alphabet, r) {
|
|
t.Fatalf("code %q contains character %q not in Alphabet %q", code, r, Alphabet)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestGenerateCodeExcludesAmbiguousChars(t *testing.T) {
|
|
// 0, O, 1, I must never appear -- they're visually confusable when a
|
|
// human reads a code aloud or types it from a screen.
|
|
ambiguous := "0O1I"
|
|
for _, r := range ambiguous {
|
|
if strings.ContainsRune(Alphabet, r) {
|
|
t.Fatalf("Alphabet %q contains ambiguous character %q", Alphabet, r)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAlphabetHas32UniqueChars(t *testing.T) {
|
|
if len(Alphabet) != 32 {
|
|
t.Fatalf("len(Alphabet) = %d, want 32", len(Alphabet))
|
|
}
|
|
seen := make(map[rune]bool, 32)
|
|
for _, r := range Alphabet {
|
|
if seen[r] {
|
|
t.Fatalf("Alphabet contains duplicate character %q", r)
|
|
}
|
|
seen[r] = true
|
|
}
|
|
}
|
|
|
|
func TestGenerateCodeIsRandom(t *testing.T) {
|
|
seen := make(map[string]bool)
|
|
for range 500 {
|
|
code, err := GenerateCode()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if seen[code] {
|
|
// Not impossible with 32^8 codes, but astronomically
|
|
// unlikely across 500 draws -- a collision here almost
|
|
// certainly means the generator isn't actually random.
|
|
t.Fatalf("code %q generated twice within 500 draws", code)
|
|
}
|
|
seen[code] = true
|
|
}
|
|
}
|
|
|
|
func TestGenerateCodeUppercaseOnly(t *testing.T) {
|
|
code, err := GenerateCode()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if code != strings.ToUpper(code) {
|
|
t.Errorf("code %q is not uppercase", code)
|
|
}
|
|
}
|