Skip to content

Commit 900dc7f

Browse files
committed
test(help): read the startup reason union from the vertical reason list too
The STE rewrite of the CLI help moved the startup reason enumeration from one sentence into the vertical list under the "iOS runner startup reasons" heading (STE rule: vertical lists for more than 3 items). The guard found only the first line naming error.details.reason, which now carries no reason names, so Coverage failed the union check on cli-help.ts. Read the enumeration from either shape: the STE list block under its heading, or the sentence naming error.details.reason. Keep the check scoped to that block, never the whole file, and assert the list is not shorter than the union so a shrinking enumeration still fails.
1 parent 26e696d commit 900dc7f

1 file changed

Lines changed: 36 additions & 10 deletions

File tree

‎test/repo-guards/runner-startup-reason-docs.test.ts‎

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,20 @@ const cliHelpPath = path.join(repoRoot, 'src/commands/schema/cli-help.ts');
2323
/** The two reasons the device reports about itself, spread into the startup union. */
2424
const DEVICE_READINESS_MEMBERS = 'RUNNER_DEVICE_READINESS_FAILURE_REASONS';
2525

26+
/** The heading of the vertical reason list, as the STE rewrite of the CLI help writes it. */
27+
const STARTUP_REASONS_HEADING = /^iOS runner startup reasons \(details\.reason\):$/;
28+
2629
test('the runner startup reason union is documented in full at both prose surfaces', () => {
2730
const reasons = startupFailureReasons();
2831

29-
for (const { surface, line } of [
30-
{ surface: 'installation.md', line: startupReasonSentence(readFile(installationDocPath)) },
31-
{ surface: 'cli-help.ts', line: startupReasonSentence(readFile(cliHelpPath)) },
32+
for (const { surface, text } of [
33+
{ surface: 'installation.md', text: readFile(installationDocPath) },
34+
{ surface: 'cli-help.ts', text: readFile(cliHelpPath) },
3235
]) {
36+
const enumeration = startupReasonEnumeration(text, reasons, surface);
3337
for (const reason of reasons) {
3438
assert.ok(
35-
line.includes(reason),
39+
enumeration.includes(reason),
3640
`${surface} must document the ${reason} reason: the union in ` +
3741
`${path.relative(repoRoot, classificationPath)} publishes it and a client cannot branch on ` +
3842
'a value it was never told exists.',
@@ -74,12 +78,34 @@ function literalMembers(source: string, name: string): string[] {
7478
);
7579
}
7680

77-
/** The sentence that enumerates the startup reasons, found on the same line at both surfaces. */
78-
function startupReasonSentence(text: string): string {
79-
const line = text
80-
.split('\n')
81-
.find((candidate) => /error details\.reason|`error\.details\.reason`/.test(candidate));
82-
assert.ok(line, 'no sentence enumerating error.details.reason was found');
81+
/**
82+
* The enumeration of the startup reasons on one prose surface: either the STE vertical list
83+
* under the "iOS runner startup reasons" heading, or the single sentence that names
84+
* `error.details.reason`. The block is scoped to the list or the sentence, never the whole
85+
* file, so a reason named only in unrelated prose cannot satisfy the guard.
86+
*/
87+
function startupReasonEnumeration(text: string, reasons: string[], surface: string): string {
88+
const lines = text.split('\n');
89+
const heading = lines.findIndex((line) => STARTUP_REASONS_HEADING.test(line.trim()));
90+
if (heading !== -1) {
91+
const block: string[] = [];
92+
for (const line of lines.slice(heading + 1)) {
93+
if (line.trim() === '') {
94+
break;
95+
}
96+
block.push(line);
97+
}
98+
assert.ok(
99+
block.length >= reasons.length,
100+
`${surface}: the list under "${STARTUP_REASONS_HEADING.source}" lists fewer entries than ` +
101+
`the ${reasons.length} reasons the union publishes; the enumeration must not shrink.`,
102+
);
103+
return block.join('\n');
104+
}
105+
const line = lines.find((candidate) =>
106+
/error details\.reason|`error\.details\.reason`/.test(candidate),
107+
);
108+
assert.ok(line, `no startup-reason enumeration was found at ${surface}`);
83109
return line;
84110
}
85111

0 commit comments

Comments
 (0)