Elffuss BraidHub

kikocis/continue public

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