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
19 changes: 19 additions & 0 deletions packages/core/src/ci-product-config-words.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { describe, expect, test } from "vitest";
import {
CI_PRODUCTS,
PRODUCT_AUDIT_KINDS,
PRODUCT_CONFIG_SCOPED_ALIASES_FLOOR,
PRODUCT_CONFIG_WORDS,
PRODUCT_CONFIG_WORDS_FLOOR,
PRODUCT_RELEASE_ALIASES,
Expand Down Expand Up @@ -179,6 +180,24 @@ describe("productConfigProblems", () => {
]);
});

test("an alias beside its key is an error at the top level", () => {
const problems = productConfigProblems({ oidc: { plan_role: "a" }, identity: { aws: {} } }, { product: "terragucci" });
expect(problems.filter((p) => p.level === "error").map((p) => [p.path, p.message])).toEqual([["oidc", "and identity are both set; set identity alone"]]);
});

test("an alias beside its key inside a scope is an error naming both", () => {
const problems = productConfigProblems({ ci: { login: { aws: {} }, identity: { aws: {} } } }, { product: "sql-yodeler", case: "camel", scopes: ["ci"] });
expect(problems.filter((p) => p.level === "error").map((p) => [p.path, p.message])).toEqual([["ci.login", "and ci.identity are both set; set ci.identity alone"]]);
expect(problems.filter((p) => p.level === "warning").map((p) => p.path)).toEqual(["ci.login"]);
// The alias alone gives the warning and no error; a scope the caller does not pass is not read.
expect(productConfigProblems({ ci: { login: { aws: {} } } }, { product: "sql-yodeler", case: "camel", scopes: ["ci"] }).filter((p) => p.level === "error")).toEqual([]);
expect(productConfigProblems({ ci: { login: {}, identity: {} } }, { product: "sql-yodeler", case: "camel" }).filter((p) => p.level === "error")).toEqual([]);
});

test("the scoped-alias floor names the next release", () => {
expect(PRODUCT_CONFIG_SCOPED_ALIASES_FLOOR).toBe(NEXT_RELEASE);
});

test("promotion is a list of distinct environment names the environments map declares", () => {
const check = (promotion: unknown, environments?: unknown) =>
productConfigProblems({ promotion, ...(environments ? { environments } : {}) }, { product: "terragucci" }).map((p) => p.message);
Expand Down
16 changes: 10 additions & 6 deletions packages/core/src/ci-product-words.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2071,7 +2071,7 @@ export interface ProductConfigOptions {
product: string;
/** How the product spells keys. Default `snake`. */
case?: ProductConfigCase;
/** Maps the vocabulary's keys may also sit under, such as sql-yodeler's `ci`. The top level is always read, and aliases are read there alone. */
/** Maps the vocabulary's keys may also sit under, such as sql-yodeler's `ci`. The top level is always read. An alias whose key starts at a scope is read inside it too, to find the key set beside it. */
scopes?: readonly string[];
}

Expand Down Expand Up @@ -2159,16 +2159,20 @@ export function productConfigProblems(config: unknown, options: ProductConfigOpt
for (const word of PRODUCT_CONFIG_WORDS) {
const shown = spelled(word.key, kase);
for (const alias of word.aliases ?? []) {
// An alias names its full path, so it is read from the top level alone.
if (prefix !== "" || alias.product !== options.product || alias.key === undefined) continue;
for (const hit of resolve(doc, segments(alias.key, kase))) {
if (alias.product !== options.product || alias.key === undefined) continue;
// An alias names its full path. Inside a scope it is read when that
// path starts at the scope; the top-level pass already reports it as a
// warning, so here it only finds the key set beside it.
const parts = segments(alias.key, kase);
if (prefix !== "" && parts[0] !== prefix.slice(0, -1)) continue;
for (const hit of resolve(doc, prefix === "" ? parts : parts.slice(1))) {
if (!hasShape(hit.value, alias.shape)) continue;
aliased.add(hit.path);
out.push({ level: "warning", path: at(hit.path), key: word.key, message: `is accepted as ${shown}, the vocabulary's key` });
if (prefix === "") out.push({ level: "warning", path: at(hit.path), key: word.key, message: `is accepted as ${shown}, the vocabulary's key` });
// The key set beside its alias, where the alias does not sit inside
// it (plywood's `notify.slack.webhook` sits inside `notify.slack`).
if (!alias.key.includes("<") && resolve(doc, segments(word.key, kase)).some((h) => !hit.path.startsWith(`${h.path}.`))) {
out.push({ level: "error", path: at(hit.path), key: word.key, message: `and ${shown} are both set; set ${shown} alone` });
out.push({ level: "error", path: at(hit.path), key: word.key, message: `and ${at(shown)} are both set; set ${at(shown)} alone` });
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/ci-product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ export {
*/
export const PRODUCT_CONFIG_WORDS_FLOOR = NEXT_RELEASE;

/**
* The first chant where `productConfigProblems` reads an alias inside a scope
* the caller passes: sql-yodeler's `ci.login` set beside `ci.identity` is an
* error naming both, as `oidc` beside `identity` is at the top level.
*/
export const PRODUCT_CONFIG_SCOPED_ALIASES_FLOOR = NEXT_RELEASE;

/**
* The first chant with the plan's cost estimate (#5334): `ci.cost` in the
* workspace declaration, read at base, which `pr-plan` and `pr-apply` run
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/floor-table.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const FLOOR_ROWS: readonly FloorRow[] = [
{ name: "OWN_JOBS_FLOOR", version: "0.124.77", gates: "The first chant with `mergeOwnJobs`, `keepOwnJobs` and `chant build --own-jobs` / `--keep-own-jobs` (#4769).", issue: "#4769", file: "ci-own-jobs.ts", modules: ["@intentius/chant/ci-own-jobs","@intentius/chant/ci-product"] },
{ name: "CI_PRODUCT_FLOOR", version: "0.124.55", gates: "The first chant with the product pipeline (#4550): the words, the `pull-request` op-wave approval source, `runCommandInProcess(argv, { words })`, the lexicons' `ciSetup`, and the member detail sections of the note (#4573).", issue: "#4573", file: "ci-product.ts", modules: ["@intentius/chant/ci-product"] },
{ name: "PRODUCT_CONFIG_WORDS_FLOOR", version: NEXT_RELEASE, gates: "The first chant with the product config vocabulary (#5343): `PRODUCT_CONFIG_WORDS`, one key and one set of value words per concept a product sets, with the chant field each maps to and the aliases each product accepts; `productConfigProblems`, which checks a product's config against it; `PRODUCT_RELEASE_WORDS` for promote, rollback and redeploy; and `PRODUCT_AUDIT_KINDS`.", issue: "#5343", file: "ci-product.ts", modules: ["@intentius/chant/ci-product"] },
{ name: "PRODUCT_CONFIG_SCOPED_ALIASES_FLOOR", version: NEXT_RELEASE, gates: "The first chant where `productConfigProblems` reads an alias inside a scope the caller passes: sql-yodeler's `ci.login` set beside `ci.identity` is an error naming both, as `oidc` beside `identity` is at the top level.", file: "ci-product.ts", modules: ["@intentius/chant/ci-product"] },
{ name: "COST_ESTIMATE_FLOOR", version: NEXT_RELEASE, gates: "The first chant with the plan's cost estimate (#5334): `ci.cost` in the workspace declaration, read at base, which `pr-plan` and `pr-apply` run over each member's plan document (`artifact.planJson` of `terraform-apply` and `pulumi-up`), with the estimate as the report's and the note's `cost` and the policy's `input.cost`; `PrPlanNote.cost` for a product's own plan note; a wave's `holds.policy` reading `input.cost` beside `holds.cost`; and `estimateCosts`, `costEstimateLines` and `policyCost`, which build the same record for a product that plans by itself.", issue: "#5334", file: "ci-product.ts", modules: ["@intentius/chant/ci-product"] },
{ name: "CHANGE_RISK_FLOOR", version: NEXT_RELEASE, gates: "The first chant with the scored change risk (#5325): `ci.risk` in the workspace declaration, read at base, which `pr-plan` and `pr-apply` score over the change set from its deletes, replacements, disruption classes, destructive migration classes, members and environments reached, graph dependents, the review's level and the answers to `ci.risk.questions`, with the record as the report's and the note's `risk`, the stored change set's `risk` and the policy's `input.risk`; a wave's and a stage gate's `holds.risk`, which over `approveAbove` holds the wave and adds its `quorum` rules; an Op gate's `approval.risk`, which puts the record in Cedar's `context.changeRisk` and counts a permit only from a proven human; the review agent's `questions` and answers; and `scoreChangeRisk`, `changeRiskLines` and `CHANGE_RISK_WEIGHTS` for a product that plans by itself.", issue: "#5325", file: "ci-product.ts", modules: ["@intentius/chant/ci-product"] },
{ name: "NOTIFY_RELAY_FLOOR", version: "0.124.55", gates: "The first chant with `chant notify relay` and the notify relay buttons (#4611).", issue: "#4611", file: "ci-product.ts", modules: ["@intentius/chant/ci-product"] },
Expand Down