fix(tasks): load goal task controller from the app entrypoint
This commit is contained in:
parent
51e4acacfe
commit
6e6277d521
|
|
@ -13,17 +13,26 @@ const read = f => fs.readFileSync(path.join(root, f), 'utf8');
|
|||
test('goal task page: authenticated controls, stable polling, XSS, report and responsive layout', async () => {
|
||||
const template = read('web/templates/index.html');
|
||||
const pageHTML = template.slice(template.indexOf('<div id="page-tasks"'), template.indexOf('<!-- C2 监听器管理页面 -->')).replace('class="page"','class="page active"');
|
||||
// Load exactly the entrypoint's scripts in their original order. Do not inject
|
||||
// long-tasks.js independently: that hid a missing production script tag.
|
||||
const scriptTags = [...template.matchAll(/<script\b[^>]*\bsrc=["']([^"']+)["'][^>]*><\/script>/g)]
|
||||
.filter(match => /^\/static\/js\/(router|auth|tasks|long-tasks)\.js(?:\?|$)/.test(match[1]))
|
||||
.map(match => match[0]).join('');
|
||||
const styleTags = [...template.matchAll(/<link\b[^>]*\bhref=["']([^"']+)["'][^>]*>/g)]
|
||||
.filter(match => /^\/static\/css\/(style|mobile|long-tasks)\.css(?:\?|$)/.test(match[1]))
|
||||
.map(match => match[0]).join('');
|
||||
const locale = JSON.parse(read('web/static/i18n/zh-CN.json'));
|
||||
const task = { id: 'fixture', name: '本地材料整理 <img src=x onerror="window.bad=1">', status: 'draft', revision: 0, objective: 'Produce a verified report', scope: 'Local fixture only', criteria: 'Evidence and gaps', strategy: '', summary: '', steps: [], guidance: [], question: '', rounds: 0, max_rounds: 40, remaining_seconds: 3600, updated_at: new Date().toISOString() };
|
||||
const authenticated = [], actions = [];
|
||||
const server = http.createServer(async (req, res) => {
|
||||
if (req.url.startsWith('/static/')) { const file = path.join(root, 'web', req.url); res.setHeader('Content-Type', file.endsWith('.css') ? 'text/css; charset=utf-8' : 'text/javascript; charset=utf-8'); return res.end(fs.readFileSync(file)); }
|
||||
const server = http.createServer(async (req, res) => {
|
||||
if (req.url.startsWith('/static/')) { const file = path.join(root, 'web', new URL(req.url, 'http://fixture').pathname); res.setHeader('Content-Type', file.endsWith('.css') ? 'text/css; charset=utf-8' : 'text/javascript; charset=utf-8'); return res.end(fs.readFileSync(file)); }
|
||||
if (req.url === '/') {
|
||||
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
||||
const html = `<!doctype html><html data-theme="light"><head><meta charset="UTF-8"><link rel="stylesheet" href="/static/css/style.css"><link rel="stylesheet" href="/static/css/mobile.css"><link rel="stylesheet" href="/static/css/long-tasks.css"><style>.page-content{padding:16px}*{box-sizing:border-box}</style></head><body><div class="container"><main class="main-layout"><section class="content-area">${pageHTML}</section></main></div><script>window.t=(key,opts={})=>{let v=key.split('.').reduce((o,k)=>o&&o[k],${JSON.stringify(locale).replaceAll("<", "\\u003c")});return String(v||key).replace(/{{(\\w+)}}/g,(_,k)=>String(opts[k]??''))};window.closeAppModal=()=>{};window.openAppModal=()=>{};window.initializeChatUI=()=>{};window.refreshAppData=async()=>{};window.refreshBatchQueues=()=>{};window.toggleTasksAutoRefresh=()=>{};</script><script src="/static/js/auth.js"></script><script>document.removeEventListener('DOMContentLoaded', initializeApp);saveAuth('fixture-token',new Date(Date.now()+3600000),{permissions:['tasks:read','tasks:write','tasks:delete'],scope:'own'});</script><script src="/static/js/long-tasks.js"></script><script>initLongTasks();</script></body></html>`; return res.end(html);
|
||||
const html = `<!doctype html><html data-theme="light"><head><meta charset="UTF-8">${styleTags}<style>.page-content{padding:16px}*{box-sizing:border-box}</style></head><body><div class="container"><main class="main-layout"><section class="content-area">${pageHTML}</section></main></div><script>window.t=(key,opts={})=>{let v=key.split('.').reduce((o,k)=>o&&o[k],${JSON.stringify(locale).replaceAll("<", "\\u003c")});return String(v||key).replace(/{{(\\w+)}}/g,(_,k)=>String(opts[k]??''))};window.closeAppModal=()=>{};window.openAppModal=()=>{};window.initializeChatUI=()=>{};window.refreshAppData=async()=>{};</script>${scriptTags}<script>document.removeEventListener('DOMContentLoaded', initializeApp);saveAuth('fixture-token',new Date(Date.now()+3600000),{permissions:['tasks:read','tasks:write','tasks:delete'],scope:'own'});</script></body></html>`; return res.end(html);
|
||||
}
|
||||
if (req.url === '/api/auth/validate') { res.setHeader('Content-Type','application/json'); return res.end('{}'); }
|
||||
if (req.url === '/favicon.ico') { res.statusCode=204; return res.end(); }
|
||||
if (req.url.startsWith('/api/batch-tasks')) { res.setHeader('Content-Type','application/json'); return res.end(JSON.stringify({queues:[],total:0,total_pages:1})); }
|
||||
if (req.url.startsWith('/api/long-tasks')) {
|
||||
authenticated.push(req.headers.authorization);
|
||||
if (req.headers.authorization !== 'Bearer fixture-token') { res.statusCode = 401; return res.end('{}'); }
|
||||
|
|
@ -54,7 +63,11 @@ test('goal task page: authenticated controls, stable polling, XSS, report and re
|
|||
const errors = []; page.on('pageerror', e => { errors.push(e.message); process.stderr.write('PAGE: ' + e.stack + '\n'); });
|
||||
page.on('console', m => { if (m.type() === 'error' || m.type() === 'warning') process.stderr.write('CONSOLE: ' + m.text() + '\n'); });
|
||||
page.setDefaultTimeout(10000);
|
||||
await page.goto('http://127.0.0.1:' + server.address().port);
|
||||
await page.goto('http://127.0.0.1:' + server.address().port + '/#tasks');
|
||||
await page.waitForFunction(() => document.getElementById('long-task-workspace').dataset.initialized === 'true');
|
||||
await page.evaluate(() => applyRBACToUI(document.getElementById('page-tasks')));
|
||||
assert.equal(await page.locator('#task-new-goal').isVisible(), true);
|
||||
assert.equal(await page.locator('#task-new-batch').isVisible(), false);
|
||||
await page.locator('[data-lt-action=select]').click();
|
||||
await page.locator('#lt-name').waitFor();
|
||||
await page.waitForFunction(() => document.getElementById('lt-name').textContent.includes('本地材料'));
|
||||
|
|
@ -95,7 +108,13 @@ test('goal task page: authenticated controls, stable polling, XSS, report and re
|
|||
await page.locator('[data-task-tab=batch]').click();
|
||||
assert.equal(await page.locator('#long-task-workspace').isVisible(), false);
|
||||
assert.equal(await page.locator('#task-batch-workspace').isVisible(), true);
|
||||
await page.evaluate(() => cleanupLongTasks());
|
||||
await page.evaluate(() => applyRBACToUI(document.getElementById('page-tasks')));
|
||||
assert.equal(await page.locator('#task-new-goal').isVisible(), false);
|
||||
assert.equal(await page.locator('#task-new-batch').isVisible(), true);
|
||||
await page.evaluate(() => { saveAuth('fixture-token',new Date(Date.now()+3600000),{permissions:['tasks:read'],scope:'own'}); applyRBACToUI(); });
|
||||
await page.locator('[data-task-tab=goals]').click();
|
||||
assert.equal(await page.locator('#task-new-goal').isVisible(), false, 'tab switches must preserve denied write permission');
|
||||
await page.evaluate(() => cleanupTasksPage());
|
||||
assert.equal(authenticated.every(a => a === 'Bearer fixture-token'), true);
|
||||
assert.ok(actions.includes('create') && actions.includes('report') && actions.includes('pause'));
|
||||
assert.deepEqual(errors, []);
|
||||
|
|
|
|||
|
|
@ -61,3 +61,6 @@
|
|||
#page-tasks .btn-primary { color:var(--bg-primary,#fff); background:var(--accent-color,#2563eb); }
|
||||
#task-new-goal[hidden],#task-new-batch[hidden] { display:none !important; }
|
||||
.lt-status-cleanup_unconfirmed { background:#fee2e2; color:#b91c1c; }
|
||||
|
||||
#page-tasks[data-task-mode="goals"] #task-new-batch,
|
||||
#page-tasks[data-task-mode="batch"] #task-new-goal { display:none !important; }
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
const { test } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
|
||||
const web = path.resolve(__dirname, '../..');
|
||||
const template = fs.readFileSync(path.join(web, 'templates/index.html'), 'utf8');
|
||||
|
||||
test('the production task page loads its goal-task controller and styles', () => {
|
||||
const scripts = [...template.matchAll(/<script\b[^>]*\bsrc=["']([^"']+)["'][^>]*>/g)]
|
||||
.map(match => new URL(match[1], 'http://fixture').pathname);
|
||||
for (const script of ['router', 'tasks', 'long-tasks']) {
|
||||
const url = `/static/js/${script}.js`;
|
||||
assert.equal(scripts.filter(src => src === url).length, 1, `${url} must be included once by the real entrypoint`);
|
||||
assert.ok(fs.existsSync(path.join(web, url)), `${url} must exist`);
|
||||
}
|
||||
const styles = [...template.matchAll(/<link\b[^>]*\bhref=["']([^"']+)["'][^>]*>/g)]
|
||||
.map(match => new URL(match[1], 'http://fixture').pathname);
|
||||
assert.ok(styles.includes('/static/css/long-tasks.css'));
|
||||
});
|
||||
|
|
@ -19,8 +19,9 @@
|
|||
state.tab = tab;
|
||||
el('long-task-workspace').hidden = tab !== 'goals';
|
||||
el('task-batch-workspace').hidden = tab !== 'batch';
|
||||
el('task-new-goal').hidden = tab !== 'goals';
|
||||
el('task-new-batch').hidden = tab !== 'batch';
|
||||
// Page mode and RBAC own separate visibility rules. Permission refreshes
|
||||
// must not reveal the other mode's button, or tab switches reveal denied controls.
|
||||
el('page-tasks').dataset.taskMode = tab;
|
||||
document.querySelectorAll('[data-task-tab]').forEach(b => b.setAttribute('aria-selected', String(b.dataset.taskTab === tab)));
|
||||
if (tab === 'goals') refresh();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@
|
|||
<link rel="stylesheet" href="/static/css/vulnerability-workspace.css?v=20261113-aligned-overview">
|
||||
<link rel="stylesheet" href="/static/css/vulnerability-list.css?v=20261113-compact-rows">
|
||||
<script src="/static/js/router.js?v=20261011-token-settings"></script>
|
||||
<link rel="stylesheet" href="/static/css/long-tasks.css">
|
||||
<link rel="stylesheet" href="/static/css/long-tasks.css?v=20261113-goal-tasks">
|
||||
</head>
|
||||
<body>
|
||||
<div id="login-overlay" class="login-overlay" style="display: none;">
|
||||
|
|
@ -2978,12 +2978,12 @@
|
|||
|
||||
<!-- 任务管理页面 -->
|
||||
|
||||
<div id="page-tasks" class="page">
|
||||
<div id="page-tasks" class="page" data-task-mode="goals">
|
||||
<div class="page-header">
|
||||
<h2 data-i18n="tasks.title">任务管理</h2>
|
||||
<div class="page-header-actions">
|
||||
<button id="task-new-goal" class="btn-primary" data-require-permission="tasks:write" data-i18n="longTasks.new">新建目标任务</button>
|
||||
<button id="task-new-batch" hidden class="btn-primary" data-require-permission="tasks:write" onclick="showBatchImportModal()" data-i18n="longTasks.newBatch">新建批量队列</button>
|
||||
<button id="task-new-batch" class="btn-primary" data-require-permission="tasks:write" onclick="showBatchImportModal()" data-i18n="longTasks.newBatch">新建批量队列</button>
|
||||
<label class="auto-refresh-toggle">
|
||||
<input type="checkbox" id="tasks-auto-refresh" checked onchange="toggleTasksAutoRefresh(this.checked)">
|
||||
<span data-i18n="tasks.autoRefresh">自动刷新</span>
|
||||
|
|
@ -7174,7 +7174,8 @@
|
|||
<script src="/static/js/vulnerability-download.js?v=20261030-2"></script>
|
||||
<script src="/static/js/webshell.js?v=20261011-token-usage-tool-title"></script>
|
||||
<script src="/static/js/chat-files.js?v=20261103-personal-integration"></script>
|
||||
<script src="/static/js/tasks.js?v=20261103-personal-integration"></script>
|
||||
<script src="/static/js/tasks.js?v=20261113-goal-tasks"></script>
|
||||
<script src="/static/js/long-tasks.js?v=20261113-goal-tasks"></script>
|
||||
<script src="/static/js/workflow-package-client.js"></script>
|
||||
<script src="/static/js/workflows.js"></script>
|
||||
<script src="/static/js/update.js?v={{.Version}}-update-status"></script>
|
||||
|
|
|
|||
Loading…
Reference in New Issue