| 1 | import assert from "node:assert/strict"; |
| 2 | import { JSDOM } from "jsdom"; |
| 3 | import { |
| 4 | fullAccessProjectConfirmationKey, |
| 5 | hasConfirmedFullAccessForProject, |
| 6 | rememberFullAccessConfirmationForProject, |
| 7 | } from "../lib/fullAccessConfirmation"; |
| 8 | |
| 9 | const dom = new JSDOM("", { url: "http://localhost" }); |
| 10 | globalThis.localStorage = dom.window.localStorage; |
| 11 | |
| 12 | try { |
| 13 | const project = fullAccessProjectConfirmationKey({ workspacePath: "/repo/project/" }); |
| 14 | const sameProject = fullAccessProjectConfirmationKey({ workspacePath: " /repo/project " }); |
| 15 | const otherProject = fullAccessProjectConfirmationKey({ workspacePath: "/repo/other" }); |
| 16 | const remoteProject = fullAccessProjectConfirmationKey({ workspacePath: "/repo/project", remoteHostId: "host-a" }); |
| 17 | const otherRemoteHost = fullAccessProjectConfirmationKey({ workspacePath: "/repo/project", remoteHostId: "host-b" }); |
| 18 | |
| 19 | assert.equal(project, sameProject, "cosmetic trailing separators do not create a new project identity"); |
| 20 | assert.notEqual(project, otherProject, "different project folders remain isolated"); |
| 21 | assert.notEqual(project, remoteProject, "local and remote projects never share confirmation state"); |
| 22 | assert.notEqual(remoteProject, otherRemoteHost, "remote hosts with the same path remain isolated"); |
| 23 | assert.equal(fullAccessProjectConfirmationKey({}), "", "an unknown folder cannot persist an acknowledgement"); |
| 24 | |
| 25 | assert.equal(hasConfirmedFullAccessForProject(project), false); |
| 26 | rememberFullAccessConfirmationForProject(project); |
| 27 | assert.equal(hasConfirmedFullAccessForProject(project), true, "confirmed projects survive later reads"); |
| 28 | assert.equal(hasConfirmedFullAccessForProject(otherProject), false); |
| 29 | assert.equal(hasConfirmedFullAccessForProject(remoteProject), false); |
| 30 | |
| 31 | localStorage.setItem("reasonix-full-access-confirmed-projects-v1", "not-json"); |
| 32 | assert.equal(hasConfirmedFullAccessForProject(project), false, "invalid persisted data fails safely"); |
| 33 | rememberFullAccessConfirmationForProject(project); |
| 34 | assert.equal(hasConfirmedFullAccessForProject(project), true, "invalid persisted data can be repaired by a new confirmation"); |
| 35 | |
| 36 | console.log("full access confirmation: project persistence and isolation passed"); |
| 37 | } finally { |
| 38 | dom.window.close(); |
| 39 | } |
| 40 |