-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.test.js
More file actions
137 lines (122 loc) · 4.3 KB
/
Copy pathinstall.test.js
File metadata and controls
137 lines (122 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
const { describe, it } = 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 installer = require('../scripts/install');
function tmpDir() {
return fs.mkdtempSync(path.join(os.tmpdir(), 'evomap-opencode-install-'));
}
function cleanup(dir) {
try {
fs.rmSync(dir, { recursive: true, force: true });
} catch (_err) {
// best effort
}
}
describe('local-file installer', () => {
it('installs a managed delegate plugin and verifies it', () => {
const dir = tmpDir();
try {
const report = installer.install({ configRoot: dir, force: false });
assert.equal(report.ok, true);
const p = installer.paths(dir);
assert.ok(fs.existsSync(p.pluginPath));
assert.ok(fs.readFileSync(p.pluginPath, 'utf8').includes('_evolver_managed: true'));
assert.ok(fs.readFileSync(p.agentsMdPath, 'utf8').includes(installer.EVOLVER_MARKER));
const mod = require(p.pluginPath);
assert.equal(typeof mod.Evolver, 'function');
const verify = installer.verify({ configRoot: dir });
assert.equal(verify.ok, true, JSON.stringify(verify, null, 2));
} finally {
cleanup(dir);
}
});
it('refuses to overwrite a user-owned plugin without force', () => {
const dir = tmpDir();
try {
const p = installer.paths(dir);
fs.mkdirSync(path.dirname(p.pluginPath), { recursive: true });
fs.writeFileSync(p.pluginPath, 'module.exports = {};\n', 'utf8');
const report = installer.install({ configRoot: dir, force: false });
assert.equal(report.ok, false);
assert.match(report.error, /refusing to overwrite/);
} finally {
cleanup(dir);
}
});
it('uninstalls only managed files and AGENTS.md section', () => {
const dir = tmpDir();
try {
installer.install({ configRoot: dir, force: false });
const p = installer.paths(dir);
const report = installer.uninstall({ configRoot: dir });
assert.equal(report.ok, true);
assert.equal(report.removed, true);
assert.ok(!fs.existsSync(p.pluginPath));
assert.ok(!fs.readFileSync(p.agentsMdPath, 'utf8').includes(installer.EVOLVER_MARKER));
} finally {
cleanup(dir);
}
});
it('removes the whole managed AGENTS.md section before reinstalling', () => {
const dir = tmpDir();
try {
installer.install({ configRoot: dir, force: false });
const p = installer.paths(dir);
installer.uninstall({ configRoot: dir });
const afterUninstall = fs.readFileSync(p.agentsMdPath, 'utf8');
assert.ok(!afterUninstall.includes(installer.EVOLVER_MARKER));
assert.ok(!afterUninstall.includes('## Evolution Memory (Evolver)'));
installer.install({ configRoot: dir, force: false });
installer.uninstall({ configRoot: dir });
const afterSecondUninstall = fs.readFileSync(p.agentsMdPath, 'utf8');
assert.ok(!afterSecondUninstall.includes('## Evolution Memory (Evolver)'));
} finally {
cleanup(dir);
}
});
it('removes legacy marker-only AGENTS.md sections', () => {
const dir = tmpDir();
try {
const p = installer.paths(dir);
fs.writeFileSync(
p.agentsMdPath,
[
'# Project',
'',
installer.EVOLVER_MARKER,
'## Evolution Memory (Evolver)',
'',
'legacy body',
'',
'## Keep Me',
'',
'real section',
'',
].join('\n'),
'utf8'
);
const report = installer.uninstall({ configRoot: dir });
assert.equal(report.ok, true);
const content = fs.readFileSync(p.agentsMdPath, 'utf8');
assert.ok(!content.includes(installer.EVOLVER_MARKER));
assert.ok(!content.includes('legacy body'));
assert.ok(content.includes('## Keep Me'));
} finally {
cleanup(dir);
}
});
it('reports verify failure before install', () => {
const dir = tmpDir();
try {
const report = installer.verify({ configRoot: dir });
assert.equal(report.ok, false);
const failed = report.checks.filter((check) => !check.ok).map((check) => check.id);
assert.ok(failed.includes('plugin_file_present'));
assert.ok(failed.includes('plugin_loadable'));
} finally {
cleanup(dir);
}
});
});