|
| 1 | +import assert from "node:assert/strict"; |
| 2 | +import fs from "node:fs"; |
| 3 | +import path from "node:path"; |
| 4 | +import { execFileSync } from "node:child_process"; |
| 5 | +import { fileURLToPath, pathToFileURL } from "node:url"; |
| 6 | + |
| 7 | +const __filename = fileURLToPath(import.meta.url); |
| 8 | +const __dirname = path.dirname(__filename); |
| 9 | +const repoRoot = path.resolve(__dirname, "..", ".."); |
| 10 | +const htmlPath = path.join(repoRoot, "tools", "workspace-v2", "index.html"); |
| 11 | +const jsPath = path.join(repoRoot, "tools", "workspace-v2", "index.js"); |
| 12 | +const resultsPath = path.join(repoRoot, "tmp", "v2-session-id-usability-results.json"); |
| 13 | + |
| 14 | +function readText(filePath) { |
| 15 | + return fs.readFileSync(filePath, "utf8"); |
| 16 | +} |
| 17 | + |
| 18 | +function checkSyntax(jsFilePath) { |
| 19 | + try { |
| 20 | + execFileSync(process.execPath, ["--check", jsFilePath], { |
| 21 | + cwd: repoRoot, |
| 22 | + stdio: ["ignore", "pipe", "pipe"] |
| 23 | + }); |
| 24 | + return { ok: true, error: "" }; |
| 25 | + } catch (error) { |
| 26 | + return { ok: false, error: (error?.stderr || error?.stdout || error?.message || "").toString().trim() }; |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +export function run() { |
| 31 | + const failures = []; |
| 32 | + const htmlExists = fs.existsSync(htmlPath); |
| 33 | + const jsExists = fs.existsSync(jsPath); |
| 34 | + const html = htmlExists ? readText(htmlPath) : ""; |
| 35 | + const js = jsExists ? readText(jsPath) : ""; |
| 36 | + const syntax = checkSyntax(jsPath); |
| 37 | + |
| 38 | + const hasSessionIdLabel = html.includes("Session ID (for Save / Load / Delete)"); |
| 39 | + const hasHelperText = html.includes("Use a session ID from Recent Sessions or saved library."); |
| 40 | + const hasCopyButtonText = js.includes("copyIdButton.textContent = \"Copy ID\";"); |
| 41 | + const hasUseButtonText = js.includes("useInLibraryButton.textContent = \"Use in Library\";"); |
| 42 | + const hasCopyMethod = js.includes("async copySessionIdToClipboard(hostContextId)"); |
| 43 | + const hasClipboardWrite = js.includes("await navigator.clipboard.writeText(hostContextId.trim());"); |
| 44 | + const hasUseMethod = js.includes("useSessionIdInLibraryInput(hostContextId)"); |
| 45 | + const hasUsePopulate = js.includes("this.sessionNameNode.value = hostContextId.trim();"); |
| 46 | + |
| 47 | + const deleteMethodStart = js.indexOf("deleteNamedSession() {"); |
| 48 | + const createSessionStart = js.indexOf("createSessionAndLaunch() {", deleteMethodStart); |
| 49 | + const deleteMethod = deleteMethodStart >= 0 && createSessionStart > deleteMethodStart |
| 50 | + ? js.slice(deleteMethodStart, createSessionStart) |
| 51 | + : ""; |
| 52 | + const deleteTouchesLibrary = deleteMethod.includes("const library = this.readSessionLibrary();") && |
| 53 | + deleteMethod.includes("delete library[sessionName];") && |
| 54 | + deleteMethod.includes("this.writeSessionLibrary(library);"); |
| 55 | + const deleteTouchesHistory = deleteMethod.includes("readSessionHistory(") || |
| 56 | + deleteMethod.includes("writeSessionHistory("); |
| 57 | + |
| 58 | + if (!htmlExists) failures.push("Missing tools/workspace-v2/index.html."); |
| 59 | + if (!jsExists) failures.push("Missing tools/workspace-v2/index.js."); |
| 60 | + if (!syntax.ok) failures.push("tools/workspace-v2/index.js failed syntax check."); |
| 61 | + if (!hasSessionIdLabel) failures.push("Session Name label was not updated to Session ID label."); |
| 62 | + if (!hasHelperText) failures.push("Session ID helper text is missing."); |
| 63 | + if (!hasCopyButtonText) failures.push("Copy ID button is missing from Recent Sessions."); |
| 64 | + if (!hasUseButtonText) failures.push("Use in Library button is missing from Recent Sessions."); |
| 65 | + if (!hasCopyMethod || !hasClipboardWrite) failures.push("Copy ID behavior does not write exact hostContextId to clipboard."); |
| 66 | + if (!hasUseMethod || !hasUsePopulate) failures.push("Use in Library behavior does not populate Session ID input."); |
| 67 | + if (!deleteTouchesLibrary) failures.push("Delete behavior is not operating on Session Library as expected."); |
| 68 | + if (deleteTouchesHistory) failures.push("Delete behavior should not affect Recent Sessions history."); |
| 69 | + |
| 70 | + fs.mkdirSync(path.dirname(resultsPath), { recursive: true }); |
| 71 | + fs.writeFileSync(resultsPath, `${JSON.stringify({ |
| 72 | + generatedAt: new Date().toISOString(), |
| 73 | + failures, |
| 74 | + checks: { |
| 75 | + htmlExists, |
| 76 | + jsExists, |
| 77 | + syntax, |
| 78 | + hasSessionIdLabel, |
| 79 | + hasHelperText, |
| 80 | + hasCopyButtonText, |
| 81 | + hasUseButtonText, |
| 82 | + hasCopyMethod, |
| 83 | + hasClipboardWrite, |
| 84 | + hasUseMethod, |
| 85 | + hasUsePopulate, |
| 86 | + deleteTouchesLibrary, |
| 87 | + deleteTouchesHistory |
| 88 | + } |
| 89 | + }, null, 2)}\n`, "utf8"); |
| 90 | + |
| 91 | + console.log(`v2 session-id usability results: ${resultsPath}`); |
| 92 | + assert.equal(failures.length, 0, `V2 session-id usability failures: ${failures.join(" | ")}`); |
| 93 | + return { failures }; |
| 94 | +} |
| 95 | + |
| 96 | +if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { |
| 97 | + try { |
| 98 | + const summary = run(); |
| 99 | + console.log(JSON.stringify(summary, null, 2)); |
| 100 | + } catch (error) { |
| 101 | + console.error(error); |
| 102 | + process.exitCode = 1; |
| 103 | + } |
| 104 | +} |
0 commit comments