refactor: clean up code

This commit is contained in:
tomasz-io 2024-11-05 10:45:30 +07:00
parent c3800fe137
commit 4482ca1ac0
3 changed files with 0 additions and 2118 deletions

View file

@ -1,30 +0,0 @@
import {
AutocompleteFileringTestInput,
testAutocompleteFiltering,
} from "./util";
import { TEST_CASES } from "./testCases";
const filterTestCases = (tests: AutocompleteFileringTestInput[]) => {
if (tests.some((test) => test.options?.only)) {
return tests.filter((test) => test.options?.only);
}
return tests;
};
describe("llms/Mock", () => {
describe("Autocomplete Filtering Tests", () => {
beforeEach(async () => {
await new Promise((resolve) => setTimeout(resolve, 50));
});
describe("Should return unmodified LLM output", () => {
it.each(filterTestCases(TEST_CASES))("$description", async (testCase) => {
await testAutocompleteFiltering(testCase);
});
});
// TODO: Add test cases where modifying LLM output is desirable
describe.skip("Should return modified LLM output", () => {});
});
});

File diff suppressed because it is too large Load diff

View file

@ -1,75 +0,0 @@
import fs from "node:fs";
import path from "node:path";
import Mock from "../../llm/llms/Mock";
import { testConfigHandler, testIde } from "../../test/util/fixtures";
import { CompletionProvider } from "../CompletionProvider";
import { AutocompleteInput } from "../util/types";
const FIM_DELIMITER = "<|fim|>";
function parseFimExample(text: string): { prefix: string; suffix: string } {
const [prefix, suffix] = text.split(FIM_DELIMITER);
return { prefix, suffix };
}
export interface AutocompleteFileringTestInput {
description: string;
filename: string;
input: string;
llmOutput: string;
expectedCompletion: string | null;
options?: {
only?: boolean;
};
}
export async function testAutocompleteFiltering(
test: AutocompleteFileringTestInput,
) {
const { prefix, suffix } = parseFimExample(test.input);
// Setup necessary objects
const llm = new Mock({
model: "mock",
});
llm.completion = test.llmOutput;
const ide = testIde;
const configHandler = testConfigHandler;
// Create a real file
const [workspaceDir] = await ide.getWorkspaceDirs();
const filepath = path.join(workspaceDir, test.filename);
fs.writeFileSync(filepath, test.input.replace(FIM_DELIMITER, ""));
// Prepare completion input and provider
const completionProvider = new CompletionProvider(
configHandler,
ide,
async () => llm,
() => {},
async () => [],
);
const line = prefix.split("\n").length - 1;
const character = prefix.split("\n")[line].length;
const autocompleteInput: AutocompleteInput = {
clipboardText: "",
completionId: "test-completion-id",
filepath,
pos: {
line,
character,
},
recentlyEditedFiles: [],
recentlyEditedRanges: [],
};
// Generate a completion
const result = await completionProvider.provideInlineCompletionItems(
autocompleteInput,
undefined,
);
// Ensure that we return the text that is wanted to be displayed
expect(result?.completion).toEqual(test.expectedCompletion);
}