mirror of
https://github.com/whyour/qinglong.git
synced 2026-09-28 09:02:12 +08:00
feat(cli): cover OpenAPI with a remote npm CLI and internal panel tools (#3074)
* feat(cli): add unified Commander CLI for QingLong 2.x * fix(cli): publish via npm and address security review feedback * ci(cli): package npm artifacts and remove evaluation collateral * test(cli): use a fixed shell fixture for log retention * refactor(cli): separate remote npm client from panel tools * feat(cli): cover active panel OpenAPI resources * docs(cli): unify authentication and skill guidance * refactor(cli): isolate internal commands and generate Commander help * refactor(cli): organize remote and internal modules by responsibility * ci(cli): publish verified npm archives from master * fix(cli): publish under the whyour npm scope * ci: use npm trusted publishing for both packages * docs: introduce the published CLI on the project homepage * fix(cli): preserve server log truncation and correct login hints * fix(cli): accept dashboard record request bodies * fix(cli): preserve stdin for local task execution * fix(cli): resolve task executables after changing directory * fix(cli): preserve shell function tasks and sanitize test failures * fix(cli): preserve shell hook state and resolve workdir after hooks * fix(cli): preserve cleanup across shared shell task timeouts * fix(cli): isolate shell control descriptors and reap timed-out descendants
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const path = require('node:path');
|
||||
const { spawnSync } = require('node:child_process');
|
||||
const { startupMain } = require('../../dist/startup');
|
||||
|
||||
test('startup compatibility uses the shared host-start handler with exact mode and directory arguments', async (t) => {
|
||||
const main = require('../../dist/main');
|
||||
const calls = [];
|
||||
t.mock.method(main, 'main', async (args, surface, signal) => {
|
||||
calls.push({ args, surface, signal });
|
||||
return 7;
|
||||
});
|
||||
assert.equal(await startupMain([]), 7);
|
||||
assert.equal(
|
||||
await startupMain([
|
||||
'reload',
|
||||
'--root',
|
||||
'/a b',
|
||||
'--data-dir',
|
||||
'/storage/data',
|
||||
'--json',
|
||||
]),
|
||||
7,
|
||||
);
|
||||
assert.equal(await startupMain(['--root', '/a b', '--no-startup']), 7);
|
||||
assert.deepEqual(
|
||||
calls.map(({ args }) => args),
|
||||
[
|
||||
['start'],
|
||||
[
|
||||
'start',
|
||||
'--reload',
|
||||
'--root',
|
||||
'/a b',
|
||||
'--data-dir',
|
||||
'/storage/data',
|
||||
'--json',
|
||||
],
|
||||
['start', '--root', '/a b', '--no-startup'],
|
||||
],
|
||||
);
|
||||
assert.ok(
|
||||
calls.every(
|
||||
({ surface, signal }) =>
|
||||
surface === 'local' && signal instanceof AbortSignal,
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('installed startup entry has bilingual JSON help and validates before executing host operations', () => {
|
||||
const entry = path.resolve(__dirname, '../../dist/startup.js');
|
||||
const run = (args, language = 'zh') =>
|
||||
spawnSync(process.execPath, [entry, ...args], {
|
||||
env: { ...process.env, QL_DIR: '', QL_DATA_DIR: '', QL_LANG: language },
|
||||
encoding: 'utf8',
|
||||
timeout: 5000,
|
||||
});
|
||||
for (const [language, pattern] of [
|
||||
['zh', /用法/],
|
||||
['en', /Usage:/],
|
||||
]) {
|
||||
const result = run(['--help', '--json'], language);
|
||||
assert.equal(result.status, 0, result.stderr);
|
||||
const help = JSON.parse(result.stdout).data.help;
|
||||
assert.match(help, pattern);
|
||||
assert.match(help, /qinglong-cli/);
|
||||
assert.match(help, /reload/);
|
||||
}
|
||||
for (const args of [[], ['reload'], ['unexpected'], ['reload', 'extra']]) {
|
||||
const result = run([...args, '--json']);
|
||||
assert.equal(result.status, 2, result.stderr);
|
||||
assert.equal(result.stdout, '');
|
||||
assert.equal(JSON.parse(result.stderr).code, 2);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user