= new Set([
+ "route_through_api",
+ "invert_dependency",
+ "extract_interface",
+]);
+
+/**
+ * What a finding's stored simulation can be said to show, decided in one place for the
+ * list, the detail and the grid panel.
+ * - `not-simulated`: no simulation was run.
+ * - `nothing-changed`: a simulation ran but no link was removed or added.
+ * - `effect-if-removed`: the fix removes the link by assumption, so this is not a check.
+ * - `link-remains`, `adds-exceptions`, `checked`: a real change to the map was simulated.
+ */
+export type SimulationKind =
+ | "not-simulated"
+ | "nothing-changed"
+ | "effect-if-removed"
+ | "link-remains"
+ | "adds-exceptions"
+ | "checked";
+
+/** The stored fix action is used whatever the AI switch says: the simulation was made for it. */
+export function simulationKind(finding: Finding | undefined): SimulationKind {
+ const simulation = finding?.simulation;
+ if (!simulation?.simulated) return "not-simulated";
+ if (simulation.links_removed === 0 && simulation.links_added === 0) return "nothing-changed";
+ const action = finding?.judgement?.fix.action;
+ if (action && LINK_REMOVING.has(action)) return "effect-if-removed";
+ if (simulation.target_link_removed === false) return "link-remains";
+ if (simulation.new_exceptions.length > 0) return "adds-exceptions";
+ return "checked";
}
-function simulationShort(simulation: Simulation | null): string {
- if (!simulation?.simulated) return "Not simulated";
- if (linkRemains(simulation)) return "Simulated: the link remains";
- if (simulation.new_exceptions.length > 0) return "Simulated, adds exceptions";
- return "Checked by simulation";
+/** Shown where a simulation ran but nothing on the map changed. */
+export const NOTHING_CHANGED_TEXT = "Not simulated. Nothing on the map changed for this fix.";
+
+/** Shown where no simulation ran. */
+export const NOT_SIMULATED_TEXT =
+ "Not simulated. Only moves and single-link removals are tried on the map.";
+
+function simulationShort(finding: Finding): string {
+ switch (simulationKind(finding)) {
+ case "not-simulated":
+ case "nothing-changed":
+ return "Not simulated";
+ case "effect-if-removed":
+ return "Effect if the link is removed";
+ case "link-remains":
+ return "Simulated: the link remains";
+ case "adds-exceptions":
+ return "Simulated, adds exceptions";
+ case "checked":
+ return "Checked by simulation";
+ }
}
function FindingDetail({
@@ -203,7 +253,7 @@ function FindingDetail({
aiOff: boolean;
sponsor: string | null;
}) {
- const { judgement, simulation, origin, trend, priority } = finding;
+ const { judgement, origin, trend, priority } = finding;
const ai = !aiOff && judgement?.status === "ai";
// Without AI text, or without a judgement at all, the computed template sentence stands in.
const claimFromModel = judgement && (ai || judgement.status === "template");
@@ -301,7 +351,7 @@ function FindingDetail({
)}
-
+
@@ -389,24 +439,37 @@ function FindingDetail({
);
}
-function SimulationText({ simulation }: { simulation: Simulation | null }) {
- if (!simulation?.simulated) {
- return <>Not simulated. Only moves and single-link removals are tried on the map.>;
- }
+function SimulationText({ finding }: { finding: Finding }) {
+ const kind = simulationKind(finding);
+ const simulation: Simulation | null = finding.simulation;
+ if (kind === "not-simulated" || !simulation) return <>{NOT_SIMULATED_TEXT}>;
+ if (kind === "nothing-changed") return <>{NOTHING_CHANGED_TEXT}>;
const loops =
simulation.loops_before !== null && simulation.loops_after !== null
? `loops ${num(simulation.loops_before)} to ${num(simulation.loops_after)}`
: "loops not counted";
const added = simulation.new_exceptions.length;
- const remains = linkRemains(simulation);
+ const exceptions =
+ added === 0 ? "No new exceptions." : `Warning: ${added} new exception${added === 1 ? "" : "s"}.`;
+ if (kind === "effect-if-removed") {
+ const removed = simulation.links_removed;
+ const taken =
+ removed === 1
+ ? "the 1 link between the two modules is taken away"
+ : `all ${num(removed)} links between the two modules are taken away`;
+ return (
+ <>
+ Effect if the link is removed: {taken}, {loops}. {exceptions}
+ >
+ );
+ }
+ const remains = kind === "link-remains";
return (
<>
{remains ? "Simulated: the link remains. " : "Fix checked by simulation: "}
{remains ? loops[0].toUpperCase() + loops.slice(1) : loops}, {num(simulation.links_removed)} link
{simulation.links_removed === 1 ? "" : "s"} removed, {num(simulation.links_added)} added.{" "}
- {added === 0
- ? "No new exceptions."
- : `Warning: ${added} new exception${added === 1 ? "" : "s"}.`}
+ {exceptions}
>
);
}
diff --git a/web/src/screens/grid/FixPanel.tsx b/web/src/screens/grid/FixPanel.tsx
index d9e5f7de..da476860 100644
--- a/web/src/screens/grid/FixPanel.tsx
+++ b/web/src/screens/grid/FixPanel.tsx
@@ -3,7 +3,7 @@
import { Badge } from "../../components/Badge";
import type { BatchSimulation, Finding } from "../../contracts/generated";
import type { View } from "../../data/view";
-import { linkRemains } from "../decisions/FixFirst";
+import { NOTHING_CHANGED_TEXT, NOT_SIMULATED_TEXT, simulationKind } from "../decisions/FixFirst";
interface Props {
finding: Finding | undefined;
@@ -32,7 +32,8 @@ function Warning({ exceptions }: { exceptions: string[] }) {
export function FixPanel({ finding, batch, fix, setFix }: Props) {
const simulation = finding?.simulation;
- const canTry = Boolean(simulation?.simulated);
+ const kind = simulationKind(finding);
+ const canTry = kind !== "not-simulated" && kind !== "nothing-changed";
const oneOn = fix === "one" && canTry;
const allOn = fix === "all" && batch !== null;
if (!finding && !batch) return null;
@@ -45,14 +46,16 @@ export function FixPanel({ finding, batch, fix, setFix }: Props) {
{oneOn
- ? linkRemains(simulation)
- ? "Fix simulated: the link remains"
- : "Fix checked by simulation"
+ ? kind === "effect-if-removed"
+ ? "Effect if the link is removed"
+ : kind === "link-remains"
+ ? "Fix simulated: the link remains"
+ : "Fix checked by simulation"
: `The fix for finding ${finding.priority.rank}`}
{!canTry && (
- Not simulated. Only moves and single-link removals are tried on the map.
+ {kind === "nothing-changed" ? NOTHING_CHANGED_TEXT : NOT_SIMULATED_TEXT}
)}
{oneOn && simulation && (