Skip to content

Commit 919d548

Browse files
committed
test(library): read the doc pin through fences and blockquotes; fix the entry counts
1 parent 6cf8f69 commit 919d548

5 files changed

Lines changed: 95 additions & 16 deletions

File tree

‎docs/reference/library.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ console.log(merged.value.yaml, merged.value.notices.length);
9999
| `SettingsFile` | const | The zod schema of the whole document, and its inferred type |
100100
| `SECTION_KEYS` | const | Every section key in execution order |
101101
| `SectionKey` | type | One of them |
102+
| `UNDECLARED_POLICY_SECTIONS` | const | The list sections whose wrapper takes `_undeclared`, and so `_layering`: the only places, beside the document top, a `_layering` directive may sit |
103+
| `UndeclaredPolicySection` | type | One of them |
102104

103105
The schema subpath serves the committed JSON Schema.
104106

@@ -115,7 +117,7 @@ console.log(parsed.success, SECTION_KEYS.length, schema.$schema);
115117
| Name | Kind | Says |
116118
|---|---|---|
117119
| `GitHubApi` | class | The REST and GraphQL client the action uses: retries, throttling, the pinned API version, trace redaction |
118-
| `GitHubApiOptions` | type | Its constructor's options: `token` required; `io`, `baseUrl`, `apiVersion` optional |
120+
| `GitHubApiOptions` | type | Its constructor's options: `token` required; `io` (the trace sink), `baseUrl`, `apiVersion`, `retryBaseMs` (real milliseconds per plugin second), `scheduler` (the throttling limiter), `userAgent` optional |
119121
| `GitHubClient` | type | The port every verb reads and writes through, and the interface a test double implements |
120122
| `DEFAULT_API_VERSION` | const | The `X-GitHub-Api-Version` the action pins |
121123
| `ApiError` | type | A failed request as the port returns it: `status`, `message`, `body` |

‎docs/upgrading/v2-to-v3.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Ten breaks (the ninth is for library consumers). One is silent (the fallback), s
1616
| The three outputs are always set | `repos-result` existed only in multi-repo runs and the `snapshot-dir` form; unset elsewhere | `result`, `skipped-sections`, and `repos-result` are set on every run; `repos-result` is `{}` outside a fleet | No error. A step testing `repos-result != ''` to detect a fleet run now always passes; [section 6](#6-the-three-outputs-are-always-set) |
1717
| One `--json` envelope on the command line | `validate` printed `{file, valid, sections}`, `permissions` a bare grant map, `init` `skippedSections` | Every subcommand prints `{result, ...}`; `permissions` puts its grants under `grant`, lists are lists | A `jq` filter on the old keys reads `null`; [section 7](#7-one---json-envelope) |
1818
| A snapshot section that fails on its own fails the target | `result: partial`, exit 0, the file written without that section | `result: failed`, exit 1, no file for that target; `init` refuses to write | The workflow step fails where it passed; [section 8](#8-a-failed-snapshot-section-fails-the-target) |
19-
| Library: a documented public entry, an internal one, and the v3 names | One entry, 194 names; `GithubApi`, `RepoRunReport`, `validateSettings` returning `warnings` | `.` holds the 116 documented names, `./internal` the rest; `GitHubApi`, `CheckReport`, every report carries `log` | The old import fails to compile, naming the missing export; every rename is in [section 9](#9-library-the-public-entry-and-the-v3-names) |
19+
| Library: a documented public entry, an internal one, and the v3 names | One entry, 192 names; `GithubApi`, `RepoRunReport`, `validateSettings` returning `warnings` | `.` holds the 118 documented names, `./internal` the rest; `GitHubApi`, `CheckReport`, every report carries `log` | The old import fails to compile, naming the missing export; every rename is in [section 9](#9-library-the-public-entry-and-the-v3-names) |
2020
| One redacted label in every mode | A single-repository run labelled its hidden target `private repository`; a fleet numbered them `private repository #N` | `private repository #N` everywhere; a run over one repository is `#1` | No error. A log filter or artifact-report reader matching `private repository:` exactly no longer matches; [section 10](#10-one-redacted-label-in-every-mode) |
2121

2222
## 1. The defaults-file fallback
@@ -130,7 +130,7 @@ The package now has two entries, and one naming family per layer:
130130

131131
| | v2 | v3 |
132132
|---|---|---|
133-
| The entry | One, 194 names, all pinned | `.`: the 116 names the [library page](../reference/library.md#the-api-by-group) tables document, under semver. `./internal`: everything else the action, the CLI, and the tests import, with no promise |
133+
| The entry | One, 192 names, all pinned | `.`: the 118 names the [library page](../reference/library.md#the-api-by-group) tables document, under semver. `./internal`: everything else the action, the CLI, and the tests import, with no promise |
134134
| The verbs | `checkRepository`, `applyRepository`, `snapshotRepository`, `snapshotRepositories`, `validateSettings`, plus `foldLayers` and `mergeLayers` for a merge | The same five, plus `mergeSettings`; every verb takes its inputs positionally and one options object of the same knobs (`sections`, `onMissingPermission`, `io`, ...), each defaulted as the action's input |
135135
| The reports | `RepoRunReport` (`log`), `SnapshotReport` (`log`), `validateSettings` (`warnings: string[]`) | `CheckReport`, `ApplyReport`, `SnapshotReport`, `MergeReport`, `ValidateReport`: one `log: CollectedLine[]` on every report, the annotation level kept beside each line |
136136

@@ -164,12 +164,12 @@ Every rename, old to new. An old name fails to compile, naming the missing expor
164164
| `AFFILIATIONS`, `ARCHIVED_FILTERS`, `FORKS_FILTERS`, `VISIBILITY_FILTERS`, `DiscoveryProblem` | `./internal` |
165165
| `stripNulls`, `describeOptOut` | `stripNulls` in `./internal`; `describeOptOut` stays public |
166166
| `quoteList`, `RERUN_ADVICE`, `ProblemOf`, `SettingsProblem`, `LayerProblem`, `CentralFileProblem`, `TopLevelShape` | `./internal` |
167-
| `DOCUMENT_DIRECTIVE_KEYS`, `PROBOT_PARITY_KEYS`, `UNDECLARED_POLICY_SECTIONS`, `UndeclaredPolicySection`, `UndeclaredPolicy`, `UndeclaredPolicyList`, `MustBeNever` | `./internal` |
167+
| `DOCUMENT_DIRECTIVE_KEYS`, `PROBOT_PARITY_KEYS`, `UndeclaredPolicy`, `UndeclaredPolicyList`, `MustBeNever` | `./internal`; `UNDECLARED_POLICY_SECTIONS` and `UndeclaredPolicySection` stay public |
168168
| `denialPosture`, `readGating`, `writeGatedReads`, `sectionOperations`, `SectionMeta`, `KeyedListLayering`, `grantFor`, `PatResource`, `SectionPermission` | `./internal` |
169169
| `Justification`, `PlannedOpBase`, `Tolerance`, `Unverifiable` | `./internal` |
170170
| `concludeSnapshot` set `repos-result` only in the dir form; `concludeMerge` set no `repos-result` | Every conclude sets the three outputs |
171171
| `FinishedSnapshot` carried `view` / `views`: each target already projected into a `SnapshotTargetView` | `FinishedSnapshot` carries `target` / `targets`: each a `TargetOutcome` whose `detail` is sealed for a hidden target; `concludeSnapshot` opens it through `publicDetail` / `toPublicView` |
172-
| `SnapshotTargetView` (snapshot's own public projection) | Removed; the public shape of every mode's target is `PublicTargetView`, which now carries the snapshot `file` |
172+
| `SnapshotTargetView` (snapshot's own redacted projection) | Removed; the shared redaction-safe projection is `PublicTargetView` in `./internal`, which now carries the snapshot `file` |
173173

174174
## 10. One redacted label in every mode
175175

‎src/index.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,13 @@ export {
104104
} from "./report/artifact-report.js";
105105
export { composeReport, type ReportInput } from "./report/composer.js";
106106
export { openReportChannel, type PrivateReportChannel } from "./report/delivery.js";
107-
export { SECTION_KEYS, type SectionKey, SettingsFile } from "./schema.js";
107+
export {
108+
SECTION_KEYS,
109+
type SectionKey,
110+
SettingsFile,
111+
UNDECLARED_POLICY_SECTIONS,
112+
type UndeclaredPolicySection,
113+
} from "./schema.js";
108114
export {
109115
type EndpointDecl,
110116
endpointMethod,

‎src/internal.ts‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,7 @@ export {
8585
PRIVATE_REPORT_CHANNELS,
8686
} from "./report/delivery.js";
8787
export { ISSUE_TITLE, MARKER_LABEL, MARKER_LABEL_CONFIG } from "./report/issue-report.js";
88-
export {
89-
DOCUMENT_DIRECTIVE_KEYS,
90-
PROBOT_PARITY_KEYS,
91-
UNDECLARED_POLICY_SECTIONS,
92-
type UndeclaredPolicySection,
93-
} from "./schema.js";
88+
export { DOCUMENT_DIRECTIVE_KEYS, PROBOT_PARITY_KEYS } from "./schema.js";
9489
export {
9590
denialPosture,
9691
type KeyedListLayering,

‎test/library/public-surface.test.ts‎

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,39 @@ export function documentedNames(markdown: string): string[] {
5959
if (start < 0) {
6060
throw new Error(`${PAGE} has no "${API_HEADING}" heading`);
6161
}
62-
const section = lines.slice(start + 1).map((raw) => raw.trim());
62+
// A line as GFM reads it: its blockquote depth (a marker is `>` plus any spaces, nested markers stack) and the text under the markers.
63+
const section = lines.slice(start + 1).map((raw) => {
64+
let text = raw.trim();
65+
let depth = 0;
66+
for (let marker = text.match(/^>\s*/); marker; marker = text.match(/^>\s*/)) {
67+
depth++;
68+
text = text.slice(marker[0].length);
69+
}
70+
return { depth, text: text.trim() };
71+
});
6372
const names: string[] = [];
6473
let inNameTable = false;
65-
for (const [offset, line] of section.entries()) {
74+
// The open fence: its mark and the quote depth it opened at. A closer is the whole line at that depth; a `>` line
75+
// inside a fence at depth 0 is fence text, and so is a table. A line below the fence's depth ends the blockquote,
76+
// and the fence with it.
77+
let fence: { mark: string; depth: number } | null = null;
78+
for (const [offset, { depth, text: line }] of section.entries()) {
79+
// A backtick fence's info string carries no backtick, so a triple-backtick inline span is not an opener.
80+
const opener = line.match(/^(`{3,})(?![^`]*`)|^(~{3,})/)?.[0];
81+
if (fence !== null && depth < fence.depth) {
82+
fence = null;
83+
}
84+
if (fence !== null) {
85+
if (depth === fence.depth && line.startsWith(fence.mark) && /^(`+|~+)$/.test(line)) {
86+
fence = null;
87+
}
88+
continue;
89+
}
90+
if (opener !== undefined) {
91+
fence = { mark: opener, depth };
92+
inNameTable = false;
93+
continue;
94+
}
6695
if (line.startsWith("## ")) {
6796
break;
6897
}
@@ -71,14 +100,14 @@ export function documentedNames(markdown: string): string[] {
71100
continue;
72101
}
73102
if (!inNameTable) {
74-
if (NAME_TABLE_HEADER.test(line) && DELIMITER_ROW.test(section[offset + 1] ?? "")) {
103+
if (NAME_TABLE_HEADER.test(line) && DELIMITER_ROW.test(section[offset + 1]?.text ?? "")) {
75104
inNameTable = true;
76105
}
77106
continue;
78107
}
79108
if (
80109
offset > 0 &&
81-
NAME_TABLE_HEADER.test(section[offset - 1] ?? "") &&
110+
NAME_TABLE_HEADER.test(section[offset - 1]?.text ?? "") &&
82111
DELIMITER_ROW.test(line)
83112
) {
84113
continue;
@@ -147,6 +176,27 @@ describe("the public entry", () => {
147176
expect(documentedNames(afterSection)).toEqual(documentedNames(page));
148177
});
149178

179+
// A fence shows its text; a table inside one renders as code, so it is not a documented name.
180+
const FENCED_TABLE =
181+
"| Name | Kind | Says |\n|---|---|---|\n| `notExported` | function | Fenced |";
182+
test.each([
183+
["a backtick fence", `\`\`\`md\n${FENCED_TABLE}\n\`\`\``],
184+
["a tilde fence", `~~~\n${FENCED_TABLE}\n~~~`],
185+
["a fence whose body opens another fence", `\`\`\`md\n\`\`\`ts\n${FENCED_TABLE}\n\n\`\`\``],
186+
[
187+
"a fence inside a blockquote",
188+
`> \`\`\`md\n> ${FENCED_TABLE.replaceAll("\n", "\n> ")}\n>\n> \`\`\``,
189+
],
190+
[
191+
"a fence whose body quotes a closed fence",
192+
`\`\`\`md\n> \`\`\`ts\n> const example = 1;\n> \`\`\`\n\n${FENCED_TABLE}\n\n\`\`\``,
193+
],
194+
])("%s holds shown text, not a documented name (negative control)", (_form, block) => {
195+
const fenced = page.replace("### Io\n", `### Io\n\n${block}\n\n`);
196+
expect(fenced).not.toBe(page);
197+
expect(documentedNames(fenced)).toEqual(documentedNames(page));
198+
});
199+
150200
// Every table form GFM renders is read, so a row cannot escape the pin by its spelling.
151201
test.each([
152202
[
@@ -169,10 +219,36 @@ describe("the public entry", () => {
169219
"### Io\n",
170220
"### Io\n\nName | Kind | Says\n--- | --- | ---\n`notExported` | function | Extra\n\n",
171221
],
222+
[
223+
"a table inside a blockquote",
224+
"### Io\n",
225+
"### Io\n\n> | Name | Kind | Says |\n> |---|---|---|\n> | `notExported` | function | Quoted |\n\n",
226+
],
227+
[
228+
"a table inside a nested blockquote",
229+
"### Io\n",
230+
"### Io\n\n> > | Name | Kind | Says |\n> > |---|---|---|\n> > | `notExported` | function | Quoted |\n\n",
231+
],
232+
[
233+
"a table inside a nested blockquote whose markers are spaced apart",
234+
"### Io\n",
235+
"### Io\n\n> > | Name | Kind | Says |\n> > |---|---|---|\n> > | `notExported` | function | Quoted |\n\n",
236+
],
237+
[
238+
"a table after a quoted fence its blockquote ended without a closer",
239+
"### Io\n",
240+
"### Io\n\n> ```md\n> example\n\n| Name | Kind | Says |\n|---|---|---|\n| `notExported` | function | Extra |\n\n",
241+
],
242+
[
243+
"a table after a triple-backtick inline span, which opens no fence",
244+
"### Io\n",
245+
"### Io\n\n```an inline `code` span```\n\n| Name | Kind | Says |\n|---|---|---|\n| `notExported` | function | Extra |\n\n",
246+
],
172247
])("%s is read as a documented name (negative control)", (_form, anchor, replacement) => {
173248
const variant = page.replace(anchor, replacement);
174249
expect(variant).not.toBe(page);
175250
expect(documentedNames(variant)).toEqual([...documentedNames(page), "notExported"].sort());
251+
expect(documentedNames(variant)).not.toEqual(exportedNames(ENTRY, entry));
176252
});
177253

178254
test("a star re-export is refused, since it pins no names (negative control)", () => {

0 commit comments

Comments
 (0)