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
21 changes: 18 additions & 3 deletions docs/architecture/flows.md
Original file line number Diff line number Diff line change
Expand Up @@ -749,16 +749,31 @@ the route it took, red only where it stopped.
from the graph ("Asks you every time"; "Asks you if it edits CI" when a person is
asked only on a side route and that person's step says what makes a run ask
with `asks_if="it edits CI"`, words that finish "Asks you if …", set on the gate
or on the segment node that holds it, as change's `decide` does; "Sometimes asks
or on a segment node that holds it, the nearest one first, as change's `decide`
and Union's Land `card` do; "Sometimes asks
you" when it says nothing, never the route's label, which names the route; "No
approval"), and its stages. The confirm after it says the same: a question every
approval"), and its stages; a lone flow has no row, and its label and approval
sit beside Ship. The confirm after it says the same: a question every
run, "Only if it edits CI" (else "On some runs"), or none. The stages are the
journey's: the stations a passing run takes, never one only a failure
reaches (a later deploy after a failed one), and a station marked
`fold=true` is bookkeeping, drawn as part of the stage before it (change's
Verdicts reads in CI + Review, its Merged in Merge); it runs like any other
station. A stage reads Person only when a person is asked on its passing
route, never for a card a segment reaches on a side route. It draws the picked one and
route, never for a card a segment reaches on a side route. A segment stage
with more than one step, or a route off them, shows its inside, read from the
graph (`insideOf` in `lib/ship/segmentInside.ts`): under its name a quiet line of
its passing steps ("PR · CI + Review · Merge"), and a press on it opens them
in place down a spine that ends at the segment's end ("Merged"). Each route
off a step hangs under that step, labelled by its edge's label, through the
steps it runs to where it goes: back to a step ("↩ Merge"), back to the
session (an end the composing flow sends to a `backend=subject` station), or
a stop. A route walks on by its edges' conditions alone, the passing one
first, then a step's default; an edge whose condition compares two words the
parser wrote in (a segment param) is never taken. A route through a person's
step is dashed and carries its "Asks you if …" words. On a run each step and
route takes its state (the route that sent the work back, the card that
waits). A single stage that sends work back draws a hook under itself. It draws the picked one and
opens the shared confirm review: steps, agent sessions that start, questions
for you, who does each step, the ways it can end, how to stop. Confirming
asks the session to run its own change through it. On a phone it opens as a
Expand Down
4 changes: 3 additions & 1 deletion packages/mobile/components/session/FlowCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { type AppFlow } from '@codecast/web/lib/line/flowPool';
import { flowDiagram, routeTail, runReached, stepStates, type DiagramStep, type SideRoute, type StepState } from '@codecast/web/lib/line/flowDiagram';
import { flowRunState, type FlowRunTone } from '@codecast/web/lib/line/flowFence';
import { takesSessionChange } from '@codecast/shared/contracts/flowPool';
import { gateWaitWords, holdWords, journeyOf, sentBackWords, stopWords, waitWords, WHO_WORDS, type JourneyNow, type JourneyStage, type JourneyWait, type StageState } from '@codecast/web/lib/ship/journey';
import { gateWaitWords, holdWords, insideWords, journeyOf, sentBackWords, stopWords, waitWords, WHO_WORDS, type JourneyNow, type JourneyStage, type JourneyWait, type StageState } from '@codecast/web/lib/ship/journey';
import type { FlowEdit } from '@codecast/shared/contracts/flowEdit';
import { asGitDiff, editDrawing, editLines, editRun, liveDeploy, type EditMark } from '@codecast/web/lib/line/flowEditCard';
import { CastDiff } from '@/components/CastDiff';
Expand Down Expand Up @@ -83,6 +83,8 @@ function ShipBody({ flow, run }: { flow: AppFlow; run: RunRow }) {
<RNText style={[styles.stepName, { color: Theme.text }]} maxFontSizeMultiplier={CHROME_FONT_CAP}>{s.label}</RNText>
<RNText style={[styles.who, { color: s.state === 'back' ? Theme.violet : Theme.textMuted }]} maxFontSizeMultiplier={CHROME_FONT_CAP}>{whoWords(s)}</RNText>
</RNView>
{/* A segment's inside, in a few words: the steps a passing run takes through it. */}
{s.inside ? <RNText style={[styles.who, { marginLeft: 20, color: Theme.textDim }]} maxFontSizeMultiplier={CHROME_FONT_CAP}>{insideWords(s.inside)}</RNText> : null}
{/* A fan-out's branches run side by side: each with its own state. */}
{s.branches?.map((b) => (
<RNView key={b.id} style={[styles.step, { marginLeft: 20, opacity: b.state === 'idle' ? 0.55 : 1 }]}>
Expand Down
15 changes: 15 additions & 0 deletions packages/shared/contracts/flowPool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ test("the main path runs through a station inserted after a segment, not its way
]);
});

test("a station only a failure reaches is off the main path, though its way on is an end", () => {
const n = (id: string, type: string) => ({ id, label: id, shape: "box", type });
const nodes = [n("start", "start"), n("deploy", "command"), n("redeploy", "command"), n("exit", "exit"), n("never", "exit")] as unknown as Parameters<typeof foldFlow>[0];
const edges = [
{ from: "start", to: "deploy" },
{ from: "deploy", to: "exit", condition: "outcome = success" },
{ from: "deploy", to: "redeploy", condition: "outcome = failure" },
{ from: "redeploy", to: "exit", condition: "outcome = success" },
{ from: "redeploy", to: "never", condition: "outcome = failure" },
];
const folded = foldFlow(nodes, edges);
expect(folded.path).toEqual(["deploy"]);
expect(folded.stations.find((s) => s.id === "redeploy")!.main).toBe(false);
});

test("a variant's edits read as one line each", () => {
const label = (id: string) => ({ check: "Check", review: "Review", decide: "Decide", lint: "Lint", e2e: "E2E" })[id] ?? id;
expect([
Expand Down
17 changes: 12 additions & 5 deletions packages/shared/contracts/flowPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ export function foldFlow(nodes: ReadonlyArray<FlowNodeIn>, edges: ReadonlyArray<
if (t === n.id) top.set(t, n);
else if (!n.segment_exit && n.type !== "exit") steps.set(t, (steps.get(t) ?? 0) + 1);
}
const outOf = new Map<string, Array<{ to: string; when: string | null; score: number }>>();
const outOf = new Map<string, Array<{ to: string; when: string | null; score: number; success: boolean }>>();
for (const e of edges) {
const from = segmentTopOf(e.from);
const to = segmentTopOf(e.to);
if (from === to) continue;
const list = outOf.get(from) ?? [];
const when = edgeWhen(e);
if (!list.some((x) => x.to === to && x.when === when)) list.push({ to, when, score: passScore(e) });
if (!list.some((x) => x.to === to && x.when === when)) list.push({ to, when, score: passScore(e), success: /\boutcome\s*=\s*success\b/.test(e.condition ?? "") });
outOf.set(from, list);
}
const start = [...top.values()].find((n) => n.type === "start");
Expand All @@ -186,7 +186,14 @@ export function foldFlow(nodes: ReadonlyArray<FlowNodeIn>, edges: ReadonlyArray<
const main = new Set<string>();
const path: string[] = [];
// The subject's own stations (backend=subject: the session the change came from fixes what a stage found) are a way back, never the way on.
const rank = (x: { to: string; score: number }) => x.score - (top.get(x.to)?.type === "exit" ? 10 : 0) - (top.get(x.to)?.backend === "subject" ? 20 : 0);
// An end comes after any station, unless its edge is the station's only `outcome = success`: a station only another
// outcome reaches never outranks where a success goes.
const exit = (id: string) => top.get(id)?.type === "exit";
const best = (list: ReadonlyArray<{ to: string; score: number; success: boolean }>) => {
const ends = !list.some((x) => x.success && !exit(x.to));
const rank = (x: (typeof list)[number]) => x.score - (exit(x.to) && !(ends && x.success) ? 10 : 0) - (top.get(x.to)?.backend === "subject" ? 20 : 0);
return [...list].sort((a, b) => rank(b) - rank(a))[0]?.to;
};
for (let at = start?.id; at && !main.has(at); ) {
main.add(at);
path.push(at);
Expand All @@ -198,13 +205,13 @@ export function foldFlow(nodes: ReadonlyArray<FlowNodeIn>, edges: ReadonlyArray<
if (top.get(b)?.type === "parallel_fanin") { join ??= b; break; }
main.add(b);
path.push(b);
b = [...(outOf.get(b) ?? [])].filter((x) => !main.has(x.to)).sort((x, y) => rank(y) - rank(x))[0]?.to;
b = best((outOf.get(b) ?? []).filter((x) => !main.has(x.to)));
}
}
at = join;
continue;
}
at = [...(outOf.get(at) ?? [])].filter((x) => !main.has(x.to)).sort((a, b) => rank(b) - rank(a))[0]?.to;
at = best((outOf.get(at) ?? []).filter((x) => !main.has(x.to)));
}
const label = (id: string) => top.get(id)?.label ?? id;
const stations: FlowStation[] = [];
Expand Down
19 changes: 12 additions & 7 deletions packages/web/components/line/widgets/RunThroughFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ export function ShipAgainButton({ flow, conversationId, sessionTitle, primary }:
);
}

/** Whether a flow asks the person before the change lands, as a chip. */
function Asks({ flow }: { flow: AppFlow }) {
const approval = approvalOf(flow);
return <span className="shp-asks" data-asks={approval.kind === "never" ? undefined : approval.kind}>{approvalWords(approval)}</span>;
}

function PoolPicker({ conversationId, session, onRun }: { conversationId: string; session: string; onRun: (flow: AppFlow) => void }) {
// The session's workspace, not the active one: the pool `cast flow run` reads where the session runs.
const workspace = useInboxStore((s) => sessionWorkspaceOf(s as any, conversationId));
Expand All @@ -229,24 +235,23 @@ function PoolPicker({ conversationId, session, onRun }: { conversationId: string
{pool.length > 1 ? (
// A native radio group: one tab stop, arrow keys move the pick, Enter ships the picked flow.
<div className="shp-flows" role="radiogroup" aria-label="Flows">
{pool.map((f) => { const approval = approvalOf(f); return (
{pool.map((f) => (
<label key={f.slug} className="shp-flow" onDoubleClick={() => onRun(f)} data-run-through-flow={f.slug}>
<input type="radio" className="shp-radio" name={`ship-flow-${conversationId}`} value={f.slug} checked={f.slug === flow.slug}
onChange={() => setPicked(f.slug)} onKeyDown={(e) => { if (e.key === "Enter") { e.preventDefault(); onRun(f); } }} />
<b>{f.label}{f === fallback ? <span className="shp-default" data-run-through-default=""><span className="sr-only"> </span>Default</span> : f.base ? <span className="shp-base">on {f.base}</span> : null}</b>
<span className="shp-path">
<span className="shp-asks" data-asks={approval.kind === "never" ? undefined : approval.kind}>{approvalWords(approval)}</span>
{journeyStages(f).map((s) => s.label).join(" → ")}
</span>
<span className="shp-path">{journeyStages(f).map((s) => s.label).join(" → ")}</span>
<Asks flow={f} />
</label>
); })}
))}
</div>
) : null}
<div className="shp-preview" data-flow={flow.slug}>
<JourneyView journey={journey} now_ms={0} />
</div>
<footer className="shp-foot">
<span className="shp-flowname">{pool.length > 1 ? null : <>{flow.label}{flow === fallback ? <span className="shp-default">Default</span> : null}</>}</span>
{/* A lone flow has no list row, so its name and whether it asks the person sit here. */}
<span className="shp-flowname">{pool.length > 1 ? null : <>{flow.label}{flow === fallback ? <span className="shp-default">Default</span> : null}<Asks flow={flow} /></>}</span>
<button type="button" className="sj-btn" data-primary onClick={() => onRun(flow)} aria-label={pool.length > 1 ? (flow.label === "Ship" ? "Ship this change" : `Ship through ${flow.label}`) : undefined} data-run-through-go={flow.slug}>Ship</button>
</footer>
</div>
Expand Down
18 changes: 18 additions & 0 deletions packages/web/components/ship/Journey.stateWords.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,21 @@ describe("states that read without color", () => {
expect(text(stopped)).toContain("CI + Review✕ (stopped), stopped");
});
});

const { journeyStages } = await import("../../lib/ship/journey");
const { appPool, flowBySlug } = await import("../../lib/line/flowPool");
const { LAND_REPO_FLOW } = await import("../../lib/ship/journeyFixtures");

describe("a segment stage", () => {
const stages = journeyStages(flowBySlug(appPool([], [LAND_REPO_FLOW]), "change")!).map((s) => ({ ...s, state: "idle", round: null })) as any;
test("hints at its inside under its name, a press away from opening it", () => {
const html = renderToStaticMarkup(<JourneyTrack stages={stages} onOpen={() => {}} insideId="in1" />);
expect(html).toContain('aria-expanded="false" aria-controls="in1"');
expect(text(html)).toContain("PR · CI + Review · Merge");
});
test("alone and sending work back, it draws a hook under itself, not a bracket of no width", () => {
expect(renderToStaticMarkup(<JourneyTrack stages={stages} />)).toContain("data-single");
const two = [stage("pr", "PR", "idle", { loops: [{ id: "fix", label: "Fix", max: 3 }] }), stage("merge", "Merge", "idle", { loops: [{ id: "fix", label: "Fix", max: 3 }] })];
expect(renderToStaticMarkup(<JourneyTrack stages={two} />)).not.toContain("data-single");
});
});
Loading