mirror of
https://github.com/whyour/qinglong.git
synced 2026-12-01 09:45:36 +08:00
feat(cron): expose run receipts and modularize execution
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.
This commit is contained in:
1 parent
77ece406ac
commit
c5458596c8
346 files changed
+32133
-11556
No files matched your search
@@ -3,51 +3,110 @@ const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs/promises');
|
||||
const os = require('node:os');
|
||||
const path = require('node:path');
|
||||
const { checkDirectoryVersions, readDirectoryPage } = require('../../back/shared/directoryPage');
|
||||
const {
|
||||
checkDirectoryVersions,
|
||||
readDirectoryPage,
|
||||
} = require('../../back/shared/directoryPage');
|
||||
|
||||
test('directory cursors survive inserts and deletes and search reaches unloaded folders', async t => {
|
||||
test('directory cursors survive inserts and deletes and search reaches unloaded folders', async (t) => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'ql-file-page-'));
|
||||
t.after(() => fs.rm(root, { recursive: true, force: true }));
|
||||
await fs.mkdir(path.join(root,'dir'));
|
||||
await fs.mkdir(path.join(root,'.tmp'));
|
||||
await fs.writeFile(path.join(root,'.tmp','secret'),'');
|
||||
await fs.symlink(os.tmpdir(), path.join(root,'outside'));
|
||||
for (const name of ['a','c','e','dir/needle#&.js','dir/needle2.js']) await fs.writeFile(path.join(root,name),'1');
|
||||
const read = (after='', search='', dir='', folders=false, newest=false) => readDirectoryPage(root,['.tmp'],dir,after,search,folders,newest,2);
|
||||
await fs.mkdir(path.join(root, 'dir'));
|
||||
await fs.mkdir(path.join(root, '.tmp'));
|
||||
await fs.writeFile(path.join(root, '.tmp', 'secret'), '');
|
||||
await fs.symlink(os.tmpdir(), path.join(root, 'outside'));
|
||||
for (const name of ['a', 'c', 'e', 'dir/needle#&.js', 'dir/needle2.js'])
|
||||
await fs.writeFile(path.join(root, name), '1');
|
||||
const read = (
|
||||
after = '',
|
||||
search = '',
|
||||
dir = '',
|
||||
folders = false,
|
||||
newest = false,
|
||||
) =>
|
||||
readDirectoryPage(root, ['.tmp'], dir, after, search, folders, newest, 2);
|
||||
const first = await read();
|
||||
assert.deepEqual(first.data.map(x=>x.key),['dir','a']);
|
||||
await fs.unlink(path.join(root,'a'));
|
||||
await fs.writeFile(path.join(root,'b'),'2');
|
||||
assert.deepEqual(
|
||||
first.data.map((x) => x.key),
|
||||
['dir', 'a'],
|
||||
);
|
||||
await fs.unlink(path.join(root, 'a'));
|
||||
await fs.writeFile(path.join(root, 'b'), '2');
|
||||
const second = await read(first.next);
|
||||
assert.deepEqual(second.data.map(x=>x.key),['b','c']);
|
||||
assert.deepEqual((await read(second.next)).data.map(x=>x.key),['e']);
|
||||
assert.deepEqual((await read('','','',false,true)).data.map(x=>x.key),['dir','e']);
|
||||
assert.deepEqual((await read('','','',true)).data.map(x=>x.key),['dir']);
|
||||
assert.deepEqual((await read('','needle')).data.map(x=>x.key),['dir/needle#&.js','dir/needle2.js']);
|
||||
assert.deepEqual((await read('','secret')).data,[]);
|
||||
for (const dir of ['../','.tmp','outside']) await assert.rejects(read('','',dir), { status:403 });
|
||||
assert.deepEqual(
|
||||
second.data.map((x) => x.key),
|
||||
['b', 'c'],
|
||||
);
|
||||
assert.deepEqual(
|
||||
(await read(second.next)).data.map((x) => x.key),
|
||||
['e'],
|
||||
);
|
||||
assert.deepEqual(
|
||||
(await read('', '', '', false, true)).data.map((x) => x.key),
|
||||
['dir', 'e'],
|
||||
);
|
||||
assert.deepEqual(
|
||||
(await read('', '', '', true)).data.map((x) => x.key),
|
||||
['dir'],
|
||||
);
|
||||
assert.deepEqual(
|
||||
(await read('', 'needle')).data.map((x) => x.key),
|
||||
['dir/needle#&.js', 'dir/needle2.js'],
|
||||
);
|
||||
assert.deepEqual((await read('', 'secret')).data, []);
|
||||
for (const dir of ['../', '.tmp', 'outside'])
|
||||
await assert.rejects(read('', '', dir), { status: 403 });
|
||||
});
|
||||
|
||||
test('a sparse cross-directory search resumes after an empty batch', async t => {
|
||||
test('a sparse cross-directory search resumes after an empty batch', async (t) => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'ql-file-search-'));
|
||||
t.after(() => fs.rm(root, { recursive: true, force: true }));
|
||||
for (let i=0; i<513; i++) await fs.writeFile(path.join(root, 'a'+i), '');
|
||||
await fs.mkdir(path.join(root,'z')); await fs.writeFile(path.join(root,'z','needle'),'');
|
||||
const page = after => readDirectoryPage(root,[], '',after,'needle',false,false);
|
||||
for (let i = 0; i < 513; i++)
|
||||
await fs.writeFile(path.join(root, 'a' + i), '');
|
||||
await fs.mkdir(path.join(root, 'z'));
|
||||
await fs.writeFile(path.join(root, 'z', 'needle'), '');
|
||||
const page = (after) =>
|
||||
readDirectoryPage(root, [], '', after, 'needle', false, false);
|
||||
const first = await page('');
|
||||
assert.deepEqual(first.data,[]); assert.ok(first.next);
|
||||
assert.deepEqual((await page(first.next)).data.map(x=>x.key),['z/needle']);
|
||||
assert.deepEqual(first.data, []);
|
||||
assert.ok(first.next);
|
||||
assert.deepEqual(
|
||||
(await page(first.next)).data.map((x) => x.key),
|
||||
['z/needle'],
|
||||
);
|
||||
});
|
||||
|
||||
test('a delayed terminal page detects changes on either side of its cursor, including a previously traversed sibling', async t => {
|
||||
test('a delayed terminal page detects changes on either side of its cursor, including a previously traversed sibling', async (t) => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'ql-moved-page-'));
|
||||
t.after(() => fs.rm(root, { recursive: true, force: true }));
|
||||
for (const dir of ['a', 'b']) await fs.mkdir(path.join(root, dir));
|
||||
for (const key of ['a/one.js', 'b/two.js']) await fs.writeFile(path.join(root, key), key);
|
||||
const first = await readDirectoryPage(root, [], '', '', '.js', false, false, 1);
|
||||
const last = await readDirectoryPage(root, [], '', first.next, '.js', false, false, 2);
|
||||
for (const key of ['a/one.js', 'b/two.js'])
|
||||
await fs.writeFile(path.join(root, key), key);
|
||||
const first = await readDirectoryPage(
|
||||
root,
|
||||
[],
|
||||
'',
|
||||
'',
|
||||
'.js',
|
||||
false,
|
||||
false,
|
||||
1,
|
||||
);
|
||||
const last = await readDirectoryPage(
|
||||
root,
|
||||
[],
|
||||
'',
|
||||
first.next,
|
||||
'.js',
|
||||
false,
|
||||
false,
|
||||
2,
|
||||
);
|
||||
assert.equal(last.next, null);
|
||||
assert.deepEqual(last.data.map(r => r.key), ['b/two.js']);
|
||||
assert.deepEqual(
|
||||
last.data.map((r) => r.key),
|
||||
['b/two.js'],
|
||||
);
|
||||
const versions = [...first.versions, ...last.versions];
|
||||
assert.equal(await checkDirectoryVersions(root, [], versions), true);
|
||||
await fs.rename(path.join(root, 'b/two.js'), path.join(root, 'a/first.js'));
|
||||
@@ -55,11 +114,14 @@ test('a delayed terminal page detects changes on either side of its cursor, incl
|
||||
await fs.writeFile(path.join(root, 'b/new.js'), 'new');
|
||||
assert.equal(await checkDirectoryVersions(root, [], versions), false);
|
||||
const fresh = await readDirectoryPage(root, [], '', '', '.js', false, false);
|
||||
assert.deepEqual(fresh.data.map(r => r.key), ['a/first.js', 'b/new.js']);
|
||||
assert.deepEqual(
|
||||
fresh.data.map((r) => r.key),
|
||||
['a/first.js', 'b/new.js'],
|
||||
);
|
||||
assert.equal(await checkDirectoryVersions(root, [], fresh.versions), true);
|
||||
});
|
||||
|
||||
test('deleting and replacing the open directory invalidates its pages and a missing path can be checked again', async t => {
|
||||
test('deleting and replacing the open directory invalidates its pages and a missing path can be checked again', async (t) => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'ql-replaced-page-'));
|
||||
t.after(() => fs.rm(root, { recursive: true, force: true }));
|
||||
const dir = path.join(root, 'open');
|
||||
@@ -75,5 +137,15 @@ test('deleting and replacing the open directory invalidates its pages and a miss
|
||||
assert.equal(await checkDirectoryVersions(root, [], missing.versions), false);
|
||||
assert.equal(await checkDirectoryVersions(root, [], before.versions), false);
|
||||
await fs.symlink(os.tmpdir(), path.join(root, 'external'));
|
||||
assert.equal(await checkDirectoryVersions(root, [], [['external', null], ['../escape', null]]), false);
|
||||
assert.equal(
|
||||
await checkDirectoryVersions(
|
||||
root,
|
||||
[],
|
||||
[
|
||||
['external', null],
|
||||
['../escape', null],
|
||||
],
|
||||
),
|
||||
false,
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user