mirror of
https://github.com/whyour/qinglong.git
synced 2026-10-01 05:13:50 +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,71 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs/promises');
|
||||
const os = require('node:os');
|
||||
const path = require('node:path');
|
||||
const { spawnSync } = require('node:child_process');
|
||||
const { createContext } = require('../../dist/internal/runtime/context');
|
||||
const { inspectPanel } = require('../../dist/internal/maintenance/check');
|
||||
const { loggedOperation } = require('../../dist/internal/runtime/commandLog');
|
||||
const { installCliEntrypoints } = require('../../dist/local/entrypoints');
|
||||
|
||||
for (const language of ['zh', 'en', 'unsupported']) {
|
||||
test(`helper validation and generated wrappers honor locale: ${language}`, async (t) => {
|
||||
const root = await fs.mkdtemp(
|
||||
path.join(os.tmpdir(), 'ql-helper-language-'),
|
||||
);
|
||||
t.after(() => fs.rm(root, { recursive: true, force: true }));
|
||||
const env = { QL_LANG: language, QlPort: '65536' };
|
||||
const context = createContext({ root }, env);
|
||||
const expected = (zh, en) => (language === 'en' ? en : zh);
|
||||
await assert.rejects(
|
||||
inspectPanel(context),
|
||||
expected(/必须在 1 到 65535/, /between 1 and 65535/),
|
||||
);
|
||||
let called = false;
|
||||
await assert.rejects(
|
||||
loggedOperation(context, '../outside', async () => {
|
||||
called = true;
|
||||
}),
|
||||
expected(/日志目录无效/, /Invalid command log directory/),
|
||||
);
|
||||
assert.equal(called, false);
|
||||
assert.deepEqual(await fs.readdir(root), []);
|
||||
const bin = path.join(root, 'bin');
|
||||
await assert.rejects(
|
||||
installCliEntrypoints(bin, 'relative', env),
|
||||
expected(/必须为绝对路径/, /must be absolute/),
|
||||
);
|
||||
await fs.mkdir(bin);
|
||||
await fs.writeFile(path.join(bin, 'ql'), 'retained');
|
||||
await fs.mkdir(path.join(root, 'dist/ql.js'), { recursive: true });
|
||||
await assert.rejects(
|
||||
installCliEntrypoints(bin, root, env),
|
||||
expected(/必须为普通文件/, /not a regular file/),
|
||||
);
|
||||
assert.equal(await fs.readFile(path.join(bin, 'ql'), 'utf8'), 'retained');
|
||||
await fs.rm(path.join(root, 'dist/ql.js'), { recursive: true });
|
||||
for (const [file, name] of [
|
||||
['ql', 'qlMain'],
|
||||
['task', 'taskMain'],
|
||||
])
|
||||
await fs.writeFile(
|
||||
path.join(root, 'dist', file + '.js'),
|
||||
`exports.${name}=async()=>{throw new Error('private-detail')};exports.taskMain=exports.${name};`,
|
||||
);
|
||||
await installCliEntrypoints(bin, root, env);
|
||||
for (const name of ['ql', 'task']) {
|
||||
const result = spawnSync(path.join(bin, name), [], {
|
||||
env,
|
||||
encoding: 'utf8',
|
||||
});
|
||||
assert.equal(result.status, 1);
|
||||
assert.equal(result.stdout, '');
|
||||
assert.match(
|
||||
result.stderr,
|
||||
expected(/CLI 调用失败/, /CLI invocation failed/),
|
||||
);
|
||||
assert.doesNotMatch(result.stderr, /private-detail/);
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user