repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

fix(the-system): make doctor notification transient

f5256df044e839c8b4508e215f02de2e867194c4

Oliver Jan Krylow <oliver@bugabinga.net> ·

SSH signature · not checked

Browse filesCompare with HEAD

Changed files (2)

extensions/the-system/__tests__/the-system.test.ts

Modified
692 692 validSystem(project);
693 693 const command = createSystemCommand({ sendUserMessage() {} } as never);
694 694 const notices: string[] = [];
695 + const severities: string[] = [];
696 + let prompts = 0;
697 + let widgets = 0;
695 698 const ctx = {
696 699 cwd: project,
700 + hasUI: true,
697 701 waitForIdle: async () => {},
698 - ui: { notify: (message: string) => notices.push(message) },
702 + ui: {
703 + confirm: async () => {
704 + prompts += 1;
705 + return true;
706 + },
707 + notify: (message: string, severity: string) => {
708 + notices.push(message);
709 + severities.push(severity);
710 + },
711 + setWidget: () => {
712 + widgets += 1;
713 + },
714 + },
699 715 } as never;
700 716 await command.handler("doctor", ctx);
701 717 await command.handler("view PX-SPEC-SPEC0001", ctx);
703 719 await command.handler("view PX-SPEC-SPEC0001 extra", ctx);
704 720 await command.handler("edit PX-SPEC-SPEC0001 extra", ctx);
705 721 assert.match(notices[0] ?? "", /OK/);
722 + assert.equal(severities[0], "info");
723 + assert.equal(prompts, 0);
724 + assert.equal(widgets, 0);
706 725 assert.match(notices[1] ?? "", /System view written:/);
707 726 assert.match(notices[1] ?? "", /Open: file:\/\//);
708 727 assert.match(notices[2] ?? "", /System book written:/);

extensions/the-system/system-command.ts

Modified
114 114 if (parsed.subcommand === "doctor") {
115 115 const result = runDoctor(ctx.cwd);
116 - await showCommandResult(
117 - ctx,
116 + ctx.ui.notify(
118 117 formatDoctor(result),
119 118 result.exitCode === 0 ? "info" : "warning",
164 163 ].join("\n");
167 -async function showCommandResult(
168 - ctx: ExtensionCommandContext,
169 - message: string,
170 - severity: "info" | "warning" | "error",
171 -): Promise<void> {
172 - await new Promise((resolve) => setTimeout(resolve, 0));
173 - if (ctx.hasUI) await ctx.ui.confirm("System doctor", message);
174 - else ctx.ui.notify(message, severity);
175 - ctx.ui.setWidget?.("the-system", message.split("\n"));
178 166 async function runSystemInit(
179 167 pi: ExtensionAPI,
180 168 activateBundleMigration: (() => void) | undefined,