Skip to content
Merged
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
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,13 @@ top 5 and of the top 10 are still in the top 5 and top 10 under the test.
answers. It does not make a new call, so it does not show how the AI text would change
on a run with the cache off.
- A simulated fix that leaves its target link on the map is shown as "Simulated: the link
remains" (on the grid, "Fix simulated: the link remains"), not as checked: 32 of the 50
simulated fixes on Artemis, 10 of 19 on Shopware and 35 of 50 on Graylog.
remains" (on the grid, "Fix simulated: the link remains"), not as checked: 29 of the 50
simulated fixes on Artemis, 1 of 19 on Shopware and 22 of 50 on Graylog.
- The simulation works on link counts between modules, and a move moves the whole
declaring file. Of the 119 simulated fixes, 14 are fixes that remove a link (Artemis 8,
Shopware 5, Graylog 1): the link is taken away by assumption, so they are shown as
"Effect if the link is removed", not as checked. Another 26 (Artemis 4, Shopware 9,
Graylog 13) changed nothing on the map and are shown as "Not simulated".
- When the AI answer names no fix action (for example when it judges the link to be
intended wiring), the finding shows "No improvement proposed." and the AI's fix text is
not shown. In the list to fix first that is 2 of 10 findings on Artemis, 5 of 10 on
Expand Down
2 changes: 1 addition & 1 deletion spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ For `move_symbol`, and for fixes that remove a specific link, the tool applies t
"links_removed": 1, "links_added": 0, "new_exceptions": []}
```

The report shows "fix checked by simulation" with these numbers. A simulated fix that does not remove the link it targets is shown as "simulated: the link remains", not as "fix checked by simulation". Other fix types are shown as "not simulated". A fix whose simulation creates new exceptions is shown with that warning.
The report shows "fix checked by simulation" with these numbers. A simulated fix that does not remove the link it targets is shown as "simulated: the link remains", not as "fix checked by simulation". A fix that removes a link (`route_through_api`, `invert_dependency`, `extract_interface`) is not tested: the map is shown with the link taken away and labelled "effect if the link is removed". A simulation that changes nothing on the map is shown as "not simulated". Other fix types are shown as "not simulated". A fix whose simulation creates new exceptions is shown with that warning.

`split_by_responsibility` is shown as "not simulated".

Expand Down
103 changes: 83 additions & 20 deletions web/src/screens/decisions/FixFirst.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { type KeyboardEvent, type ReactNode, useEffect, useRef, useState } from
import { Link } from "react-router";
import { Badge } from "../../components/Badge";
import { formatDate, formatSponsorDate } from "../../components/Shell";
import type { Decision, Finding, Simulation } from "../../contracts/generated";
import type { Decision, Finding, Fix, Simulation } from "../../contracts/generated";
import { viewLink } from "../../data/view";
import {
ACTION_LABEL,
Expand Down Expand Up @@ -142,7 +142,7 @@ export function FixFirst({
</>
)}
</span>
<span className="fix__sim">{simulationShort(finding.simulation)}</span>
<span className="fix__sim">{simulationShort(finding)}</span>
<span className="num fix__score">{finding.priority.score.toFixed(2)}</span>
<svg className="chevron" viewBox="0 0 24 24" aria-hidden="true">
<path d="m9 18 6-6-6-6" />
Expand Down Expand Up @@ -176,16 +176,66 @@ export function FixFirst({
);
}

/** True when the fix was simulated but the link it targets is still on the map. */
export function linkRemains(simulation: Simulation | null | undefined): boolean {
return Boolean(simulation?.simulated) && simulation?.target_link_removed === false;
/**
* Fix actions the simulation applies by taking every link between the two modules away,
* so the link is gone by assumption, not by a test. The pipeline's list is
* `LINK_REMOVING` in `src/codexray/judge/jobs.py`.
*/
const LINK_REMOVING: ReadonlySet<Fix["action"]> = 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({
Expand All @@ -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");
Expand Down Expand Up @@ -301,7 +351,7 @@ function FindingDetail({
)}
<p className="detail__sim">
<Badge origin="computed" />
<SimulationText simulation={simulation} />
<SimulationText finding={finding} />
</p>
</div>

Expand Down Expand Up @@ -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}
</>
);
}
Expand Down
15 changes: 9 additions & 6 deletions web/src/screens/grid/FixPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -45,14 +46,16 @@ export function FixPanel({ finding, batch, fix, setFix }: Props) {
<p className="fix-panel__title">
<Badge origin="computed" />
{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}`}
</p>
{!canTry && (
<p className="muted small">
Not simulated. Only moves and single-link removals are tried on the map.
{kind === "nothing-changed" ? NOTHING_CHANGED_TEXT : NOT_SIMULATED_TEXT}
</p>
)}
{oneOn && simulation && (
Expand Down