@@ -50,6 +50,21 @@ describe("resolveSessionKeyFromResolveParams", () => {
|
50 | 50 | const legacyKey = "agent:main:legacy"; |
51 | 51 | const storePath = "/tmp/sessions.json"; |
52 | 52 | |
| 53 | +const expectResolveToCanonicalKey = async ( |
| 54 | +p: Parameters<typeof resolveSessionKeyFromResolveParams>[0]["p"], |
| 55 | +) => { |
| 56 | +await expect( |
| 57 | +resolveSessionKeyFromResolveParams({ |
| 58 | +cfg: {}, |
| 59 | + p, |
| 60 | +}), |
| 61 | +).resolves.toEqual({ |
| 62 | +ok: true, |
| 63 | +key: canonicalKey, |
| 64 | +}); |
| 65 | +expect(hoisted.listSessionsFromStoreMock).not.toHaveBeenCalled(); |
| 66 | +}; |
| 67 | + |
53 | 68 | beforeEach(() => { |
54 | 69 | hoisted.loadSessionStoreMock.mockReset(); |
55 | 70 | hoisted.updateSessionStoreMock.mockReset(); |
@@ -116,16 +131,7 @@ describe("resolveSessionKeyFromResolveParams", () => {
|
116 | 131 | } |
117 | 132 | hoisted.loadSessionStoreMock.mockReturnValue(store); |
118 | 133 | |
119 | | -await expect( |
120 | | -resolveSessionKeyFromResolveParams({ |
121 | | -cfg: {}, |
122 | | -p: { key: canonicalKey, spawnedBy: "controller-1" }, |
123 | | -}), |
124 | | -).resolves.toEqual({ |
125 | | -ok: true, |
126 | | -key: canonicalKey, |
127 | | -}); |
128 | | -expect(hoisted.listSessionsFromStoreMock).not.toHaveBeenCalled(); |
| 134 | +await expectResolveToCanonicalKey({ key: canonicalKey, spawnedBy: "controller-1" }); |
129 | 135 | }); |
130 | 136 | |
131 | 137 | it("re-checks migrated legacy keys through the same visibility filter", async () => { |
@@ -134,21 +140,12 @@ describe("resolveSessionKeyFromResolveParams", () => {
|
134 | 140 | } satisfies Record<string, SessionEntry>; |
135 | 141 | hoisted.loadSessionStoreMock.mockImplementation(() => store); |
136 | 142 | |
137 | | -await expect( |
138 | | -resolveSessionKeyFromResolveParams({ |
139 | | -cfg: {}, |
140 | | -p: { key: canonicalKey, spawnedBy: "controller-1" }, |
141 | | -}), |
142 | | -).resolves.toEqual({ |
143 | | -ok: true, |
144 | | -key: canonicalKey, |
145 | | -}); |
| 143 | +await expectResolveToCanonicalKey({ key: canonicalKey, spawnedBy: "controller-1" }); |
146 | 144 | |
147 | 145 | expect(hoisted.updateSessionStoreMock).toHaveBeenCalledTimes(1); |
148 | 146 | const updateSessionStoreCall = hoisted.updateSessionStoreMock.mock.calls[0]; |
149 | 147 | expect(updateSessionStoreCall?.[0]).toBe(storePath); |
150 | 148 | expect(typeof updateSessionStoreCall?.[1]).toBe("function"); |
151 | | -expect(hoisted.listSessionsFromStoreMock).not.toHaveBeenCalled(); |
152 | 149 | }); |
153 | 150 | |
154 | 151 | it("rejects sessions belonging to a deleted agent (key-based lookup)", async () => { |
|