-
Notifications
You must be signed in to change notification settings - Fork 0
test: prove generated installer lifecycle #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| "use strict"; | ||
|
|
||
| const test = require("node:test"); | ||
| const assert = require("node:assert/strict"); | ||
| const fs = require("node:fs"); | ||
| const os = require("node:os"); | ||
| const path = require("node:path"); | ||
| const { spawnSync } = require("node:child_process"); | ||
|
|
||
| const artifactRoot = path.join(__dirname, "..", "artifact"); | ||
| const installer = path.join(artifactRoot, "install.mjs"); | ||
|
|
||
| function makeHome() { | ||
| const home = fs.mkdtempSync(path.join(os.tmpdir(), "plugin-library-install-")); | ||
| fs.mkdirSync(path.join(home, ".cursor")); | ||
| return home; | ||
| } | ||
|
|
||
| function runInstaller(home, args = []) { | ||
| const env = { | ||
| ...process.env, | ||
| HOME: home, | ||
| XDG_STATE_HOME: path.join(home, ".local", "state"), | ||
| }; | ||
| delete env.AGENT_BUNDLE_STATE_ROOT; | ||
| return spawnSync(process.execPath, [installer, ...args], { | ||
| encoding: "utf8", | ||
| env, | ||
| }); | ||
| } | ||
|
|
||
| test("generated installer copies only the artifact and writes a lifecycle receipt", (t) => { | ||
| const home = makeHome(); | ||
| t.after(() => fs.rmSync(home, { force: true, recursive: true })); | ||
|
|
||
| const result = runInstaller(home); | ||
| assert.equal(result.status, 0, result.stderr); | ||
| assert.match(result.stdout, /Installed plugin-library@0\.3\.0/); | ||
|
|
||
| const installed = path.join(home, ".cursor", "plugins", "local", "plugin-library"); | ||
| assert.equal(fs.lstatSync(installed).isSymbolicLink(), false); | ||
| assert.equal(fs.existsSync(path.join(installed, ".cursor-plugin", "plugin.json")), true); | ||
| assert.equal(fs.existsSync(path.join(installed, "commands", "plugin-library.md")), true); | ||
| assert.equal(fs.existsSync(path.join(installed, "skills", "plugin-library", "SKILL.md")), true); | ||
| assert.equal(fs.existsSync(path.join(installed, "assets", "data", "unified-catalog.json")), true); | ||
| assert.equal(fs.existsSync(path.join(installed, "scripts", "plugin-library.mjs")), true); | ||
|
|
||
| const receipt = JSON.parse( | ||
| fs.readFileSync(path.join(installed, ".agent-bundle-install.json"), "utf8"), | ||
| ); | ||
| const manifest = JSON.parse( | ||
| fs.readFileSync(path.join(artifactRoot, "agent-bundle.manifest.json"), "utf8"), | ||
| ); | ||
| assert.equal(receipt.format, "agent-bundle-install-receipt/2"); | ||
| assert.equal(receipt.plugin, "plugin-library"); | ||
| assert.equal(receipt.version, "0.3.0"); | ||
| assert.equal(receipt.host, "cursor"); | ||
| assert.equal(receipt.mode, "local"); | ||
| assert.equal(receipt.scope, "user"); | ||
| assert.deepEqual(receipt.registrations, [{ kind: "cursor-local-plugin" }]); | ||
| assert.deepEqual( | ||
| [...receipt.files].sort(), | ||
| ["agent-bundle.manifest.json", ...manifest.files.map((file) => file.path)].sort(), | ||
| ); | ||
| assert.match(receipt.contentHash, /^[a-f0-9]{64}$/); | ||
| }); | ||
|
|
||
| test("generated installer is idempotent for identical content", (t) => { | ||
| const home = makeHome(); | ||
| t.after(() => fs.rmSync(home, { force: true, recursive: true })); | ||
|
|
||
| assert.equal(runInstaller(home).status, 0); | ||
| const second = runInstaller(home); | ||
| assert.equal(second.status, 0, second.stderr); | ||
| assert.match(second.stdout, /Already installed plugin-library@0\.3\.0/); | ||
| }); | ||
|
|
||
| test("generated installer plans and performs receipt-owned uninstall", (t) => { | ||
| const home = makeHome(); | ||
| t.after(() => fs.rmSync(home, { force: true, recursive: true })); | ||
| const installed = path.join(home, ".cursor", "plugins", "local", "plugin-library"); | ||
|
|
||
| assert.equal(runInstaller(home).status, 0); | ||
| const plan = runInstaller(home, ["--uninstall", "--plan"]); | ||
| assert.equal(plan.status, 0, plan.stderr); | ||
| assert.match(plan.stdout, /Would uninstall plugin-library@0\.3\.0/); | ||
| assert.equal(fs.existsSync(installed), true); | ||
|
|
||
| const uninstall = runInstaller(home, ["--uninstall"]); | ||
| assert.equal(uninstall.status, 0, uninstall.stderr); | ||
| assert.match(uninstall.stdout, /Uninstalled plugin-library@0\.3\.0/); | ||
| assert.equal(fs.existsSync(installed), false); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the generated installer copies an unexpected or stale file but still populates
receipt.filesfrom the manifest, this assertion passes because it compares two metadata lists rather than inspecting the installed directory. Since this test is intended to prove that only manifest files are installed, recursively enumerate the installation tree (excluding the receipt itself) and compare that inventory with the manifest.Useful? React with 👍 / 👎.