|
| 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 testPath = path.join(repoRoot, "tests", "runtime", "V2SessionLibraryActionCleanup.test.mjs"); |
| 13 | +const resultsPath = path.join(repoRoot, "tmp", "v2-session-library-action-cleanup-results.json"); |
| 14 | + |
| 15 | +function checkSyntax(filePath) { |
| 16 | + try { |
| 17 | + execFileSync(process.execPath, ["--check", filePath], { |
| 18 | + cwd: repoRoot, |
| 19 | + stdio: ["ignore", "pipe", "pipe"] |
| 20 | + }); |
| 21 | + return { ok: true, error: "" }; |
| 22 | + } catch (error) { |
| 23 | + return { ok: false, error: (error?.stderr || error?.stdout || error?.message || "").toString().trim() }; |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +export function run() { |
| 28 | + const failures = []; |
| 29 | + const htmlExists = fs.existsSync(htmlPath); |
| 30 | + const jsExists = fs.existsSync(jsPath); |
| 31 | + const html = htmlExists ? fs.readFileSync(htmlPath, "utf8") : ""; |
| 32 | + const js = jsExists ? fs.readFileSync(jsPath, "utf8") : ""; |
| 33 | + const jsSyntax = checkSyntax(jsPath); |
| 34 | + const testSyntax = checkSyntax(testPath); |
| 35 | + |
| 36 | + if (!htmlExists) failures.push("Missing tools/workspace-v2/index.html."); |
| 37 | + if (!jsExists) failures.push("Missing tools/workspace-v2/index.js."); |
| 38 | + if (!jsSyntax.ok) failures.push("tools/workspace-v2/index.js failed syntax check."); |
| 39 | + if (!testSyntax.ok) failures.push("tests/runtime/V2SessionLibraryActionCleanup.test.mjs failed syntax check."); |
| 40 | + |
| 41 | + const requiredHtmlTokens = [ |
| 42 | + '<label for="workspaceV2SessionName">New Session ID (Save Session)</label>', |
| 43 | + '<button id="workspaceV2SaveSessionButton" type="button">Save Session</button>', |
| 44 | + '<button id="workspaceV2OverwriteSessionButton" type="button" hidden>Overwrite Session</button>', |
| 45 | + '<button id="workspaceV2LoadSessionButton" type="button" hidden>Load Session</button>', |
| 46 | + '<button id="workspaceV2DeleteSessionButton" type="button" hidden>Delete Saved Session</button>', |
| 47 | + 'Use Save Session to create a new saved entry. Manage existing saved sessions from their Saved Sessions cards.' |
| 48 | + ]; |
| 49 | + requiredHtmlTokens.forEach((token) => { |
| 50 | + if (!html.includes(token)) failures.push(`Missing expected Session Library cleanup HTML token: ${token}`); |
| 51 | + }); |
| 52 | + |
| 53 | + const requiredJsTokens = [ |
| 54 | + 'this.setLibraryStatus("Saved session already exists. Manage it from its Saved Sessions card.");', |
| 55 | + 'Saved session created. Manage this session from its Saved Sessions card.', |
| 56 | + 'loadButton.textContent = "Load";', |
| 57 | + 'deleteSavedButton.textContent = "Delete Saved";', |
| 58 | + 'useInLibraryButton.textContent = "Use in Diff/Merge";' |
| 59 | + ]; |
| 60 | + requiredJsTokens.forEach((token) => { |
| 61 | + if (!js.includes(token)) failures.push(`Missing expected Session Library cleanup JS token: ${token}`); |
| 62 | + }); |
| 63 | + |
| 64 | + fs.mkdirSync(path.dirname(resultsPath), { recursive: true }); |
| 65 | + fs.writeFileSync(resultsPath, `${JSON.stringify({ |
| 66 | + generatedAt: new Date().toISOString(), |
| 67 | + failures, |
| 68 | + checks: { htmlExists, jsExists, jsSyntax, testSyntax } |
| 69 | + }, null, 2)} |
| 70 | +`, "utf8"); |
| 71 | + |
| 72 | + console.log(`v2 session-library-action-cleanup results: ${resultsPath}`); |
| 73 | + assert.equal(failures.length, 0, `V2 session-library-action-cleanup failures: ${failures.join(" | ")}`); |
| 74 | + return { failures }; |
| 75 | +} |
| 76 | + |
| 77 | +if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { |
| 78 | + try { |
| 79 | + const summary = run(); |
| 80 | + console.log(JSON.stringify(summary, null, 2)); |
| 81 | + } catch (error) { |
| 82 | + console.error(error); |
| 83 | + process.exitCode = 1; |
| 84 | + } |
| 85 | +} |
0 commit comments