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>
170 lines
5.0 KiB
Go
170 lines
5.0 KiB
Go
package dolt
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestCommitExists tests the CommitExists method.
|
|
func TestCommitExists(t *testing.T) {
|
|
store, cleanup := setupTestStore(t)
|
|
defer cleanup()
|
|
|
|
ctx, cancel := testContext(t)
|
|
defer cancel()
|
|
|
|
// Get the current commit hash (should exist after store initialization)
|
|
currentCommit, err := store.GetCurrentCommit(ctx)
|
|
if err != nil {
|
|
t.Fatalf("failed to get current commit: %v", err)
|
|
}
|
|
|
|
t.Run("valid commit hash returns true", func(t *testing.T) {
|
|
exists, err := store.CommitExists(ctx, currentCommit)
|
|
if err != nil {
|
|
t.Fatalf("CommitExists failed: %v", err)
|
|
}
|
|
if !exists {
|
|
t.Errorf("expected commit %s to exist", currentCommit)
|
|
}
|
|
})
|
|
|
|
t.Run("short hash prefix returns true", func(t *testing.T) {
|
|
// Use first 8 characters as a short hash (like git's default short SHA)
|
|
if len(currentCommit) < 8 {
|
|
t.Skip("commit hash too short for prefix test")
|
|
}
|
|
shortHash := currentCommit[:8]
|
|
exists, err := store.CommitExists(ctx, shortHash)
|
|
if err != nil {
|
|
t.Fatalf("CommitExists failed: %v", err)
|
|
}
|
|
if !exists {
|
|
t.Errorf("expected short hash %s to match commit %s", shortHash, currentCommit)
|
|
}
|
|
})
|
|
|
|
t.Run("invalid nonexistent commit returns false", func(t *testing.T) {
|
|
exists, err := store.CommitExists(ctx, "0000000000000000000000000000000000000000")
|
|
if err != nil {
|
|
t.Fatalf("CommitExists failed: %v", err)
|
|
}
|
|
if exists {
|
|
t.Error("expected nonexistent commit to return false")
|
|
}
|
|
})
|
|
|
|
t.Run("empty string returns false", func(t *testing.T) {
|
|
exists, err := store.CommitExists(ctx, "")
|
|
if err != nil {
|
|
t.Fatalf("CommitExists failed: %v", err)
|
|
}
|
|
if exists {
|
|
t.Error("expected empty string to return false")
|
|
}
|
|
})
|
|
|
|
t.Run("malformed input returns false", func(t *testing.T) {
|
|
testCases := []string{
|
|
"invalid hash with spaces",
|
|
"hash'with'quotes",
|
|
"hash;injection",
|
|
"hash--comment",
|
|
}
|
|
for _, tc := range testCases {
|
|
exists, err := store.CommitExists(ctx, tc)
|
|
if err != nil {
|
|
t.Fatalf("CommitExists(%q) returned error: %v", tc, err)
|
|
}
|
|
if exists {
|
|
t.Errorf("expected malformed input %q to return false", tc)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
// TestCommitPending tests the batch commit mechanism.
|
|
func TestCommitPending(t *testing.T) {
|
|
store, cleanup := setupTestStore(t)
|
|
defer cleanup()
|
|
|
|
ctx, cancel := testContext(t)
|
|
defer cancel()
|
|
|
|
// Initial commit so the store has a clean HEAD
|
|
if err := store.Commit(ctx, "initial state"); err != nil {
|
|
t.Fatalf("initial commit failed: %v", err)
|
|
}
|
|
|
|
t.Run("returns false when nothing to commit", func(t *testing.T) {
|
|
committed, err := store.CommitPending(ctx, "test-actor")
|
|
if err != nil {
|
|
t.Fatalf("CommitPending failed: %v", err)
|
|
}
|
|
if committed {
|
|
t.Error("expected false when no changes pending")
|
|
}
|
|
})
|
|
|
|
t.Run("commits accumulated changes with summary", func(t *testing.T) {
|
|
headBefore, err := store.GetCurrentCommit(ctx)
|
|
if err != nil {
|
|
t.Fatalf("failed to get HEAD: %v", err)
|
|
}
|
|
|
|
// Insert directly via SQL to leave changes uncommitted in Dolt working set.
|
|
// (CreateIssue auto-commits via DOLT_COMMIT, so it can't be used here.)
|
|
_, err = store.db.ExecContext(ctx,
|
|
`INSERT INTO issues (id, title, description, design, acceptance_criteria, notes, status, priority, issue_type, created_at, updated_at)
|
|
VALUES ('batch-test-1', 'Batch test issue', '', '', '', '', 'open', 2, 'task', NOW(), NOW())`)
|
|
if err != nil {
|
|
t.Fatalf("raw INSERT failed: %v", err)
|
|
}
|
|
|
|
// Now commit pending changes
|
|
committed, err := store.CommitPending(ctx, "test-actor")
|
|
if err != nil {
|
|
t.Fatalf("CommitPending failed: %v", err)
|
|
}
|
|
if !committed {
|
|
t.Error("expected true when changes were pending")
|
|
}
|
|
|
|
headAfter, err := store.GetCurrentCommit(ctx)
|
|
if err != nil {
|
|
t.Fatalf("failed to get HEAD after commit: %v", err)
|
|
}
|
|
if headAfter == headBefore {
|
|
t.Error("expected HEAD to advance after CommitPending")
|
|
}
|
|
})
|
|
|
|
t.Run("generates descriptive message", func(t *testing.T) {
|
|
// Insert directly via SQL to leave changes uncommitted in Dolt working set.
|
|
// (CreateIssue auto-commits via DOLT_COMMIT, so it can't be used here.)
|
|
_, err := store.db.ExecContext(ctx,
|
|
`INSERT INTO issues (id, title, description, design, acceptance_criteria, notes, status, priority, issue_type, created_at, updated_at)
|
|
VALUES ('msg-test-1', 'Message test issue', '', '', '', '', 'open', 2, 'task', NOW(), NOW())`)
|
|
if err != nil {
|
|
t.Fatalf("raw INSERT failed: %v", err)
|
|
}
|
|
|
|
// Build the message (without committing)
|
|
msg := store.buildBatchCommitMessage(ctx, "test-actor")
|
|
if !strings.Contains(msg, "batch commit") {
|
|
t.Errorf("expected 'batch commit' in message, got: %q", msg)
|
|
}
|
|
if !strings.Contains(msg, "test-actor") {
|
|
t.Errorf("expected actor in message, got: %q", msg)
|
|
}
|
|
if !strings.Contains(msg, "created") {
|
|
t.Errorf("expected 'created' in message for new issues, got: %q", msg)
|
|
}
|
|
|
|
// Clean up — commit to clear working set
|
|
if err := store.Commit(ctx, "cleanup"); err != nil {
|
|
t.Fatalf("cleanup commit failed: %v", err)
|
|
}
|
|
})
|
|
}
|