Elffuss BraidHub

kikocis/continue public

main · 4.0 KiBRawPermalink
1import * as fs from "fs/promises";
2
3import { expect } from "chai";
4import { EditorView, TextEditor } from "vscode-extension-tester";
5
6import { GlobalActions } from "../actions/Global.actions";
7import { NextEditActions } from "../actions/NextEdit.actions";
8import { DEFAULT_TIMEOUT } from "../constants";
9import { TestUtils } from "../TestUtils";
10
11describe("Next Edit", () => {
12 let editor: TextEditor;
13
14 before(async function () {
15 // this.timeout(DEFAULT_TIMEOUT.XL);
16
17 const globalContextPath = TestUtils.getGlobalContextFilePath();
18
19 // Update config.json to add optInNextEditFeature.
20 // globalContext.json does not exist in CI before this test runs.
21 if (await TestUtils.fileExists(globalContextPath)) {
22 const globalContext = await fs.readFile(globalContextPath, "utf8");
23 const sharedConfig = JSON.parse(globalContext).sharedConfig;
24
25 const sharedConfigWithNextEditEnabled = {
26 ...sharedConfig,
27 optInNextEditFeature: true,
28 };
29
30 const globalContextWithNextEditEnabled = {
31 ...JSON.parse(globalContext),
32 sharedConfig: sharedConfigWithNextEditEnabled,
33 };
34
35 await fs.writeFile(
36 globalContextPath,
37 JSON.stringify(globalContextWithNextEditEnabled, null, 2),
38 "utf8",
39 );
40 } else {
41 await fs.writeFile(
42 globalContextPath,
43 JSON.stringify(
44 {
45 sharedConfig: {
46 optInNextEditFeature: true,
47 },
48 selectedModelsByProfileId: {
49 local: {
50 chat: "TEST LLM",
51 edit: "TEST LLM",
52 apply: "TEST LLM",
53 embed: "Transformers.js (Built-In)",
54 autocomplete: "TEST LLM",
55 rerank: null,
56 summarize: null,
57 },
58 },
59 },
60 null,
61 2,
62 ),
63 );
64 }
65
66 await NextEditActions.reload();
67 }).timeout(DEFAULT_TIMEOUT.XL);
68
69 beforeEach(async function () {
70 // this.timeout(DEFAULT_TIMEOUT.XL);
71
72 await GlobalActions.openTestWorkspace();
73 ({ editor } = await GlobalActions.createAndOpenNewTextFile());
74 }).timeout(DEFAULT_TIMEOUT.XL);
75
76 afterEach(async function () {
77 // this.timeout(DEFAULT_TIMEOUT.XL);
78
79 await editor.clearText();
80 await new EditorView().closeAllEditors();
81 }).timeout(DEFAULT_TIMEOUT.XL);
82
83 after(async function () {
84 // this.timeout(DEFAULT_TIMEOUT.XL);
85
86 // Update config.json to delete optInNextEditFeature.
87 const globalContext = await fs.readFile(
88 TestUtils.getGlobalContextFilePath(),
89 "utf8",
90 );
91 const sharedConfig = JSON.parse(globalContext).sharedConfig;
92
93 const sharedConfigWithoutNextEdit = { ...sharedConfig };
94 delete sharedConfigWithoutNextEdit.optInNextEditFeature;
95
96 const globalContextWithNextEditEnabled = {
97 ...JSON.parse(globalContext),
98 sharedConfig: sharedConfigWithoutNextEdit,
99 };
100
101 await fs.writeFile(
102 TestUtils.getGlobalContextFilePath(),
103 JSON.stringify(globalContextWithNextEditEnabled, null, 2),
104 "utf8",
105 );
106 await NextEditActions.reload();
107 }).timeout(DEFAULT_TIMEOUT.XL);
108
109 // it("Should enable Next Edit feature in settings", async () => {
110 // expect(false).to.be.true;
111 // }).timeout(DEFAULT_TIMEOUT.XL);
112
113 // it("Should check that autocomplete is disabled when next edit is enabled", async () => {
114 // expect(false).to.be.true;
115 // }).timeout(DEFAULT_TIMEOUT.XL);
116
117 it("Should force a Next Edit", async () => {
118 const hasDecoration = await NextEditActions.forceNextEdit(editor);
119 expect(hasDecoration).to.be.true;
120 }).timeout(DEFAULT_TIMEOUT.XXL);
121
122 it("Should accept Next Edit suggestion with Tab", async () => {
123 const accepted = await NextEditActions.acceptNextEditSuggestion(editor);
124 expect(accepted).to.be.true;
125 }).timeout(DEFAULT_TIMEOUT.XXL);
126
127 it("Should reject Next Edit suggestion with Esc", async () => {
128 const rejected = await NextEditActions.rejectNextEditSuggestion(editor);
129 expect(rejected).to.be.true;
130 }).timeout(DEFAULT_TIMEOUT.XXL);
131});