Chinese era ended in the 15thC
From then til 1778, you had rival powers in the Trinh Lords in the North, and Nguyen Lords in the South(Todays Central Vietnam), and in the far South, what was left of the shattered Cham Kingdoms and the Khmer to the SW.
This was the main 'Civil War' era in the 17thC
After that, the South expanded into Cambodian territory along the Mekong River and took over the Cham.
The South then had a peasant uprising, and the Northern Trinh took advantage becoming allied, eliminating the Nguyen's from power. Most of the Nguyen Family were executed, but not all.
Enter France, and Siam, new allies for Nguyen Ahn.
Meanwhile, the Trinh Lords were having problems with their allies of convenience, the Tay Son, and lost to them.
Nguyen Ahn with his new backers, was able to win over the Tay Son, and unify the Country, and had Laos and Cambodia as tributaries, and indecisive wars with Siam.
A succession crisis let the French take control in the 1880s.
Roughly 80 years of unified country before screwed by the French
Nope the Cham were mainly located in Central Vietnam( I know that you're referingo he Cham remants, but to us Vietnamese, the far south is the Mekong Delta). By 1778, the Nguyễn has seized control over the entirety of the Western Mekong Delta (Known to the Khmer as Khmer Krom). Secondly, the Last Cham city state was annihilated by Minh Mang (Second Emperor of Vietnam) in 1832. Thirdly, there are no mention that the Tay Son and Trinh were allied with each other:
(Extract from Vietnamese Wikipedia)
Since the fighting in 1672 , the Trinh and Nguyen lords ended the conflict, taking the Gianh river as the boundary to divide Dai Viet into Dang Trong and Dang Ngoai .
One hundred years later, the Tay Son brothers led by Nguyen Nhac rebelled against the Nguyen family. Realizing that the internal situation in Dang Trong was a male opportunity to destroy the Nguyen family, in 1774, Trinh Sam in Dang Ngoai decided to send a large army to the south. In early 1775, Trinh army invaded Phu Xuan , Lord Nguyen Phuc Thuan fled to the south. The leader of Tay Son Nguyen Nhac also sent troops from Quy Nhon to attack Quang Nam . The two sides clashed at the battle of Cam Sa , the Trinh army prevailed. Nguyen Nhac surrendered and asked fight the Nguyen.
His yeld accepted by Lord Trinh, Nguyen Nhac gathered forces to defeat Lord Nguyen, occupying the entire territory from Quang Nam to the end of the South. In 1778 , after killing two Nguyen Lords, Nguyen Nhac claiming to be king, take the name Thai Duc. Trinh Sam knew about it but did not ask. In 1782, Trinh Sam died and his two sons, Trinh Khai and Trinh Can, competed as lords. Trinh Khai killed Trinh Can's aide Hoang Dinh Bao (young), took the throne. The servant of Dinh Bao, Nguyen Huu Chinh, fled to the south to surrender to Tay Son.
In 1785, the Tây Sơn army defeated the Siamese army invoked by Nguyễn Anh at the Battle of Rạch Gầm-Xoài Mút . Nguyen Anh had to flee exile to Siam. Nguyen Nhac owned the entire southern central and southern regions, beginning prepare for an invasion of the north.
This seems like just a truce more than an alliance.
vi.wikipedia.org