This repository has been archived on 2026-11-17. You can view files and clone it, but cannot push or open issues or pull requests.
caelum0x 49b183818c Unify gitgram + aitimemachine into the monorepo (de-submodule) and merge vendored engines
Convert gitgram/ and aitimemachine/ from embedded git repos (which showed as
opaque submodule gitlinks on GitHub) into fully-tracked first-party content.

AITM now merges its 7 vendored repos as first-party engines:
- memory: beads (Go task DAG) + context7 (docs SDK), unified into saved_contexts
- git: vendored C git (bundled binary) + gitnexus (in-process code intelligence)
- agentic: a2a (@a2a-js/sdk) + pal (AITM-managed Python subprocess)

Includes the full session's product build: Gitgram web/mobile/backend features,
AITM website/CLI/MCP, the unified memory layer, engine build tooling
(scripts/build-engines.sh, Dockerfile, CI), docs (README, ENGINES.md, ARCHITECTURE.md),
and extensive test suites.

Build artifacts, node_modules, external/, and gemini-cli are gitignored.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-23 14:14:09 +03:00

121 lines
3.3 KiB
Go

//go:build cgo
package embeddeddolt
import (
"os"
"path/filepath"
"testing"
"time"
)
func TestCleanGitRemoteCacheGarbage(t *testing.T) {
// Reset the throttle so the test always runs the cleanup.
cacheCleanupThrottle.mu.Lock()
cacheCleanupThrottle.lastRun = time.Time{}
cacheCleanupThrottle.mu.Unlock()
tmpDir := t.TempDir()
packDir := filepath.Join(tmpDir, "testdb", ".dolt", "git-remote-cache", "abc123", "repo.git", "objects", "pack")
if err := os.MkdirAll(packDir, 0755); err != nil {
t.Fatal(err)
}
staleFile := filepath.Join(packDir, "tmp_pack_STALE1")
if err := os.WriteFile(staleFile, []byte("stale data"), 0444); err != nil {
t.Fatal(err)
}
// Backdate the file well past the min age.
old := time.Now().Add(-1 * time.Hour)
if err := os.Chtimes(staleFile, old, old); err != nil {
t.Fatal(err)
}
staleIdx := filepath.Join(packDir, "tmp_idx_STALE2")
if err := os.WriteFile(staleIdx, []byte("stale idx"), 0444); err != nil {
t.Fatal(err)
}
if err := os.Chtimes(staleIdx, old, old); err != nil {
t.Fatal(err)
}
recentFile := filepath.Join(packDir, "tmp_pack_RECENT")
if err := os.WriteFile(recentFile, []byte("in progress"), 0444); err != nil {
t.Fatal(err)
}
finalPack := filepath.Join(packDir, "pack-abc123.pack")
if err := os.WriteFile(finalPack, []byte("real pack"), 0444); err != nil {
t.Fatal(err)
}
if err := os.Chtimes(finalPack, old, old); err != nil {
t.Fatal(err)
}
s := &EmbeddedDoltStore{
dataDir: tmpDir,
database: "testdb",
}
s.cleanGitRemoteCacheGarbage()
if _, err := os.Stat(staleFile); !os.IsNotExist(err) {
t.Errorf("stale tmp_pack file should have been deleted, but still exists")
}
if _, err := os.Stat(staleIdx); !os.IsNotExist(err) {
t.Errorf("stale tmp_idx file should have been deleted, but still exists")
}
if _, err := os.Stat(recentFile); err != nil {
t.Errorf("recent tmp_pack file should NOT have been deleted: %v", err)
}
if _, err := os.Stat(finalPack); err != nil {
t.Errorf("finalized pack file should NOT have been deleted: %v", err)
}
}
func TestCleanGitRemoteCacheGarbage_Throttled(t *testing.T) {
// Reset then immediately mark as just-run.
cacheCleanupThrottle.mu.Lock()
cacheCleanupThrottle.lastRun = time.Now()
cacheCleanupThrottle.mu.Unlock()
tmpDir := t.TempDir()
packDir := filepath.Join(tmpDir, "testdb", ".dolt", "git-remote-cache", "abc123", "repo.git", "objects", "pack")
if err := os.MkdirAll(packDir, 0755); err != nil {
t.Fatal(err)
}
staleFile := filepath.Join(packDir, "tmp_pack_STALE1")
if err := os.WriteFile(staleFile, []byte("stale"), 0444); err != nil {
t.Fatal(err)
}
old := time.Now().Add(-1 * time.Hour)
if err := os.Chtimes(staleFile, old, old); err != nil {
t.Fatal(err)
}
s := &EmbeddedDoltStore{
dataDir: tmpDir,
database: "testdb",
}
s.cleanGitRemoteCacheGarbage()
if _, err := os.Stat(staleFile); os.IsNotExist(err) {
t.Errorf("throttled cleanup should NOT have deleted the file, but it was deleted")
}
}
func TestCleanGitRemoteCacheGarbage_NoCacheDir(t *testing.T) {
// Reset throttle.
cacheCleanupThrottle.mu.Lock()
cacheCleanupThrottle.lastRun = time.Time{}
cacheCleanupThrottle.mu.Unlock()
tmpDir := t.TempDir()
s := &EmbeddedDoltStore{
dataDir: tmpDir,
database: "testdb",
}
// Should not panic when the cache directory doesn't exist.
s.cleanGitRemoteCacheGarbage()
}