Skip to content

Commit 959e226

Browse files
Vivswansettings-as-code-release
andauthored
style: comments carry only what the code cannot show (#155)
Co-authored-by: settings-as-code-release <settings-as-code-release@users.noreply.github.com>
1 parent cbeb56f commit 959e226

314 files changed

Lines changed: 4606 additions & 14026 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/scripts/arch-lint.ts‎

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
/**
2-
* The architecture lint (bun run lint:arch): the imports between the layers
3-
* of src/ are exactly the edges architecture.yml declares - an undeclared
4-
* edge and a stale allowance both fail. gen-docs.ts renders the same
5-
* declaration as the module map. dependency-cruiser was the intended tool but
6-
* cannot cruise this repository: it needs the TypeScript compiler API, which
7-
* the pinned typescript 7 no longer ships, so it resolves nothing.
8-
*
9-
* An edge is any way one file names another: the runtime loads the
10-
* changed-sections scanner reads, plus type-only imports, re-exports, and
11-
* `import("./x.js").T` and `import X = require("./x.js")` in type positions.
2+
* The architecture lint (bun run lint:arch): src/ imports between layers must be exactly the edges architecture.yml
3+
* declares; an undeclared edge and a stale allowance both fail. dependency-cruiser was the intended tool, but it
4+
* needs the TypeScript compiler API, which the pinned typescript 7 no longer ships, so it resolves nothing here.
5+
* runtime loads (what the changed-sections scanner reads) -> edges
6+
* type-only imports, re-exports -> edges too
7+
* `import("./x.js").T`, `import X = require("./x.js")` in type positions -> edges too
128
*/
139

1410
import { readdirSync, readFileSync } from "node:fs";
@@ -31,7 +27,6 @@ export function readArchitecture(root: string): Architecture {
3127
return parseYaml(readFileSync(join(root, ARCHITECTURE_PATH), "utf8")) as Architecture;
3228
}
3329

34-
/** The layer owning a repo-relative path, or undefined. */
3530
function layerOf(arch: Architecture, path: string): string | undefined {
3631
return Object.entries(arch.layers).find(([, paths]) =>
3732
paths.some((owned) => (owned.endsWith("/") ? path.startsWith(owned) : path === owned)),
@@ -53,7 +48,6 @@ function* nodesOf(value: unknown): Generator<Node> {
5348
}
5449
}
5550

56-
/** Every relative specifier `text` names, runtime and type-level alike. */
5751
export function importSpecifiers(text: string, file: string): string[] {
5852
const { program, module } = parseSync(file, text);
5953
const typeLevel = [...nodesOf(program)].flatMap((node) => {
@@ -76,11 +70,6 @@ export function importSpecifiers(text: string, file: string): string[] {
7670
return [...all].filter((specifier) => /^\.\.?\//.test(specifier));
7771
}
7872

79-
/**
80-
* The lint verdict for `root`: an import between layers the declaration lacks
81-
* (naming both files), a declared edge no file draws, or a cruised file outside
82-
* every layer. Empty means the declaration is exactly the tree.
83-
*/
8473
export function lintArchitecture(root: string, arch = readArchitecture(root)): string[] {
8574
const excluded = arch.exclude.map((pattern) => new Bun.Glob(pattern));
8675
const drawn = new Map<string, string[]>();
@@ -129,7 +118,7 @@ export function lintArchitecture(root: string, arch = readArchitecture(root)): s
129118
return problems;
130119
}
131120

132-
/** The module map over the DECLARED edges; a hyphen in a layer name is edge syntax to mermaid. */
121+
/** A hyphen in a layer name is edge syntax to mermaid, so ids swap it for an underscore. */
133122
export function renderArchitectureMermaid(arch: Architecture): string {
134123
const id = (layer: string): string => layer.replace(/-/g, "_");
135124
return [

‎.github/scripts/changed-sections.ts‎

Lines changed: 40 additions & 143 deletions
Large diffs are not rendered by default.

‎.github/scripts/check-endpoint-coverage.ts‎

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
11
/**
2-
* Endpoint-coverage tripwire for the nightly e2e run. Every "section.role" key
3-
* in allEndpoints() AND allGraphqlOps() must be exercised at least once by the
4-
* curated corpus; a cold route means the harness has a blind spot, an endpoint
5-
* the action can call that no scenario reaches, so a regression there would
6-
* ship unnoticed.
2+
* Endpoint-coverage tripwire: every "section.role" key in allEndpoints() AND allGraphqlOps() must be reached by the
3+
* curated corpus at least once. A cold route is a blind spot, an endpoint the action can call that no scenario
4+
* reaches, so a regression there would ship unnoticed.
75
*
8-
* This runs the full corpus through runScenario and reads each report's request
9-
* log (ScenarioReport.requests, the snapshot the runner takes before teardown),
10-
* attributing every logged request to a registered route via matchesTemplate
11-
* (the same matcher the mock routes with) - or, for GraphQL, via the
12-
* operationName the mock dispatched. It then fails naming any route no
13-
* request reached.
14-
*
15-
* Usage: `bun .github/scripts/check-endpoint-coverage.ts`. Exit 0 when every
16-
* route was hit; exit 1 naming the cold routes otherwise.
6+
* `bun .github/scripts/check-endpoint-coverage.ts` fails on any cold route, naming it.
177
*/
188

199
import {
@@ -26,19 +16,10 @@ import type { LoggedRequest } from "../../test/e2e/mock/contract.js";
2616
import { runScenario } from "../../test/e2e/runner.js";
2717
import { loadScenarios, scenarioRoots } from "../../test/e2e/schema.js";
2818

29-
/**
30-
* One registered route, discriminated by how a hit is attributed: a REST
31-
* route matches by method + path template, a GraphQL operation by the
32-
* operationName the mock logged for the request.
33-
*/
3419
type Route =
3520
| { kind: "rest"; key: string; method: string; path: string }
3621
| { kind: "graphql"; key: string; opName: string };
3722

38-
/**
39-
* The registered routes - every REST endpoint plus every GraphQL operation -
40-
* so a cold GraphQL op fails the sweep exactly like a cold REST route.
41-
*/
4223
export function registeredRoutes(): Route[] {
4324
return [
4425
...Object.entries(allEndpoints()).map(
@@ -55,7 +36,6 @@ export function registeredRoutes(): Route[] {
5536
];
5637
}
5738

58-
/** Record every route each request hit into `hit` (mutated in place). */
5939
export function recordHits(
6040
requests: readonly LoggedRequest[],
6141
routes: Route[],
@@ -77,7 +57,6 @@ export function recordHits(
7757
}
7858
}
7959

80-
/** The registered route keys no request reached, sorted. */
8160
export function coldRoutes(hit: ReadonlySet<string>, routes: Route[]): string[] {
8261
return routes
8362
.filter((route) => !hit.has(route.key))
@@ -96,13 +75,9 @@ async function main(): Promise<number> {
9675
return 1;
9776
}
9877
for (const scenario of scenarios) {
99-
// A scenario's own pass/fail is the corpus job's concern; here we only
100-
// aggregate which routes it reached, so a throw does not stop the sweep. A
101-
// fault-injection scenario can drop the connection mid-run and make
102-
// runScenario throw; runScenario snapshots its request log into the report
103-
// and only returns on success, so a throw yields no report and its routes
104-
// go unattributed. That could turn a real hit into a false cold route, so
105-
// NAME the scenario loudly rather than swallow the throw.
78+
// A scenario's own pass/fail is the corpus job's concern; here only its reached routes matter. runScenario
79+
// returns a report (with the request log) even for a failing scenario, so a THROW is the one path that loses the
80+
// routes it did reach and can turn a real hit into a cold route: name the scenario loudly, never swallow it.
10681
try {
10782
const report = await runScenario(scenario);
10883
recordHits(report.requests, routes, hit);

‎.github/scripts/coverage-data.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/**
2-
* The authored half of COVERAGE.md (rendered by gen-docs.ts): the prose no declaration can
3-
* derive, because it enumerates what does NOT exist - the repo-scoped gaps, the settings with no
4-
* public API, and the account-scoped surface. The data is coverage-data.yml beside this file;
5-
* this module is its shape and loader. The Supported table renders from each section's <key>.docs.yml.
2+
* The authored half of COVERAGE.md (rendered by gen-docs.ts): the prose no declaration can derive, because it
3+
* enumerates what does NOT exist. The data is coverage-data.yml beside this file; the Supported table renders from
4+
* each section's <key>.docs.yml.
65
*/
76

87
import { join } from "node:path";
@@ -41,7 +40,6 @@ const CoverageGaps = z.union([
4140
.readonly(),
4241
]);
4342

44-
/** A non-empty list of authored bullets. */
4543
const Items = z.tuple([z.string().min(1)], z.string().min(1)).readonly();
4644

4745
export const CoverageData = z

‎.github/scripts/fetch-graphql-schema.ts‎

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,49 @@
11
/**
2-
* Fetch GitHub's public GraphQL schema and write it to disk, the GraphQL
3-
* sibling of trim-openapi.ts. The query-validation unit test
4-
* (test/sections/graphql-queries.test.ts) loads the schema from disk - never
5-
* the network - so test runs stay hermetic and fast; this script is the ONLY
6-
* thing that touches the network. The output is a FETCHED, gitignored
7-
* artifact (a multi-MB generated blob kept out of history): local devs run
8-
* this once, and CI restores it from actions/cache or re-fetches on a miss.
2+
* Fetches GitHub's public GraphQL schema to disk, the GraphQL sibling of trim-openapi.ts. This script is the ONLY
3+
* thing that touches the network; the output is a fetched, gitignored artifact.
4+
* test/sections/graphql-queries.test.ts -> loads it from disk
5+
* local dev -> runs this once
6+
* CI -> restores it from cache, re-fetches on a miss
7+
* UPSTREAM_REF -> PINNED to a github/docs commit, so two runs months apart fetch byte-identical text
98
*
10-
* Run: `bun .github/scripts/fetch-graphql-schema.ts` (writes the schema in
11-
* place). Re-run to adopt a newer upstream ref.
12-
*
13-
* The upstream ref is PINNED to a github/docs commit SHA (the docs pipeline
14-
* publishes the schema at src/graphql/data/fpt/schema.docs.graphql and
15-
* updates it continuously on main), so two runs months apart fetch
16-
* byte-identical schema text - the same reproducibility contract as
17-
* trim-openapi's UPSTREAM_REF.
9+
* Run: `bun .github/scripts/fetch-graphql-schema.ts`; re-run after bumping UPSTREAM_REF.
1810
*/
1911

2012
import { mkdirSync, renameSync, writeFileSync } from "node:fs";
2113
import { dirname, join } from "node:path";
2214
import { buildSchema } from "graphql";
2315
import { fetchTextWithRetry } from "./lib/fetch-retry.js";
2416

25-
/**
26-
* The github/docs commit the schema is fetched at. Bump this (and re-run) to
27-
* adopt upstream schema changes; pinning to a SHA keeps the output
28-
* reproducible.
29-
*/
3017
const UPSTREAM_REF = "01f2174e1ab5d15d4946cfe96ef7dfb5c9a8b889";
3118

32-
/** The free-tier (github.com) schema, the flavor the action targets. */
19+
/** fpt is the free-tier (github.com) flavor, the one the action targets. */
3320
const SCHEMA_URL =
3421
`https://raw.githubusercontent.com/github/docs/${UPSTREAM_REF}` +
3522
"/src/graphql/data/fpt/schema.docs.graphql";
3623

3724
const OUT_PATH = join(import.meta.dir, "..", "..", "test", "e2e", "graphql", "schema.docs.graphql");
3825

39-
/** Abandon a fetch attempt if the (large) schema has not arrived in this long. */
4026
const FETCH_TIMEOUT_MS = 60_000;
4127

4228
async function main(): Promise<number> {
4329
console.log(`fetching ${SCHEMA_URL}`);
44-
// Per-attempt timeout plus bounded retry (lib/fetch-retry.ts): a hung
45-
// connection or a transient blip - even mid-download - fails loudly with
46-
// advice instead of the script stalling forever, or one blip failing the
47-
// whole CI gate.
4830
const fetched = await fetchTextWithRetry("GraphQL schema", SCHEMA_URL, FETCH_TIMEOUT_MS);
4931
if (!fetched.ok) {
5032
throw new Error(
5133
`failed to fetch the GraphQL schema: ${fetched.status} ${fetched.statusText} for ${SCHEMA_URL}. Check UPSTREAM_REF and the schema path`,
5234
);
5335
}
5436
const text = fetched.text;
55-
// Integrity at generation, the assertRefFree analog: a truncated download
56-
// or a moved upstream file must fail HERE, not as an opaque parse error in
57-
// the disk-only consumer.
37+
// A truncated download or a moved upstream file must fail HERE, not as an opaque parse error in the disk-only consumer.
5838
try {
5939
buildSchema(text);
6040
} catch (error) {
6141
throw new Error(
6242
`the fetched GraphQL schema from ${SCHEMA_URL} failed to parse: ${error instanceof Error ? error.message : String(error)}. The download may be truncated (re-run), or the upstream file changed shape (check UPSTREAM_REF)`,
6343
);
6444
}
65-
// Atomic write: serialize to a temp file, then rename over the target, so
66-
// an aborted run leaves the previously written schema intact. The directory
67-
// holds no tracked file, so a fresh checkout must create it first.
45+
// Temp file then rename, so an aborted run leaves the previously written schema intact. The directory holds no
46+
// tracked file, so a fresh checkout must create it first.
6847
mkdirSync(dirname(OUT_PATH), { recursive: true });
6948
const tmpPath = `${OUT_PATH}.tmp`;
7049
writeFileSync(tmpPath, text);

0 commit comments

Comments
 (0)