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
36 changes: 32 additions & 4 deletions plugins/stewards/assessment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ export type AssessedLiveness = {
live: boolean;
/** The stored typed wait's own liveness (BB-333); null when the binding has no typed wait. */
waitLive: boolean | null;
/**
* A compact fingerprint of the freshly read waited `pull`/`review` ref
* (BB-333), so a change on it wakes the binding. Null for any other wait or
* when the ref could not be read; JSON, never the raw snapshot.
*/
waited: string | null;
/** `idleInActiveStage` before the typed wait is applied: what the consumer's idle wake reads (BB-333). */
idleBase: boolean;
/** `idleInActiveStage`. */
Expand Down Expand Up @@ -180,6 +186,28 @@ function waitPullKey(ref: string): string | null {
return parsed === null ? null : `${parsed.repo}#${parsed.number}`.toLowerCase();
}

/**
* A compact, JSON fingerprint of the freshly read waited `pull`/`review` ref
* (BB-333): the fields a steward's wait is about, so any change on the ref
* wakes the binding without storing the snapshot. Null for another kind or a
* ref the look could not read.
*/
function waitFingerprint(wait: Wait | null, input: AssessmentInput): string | null {
if (wait === null || (wait.kind !== "pull" && wait.kind !== "review")) return null;
const key = waitPullKey(wait.ref);
const e = key === null ? undefined : input.waitedPulls?.get(key);
if (e === undefined) return null;
return JSON.stringify({
key: e.key,
state: e.state,
title: e.title,
head: e.pull?.headSha ?? null,
checks: e.pull?.checks?.state ?? null,
review: reviewGiven(e),
merged: e.pull?.merged === true,
});
}

/**
* Whether the stored typed wait is live, resolved against the rows the look
* holds (BB-333): the freshly read waited pull, the deployment watches, the
Expand All @@ -206,10 +234,9 @@ function typedWaitLive(wait: Wait, input: AssessmentInput): boolean {
case "date":
// The design's rule: a `date` wait is live while the binding's own
// requeue is still ahead (`requeueUntil`). `steward_report` sets
// `requeueUntil` only from `until` today, not yet from the ref, so a
// `date` wait that sent only a ref is not live. Reading the ref here
// claimed a wake the plugin never scheduled; the report-path gap (the
// design has the ref set `requeueUntil` too) is a separate fix.
// `requeueUntil` from the ref (or from `until`) in PR 3, so a `date`
// wait that sent only a ref is live while the date is ahead. Reading the
// ref here would claim a wake the plugin never scheduled.
return input.binding.requeueUntil !== null && input.binding.requeueUntil > input.now;
case "person":
return input.hasOpenItem?.(wait.ref) ?? false;
Expand Down Expand Up @@ -321,6 +348,7 @@ export function assess(input: AssessmentInput): Assessment {
liveness: {
live,
waitLive,
waited: waitFingerprint(wait, input),
idleBase,
// A live typed wait is something the plugin waits on, so it suppresses
// the idle wake; a stalled or external one does not (BB-333).
Expand Down
20 changes: 0 additions & 20 deletions plugins/stewards/characterization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ import {
anyWorkerInFlight,
gateKnownUnmet,
idleInActiveStage,
namesUserAsBlocker,
productGateOptions,
runningWorkerReason,
stuckDue,
unheardWait,
workerInFlight,
workerRunning,
type IdleBinding,
Expand Down Expand Up @@ -187,24 +185,6 @@ describe("the worker-busy predicates: workerInFlight vs runningWorkerReason", ()
expect(["starting", "active", "stopping"].every(isBusy)).toBe(true);
expect(["idle", "finished", "failed"].some(isBusy)).toBe(false);
});

it("pins unheardWait: a wait on the project steward or the user with no open escalation or need", () => {
const status = (waitingOn: string | null) => ({ phase: "In Progress", summary: "s", nextAction: "n", actor: "other" as const, waitingOn, requeueAfterMs: null, conditions: [], resources: { workers: [], pullRequests: [], children: [] }, at: 1 });
expect(unheardWait(status("the project steward's approval of the new spec"), [])).toMatch(/project steward/u);
expect(unheardWait(status("the user's answer on scope"), [])).toMatch(/the user/u);
expect(unheardWait(status("the user's answer"), [{ kind: "approval" } as never])).toBeNull();
expect(unheardWait(status("Sam's review"), [])).toBeNull();
expect(unheardWait(status(null), [])).toBeNull();
});

it("pins namesUserAsBlocker: user/owner/human as a word, not inside another word", () => {
expect(namesUserAsBlocker("the user must choose")).toBe(true);
expect(namesUserAsBlocker("the owner's approval")).toBe(true);
expect(namesUserAsBlocker("a human review")).toBe(true);
expect(namesUserAsBlocker("the username is wrong")).toBe(false);
expect(namesUserAsBlocker("ownerless")).toBe(false);
expect(namesUserAsBlocker("waiting on the reviewer")).toBe(false);
});
});

// ---------------------------------------------------------------------------
Expand Down
26 changes: 11 additions & 15 deletions plugins/stewards/reconcile.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it } from "vitest";
import { parsePlaybook, phaseOf } from "./config.js";
import { comment, issue, pull } from "./fixtures.js";
import { answerDiffers, anyWorkerInFlight, asksForOpenApproval, checksPhrase, commentDiffersFromRecommendation, compactDue, deploymentSettled, diffObserved, endingDeadline, followingThrough, gateKnownUnmet, idleInActiveStage, isCommentNews, isOwnStageChange, isOwnStageMove, lifecycle, markerLaneChange, mechanicalStatus, namesUserAsBlocker, newestEditComment, ownChecksFinished, ownPullClosed, ownPullMerged, phaseAndStage, productGateOptions, specDiff, specHash, specText, stuckDue, unheardWait, workerInFlight, workerReportedTerminal, type IdleBinding } from "./reconcile.js";
import { answerDiffers, anyWorkerInFlight, asksForOpenApproval, checksPhrase, commentDiffersFromRecommendation, compactDue, deploymentSettled, diffObserved, endingDeadline, followingThrough, gateKnownUnmet, idleInActiveStage, isCommentNews, isOwnStageChange, isOwnStageMove, lifecycle, markerLaneChange, mechanicalStatus, mentionsOwnerOrUser, newestEditComment, ownChecksFinished, ownPullClosed, ownPullMerged, phaseAndStage, productGateOptions, specDiff, specHash, specText, stuckDue, workerInFlight, workerReportedTerminal, type IdleBinding } from "./reconcile.js";
import { approvalMarkerLine, classifyApproval, ownerApproval, prGate, productReason, projectApprovalMarker, reviewMarker, reviewWorkerThread, UNREADABLE_VERDICT, type ProjectApprovalRecord } from "./gate.js";
import { approvalWanted, gateState, resolveChecklistItem } from "./ready-gate.js";
import { readyStateSchema, statusRecordSchema } from "./store.js";
Expand Down Expand Up @@ -306,14 +306,6 @@ describe("waits nobody hears", () => {
const status = (waitingOn: string | null) => ({ phase: "Todo", summary: "s", nextAction: "n", actor: "other" as const, waitingOn, requeueAfterMs: null, conditions: [], resources: { workers: [], pullRequests: [], children: [] }, at: 1 });
const open = [{ id: "esc_1", bindingId: "b", kind: "decision" as const, question: "q", context: null, meanwhile: "m", route: "project" as const, recommendation: null, choices: [], status: "open" as const, resolution: null, createdAt: 1, resolvedAt: null, deliveredAt: null, projectId: null, origin: { threadId: null, bindingId: null, chain: [] }, resolutionKind: null, url: null, data: {}, answeredBy: null, forwardedFrom: null, headSha: null, isQuestion: false, citedLessons: [], correctionsCounted: false, rationaleWanted: null, rationaleAsked: false, rationaleGiven: false, clusterKey: null, why: null, details: null }];

it("flags a status waiting on the project steward or the user with no escalation open", () => {
expect(unheardWait(status("project steward's approval of the new spec"), [])).toMatch(/project steward/u);
expect(unheardWait(status("the user's answer on scope"), [])).toMatch(/the user/u);
expect(unheardWait(status("project steward's approval"), open)).toBeNull();
expect(unheardWait(status("Sam's review"), [])).toBeNull();
expect(unheardWait(status(null), [])).toBeNull();
});

it("tells the steward's own signed description edit from someone else's edit of it", () => {
const signed = (text: string) => issue({ description: `${text}\n\n_— from bb thread thr_s_` });
const own = (before: ReturnType<typeof issue>, after: ReturnType<typeof issue>) => diffObserved({ entity: before, pulls: [] }, { entity: after, pulls: [] }, ctx).find((c) => c.text.startsWith("Description edited"))!;
Expand Down Expand Up @@ -993,12 +985,16 @@ describe("the pull request gate (build-tickets)", () => {
});

describe("a waitingOn naming the user", () => {
it("is refused without an item and allowed with one", () => {
expect(namesUserAsBlocker("the user's answer on scope")).toBe(true);
expect(namesUserAsBlocker("the owner's approval")).toBe(true);
expect(namesUserAsBlocker("a human has to install it")).toBe(true);
expect(namesUserAsBlocker("the project steward's call")).toBe(false);
expect(namesUserAsBlocker("sam's review")).toBe(false);
// BB-333: the exported name is retired, but the guard is live for an
// `external`/no-kind report; its word boundaries stay pinned.
it("matches user/owner/human as a word, not inside another word", () => {
expect(mentionsOwnerOrUser("the user's answer on scope")).toBe(true);
expect(mentionsOwnerOrUser("the owner's approval")).toBe(true);
expect(mentionsOwnerOrUser("a human has to install it")).toBe(true);
expect(mentionsOwnerOrUser("the username is wrong")).toBe(false);
expect(mentionsOwnerOrUser("ownerless")).toBe(false);
expect(mentionsOwnerOrUser("the project steward's call")).toBe(false);
expect(mentionsOwnerOrUser("sam's review")).toBe(false);
});
});

Expand Down
25 changes: 8 additions & 17 deletions plugins/stewards/reconcile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,15 +560,17 @@ export function diffObserved(before: Observed, after: Observed, ctx: ObservedDif
}

/**
* A `waitingOn` that names the user, the owner or a human. A status record
* naming one of them without an open `needs` item is refused: the item is what
* puts the ask on the Stewards page (BB-109 keeps the refusal for `waitingOn`).
*/
export function namesUserAsBlocker(text: string): boolean {
* A `waitingOn` that names the user, the owner or a human. Retained for a
* typed wait that is not a valid `person` wait (an `external` wait, or a
* `person` ref the plugin could not resolve) and for a no-kind report: naming
* one of them without an open `needs` item is refused, because the item is
* what puts the ask on the Stewards page. A valid `person` wait is the
* structured replacement and bypasses it (BB-333).
*/
export function mentionsOwnerOrUser(text: string): boolean {
return /(?:^|[^\p{L}\p{N}])(?:user|owner|human)(?:[^\p{L}\p{N}]|$)/iu.test(text);
}


/**
* A steward that asks for an approval that is already open. The plugin files
* the request and lists it on the Stewards page, so the playbook says not to
Expand Down Expand Up @@ -649,17 +651,6 @@ export function gateKnownUnmet(playbook: Playbook, ready: ReadyState, currentSpe
return gate.unmet.some((item) => reportedItem(ready, item)?.met === false);
}

/**
* A status that says it waits on the project steward or the user while
* none of its escalations is open: a wait nobody above it hears about.
*/
export function unheardWait(status: Binding["status"], open: readonly Escalation[], needs: readonly Pick<Need, "kind">[] = []): string | null {
if (status === null || status.waitingOn === null || open.length > 0 || needs.length > 0) return null;
if (/project steward/iu.test(status.waitingOn)) return "waits on the project steward, with no open escalation";
if (/\buser\b/iu.test(status.waitingOn)) return "waits on the user, with no open escalation";
return null;
}

// ---- idle in an active stage (BB-83) --------------------------------------------

/**
Expand Down
Loading
Loading