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
21 changes: 21 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,27 @@ a scheduled read: it holds a slot in the read budget, has the read deadline,
and stops when the request does. `serve --hud <url>` (or `BEHOLD_HUD_URL`)
links a proposed decision to its review in hud.

## Chant version floors (behold#691)

behold shells each project's own chant, so a read can reach a chant that
predates it. Every read has one floor, and every floor lives in
`src/chant-floors.ts`:

- one constant per read, named after the read (`WHY_CHANT_FLOOR`) and set to the
chant release that adds it;
- one entry in `CHANT_FLOORS` (the read in words, the floor, what adds it in
chant), which is what `behold doctor` lists with the project's chant version
and whether the floor is met;
- the code that makes the read checks the project's chant first (`floorMet`,
`floorRefusal`) and never sends the read to a chant that would reject it.

On an older chant the pane that needs the read shows `floorRefusal`'s words
(the read, the chant that adds it, the project's version) and the rest of
behold works. The why route does this: `GET /api/workspace/why` refuses before
spawning the read. A new read adds its constant and entry in the issue that
adds the read, once the chant release is known, and reads through the read
contract (`src/workspace-reader.ts`), never chant's library.

## A pipeline's numbers, from Prometheus (behold#571)

`behold serve --prometheus <url>` (or `BEHOLD_PROMETHEUS_URL`) adds `GET
Expand Down
5 changes: 3 additions & 2 deletions src/carve-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,9 @@ function mergeCarveStates(byTarget: Map<string, CarveState>, paths: readonly str

// ── Discovery through chant (chant#2038, chant ≥ 0.54.0) ─────────────────────

/** The chant that first answers `chant carve status`. */
export const CARVE_STATUS_FLOOR = "0.54.0";
/** The chant that first answers `chant carve status`; see src/chant-floors.ts. */
import { CARVE_STATUS_FLOOR } from "./chant-floors.ts";
export { CARVE_STATUS_FLOOR };

/** One row of `chant carve status --from <dir> --json` — chant's own
* `CarveStatusRow` (cli/commands/carve-status.ts), reproduced rather than
Expand Down
85 changes: 85 additions & 0 deletions src/chant-floors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* The registry of chant version floors (#691).
*
* behold shells each project's own chant, so a read can be asked of a chant
* that predates it. Every such read has one floor here: the first chant
* release that answers it. The convention:
*
* - One constant per read, named after the read (`WHY_CHANT_FLOOR`), set to
* the chant release that adds the read, and defined in this file.
* - One entry in {@link CHANT_FLOORS} naming the read in words a person
* recognises, the floor, and the chant issue or release that adds it.
* - The code that makes the read checks the project's chant with
* {@link floorRefusal} (or `meetsFloor`) before spawning anything, and a
* pane that needs the read shows that refusal while the rest of behold
* works. A read is never sent to a chant that would reject it.
* - `behold doctor` lists every entry with the project's chant version, so
* a new entry shows up there without further work.
*
* New reads go through the read contract (src/workspace-reader.ts), never
* through chant's library. Pure: imports only src/floor.ts, so any module may
* import it.
*/
import { meetsFloor } from "./floor.ts";

/** The first chant whose `graph` takes `--traffic` (chant#2377). An older one
* rejects an unknown flag outright (chant#1127), so the flag is never sent
* hopefully. */
export const TRAFFIC_FLOOR = "0.75.0";
/** The chant that ships `graph --live --namespace <ns>` (chant#1629). Below
* this the flag is not merely ignored: chant#1127 made an unrecognised `--`
* flag a hard error, so a member on an older chant is left unjoined rather
* than sent an invocation its own CLI will refuse, which would turn today's
* "pending, with the note" into "unobserved", a strictly worse picture. */
export const NAMESPACE_JOIN_FLOOR = "0.44.5";
/** The first chant that writes contract 1. An older one has no `workspace` command at all. */
export const WORKSPACE_CHANT_FLOOR = "0.81.0";
/** The first chant whose intent document carries `why` (INTENTIUS/chant#3312). */
export const WHY_CHANT_FLOOR = "0.102.0";
/** The chant that ships `chant operator log` (chant#2029). */
export const OPERATOR_LOG_FLOOR = "0.53.1";
/** The chant that first answers `chant carve status` (chant#2038). */
export const CARVE_STATUS_FLOOR = "0.54.0";

export interface ChantFloor {
/** The read, in words: `the why of a member or a card`. */
read: string;
/** The floor constant's value: the first chant release that adds the read. */
floor: string;
/** What adds it in chant, for the person reading doctor. */
adds: string;
}

/** Every read behold makes of chant that an older chant cannot answer. Add
* one entry per new read. */
export const CHANT_FLOORS: readonly ChantFloor[] = [
{ read: "workspace read contract", floor: WORKSPACE_CHANT_FLOOR, adds: "chant workspace (contract 1)" },
{ read: "why", floor: WHY_CHANT_FLOOR, adds: "graph --intent writes a why (chant#3312)" },
{ read: "carve status", floor: CARVE_STATUS_FLOOR, adds: "chant carve status (chant#2038)" },
{ read: "operator log", floor: OPERATOR_LOG_FLOOR, adds: "chant operator log (chant#2029)" },
{ read: "graph traffic", floor: TRAFFIC_FLOOR, adds: "graph --traffic (chant#2377)" },
{ read: "namespace join", floor: NAMESPACE_JOIN_FLOOR, adds: "graph --live --namespace (chant#1629)" },
];

/** One read's floor against one chant version. An unknown version meets it
* (an unknown version is not evidence of an old one). */
export function floorMet(f: ChantFloor, version: string | undefined): boolean {
return meetsFloor(version, f.floor);
}

/** The refusal a pane shows when the chant it would ask is older than the read's floor. */
export function floorRefusal(f: ChantFloor, version: string | undefined): { error: string; code: string; remedy: string } {
return {
error: `${f.read[0].toUpperCase()}${f.read.slice(1)} needs chant ${f.floor} or newer. This project has chant ${version ?? "(unknown version)"}.`,
code: "chant-too-old",
remedy: `Upgrade @intentius/chant to ${f.floor} or newer in the project.`,
};
}

/** The registry's entry for a read, by its `read` name. Several reads can share one floor version, so the
* lookup is by name. Throws on a read not registered, so a typo fails a test. */
export function floorFor(read: string): ChantFloor {
const f = CHANT_FLOORS.find((x) => x.read === read);
if (!f) throw new Error(`no chant floor for the read "${read}" in src/chant-floors.ts`);
return f;
}
7 changes: 3 additions & 4 deletions src/chant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,9 @@ export function envOverridesFor(opts: GraphOptions): Record<string, string> | un
return Object.keys(overrides).length ? overrides : undefined;
}

/** The first chant whose `graph` takes `--traffic` (chant#2377). An older one
* rejects an unknown flag outright (chant#1127), so the flag is never sent
* hopefully. */
export const TRAFFIC_FLOOR = "0.75.0";
/** The first chant whose `graph` takes `--traffic` (chant#2377); see src/chant-floors.ts. */
import { TRAFFIC_FLOOR } from "./chant-floors.ts";
export { TRAFFIC_FLOOR };

/** Does this member's own read take `--traffic` (#402)? A chant member does
* when its own chant has the flag; a terraform member is read by behold's
Expand Down
39 changes: 37 additions & 2 deletions src/doctor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import type { Kubeconfig } from "./k8s-target.ts";
import type { Substrate } from "./substrates.ts";
import { discoverTerraformRoots as realRoots } from "./terraform-member.ts";
import { chantFloor } from "./chant.ts";
import { CHANT_FLOORS } from "./chant-floors.ts";
import { WHY_CHANT_FLOOR } from "./workspace-why.ts";

// Fixtures are built in the OS tmpdir rather than pointed at the bundled
// examples: example-writes' node_modules is intentionally absent in a fresh
Expand Down Expand Up @@ -89,7 +91,7 @@ describe("diagnose", () => {

expect(report.ok).toBe(true);
expect(report.kind).toBe("project");
expect(report.checks.map((c) => c.status)).toEqual(["pass", "pass", "pass", "pass", "pass", "pass", "pass", "pass"]);
expect(report.checks.map((c) => c.status)).toEqual(Array(8 + CHANT_FLOORS.length).fill("pass"));
expect(by(report, "chant").detail).toContain(`chant ${AT_FLOOR}`);
expect(by(report, "lexicons").detail).toContain("aws 0.61.0");
expect(by(report, "envs").detail).toContain("prod");
Expand Down Expand Up @@ -119,6 +121,39 @@ describe("diagnose", () => {
expect(chant.detail).toContain(`below behold's floor ${chantFloor()}`);
});

it("lists each chant read with the project's chant version and whether its floor is met (#691)", async () => {
const stale = fixture({
"chant.config.ts": `export default { lexicons: ["aws"], environments: ["prod"], sourceDir: "src" };`,
"package.json": JSON.stringify({ name: "stale", dependencies: { "@intentius/chant": "^0.95.0" } }),
"src/main.ts": "",
...installed("@intentius/chant", "0.95.0", "bin/chant"),
});
const report = await diagnose(stale, probes({ detectSubstrates: async () => up }));
const floors = report.checks.filter((c) => c.name === "floor");
expect(floors).toHaveLength(CHANT_FLOORS.length);
const why = floors.find((c) => c.detail.startsWith("why:"))!;
// 0.95.0 is below WHY_CHANT_FLOOR (0.102.0): named, with the project's version.
expect(why.status).toBe("warn");
expect(why.detail).toContain(`needs chant ${WHY_CHANT_FLOOR}`);
expect(why.detail).toContain("chant 0.95.0");
expect(why.detail).toContain("not met");
expect(why.fix).toContain(WHY_CHANT_FLOOR);
// The workspace contract floor (0.81.0) is met by the same chant.
const contract = floors.find((c) => c.detail.startsWith("workspace read contract:"))!;
expect(contract.status).toBe("pass");
expect(contract.detail).toMatch(/, met$/);
expect(formatReport(report)).toContain("why: needs chant");

const current = fixture({
"chant.config.ts": `export default { lexicons: ["aws"], environments: ["prod"], sourceDir: "src" };`,
"package.json": JSON.stringify({ name: "fresh", dependencies: { "@intentius/chant": "^99.0.0" } }),
"src/main.ts": "",
...installed("@intentius/chant", "99.0.0", "bin/chant"),
});
const ok = await diagnose(current, probes({ detectSubstrates: async () => up }));
expect(ok.checks.filter((c) => c.name === "floor").every((c) => c.status === "pass")).toBe(true);
});

it("fails with one line, and the fix, for a directory that is no project at all (#193's dead end)", async () => {
const report = await diagnose(fixture({ "notes.txt": "hello" }), probes());

Expand Down Expand Up @@ -446,7 +481,7 @@ describe("--json", () => {
expect(round.dir).toBe(dir);
expect(round.kind).toBe("project");
expect(round.ok).toBe(true);
expect(round.checks.map((c) => c.name)).toEqual(["project", "chant", "lexicons", "targets", "envs", "kube", "substrates", "ops"]);
expect(round.checks.map((c) => c.name)).toEqual(["project", "chant", ...CHANT_FLOORS.map(() => "floor"), "lexicons", "targets", "envs", "kube", "substrates", "ops"]);
for (const c of round.checks) {
expect(Object.keys(c).filter((k) => k !== "fix")).toEqual(["name", "status", "detail"]);
expect(["pass", "warn", "fail"]).toContain(c.status);
Expand Down
21 changes: 20 additions & 1 deletion src/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
type ChantResolution,
} from "./chant.ts";
import { registeredMemberKinds } from "./member-kind.ts";
import { CHANT_FLOORS, floorMet } from "./chant-floors.ts";
import { CHOUDOUFU_FLOOR, choudoufuBinary, choudoufuMeetsFloor, choudoufuVersion, readLiveCheck, type ChoudoufuVersion, type LiveCheckParse } from "./choudoufu-member.ts";
import { detectProject, detectProjectShape, loadBeholdConfig, type ProjectKind } from "./project.ts";
import { terragucciConfig } from "./terragucci-repo.ts";
Expand All @@ -59,7 +60,7 @@ export type CheckStatus = "pass" | "warn" | "fail";
* on it); `detail` is what behold found; `fix` is the single next step, set
* whenever the status isn't a pass. */
export interface DoctorCheck {
name: "project" | "chant" | "lexicons" | "targets" | "envs" | "kube" | "substrates" | "ops" | "choudoufu" | "terraform";
name: "project" | "chant" | "lexicons" | "targets" | "envs" | "kube" | "substrates" | "floor" | "ops" | "choudoufu" | "terraform";
status: CheckStatus;
detail: string;
fix?: string;
Expand Down Expand Up @@ -153,6 +154,23 @@ function chantCheck(root: string, targets: string[], estate: boolean): DoctorChe
return { name: "chant", status: "pass", detail: `${versions}${floor ? ` (behold's floor ${floor})` : ""}` };
}

/** #691: one line per chant read behold makes (src/chant-floors.ts), each with
* the chant version of the project (every chant member of an estate) and
* whether the read's floor is met. An unmet floor is a warn: the pane that
* needs the read says so and the rest of behold works. */
export function floorChecks(root: string, targets: string[], estate: boolean): DoctorCheck[] {
if (!targets.length) return [];
const resolutions = targets.map((t) => ({ target: t, res: resolveChant(t) }));
const have = list(resolutions.map(({ target, res }) => `${labelFor(root, target, estate)}chant ${res.version ?? "(unknown version)"}`));
return CHANT_FLOORS.map((f): DoctorCheck => {
const behind = resolutions.filter(({ res }) => !floorMet(f, res.version));
const head = `${f.read}: needs chant ${f.floor} (${f.adds}); ${have}`;
return behind.length
? { name: "floor", status: "warn", detail: `${head}, not met`, fix: `Upgrade @intentius/chant to ${f.floor} or newer in ${list(behind.map(({ target }) => relative(root, target) || target))}; the pane that needs the ${f.read} stays off until then.` }
: { name: "floor", status: "pass", detail: `${head}, met` };
});
}

/** The lexicons line: what the config declares against what's installed. A
* declared-but-missing lexicon is the same "not-installed" chant would raise
* at graph time, said before a graph route has to. */
Expand Down Expand Up @@ -585,6 +603,7 @@ export async function diagnose(dir: string, probes: DoctorProbes = {}): Promise<
const checks: DoctorCheck[] = [
projectCheck,
chantCheck(root, chantTargets, estate),
...floorChecks(root, chantTargets, estate),
lexiconCheck(root, declared, estate),
targetCheck(declared),
// An estate root is not itself servable — the hint has to name its members
Expand Down
9 changes: 3 additions & 6 deletions src/estate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,9 @@ export function namespaceRuntimeOwners(name: string, ir: GraphIR): GraphIR {
// and an object naming its own namespace is untouched.
// ---------------------------------------------------------------------------

/** The chant that ships `graph --live --namespace <ns>` (chant#1629). Below
* this the flag is not merely ignored: chant#1127 made an unrecognised `--`
* flag a hard error, so a member on an older chant is left unjoined rather
* than sent an invocation its own CLI will refuse — which would turn today's
* "pending, with the note" into "unobserved", a strictly worse picture. */
export const NAMESPACE_JOIN_FLOOR = "0.44.5";
/** The chant that ships `graph --live --namespace <ns>` (chant#1629); see src/chant-floors.ts. */
import { NAMESPACE_JOIN_FLOOR } from "./chant-floors.ts";
export { NAMESPACE_JOIN_FLOOR };

type Rec = Record<string, unknown>;
const rec = (v: unknown): Rec | undefined => (v && typeof v === "object" && !Array.isArray(v) ? (v as Rec) : undefined);
Expand Down
3 changes: 2 additions & 1 deletion src/operator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,8 @@ export function convergeGateCards(rows: readonly OpStatusLine[]): ConvergeGateCa
* subcommand. That is a happy accident of flag ordering, not a guarantee, and it
* is not what behold relies on.)
*/
export const OPERATOR_LOG_FLOOR = "0.53.1";
import { OPERATOR_LOG_FLOOR } from "./chant-floors.ts";
export { OPERATOR_LOG_FLOOR };

/** How many timeline entries behold asks for when nothing says otherwise. */
export const OPERATOR_LOG_LIMIT = 50;
Expand Down
8 changes: 8 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ import { discoverSplitPlans, moveMembers, moveReceipt, movesPayload, readSplitPl
import { servedWorkspace, setServedWorkspace, workspaceMemberOf, type Workspace } from "./workspace.ts";
import { approveArgs, isEnvName, isOverrideGate, localApprover, readWorkspaceGates } from "./workspace-gates.ts";
import { readWhy, whyRegion } from "./workspace-why.ts";
import { floorFor, floorMet, floorRefusal } from "./chant-floors.ts";
import { allowedHostsFrom, guardRequest } from "./request-guard.ts";
import { applyMemberPasses, memberKindOf, memberKindSpec, memberPassNote, servesAsEstate, type MemberPassRun } from "./member-kind.ts";
import { TerraformReadError, terraformMemberProject, terraformReaderState, terraformVia } from "./terraform-member.ts";
Expand Down Expand Up @@ -1548,6 +1549,13 @@ export function createApp(
if (!ws) return c.json({ workspace: false, error: "behold isn't serving a declared chant workspace, so there is no why to read.", code: "no-workspace" });
const ask = whyRegion(ws, { member: c.req.query("member") || null, node: c.req.query("node") || null });
if (!ask.ok) return c.json({ workspace: true, ...ask.refusal }, 400);
// #691: a chant below the why floor is refused here, before the slow read
// is spawned; the pane says what is missing and the rest of behold works.
const whyFloor = floorFor("why");
const whyChant = resolveChant(ws.root).version;
if (!floorMet(whyFloor, whyChant)) {
return c.json({ workspace: true, member: ask.member, region: ask.region, ms: 0, refusal: floorRefusal(whyFloor, whyChant) });
}
const started = Date.now();
let read: Awaited<ReturnType<typeof readWhy>>;
try {
Expand Down
5 changes: 3 additions & 2 deletions src/workspace-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ import { runChantRaw } from "./chant.ts";

/** The read contract version behold reads (chant's `reference/workspace-read-contract`). */
export const WORKSPACE_CONTRACT = 1;
/** The first chant that writes contract 1. An older one has no `workspace` command at all. */
export const WORKSPACE_CHANT_FLOOR = "0.81.0";
/** The first chant that writes contract 1 (see src/chant-floors.ts). */
import { WORKSPACE_CHANT_FLOOR } from "./chant-floors.ts";
export { WORKSPACE_CHANT_FLOOR };

/** The read-contract commands behold reads, named the way chant's conformance suite names them. */
export const BEHOLD_READS = ["ls", "graph", "status", "graph --intent"] as const;
Expand Down
Loading
Loading