Open History to see the last commit
1import { KeybindingCommand, KeybindingRule, KeybindingsConfig } from "@t3tools/contracts";
2import * as NodeServices from "@effect/platform-node/NodeServices";
3import { assert, it } from "@effect/vitest";
4import { assertFailure } from "@effect/vitest/utils";
5import * as Cause from "effect/Cause";
6import * as Effect from "effect/Effect";
7import * as FileSystem from "effect/FileSystem";
8import * as Layer from "effect/Layer";
9import * as Logger from "effect/Logger";
10import * as Path from "effect/Path";
11import * as Schema from "effect/Schema";
12import * as ServerConfig from "./config.ts";
13import * as Keybindings from "./keybindings.ts";
14import { KeybindingsConfigError } from "@t3tools/contracts";
15import { HostProcessPlatform } from "@t3tools/shared/hostProcess";
16
17const KeybindingsConfigJson = Schema.fromJsonString(KeybindingsConfig);
18const encodeKeybindingsConfigJson = Schema.encodeEffect(KeybindingsConfigJson);
19const decodeKeybindingsConfigJson = Schema.decodeUnknownEffect(KeybindingsConfigJson);
20const encodeResolvedKeybindingFromConfig = Schema.encodeEffect(
21 Keybindings.ResolvedKeybindingFromConfig,
22);
23const decodeResolvedKeybindingFromConfigExit = Schema.decodeUnknownExit(
24 Keybindings.ResolvedKeybindingFromConfig,
25);
26const makeKeybindingsLayer = () => {
27 return Keybindings.layer.pipe(
28 Layer.provideMerge(
29 Layer.fresh(
30 ServerConfig.layerTest(process.cwd(), {
31 prefix: "t3code-keybindings-test-",
32 }),
33 ),
34 ),
35 );
36};
37
38const toDetailResult = <A, R>(effect: Effect.Effect<A, KeybindingsConfigError, R>) =>
39 effect.pipe(
40 Effect.mapError((error) => error.detail),
41 Effect.result,
42 );
43
44const writeKeybindingsConfig = (configPath: string, rules: readonly KeybindingRule[]) =>
45 Effect.gen(function* () {
46 const fileSystem = yield* FileSystem.FileSystem;
47 const path = yield* Path.Path;
48 const encoded = yield* encodeKeybindingsConfigJson(rules);
49 yield* fileSystem.makeDirectory(path.dirname(configPath), { recursive: true });
50 yield* fileSystem.writeFileString(configPath, encoded);
51 });
52
53const readKeybindingsConfig = (configPath: string) =>
54 Effect.gen(function* () {
55 const fileSystem = yield* FileSystem.FileSystem;
56 const rawConfig = yield* fileSystem.readFileString(configPath);
57 return yield* decodeKeybindingsConfigJson(rawConfig);
58 });
59
60it.layer(NodeServices.layer)("keybindings", (it) => {
61 it.effect("parses shortcuts including plus key", () =>
62 Effect.sync(() => {
63 assert.deepEqual(Keybindings.parseKeybindingShortcut("mod+j"), {
64 key: "j",
65 metaKey: false,
66 ctrlKey: false,
67 shiftKey: false,
68 altKey: false,
69 modKey: true,
70 });
71 assert.deepEqual(Keybindings.parseKeybindingShortcut("mod++"), {
72 key: "+",
73 metaKey: false,
74 ctrlKey: false,
75 shiftKey: false,
76 altKey: false,
77 modKey: true,
78 });
79 }),
80 );
81
82 it.effect("compiles valid rule with parsed when AST", () =>
83 Effect.sync(() => {
84 const compiled = Keybindings.compileResolvedKeybindingRule({
85 key: "mod+d",
86 command: "terminal.split",
87 when: "terminalOpen && !terminalFocus",
88 });
89
90 assert.deepEqual(compiled, {
91 command: "terminal.split",
92 shortcut: {
93 key: "d",
94 metaKey: false,
95 ctrlKey: false,
96 shiftKey: false,
97 altKey: false,
98 modKey: true,
99 },
100 whenAst: {
101 type: "and",
102 left: { type: "identifier", name: "terminalOpen" },
103 right: {
104 type: "not",
105 node: { type: "identifier", name: "terminalFocus" },
106 },
107 },
108 });
109 }),
110 );
111
112 it.effect("encodes resolved plus-key shortcuts", () =>
113 Effect.gen(function* () {
114 const encoded = yield* encodeResolvedKeybindingFromConfig({
115 command: "terminal.toggle",
116 shortcut: {
117 key: "+",
118 metaKey: false,
119 ctrlKey: false,
120 shiftKey: false,
121 altKey: false,
122 modKey: true,
123 },
124 });
125
126 assert.equal(encoded.key, "mod++");
127 assert.equal(encoded.command, "terminal.toggle");
128 }),
129 );
130
131 it.effect("rejects invalid rules", () =>
132 Effect.sync(() => {
133 assert.isNull(
134 Keybindings.compileResolvedKeybindingRule({
135 key: "mod+shift+d+o",
136 command: "terminal.new",
137 }),
138 );
139
140 assert.isNull(
141 Keybindings.compileResolvedKeybindingRule({
142 key: "mod+d",
143 command: "terminal.split",
144 when: "terminalFocus && (",
145 }),
146 );
147
148 assert.isNull(
149 Keybindings.compileResolvedKeybindingRule({
150 key: "mod+d",
151 command: "terminal.split",
152 when: `${"!".repeat(300)}terminalFocus`,
153 }),
154 );
155 }),
156 );
157
158 it.effect("formats invalid resolved keybinding rules with the custom message", () =>
159 Effect.sync(() => {
160 const result = decodeResolvedKeybindingFromConfigExit({
161 key: "mod+shift+d+o",
162 command: "terminal.new",
163 });
164
165 if (result._tag !== "Failure") {
166 assert.fail("Expected invalid keybinding decode to fail");
167 }
168
169 const detail = Cause.pretty(result.cause);
170 assert.isTrue(detail.includes("Invalid keybinding rule"));
171 assert.isFalse(detail.includes("Invalid data"));
172 }),
173 );
174
175 it.effect("bootstraps default keybindings when config file is missing", () =>
176 Effect.gen(function* () {
177 const fs = yield* FileSystem.FileSystem;
178 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
179 assert.isFalse(yield* fs.exists(keybindingsConfigPath));
180
181 yield* Effect.gen(function* () {
182 const keybindings = yield* Keybindings.Keybindings;
183 yield* keybindings.syncDefaultKeybindingsOnStartup;
184 });
185
186 const persisted = yield* readKeybindingsConfig(keybindingsConfigPath);
187 assert.deepEqual(persisted, Keybindings.DEFAULT_KEYBINDINGS);
188 }).pipe(Effect.provide(makeKeybindingsLayer())),
189 );
190
191 it.effect("ships configurable thread navigation defaults", () =>
192 Effect.sync(() => {
193 const defaultsByCommand = new Map(
194 Keybindings.DEFAULT_KEYBINDINGS.map((binding) => [binding.command, binding.key] as const),
195 );
196
197 assert.equal(defaultsByCommand.get("thread.previous"), "mod+shift+[");
198 assert.equal(defaultsByCommand.get("thread.next"), "mod+shift+]");
199 assert.equal(defaultsByCommand.get("thread.copyReference"), "mod+shift+c");
200 assert.equal(defaultsByCommand.get("thread.settle"), "mod+shift+s");
201 assert.equal(defaultsByCommand.get("thread.pin"), "mod+shift+p");
202 assert.equal(defaultsByCommand.get("thread.jump.1"), "mod+1");
203 assert.equal(defaultsByCommand.get("thread.jump.9"), "mod+9");
204 assert.equal(defaultsByCommand.get("modelPicker.toggle"), "mod+shift+m");
205 assert.equal(defaultsByCommand.get("themeEditor.toggle"), "mod+alt+shift+t");
206 assert.equal(defaultsByCommand.get("filePicker.toggle"), "mod+p");
207 assert.equal(defaultsByCommand.get("projectSearch.toggle"), "mod+shift+f");
208 assert.equal(defaultsByCommand.get("sidebar.toggle"), "mod+b");
209 assert.equal(defaultsByCommand.get("rightPanel.toggle"), "mod+alt+b");
210 assert.isFalse(defaultsByCommand.has("rightPanel.toggleMaximized"));
211 assert.equal(defaultsByCommand.get("rightPanel.close"), "mod+w");
212 assert.equal(defaultsByCommand.get("terminal.splitVertical"), "mod+shift+d");
213 assert.equal(defaultsByCommand.get("modelPicker.jump.1"), "mod+1");
214 assert.equal(defaultsByCommand.get("modelPicker.jump.9"), "mod+9");
215 }),
216 );
217
218 it.effect("uses defaults in runtime when config is malformed without overriding file", () =>
219 Effect.gen(function* () {
220 const fs = yield* FileSystem.FileSystem;
221 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
222 yield* fs.writeFileString(keybindingsConfigPath, "{ not-json");
223
224 const configState = yield* Effect.gen(function* () {
225 const keybindings = yield* Keybindings.Keybindings;
226 return yield* keybindings.loadConfigState;
227 });
228
229 assert.deepEqual(
230 configState.keybindings,
231 Keybindings.compileResolvedKeybindingsConfig(Keybindings.DEFAULT_KEYBINDINGS),
232 );
233 assert.deepEqual(configState.issues, [
234 {
235 kind: "keybindings.malformed-config",
236 message: configState.issues[0]?.message ?? "",
237 },
238 ]);
239 assert.equal(yield* fs.readFileString(keybindingsConfigPath), "{ not-json");
240 }).pipe(Effect.provide(makeKeybindingsLayer())),
241 );
242
243 it.effect("ignores invalid entries in runtime and reports them as issues", () =>
244 Effect.gen(function* () {
245 const fs = yield* FileSystem.FileSystem;
246 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
247 yield* fs.writeFileString(
248 keybindingsConfigPath,
249 // @effect-diagnostics-next-line preferSchemaOverJson:off
250 JSON.stringify([
251 { key: "mod+j", command: "terminal.toggle" },
252 { key: "mod+shift+d+o", command: "terminal.new" },
253 { key: "mod+x", command: "invalid.command" },
254 ]),
255 );
256
257 const configState = yield* Effect.gen(function* () {
258 const keybindings = yield* Keybindings.Keybindings;
259 return yield* keybindings.loadConfigState;
260 });
261
262 assert.isTrue(configState.keybindings.some((entry) => entry.command === "terminal.toggle"));
263 assert.isFalse(
264 configState.keybindings.some((entry) => String(entry.command) === "invalid.command"),
265 );
266 assert.deepEqual(configState.issues, [
267 {
268 kind: "keybindings.invalid-entry",
269 index: 1,
270 message: configState.issues[0]?.message ?? "",
271 },
272 {
273 kind: "keybindings.invalid-entry",
274 index: 2,
275 message: configState.issues[1]?.message ?? "",
276 },
277 ]);
278 }).pipe(Effect.provide(makeKeybindingsLayer())),
279 );
280
281 it.effect(
282 "upserts missing default keybindings on startup without overriding existing command rules",
283 () =>
284 Effect.gen(function* () {
285 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
286 yield* writeKeybindingsConfig(keybindingsConfigPath, [
287 { key: "mod+shift+t", command: "terminal.toggle" },
288 { key: "mod+shift+r", command: "script.run-tests.run" },
289 ]);
290
291 yield* Effect.gen(function* () {
292 const keybindings = yield* Keybindings.Keybindings;
293 yield* keybindings.syncDefaultKeybindingsOnStartup;
294 });
295
296 const persisted = yield* readKeybindingsConfig(keybindingsConfigPath);
297 const byCommand = new Map(persisted.map((entry) => [entry.command, entry]));
298
299 const persistedToggle = byCommand.get("terminal.toggle");
300 assert.isNotNull(persistedToggle);
301 assert.equal(persistedToggle?.key, "mod+shift+t");
302 assert.isFalse(
303 persisted.some((entry) => entry.command === "terminal.toggle" && entry.key === "mod+j"),
304 );
305
306 for (const defaultRule of Keybindings.DEFAULT_KEYBINDINGS) {
307 assert.isTrue(byCommand.has(defaultRule.command), `expected ${defaultRule.command}`);
308 }
309 assert.isTrue(byCommand.has("script.run-tests.run"));
310 }).pipe(Effect.provide(makeKeybindingsLayer())),
311 );
312
313 it.effect("skips conflicting default keybindings on startup and logs a detailed warning", () => {
314 const messages: string[] = [];
315 const logger = Logger.make(({ message }) => {
316 messages.push(String(message));
317 });
318
319 return Effect.gen(function* () {
320 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
321 yield* writeKeybindingsConfig(keybindingsConfigPath, [
322 { key: "mod+j", command: "script.custom-action.run" },
323 ]);
324
325 yield* Effect.gen(function* () {
326 const keybindings = yield* Keybindings.Keybindings;
327 yield* keybindings.syncDefaultKeybindingsOnStartup;
328 });
329
330 const persisted = yield* readKeybindingsConfig(keybindingsConfigPath);
331 assert.isFalse(persisted.some((entry) => entry.command === "terminal.toggle"));
332 assert.isTrue(persisted.some((entry) => entry.command === "script.custom-action.run"));
333
334 assert.isTrue(
335 messages.some((message) =>
336 message.includes("skipping default keybinding due to shortcut conflict"),
337 ),
338 );
339 }).pipe(
340 Effect.provide(
341 Layer.mergeAll(
342 makeKeybindingsLayer(),
343 Logger.layer([logger], { mergeWithExisting: false }),
344 ),
345 ),
346 );
347 });
348
349 it.effect("upserts custom keybindings to configured path", () =>
350 Effect.gen(function* () {
351 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
352 yield* writeKeybindingsConfig(keybindingsConfigPath, [
353 { key: "mod+j", command: "terminal.toggle" },
354 ]);
355
356 const resolved = yield* Effect.gen(function* () {
357 const keybindings = yield* Keybindings.Keybindings;
358 return yield* keybindings.upsertKeybindingRule({
359 key: "mod+shift+r",
360 command: "script.run-tests.run",
361 });
362 });
363
364 const persisted = yield* readKeybindingsConfig(keybindingsConfigPath);
365 const persistedView = persisted.map(({ key, command }) => ({ key, command }));
366
367 assert.deepEqual(persistedView, [
368 { key: "mod+j", command: "terminal.toggle" },
369 { key: "mod+shift+r", command: "script.run-tests.run" },
370 ]);
371 assert.isTrue(resolved.some((entry) => entry.command === "script.run-tests.run"));
372 }).pipe(Effect.provide(makeKeybindingsLayer())),
373 );
374
375 it.effect("appends additional custom keybindings for the same command", () =>
376 Effect.gen(function* () {
377 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
378 yield* writeKeybindingsConfig(keybindingsConfigPath, [
379 { key: "mod+r", command: "script.run-tests.run" },
380 ]);
381 yield* Effect.gen(function* () {
382 const keybindings = yield* Keybindings.Keybindings;
383 return yield* keybindings.upsertKeybindingRule({
384 key: "mod+shift+r",
385 command: "script.run-tests.run",
386 });
387 });
388
389 const persisted = yield* readKeybindingsConfig(keybindingsConfigPath);
390 const persistedView = persisted.map(({ key, command }) => ({ key, command }));
391 assert.deepEqual(persistedView, [
392 { key: "mod+r", command: "script.run-tests.run" },
393 { key: "mod+shift+r", command: "script.run-tests.run" },
394 ]);
395 }).pipe(Effect.provide(makeKeybindingsLayer())),
396 );
397
398 it.effect("replaces only the targeted custom keybinding", () =>
399 Effect.gen(function* () {
400 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
401 yield* writeKeybindingsConfig(keybindingsConfigPath, [
402 { key: "mod+r", command: "script.run-tests.run" },
403 { key: "mod+shift+r", command: "script.run-tests.run" },
404 ]);
405 yield* Effect.gen(function* () {
406 const keybindings = yield* Keybindings.Keybindings;
407 return yield* keybindings.upsertKeybindingRule({
408 key: "mod+alt+r",
409 command: "script.run-tests.run",
410 replace: { key: "mod+r", command: "script.run-tests.run" },
411 });
412 });
413
414 const persisted = yield* readKeybindingsConfig(keybindingsConfigPath);
415 const persistedView = persisted.map(({ key, command }) => ({ key, command }));
416 assert.deepEqual(persistedView, [
417 { key: "mod+shift+r", command: "script.run-tests.run" },
418 { key: "mod+alt+r", command: "script.run-tests.run" },
419 ]);
420 }).pipe(Effect.provide(makeKeybindingsLayer())),
421 );
422
423 it.effect("replacing with a rule that already exists elsewhere does not duplicate it", () =>
424 Effect.gen(function* () {
425 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
426 yield* writeKeybindingsConfig(keybindingsConfigPath, [
427 { key: "mod+r", command: "script.run-tests.run" },
428 { key: "mod+alt+r", command: "script.run-tests.run" },
429 ]);
430 yield* Effect.gen(function* () {
431 const keybindings = yield* Keybindings.Keybindings;
432 return yield* keybindings.upsertKeybindingRule({
433 key: "mod+alt+r",
434 command: "script.run-tests.run",
435 replace: { key: "mod+r", command: "script.run-tests.run" },
436 });
437 });
438
439 const persisted = yield* readKeybindingsConfig(keybindingsConfigPath);
440 const persistedView = persisted.map(({ key, command }) => ({ key, command }));
441 assert.deepEqual(persistedView, [{ key: "mod+alt+r", command: "script.run-tests.run" }]);
442 }).pipe(Effect.provide(makeKeybindingsLayer())),
443 );
444
445 it.effect("removes only the targeted custom keybinding", () =>
446 Effect.gen(function* () {
447 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
448 yield* writeKeybindingsConfig(keybindingsConfigPath, [
449 { key: "mod+r", command: "script.run-tests.run" },
450 { key: "mod+shift+r", command: "script.run-tests.run" },
451 ]);
452 yield* Effect.gen(function* () {
453 const keybindings = yield* Keybindings.Keybindings;
454 return yield* keybindings.removeKeybindingRule({
455 key: "mod+r",
456 command: "script.run-tests.run",
457 });
458 });
459
460 const persisted = yield* readKeybindingsConfig(keybindingsConfigPath);
461 const persistedView = persisted.map(({ key, command }) => ({ key, command }));
462 assert.deepEqual(persistedView, [{ key: "mod+shift+r", command: "script.run-tests.run" }]);
463 }).pipe(Effect.provide(makeKeybindingsLayer())),
464 );
465
466 it.effect("refuses to overwrite malformed keybindings config", () =>
467 Effect.gen(function* () {
468 const fs = yield* FileSystem.FileSystem;
469 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
470 yield* fs.writeFileString(keybindingsConfigPath, "{ not-json");
471
472 const result = yield* Effect.gen(function* () {
473 const keybindings = yield* Keybindings.Keybindings;
474 return yield* keybindings.upsertKeybindingRule({
475 key: "mod+shift+r",
476 command: "script.run-tests.run",
477 });
478 }).pipe(toDetailResult);
479 assertFailure(result, "expected JSON array");
480
481 const persistedRaw = yield* fs.readFileString(keybindingsConfigPath);
482 assert.equal(persistedRaw, "{ not-json");
483 }).pipe(Effect.provide(makeKeybindingsLayer())),
484 );
485
486 it.effect("reports non-array config parse errors without duplicate prefix", () =>
487 Effect.gen(function* () {
488 const fs = yield* FileSystem.FileSystem;
489 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
490 yield* fs.writeFileString(
491 keybindingsConfigPath,
492 '{"key":"mod+j","command":"terminal.toggle"}',
493 );
494
495 const firstResult = yield* Effect.gen(function* () {
496 const keybindings = yield* Keybindings.Keybindings;
497 return yield* keybindings.upsertKeybindingRule({
498 key: "mod+shift+r",
499 command: "script.run-tests.run",
500 });
501 }).pipe(toDetailResult);
502 assertFailure(firstResult, "expected JSON array");
503
504 const secondResult = yield* Effect.gen(function* () {
505 const keybindings = yield* Keybindings.Keybindings;
506 return yield* keybindings.upsertKeybindingRule({
507 key: "mod+shift+r",
508 command: "script.run-tests.run",
509 });
510 }).pipe(toDetailResult);
511 assertFailure(secondResult, "expected JSON array");
512 }).pipe(Effect.provide(makeKeybindingsLayer())),
513 );
514
515 // chmod cannot make a directory unwritable on Windows, so the write succeeds.
516 it.effect.skipIf(HostProcessPlatform.defaultValue() === "win32")(
517 "fails when config directory is not writable",
518 () =>
519 Effect.gen(function* () {
520 const fs = yield* FileSystem.FileSystem;
521 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
522 const { dirname } = yield* Path.Path;
523 yield* writeKeybindingsConfig(keybindingsConfigPath, [
524 { key: "mod+j", command: "terminal.toggle" },
525 ]);
526 yield* fs.chmod(dirname(keybindingsConfigPath), 0o500);
527
528 const result = yield* Effect.gen(function* () {
529 const keybindings = yield* Keybindings.Keybindings;
530 return yield* keybindings.upsertKeybindingRule({
531 key: "mod+shift+r",
532 command: "script.run-tests.run",
533 });
534 }).pipe(toDetailResult);
535 assertFailure(result, "failed to write keybindings config");
536
537 yield* fs.chmod(dirname(keybindingsConfigPath), 0o700);
538
539 const persisted = yield* readKeybindingsConfig(keybindingsConfigPath);
540 const persistedView = persisted.map(({ key, command }) => ({ key, command }));
541 assert.deepEqual(persistedView, [{ key: "mod+j", command: "terminal.toggle" }]);
542 }).pipe(Effect.provide(makeKeybindingsLayer())),
543 );
544
545 it.effect("caches loaded resolved config across repeated reads", () =>
546 Effect.gen(function* () {
547 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
548 yield* writeKeybindingsConfig(keybindingsConfigPath, [
549 { key: "mod+j", command: "terminal.toggle" },
550 ]);
551
552 const [first, second] = yield* Effect.gen(function* () {
553 const keybindings = yield* Keybindings.Keybindings;
554 const firstLoad = (yield* keybindings.loadConfigState).keybindings;
555 const secondLoad = (yield* keybindings.loadConfigState).keybindings;
556 return [firstLoad, secondLoad] as const;
557 });
558
559 assert.deepEqual(first, second);
560 assert.isTrue(second.some((entry) => entry.command === "terminal.toggle"));
561 }).pipe(Effect.provide(makeKeybindingsLayer())),
562 );
563
564 it.effect("updates cached resolved config after upsert", () =>
565 Effect.gen(function* () {
566 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
567 yield* writeKeybindingsConfig(keybindingsConfigPath, [
568 { key: "mod+j", command: "terminal.toggle" },
569 ]);
570
571 const loadedAfterUpsert = yield* Effect.gen(function* () {
572 const keybindings = yield* Keybindings.Keybindings;
573 yield* keybindings.loadConfigState;
574 yield* keybindings.upsertKeybindingRule({
575 key: "mod+shift+r",
576 command: "script.run-tests.run",
577 });
578 return (yield* keybindings.loadConfigState).keybindings;
579 });
580
581 assert.isTrue(loadedAfterUpsert.some((entry) => entry.command === "script.run-tests.run"));
582 assert.isTrue(loadedAfterUpsert.some((entry) => entry.command === "terminal.toggle"));
583 }).pipe(Effect.provide(makeKeybindingsLayer())),
584 );
585
586 it.effect("serializes concurrent upserts to avoid lost updates", () =>
587 Effect.gen(function* () {
588 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
589 yield* writeKeybindingsConfig(keybindingsConfigPath, []);
590
591 const commands = Array.from(
592 { length: 20 },
593 (_, index): KeybindingCommand => `script.concurrent-${index}.run`,
594 );
595 yield* Effect.gen(function* () {
596 const keybindings = yield* Keybindings.Keybindings;
597 yield* Effect.all(
598 commands.map((command, index) =>
599 keybindings.upsertKeybindingRule({
600 key: `mod+${String.fromCharCode(97 + index)}`,
601 command,
602 }),
603 ),
604 { concurrency: "unbounded", discard: true },
605 );
606 });
607
608 const persisted = yield* readKeybindingsConfig(keybindingsConfigPath);
609 const persistedCommands = new Set(persisted.map((entry) => entry.command));
610 for (const command of commands) {
611 assert.isTrue(persistedCommands.has(command), `expected persisted command ${command}`);
612 }
613 }).pipe(Effect.provide(makeKeybindingsLayer())),
614 );
615});