@volcengine/mediakit-cli
Advanced tools
| const assert = require('node:assert/strict') | ||
| const fs = require('node:fs') | ||
| const os = require('node:os') | ||
| const path = require('node:path') | ||
| const test = require('node:test') | ||
| const { runInstallWizard } = require('./install-wizard') | ||
| function writeExecutable(file, content) { | ||
| fs.writeFileSync(file, content, { mode: 0o755 }) | ||
| } | ||
| async function captureLogs(t, fn) { | ||
| const oldLog = console.log | ||
| const logs = [] | ||
| console.log = (...args) => logs.push(args.join(' ')) | ||
| t.after(() => { | ||
| console.log = oldLog | ||
| }) | ||
| await fn() | ||
| console.log = oldLog | ||
| return logs.join('\n') | ||
| } | ||
| test('installs skills from the npm package skills directory', async (t) => { | ||
| const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'mediakit-install-wizard-')) | ||
| const bin = path.join(temp, 'bin') | ||
| fs.mkdirSync(bin) | ||
| const log = path.join(temp, 'calls.jsonl') | ||
| writeExecutable( | ||
| path.join(bin, 'npm'), | ||
| `#!/usr/bin/env node | ||
| const fs = require('node:fs') | ||
| fs.appendFileSync(${JSON.stringify(log)}, JSON.stringify({ cmd: 'npm', args: process.argv.slice(2) }) + '\\n') | ||
| process.exit(0) | ||
| `, | ||
| ) | ||
| writeExecutable( | ||
| path.join(bin, 'npx'), | ||
| `#!/usr/bin/env node | ||
| const fs = require('node:fs') | ||
| fs.appendFileSync(${JSON.stringify(log)}, JSON.stringify({ cmd: 'npx', args: process.argv.slice(2) }) + '\\n') | ||
| process.exit(0) | ||
| `, | ||
| ) | ||
| t.after(() => fs.rmSync(temp, { recursive: true, force: true })) | ||
| const oldPath = process.env.PATH | ||
| const oldHome = process.env.HOME | ||
| process.env.PATH = `${bin}${path.delimiter}${oldPath || ''}` | ||
| process.env.HOME = temp | ||
| t.after(() => { | ||
| process.env.PATH = oldPath | ||
| process.env.HOME = oldHome | ||
| }) | ||
| await runInstallWizard(['--skills-only', '--skill', 'byted-mediakit-video', '-y']) | ||
| const calls = fs | ||
| .readFileSync(log, 'utf8') | ||
| .trim() | ||
| .split('\n') | ||
| .map((line) => JSON.parse(line)) | ||
| assert.equal(calls.length, 1) | ||
| assert.equal(calls[0].cmd, 'npx') | ||
| assert.deepEqual(calls[0].args, [ | ||
| '-y', | ||
| 'skills', | ||
| 'add', | ||
| path.join(__dirname, '..', 'skills'), | ||
| '-s', | ||
| 'byted-mediakit-video', | ||
| '-g', | ||
| '-y', | ||
| ]) | ||
| assert(!calls[0].args.some((arg) => /^https?:\/\//.test(String(arg)))) | ||
| const state = JSON.parse( | ||
| fs.readFileSync(path.join(temp, '.mediakit', 'skills-state.json'), 'utf8'), | ||
| ) | ||
| assert.equal(state.package_name, '@volcengine/mediakit-cli') | ||
| assert.equal(state.version, '0.1.7') | ||
| assert.equal(state.skills_dir, path.join(__dirname, '..', 'skills')) | ||
| }) | ||
| test('regular install delegates skills installation to npm postinstall', async (t) => { | ||
| const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'mediakit-install-wizard-')) | ||
| const bin = path.join(temp, 'bin') | ||
| fs.mkdirSync(bin) | ||
| const log = path.join(temp, 'calls.jsonl') | ||
| writeExecutable( | ||
| path.join(bin, 'npm'), | ||
| `#!/usr/bin/env node | ||
| const fs = require('node:fs') | ||
| fs.appendFileSync(${JSON.stringify(log)}, JSON.stringify({ cmd: 'npm', args: process.argv.slice(2) }) + '\\n') | ||
| process.exit(0) | ||
| `, | ||
| ) | ||
| writeExecutable( | ||
| path.join(bin, 'npx'), | ||
| `#!/usr/bin/env node | ||
| const fs = require('node:fs') | ||
| fs.appendFileSync(${JSON.stringify(log)}, JSON.stringify({ cmd: 'npx', args: process.argv.slice(2) }) + '\\n') | ||
| process.exit(0) | ||
| `, | ||
| ) | ||
| t.after(() => fs.rmSync(temp, { recursive: true, force: true })) | ||
| const oldPath = process.env.PATH | ||
| process.env.PATH = `${bin}${path.delimiter}${oldPath || ''}` | ||
| t.after(() => { | ||
| process.env.PATH = oldPath | ||
| }) | ||
| const output = await captureLogs(t, () => runInstallWizard(['-y'])) | ||
| const calls = fs | ||
| .readFileSync(log, 'utf8') | ||
| .trim() | ||
| .split('\n') | ||
| .map((line) => JSON.parse(line)) | ||
| assert.deepEqual(calls, [ | ||
| { | ||
| cmd: 'npm', | ||
| args: [ | ||
| 'install', | ||
| '-g', | ||
| '@volcengine/mediakit-cli@0.1.7', | ||
| '--foreground-scripts', | ||
| '--ignore-scripts=false', | ||
| ], | ||
| }, | ||
| ]) | ||
| assert.match(output, /installing @volcengine\/mediakit-cli@0\.1\.7 via npm install -g/) | ||
| assert.match(output, /Installing skills \.\.\./) | ||
| assert.match(output, /✓ Successfully installed mediakit-cli 0\.1\.7/) | ||
| assert.match(output, /✓ Skills installed/) | ||
| }) | ||
| test('install wizard rejects unsupported version override', async (t) => { | ||
| const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'mediakit-install-wizard-')) | ||
| const bin = path.join(temp, 'bin') | ||
| fs.mkdirSync(bin) | ||
| const log = path.join(temp, 'calls.jsonl') | ||
| writeExecutable( | ||
| path.join(bin, 'npm'), | ||
| `#!/usr/bin/env node | ||
| const fs = require('node:fs') | ||
| fs.appendFileSync(${JSON.stringify(log)}, JSON.stringify({ cmd: 'npm', args: process.argv.slice(2) }) + '\\n') | ||
| process.exit(0) | ||
| `, | ||
| ) | ||
| writeExecutable( | ||
| path.join(bin, 'npx'), | ||
| `#!/usr/bin/env node | ||
| process.exit(0) | ||
| `, | ||
| ) | ||
| t.after(() => fs.rmSync(temp, { recursive: true, force: true })) | ||
| const oldPath = process.env.PATH | ||
| process.env.PATH = `${bin}${path.delimiter}${oldPath || ''}` | ||
| t.after(() => { | ||
| process.env.PATH = oldPath | ||
| }) | ||
| await assert.rejects( | ||
| () => runInstallWizard(['--version', '0.1.7', '-y']), | ||
| /--version is not supported/, | ||
| ) | ||
| assert.equal(fs.existsSync(log), false) | ||
| }) |
| const assert = require('node:assert/strict') | ||
| const fs = require('node:fs') | ||
| const os = require('node:os') | ||
| const path = require('node:path') | ||
| const test = require('node:test') | ||
| const { install } = require('./install') | ||
| function writeExecutable(file, content) { | ||
| fs.writeFileSync(file, content, { mode: 0o755 }) | ||
| } | ||
| async function captureLogs(t, fn) { | ||
| const oldLog = console.log | ||
| const logs = [] | ||
| console.log = (...args) => logs.push(args.join(' ')) | ||
| t.after(() => { | ||
| console.log = oldLog | ||
| }) | ||
| await fn() | ||
| console.log = oldLog | ||
| return logs.join('\n') | ||
| } | ||
| test('postinstall installs skills from the npm package skills directory when binary already exists', async (t) => { | ||
| const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'mediakit-postinstall-')) | ||
| const bin = path.join(temp, 'bin') | ||
| fs.mkdirSync(bin) | ||
| const log = path.join(temp, 'calls.jsonl') | ||
| writeExecutable( | ||
| path.join(bin, 'npx'), | ||
| `#!/usr/bin/env node | ||
| const fs = require('node:fs') | ||
| fs.appendFileSync(${JSON.stringify(log)}, JSON.stringify({ cmd: 'npx', args: process.argv.slice(2) }) + '\\n') | ||
| process.exit(0) | ||
| `, | ||
| ) | ||
| t.after(() => fs.rmSync(temp, { recursive: true, force: true })) | ||
| const oldPath = process.env.PATH | ||
| const oldHome = process.env.HOME | ||
| const oldSkip = process.env.MEDIAKIT_CLI_SKIP_DOWNLOAD | ||
| process.env.PATH = `${bin}${path.delimiter}${oldPath || ''}` | ||
| process.env.HOME = temp | ||
| delete process.env.MEDIAKIT_CLI_SKIP_DOWNLOAD | ||
| t.after(() => { | ||
| process.env.PATH = oldPath | ||
| process.env.HOME = oldHome | ||
| if (oldSkip === undefined) { | ||
| delete process.env.MEDIAKIT_CLI_SKIP_DOWNLOAD | ||
| } else { | ||
| process.env.MEDIAKIT_CLI_SKIP_DOWNLOAD = oldSkip | ||
| } | ||
| }) | ||
| const output = await captureLogs(t, () => install()) | ||
| const calls = fs | ||
| .readFileSync(log, 'utf8') | ||
| .trim() | ||
| .split('\n') | ||
| .map((line) => JSON.parse(line)) | ||
| assert.equal(calls.length, 1) | ||
| assert.deepEqual(calls[0].args, [ | ||
| '-y', | ||
| 'skills', | ||
| 'add', | ||
| path.join(__dirname, '..', 'skills'), | ||
| '-g', | ||
| '-y', | ||
| ]) | ||
| assert.match(output, /Installing skills \.\.\./) | ||
| assert.match(output, /✓ Skills installed/) | ||
| const state = JSON.parse( | ||
| fs.readFileSync(path.join(temp, '.mediakit', 'skills-state.json'), 'utf8'), | ||
| ) | ||
| assert.equal(state.package_name, '@volcengine/mediakit-cli') | ||
| assert.equal(state.version, '0.1.7') | ||
| assert.equal(state.skills_dir, path.join(__dirname, '..', 'skills')) | ||
| }) |
+6
-6
@@ -1,6 +0,6 @@ | ||
| 66598be436ea93af017992426536f458e8970debd932836664addc555b408970 mediakit-cli_0.1.9_darwin_amd64.tar.gz | ||
| b0616c2df676c87a955bbdd9ecb12e27fedd1c8f32c989ab9cf8fa3368f74f04 mediakit-cli_0.1.9_darwin_arm64.tar.gz | ||
| 229fdd6ab98818cb5790b62c64f0182fac0e4158456111f7ded994661db94463 mediakit-cli_0.1.9_linux_amd64.tar.gz | ||
| af403f49fc01aa7cd317a8b9c8b2de4ab2267a6136847f972a847a846c579f16 mediakit-cli_0.1.9_linux_arm64.tar.gz | ||
| 64edb2f1faa40b34fc61a072cc10a1df498b1057bc33842277f3ababcbced147 mediakit-cli_0.1.9_windows_amd64.zip | ||
| 8a4885558e168f8595ee18bce3a6c710a274ce56f917687564364a51e088e6bd mediakit-cli_0.1.9_windows_arm64.zip | ||
| 71d355a4b018b4a93e7f89ca2094f3b3c1133675416576003aa406feb0018e29 mediakit-cli_0.2.0-beta.0_darwin_amd64.tar.gz | ||
| 18255028c96e03c896f488c271494307164967df974d552e1730b67e3903778b mediakit-cli_0.2.0-beta.0_darwin_arm64.tar.gz | ||
| cc4b78f7d44d231a1272e23132190a7b6565be08865486398a8ff366b9e9e035 mediakit-cli_0.2.0-beta.0_linux_amd64.tar.gz | ||
| 22f4673d7e91e17b1db4079c59644bcbf57626a239791fd86c1333fd437e71c0 mediakit-cli_0.2.0-beta.0_linux_arm64.tar.gz | ||
| 7f912402c18d2f84a0cebb262cdd684bba463c2c31010aa1ce4e0f7a085bfd85 mediakit-cli_0.2.0-beta.0_windows_amd64.zip | ||
| 3ebc51347f7378f8754a831597f096caaa448fd798e2e2e639e1021b55985f89 mediakit-cli_0.2.0-beta.0_windows_arm64.zip |
+1
-1
| { | ||
| "name": "@volcengine/mediakit-cli", | ||
| "version": "0.1.9", | ||
| "version": "0.2.0-beta.0", | ||
| "description": "MediaKit CLI with multi-platform binary distribution via npm", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 2 instances
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 2 instances
210302
3.7%65
3.17%702
48.73%39
160%