diff --git a/core/diff/streamDiff.test.ts b/core/diff/streamDiff.test.ts index de6bd06a4..94933623c 100644 --- a/core/diff/streamDiff.test.ts +++ b/core/diff/streamDiff.test.ts @@ -51,7 +51,7 @@ function getMyersDiffType(diff: any): MyersDiffTypes | undefined { function displayDiff(diff: DiffLine[]) { const symbol = { - same: " ", + same: "", new: "+", old: "-", }; @@ -69,7 +69,7 @@ async function expectDiff(file: string) { const testFileContents = fs.readFileSync(testFilePath, "utf-8"); const [oldText, newText, expectedDiff] = testFileContents .split("\n---\n") - .map((s) => s.trim()); + .map((s) => s.replace(/^\n+/, "").trimEnd()); const oldLines = oldText.split("\n"); const newLines = newText.split("\n"); const { streamDiffs, myersDiffs } = await collectDiffs(oldLines, newLines); @@ -236,4 +236,8 @@ describe("streamDiff(", () => { test("FastAPI comments", async () => { await expectDiff("add-comments"); }); + + test.skip("Mock LLM example", async () => { + await expectDiff("mock-llm"); + }); }); diff --git a/core/diff/test-examples/add-comments.diff b/core/diff/test-examples/add-comments.diff index c29c0c5cd..8cc084dce 100644 --- a/core/diff/test-examples/add-comments.diff +++ b/core/diff/test-examples/add-comments.diff @@ -33,21 +33,21 @@ def read_landing_page(): --- + # Import the FastAPI class from the fastapi module - from fastapi import FastAPI - + from fastapi import FastAPI + + # Create an instance of the FastAPI application - app = FastAPI() - + app = FastAPI() + + # Define a route for the root endpoint ("/") - @app.get("/") - def read_root(): + @app.get("/") + def read_root(): + # Return a simple JSON response + return {"Hello": "World"} // This is an example comment + + # Define a route for the landing page endpoint ("/landing") - return {"Hello": "World"} - - @app.get("/landing") - def read_landing_page(): + @app.get("/landing") + def read_landing_page(): + # Return a JSON response with a welcome message - return {"message": "Welcome to the landing page"} \ No newline at end of file + return {"message": "Welcome to the landing page"} \ No newline at end of file diff --git a/core/diff/test-examples/fastapi-tabs-vs-spaces.diff b/core/diff/test-examples/fastapi-tabs-vs-spaces.diff index 84bea74c7..37df56673 100644 --- a/core/diff/test-examples/fastapi-tabs-vs-spaces.diff +++ b/core/diff/test-examples/fastapi-tabs-vs-spaces.diff @@ -28,19 +28,15 @@ def read_landing_page(): - from fastapi import FastAPI + from fastapi import FastAPI, HTTPException - - app = FastAPI() - - @app.get("/") - def read_root(): + + app = FastAPI() + + @app.get("/") + def read_root(): - \treturn {"Hello": "World"} + return {"Hello": "World"} - - @app.get("/landing") - def read_landing_page(): + + @app.get("/landing") + def read_landing_page(): + raise HTTPException(status_code=404, detail="Page not found") -- \treturn {"message": "Welcome to the landing page"} - ---- - -Make sure we correctly ignore tabs-vs-spaces changes \ No newline at end of file +- \treturn {"message": "Welcome to the landing page"} \ No newline at end of file diff --git a/core/diff/test-examples/fastapi.diff b/core/diff/test-examples/fastapi.diff index 9c3b6d1f7..0c8a0ba76 100644 --- a/core/diff/test-examples/fastapi.diff +++ b/core/diff/test-examples/fastapi.diff @@ -28,14 +28,14 @@ def read_landing_page(): - from fastapi import FastAPI + from fastapi import FastAPI, HTTPException - - app = FastAPI() - - @app.get("/") - def read_root(): - return {"Hello": "World"} - - @app.get("/landing") - def read_landing_page(): + + app = FastAPI() + + @app.get("/") + def read_root(): + return {"Hello": "World"} + + @app.get("/landing") + def read_landing_page(): + raise HTTPException(status_code=404, detail="Page not found") - return {"message": "Welcome to the landing page"} \ No newline at end of file diff --git a/core/diff/test-examples/mock-llm.diff b/core/diff/test-examples/mock-llm.diff new file mode 100644 index 000000000..2bf49c698 --- /dev/null +++ b/core/diff/test-examples/mock-llm.diff @@ -0,0 +1,103 @@ +import { ChatMessage, CompletionOptions, ModelProvider } from "../../index.js"; +import { BaseLLM } from "../index.js"; + +class Mock extends BaseLLM { + static Completion = "Test Completion"; + static providerName: ModelProvider = "mock"; + + protected async *_streamComplete( + prompt: string, + options: CompletionOptions, + ): AsyncGenerator { + yield Mock.Completion; + } + + protected async *_streamChat( + messages: ChatMessage[], + options: CompletionOptions, + ): AsyncGenerator { + yield { + role: "assistant", + content: Mock.Completion, + }; + } +} + +export default Mock; + +--- + +import { ChatMessage, CompletionOptions, ModelProvider } from "../../index.js"; +import { BaseLLM } from "../index.js"; + +class Mock extends BaseLLM { + private static _completion: string = "Test Completion"; + static providerName: ModelProvider = "mock"; + + static get completion(): string { + return Mock._completion; + } + + static set completion(value: string) { + Mock._completion = value; + } + + protected async *_streamComplete( + prompt: string, + options: CompletionOptions, + ): AsyncGenerator { + yield Mock.completion; + } + + protected async *_streamChat( + messages: ChatMessage[], + options: CompletionOptions, + ): AsyncGenerator { + yield { + role: "assistant", + content: Mock.completion, + }; + } +} + +export default Mock; + +--- + + import { ChatMessage, CompletionOptions, ModelProvider } from "../../index.js"; + import { BaseLLM } from "../index.js"; + + class Mock extends BaseLLM { +- static Completion = "Test Completion"; ++ private static _completion: string = "Test Completion"; + static providerName: ModelProvider = "mock"; + ++ static get completion(): string { ++ return Mock._completion; ++ } ++ ++ static set completion(value: string) { ++ Mock._completion = value; ++ } ++ + protected async *_streamComplete( + prompt: string, + options: CompletionOptions, + ): AsyncGenerator { +- yield Mock.Completion; ++ yield Mock.completion; + } + + protected async *_streamChat( + messages: ChatMessage[], + options: CompletionOptions, + ): AsyncGenerator { + yield { + role: "assistant", +- content: Mock.Completion, ++ content: Mock.completion, + }; + } + } + + export default Mock; \ No newline at end of file