Brookline and Watertown last week became the first communities in the state to adopt a new building code discouraging the use of fossil fuels in new buildings, and 22 more cities and towns have signaled they intend to take similar action, in what climate advocates say is the first large-scale test of Massachusetts’ willingness to wean itself from gas and oil.