|
| 1 | +const assert = require("assert"); |
| 2 | +const fs = require("fs"); |
| 3 | +const path = require("path"); |
| 4 | +const { spawnSync } = require("child_process"); |
| 5 | + |
| 6 | +const repoRoot = path.resolve(__dirname, "..", "..", ".."); |
| 7 | +const cliPath = path.join(repoRoot, "packages", "cli", "dist", "index.js"); |
| 8 | +const workspaceRoot = path.join( |
| 9 | + repoRoot, |
| 10 | + "test", |
| 11 | + ".tmp", |
| 12 | + `golden-closed-intent-gate-proof-${Date.now()}`, |
| 13 | +); |
| 14 | + |
| 15 | +function writeFile(relativePath, contents) { |
| 16 | + const filePath = path.join(workspaceRoot, relativePath); |
| 17 | + fs.mkdirSync(path.dirname(filePath), { recursive: true }); |
| 18 | + fs.writeFileSync(filePath, contents); |
| 19 | +} |
| 20 | + |
| 21 | +function runCliResult(args) { |
| 22 | + return spawnSync(process.execPath, [cliPath, ...args], { |
| 23 | + cwd: workspaceRoot, |
| 24 | + encoding: "utf8", |
| 25 | + stdio: ["ignore", "pipe", "pipe"], |
| 26 | + }); |
| 27 | +} |
| 28 | + |
| 29 | +function assertIncludes(output, expected, label) { |
| 30 | + assert( |
| 31 | + output.includes(expected), |
| 32 | + `${label} should include ${expected}\n\nOutput:\n${output}`, |
| 33 | + ); |
| 34 | +} |
| 35 | + |
| 36 | +function assertNotIncludes(output, unexpected, label) { |
| 37 | + assert( |
| 38 | + !output.includes(unexpected), |
| 39 | + `${label} should not include ${unexpected}\n\nOutput:\n${output}`, |
| 40 | + ); |
| 41 | +} |
| 42 | + |
| 43 | +function setupClosedIntentFixture() { |
| 44 | + if (!fs.existsSync(cliPath)) { |
| 45 | + throw new Error("CLI build output is missing. Run npm run build:cli first."); |
| 46 | + } |
| 47 | + |
| 48 | + writeFile( |
| 49 | + "package.json", |
| 50 | + JSON.stringify({ name: "ripple-closed-intent-gate-proof" }, null, 2), |
| 51 | + ); |
| 52 | + writeFile( |
| 53 | + ".ripple/intents/latest.json", |
| 54 | + `${JSON.stringify( |
| 55 | + { |
| 56 | + protocol: "ripple-closed-intent", |
| 57 | + version: 1, |
| 58 | + closedAt: "2026-06-12T00:00:00.000Z", |
| 59 | + closedBy: "Ripple Golden Proof", |
| 60 | + reason: "previous boundary is complete", |
| 61 | + originalIntentPath: ".ripple/intents/latest.json", |
| 62 | + intent: { |
| 63 | + protocol: "ripple-change-intent", |
| 64 | + version: 1, |
| 65 | + id: "intent-golden-closed", |
| 66 | + createdAt: "2026-06-12T00:00:00.000Z", |
| 67 | + task: "change auth behavior", |
| 68 | + targetFile: "src/auth.ts", |
| 69 | + controlMode: "file", |
| 70 | + humanGate: "required-before-edit", |
| 71 | + boundaryRisk: "critical", |
| 72 | + }, |
| 73 | + }, |
| 74 | + null, |
| 75 | + 2, |
| 76 | + )}\n`, |
| 77 | + ); |
| 78 | +} |
| 79 | + |
| 80 | +function main() { |
| 81 | + setupClosedIntentFixture(); |
| 82 | + |
| 83 | + const result = runCliResult(["gate", "--intent", "latest"]); |
| 84 | + if (result.error) { |
| 85 | + throw result.error; |
| 86 | + } |
| 87 | + const stdout = result.stdout ?? ""; |
| 88 | + const stderr = result.stderr ?? ""; |
| 89 | + const output = `${stdout}\n${stderr}`; |
| 90 | + |
| 91 | + assert.notStrictEqual( |
| 92 | + result.status, |
| 93 | + 0, |
| 94 | + "closed intent gate should stop instead of continuing", |
| 95 | + ); |
| 96 | + assert.strictEqual( |
| 97 | + stdout, |
| 98 | + "", |
| 99 | + "closed intent gate should not print a successful gate report", |
| 100 | + ); |
| 101 | + |
| 102 | + [ |
| 103 | + "Ripple CLI error:", |
| 104 | + "No active Ripple change intent found", |
| 105 | + "the saved boundary is closed", |
| 106 | + "Closed by: Ripple Golden Proof.", |
| 107 | + "Reason: previous boundary is complete", |
| 108 | + "Agents must not continue from a closed boundary.", |
| 109 | + "Run ripple intent status", |
| 110 | + "create a new saved plan", |
| 111 | + "ripple plan --file <file> --task \"<task>\" --agent --save", |
| 112 | + ].forEach((expected) => |
| 113 | + assertIncludes(output, expected, "golden closed intent gate proof"), |
| 114 | + ); |
| 115 | + |
| 116 | + [ |
| 117 | + "git diff", |
| 118 | + "Git could not be started", |
| 119 | + "Could not read staged files", |
| 120 | + "Ripple gate: CONTINUE", |
| 121 | + ].forEach((unexpected) => |
| 122 | + assertNotIncludes(output, unexpected, "golden closed intent gate proof"), |
| 123 | + ); |
| 124 | + |
| 125 | + console.log("Ripple golden closed intent gate proof passed"); |
| 126 | + console.log(`Workspace: ${workspaceRoot}`); |
| 127 | + console.log("Gate: closed intent fails closed before git"); |
| 128 | +} |
| 129 | + |
| 130 | +main(); |
0 commit comments