Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

keybindings.test.ts

609 lines23.0 KB

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