Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/core/src/__tests__/severity.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expect, it } from "vitest";
import { findingSchema, revalidationSchema } from "../schemas.js";
import { SEVERITY_ORDER } from "../severity.js";

describe("severity levels", () => {
const baseFinding = {
Expand Down Expand Up @@ -38,6 +39,17 @@ describe("severity levels", () => {
it("rejects empty severity", () => {
expect(() => findingSchema.parse({ ...baseFinding, severity: "" })).toThrow();
});

it("uses one canonical ordering including LOW", () => {
expect(SEVERITY_ORDER).toEqual({
CRITICAL: 0,
HIGH: 1,
MEDIUM: 2,
HIGH_BUG: 3,
BUG: 4,
LOW: 5,
});
});
});

describe("revalidation adjustedSeverity", () => {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export * from "./paths.js";
export * from "./plugin.js";
export * from "./run.js";
export * from "./schemas.js";
export * from "./severity.js";
export * from "./types.js";
14 changes: 14 additions & 0 deletions packages/core/src/severity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { Severity } from "./types.js";

/**
* Canonical severity ranking used for filtering and presentation.
* Lower numbers are more severe.
*/
export const SEVERITY_ORDER: Record<Severity, number> = {
CRITICAL: 0,
HIGH: 1,
MEDIUM: 2,
HIGH_BUG: 3,
BUG: 4,
LOW: 5,
};
11 changes: 1 addition & 10 deletions packages/deepsec/src/commands/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,10 @@ import crypto from "node:crypto";
import fs from "node:fs";
import path from "node:path";
import type { FileRecord, Finding, Severity } from "@deepsec/core";
import { dataDir, getDataRoot, loadAllFileRecords } from "@deepsec/core";
import { dataDir, getDataRoot, loadAllFileRecords, SEVERITY_ORDER } from "@deepsec/core";
import { BOLD, DIM, GREEN, RESET, YELLOW } from "../formatters.js";
import { resolveAgentType } from "../resolve-agent-type.js";

const SEVERITY_ORDER: Record<Severity, number> = {
CRITICAL: 0,
HIGH: 1,
HIGH_BUG: 2,
MEDIUM: 3,
BUG: 4,
LOW: 5,
};

interface OwnerSummary {
assignee?: string;
assigneeSource?: "oncall" | "manager" | "top-contributor" | "last-committer";
Expand Down
16 changes: 1 addition & 15 deletions packages/deepsec/src/pr-comment.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
import { type FileRecord, loadAllFileRecords, type Severity } from "@deepsec/core";

/**
* Severity ordering used to sort findings within the PR comment. Mirrors
* the order in `packages/processor/src/index.ts:SEVERITY_ORDER` — keep them
* in sync if you add a tier.
*/
const SEVERITY_ORDER: Record<Severity, number> = {
CRITICAL: 0,
HIGH: 1,
MEDIUM: 2,
HIGH_BUG: 3,
BUG: 4,
LOW: 5,
};
import { type FileRecord, loadAllFileRecords, SEVERITY_ORDER, type Severity } from "@deepsec/core";

const SEVERITY_BADGE: Record<Severity, string> = {
CRITICAL: "🔴 CRITICAL",
Expand Down
18 changes: 7 additions & 11 deletions packages/deepsec/src/sandbox/partitioner.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import fs from "node:fs";
import path from "node:path";
import type { FileRecord } from "@deepsec/core";
import { dataDir, loadAllFileRecords } from "@deepsec/core";
import { dataDir, loadAllFileRecords, SEVERITY_ORDER } from "@deepsec/core";
import { noiseScore } from "@deepsec/scanner";
import type { PartitionResult, SandboxSubcommand } from "./types.js";

const SEVERITY_ORDER: Record<string, number> = {
CRITICAL: 0,
HIGH: 1,
MEDIUM: 2,
HIGH_BUG: 3,
BUG: 4,
};
function severityRank(severity: string): number {
return SEVERITY_ORDER[severity as keyof typeof SEVERITY_ORDER] ?? 99;
}

/**
* Load eligible files for the given command and split into N disjoint partitions.
Expand Down Expand Up @@ -68,7 +64,7 @@ export function partitionFiles(
if (r.findings.length === 0) return false;
const unrevalidated = r.findings.filter((f) => {
if (!opts.force && f.revalidation) return false;
if (opts.minSeverity && SEVERITY_ORDER[f.severity] > SEVERITY_ORDER[opts.minSeverity])
if (opts.minSeverity && severityRank(f.severity) > severityRank(opts.minSeverity))
return false;
return true;
});
Expand All @@ -95,8 +91,8 @@ export function partitionFiles(
eligible.sort((a, b) => {
if (command === "revalidate") {
// Sort by severity (CRITICAL first)
const aBest = Math.min(...a.findings.map((f) => SEVERITY_ORDER[f.severity] ?? 99));
const bBest = Math.min(...b.findings.map((f) => SEVERITY_ORDER[f.severity] ?? 99));
const aBest = Math.min(...a.findings.map((f) => severityRank(f.severity)));
const bBest = Math.min(...b.findings.map((f) => severityRank(f.severity)));
if (aBest !== bBest) return aBest - bBest;
}

Expand Down
10 changes: 1 addition & 9 deletions packages/processor/src/enrich.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
getRegistry,
loadAllFileRecords,
readProjectConfig,
SEVERITY_ORDER,
writeFileRecord,
} from "@deepsec/core";

Expand Down Expand Up @@ -153,15 +154,6 @@ interface EnrichProgress {
total?: number;
}

const SEVERITY_ORDER: Record<Severity, number> = {
CRITICAL: 0,
HIGH: 1,
HIGH_BUG: 2,
MEDIUM: 3,
BUG: 4,
LOW: 5,
};

export async function enrich(params: {
projectId: string;
filter?: string;
Expand Down
10 changes: 1 addition & 9 deletions packages/processor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
readProjectConfig,
readRunMeta,
registerActiveRun,
SEVERITY_ORDER,
writeFileRecord,
writeRunMeta,
} from "@deepsec/core";
Expand Down Expand Up @@ -806,15 +807,6 @@ export async function process(params: {

// --- Revalidation ---

const SEVERITY_ORDER: Record<Severity, number> = {
CRITICAL: 0,
HIGH: 1,
MEDIUM: 2,
HIGH_BUG: 3,
BUG: 4,
LOW: 5,
};

export async function revalidate(params: {
projectId: string;
runId?: string;
Expand Down