47 lines
4.1 KiB
JavaScript
47 lines
4.1 KiB
JavaScript
// Read-only full Dummy scanner Results inspection; never reads another project.
|
|
import { build } from 'esbuild';
|
|
import { mkdir, writeFile } from 'node:fs/promises';
|
|
import { pathToFileURL } from 'node:url';
|
|
import { resolve } from 'node:path';
|
|
const bundle = await build({ stdin: { resolveDir: process.cwd(), loader: 'ts', contents: `
|
|
import { canonicalModelsToDataset } from './src/features/project-import/canonical-model-to-dataset';
|
|
import { recordResultSheets } from './src/features/linked-results/record-results';
|
|
import { resultOutcomeFor, resultSheetRowToneFor } from './src/features/linked-results/result-message';
|
|
import { toolIdForRecord } from './src/importers/status-normalization';
|
|
import { inlineResultTableSheets } from './src/features/linked-results/inline-result-tables';
|
|
import { resultSectionRowClassName } from './src/features/linked-results/result-message';
|
|
import { loadCanonicalProjectWorkspace } from './src/features/project-import/load-canonical-project-workspace';
|
|
import { AssessorApiClient } from './src/api/assessor-api-client';
|
|
const base='http://127.0.0.1:4173/api/v1';
|
|
const get=async path=>{const response=await fetch(base+path);if(!response.ok)throw new Error(path+': '+response.status);return response.json();};
|
|
const project=await get('/projects/project-7cbcb7ad');if(project.name!=='Dummy')throw new Error('Only Dummy permitted');
|
|
const assessments=await get('/projects/'+project.id+'/assessments');
|
|
const models=[]; for(const a of assessments) models.push(await get('/assessments/'+a.id+'/model'));
|
|
const api=new AssessorApiClient({baseUrl:base,describeActivity:()=>undefined});
|
|
const workspace=await loadCanonicalProjectWorkspace({
|
|
listProjectAssessments:async()=>assessments,loadAssessmentModel:async id=>models.find(m=>m.assessment.id===id),
|
|
queryUnifiedResults:q=>api.queryUnifiedResults(q),listPolicyEvaluations:id=>api.listPolicyEvaluations(id),
|
|
getPolicyAnalysisOverview:id=>api.getPolicyAnalysisOverview(id)
|
|
},project.id,undefined,assessments.map(a=>a.id),{includeHistoricalScores:false,includeBaselineGuidance:false});
|
|
const dataset=workspace.dataset; const counts={}; const findings=[];
|
|
for(const sheet of dataset.sheets.filter(s=>s.isProjectSheet))for(const record of sheet.analysis.records){
|
|
const tool=toolIdForRecord(record,sheet.toolId); const tables=recordResultSheets(record,dataset.sheets,sheet.id,tool);
|
|
const inline=tool==='maester'?inlineResultTableSheets(record):[];
|
|
const key=tool??'mixed';counts[key]??={findings:0,tables:0,rows:0};counts[key].findings++;counts[key].tables+=tables.length;
|
|
for(const table of tables)counts[key].rows+=table.analysis.records.length;
|
|
for(const table of inline) { counts[key].inlineRows=(counts[key].inlineRows??0)+table.analysis.records.length;
|
|
for(const row of table.analysis.records){const tone=resultSectionRowClassName(tool,table.analysis.headers,row.fields.map(f=>f.value))??'neutral';counts[key][tone]=(counts[key][tone]??0)+1;} }
|
|
if(tables.length) findings.push({tool,id:record.id,title:record.title,outcome:resultOutcomeFor(record,tool),
|
|
binding:tool==='purple-knight'?{source:record.sourceFile,fields:record.fields.filter(f=>/file|datei|results?/i.test(f.label)),tables:tables.map(t=>({file:t.sourceFile,index:t.sourceTableIndex}))}:undefined,
|
|
rule:record.fields.filter(f=>/rule id|risk id|shortname/i.test(f.label)).map(f=>[f.label,f.value]),
|
|
links:record.fields.filter(f=>f.label==='Verwandte Daten').map(f=>f.value),
|
|
tables:tables.map(t=>({id:t.id,name:t.name,headers:t.analysis.headers,rows:t.analysis.records.length,
|
|
samples:t.analysis.records.slice(0,2).map(r=>r.fields.map(f=>f.value)),
|
|
tones:t.analysis.records.reduce((a,r)=>{const tone=resultSheetRowToneFor(tool,r,resultOutcomeFor(record,tool),{finding:record,sheet:t})??'neutral';a[tone]=(a[tone]??0)+1;return a;},{})}))});
|
|
}
|
|
console.log(JSON.stringify({counts,findings},null,2));
|
|
` }, bundle:true,platform:'node',format:'esm',packages:'external',write:false });
|
|
await mkdir('node_modules/.cache',{recursive:true});
|
|
const target=resolve('node_modules/.cache/dummy-results-audit.mjs');await writeFile(target,bundle.outputFiles[0].contents);
|
|
await import(pathToFileURL(target).href);
|