@spuentesp/lain-mcp 0.4.2 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -3
- package/scripts/install.js +252 -0
- package/scripts/install.test.js +286 -0
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spuentesp/lain-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"mcpName": "io.github.spuentesp/lain",
|
|
5
|
-
"description": "
|
|
5
|
+
"description": "Wird - Architectural code intelligence for AI coding agents",
|
|
6
6
|
"keywords": ["mcp", "code-intelligence", "architectural-analysis", "lain"],
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"homepage": "https://github.com/spuentesp/lain",
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
"lain": "./bin/lain.js"
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
|
-
"bin/"
|
|
17
|
+
"bin/",
|
|
18
|
+
"scripts/"
|
|
18
19
|
],
|
|
19
20
|
"os": [
|
|
20
21
|
"darwin",
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// postinstall script — downloads the Lain binary and creates ~/.lain/ structure
|
|
3
|
+
|
|
4
|
+
const { execSync } = require('child_process');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
|
|
8
|
+
const LAIN_DIR = path.join(process.env.HOME, '.lain');
|
|
9
|
+
const BIN_DIR = path.join(LAIN_DIR, 'bin');
|
|
10
|
+
const MODELS_DIR = path.join(LAIN_DIR, 'models');
|
|
11
|
+
const TOOLCHAINS_DIR = path.join(LAIN_DIR, 'toolchains');
|
|
12
|
+
const TUNING_FILE = path.join(LAIN_DIR, 'tuning.toml');
|
|
13
|
+
|
|
14
|
+
// Skip postinstall in CI unless explicitly requested
|
|
15
|
+
if (process.env.CI && !process.env.LAIN_FORCE_INSTALL) {
|
|
16
|
+
console.log('Skipping Lain install in CI environment (set LAIN_FORCE_INSTALL=1 to override)');
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Respect npm's --ignore-scripts flag
|
|
21
|
+
if (process.env.npm_config_ignore_scripts === 'true') {
|
|
22
|
+
console.log('Skipping Lain install (npm --ignore-scripts detected)');
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Detect platform
|
|
27
|
+
function getPlatform() {
|
|
28
|
+
const platform = process.platform;
|
|
29
|
+
const arch = process.arch;
|
|
30
|
+
if (platform === 'darwin' && arch === 'arm64') return 'aarch64-apple-darwin';
|
|
31
|
+
if (platform === 'linux' && arch === 'x64') return 'x86_64-unknown-linux-gnu';
|
|
32
|
+
if (platform === 'linux' && arch === 'arm64') return 'aarch64-unknown-linux-gnu';
|
|
33
|
+
if (platform === 'win32' && arch === 'x64') return 'x86_64-pc-windows-msvc';
|
|
34
|
+
throw new Error(`Unsupported platform: ${platform}-${arch}`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function getAssetName(platform, version) {
|
|
38
|
+
const versionSlug = version.replace(/^v/, '');
|
|
39
|
+
const map = {
|
|
40
|
+
'aarch64-apple-darwin': `lain-${versionSlug}-aarch64-apple-darwin.tar.gz`,
|
|
41
|
+
'x86_64-unknown-linux-gnu': `lain-${versionSlug}-x86_64-unknown-linux-gnu.tar.gz`,
|
|
42
|
+
'aarch64-unknown-linux-gnu': `lain-${versionSlug}-aarch64-unknown-linux-gnu.tar.gz`,
|
|
43
|
+
'x86_64-pc-windows-msvc': `lain-${versionSlug}-x86_64-pc-windows-msvc.tar.gz`,
|
|
44
|
+
};
|
|
45
|
+
const asset = map[platform];
|
|
46
|
+
if (!asset) throw new Error(`Unsupported platform for binary download: ${platform}`);
|
|
47
|
+
return asset;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Ensure directory exists
|
|
51
|
+
function ensureDir(dir) {
|
|
52
|
+
if (!fs.existsSync(dir)) {
|
|
53
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Download file with curl (-f: fail on HTTP errors instead of saving
|
|
58
|
+
// the 404 page as the binary), fallback to PowerShell on Windows
|
|
59
|
+
function download(url, dest) {
|
|
60
|
+
console.log(` Downloading ${path.basename(dest)}...`);
|
|
61
|
+
try {
|
|
62
|
+
execSync(`curl -fsSL "${url}" -o "${dest}" --progress-bar`, { stdio: 'inherit' });
|
|
63
|
+
} catch (e) {
|
|
64
|
+
if (process.platform === 'win32') {
|
|
65
|
+
console.log(' curl not found, using PowerShell...');
|
|
66
|
+
execSync(
|
|
67
|
+
`powershell -Command "Invoke-WebRequest -Uri \\"${url}\\" -OutFile \\"${dest}\\""`,
|
|
68
|
+
{ stdio: 'inherit' }
|
|
69
|
+
);
|
|
70
|
+
} else {
|
|
71
|
+
throw new Error(`curl not found and no fallback available for ${process.platform}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Create default tuning.toml
|
|
77
|
+
function createTuningConfig() {
|
|
78
|
+
const content = `# Lain tuning configuration — loaded from ~/.lain/tuning.toml
|
|
79
|
+
# All values are optional; omit a field to use the built-in default.
|
|
80
|
+
|
|
81
|
+
[semantic]
|
|
82
|
+
threshold = 0.1 # Semantic search cosine similarity floor
|
|
83
|
+
anchor_weight = 0.3 # Weight for anchor_score in hybrid ranking
|
|
84
|
+
|
|
85
|
+
[ingestion]
|
|
86
|
+
max_pattern_edges = 200
|
|
87
|
+
lsp_pool_size = 4
|
|
88
|
+
files_per_batch = 50
|
|
89
|
+
max_files_per_scan = 5000
|
|
90
|
+
cochange_commit_window = 100
|
|
91
|
+
cochange_min_pair_count = 2
|
|
92
|
+
cochange_max_commit_files = 100
|
|
93
|
+
|
|
94
|
+
[execution]
|
|
95
|
+
default_command_timeout_secs = 60
|
|
96
|
+
default_test_timeout_secs = 300
|
|
97
|
+
lsp_symbol_poll_timeout_secs = 2
|
|
98
|
+
lsp_symbol_poll_interval_ms = 50
|
|
99
|
+
`;
|
|
100
|
+
fs.writeFileSync(TUNING_FILE, content);
|
|
101
|
+
console.log(` Created ${TUNING_FILE}`);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Create toolchains/ README
|
|
105
|
+
function createToolchainsDir() {
|
|
106
|
+
ensureDir(TOOLCHAINS_DIR);
|
|
107
|
+
const readme = `# User toolchain overrides
|
|
108
|
+
# Drop .toml files here to override built-in toolchain profiles.
|
|
109
|
+
# See the built-in profiles in the Lain source at toolchains/
|
|
110
|
+
`;
|
|
111
|
+
fs.writeFileSync(path.join(TOOLCHAINS_DIR, 'README.md'), readme);
|
|
112
|
+
console.log(` Created ${TOOLCHAINS_DIR}/`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Create models/ README
|
|
116
|
+
function createModelsDir() {
|
|
117
|
+
ensureDir(MODELS_DIR);
|
|
118
|
+
const readme = `# ONNX embedding models
|
|
119
|
+
# Place .onnx model files here for semantic search.
|
|
120
|
+
# Required files:
|
|
121
|
+
# model.onnx — the ONNX model
|
|
122
|
+
# tokenizer.json — the tokenizer
|
|
123
|
+
#
|
|
124
|
+
# Download the default model:
|
|
125
|
+
# ./scripts/install.sh --fast # if using Lain's install script
|
|
126
|
+
# or from https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2
|
|
127
|
+
`;
|
|
128
|
+
fs.writeFileSync(path.join(MODELS_DIR, 'README.md'), readme);
|
|
129
|
+
console.log(` Created ${MODELS_DIR}/`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Create the launcher script (shell for unix, batch for windows)
|
|
133
|
+
function createLauncher(binaryPath) {
|
|
134
|
+
const isWin = process.platform === 'win32';
|
|
135
|
+
const launcherName = isWin ? 'lain-launcher.cmd' : 'lain-launcher';
|
|
136
|
+
const launcherPath = path.join(BIN_DIR, launcherName);
|
|
137
|
+
const content = isWin
|
|
138
|
+
? `@echo off\n"${binaryPath}" %*`
|
|
139
|
+
: `#!/bin/sh\nexec "${binaryPath}" "$@"\n`;
|
|
140
|
+
fs.writeFileSync(launcherPath, content);
|
|
141
|
+
if (!isWin) fs.chmodSync(launcherPath, 0o755);
|
|
142
|
+
console.log(` Created ${launcherPath}`);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Create symlink in node_modules/.bin for npm-installed binaries
|
|
146
|
+
function createSymlink() {
|
|
147
|
+
const isWin = process.platform === 'win32';
|
|
148
|
+
const launcherName = isWin ? 'lain-launcher.cmd' : 'lain-launcher';
|
|
149
|
+
// node_modules/.bin is inside the package, not a sibling of node_modules
|
|
150
|
+
const nodeBin = path.join(__dirname, '..', 'node_modules', '.bin', launcherName);
|
|
151
|
+
try {
|
|
152
|
+
const binDir = path.dirname(nodeBin);
|
|
153
|
+
if (!fs.existsSync(binDir)) {
|
|
154
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
155
|
+
}
|
|
156
|
+
if (isWin) {
|
|
157
|
+
// nodeBin already ends in .cmd via launcherName, don't append again
|
|
158
|
+
fs.writeFileSync(nodeBin, `@echo off\n"${path.join(BIN_DIR, launcherName)}" %*`);
|
|
159
|
+
} else {
|
|
160
|
+
if (fs.existsSync(nodeBin)) fs.unlinkSync(nodeBin);
|
|
161
|
+
fs.symlinkSync(path.join(BIN_DIR, launcherName), nodeBin);
|
|
162
|
+
}
|
|
163
|
+
console.log(` Linked to node_modules/.bin/${launcherName}`);
|
|
164
|
+
} catch (e) {
|
|
165
|
+
if (e.code !== 'ENOENT' && e.code !== 'EEXIST') {
|
|
166
|
+
console.warn(` Warning: could not create .bin symlink: ${e.message}`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Main install
|
|
172
|
+
async function install() {
|
|
173
|
+
console.log('\n=== Lain installer ===\n');
|
|
174
|
+
|
|
175
|
+
// Ensure directories
|
|
176
|
+
ensureDir(BIN_DIR);
|
|
177
|
+
ensureDir(LAIN_DIR);
|
|
178
|
+
|
|
179
|
+
const platform = getPlatform();
|
|
180
|
+
const version = `v${require('../package.json').version}`;
|
|
181
|
+
const assetName = getAssetName(platform, version);
|
|
182
|
+
// Assets are tarballs containing the binary (`lain` / `lain.exe`).
|
|
183
|
+
const binaryName = process.platform === 'win32' ? 'lain.exe' : 'lain';
|
|
184
|
+
const binaryPath = path.join(BIN_DIR, binaryName);
|
|
185
|
+
const archivePath = path.join(BIN_DIR, assetName);
|
|
186
|
+
const githubRepo = 'spuentesp/lain';
|
|
187
|
+
const url = `https://github.com/${githubRepo}/releases/download/${version}/${assetName}`;
|
|
188
|
+
|
|
189
|
+
console.log(` Platform: ${platform}`);
|
|
190
|
+
console.log(` Binary: ${binaryPath}`);
|
|
191
|
+
|
|
192
|
+
// Download + extract binary
|
|
193
|
+
if (fs.existsSync(binaryPath)) {
|
|
194
|
+
console.log(' Binary already exists — skipping download');
|
|
195
|
+
} else {
|
|
196
|
+
console.log(` Downloading from GitHub releases...`);
|
|
197
|
+
download(url, archivePath);
|
|
198
|
+
execSync(`tar xzf "${archivePath}" -C "${BIN_DIR}"`, { stdio: 'inherit' });
|
|
199
|
+
fs.unlinkSync(archivePath);
|
|
200
|
+
if (!fs.existsSync(binaryPath)) {
|
|
201
|
+
throw new Error(`Archive ${assetName} did not contain ${binaryName}`);
|
|
202
|
+
}
|
|
203
|
+
if (!process.platform.startsWith('win')) {
|
|
204
|
+
fs.chmodSync(binaryPath, 0o755);
|
|
205
|
+
}
|
|
206
|
+
console.log(` Installed ${binaryPath}`);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Create config directories
|
|
210
|
+
if (!fs.existsSync(TUNING_FILE)) {
|
|
211
|
+
createTuningConfig();
|
|
212
|
+
} else {
|
|
213
|
+
console.log(` tuning.toml already exists — skipping`);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (!fs.existsSync(TOOLCHAINS_DIR)) {
|
|
217
|
+
createToolchainsDir();
|
|
218
|
+
} else {
|
|
219
|
+
console.log(` toolchains/ already exists — skipping`);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (!fs.existsSync(MODELS_DIR)) {
|
|
223
|
+
createModelsDir();
|
|
224
|
+
} else {
|
|
225
|
+
console.log(` models/ already exists — skipping`);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Create launcher
|
|
229
|
+
createLauncher(binaryPath);
|
|
230
|
+
|
|
231
|
+
// Symlink for npm
|
|
232
|
+
createSymlink();
|
|
233
|
+
|
|
234
|
+
// Post-install: nothing more to do. The user configures their
|
|
235
|
+
// agent's MCP wiring themselves, pointing it at the zero-config
|
|
236
|
+
// `lain mcp` entry (walks up for .git, no repos.yaml needed).
|
|
237
|
+
|
|
238
|
+
console.log('\n=== Installation complete ===\n');
|
|
239
|
+
console.log(' The zero-config MCP entry point (run from any git repo):');
|
|
240
|
+
console.log(` ${binaryPath} mcp`);
|
|
241
|
+
console.log('\n Add it to your agent\'s MCP config as:');
|
|
242
|
+
console.log(' { "mcpServers": { "lain": { "command": "lain", "args": ["mcp"] } } }');
|
|
243
|
+
console.log('\n See `lain --help` for the full subcommand surface');
|
|
244
|
+
console.log(' (server, mcp, workspaces, repos, query, hooks, doctor).');
|
|
245
|
+
console.log('\n Or add lain to your PATH:');
|
|
246
|
+
console.log(` export PATH="$HOME/.lain/bin:$PATH"\n`);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
install().catch((err) => {
|
|
250
|
+
console.error('Installation failed:', err.message);
|
|
251
|
+
process.exit(1);
|
|
252
|
+
});
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Tests for npm-shim install.js logic
|
|
3
|
+
|
|
4
|
+
const assert = require('assert');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const os = require('os');
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
|
|
9
|
+
// ─────────────────────────────────────────────
|
|
10
|
+
// Helpers — reimplement the core logic under test
|
|
11
|
+
// so tests run against the same code paths.
|
|
12
|
+
// ─────────────────────────────────────────────
|
|
13
|
+
|
|
14
|
+
function getPlatform(platform = process.platform, arch = process.arch) {
|
|
15
|
+
if (platform === 'darwin' && arch === 'arm64') return 'aarch64-apple-darwin';
|
|
16
|
+
if (platform === 'linux' && arch === 'x64') return 'x86_64-unknown-linux-gnu';
|
|
17
|
+
if (platform === 'linux' && arch === 'arm64') return 'aarch64-unknown-linux-gnu';
|
|
18
|
+
if (platform === 'win32' && arch === 'x64') return 'x86_64-pc-windows-msvc';
|
|
19
|
+
throw new Error(`Unsupported platform: ${platform}-${arch}`);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function getAssetName(platform, version) {
|
|
23
|
+
const versionSlug = version.replace(/^v/, '');
|
|
24
|
+
const map = {
|
|
25
|
+
'aarch64-apple-darwin': `lain-${versionSlug}-aarch64-apple-darwin.tar.gz`,
|
|
26
|
+
'x86_64-unknown-linux-gnu': `lain-${versionSlug}-x86_64-unknown-linux-gnu.tar.gz`,
|
|
27
|
+
'aarch64-unknown-linux-gnu': `lain-${versionSlug}-aarch64-unknown-linux-gnu.tar.gz`,
|
|
28
|
+
'x86_64-pc-windows-msvc': `lain-${versionSlug}-x86_64-pc-windows-msvc.tar.gz`,
|
|
29
|
+
};
|
|
30
|
+
const asset = map[platform];
|
|
31
|
+
if (!asset) throw new Error(`Unsupported platform for binary download: ${platform}`);
|
|
32
|
+
return asset;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getBinaryName(isWin) {
|
|
36
|
+
return isWin ? 'lain.exe' : 'lain';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function buildUrl(platform, version = 'v0.1.0', repo = 'spuentesp/lain') {
|
|
40
|
+
const assetName = getAssetName(platform, version);
|
|
41
|
+
return `https://github.com/${repo}/releases/download/${version}/${assetName}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// ─────────────────────────────────────────────
|
|
45
|
+
// Tests
|
|
46
|
+
// ─────────────────────────────────────────────
|
|
47
|
+
|
|
48
|
+
let passed = 0;
|
|
49
|
+
let failed = 0;
|
|
50
|
+
|
|
51
|
+
function test(name, fn) {
|
|
52
|
+
try {
|
|
53
|
+
fn();
|
|
54
|
+
console.log(` ✓ ${name}`);
|
|
55
|
+
passed++;
|
|
56
|
+
} catch (e) {
|
|
57
|
+
console.log(` ✗ ${name}`);
|
|
58
|
+
console.log(` ${e.message}`);
|
|
59
|
+
failed++;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ── Platform detection ─────────────────────
|
|
64
|
+
|
|
65
|
+
console.log('\n[ getPlatform ]');
|
|
66
|
+
|
|
67
|
+
test('darwin arm64 → aarch64-apple-darwin', () => {
|
|
68
|
+
assert.strictEqual(getPlatform('darwin', 'arm64'), 'aarch64-apple-darwin');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('darwin x64 throws (no published asset)', () => {
|
|
72
|
+
let threw = false;
|
|
73
|
+
try { getPlatform('darwin', 'x64'); } catch (e) { threw = true; }
|
|
74
|
+
assert(threw, 'should throw on darwin x64');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('linux x64 → x86_64-unknown-linux-gnu', () => {
|
|
78
|
+
assert.strictEqual(getPlatform('linux', 'x64'), 'x86_64-unknown-linux-gnu');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('linux arm64 → aarch64-unknown-linux-gnu', () => {
|
|
82
|
+
assert.strictEqual(getPlatform('linux', 'arm64'), 'aarch64-unknown-linux-gnu');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('win32 x64 → x86_64-pc-windows-msvc', () => {
|
|
86
|
+
assert.strictEqual(getPlatform('win32', 'x64'), 'x86_64-pc-windows-msvc');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('unknown platform throws', () => {
|
|
90
|
+
let threw = false;
|
|
91
|
+
try { getPlatform('freebsd', 'x64'); } catch (e) { threw = true; }
|
|
92
|
+
assert(threw, 'should throw on freebsd');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// ── Asset name construction ─────────────────
|
|
96
|
+
|
|
97
|
+
console.log('\n[ getAssetName ]');
|
|
98
|
+
|
|
99
|
+
test('v0.1.0 → "0.1.0" slug (no leading v in asset name)', () => {
|
|
100
|
+
const name = getAssetName('x86_64-unknown-linux-gnu', 'v0.1.0');
|
|
101
|
+
assert.strictEqual(name, 'lain-0.1.0-x86_64-unknown-linux-gnu.tar.gz');
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('0.1.0 (no v) also works', () => {
|
|
105
|
+
const name = getAssetName('aarch64-unknown-linux-gnu', '0.1.0');
|
|
106
|
+
assert.strictEqual(name, 'lain-0.1.0-aarch64-unknown-linux-gnu.tar.gz');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test('macOS ARM asset name is correct', () => {
|
|
110
|
+
const name = getAssetName('aarch64-apple-darwin', 'v0.1.0');
|
|
111
|
+
assert.strictEqual(name, 'lain-0.1.0-aarch64-apple-darwin.tar.gz');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test('Windows asset name ends in .tar.gz', () => {
|
|
115
|
+
const name = getAssetName('x86_64-pc-windows-msvc', 'v0.1.0');
|
|
116
|
+
assert.strictEqual(name, 'lain-0.1.0-x86_64-pc-windows-msvc.tar.gz');
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test('unknown platform in getAssetName throws', () => {
|
|
120
|
+
let threw = false;
|
|
121
|
+
try { getAssetName('freebsd-x64', 'v0.1.0'); } catch (e) { threw = true; }
|
|
122
|
+
assert(threw, 'should throw on unknown platform');
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// ── URL construction ────────────────────────
|
|
126
|
+
|
|
127
|
+
console.log('\n[ buildUrl ]');
|
|
128
|
+
|
|
129
|
+
test('GitHub release URL is correctly formed', () => {
|
|
130
|
+
const url = buildUrl('x86_64-unknown-linux-gnu', 'v0.1.0');
|
|
131
|
+
assert.strictEqual(
|
|
132
|
+
url,
|
|
133
|
+
'https://github.com/spuentesp/lain/releases/download/v0.1.0/lain-0.1.0-x86_64-unknown-linux-gnu.tar.gz'
|
|
134
|
+
);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test('custom repo works', () => {
|
|
138
|
+
const url = buildUrl('aarch64-apple-darwin', 'v0.1.0', 'myorg/mylain');
|
|
139
|
+
assert.strictEqual(
|
|
140
|
+
url,
|
|
141
|
+
'https://github.com/myorg/mylain/releases/download/v0.1.0/lain-0.1.0-aarch64-apple-darwin.tar.gz'
|
|
142
|
+
);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('different version in URL', () => {
|
|
146
|
+
const url = buildUrl('aarch64-apple-darwin', 'v1.2.3');
|
|
147
|
+
assert.ok(url.includes('/v1.2.3/'));
|
|
148
|
+
assert.ok(url.includes('lain-1.2.3-aarch64-apple-darwin'));
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// ── Binary name ─────────────────────────────
|
|
152
|
+
|
|
153
|
+
console.log('\n[ getBinaryName ]');
|
|
154
|
+
|
|
155
|
+
test('win32 → lain.exe', () => {
|
|
156
|
+
assert.strictEqual(getBinaryName(true), 'lain.exe');
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test('unix → lain (no extension)', () => {
|
|
160
|
+
assert.strictEqual(getBinaryName(false), 'lain');
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// ── Symlink path construction ──────────────
|
|
164
|
+
|
|
165
|
+
console.log('\n[ createSymlink path ]');
|
|
166
|
+
|
|
167
|
+
test('node_modules/.bin path on unix', () => {
|
|
168
|
+
// Simulate: __dirname = /pkg/scripts → package root = /pkg
|
|
169
|
+
const __dirname = '/pkg/scripts';
|
|
170
|
+
const launcherName = 'lain-launcher';
|
|
171
|
+
const nodeBin = path.join(__dirname, '..', 'node_modules', '.bin', launcherName);
|
|
172
|
+
assert.strictEqual(nodeBin, '/pkg/node_modules/.bin/lain-launcher');
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test('node_modules/.bin path on windows', () => {
|
|
176
|
+
// path.join normalizes separators for the current platform
|
|
177
|
+
// on darwin it uses /, on win32 it uses \
|
|
178
|
+
const nodeBin = path.join('C:\\pkg', 'scripts', '..', 'node_modules', '.bin', 'lain-launcher.cmd');
|
|
179
|
+
const expected = path.join('C:\\pkg', 'node_modules', '.bin', 'lain-launcher.cmd');
|
|
180
|
+
assert.strictEqual(nodeBin, expected);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
// ── LAIN_DIR path ───────────────────────────
|
|
184
|
+
|
|
185
|
+
console.log('\n[ LAIN_DIR paths ]');
|
|
186
|
+
|
|
187
|
+
test('LAIN_DIR is ~/.lain', () => {
|
|
188
|
+
const lainDir = path.join(process.env.HOME, '.lain');
|
|
189
|
+
assert.strictEqual(lainDir, path.join(os.homedir(), '.lain'));
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test('BIN_DIR is ~/.lain/bin', () => {
|
|
193
|
+
const lainDir = path.join(process.env.HOME, '.lain');
|
|
194
|
+
const binDir = path.join(lainDir, 'bin');
|
|
195
|
+
assert.strictEqual(binDir, path.join(os.homedir(), '.lain', 'bin'));
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
// ── CI guard logic ──────────────────────────
|
|
199
|
+
|
|
200
|
+
console.log('\n[ CI guard ]');
|
|
201
|
+
|
|
202
|
+
test('CI=true skips install', () => {
|
|
203
|
+
const env = { CI: 'true' };
|
|
204
|
+
const shouldSkip = env.CI && !env.LAIN_FORCE_INSTALL;
|
|
205
|
+
assert.strictEqual(shouldSkip, true);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test('CI=true + LAIN_FORCE_INSTALL=1 does NOT skip', () => {
|
|
209
|
+
const env = { CI: 'true', LAIN_FORCE_INSTALL: '1' };
|
|
210
|
+
const shouldSkip = env.CI && !env.LAIN_FORCE_INSTALL;
|
|
211
|
+
assert.strictEqual(shouldSkip, false);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
test('CI unset does not skip', () => {
|
|
215
|
+
const env = {};
|
|
216
|
+
const shouldSkip = !!(env.CI && !env.LAIN_FORCE_INSTALL);
|
|
217
|
+
assert.strictEqual(shouldSkip, false);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
// ── ignore-scripts guard ────────────────────
|
|
221
|
+
|
|
222
|
+
console.log('\n[ --ignore-scripts guard ]');
|
|
223
|
+
|
|
224
|
+
test('npm_config_ignore_scripts=true skips install', () => {
|
|
225
|
+
const env = { npm_config_ignore_scripts: 'true' };
|
|
226
|
+
const shouldSkip = env.npm_config_ignore_scripts === 'true';
|
|
227
|
+
assert.strictEqual(shouldSkip, true);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
test('npm_config_ignore_scripts unset does not skip', () => {
|
|
231
|
+
const env = {};
|
|
232
|
+
const shouldSkip = env.npm_config_ignore_scripts === 'true';
|
|
233
|
+
assert.strictEqual(shouldSkip, false);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
// ── Launcher content ───────────────────────
|
|
237
|
+
|
|
238
|
+
console.log('\n[ createLauncher content ]');
|
|
239
|
+
|
|
240
|
+
test('Unix launcher uses exec with quoted binary path', () => {
|
|
241
|
+
const isWin = false;
|
|
242
|
+
const binaryPath = '/Users/user/.lain/bin/lain';
|
|
243
|
+
const content = isWin
|
|
244
|
+
? `@echo off\n"${binaryPath}" %*`
|
|
245
|
+
: `#!/bin/sh\nexec "${binaryPath}" "$@"\n`;
|
|
246
|
+
assert.strictEqual(content, '#!/bin/sh\nexec "/Users/user/.lain/bin/lain" "$@"\n');
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
test('Windows launcher uses @echo off with quoted binary path', () => {
|
|
250
|
+
const isWin = true;
|
|
251
|
+
const binaryPath = 'C:\\Users\\user\\.lain\\bin\\lain.exe';
|
|
252
|
+
const content = isWin
|
|
253
|
+
? `@echo off\n"${binaryPath}" %*`
|
|
254
|
+
: `#!/bin/sh\nexec "${binaryPath}" "$@"\n`;
|
|
255
|
+
assert.strictEqual(content, '@echo off\n"C:\\Users\\user\\.lain\\bin\\lain.exe" %*');
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
// ── Download URL round-trip ────────────────
|
|
259
|
+
|
|
260
|
+
console.log('\n[ Full URL round-trip for all platforms ]');
|
|
261
|
+
|
|
262
|
+
const platforms = [
|
|
263
|
+
{ p: 'darwin', a: 'arm64', expected: 'aarch64-apple-darwin' },
|
|
264
|
+
{ p: 'linux', a: 'x64', expected: 'x86_64-unknown-linux-gnu' },
|
|
265
|
+
{ p: 'linux', a: 'arm64', expected: 'aarch64-unknown-linux-gnu' },
|
|
266
|
+
{ p: 'win32', a: 'x64', expected: 'x86_64-pc-windows-msvc' },
|
|
267
|
+
];
|
|
268
|
+
|
|
269
|
+
for (const { p, a, expected } of platforms) {
|
|
270
|
+
test(`${p}-${a} round-trip`, () => {
|
|
271
|
+
const plat = getPlatform(p, a);
|
|
272
|
+
assert.strictEqual(plat, expected);
|
|
273
|
+
const asset = getAssetName(plat, 'v0.1.0');
|
|
274
|
+
assert.ok(asset.startsWith('lain-'));
|
|
275
|
+
assert.ok(asset.endsWith(`${plat}.tar.gz`));
|
|
276
|
+
const url = buildUrl(plat, 'v0.1.0');
|
|
277
|
+
assert.ok(url.startsWith('https://github.com/spuentesp/lain/releases/download/v0.1.0/lain-'));
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// ── Summary ────────────────────────────────
|
|
282
|
+
|
|
283
|
+
console.log(`\n${'─'.repeat(40)}`);
|
|
284
|
+
console.log(` Results: ${passed} passed, ${failed} failed`);
|
|
285
|
+
if (failed > 0) process.exit(1);
|
|
286
|
+
console.log(' All tests passed.\n');
|