berget 2.2.7 → 2.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish.yml +6 -6
- package/.github/workflows/test.yml +1 -1
- package/.prettierrc +5 -3
- package/dist/index.js +24 -25
- package/dist/package.json +5 -3
- package/dist/src/agents/app.js +8 -8
- package/dist/src/agents/backend.js +3 -3
- package/dist/src/agents/devops.js +8 -8
- package/dist/src/agents/frontend.js +3 -3
- package/dist/src/agents/fullstack.js +3 -3
- package/dist/src/agents/index.js +18 -18
- package/dist/src/agents/quality.js +8 -8
- package/dist/src/agents/security.js +8 -8
- package/dist/src/client.js +115 -127
- package/dist/src/commands/api-keys.js +195 -202
- package/dist/src/commands/auth.js +16 -25
- package/dist/src/commands/autocomplete.js +8 -8
- package/dist/src/commands/billing.js +10 -19
- package/dist/src/commands/chat.js +139 -170
- package/dist/src/commands/clusters.js +21 -30
- package/dist/src/commands/code/__tests__/auth-sync.test.js +189 -186
- package/dist/src/commands/code/__tests__/fake-api-key-service.js +3 -13
- package/dist/src/commands/code/__tests__/fake-auth-service.js +21 -29
- package/dist/src/commands/code/__tests__/fake-command-runner.js +22 -33
- package/dist/src/commands/code/__tests__/fake-file-store.js +19 -41
- package/dist/src/commands/code/__tests__/fake-prompter.js +81 -97
- package/dist/src/commands/code/__tests__/setup-flow.test.js +295 -295
- package/dist/src/commands/code/adapters/clack-prompter.js +15 -32
- package/dist/src/commands/code/adapters/fs-file-store.js +25 -44
- package/dist/src/commands/code/adapters/spawn-command-runner.js +27 -41
- package/dist/src/commands/code/auth-sync.js +215 -228
- package/dist/src/commands/code/errors.js +15 -12
- package/dist/src/commands/code/setup.js +390 -425
- package/dist/src/commands/code.js +279 -294
- package/dist/src/commands/index.js +5 -5
- package/dist/src/commands/models.js +16 -25
- package/dist/src/commands/users.js +9 -18
- package/dist/src/constants/command-structure.js +138 -138
- package/dist/src/services/api-key-service.js +132 -152
- package/dist/src/services/auth-service.js +81 -95
- package/dist/src/services/browser-auth.js +121 -131
- package/dist/src/services/chat-service.js +369 -386
- package/dist/src/services/cluster-service.js +47 -62
- package/dist/src/services/collaborator-service.js +9 -21
- package/dist/src/services/flux-service.js +13 -25
- package/dist/src/services/helm-service.js +9 -21
- package/dist/src/services/kubectl-service.js +15 -29
- package/dist/src/utils/config-checker.js +7 -7
- package/dist/src/utils/config-loader.js +109 -109
- package/dist/src/utils/default-api-key.js +129 -139
- package/dist/src/utils/env-manager.js +55 -66
- package/dist/src/utils/error-handler.js +62 -62
- package/dist/src/utils/logger.js +74 -67
- package/dist/src/utils/markdown-renderer.js +28 -28
- package/dist/src/utils/opencode-validator.js +67 -69
- package/dist/src/utils/token-manager.js +67 -65
- package/dist/tests/commands/chat.test.js +30 -39
- package/dist/tests/commands/code.test.js +186 -195
- package/dist/tests/utils/config-loader.test.js +107 -107
- package/dist/tests/utils/env-manager.test.js +81 -90
- package/dist/tests/utils/opencode-validator.test.js +42 -41
- package/dist/vitest.config.js +1 -1
- package/eslint.config.mjs +50 -30
- package/index.ts +30 -31
- package/package.json +5 -3
- package/src/agents/app.ts +9 -9
- package/src/agents/backend.ts +4 -4
- package/src/agents/devops.ts +9 -9
- package/src/agents/frontend.ts +4 -4
- package/src/agents/fullstack.ts +4 -4
- package/src/agents/index.ts +27 -25
- package/src/agents/quality.ts +9 -9
- package/src/agents/security.ts +9 -9
- package/src/agents/types.ts +10 -10
- package/src/client.ts +85 -77
- package/src/commands/api-keys.ts +190 -185
- package/src/commands/auth.ts +15 -14
- package/src/commands/autocomplete.ts +10 -10
- package/src/commands/billing.ts +13 -12
- package/src/commands/chat.ts +145 -142
- package/src/commands/clusters.ts +20 -19
- package/src/commands/code/__tests__/auth-sync.test.ts +176 -175
- package/src/commands/code/__tests__/fake-api-key-service.ts +2 -2
- package/src/commands/code/__tests__/fake-auth-service.ts +18 -18
- package/src/commands/code/__tests__/fake-command-runner.ts +28 -22
- package/src/commands/code/__tests__/fake-file-store.ts +15 -15
- package/src/commands/code/__tests__/fake-prompter.ts +86 -85
- package/src/commands/code/__tests__/setup-flow.test.ts +253 -251
- package/src/commands/code/adapters/clack-prompter.ts +32 -30
- package/src/commands/code/adapters/fs-file-store.ts +18 -17
- package/src/commands/code/adapters/spawn-command-runner.ts +20 -15
- package/src/commands/code/auth-sync.ts +210 -210
- package/src/commands/code/errors.ts +11 -11
- package/src/commands/code/ports/auth-services.ts +7 -7
- package/src/commands/code/ports/command-runner.ts +2 -2
- package/src/commands/code/ports/file-store.ts +3 -3
- package/src/commands/code/ports/prompter.ts +13 -13
- package/src/commands/code/setup.ts +408 -406
- package/src/commands/code.ts +288 -287
- package/src/commands/index.ts +11 -10
- package/src/commands/models.ts +19 -18
- package/src/commands/users.ts +11 -10
- package/src/constants/command-structure.ts +159 -159
- package/src/services/api-key-service.ts +85 -85
- package/src/services/auth-service.ts +55 -54
- package/src/services/browser-auth.ts +62 -62
- package/src/services/chat-service.ts +169 -170
- package/src/services/cluster-service.ts +28 -28
- package/src/services/collaborator-service.ts +6 -6
- package/src/services/flux-service.ts +17 -17
- package/src/services/helm-service.ts +11 -11
- package/src/services/kubectl-service.ts +12 -12
- package/src/types/api.d.ts +1933 -1933
- package/src/types/json.d.ts +1 -1
- package/src/utils/config-checker.ts +6 -6
- package/src/utils/config-loader.ts +130 -129
- package/src/utils/default-api-key.ts +81 -80
- package/src/utils/env-manager.ts +37 -37
- package/src/utils/error-handler.ts +64 -64
- package/src/utils/logger.ts +72 -66
- package/src/utils/markdown-renderer.ts +28 -28
- package/src/utils/opencode-validator.ts +72 -71
- package/src/utils/token-manager.ts +69 -68
- package/tests/commands/chat.test.ts +32 -31
- package/tests/commands/code.test.ts +182 -181
- package/tests/utils/config-loader.test.ts +111 -110
- package/tests/utils/env-manager.test.ts +83 -79
- package/tests/utils/opencode-validator.test.ts +43 -42
- package/tsconfig.json +2 -1
- package/vitest.config.ts +2 -2
|
@@ -1,55 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.FakeAuthService = void 0;
|
|
13
|
-
function base64urlEncode(data) {
|
|
14
|
-
return Buffer.from(data).toString("base64url");
|
|
15
|
-
}
|
|
16
|
-
function makeJwt(payload) {
|
|
17
|
-
const header = base64urlEncode(JSON.stringify({ alg: "none", typ: "JWT" }));
|
|
18
|
-
const body = base64urlEncode(JSON.stringify(payload));
|
|
19
|
-
return `${header}.${body}.signature`;
|
|
20
|
-
}
|
|
21
4
|
class FakeAuthService {
|
|
5
|
+
_shouldSucceed;
|
|
6
|
+
_hasSeat;
|
|
7
|
+
_validToken;
|
|
8
|
+
loginCallCount = 0;
|
|
9
|
+
loginInteractiveCallCount = 0;
|
|
22
10
|
constructor(_shouldSucceed, _hasSeat = true, _validToken = true) {
|
|
23
11
|
this._shouldSucceed = _shouldSucceed;
|
|
24
12
|
this._hasSeat = _hasSeat;
|
|
25
13
|
this._validToken = _validToken;
|
|
26
|
-
this.loginCallCount = 0;
|
|
27
|
-
this.loginInteractiveCallCount = 0;
|
|
28
14
|
}
|
|
29
|
-
login() {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return this._shouldSucceed;
|
|
33
|
-
});
|
|
15
|
+
async login() {
|
|
16
|
+
this.loginCallCount++;
|
|
17
|
+
return this._shouldSucceed;
|
|
34
18
|
}
|
|
35
19
|
loginInteractive() {
|
|
36
20
|
this.loginInteractiveCallCount++;
|
|
37
21
|
if (!this._shouldSucceed) {
|
|
38
|
-
return Promise.resolve({
|
|
22
|
+
return Promise.resolve({ error: 'Login failed', success: false });
|
|
39
23
|
}
|
|
40
24
|
const farFuture = Math.floor(Date.now() / 1000) + 3600 * 24 * 365; // 1 year from now in seconds
|
|
41
25
|
const accessToken = this._validToken
|
|
42
26
|
? makeJwt({
|
|
43
|
-
realm_access: { roles: this._hasSeat ? ["berget_code_seat"] : ["default-roles-berget"] },
|
|
44
27
|
exp: farFuture,
|
|
28
|
+
realm_access: { roles: this._hasSeat ? ['berget_code_seat'] : ['default-roles-berget'] },
|
|
45
29
|
})
|
|
46
|
-
:
|
|
30
|
+
: 'invalid.token.here';
|
|
47
31
|
return Promise.resolve({
|
|
48
|
-
success: true,
|
|
49
32
|
accessToken,
|
|
50
|
-
refreshToken: "refresh",
|
|
51
33
|
expiresIn: 3600,
|
|
34
|
+
refreshToken: 'refresh',
|
|
35
|
+
success: true,
|
|
52
36
|
});
|
|
53
37
|
}
|
|
54
38
|
}
|
|
55
39
|
exports.FakeAuthService = FakeAuthService;
|
|
40
|
+
function base64urlEncode(data) {
|
|
41
|
+
return Buffer.from(data).toString('base64url');
|
|
42
|
+
}
|
|
43
|
+
function makeJwt(payload) {
|
|
44
|
+
const header = base64urlEncode(JSON.stringify({ alg: 'none', typ: 'JWT' }));
|
|
45
|
+
const body = base64urlEncode(JSON.stringify(payload));
|
|
46
|
+
return `${header}.${body}.signature`;
|
|
47
|
+
}
|
|
@@ -1,25 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.FakeCommandRunner = void 0;
|
|
13
4
|
class FakeCommandRunner {
|
|
14
|
-
|
|
15
|
-
this.
|
|
16
|
-
|
|
5
|
+
get calls() {
|
|
6
|
+
return this._calls;
|
|
7
|
+
}
|
|
8
|
+
_calls = [];
|
|
9
|
+
handlers = [];
|
|
10
|
+
checkInstalled(binary) {
|
|
11
|
+
this._calls.push({ args: [], command: `check:${binary}` });
|
|
12
|
+
return Promise.resolve(this.handlers.some((h) => h.match(binary, ['--version'])) || false);
|
|
17
13
|
}
|
|
18
14
|
handle(match, response) {
|
|
19
15
|
this.handlers.push({
|
|
20
|
-
match: (cmd,
|
|
21
|
-
const full = `${cmd} ${
|
|
22
|
-
if (typeof match ===
|
|
16
|
+
match: (cmd, arguments_) => {
|
|
17
|
+
const full = `${cmd} ${arguments_.join(' ')}`;
|
|
18
|
+
if (typeof match === 'string')
|
|
23
19
|
return full.startsWith(match);
|
|
24
20
|
return match.test(full);
|
|
25
21
|
},
|
|
@@ -27,24 +23,17 @@ class FakeCommandRunner {
|
|
|
27
23
|
});
|
|
28
24
|
return this;
|
|
29
25
|
}
|
|
30
|
-
|
|
31
|
-
this._calls.push({
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (result instanceof Error)
|
|
42
|
-
throw result;
|
|
43
|
-
return result;
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
get calls() {
|
|
47
|
-
return this._calls;
|
|
26
|
+
async run(command, arguments_, options) {
|
|
27
|
+
this._calls.push({ args: [...arguments_], command, options });
|
|
28
|
+
const handler = this.handlers.find((h) => h.match(command, arguments_));
|
|
29
|
+
if (!handler)
|
|
30
|
+
throw new Error(`Unexpected command: ${command} ${arguments_.join(' ')}`);
|
|
31
|
+
const result = typeof handler.response === 'function'
|
|
32
|
+
? handler.response(command, arguments_)
|
|
33
|
+
: handler.response;
|
|
34
|
+
if (result instanceof Error)
|
|
35
|
+
throw result;
|
|
36
|
+
return result;
|
|
48
37
|
}
|
|
49
38
|
}
|
|
50
39
|
exports.FakeCommandRunner = FakeCommandRunner;
|
|
@@ -1,55 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.FakeFileStore = void 0;
|
|
13
4
|
class FakeFileStore {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
5
|
+
_chmodCalls = [];
|
|
6
|
+
dirs = new Set();
|
|
7
|
+
files = new Map();
|
|
8
|
+
async chmod(path, mode) {
|
|
9
|
+
this._chmodCalls.push({ mode, path });
|
|
18
10
|
}
|
|
19
|
-
|
|
20
|
-
this.files.
|
|
11
|
+
async exists(path) {
|
|
12
|
+
return this.files.has(path) || this.dirs.has(path);
|
|
21
13
|
}
|
|
22
|
-
|
|
23
|
-
return
|
|
24
|
-
return this.files.has(path) || this.dirs.has(path);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
readFile(path) {
|
|
28
|
-
var _a;
|
|
29
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
-
return (_a = this.files.get(path)) !== null && _a !== void 0 ? _a : null;
|
|
31
|
-
});
|
|
14
|
+
getChmodCalls() {
|
|
15
|
+
return this._chmodCalls;
|
|
32
16
|
}
|
|
33
|
-
|
|
34
|
-
return
|
|
35
|
-
this.files.set(path, content);
|
|
36
|
-
});
|
|
17
|
+
getWrittenFiles() {
|
|
18
|
+
return new Map(this.files);
|
|
37
19
|
}
|
|
38
|
-
mkdir(path) {
|
|
39
|
-
|
|
40
|
-
this.dirs.add(path);
|
|
41
|
-
});
|
|
20
|
+
async mkdir(path) {
|
|
21
|
+
this.dirs.add(path);
|
|
42
22
|
}
|
|
43
|
-
|
|
44
|
-
return
|
|
45
|
-
this._chmodCalls.push({ path, mode });
|
|
46
|
-
});
|
|
23
|
+
async readFile(path) {
|
|
24
|
+
return this.files.get(path) ?? null;
|
|
47
25
|
}
|
|
48
|
-
|
|
49
|
-
|
|
26
|
+
seed(path, content) {
|
|
27
|
+
this.files.set(path, content);
|
|
50
28
|
}
|
|
51
|
-
|
|
52
|
-
|
|
29
|
+
async writeFile(path, content) {
|
|
30
|
+
this.files.set(path, content);
|
|
53
31
|
}
|
|
54
32
|
}
|
|
55
33
|
exports.FakeFileStore = FakeFileStore;
|
|
@@ -1,133 +1,117 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.FakePrompter = exports.multiselect = exports.confirm = exports.text = exports.select = exports.CANCEL = void 0;
|
|
13
4
|
const errors_1 = require("../errors");
|
|
14
|
-
exports.CANCEL = Symbol(
|
|
5
|
+
exports.CANCEL = Symbol('cancel');
|
|
15
6
|
const select = (value, match) => ({
|
|
16
|
-
kind:
|
|
17
|
-
match: typeof match ===
|
|
18
|
-
response: typeof value ===
|
|
7
|
+
kind: 'select',
|
|
8
|
+
match: typeof match === 'string' ? new RegExp(match) : match,
|
|
9
|
+
response: typeof value === 'symbol' ? value : String(value),
|
|
19
10
|
});
|
|
20
11
|
exports.select = select;
|
|
21
12
|
const text = (value, match) => ({
|
|
22
|
-
kind:
|
|
23
|
-
match: typeof match ===
|
|
13
|
+
kind: 'text',
|
|
14
|
+
match: typeof match === 'string' ? new RegExp(match) : match,
|
|
24
15
|
response: value,
|
|
25
16
|
});
|
|
26
17
|
exports.text = text;
|
|
27
18
|
const confirm = (value, match) => ({
|
|
28
|
-
kind:
|
|
29
|
-
match: typeof match ===
|
|
19
|
+
kind: 'confirm',
|
|
20
|
+
match: typeof match === 'string' ? new RegExp(match) : match,
|
|
30
21
|
response: value,
|
|
31
22
|
});
|
|
32
23
|
exports.confirm = confirm;
|
|
33
24
|
const multiselect = (values, match) => ({
|
|
34
|
-
kind:
|
|
35
|
-
match: typeof match ===
|
|
36
|
-
response: values === exports.CANCEL ? [exports.CANCEL] : values.map(
|
|
25
|
+
kind: 'multiselect',
|
|
26
|
+
match: typeof match === 'string' ? new RegExp(match) : match,
|
|
27
|
+
response: values === exports.CANCEL ? [exports.CANCEL] : values.map(String),
|
|
37
28
|
});
|
|
38
29
|
exports.multiselect = multiselect;
|
|
39
30
|
class FakePrompter {
|
|
31
|
+
_script;
|
|
32
|
+
get calls() {
|
|
33
|
+
return this._calls;
|
|
34
|
+
}
|
|
35
|
+
_calls = [];
|
|
36
|
+
_cursor = 0;
|
|
40
37
|
constructor(_script) {
|
|
41
38
|
this._script = _script;
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
}
|
|
40
|
+
assertExhausted() {
|
|
41
|
+
if (this._cursor !== this._script.length) {
|
|
42
|
+
throw new Error(`Script not exhausted: ${this._script.length - this._cursor} entries left`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async confirm(options) {
|
|
46
|
+
this._calls.push({ args: options, method: 'confirm' });
|
|
47
|
+
const entry = this._script[this._cursor++];
|
|
48
|
+
if (!entry)
|
|
49
|
+
throw new Error(`No script entry for confirm #${this._cursor} (${options.message})`);
|
|
50
|
+
if (entry.kind !== 'confirm')
|
|
51
|
+
throw new Error(`Expected confirm, got ${entry.kind} for ${options.message}`);
|
|
52
|
+
if (entry.match && !entry.match.test(options.message))
|
|
53
|
+
throw new Error(`Message mismatch: got "${options.message}"`);
|
|
54
|
+
if (entry.response === exports.CANCEL)
|
|
55
|
+
throw new errors_1.CancelledError();
|
|
56
|
+
return entry.response;
|
|
44
57
|
}
|
|
45
58
|
intro(message) {
|
|
46
|
-
this._calls.push({
|
|
59
|
+
this._calls.push({ args: { message }, method: 'intro' });
|
|
47
60
|
}
|
|
48
|
-
|
|
49
|
-
this._calls.push({
|
|
61
|
+
async multiselect(options) {
|
|
62
|
+
this._calls.push({ args: options, method: 'multiselect' });
|
|
63
|
+
const entry = this._script[this._cursor++];
|
|
64
|
+
if (!entry)
|
|
65
|
+
throw new Error(`No script entry for multiselect #${this._cursor} (${options.message})`);
|
|
66
|
+
if (entry.kind !== 'multiselect')
|
|
67
|
+
throw new Error(`Expected multiselect, got ${entry.kind} for ${options.message}`);
|
|
68
|
+
if (entry.match && !entry.match.test(options.message))
|
|
69
|
+
throw new Error(`Message mismatch: got "${options.message}"`);
|
|
70
|
+
if (entry.response.includes(exports.CANCEL))
|
|
71
|
+
throw new errors_1.CancelledError();
|
|
72
|
+
return entry.response;
|
|
50
73
|
}
|
|
51
74
|
note(message, title) {
|
|
52
|
-
this._calls.push({
|
|
75
|
+
this._calls.push({ args: { message, title }, method: 'note' });
|
|
76
|
+
}
|
|
77
|
+
outro(message) {
|
|
78
|
+
this._calls.push({ args: { message }, method: 'outro' });
|
|
79
|
+
}
|
|
80
|
+
async select(options) {
|
|
81
|
+
this._calls.push({ args: options, method: 'select' });
|
|
82
|
+
const entry = this._script[this._cursor++];
|
|
83
|
+
if (!entry)
|
|
84
|
+
throw new Error(`No script entry for select #${this._cursor} (${options.message})`);
|
|
85
|
+
if (entry.kind !== 'select')
|
|
86
|
+
throw new Error(`Expected select, got ${entry.kind} for ${options.message}`);
|
|
87
|
+
if (entry.match && !entry.match.test(options.message))
|
|
88
|
+
throw new Error(`Message mismatch: got "${options.message}"`);
|
|
89
|
+
if (entry.response === exports.CANCEL)
|
|
90
|
+
throw new errors_1.CancelledError();
|
|
91
|
+
return entry.response;
|
|
53
92
|
}
|
|
54
93
|
spinner() {
|
|
55
94
|
return {
|
|
56
|
-
start: (
|
|
57
|
-
this._calls.push({
|
|
95
|
+
start: (message) => {
|
|
96
|
+
this._calls.push({ args: { message: message }, method: 'spinner.start' });
|
|
58
97
|
},
|
|
59
|
-
stop: (
|
|
60
|
-
this._calls.push({
|
|
98
|
+
stop: (message) => {
|
|
99
|
+
this._calls.push({ args: { message: message }, method: 'spinner.stop' });
|
|
61
100
|
},
|
|
62
101
|
};
|
|
63
102
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return entry.response;
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
confirm(opts) {
|
|
80
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
this._calls.push({ method: "confirm", args: opts });
|
|
82
|
-
const entry = this._script[this._cursor++];
|
|
83
|
-
if (!entry)
|
|
84
|
-
throw new Error(`No script entry for confirm #${this._cursor} (${opts.message})`);
|
|
85
|
-
if (entry.kind !== "confirm")
|
|
86
|
-
throw new Error(`Expected confirm, got ${entry.kind} for ${opts.message}`);
|
|
87
|
-
if (entry.match && !entry.match.test(opts.message))
|
|
88
|
-
throw new Error(`Message mismatch: got "${opts.message}"`);
|
|
89
|
-
if (entry.response === exports.CANCEL)
|
|
90
|
-
throw new errors_1.CancelledError();
|
|
91
|
-
return entry.response;
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
text(opts) {
|
|
95
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
-
this._calls.push({ method: "text", args: opts });
|
|
97
|
-
const entry = this._script[this._cursor++];
|
|
98
|
-
if (!entry)
|
|
99
|
-
throw new Error(`No script entry for text #${this._cursor} (${opts.message})`);
|
|
100
|
-
if (entry.kind !== "text")
|
|
101
|
-
throw new Error(`Expected text, got ${entry.kind} for ${opts.message}`);
|
|
102
|
-
if (entry.match && !entry.match.test(opts.message))
|
|
103
|
-
throw new Error(`Message mismatch: got "${opts.message}"`);
|
|
104
|
-
if (entry.response === exports.CANCEL)
|
|
105
|
-
throw new errors_1.CancelledError();
|
|
106
|
-
return entry.response;
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
multiselect(opts) {
|
|
110
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
-
this._calls.push({ method: "multiselect", args: opts });
|
|
112
|
-
const entry = this._script[this._cursor++];
|
|
113
|
-
if (!entry)
|
|
114
|
-
throw new Error(`No script entry for multiselect #${this._cursor} (${opts.message})`);
|
|
115
|
-
if (entry.kind !== "multiselect")
|
|
116
|
-
throw new Error(`Expected multiselect, got ${entry.kind} for ${opts.message}`);
|
|
117
|
-
if (entry.match && !entry.match.test(opts.message))
|
|
118
|
-
throw new Error(`Message mismatch: got "${opts.message}"`);
|
|
119
|
-
if (entry.response.includes(exports.CANCEL))
|
|
120
|
-
throw new errors_1.CancelledError();
|
|
121
|
-
return entry.response;
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
get calls() {
|
|
125
|
-
return this._calls;
|
|
126
|
-
}
|
|
127
|
-
assertExhausted() {
|
|
128
|
-
if (this._cursor !== this._script.length) {
|
|
129
|
-
throw new Error(`Script not exhausted: ${this._script.length - this._cursor} entries left`);
|
|
130
|
-
}
|
|
103
|
+
async text(options) {
|
|
104
|
+
this._calls.push({ args: options, method: 'text' });
|
|
105
|
+
const entry = this._script[this._cursor++];
|
|
106
|
+
if (!entry)
|
|
107
|
+
throw new Error(`No script entry for text #${this._cursor} (${options.message})`);
|
|
108
|
+
if (entry.kind !== 'text')
|
|
109
|
+
throw new Error(`Expected text, got ${entry.kind} for ${options.message}`);
|
|
110
|
+
if (entry.match && !entry.match.test(options.message))
|
|
111
|
+
throw new Error(`Message mismatch: got "${options.message}"`);
|
|
112
|
+
if (entry.response === exports.CANCEL)
|
|
113
|
+
throw new errors_1.CancelledError();
|
|
114
|
+
return entry.response;
|
|
131
115
|
}
|
|
132
116
|
}
|
|
133
117
|
exports.FakePrompter = FakePrompter;
|