|
| 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 jsPath = path.join(repoRoot, "tools", "workspace-v2", "index.js"); |
| 11 | +const resultsPath = path.join(repoRoot, "tmp", "v2-session-ux-stabilization-results.json"); |
| 12 | + |
| 13 | +function checkSyntax(filePath) { |
| 14 | + try { |
| 15 | + execFileSync(process.execPath, ["--check", filePath], { |
| 16 | + cwd: repoRoot, |
| 17 | + stdio: ["ignore", "pipe", "pipe"] |
| 18 | + }); |
| 19 | + return { ok: true, error: "" }; |
| 20 | + } catch (error) { |
| 21 | + return { ok: false, error: (error?.stderr || error?.stdout || error?.message || "").toString().trim() }; |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +function libraryActionState(sessionName) { |
| 26 | + const hasSessionInput = Boolean(typeof sessionName === "string" && sessionName.trim()); |
| 27 | + return { |
| 28 | + saveDisabled: !hasSessionInput, |
| 29 | + overwriteDisabled: !hasSessionInput, |
| 30 | + loadDisabled: !hasSessionInput, |
| 31 | + deleteDisabled: !hasSessionInput |
| 32 | + }; |
| 33 | +} |
| 34 | + |
| 35 | +function mergeEnableText({ canPreviewMerge, previewFresh, previewHasConflicts, previewConfirmed, previewExists }) { |
| 36 | + if (!canPreviewMerge) { |
| 37 | + return "Select two different sessions to enable Preview Merge."; |
| 38 | + } |
| 39 | + if (previewExists && !previewFresh) { |
| 40 | + return "Preview is stale. Run Preview Merge again."; |
| 41 | + } |
| 42 | + if (previewExists && previewHasConflicts) { |
| 43 | + return "Preview has conflicts. Resolve conflicts before applying."; |
| 44 | + } |
| 45 | + if (previewExists && previewConfirmed && previewFresh && !previewHasConflicts) { |
| 46 | + return "Apply Merge is enabled."; |
| 47 | + } |
| 48 | + if (previewExists && !previewConfirmed && previewFresh && !previewHasConflicts) { |
| 49 | + return "Confirm Preview is enabled."; |
| 50 | + } |
| 51 | + return "Preview Merge is enabled."; |
| 52 | +} |
| 53 | + |
| 54 | +function diffEnableText(canRunDiff) { |
| 55 | + return canRunDiff ? "Compute Diff is enabled." : "Select two different sessions to enable Compute Diff."; |
| 56 | +} |
| 57 | + |
| 58 | +export function run() { |
| 59 | + const failures = []; |
| 60 | + const jsExists = fs.existsSync(jsPath); |
| 61 | + const js = jsExists ? fs.readFileSync(jsPath, "utf8") : ""; |
| 62 | + const jsSyntax = checkSyntax(jsPath); |
| 63 | + const testSyntax = checkSyntax(path.join(repoRoot, "tests", "runtime", "V2SessionUxStabilization.test.mjs")); |
| 64 | + |
| 65 | + if (!jsExists) failures.push("Missing tools/workspace-v2/index.js."); |
| 66 | + if (!jsSyntax.ok) failures.push("tools/workspace-v2/index.js failed syntax check."); |
| 67 | + if (!testSyntax.ok) failures.push("tests/runtime/V2SessionUxStabilization.test.mjs failed syntax check."); |
| 68 | + |
| 69 | + const requiredTokens = [ |
| 70 | + "updateSessionLibraryActionState()", |
| 71 | + "this.sessionNameNode.addEventListener(\"input\", () => {", |
| 72 | + "this.renderSessionLibrary();", |
| 73 | + "this.renderSessionHistory();", |
| 74 | + "Workspace V2 session views refreshed.", |
| 75 | + "Compute Diff is enabled.", |
| 76 | + "Preview Merge is enabled.", |
| 77 | + "Confirm Preview is enabled.", |
| 78 | + "Apply Merge is enabled.", |
| 79 | + "Preview confirmed. Apply Merge is enabled.", |
| 80 | + "Merged session is available for save.", |
| 81 | + "clearMergePanelTransientState(" |
| 82 | + ]; |
| 83 | + requiredTokens.forEach((token) => { |
| 84 | + if (!js.includes(token)) failures.push(`Missing PR_11_263 UX stabilization token/text: ${token}`); |
| 85 | + }); |
| 86 | + |
| 87 | + const removedTokens = [ |
| 88 | + "Ready to compute diff.", |
| 89 | + "Ready to preview merge.", |
| 90 | + "Preview ready. Confirm to enable apply.", |
| 91 | + "Preview confirmed. Ready to apply merge.", |
| 92 | + "Merged session ready. Choose an ID and save if desired." |
| 93 | + ]; |
| 94 | + removedTokens.forEach((token) => { |
| 95 | + if (js.includes(token)) failures.push(`Deprecated/misleading hint text still present: ${token}`); |
| 96 | + }); |
| 97 | + |
| 98 | + const emptyInput = libraryActionState(""); |
| 99 | + if (!emptyInput.saveDisabled || !emptyInput.overwriteDisabled || !emptyInput.loadDisabled || !emptyInput.deleteDisabled) { |
| 100 | + failures.push("Library actions should be disabled when session input is empty."); |
| 101 | + } |
| 102 | + const filledInput = libraryActionState("asset-browser-v2-123"); |
| 103 | + if (filledInput.saveDisabled || filledInput.overwriteDisabled || filledInput.loadDisabled || filledInput.deleteDisabled) { |
| 104 | + failures.push("Library actions should be enabled when session input is present."); |
| 105 | + } |
| 106 | + |
| 107 | + const mergeNoPreview = mergeEnableText({ |
| 108 | + canPreviewMerge: true, |
| 109 | + previewFresh: false, |
| 110 | + previewHasConflicts: false, |
| 111 | + previewConfirmed: false, |
| 112 | + previewExists: false |
| 113 | + }); |
| 114 | + if (mergeNoPreview !== "Preview Merge is enabled.") { |
| 115 | + failures.push("Merge enable text should reflect immediate current state when selection is valid and preview not present."); |
| 116 | + } |
| 117 | + const mergeReadyConfirm = mergeEnableText({ |
| 118 | + canPreviewMerge: true, |
| 119 | + previewFresh: true, |
| 120 | + previewHasConflicts: false, |
| 121 | + previewConfirmed: false, |
| 122 | + previewExists: true |
| 123 | + }); |
| 124 | + if (mergeReadyConfirm !== "Confirm Preview is enabled.") { |
| 125 | + failures.push("Merge enable text should indicate Confirm enablement for fresh conflict-free preview."); |
| 126 | + } |
| 127 | + const mergeReadyApply = mergeEnableText({ |
| 128 | + canPreviewMerge: true, |
| 129 | + previewFresh: true, |
| 130 | + previewHasConflicts: false, |
| 131 | + previewConfirmed: true, |
| 132 | + previewExists: true |
| 133 | + }); |
| 134 | + if (mergeReadyApply !== "Apply Merge is enabled.") { |
| 135 | + failures.push("Merge enable text should indicate Apply enablement after confirmed fresh preview."); |
| 136 | + } |
| 137 | + |
| 138 | + if (diffEnableText(true) !== "Compute Diff is enabled.") { |
| 139 | + failures.push("Diff enable text should indicate immediate enabled state."); |
| 140 | + } |
| 141 | + |
| 142 | + fs.mkdirSync(path.dirname(resultsPath), { recursive: true }); |
| 143 | + fs.writeFileSync(resultsPath, `${JSON.stringify({ |
| 144 | + generatedAt: new Date().toISOString(), |
| 145 | + failures, |
| 146 | + checks: { jsExists, jsSyntax, testSyntax }, |
| 147 | + scenarios: { |
| 148 | + emptyInput, |
| 149 | + filledInput, |
| 150 | + mergeNoPreview, |
| 151 | + mergeReadyConfirm, |
| 152 | + mergeReadyApply, |
| 153 | + diffEnabled: diffEnableText(true) |
| 154 | + } |
| 155 | + }, null, 2)}\n`, "utf8"); |
| 156 | + |
| 157 | + console.log(`v2 session-ux-stabilization results: ${resultsPath}`); |
| 158 | + assert.equal(failures.length, 0, `V2 session-ux-stabilization failures: ${failures.join(" | ")}`); |
| 159 | + return { failures }; |
| 160 | +} |
| 161 | + |
| 162 | +if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { |
| 163 | + try { |
| 164 | + const summary = run(); |
| 165 | + console.log(JSON.stringify(summary, null, 2)); |
| 166 | + } catch (error) { |
| 167 | + console.error(error); |
| 168 | + process.exitCode = 1; |
| 169 | + } |
| 170 | +} |
0 commit comments