Is Capital Gains Tax Owed on Car Lease Trade-In?

I think it has been established if you buy a car and it has appreciated in value, when the car is sold or traded-in for a net profit, capital gains tax is owed. 

 

I think it has also been established if you lease a car, buy-out the car, and in-turn sell the car for a net profit (where sale > buyout), capital gains tax is also owed. 

 

So what happens when you trade-in a lease (car A) that has positive equity, as part of a deal to buy a different car (car B)? In other words, the dealer is willing to pay more than the buyout amount for the lease. Thus you have a net profit, that is subtracted from the cost of car B.

 

I could see one reasoning capital gains tax is owed on the net profit from the lease trade-in (where dealer buyout > lease buyout). Since technically the lease trade-in is a different transaction than the purchase of car B.

 

On the other hand, the customer (lessee) never owned the lease car A (i.e. did not hold title). The bank (lessor) owned the lease. Thus how could the lessee make a sale and profit from a car they never owned? Also overall, there was not a profit; actually a "loss" from the purchase of car B.

 

Finally, the basis tracking of car B starts to get ambiguous. I assume the basis of car B is not the actual total that they paid, but rather the amount before the net trade-in was deducted?