Elffuss BraidHub

kikocis/continue public

9df136a0123e · 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(globalContextPath, JSON.stringify(globalContextWithNextEditEnabled, null, 2), "utf8");
35 } else {
36 await fs.writeFile(
37 globalContextPath,
38 JSON.stringify(
39 {
40 sharedConfig: {
41 optInNextEditFeature: true
42 },
43 selectedModelsByProfileId: {
44 local: {
45 chat: "TEST LLM",
46 edit: "TEST LLM",
47 apply: "TEST LLM",
48 embed: "Transformers.js (Built-In)",
49 autocomplete: "TEST LLM",
50 rerank: null,
51 summarize: null
52 }
53 }
54 },
55 null,
56 2,
57 ),
58 );
59 }
60
61 await NextEditActions.reload();
62 }).timeout(DEFAULT_TIMEOUT.XL);
63
64 beforeEach(async function () {
65 // this.timeout(DEFAULT_TIMEOUT.XL);
66
67 await GlobalActions.openTestWorkspace();
68 ({ editor } = await GlobalActions.createAndOpenNewTextFile());
69 }).timeout(DEFAULT_TIMEOUT.XL);
70
71 afterEach(async function () {
72 // this.timeout(DEFAULT_TIMEOUT.XL);
73
74 await editor.clearText();
75 await new EditorView().closeAllEditors();
76 }).timeout(DEFAULT_TIMEOUT.XL);
77
78 after(async function () {
79 // this.timeout(DEFAULT_TIMEOUT.XL);
80
81 // Update config.json to delete optInNextEditFeature.
82 const globalContext = await fs.readFile(TestUtils.getGlobalContextFilePath(), "utf8");
83 const sharedConfig = JSON.parse(globalContext).sharedConfig;
84
85 const sharedConfigWithoutNextEdit = { ...sharedConfig };
86 delete sharedConfigWithoutNextEdit.optInNextEditFeature;
87
88 const globalContextWithNextEditEnabled = {
89 ...JSON.parse(globalContext),
90 "sharedConfig": sharedConfigWithoutNextEdit
91 };
92
93 await fs.writeFile(TestUtils.getGlobalContextFilePath(), JSON.stringify(globalContextWithNextEditEnabled, null, 2), "utf8");
94 await NextEditActions.reload();
95 }).timeout(DEFAULT_TIMEOUT.XL);
96
97 // it("Should enable Next Edit feature in settings", async () => {
98 // expect(false).to.be.true;
99 // }).timeout(DEFAULT_TIMEOUT.XL);
100
101 // it("Should check that autocomplete is disabled when next edit is enabled", async () => {
102 // expect(false).to.be.true;
103 // }).timeout(DEFAULT_TIMEOUT.XL);
104
105 it("Should force a Next Edit", async () => {
106 const hasDecoration = await NextEditActions.forceNextEdit(editor);
107 expect(hasDecoration).to.be.true;
108 }).timeout(DEFAULT_TIMEOUT.XXL);
109
110 it("Should accept Next Edit suggestion with Tab", async () => {
111 const accepted = await NextEditActions.acceptNextEditSuggestion(editor);
112 expect(accepted).to.be.true;
113 }).timeout(DEFAULT_TIMEOUT.XXL);
114
115 it("Should reject Next Edit suggestion with Esc", async () => {
116 const rejected = await NextEditActions.rejectNextEditSuggestion(editor);
117 expect(rejected).to.be.true;
118 }).timeout(DEFAULT_TIMEOUT.XXL);
119
120});