





















@@ -25,6 +25,7 @@ import {
2525createDefaultEmbeddedSession,
2626createContextEngineBootstrapAndAssemble,
2727createContextEngineAttemptRunner,
28+createSubscriptionMock,
2829expectCalledWithSessionKey,
2930getHoisted,
3031resetEmbeddedAttemptHarness,
@@ -1514,6 +1515,102 @@ describe("runEmbeddedAttempt context engine sessionKey forwarding", () => {
15141515expect(events.indexOf("bootstrap")).toBeLessThan(events.indexOf("lock"));
15151516});
151615171518+it("does not acquire the session write lock after aborting during prep", async () => {
1519+const abortController = new AbortController();
1520+hoisted.resolveBootstrapContextForRunMock.mockImplementation(async () => {
1521+abortController.abort();
1522+return { bootstrapFiles: [], contextFiles: [] };
1523+});
1524+1525+await expect(
1526+createContextEngineAttemptRunner({
1527+contextEngine: createContextEngineBootstrapAndAssemble(),
1528+ sessionKey,
1529+ tempPaths,
1530+attemptOverrides: { abortSignal: abortController.signal },
1531+}),
1532+).rejects.toMatchObject({ name: "AbortError" });
1533+1534+expect(hoisted.acquireSessionWriteLockMock).not.toHaveBeenCalled();
1535+});
1536+1537+it("disposes prep runtimes after aborting before the session write lock", async () => {
1538+const abortController = new AbortController();
1539+const lspDispose = vi.fn(async () => {});
1540+hoisted.createBundleLspToolRuntimeMock.mockImplementationOnce(async () => {
1541+abortController.abort();
1542+return {
1543+tools: [],
1544+dispose: lspDispose,
1545+};
1546+});
1547+1548+await expect(
1549+createContextEngineAttemptRunner({
1550+contextEngine: createContextEngineBootstrapAndAssemble(),
1551+ sessionKey,
1552+ tempPaths,
1553+attemptOverrides: {
1554+abortSignal: abortController.signal,
1555+disableTools: false,
1556+toolsAllow: ["*"],
1557+},
1558+}),
1559+).rejects.toMatchObject({ name: "AbortError" });
1560+1561+expect(hoisted.acquireSessionWriteLockMock).not.toHaveBeenCalled();
1562+expect(hoisted.createBundleLspToolRuntimeMock).toHaveBeenCalledTimes(1);
1563+expect(lspDispose).toHaveBeenCalledTimes(1);
1564+});
1565+1566+it("stops session setup when aborting after the session write lock", async () => {
1567+const abortController = new AbortController();
1568+const { bootstrap, assemble } = createContextEngineBootstrapAndAssemble();
1569+hoisted.sessionManagerOpenMock.mockImplementationOnce(() => {
1570+abortController.abort();
1571+return hoisted.sessionManager;
1572+});
1573+1574+await expect(
1575+createContextEngineAttemptRunner({
1576+contextEngine: createTestContextEngine({ bootstrap, assemble }),
1577+ sessionKey,
1578+ tempPaths,
1579+attemptOverrides: { abortSignal: abortController.signal },
1580+}),
1581+).rejects.toMatchObject({ name: "AbortError" });
1582+1583+expect(hoisted.acquireSessionWriteLockMock).toHaveBeenCalledTimes(1);
1584+expect(bootstrap).not.toHaveBeenCalled();
1585+expect(assemble).not.toHaveBeenCalled();
1586+expect(hoisted.createAgentSessionMock).not.toHaveBeenCalled();
1587+});
1588+1589+it("does not submit a prompt after aborting a created session", async () => {
1590+const abortController = new AbortController();
1591+const sessionPrompt = vi.fn(async () => {});
1592+hoisted.subscribeEmbeddedPiSessionMock.mockImplementationOnce(() => {
1593+abortController.abort();
1594+return createSubscriptionMock();
1595+});
1596+1597+await expect(
1598+createContextEngineAttemptRunner({
1599+contextEngine: createContextEngineBootstrapAndAssemble(),
1600+ sessionKey,
1601+ tempPaths,
1602+createSession: () =>
1603+createDefaultEmbeddedSession({
1604+initialMessages: [seedMessage],
1605+prompt: sessionPrompt,
1606+}),
1607+attemptOverrides: { abortSignal: abortController.signal },
1608+}),
1609+).rejects.toMatchObject({ name: "AbortError" });
1610+1611+expect(sessionPrompt).not.toHaveBeenCalled();
1612+});
1613+15171614it("forwards modelId to assemble", async () => {
15181615const { bootstrap, assemble } = createContextEngineBootstrapAndAssemble();
15191616const contextEngine = createTestContextEngine({ bootstrap, assemble });
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。