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,72 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs/promises');
|
||||
const path = require('node:path');
|
||||
const os = require('node:os');
|
||||
const { execFileSync } = require('node:child_process');
|
||||
const { createContext } = require('../../dist/internal/runtime/context');
|
||||
const { listTaskScripts } = require('../../dist/internal/execution/scriptInventory');
|
||||
|
||||
test('no-argument runner lists legacy JS candidates without evaluating scripts or config', async (t) => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'ql-inventory-'));
|
||||
t.after(() => fs.rm(root, { recursive: true, force: true }));
|
||||
const context = createContext({ root }, { PATH: process.env.PATH });
|
||||
const scripts = context.paths.dir_scripts;
|
||||
await fs.mkdir(scripts, { recursive: true });
|
||||
await fs.mkdir(context.paths.dir_config, { recursive: true });
|
||||
await fs.writeFile(context.paths.file_config_user, 'exit 99\n');
|
||||
await fs.writeFile(
|
||||
path.join(scripts, 'job.js'),
|
||||
'throw Error("must not execute");\nconst $ = new Env("Daily job");\n',
|
||||
);
|
||||
await fs.writeFile(
|
||||
path.join(scripts, 'plain.js'),
|
||||
'throw Error("must not execute")',
|
||||
);
|
||||
await fs.writeFile(path.join(scripts, 'sendNotify.js'), '');
|
||||
await fs.writeFile(path.join(scripts, 'python.py'), '');
|
||||
await fs.mkdir(path.join(scripts, 'directory.js'));
|
||||
const old = await fs.readFile(
|
||||
path.resolve(__dirname, '../../../shell/otask.sh'),
|
||||
'utf8',
|
||||
);
|
||||
const definition = old.slice(
|
||||
old.indexOf('gen_array_scripts() {'),
|
||||
old.indexOf('## 使用说明'),
|
||||
);
|
||||
const legacy = execFileSync(
|
||||
'bash',
|
||||
[
|
||||
'-c',
|
||||
definition + '\ngen_array_scripts\nprintf "%s\\n" "${array_scripts[@]}"',
|
||||
],
|
||||
{
|
||||
env: { PATH: process.env.PATH, dir_scripts: scripts },
|
||||
encoding: 'utf8',
|
||||
},
|
||||
)
|
||||
.trim()
|
||||
.split('\n')
|
||||
.sort();
|
||||
const expected = [
|
||||
{ file: 'job.js', name: 'Daily job' },
|
||||
{ file: 'plain.js', name: null },
|
||||
];
|
||||
assert.deepEqual(await listTaskScripts(context), expected);
|
||||
assert.deepEqual(
|
||||
expected.map((x) => x.file),
|
||||
legacy,
|
||||
);
|
||||
const entry = path.resolve(__dirname, '../../dist/runner.js');
|
||||
const run = (args) =>
|
||||
execFileSync(process.execPath, [entry, '--root', root, ...args], {
|
||||
env: { PATH: process.env.PATH, QL_LANG: 'en' },
|
||||
encoding: 'utf8',
|
||||
});
|
||||
assert.deepEqual(JSON.parse(run(['--json'])).data.scripts, expected);
|
||||
assert.match(run([]), /Available scripts:/);
|
||||
assert.equal(JSON.parse(run(['--help', '--json'])).data.scripts, undefined);
|
||||
await fs.rm(scripts, { recursive: true });
|
||||
assert.deepEqual(JSON.parse(run(['--json'])).data.scripts, []);
|
||||
assert.match(run([]), /No scripts available/);
|
||||
});
|
||||
Reference in New Issue
Block a user