|
| 1 | +// @ts-check |
| 2 | +// The approval claim in the README, written as executable assertions. |
| 3 | +// |
| 4 | +// The point of this file: the sentence that describes approval is checked, not read. |
| 5 | +// |
| 6 | +// 1. the Agent-turns bullet says the condition its claim depends on (the Host's |
| 7 | +// permission mode) and says what the plugin still guarantees — that when approval is |
| 8 | +// asked for it never approves by itself. Appending an "approved automatically" |
| 9 | +// qualifier while keeping the old promise fails, and so does flipping the claim to |
| 10 | +// "the plugin approves it by itself"; |
| 11 | +// 2. the plugin version is one value in the manifest, in package.json and in the |
| 12 | +// serverInfo the MCP server reports, so no release ships as three different things; |
| 13 | +// 3. the README has a changelog entry for that version, after the 0.7.24 entry, with a |
| 14 | +// bullet of its own that talks about the approval claim — a renamed heading alone is |
| 15 | +// not an entry. |
| 16 | + |
| 17 | +import assert from 'node:assert/strict'; |
| 18 | +import { readFileSync } from 'node:fs'; |
| 19 | +import { test } from 'node:test'; |
| 20 | +import { join } from 'node:path'; |
| 21 | + |
| 22 | +const root = join(import.meta.dirname, '..'); |
| 23 | + |
| 24 | +/** @param {string} name */ |
| 25 | +const readText = (name) => readFileSync(join(root, name), 'utf8'); |
| 26 | + |
| 27 | +/** @param {string} name */ |
| 28 | +const readJson = (name) => JSON.parse(readText(name)); |
| 29 | + |
| 30 | +/** |
| 31 | + * The body of a numbered changelog section: its bullets, without the heading line, up to |
| 32 | + * the next `## ` heading. |
| 33 | + * |
| 34 | + * `heading` may be the start of a heading (`## 0.7.24 `) or its whole text including a |
| 35 | + * topic (`## 0.7.26 The approval claim`): a version number alone does not identify a |
| 36 | + * section, because two candidates can carry the same number and the first one found is |
| 37 | + * not necessarily the entry being checked. |
| 38 | + * @param {string} readme |
| 39 | + * @param {string} heading the heading prefix to match, e.g. `## 0.7.24 ` |
| 40 | + */ |
| 41 | +function sectionOf(readme, heading) { |
| 42 | + const lines = readme.split('\n'); |
| 43 | + const start = lines.findIndex((line) => line.startsWith(heading)); |
| 44 | + assert.notEqual(start, -1, `README has no section starting with ${JSON.stringify(heading)}`); |
| 45 | + const next = lines.findIndex((line, index) => index > start && line.startsWith('## ')); |
| 46 | + const end = next === -1 ? lines.length : next; |
| 47 | + return { at: start, heading: lines[start], body: lines.slice(start + 1, end).join('\n') }; |
| 48 | +} |
| 49 | + |
| 50 | +test('the Agent-turns bullet makes the approval claim conditional on the Host permission mode', () => { |
| 51 | + const readme = readText('README.md'); |
| 52 | + const bullet = readme.split('\n').find((line) => line.startsWith('- **Agent turns**')); |
| 53 | + assert.ok(bullet, 'README has an Agent turns bullet'); |
| 54 | + |
| 55 | + // It has to name the condition its claim depends on, in the README's own words: the |
| 56 | + // Host decides whether approval is asked for at all. |
| 57 | + assert.match(bullet, /the Host's permission mode/i); |
| 58 | + // And it has to keep the plugin's own side of the claim, as the reviewed clause: when |
| 59 | + // approval is asked for, the plugin never approves it by itself. |
| 60 | + assert.match(bullet, /when it is needed, the plugin never approves it by itself/i); |
| 61 | + // The old unconditional promise must be gone, including the variants that phrase the |
| 62 | + // same promise ("nothing is ever approved automatically", "nothing gets approved ..."). |
| 63 | + assert.doesNotMatch(bullet, /\bnothing (?:is|is ever|gets) (?:ever )?approved automatically\b/i); |
| 64 | + // And the claim must not be flipped: the plugin does not approve the call by itself. |
| 65 | + assert.doesNotMatch(bullet, /plugin approves (?:it|the call|a call) by itself/i); |
| 66 | + // Same guard in the words a later edit would actually reach for. The reviewed sentence |
| 67 | + // uses neither, so these cannot fire on the text this test is written for: nothing in |
| 68 | + // the bullet says a call is approved without a person, and nothing says the plugin can |
| 69 | + // approve one. |
| 70 | + assert.doesNotMatch(bullet, /\bautomatically\b/i); |
| 71 | + assert.doesNotMatch(bullet, /(?:can|may|will|would|does)\s+approve/i); |
| 72 | +}); |
| 73 | + |
| 74 | +test('the plugin version is the same value in the manifest, package.json and serverInfo', () => { |
| 75 | + const version = readJson('.minimax-plugin/plugin.json').version; |
| 76 | + assert.match(version, /^\d+\.\d+\.\d+$/); |
| 77 | + |
| 78 | + assert.equal(readJson('package.json').version, version); |
| 79 | + |
| 80 | + const server = readText('miniapp/node/mcp.mjs'); |
| 81 | + const found = server.match(/serverInfo:\s*\{[^}]*version:\s*'([0-9]+\.[0-9]+\.[0-9]+)'/); |
| 82 | + assert.ok(found, 'mcp.mjs reports a serverInfo version'); |
| 83 | + assert.equal(found[1], version); |
| 84 | +}); |
| 85 | + |
| 86 | +test('the README has a changelog entry for this version, after the 0.7.24 one', () => { |
| 87 | + const readme = readText('README.md'); |
| 88 | + const version = readJson('.minimax-plugin/plugin.json').version; |
| 89 | + |
| 90 | + const previous = sectionOf(readme, '## 0.7.24 '); |
| 91 | + // The release under review is found by its version alone, so a later release with a |
| 92 | + // topic of its own stays green. |
| 93 | + const current = sectionOf(readme, `## ${version} `); |
| 94 | + assert.ok(current.at > previous.at, `the ${version} entry comes after the 0.7.24 entry`); |
| 95 | + |
| 96 | + // The approval claim is pinned to this release's own section, named literally: it is |
| 97 | + // this changelog entry that has to talk about it, not whichever section a later |
| 98 | + // version happens to put first. A renamed heading alone is not an entry either — the |
| 99 | + // approval claim has to be talked about in a bullet, not in the heading. |
| 100 | + const documented = sectionOf(readme, '## 0.7.26 '); |
| 101 | + const bullets = documented.body.split('\n').filter((line) => line.startsWith('- ')); |
| 102 | + assert.ok(bullets.length >= 1, 'the 0.7.26 entry has at least one bullet, not just a heading'); |
| 103 | + assert.match(bullets.join('\n'), /approval/u); |
| 104 | +}); |
0 commit comments