@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.
- package/backend/methods.ts +6 -5
- package/backend/test/methods.test.ts +30 -1
- package/backend/test/present.test.ts +11 -0
- package/dist/assets/{FileTab-Dh_MXYyL.js → FileTab-zF5NkUyI.js} +42 -42
- package/dist/assets/InkcapFileTree-C6fCPfVL.js +1 -0
- package/dist/assets/{InkcapRepositoryApp-D0pW-5wq.js → InkcapRepositoryApp-Q7oVxGhL.js} +1 -1
- package/dist/assets/changes-patch-zJT5MXFh.js +45 -0
- package/dist/assets/{dropdown-menu-D1-KaUEJ.js → dropdown-menu-tOc7lHNr.js} +11 -11
- package/dist/assets/index-Bd5Z2Jjo.js +2 -0
- package/dist/assets/{tree-path-AxEg-Kjh.js → tree-path-u_q4dC9E.js} +12 -12
- package/dist/assets/{useFileTree-C86PCVGL.js → useFileTree-K8mSEqOR.js} +1 -1
- package/dist/assets/{useForm-BDtDFyLf.js → useForm-CLwjuIXa.js} +1 -1
- package/dist/index.html +4 -4
- package/package.json +6 -6
- package/dist/assets/InkcapFileTree-BOkmSC0u.js +0 -1
- package/dist/assets/changes-patch-CrPexAyH.js +0 -45
- package/dist/assets/index-DqkwqNVw.js +0 -2
package/backend/methods.ts
CHANGED
|
@@ -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.
|
|
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
|
-
|
|
276
|
-
?
|
|
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
|
-
|
|
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
|
+
});
|