|
1 | | ---- @diagnostic disable: invisible, missing-fields, assign-type-mismatch, cast-local-type, param-type-mismatch |
| 1 | +--- @diagnostic disable: invisible, missing-fields, assign-type-mismatch, cast-local-type, param-type-mismatch, return-type-mismatch |
2 | 2 | local assert = require("tests.helpers.assert") |
3 | 3 | local spy = require("tests.helpers.spy") |
4 | 4 |
|
@@ -1757,4 +1757,74 @@ describe("agentic.SessionManager", function() |
1757 | 1757 | handlers.on_request_permission(mock_request, mock_callback) |
1758 | 1758 | end) |
1759 | 1759 | end) |
| 1760 | + |
| 1761 | + describe("reconnect", function() |
| 1762 | + --- @type TestStub |
| 1763 | + local notify_stub |
| 1764 | + |
| 1765 | + before_each(function() |
| 1766 | + notify_stub = spy.stub(Logger, "notify") |
| 1767 | + end) |
| 1768 | + |
| 1769 | + after_each(function() |
| 1770 | + notify_stub:revert() |
| 1771 | + end) |
| 1772 | + |
| 1773 | + --- @param overrides table |
| 1774 | + --- @return agentic.SessionManager session, table calls |
| 1775 | + local function make_session(overrides) |
| 1776 | + local calls = |
| 1777 | + { reconnected = false, loaded_with = nil, new = false } |
| 1778 | + local session = { |
| 1779 | + session_id = overrides.session_id, |
| 1780 | + is_generating = true, |
| 1781 | + status_animation = { stop = function() end }, |
| 1782 | + agent = { |
| 1783 | + reconnect = function() |
| 1784 | + calls.reconnected = true |
| 1785 | + end, |
| 1786 | + -- Fire the ready callback synchronously. |
| 1787 | + when_ready = function(_self, cb) |
| 1788 | + cb() |
| 1789 | + end, |
| 1790 | + agent_capabilities = overrides.caps, |
| 1791 | + }, |
| 1792 | + reconnect = SessionManager.reconnect, |
| 1793 | + load_acp_session = function(_self, id) |
| 1794 | + calls.loaded_with = id |
| 1795 | + end, |
| 1796 | + new_session = function() |
| 1797 | + calls.new = true |
| 1798 | + end, |
| 1799 | + } --[[@as agentic.SessionManager]] |
| 1800 | + return session, calls |
| 1801 | + end |
| 1802 | + |
| 1803 | + it("respawns the agent and reloads the current session", function() |
| 1804 | + local session, calls = make_session({ |
| 1805 | + session_id = "sess-1", |
| 1806 | + caps = { loadSession = true }, |
| 1807 | + }) |
| 1808 | + |
| 1809 | + session:reconnect() |
| 1810 | + |
| 1811 | + assert.is_true(calls.reconnected) |
| 1812 | + assert.is_false(session.is_generating) |
| 1813 | + assert.equal("sess-1", calls.loaded_with) |
| 1814 | + assert.is_false(calls.new) |
| 1815 | + end) |
| 1816 | + |
| 1817 | + it("starts a fresh session when there is none to reload", function() |
| 1818 | + local session, calls = make_session({ |
| 1819 | + session_id = nil, |
| 1820 | + caps = { loadSession = true }, |
| 1821 | + }) |
| 1822 | + |
| 1823 | + session:reconnect() |
| 1824 | + |
| 1825 | + assert.is_true(calls.reconnected) |
| 1826 | + assert.is_nil(calls.loaded_with) |
| 1827 | + assert.is_true(calls.new) |
| 1828 | + end) |
| 1829 | + end) |
1760 | 1830 | end) |
0 commit comments