diff --git a/internal/handler/assessment.go b/internal/handler/assessment.go index fff481f0..baed96f1 100644 --- a/internal/handler/assessment.go +++ b/internal/handler/assessment.go @@ -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 { diff --git a/scripts/assessment-browser-smoke.mjs b/scripts/assessment-browser-smoke.mjs index c1eefb4c..ba95eb9e 100644 --- a/scripts/assessment-browser-smoke.mjs +++ b/scripts/assessment-browser-smoke.mjs @@ -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==='本地测评 · 浏览器验证'"); diff --git a/web/static/js/assessments.js b/web/static/js/assessments.js index b6942dcc..df310e62 100644 --- a/web/static/js/assessments.js +++ b/web/static/js/assessments.js @@ -116,7 +116,7 @@ const field = (name, type, value, extra) => ''; dialog.innerHTML = '