Files
qinglong/cli/test/internal/pathDiagnostics.test.cjs
T
whyour 801a71d740 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
2026-09-25 23:24:41 +08:00

84 lines
3.1 KiB
JavaScript

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 { within } = require('../../dist/internal/runtime/files');
const { createContext } = require('../../dist/internal/runtime/context');
const { loggedOperation } = require('../../dist/internal/runtime/commandLog');
const { executeTask } = require('../../dist/internal/execution/taskRunner');
const { syncRaw, repositoryName } = require('../../dist/internal/subscription/subscriptionRunner');
const { LocalApi } = require('../../dist/internal/runtime/api');
const subprocess = require('../../dist/internal/runtime/process');
for (const language of ['zh', 'en', 'unsupported']) {
test(`path and subscription failures use their own operation language: ${language}`, async (t) => {
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'ql-path-language-'));
t.after(() => fs.rm(root, { recursive: true, force: true }));
const env = { QL_LANG: language, real_log_path: '../../outside' };
const context = createContext({ root }, env);
const expected = (zh, en) => (language === 'en' ? en : zh);
const boundaryError = (error) => {
assert.equal(error.exitCode, 2);
assert.match(error.message, expected(/管理目录内部/, /descendant/));
return true;
};
for (const relative of ['', '..', '../outside', path.dirname(root)])
assert.throws(() => within(root, relative, env), boundaryError);
assert.equal(
within(root, 'safe/file.js', env),
path.join(root, 'safe/file.js'),
);
let called = false;
await assert.rejects(
loggedOperation(context, 'extra', async () => {
called = true;
}),
boundaryError,
);
assert.equal(called, false);
await assert.rejects(
executeTask(context, { argv: ['must-not-execute'] }),
boundaryError,
);
assert.throws(
() =>
repositoryName('https://example.invalid/invalid\nname', undefined, env),
expected(/仓库路径无效/, /Invalid repository path/),
);
await assert.rejects(
syncRaw(context, { url: 'file:///private/example.js' }),
expected(/需要 HTTP\(S\)/, /require HTTP\(S\)/),
);
assert.deepEqual(await fs.readdir(root), []);
t.mock.method(subprocess, 'checkedProcess', async (program, args) => {
assert.equal(program, 'curl');
await fs.writeFile(
args[args.indexOf('--output') + 1],
'console.log("fixture")',
);
return { code: 0 };
});
const calls = [];
t.mock.method(LocalApi.prototype, 'call', async (...args) => {
calls.push(args);
return { data: null };
});
await assert.rejects(
syncRaw(context, {
url: 'https://example.invalid/job.js',
autoAdd: true,
}),
(error) => {
assert.equal(error.exitCode, 1);
assert.match(
error.message,
expected(/无效任务列表/, /Invalid task list/),
);
return true;
},
);
assert.deepEqual(calls, [['crons']]);
});
}