mirror of
https://github.com/whyour/qinglong.git
synced 2026-12-01 01:39:52 +08:00
Return committed trigger IDs and add CLI wait and trigger-specific logs while preserving API, CLI, transaction, deduplication and unknown-result semantics. Move scheduling, lifecycle, settlement, queries and legacy adapters into back/cron; remove obsolete internal import paths and circular dependencies. Apply project formatting across the repository, cover CJS/MJS in formatting hooks, add prettier:check and require formatting checks in AGENTS.md. Validation: backend build; 1398 backend/frontend tests passed (17 platform skips); 327 CLI tests passed (6 platform skips); 670 files pass format checks.
80 lines
2.8 KiB
JavaScript
80 lines
2.8 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 { spawnSync } = require('node:child_process');
|
|
|
|
test('standalone public commands load only public modules and never local operators or backend dependencies', async (t) => {
|
|
const root = await fs.realpath(
|
|
await fs.mkdtemp(path.join(os.tmpdir(), 'ql-loading-')),
|
|
);
|
|
t.after(() => fs.rm(root, { recursive: true, force: true }));
|
|
const dist = path.join(root, 'dist');
|
|
await fs.cp(path.resolve(__dirname, '../../dist'), dist, { recursive: true });
|
|
const script = `
|
|
const path = require('node:path');
|
|
const originalWrite = process.stdout.write.bind(process.stdout);
|
|
process.stdout.write = () => true;
|
|
process.stderr.write = () => true;
|
|
const entry = process.argv[1];
|
|
require(entry).main(JSON.parse(process.argv[2])).then(code => {
|
|
originalWrite(JSON.stringify({ code, modules: Object.keys(require.cache).map(file => path.relative(path.dirname(entry), file)) }));
|
|
});
|
|
`;
|
|
for (const [args, expected] of [
|
|
[['--help'], 0],
|
|
[['task', 'list', '--help'], 0],
|
|
[['auth', 'logout'], 0],
|
|
[['auth', 'status', '--json'], 3],
|
|
[['task', 'list', '--json'], 3],
|
|
[['subscription', 'list', '--json'], 3],
|
|
]) {
|
|
const child = spawnSync(
|
|
process.execPath,
|
|
['-e', script, path.join(dist, 'main.js'), JSON.stringify(args)],
|
|
{
|
|
cwd: root,
|
|
encoding: 'utf8',
|
|
env: {
|
|
PATH: process.env.PATH,
|
|
QL_CLI_CONFIG: path.join(root, 'missing/config.json'),
|
|
QL_DIR: '/nonexistent-panel',
|
|
},
|
|
timeout: 10000,
|
|
},
|
|
);
|
|
assert.equal(child.status, 0, child.stderr);
|
|
const result = JSON.parse(child.stdout);
|
|
assert.equal(result.code, expected, JSON.stringify(args));
|
|
assert.ok(result.modules.length > 0);
|
|
for (const module of result.modules) {
|
|
assert.ok(!module.startsWith('..'), `External module loaded: ${module}`);
|
|
assert.doesNotMatch(
|
|
module,
|
|
/^(local|internal|back|preload)[/\\]|(^|[/\\])node_modules[/\\]/,
|
|
JSON.stringify(args),
|
|
);
|
|
}
|
|
if (args.includes('--help'))
|
|
assert.ok(
|
|
!result.modules.some((module) =>
|
|
/^remote[/\\](commands[/\\](auth|open|task|subscription)\.js|api[/\\](client|download)\.js|auth[/\\])/.test(
|
|
module,
|
|
),
|
|
),
|
|
'Help eagerly loaded command implementation',
|
|
);
|
|
if (args[0] === 'task' && !args.includes('--help'))
|
|
assert.ok(
|
|
result.modules.includes(path.join('remote', 'commands', 'task.js')),
|
|
);
|
|
if (args[0] === 'subscription')
|
|
assert.ok(
|
|
result.modules.includes(
|
|
path.join('remote', 'commands', 'subscription.js'),
|
|
),
|
|
);
|
|
}
|
|
});
|