@fungi.computer/inkcap 0.18.0 → 0.18.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -136,7 +136,7 @@ function parentFolder(path: string) {
136
136
  function parentNotFound(path: string) {
137
137
  return {
138
138
  error: "parent_not_found" as const,
139
- message: `The folder ${parentFolder(path)} does not exist and could not be created. Save into an existing folder (for example /notes.md at the top level), or list folders with listFiles.`,
139
+ message: `The folder ${parentFolder(path)} does not exist and could not be created. Save into an existing folder (for example /workspace/notes.md at the top level), or list folders with listFiles.`,
140
140
  };
141
141
  }
142
142
  function fileGone(path: string) {
@@ -257,7 +257,7 @@ export const appBackend = defineAppBackend({
257
257
  }),
258
258
  writeFile: defineAppMethod({
259
259
  description:
260
- "Write UTF-8 text on the attached Computer. A missing folder is created first; if it cannot be created the write is refused as parent_not_found, and the path is on the Computer, not the host machine. Supply expectedContent for a compare-and-swap; combined content is limited to 48 KiB. The host owns attribution and the attachment write budget.",
260
+ "Write UTF-8 text on the attached Computer. Missing parent folders are created first; a folder-creation refusal keeps its cause. Paths are on the Computer, not the host machine. Supply expectedContent for a compare-and-swap; combined content is limited to 48 KiB. The host owns attribution and the attachment write budget.",
261
261
  effect: "write",
262
262
  label: "Save a file on your Computer",
263
263
  requires: ["computer.writeFile"],
@@ -272,8 +272,8 @@ export const appBackend = defineAppBackend({
272
272
  id: "refused",
273
273
  title: "Inkcap could not write the file",
274
274
  detail:
275
- output.error === "parent_not_found"
276
- ? "That folder does not exist on the Computer"
275
+ "message" in output
276
+ ? output.message
277
277
  : computerRefusalMessage(output.error),
278
278
  tone: "error",
279
279
  }
@@ -319,7 +319,8 @@ export const appBackend = defineAppBackend({
319
319
  absent,
320
320
  ),
321
321
  );
322
- return "error" in made ? absent : await attempt();
322
+ if ("error" in made) return made.error === "not_found" ? absent : made;
323
+ return await attempt();
323
324
  },
324
325
  }),
325
326
  },
@@ -642,7 +642,7 @@ it("refuses a missing folder or file as not_found instead of throwing an opaque
642
642
  );
643
643
  expect(inBand).toMatchObject({ error: "parent_not_found" });
644
644
  expect(JSON.stringify(inBand)).toContain("The folder /x does not exist");
645
- expect(JSON.stringify(inBand)).toContain("for example /notes.md");
645
+ expect(JSON.stringify(inBand)).toContain("for example /workspace/notes.md");
646
646
  // An edit of a file that was deleted is not a folder problem.
647
647
  const gone = await appBackend.call(
648
648
  "writeFile",
@@ -745,3 +745,32 @@ it("does not create folders for an edit of an existing file", async () => {
745
745
  expect(gone).toMatchObject({ error: "not_found" });
746
746
  expect(mkdir).not.toHaveBeenCalled();
747
747
  });
748
+
749
+ it.each([
750
+ { error: "not_granted" },
751
+ { error: "attachment_budget_exceeded", kind: "write", retryAfterMs: 2000 },
752
+ ] as const)(
753
+ "keeps the folder creation refusal $error instead of calling it a missing folder",
754
+ async (refused) => {
755
+ const write = vi.fn(() => Promise.resolve({ error: "not_found" }));
756
+ const result = await appBackend.call(
757
+ "writeFile",
758
+ { path: "/workspace/Notes & Drafts/README.md", content: "Draft" },
759
+ {
760
+ activity,
761
+ documentsChanged,
762
+ env: {
763
+ ...unrelated,
764
+ COMPUTER: {
765
+ ...unrelated.COMPUTER,
766
+ write,
767
+ mkdir: () => Promise.resolve(z.json().parse(refused)),
768
+ },
769
+ },
770
+ },
771
+ caller,
772
+ );
773
+ expect(result).toEqual(refused);
774
+ expect(write).toHaveBeenCalledTimes(1);
775
+ },
776
+ );
@@ -23,3 +23,14 @@ it("reads a refused write as an error row", () => {
23
23
  ),
24
24
  ).toMatchObject({ title: "Inkcap could not write the file", tone: "error" });
25
25
  });
26
+
27
+ it("shows the named folder cause in the refused write row", () => {
28
+ const message =
29
+ "The folder /workspace/Notes & Drafts does not exist and could not be created.";
30
+ expect(
31
+ appBackend.methods.writeFile?.present?.(
32
+ { path: "/workspace/Notes & Drafts/README.md", content: "Draft" },
33
+ { error: "parent_not_found", message },
34
+ ),
35
+ ).toMatchObject({ detail: message, tone: "error" });
36
+ });