Fun fact: you won't see anybody signing that treaty as "king (or queen) of Spain" -- because "Spain" didn't exist as a polity back then, and wouldn't for a couple more centuries.
And as a geographic concept, Portugal was as much "Spain" as Castille, Leon, Aragon, Granada...
So, no, actually "Spain" and Portugal did not really agree to anything.