The White House and the Department of Homeland Security were caught off guard by Friday’s defeat of a House bill to fund the agency for three weeks — and they spent several hours scrambling to figure out how to prevent a shutdown. Until late afternoon, it looked fairly clear that the House would pass a three-week continuing resolution,...