Philippine President Rodrigo Duterte enters his second year in office confronting the prospect of a terror contagion in southern Philippines. For more than a month, the Philippine military has struggled to wrest control of Marawi, the country's largest Muslim-majority city, from a legion of the Islamic State In Iraq and Syria (ISIS) affiliated fighters under the command of the Maute Group.

Intensive clashes have left much of the city in ruins, claiming about 400 lives including 50 civilians, with hundreds of thousands of residents now languishing in refugee camps. Other ISIS-affiliated groups such as the Bangsamoro Islamic Freedom Fighters (BIFF) have stepped up their operations in other corners of Mindanao, which has been placed under martial law.

Without a doubt, the spectre of an ISIS "wilayat", or governorate, in southern Philippines represents Mr Duterte's greatest political challenge so far. The tough-talking Filipino president, however, is also at the receiving end of military assistance from the United States and China.

Both superpowers are not only concerned about the prospect of ISIS terrorism, but also their bilateral strategic relations with the Duterte administration. Thus, the crisis in Mindanao is testing Mr Duterte's pursuit of an "independent" foreign policy away from traditional allies in favour of alternative poles of power.

Three weeks into the Battle of Marawi, as the Philippine military struggled with full-scale urban warfare against ISIS-affiliated fighters, Manila sought American military assistance. In response, the Pentagon deployed a Special Forces unit to provide training and technical assistance to their Filipino counterparts, who grappled with the militants' improvised explosive devices and snipers.

Washington dispatched drones to gather intelligence on the precise movement and location of enemy combatants. It also provided a new batch of weapons, namely machine guns, carbines, pistols and grenade launchers to the Philippine military, which deployed several battalions to Marawi.

Warming Philippine-China defence relations face major constraints down the road. Crucially, China is yet to sign a treaty alliance and/or a visiting forces agreement, which will allow it, as with the US, to enjoy extended and rotational access to Philippine bases.

The two allies also conducted joint patrols last week in the Sulu Sea, with the American littoral combat ship USS Coronado training side by side with the Philippines' flagship warship, the del Pilar class frigate BRP Ramon Alcaraz. The exercise was primarily targeted at other ISIS- affiliated groups, namely the notorious Abu Sayyaf group, which has engaged in widespread kidnap and ransom operations in the area for years.

As Washington expands its counter-terror cooperation with the Philippines, it is bound to seek greater access to military bases and military footprint on Philippine soil. Not to mention, this would solidify deep and enduring bonds with the Philippine military.

This, however, runs counter to Mr Duterte's pursuit of an "independent" foreign policy and warming relations with China, which has vociferously opposed large American military presence in the region. Throughout his first year in office, Mr Duterte visited 17 countries, including Russia, and twice in the case of China.

He is, however, yet to visit a single major Western destination, including Washington, which has traditionally been the first major destination of Filipino presidents.

Mr Duterte, who has often lashed out at Washington for alleged interference in Philippine domestic affairs, went so far as claiming that he "never approached any American" to seek their assistance in Mindanao.

He subsequently implied that the decision was made by the Philippine military without his prior approval, saying: "This is really their sentiment, our soldiers are really pro-American, that I cannot deny."

Under Mr Duterte's watch, members of the security establishment have gained greater voice in the government. Mr Duterte has appointed 59 former military and police officials to key positions, with as many as six former and current Armed Forces of the Philippines chiefs of staff serving (or set to serve) in Cabinet-level positions. Many of them have had historically warm ties with Washington, which has been a main source of weapons, training, equipment and high-grade intelligence to the Philippine security forces.

Eager to push back against the United States' growing military presence in Mindanao, Beijing offered an unprecedented package of counter-terror assistance, including US$16 million (S$22 million) in weapons and ammunition. The two sides are also negotiating joint exercises and intelligence-sharing agreements in an effort to upgrade their historically lukewarm, but at times hostile, military relations.

China also provided humanitarian assistance to affected communities. Mr Duterte has allocated US$400 million to the reconstruction of Marawi, with China expected to play a central role in infrastructure development in Mindanao, including in conflict-ridden areas.

Yet, warming Philippine-China defence relations face major constraints down the road. Crucially, China is yet to sign a treaty alliance and/or a visiting forces agreement, which will allow it, as with the US, to enjoy extended and rotational access to Philippine bases.

Beijing remains deeply unpopular among the Philippine public and the defence establishment, which continues to view China as a major threat in the South China Sea. China's expanding military footprint in disputed land features in the Spratlys will further undermine domestic support in the Philippines for warmer ties with the Asian powerhouse.

It is unlikely that the Philippine legislature, which has the power to ratify treaties, and the Supreme Court, which can review the constitutionality of security agreements, will approve of any significant upgrade in Philippine-China defence relations in the near future.

Despite Mr Duterte's best efforts to reorient his country's foreign policy, the Philippines has found itself largely relying on tried-and-tested allies once again.