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.
Files changed (130) hide show
  1. package/.github/workflows/publish.yml +6 -6
  2. package/.github/workflows/test.yml +1 -1
  3. package/.prettierrc +5 -3
  4. package/dist/index.js +24 -25
  5. package/dist/package.json +5 -3
  6. package/dist/src/agents/app.js +8 -8
  7. package/dist/src/agents/backend.js +3 -3
  8. package/dist/src/agents/devops.js +8 -8
  9. package/dist/src/agents/frontend.js +3 -3
  10. package/dist/src/agents/fullstack.js +3 -3
  11. package/dist/src/agents/index.js +18 -18
  12. package/dist/src/agents/quality.js +8 -8
  13. package/dist/src/agents/security.js +8 -8
  14. package/dist/src/client.js +115 -127
  15. package/dist/src/commands/api-keys.js +195 -202
  16. package/dist/src/commands/auth.js +16 -25
  17. package/dist/src/commands/autocomplete.js +8 -8
  18. package/dist/src/commands/billing.js +10 -19
  19. package/dist/src/commands/chat.js +139 -170
  20. package/dist/src/commands/clusters.js +21 -30
  21. package/dist/src/commands/code/__tests__/auth-sync.test.js +189 -186
  22. package/dist/src/commands/code/__tests__/fake-api-key-service.js +3 -13
  23. package/dist/src/commands/code/__tests__/fake-auth-service.js +21 -29
  24. package/dist/src/commands/code/__tests__/fake-command-runner.js +22 -33
  25. package/dist/src/commands/code/__tests__/fake-file-store.js +19 -41
  26. package/dist/src/commands/code/__tests__/fake-prompter.js +81 -97
  27. package/dist/src/commands/code/__tests__/setup-flow.test.js +295 -295
  28. package/dist/src/commands/code/adapters/clack-prompter.js +15 -32
  29. package/dist/src/commands/code/adapters/fs-file-store.js +25 -44
  30. package/dist/src/commands/code/adapters/spawn-command-runner.js +27 -41
  31. package/dist/src/commands/code/auth-sync.js +215 -228
  32. package/dist/src/commands/code/errors.js +15 -12
  33. package/dist/src/commands/code/setup.js +390 -425
  34. package/dist/src/commands/code.js +279 -294
  35. package/dist/src/commands/index.js +5 -5
  36. package/dist/src/commands/models.js +16 -25
  37. package/dist/src/commands/users.js +9 -18
  38. package/dist/src/constants/command-structure.js +138 -138
  39. package/dist/src/services/api-key-service.js +132 -152
  40. package/dist/src/services/auth-service.js +81 -95
  41. package/dist/src/services/browser-auth.js +121 -131
  42. package/dist/src/services/chat-service.js +369 -386
  43. package/dist/src/services/cluster-service.js +47 -62
  44. package/dist/src/services/collaborator-service.js +9 -21
  45. package/dist/src/services/flux-service.js +13 -25
  46. package/dist/src/services/helm-service.js +9 -21
  47. package/dist/src/services/kubectl-service.js +15 -29
  48. package/dist/src/utils/config-checker.js +7 -7
  49. package/dist/src/utils/config-loader.js +109 -109
  50. package/dist/src/utils/default-api-key.js +129 -139
  51. package/dist/src/utils/env-manager.js +55 -66
  52. package/dist/src/utils/error-handler.js +62 -62
  53. package/dist/src/utils/logger.js +74 -67
  54. package/dist/src/utils/markdown-renderer.js +28 -28
  55. package/dist/src/utils/opencode-validator.js +67 -69
  56. package/dist/src/utils/token-manager.js +67 -65
  57. package/dist/tests/commands/chat.test.js +30 -39
  58. package/dist/tests/commands/code.test.js +186 -195
  59. package/dist/tests/utils/config-loader.test.js +107 -107
  60. package/dist/tests/utils/env-manager.test.js +81 -90
  61. package/dist/tests/utils/opencode-validator.test.js +42 -41
  62. package/dist/vitest.config.js +1 -1
  63. package/eslint.config.mjs +50 -30
  64. package/index.ts +30 -31
  65. package/package.json +5 -3
  66. package/src/agents/app.ts +9 -9
  67. package/src/agents/backend.ts +4 -4
  68. package/src/agents/devops.ts +9 -9
  69. package/src/agents/frontend.ts +4 -4
  70. package/src/agents/fullstack.ts +4 -4
  71. package/src/agents/index.ts +27 -25
  72. package/src/agents/quality.ts +9 -9
  73. package/src/agents/security.ts +9 -9
  74. package/src/agents/types.ts +10 -10
  75. package/src/client.ts +85 -77
  76. package/src/commands/api-keys.ts +190 -185
  77. package/src/commands/auth.ts +15 -14
  78. package/src/commands/autocomplete.ts +10 -10
  79. package/src/commands/billing.ts +13 -12
  80. package/src/commands/chat.ts +145 -142
  81. package/src/commands/clusters.ts +20 -19
  82. package/src/commands/code/__tests__/auth-sync.test.ts +176 -175
  83. package/src/commands/code/__tests__/fake-api-key-service.ts +2 -2
  84. package/src/commands/code/__tests__/fake-auth-service.ts +18 -18
  85. package/src/commands/code/__tests__/fake-command-runner.ts +28 -22
  86. package/src/commands/code/__tests__/fake-file-store.ts +15 -15
  87. package/src/commands/code/__tests__/fake-prompter.ts +86 -85
  88. package/src/commands/code/__tests__/setup-flow.test.ts +253 -251
  89. package/src/commands/code/adapters/clack-prompter.ts +32 -30
  90. package/src/commands/code/adapters/fs-file-store.ts +18 -17
  91. package/src/commands/code/adapters/spawn-command-runner.ts +20 -15
  92. package/src/commands/code/auth-sync.ts +210 -210
  93. package/src/commands/code/errors.ts +11 -11
  94. package/src/commands/code/ports/auth-services.ts +7 -7
  95. package/src/commands/code/ports/command-runner.ts +2 -2
  96. package/src/commands/code/ports/file-store.ts +3 -3
  97. package/src/commands/code/ports/prompter.ts +13 -13
  98. package/src/commands/code/setup.ts +408 -406
  99. package/src/commands/code.ts +288 -287
  100. package/src/commands/index.ts +11 -10
  101. package/src/commands/models.ts +19 -18
  102. package/src/commands/users.ts +11 -10
  103. package/src/constants/command-structure.ts +159 -159
  104. package/src/services/api-key-service.ts +85 -85
  105. package/src/services/auth-service.ts +55 -54
  106. package/src/services/browser-auth.ts +62 -62
  107. package/src/services/chat-service.ts +169 -170
  108. package/src/services/cluster-service.ts +28 -28
  109. package/src/services/collaborator-service.ts +6 -6
  110. package/src/services/flux-service.ts +17 -17
  111. package/src/services/helm-service.ts +11 -11
  112. package/src/services/kubectl-service.ts +12 -12
  113. package/src/types/api.d.ts +1933 -1933
  114. package/src/types/json.d.ts +1 -1
  115. package/src/utils/config-checker.ts +6 -6
  116. package/src/utils/config-loader.ts +130 -129
  117. package/src/utils/default-api-key.ts +81 -80
  118. package/src/utils/env-manager.ts +37 -37
  119. package/src/utils/error-handler.ts +64 -64
  120. package/src/utils/logger.ts +72 -66
  121. package/src/utils/markdown-renderer.ts +28 -28
  122. package/src/utils/opencode-validator.ts +72 -71
  123. package/src/utils/token-manager.ts +69 -68
  124. package/tests/commands/chat.test.ts +32 -31
  125. package/tests/commands/code.test.ts +182 -181
  126. package/tests/utils/config-loader.test.ts +111 -110
  127. package/tests/utils/env-manager.test.ts +83 -79
  128. package/tests/utils/opencode-validator.test.ts +43 -42
  129. package/tsconfig.json +2 -1
  130. 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
- return __awaiter(this, void 0, void 0, function* () {
31
- this.loginCallCount++;
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({ success: false, error: "Login failed" });
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
- : "invalid.token.here";
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
- constructor() {
15
- this.handlers = [];
16
- this._calls = [];
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, args) => {
21
- const full = `${cmd} ${args.join(" ")}`;
22
- if (typeof match === "string")
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
- checkInstalled(binary) {
31
- this._calls.push({ command: `check:${binary}`, args: [] });
32
- return Promise.resolve(this.handlers.some(h => h.match(binary, ["--version"])) || false);
33
- }
34
- run(command, args, options) {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- this._calls.push({ command, args: [...args], options });
37
- const handler = this.handlers.find(h => h.match(command, args));
38
- if (!handler)
39
- throw new Error(`Unexpected command: ${command} ${args.join(" ")}`);
40
- const result = typeof handler.response === "function" ? handler.response(command, args) : handler.response;
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
- constructor() {
15
- this.files = new Map();
16
- this.dirs = new Set();
17
- this._chmodCalls = [];
5
+ _chmodCalls = [];
6
+ dirs = new Set();
7
+ files = new Map();
8
+ async chmod(path, mode) {
9
+ this._chmodCalls.push({ mode, path });
18
10
  }
19
- seed(path, content) {
20
- this.files.set(path, content);
11
+ async exists(path) {
12
+ return this.files.has(path) || this.dirs.has(path);
21
13
  }
22
- exists(path) {
23
- return __awaiter(this, void 0, void 0, function* () {
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
- writeFile(path, content) {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- this.files.set(path, content);
36
- });
17
+ getWrittenFiles() {
18
+ return new Map(this.files);
37
19
  }
38
- mkdir(path) {
39
- return __awaiter(this, void 0, void 0, function* () {
40
- this.dirs.add(path);
41
- });
20
+ async mkdir(path) {
21
+ this.dirs.add(path);
42
22
  }
43
- chmod(path, mode) {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- this._chmodCalls.push({ path, mode });
46
- });
23
+ async readFile(path) {
24
+ return this.files.get(path) ?? null;
47
25
  }
48
- getWrittenFiles() {
49
- return new Map(this.files);
26
+ seed(path, content) {
27
+ this.files.set(path, content);
50
28
  }
51
- getChmodCalls() {
52
- return this._chmodCalls;
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("cancel");
5
+ exports.CANCEL = Symbol('cancel');
15
6
  const select = (value, match) => ({
16
- kind: "select",
17
- match: typeof match === "string" ? new RegExp(match) : match,
18
- response: typeof value === "symbol" ? value : String(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: "text",
23
- match: typeof match === "string" ? new RegExp(match) : 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: "confirm",
29
- match: typeof match === "string" ? new RegExp(match) : 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: "multiselect",
35
- match: typeof match === "string" ? new RegExp(match) : match,
36
- response: values === exports.CANCEL ? [exports.CANCEL] : values.map(v => String(v)),
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
- this._calls = [];
43
- this._cursor = 0;
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({ method: "intro", args: { message } });
59
+ this._calls.push({ args: { message }, method: 'intro' });
47
60
  }
48
- outro(message) {
49
- this._calls.push({ method: "outro", args: { message } });
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({ method: "note", args: { message, title } });
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: (msg) => {
57
- this._calls.push({ method: "spinner.start", args: { message: msg } });
95
+ start: (message) => {
96
+ this._calls.push({ args: { message: message }, method: 'spinner.start' });
58
97
  },
59
- stop: (msg) => {
60
- this._calls.push({ method: "spinner.stop", args: { message: msg } });
98
+ stop: (message) => {
99
+ this._calls.push({ args: { message: message }, method: 'spinner.stop' });
61
100
  },
62
101
  };
63
102
  }
64
- select(opts) {
65
- return __awaiter(this, void 0, void 0, function* () {
66
- this._calls.push({ method: "select", args: opts });
67
- const entry = this._script[this._cursor++];
68
- if (!entry)
69
- throw new Error(`No script entry for select #${this._cursor} (${opts.message})`);
70
- if (entry.kind !== "select")
71
- throw new Error(`Expected select, got ${entry.kind} for ${opts.message}`);
72
- if (entry.match && !entry.match.test(opts.message))
73
- throw new Error(`Message mismatch: got "${opts.message}"`);
74
- if (entry.response === exports.CANCEL)
75
- throw new errors_1.CancelledError();
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;