package browse import ( "context" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) // TestLogFromHashGarbage covers the MCP get_commit_log case: a caller-supplied // cursor that does not even parse as a dolt hash must be an ordinary "not // found" (errors.Is(err, ErrRefNotFound)), not an opaque internal error. func TestLogFromHashGarbage(t *testing.T) { db := openFixture(t) ctx := context.Background() _, _, err := db.Log(ctx, "main", "not-a-hash", 10) require.Error(t, err) assert.ErrorIs(t, err, ErrRefNotFound) } // TestLogFromHashWellFormedButUnknown covers a fromHash that parses fine but // names no commit this store has: same classification as a garbage string. func TestLogFromHashWellFormedButUnknown(t *testing.T) { db := openFixture(t) ctx := context.Background() // 32 'a' characters is a syntactically valid (but non-existent) dolt hash. _, _, err := db.Log(ctx, "main", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 10) require.Error(t, err) assert.ErrorIs(t, err, ErrRefNotFound) } // TestLogFromHashValid confirms the happy path is untouched: a real hash // still starts the walk there and pages as before. func TestLogFromHashValid(t *testing.T) { db := openFixture(t) ctx := context.Background() commits, next, err := db.Log(ctx, "main", commitHash(t, msgInsert), 100) require.NoError(t, err) assert.Empty(t, next) want := []string{msgInsert, msgAddUser, msgInitial} require.Len(t, commits, len(want)) for i, w := range want { assert.Equal(t, w, commits[i].Message) } } // TestLogFromHashEmpty confirms "" still means "start from ref's head". func TestLogFromHashEmpty(t *testing.T) { db := openFixture(t) ctx := context.Background() commits, _, err := db.Log(ctx, "main", "", 100) require.NoError(t, err) require.NotEmpty(t, commits) assert.Equal(t, msgAddItem, commits[0].Message) }