fix(assessment): select projects by name and preserve task links
This commit is contained in:
parent
900b21a99b
commit
9a0d83c491
|
|
@ -66,7 +66,19 @@ func (h *AssessmentHandler) Options(c *gin.Context) {
|
|||
for _, tool := range tools {
|
||||
safe = append(safe, gin.H{"name": tool.Function.Name, "description": tool.Function.Description})
|
||||
}
|
||||
c.JSON(200, gin.H{"models": options, "tools": safe})
|
||||
projects := []gin.H{}
|
||||
session, _ := security.CurrentSession(c)
|
||||
if security.SessionHasPermission(c, "project:read") {
|
||||
list, err := h.DB.ListProjectsForAccess("active", "", 500, 0, session.UserID, session.ScopeFor("project:read"))
|
||||
if err != nil {
|
||||
h.fail(c, err)
|
||||
return
|
||||
}
|
||||
for _, p := range list {
|
||||
projects = append(projects, gin.H{"id": p.ID, "name": p.Name})
|
||||
}
|
||||
}
|
||||
c.JSON(200, gin.H{"models": options, "tools": safe, "projects": projects})
|
||||
}
|
||||
func allAssessmentToolNames(h *AssessmentHandler) []string {
|
||||
if r, ok := h.Engine.Runtime.(*assessment.CSAIRuntime); ok && r.Agent != nil {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ const server = http.createServer(async (req, res) => {
|
|||
}
|
||||
let body = ''; for await (const chunk of req) body += chunk;
|
||||
const input = body ? JSON.parse(body) : {};
|
||||
if (url.pathname === '/api/assessments/options') { send({ models: [{ id: 'fixture', name: 'Fixture', model: 'local-test' }], tools: [{ name: 'inspect', description: 'Inspect local fixture' }] }); return; }
|
||||
if (url.pathname === '/api/assessments/options') { send({ models: [{ id: 'fixture', name: 'Fixture', model: 'local-test' }], tools: [{ name: 'inspect', description: 'Inspect local fixture' }], projects: [{id:'fixture-project',name:'本地测试项目'}] }); return; }
|
||||
if (url.pathname === '/api/assessments' && req.method === 'POST') {
|
||||
const created = { ...task, ...input, id: 'created-' + (++sequence), status: 'draft', steps: [], tokens: 0, rounds: 0, created_at: now(), updated_at: now() }; tasks.unshift(created); send({ assessment: created }); return;
|
||||
}
|
||||
|
|
@ -78,9 +78,10 @@ try {
|
|||
await evaluate("document.documentElement.dataset.theme='dark'"); await click('[data-tab=chain]'); await screenshot('desktop-dark-chain'); await evaluate("document.documentElement.dataset.theme='light'");
|
||||
await click('[data-tab=evidence]'); assert.equal(await evaluate("document.querySelectorAll('[data-assessment-action=vulnerability]').length"), 1);
|
||||
await click('[data-tab=logs]'); assert.equal(await evaluate('window.XSS || 0'), 0, 'untrusted log rendered as HTML');
|
||||
await click('[data-assessment-action=new]'); await waitFor("document.getElementById('assessment-create')?.open");
|
||||
await click('[data-assessment-action=new]'); await waitFor("document.getElementById('assessment-create')?.open"); assert.equal(await evaluate("document.querySelector('[name=project_id] option:last-child').textContent"), '本地测试项目');
|
||||
await evaluate(`document.querySelector('[name=name]').value='Created in browser';document.querySelector('[name=goal]').value='Inspect fixture';document.querySelector('[name=scope]').value='Local fixture';document.querySelector('[name=tools]').checked=true;document.getElementById('assessment-create-form').requestSubmit()`);
|
||||
await waitFor("document.querySelector('#assessment-detail h2')?.textContent==='Created in browser'");
|
||||
assert.ok((await evaluate('location.hash')).startsWith('#assessments?task=created-'), 'created task deep link missing');
|
||||
await click('[data-assessment-action=start]'); await waitFor("document.querySelector('#assessment-detail .assessment-status')?.dataset.status==='awaiting_approval'");
|
||||
await click('[data-tab=plan]'); await waitFor("!!document.querySelector('[data-assessment-action=approve]')"); await click('[data-assessment-action=approve]'); await waitFor("document.querySelector('#assessment-detail .assessment-status')?.dataset.status==='completed'");
|
||||
await click('[data-id=fixture-assessment]'); await waitFor("document.querySelector('#assessment-detail h2')?.textContent==='本地测评 · 浏览器验证'");
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@
|
|||
const field = (name, type, value, extra) => '<label class="assessment-field">' + esc(tr(name)) + '<input name="' + name + '" type="' + type + '" value="' + esc(value || '') + '" ' + (extra || '') + '></label>';
|
||||
dialog.innerHTML = '<form id="assessment-create-form"><h2>' + esc(tr('new')) + '</h2>' + field('name', 'text', '', 'required maxlength="200"') +
|
||||
['goal', 'scope', 'material'].map(name => '<label class="assessment-field">' + esc(tr(name)) + '<textarea name="' + name + '" rows="3" maxlength="' + (name === 'material' ? '24000' : '12000') + '"' + (name !== 'material' ? ' required' : '') + '></textarea></label>').join('') +
|
||||
'<div class="assessment-form-grid">' + field('project_id', 'text', '', 'maxlength="64"') + '<label class="assessment-field">' + esc(tr('model')) + '<select name="model">' + options.models.map(m => '<option value="' + esc(m.id) + '"' + (m.default ? ' selected' : '') + '>' + esc((m.name || m.id || tr('default')) + ' · ' + m.model) + '</option>').join('') + '</select></label>' +
|
||||
'<div class="assessment-form-grid">' + '<label class="assessment-field">' + esc(tr('project')) + '<select name="project_id"><option value="">' + esc(tr('none')) + '</option>' + (options.projects || []).map(p => '<option value="' + esc(p.id) + '">' + esc(p.name) + '</option>').join('') + '</select></label>' + '<label class="assessment-field">' + esc(tr('model')) + '<select name="model">' + options.models.map(m => '<option value="' + esc(m.id) + '"' + (m.default ? ' selected' : '') + '>' + esc((m.name || m.id || tr('default')) + ' · ' + m.model) + '</option>').join('') + '</select></label>' +
|
||||
'<label class="assessment-field">' + esc(tr('approvalMode')) + '<select name="approval_mode"><option value="policy">' + esc(tr('approvalPolicy')) + '</option><option value="manual">' + esc(tr('approvalManual')) + '</option></select></label>' + field('concurrency', 'number', 2, 'min="1" max="4" required') + field('token_budget', 'number', 200000, 'min="4000" max="10000000" required') + field('duration', 'number', 120, 'min="1" max="1440" required') + field('max_rounds', 'number', 12, 'min="1" max="50" required') + '</div>' +
|
||||
'<fieldset><legend>' + esc(tr('tools')) + '</legend><p>' + esc(tr('toolsHint')) + '</p><div class="assessment-tool-picker">' + options.tools.map(tool => '<label><input type="checkbox" name="tools" value="' + esc(tool.name) + '"><span><strong>' + esc(tool.name) + '</strong><small>' + esc(tool.description) + '</small></span></label>').join('') + '</div></fieldset><p id="assessment-create-error" role="alert"></p><div class="assessment-actions"><button type="button" class="btn-secondary" data-assessment-action="cancel-create">' + esc(tr('cancel')) + '</button><button class="btn-primary" type="submit">' + esc(tr('createDraft')) + '</button></div></form>';
|
||||
document.body.appendChild(dialog); dialog.addEventListener('click', onClick);
|
||||
|
|
@ -124,7 +124,7 @@
|
|||
ev.preventDefault(); const submit = dialog.querySelector('[type=submit]'); submit.disabled = true;
|
||||
const data = new FormData(ev.target), body = Object.fromEntries(data.entries());
|
||||
body.tools = data.getAll('tools'); ['concurrency', 'token_budget', 'max_rounds'].forEach(key => body[key] = Number(body[key])); body.remaining_seconds = Number(body.duration) * 60; delete body.duration;
|
||||
try { const created = await api('', 'POST', body); selected = created.assessment.id; events = []; after = 0; task = created.assessment; dialog.close(); dialog.remove(); tab = 'overview'; await refresh(true); }
|
||||
try { const created = await api('', 'POST', body); selected = created.assessment.id; history.replaceState(null, '', '#assessments?task=' + encodeURIComponent(selected)); events = []; after = 0; task = created.assessment; dialog.close(); dialog.remove(); tab = 'overview'; await refresh(true); }
|
||||
catch (err) { dialog.querySelector('#assessment-create-error').textContent = err.message; submit.disabled = false; }
|
||||
});
|
||||
dialog.showModal();
|
||||
|
|
@ -145,7 +145,7 @@
|
|||
else if (action === 'steer') await api('/' + id + '/control/steer', 'POST', { message: document.getElementById('assessment-guidance').value });
|
||||
else if (action === 'approve' || action === 'deny') await api('/' + id + '/steps/' + target.dataset.step + '/decision', 'POST', { approved: action === 'approve' });
|
||||
else if (action === 'retry') { if (!window.confirm(tr('retryConfirm'))) return; await api('/' + id + '/steps/' + target.dataset.step + '/retry', 'POST', {}); }
|
||||
else if (action === 'delete') { if (!window.confirm(tr('deleteConfirm'))) return; await api('/' + id, 'DELETE'); selected = ''; task = null; events = []; after = 0; }
|
||||
else if (action === 'delete') { if (!window.confirm(tr('deleteConfirm'))) return; await api('/' + id, 'DELETE'); selected = ''; history.replaceState(null, '', '#assessments'); task = null; events = []; after = 0; }
|
||||
else if (action === 'fact' || action === 'vulnerability' || action === 'asset') { await api('/' + id + '/publish', 'POST', { step_id: target.dataset.step, index: Number(target.dataset.index), kind: action }); message(tr('published')); }
|
||||
else if (action === 'report') {
|
||||
const response = await fetch('/api/assessments/' + id + '/report', { credentials: 'same-origin' }); if (!response.ok) throw new Error(response.statusText);
|
||||
|
|
|
|||
Loading…
Reference in New Issue