"""Moving a session between a local and a remote location, through its route. This is the one scenario for the wiring the cheaper tests cannot reach: the `/sessions/{id}/workspace` route asks the live session actor, which checks the destination with `locations.workspace` and records its canonical spelling, and the session representation then shows the parsed location. The parsing, the refusals, and the recorded family intent under its validator are checked in apps/albedo/test/albedo/workspace/location_test.gleam and apps/albedo/test/albedo/session/workspace_move_test.gleam. """ import json import unittest import urllib.error from harness import Albedo HOST = "albedo-e2e-nowhere" class LocationsTest(unittest.TestCase): def setUp(self): self.app = Albedo().__enter__() self.addCleanup(self.app.__exit__, None, None, None) def api(self, path, body=None, **options): with self.app.api(path, body, **options) as response: return json.load(response) def move(self, session, workspace): snapshot = self.api(f"/sessions/{session}?tail=0") resource = snapshot["configuration_resource"] return self.api( f"/sessions/{session}/workspace", {"workspace": workspace, "family_revision": snapshot["family_revision"]}, method="POST", headers={"If-Match": resource["etag"]}, )["session"] def test_a_session_moves_to_a_remote_location_and_back(self): session = self.app.session() moved = self.move(session, f"{HOST}:/srv//app/") self.assertEqual(moved["workspace"], f"{HOST}:/srv/app") self.assertEqual(moved["location"]["host"], HOST) with self.assertRaises(urllib.error.HTTPError) as invalid: self.move(session, f"{HOST}:app") self.assertEqual(invalid.exception.code, 400) self.assertIn("must be absolute", json.load(invalid.exception)["detail"]) back = self.move(session, str(self.app.workspace)) self.assertEqual(back["workspace"], str(self.app.workspace)) self.assertIsNone(back["location"]["host"]) if __name__ == "__main__": unittest.main()