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";
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.copyReference"), "mod+shift+c");
199 assert.equal(defaultsByCommand.get("thread.settle"), "mod+shift+s");
200 assert.equal(defaultsByCommand.get("thread.pin"), "mod+shift+p");
201 assert.equal(defaultsByCommand.get("thread.jump.1"), "mod+1");
202 assert.equal(defaultsByCommand.get("thread.jump.9"), "mod+9");
203 assert.equal(defaultsByCommand.get("modelPicker.toggle"), "mod+shift+m");
204 assert.equal(defaultsByCommand.get("themeEditor.toggle"), "mod+alt+shift+t");
205 assert.equal(defaultsByCommand.get("filePicker.toggle"), "mod+p");
206 assert.equal(defaultsByCommand.get("projectSearch.toggle"), "mod+shift+f");
207 assert.equal(defaultsByCommand.get("sidebar.toggle"), "mod+b");
208 assert.equal(defaultsByCommand.get("rightPanel.toggle"), "mod+alt+b");
209 assert.isFalse(defaultsByCommand.has("rightPanel.toggleMaximized"));
210 assert.equal(defaultsByCommand.get("rightPanel.close"), "mod+w");
211 assert.equal(defaultsByCommand.get("terminal.splitVertical"), "mod+shift+d");
212 assert.equal(defaultsByCommand.get("modelPicker.jump.1"), "mod+1");
213 assert.equal(defaultsByCommand.get("modelPicker.jump.9"), "mod+9");
214 }),
215 );
216
217 it.effect("uses defaults in runtime when config is malformed without overriding file", () =>
218 Effect.gen(function* () {
219 const fs = yield* FileSystem.FileSystem;
220 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
221 yield* fs.writeFileString(keybindingsConfigPath, "{ not-json");
222
223 const configState = yield* Effect.gen(function* () {
224 const keybindings = yield* Keybindings.Keybindings;
225 return yield* keybindings.loadConfigState;
226 });
227
228 assert.deepEqual(
229 configState.keybindings,
230 Keybindings.compileResolvedKeybindingsConfig(Keybindings.DEFAULT_KEYBINDINGS),
231 );
232 assert.deepEqual(configState.issues, [
233 {
234 kind: "keybindings.malformed-config",
235 message: configState.issues[0]?.message ?? "",
236 },
237 ]);
238 assert.equal(yield* fs.readFileString(keybindingsConfigPath), "{ not-json");
239 }).pipe(Effect.provide(makeKeybindingsLayer())),
240 );
241
242 it.effect("ignores invalid entries in runtime and reports them as issues", () =>
243 Effect.gen(function* () {
244 const fs = yield* FileSystem.FileSystem;
245 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
246 yield* fs.writeFileString(
247 keybindingsConfigPath,
248 // @effect-diagnostics-next-line preferSchemaOverJson:off
249 JSON.stringify([
250 { key: "mod+j", command: "terminal.toggle" },
251 { key: "mod+shift+d+o", command: "terminal.new" },
252 { key: "mod+x", command: "invalid.command" },
253 ]),
254 );
255
256 const configState = yield* Effect.gen(function* () {
257 const keybindings = yield* Keybindings.Keybindings;
258 return yield* keybindings.loadConfigState;
259 });
260
261 assert.isTrue(configState.keybindings.some((entry) => entry.command === "terminal.toggle"));
262 assert.isFalse(
263 configState.keybindings.some((entry) => String(entry.command) === "invalid.command"),
264 );
265 assert.deepEqual(configState.issues, [
266 {
267 kind: "keybindings.invalid-entry",
268 index: 1,
269 message: configState.issues[0]?.message ?? "",
270 },
271 {
272 kind: "keybindings.invalid-entry",
273 index: 2,
274 message: configState.issues[1]?.message ?? "",
275 },
276 ]);
277 }).pipe(Effect.provide(makeKeybindingsLayer())),
278 );
279
280 it.effect(
281 "upserts missing default keybindings on startup without overriding existing command rules",
282 () =>
283 Effect.gen(function* () {
284 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
285 yield* writeKeybindingsConfig(keybindingsConfigPath, [
286 { key: "mod+shift+t", command: "terminal.toggle" },
287 { key: "mod+shift+r", command: "script.run-tests.run" },
288 ]);
289
290 yield* Effect.gen(function* () {
291 const keybindings = yield* Keybindings.Keybindings;
292 yield* keybindings.syncDefaultKeybindingsOnStartup;
293 });
294
295 const persisted = yield* readKeybindingsConfig(keybindingsConfigPath);
296 const byCommand = new Map(persisted.map((entry) => [entry.command, entry]));
297
298 const persistedToggle = byCommand.get("terminal.toggle");
299 assert.isNotNull(persistedToggle);
300 assert.equal(persistedToggle?.key, "mod+shift+t");
301 assert.isFalse(
302 persisted.some((entry) => entry.command === "terminal.toggle" && entry.key === "mod+j"),
303 );
304
305 for (const defaultRule of Keybindings.DEFAULT_KEYBINDINGS) {
306 assert.isTrue(byCommand.has(defaultRule.command), `expected ${defaultRule.command}`);
307 }
308 assert.isTrue(byCommand.has("script.run-tests.run"));
309 }).pipe(Effect.provide(makeKeybindingsLayer())),
310 );
311
312 it.effect("skips conflicting default keybindings on startup and logs a detailed warning", () => {
313 const messages: string[] = [];
314 const logger = Logger.make(({ message }) => {
315 messages.push(String(message));
316 });
317
318 return Effect.gen(function* () {
319 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
320 yield* writeKeybindingsConfig(keybindingsConfigPath, [
321 { key: "mod+j", command: "script.custom-action.run" },
322 ]);
323
324 yield* Effect.gen(function* () {
325 const keybindings = yield* Keybindings.Keybindings;
326 yield* keybindings.syncDefaultKeybindingsOnStartup;
327 });
328
329 const persisted = yield* readKeybindingsConfig(keybindingsConfigPath);
330 assert.isFalse(persisted.some((entry) => entry.command === "terminal.toggle"));
331 assert.isTrue(persisted.some((entry) => entry.command === "script.custom-action.run"));
332
333 assert.isTrue(
334 messages.some((message) =>
335 message.includes("skipping default keybinding due to shortcut conflict"),
336 ),
337 );
338 }).pipe(
339 Effect.provide(
340 Layer.mergeAll(
341 makeKeybindingsLayer(),
342 Logger.layer([logger], { mergeWithExisting: false }),
343 ),
344 ),
345 );
346 });
347
348 it.effect("upserts custom keybindings to configured path", () =>
349 Effect.gen(function* () {
350 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
351 yield* writeKeybindingsConfig(keybindingsConfigPath, [
352 { key: "mod+j", command: "terminal.toggle" },
353 ]);
354
355 const resolved = yield* Effect.gen(function* () {
356 const keybindings = yield* Keybindings.Keybindings;
357 return yield* keybindings.upsertKeybindingRule({
358 key: "mod+shift+r",
359 command: "script.run-tests.run",
360 });
361 });
362
363 const persisted = yield* readKeybindingsConfig(keybindingsConfigPath);
364 const persistedView = persisted.map(({ key, command }) => ({ key, command }));
365
366 assert.deepEqual(persistedView, [
367 { key: "mod+j", command: "terminal.toggle" },
368 { key: "mod+shift+r", command: "script.run-tests.run" },
369 ]);
370 assert.isTrue(resolved.some((entry) => entry.command === "script.run-tests.run"));
371 }).pipe(Effect.provide(makeKeybindingsLayer())),
372 );
373
374 it.effect("appends additional custom keybindings for the same command", () =>
375 Effect.gen(function* () {
376 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
377 yield* writeKeybindingsConfig(keybindingsConfigPath, [
378 { key: "mod+r", command: "script.run-tests.run" },
379 ]);
380 yield* Effect.gen(function* () {
381 const keybindings = yield* Keybindings.Keybindings;
382 return yield* keybindings.upsertKeybindingRule({
383 key: "mod+shift+r",
384 command: "script.run-tests.run",
385 });
386 });
387
388 const persisted = yield* readKeybindingsConfig(keybindingsConfigPath);
389 const persistedView = persisted.map(({ key, command }) => ({ key, command }));
390 assert.deepEqual(persistedView, [
391 { key: "mod+r", command: "script.run-tests.run" },
392 { key: "mod+shift+r", command: "script.run-tests.run" },
393 ]);
394 }).pipe(Effect.provide(makeKeybindingsLayer())),
395 );
396
397 it.effect("replaces only the targeted custom keybinding", () =>
398 Effect.gen(function* () {
399 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
400 yield* writeKeybindingsConfig(keybindingsConfigPath, [
401 { key: "mod+r", command: "script.run-tests.run" },
402 { key: "mod+shift+r", command: "script.run-tests.run" },
403 ]);
404 yield* Effect.gen(function* () {
405 const keybindings = yield* Keybindings.Keybindings;
406 return yield* keybindings.upsertKeybindingRule({
407 key: "mod+alt+r",
408 command: "script.run-tests.run",
409 replace: { key: "mod+r", command: "script.run-tests.run" },
410 });
411 });
412
413 const persisted = yield* readKeybindingsConfig(keybindingsConfigPath);
414 const persistedView = persisted.map(({ key, command }) => ({ key, command }));
415 assert.deepEqual(persistedView, [
416 { key: "mod+shift+r", command: "script.run-tests.run" },
417 { key: "mod+alt+r", command: "script.run-tests.run" },
418 ]);
419 }).pipe(Effect.provide(makeKeybindingsLayer())),
420 );
421
422 it.effect("replacing with a rule that already exists elsewhere does not duplicate it", () =>
423 Effect.gen(function* () {
424 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
425 yield* writeKeybindingsConfig(keybindingsConfigPath, [
426 { key: "mod+r", command: "script.run-tests.run" },
427 { key: "mod+alt+r", command: "script.run-tests.run" },
428 ]);
429 yield* Effect.gen(function* () {
430 const keybindings = yield* Keybindings.Keybindings;
431 return yield* keybindings.upsertKeybindingRule({
432 key: "mod+alt+r",
433 command: "script.run-tests.run",
434 replace: { key: "mod+r", command: "script.run-tests.run" },
435 });
436 });
437
438 const persisted = yield* readKeybindingsConfig(keybindingsConfigPath);
439 const persistedView = persisted.map(({ key, command }) => ({ key, command }));
440 assert.deepEqual(persistedView, [{ key: "mod+alt+r", command: "script.run-tests.run" }]);
441 }).pipe(Effect.provide(makeKeybindingsLayer())),
442 );
443
444 it.effect("removes only the targeted custom keybinding", () =>
445 Effect.gen(function* () {
446 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
447 yield* writeKeybindingsConfig(keybindingsConfigPath, [
448 { key: "mod+r", command: "script.run-tests.run" },
449 { key: "mod+shift+r", command: "script.run-tests.run" },
450 ]);
451 yield* Effect.gen(function* () {
452 const keybindings = yield* Keybindings.Keybindings;
453 return yield* keybindings.removeKeybindingRule({
454 key: "mod+r",
455 command: "script.run-tests.run",
456 });
457 });
458
459 const persisted = yield* readKeybindingsConfig(keybindingsConfigPath);
460 const persistedView = persisted.map(({ key, command }) => ({ key, command }));
461 assert.deepEqual(persistedView, [{ key: "mod+shift+r", command: "script.run-tests.run" }]);
462 }).pipe(Effect.provide(makeKeybindingsLayer())),
463 );
464
465 it.effect("refuses to overwrite malformed keybindings config", () =>
466 Effect.gen(function* () {
467 const fs = yield* FileSystem.FileSystem;
468 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
469 yield* fs.writeFileString(keybindingsConfigPath, "{ not-json");
470
471 const result = yield* Effect.gen(function* () {
472 const keybindings = yield* Keybindings.Keybindings;
473 return yield* keybindings.upsertKeybindingRule({
474 key: "mod+shift+r",
475 command: "script.run-tests.run",
476 });
477 }).pipe(toDetailResult);
478 assertFailure(result, "expected JSON array");
479
480 const persistedRaw = yield* fs.readFileString(keybindingsConfigPath);
481 assert.equal(persistedRaw, "{ not-json");
482 }).pipe(Effect.provide(makeKeybindingsLayer())),
483 );
484
485 it.effect("reports non-array config parse errors without duplicate prefix", () =>
486 Effect.gen(function* () {
487 const fs = yield* FileSystem.FileSystem;
488 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
489 yield* fs.writeFileString(
490 keybindingsConfigPath,
491 '{"key":"mod+j","command":"terminal.toggle"}',
492 );
493
494 const firstResult = yield* Effect.gen(function* () {
495 const keybindings = yield* Keybindings.Keybindings;
496 return yield* keybindings.upsertKeybindingRule({
497 key: "mod+shift+r",
498 command: "script.run-tests.run",
499 });
500 }).pipe(toDetailResult);
501 assertFailure(firstResult, "expected JSON array");
502
503 const secondResult = yield* Effect.gen(function* () {
504 const keybindings = yield* Keybindings.Keybindings;
505 return yield* keybindings.upsertKeybindingRule({
506 key: "mod+shift+r",
507 command: "script.run-tests.run",
508 });
509 }).pipe(toDetailResult);
510 assertFailure(secondResult, "expected JSON array");
511 }).pipe(Effect.provide(makeKeybindingsLayer())),
512 );
513
514 it.effect("fails when config directory is not writable", () =>
515 Effect.gen(function* () {
516 const fs = yield* FileSystem.FileSystem;
517 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
518 const { dirname } = yield* Path.Path;
519 yield* writeKeybindingsConfig(keybindingsConfigPath, [
520 { key: "mod+j", command: "terminal.toggle" },
521 ]);
522 yield* fs.chmod(dirname(keybindingsConfigPath), 0o500);
523
524 const result = yield* Effect.gen(function* () {
525 const keybindings = yield* Keybindings.Keybindings;
526 return yield* keybindings.upsertKeybindingRule({
527 key: "mod+shift+r",
528 command: "script.run-tests.run",
529 });
530 }).pipe(toDetailResult);
531 assertFailure(result, "failed to write keybindings config");
532
533 yield* fs.chmod(dirname(keybindingsConfigPath), 0o700);
534
535 const persisted = yield* readKeybindingsConfig(keybindingsConfigPath);
536 const persistedView = persisted.map(({ key, command }) => ({ key, command }));
537 assert.deepEqual(persistedView, [{ key: "mod+j", command: "terminal.toggle" }]);
538 }).pipe(Effect.provide(makeKeybindingsLayer())),
539 );
540
541 it.effect("caches loaded resolved config across repeated reads", () =>
542 Effect.gen(function* () {
543 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
544 yield* writeKeybindingsConfig(keybindingsConfigPath, [
545 { key: "mod+j", command: "terminal.toggle" },
546 ]);
547
548 const [first, second] = yield* Effect.gen(function* () {
549 const keybindings = yield* Keybindings.Keybindings;
550 const firstLoad = (yield* keybindings.loadConfigState).keybindings;
551 const secondLoad = (yield* keybindings.loadConfigState).keybindings;
552 return [firstLoad, secondLoad] as const;
553 });
554
555 assert.deepEqual(first, second);
556 assert.isTrue(second.some((entry) => entry.command === "terminal.toggle"));
557 }).pipe(Effect.provide(makeKeybindingsLayer())),
558 );
559
560 it.effect("updates cached resolved config after upsert", () =>
561 Effect.gen(function* () {
562 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
563 yield* writeKeybindingsConfig(keybindingsConfigPath, [
564 { key: "mod+j", command: "terminal.toggle" },
565 ]);
566
567 const loadedAfterUpsert = yield* Effect.gen(function* () {
568 const keybindings = yield* Keybindings.Keybindings;
569 yield* keybindings.loadConfigState;
570 yield* keybindings.upsertKeybindingRule({
571 key: "mod+shift+r",
572 command: "script.run-tests.run",
573 });
574 return (yield* keybindings.loadConfigState).keybindings;
575 });
576
577 assert.isTrue(loadedAfterUpsert.some((entry) => entry.command === "script.run-tests.run"));
578 assert.isTrue(loadedAfterUpsert.some((entry) => entry.command === "terminal.toggle"));
579 }).pipe(Effect.provide(makeKeybindingsLayer())),
580 );
581
582 it.effect("serializes concurrent upserts to avoid lost updates", () =>
583 Effect.gen(function* () {
584 const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
585 yield* writeKeybindingsConfig(keybindingsConfigPath, []);
586
587 const commands = Array.from(
588 { length: 20 },
589 (_, index): KeybindingCommand => `script.concurrent-${index}.run`,
590 );
591 yield* Effect.gen(function* () {
592 const keybindings = yield* Keybindings.Keybindings;
593 yield* Effect.all(
594 commands.map((command, index) =>
595 keybindings.upsertKeybindingRule({
596 key: `mod+${String.fromCharCode(97 + index)}`,
597 command,
598 }),
599 ),
600 { concurrency: "unbounded", discard: true },
601 );
602 });
603
604 const persisted = yield* readKeybindingsConfig(keybindingsConfigPath);
605 const persistedCommands = new Set(persisted.map((entry) => entry.command));
606 for (const command of commands) {
607 assert.isTrue(persistedCommands.has(command), `expected persisted command ${command}`);
608 }
609 }).pipe(Effect.provide(makeKeybindingsLayer())),
610 );
611});