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

keybindings.test.ts

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