With question swirling about the durability of California’s long-running economic expansion, state finances got surprisingly kind words from three major credit-rating agencies.

I often hear critics of California’s government claim the state is ill-prepared to pay its long-term bills, most notably retirement benefits promised to its workers. And in the short run, state coffers are especially vulnerable to swings in the broad economy as government revenues are deeply tied to unpredictable income-tax collections.

Yet so far in this economic cycle, such risks have yet to spook the Wall Street shops that review municipal finances.

Yes, the three major credit agencies gave 40-plus states higher ratings. But these agencies also gave California their fourth-highest grade for creditworthiness, a level described as “high quality and subject to very low credit risk.”

Let’s start with Moody’s Investors Service, which took the boldest action of late.

Moody’s has rated the state “Aa3” since June 2014, a steady improvement from a recessionary low of “Baa1” — four notches lower. And Moody’s recently upped its outlook for state finances to “positive” from “stable,” a hint that an official rating upgrade could happen in the next two years.

Moody’s noted “the state’s improved financial position against its exposure to a highly volatile revenue structure. Long-term liability and fixed-cost burdens are slightly higher than state medians.”

S&P Global has seen California as an “AA-minus” risk since July 2015 after scoring the state at various levels of riskier “A” grade the previous 11 years.

In a recent “stress test” of state finances in worst-case scenarios, S&P analysts found the state’s rainy-day fund — reserves for tough times boosted in size at Gov. Jerry Brown’s insistence — could provide somewhat adequate protection.

The state’s volatile revenue streams — heavily tied to how well the state’s wealthiest residents fared financially — combined with numerous spending and savings mandates make budget management tricky in an economic downturn.

“A recession would strain the state’s finances, but its efforts in recent years at shoring up its finances have paid off,” S&P wrote. “California’s budget reserves, while now at record balances, may also be at something of the minimum necessary for it to withstand a recession.”

When Fitch Ratings recently graded the state for a major bond offering, it noted similar fiscal improvements as its peers did. Fitch has scored the state as “AA-minus” — its fourth-highest grade — since August 2016, up from “BBB” — five grades lower — mid-recession.

But Fitch analysts added a caveat, a nudge to Governor-elect Gavin Newsom for his dealings with budgetary issues and a legislature dominated by fellow Democrats: “The rating is sensitive to the state’s ability and willingness, both within the legislative and executive branches, to maintain fiscal discipline throughout the economic cycle.”

These upbeat reviews of California’s creditworthiness are both a blessing and a curse for Newsom.

The good news is that Newsom won’t immediately have to deal with tough, politically challenging budget realignments like Brown did. When Brown returned to the governorship for his second tour of duty in 2011, state finances were in shambles as the Great Recession was ending.

An eight-year economic recovery — and some budgetary process improvements — helped to right the state’s fiscal ship.

“Compared with most states, California has assembled one of the strongest fiscal recoveries of the post-recession period,” S&P wrote.

Amid the Great Recession’s economic chaos, the state ran multibillion-dollar deficits. Last year, in far better times, the state ran an $8 billion surplus. But numerous forecasts show slowing growth for California’s business climate.

Newsom got elected Nov. 6 with the state’s creditworthiness is at its highest since the start of the century. The monetary management bar is high.