|
| 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-enable-state-feedback-results.json"); |
| 13 | + |
| 14 | +function checkSyntax(filePath) { |
| 15 | + try { |
| 16 | + execFileSync(process.execPath, ["--check", filePath], { |
| 17 | + cwd: repoRoot, |
| 18 | + stdio: ["ignore", "pipe", "pipe"] |
| 19 | + }); |
| 20 | + return { ok: true, error: "" }; |
| 21 | + } catch (error) { |
| 22 | + return { ok: false, error: (error?.stderr || error?.stdout || error?.message || "").toString().trim() }; |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +function computeEnableState(leftId, rightId) { |
| 27 | + const enabled = Boolean(leftId && rightId && leftId !== rightId); |
| 28 | + return { |
| 29 | + diff: enabled ? "Ready to compute diff." : "Select two different sessions to enable Compute Diff.", |
| 30 | + merge: enabled ? "Ready to preview merge." : "Select two different sessions to enable Preview Merge." |
| 31 | + }; |
| 32 | +} |
| 33 | + |
| 34 | +export function run() { |
| 35 | + const failures = []; |
| 36 | + const htmlExists = fs.existsSync(htmlPath); |
| 37 | + const jsExists = fs.existsSync(jsPath); |
| 38 | + const html = htmlExists ? fs.readFileSync(htmlPath, "utf8") : ""; |
| 39 | + const js = jsExists ? fs.readFileSync(jsPath, "utf8") : ""; |
| 40 | + const jsSyntax = checkSyntax(jsPath); |
| 41 | + const testSyntax = checkSyntax(path.join(repoRoot, "tests", "runtime", "V2EnableStateFeedback.test.mjs")); |
| 42 | + |
| 43 | + if (!htmlExists) failures.push("Missing tools/workspace-v2/index.html."); |
| 44 | + if (!jsExists) failures.push("Missing tools/workspace-v2/index.js."); |
| 45 | + if (!jsSyntax.ok) failures.push("tools/workspace-v2/index.js failed syntax check."); |
| 46 | + if (!testSyntax.ok) failures.push("tests/runtime/V2EnableStateFeedback.test.mjs failed syntax check."); |
| 47 | + |
| 48 | + if (!html.includes("id=\"workspaceV2DiffEnableState\"")) failures.push("Missing Diff enable-state line."); |
| 49 | + if (!html.includes("id=\"workspaceV2MergeEnableState\"")) failures.push("Missing Merge enable-state line."); |
| 50 | + if (!js.includes("this.diffEnableStateNode.textContent = canRunDiff")) failures.push("Diff enable-state update is missing."); |
| 51 | + if (!js.includes("this.mergeEnableStateNode.textContent = canPreviewMerge")) failures.push("Merge enable-state update is missing."); |
| 52 | + if (!js.includes("Select two different sessions to enable Compute Diff.")) failures.push("Missing disabled Diff status text."); |
| 53 | + if (!js.includes("Ready to compute diff.")) failures.push("Missing enabled Diff status text."); |
| 54 | + if (!js.includes("Select two different sessions to enable Preview Merge.")) failures.push("Missing disabled Merge status text."); |
| 55 | + if (!js.includes("Ready to preview merge.")) failures.push("Missing enabled Merge status text."); |
| 56 | + |
| 57 | + const noneSelected = computeEnableState("", ""); |
| 58 | + const oneSelected = computeEnableState("a", ""); |
| 59 | + const sameSelected = computeEnableState("a", "a"); |
| 60 | + const twoSelected = computeEnableState("a", "b"); |
| 61 | + |
| 62 | + if (noneSelected.diff !== "Select two different sessions to enable Compute Diff.") failures.push("No selection should show disabled Diff status."); |
| 63 | + if (oneSelected.diff !== "Select two different sessions to enable Compute Diff.") failures.push("One selection should show disabled Diff status."); |
| 64 | + if (sameSelected.diff !== "Select two different sessions to enable Compute Diff.") failures.push("Same selection should show disabled Diff status."); |
| 65 | + if (twoSelected.diff !== "Ready to compute diff.") failures.push("Two distinct selections should show enabled Diff status."); |
| 66 | + if (noneSelected.merge !== "Select two different sessions to enable Preview Merge.") failures.push("No selection should show disabled Merge status."); |
| 67 | + if (twoSelected.merge !== "Ready to preview merge.") failures.push("Two distinct selections should show enabled Merge status."); |
| 68 | + |
| 69 | + fs.mkdirSync(path.dirname(resultsPath), { recursive: true }); |
| 70 | + fs.writeFileSync(resultsPath, `${JSON.stringify({ |
| 71 | + generatedAt: new Date().toISOString(), |
| 72 | + failures, |
| 73 | + checks: { htmlExists, jsExists, jsSyntax, testSyntax }, |
| 74 | + states: { noneSelected, oneSelected, sameSelected, twoSelected } |
| 75 | + }, null, 2)}\n`, "utf8"); |
| 76 | + |
| 77 | + console.log(`v2 enable-state feedback results: ${resultsPath}`); |
| 78 | + assert.equal(failures.length, 0, `V2 enable-state feedback failures: ${failures.join(" | ")}`); |
| 79 | + return { failures }; |
| 80 | +} |
| 81 | + |
| 82 | +if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { |
| 83 | + try { |
| 84 | + const summary = run(); |
| 85 | + console.log(JSON.stringify(summary, null, 2)); |
| 86 | + } catch (error) { |
| 87 | + console.error(error); |
| 88 | + process.exitCode = 1; |
| 89 | + } |
| 90 | +} |
| 91 | + |
0 commit comments