| 1 | import assert from "node:assert/strict"; |
| 2 | import { ordinaryFileSource } from "../lib/attachDedup"; |
| 3 | import { formatWorkspaceReference, parseWorkspaceReference } from "../lib/workspaceDrag"; |
| 4 | import { isExternalWorkspaceReference, restoreExternalFolderReferences } from "../lib/attachmentSubmit"; |
| 5 | import type { AppBindings } from "../lib/bridge"; |
| 6 | |
| 7 | const a = new File(["first"], "app.apk", { lastModified: 1 }); |
| 8 | const b = new File(["other"], "app.apk", { lastModified: 1 }); |
| 9 | assert.equal(ordinaryFileSource(a, ""), ordinaryFileSource(a, "")); |
| 10 | assert.notEqual(ordinaryFileSource(a, ""), ordinaryFileSource(b, "")); |
| 11 | assert.equal(ordinaryFileSource(a, "/outside/app.apk"), "path:/outside/app.apk"); |
| 12 | for (const path of ["/outside/large app.apk", "C:\\Downloads\\large app.apk", "src/main.go"]) { |
| 13 | assert.equal(parseWorkspaceReference(formatWorkspaceReference(path))?.path, path); |
| 14 | } |
| 15 | assert.equal(isExternalWorkspaceReference({ path: "/outside/large app.apk", displayPath: "/outside/large app.apk" }), true); |
| 16 | assert.equal(isExternalWorkspaceReference({ path: "C:/Downloads/large app.apk", displayPath: "C:/Downloads/large app.apk" }), true); |
| 17 | assert.equal(isExternalWorkspaceReference({ path: "src/main.go" }), false); |
| 18 | const calls: string[] = []; |
| 19 | const bindings: Partial<AppBindings> = { |
| 20 | CaptureAttachmentTarget: async () => ({ token: "captured", capabilities: ["attachments-v2"] }), |
| 21 | AttachDroppedForTarget: async (token: string, path: string) => { calls.push(`${token}:${path}`); return { kind: "workspace", path, displayPath: path }; }, |
| 22 | ReleaseAttachmentTarget: async (token: string) => { calls.push(`release:${token}`); }, |
| 23 | }; |
| 24 | await restoreExternalFolderReferences(bindings as AppBindings, { kind: "session", tabId: "source" }, [{ path: "/outside/large app.apk", displayPath: "/outside/large app.apk" }]); |
| 25 | assert.deepEqual(calls, ["captured:/outside/large app.apk", "release:captured"]); |
| 26 | console.log("attachment references: object identity, escaped paths and restored exact-file authorization passed"); |
| 27 |