Skip to content

Visual Studio Code, rebuilt in Rust

Rust

fix(port): word the README coverage block with no open parts

rokartur1901206f75c4
diff --git a/port/tools/readme-coverage.test.ts b/port/tools/readme-coverage.test.ts
new file mode 100644
index 00000000000..c901981ae87
--- /dev/null
+++ b/port/tools/readme-coverage.test.ts
@@ -0,0 +1,35 @@
+import { expect, test } from 'bun:test';
+import { cpSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+
+function coverageBlock(units: string[]) {
+ const root = mkdtempSync(join(tmpdir(), 'readme-coverage-test-'));
+ mkdirSync(join(root, 'port/tools'), { recursive: true });
+ mkdirSync(join(root, 'upstream'));
+ for (const file of ['readme-coverage.ts', 'vscode-src.ts']) {
+ cpSync(join(import.meta.dir, file), join(root, 'port/tools', file));
+ }
+ writeFileSync(join(root, 'upstream/package.json'), '{"version": "1.148.0"}');
+ writeFileSync(join(root, 'README.md'), '<!-- coverage:start -->\n<!-- coverage:end -->\n');
+ writeFileSync(join(root, 'port/ledger.md'), ['# Port ledger', '', '## Units', '', '| unit | area | milestone | status | gaps | check |', '|---|---|---|---|---|---|', ...units].join('\n'));
+ const run = Bun.spawnSync(['bun', join(root, 'port/tools/readme-coverage.ts')], { env: { ...process.env, VSCODE_SRC: 'upstream' } });
+ expect(run.exitCode).toBe(0);
+ const readme = readFileSync(join(root, 'README.md'), 'utf8');
+ rmSync(root, { recursive: true });
+ return readme;
+}
+
+test('with every covered part verified, the block names no open parts', () => {
+ const readme = coverageBlock(['| a | port feature | M1 | verified | | check |', '| b | port feature | | removed | | why |']);
+ expect(readme).toContain('**1 of the 1 parts of VS Code 1.148.0 the port covers match upstream 1:1 (100%).** 1 more are left out on purpose.');
+ expect(readme).toContain('No part works with open gaps.');
+ expect(readme).not.toContain('The other 0');
+ expect(readme).not.toMatch(/\n\.\n/);
+});
+
+test('an open part is listed with its gap count', () => {
+ const readme = coverageBlock(['| a | port feature | M1 | verified | | check |', '| b | port feature | M1 | ported | [x S] | check |']);
+ expect(readme).toContain('The other one works, with open gaps listed below.');
+ expect(readme).toContain('`b` 1.');
+});
diff --git a/port/tools/readme-coverage.ts b/port/tools/readme-coverage.ts
index 2bd546cae59..95df5f5da75 100755
--- a/port/tools/readme-coverage.ts
+++ b/port/tools/readme-coverage.ts
@@ -61,7 +61,7 @@ const bar = (c: typeof total) => {
};
const lines = [
- `**${total.verified} of the ${inScope(total)} parts of VS Code ${version} the port covers match upstream 1:1 (${percent(total)}%).** ${inScope(total) - total.verified === 1 ? 'The other one works' : `The other ${inScope(total) - total.verified} work`}, with open gaps listed below. ${leftOut(total)} more are left out on purpose. A part is one upstream folder: a feature, a service or a built-in extension, counted from [port/ledger.md](port/ledger.md).`,
+ `**${total.verified} of the ${inScope(total)} parts of VS Code ${version} the port covers match upstream 1:1 (${percent(total)}%).** ${otherParts(inScope(total) - total.verified)}${leftOut(total)} more are left out on purpose. A part is one upstream folder: a feature, a service or a built-in extension, counted from [port/ledger.md](port/ledger.md).`,
'',
'```mermaid',
`%%{init: {"theme": "base", "themeVariables": {"pie1": "#2da44e", "pie2": "#d4a72c", "pie3": "#8c959f", "pieStrokeColor": "#ffffff", "pieOuterStrokeColor": "#ffffff", "pieSectionTextColor": "#ffffff", "pieLegendTextColor": "#8c959f", "pieTitleTextColor": "#8c959f"}}}%%`,
@@ -80,9 +80,12 @@ for (const [area, c] of [...areas].sort((a, b) => inScope(b[1]) + leftOut(b[1])
lines.push(`| ${areaNames[area]} | ${c.verified} | ${inScope(c) - c.verified} | ${leftOut(c)} | ${bar(c)} |`);
}
lines.push(`| **All** | **${total.verified}** | **${inScope(total) - total.verified}** | **${leftOut(total)}** | ${bar(total)} |`);
-lines.push('', '"Matches 1:1" means upstream\'s tests or a named check against VS Code pass. Parts that work with open gaps, by gap count:', '');
+lines.push('', '"Matches 1:1" means upstream\'s tests or a named check against VS Code pass. ' + (openRows.length === 0 ? 'No part works with open gaps.' : 'Parts that work with open gaps, by gap count:'));
openRows.sort((a, b) => b.gaps - a.gaps || a.id.localeCompare(b.id));
-lines.push(openRows.map(row => `\`${row.id}\` ${row.gaps}`).join(', ') + '.', '', '</details>');
+if (openRows.length > 0) {
+ lines.push('', openRows.map(row => `\`${row.id}\` ${row.gaps}`).join(', ') + '.');
+}
+lines.push('', '</details>');
const readmePath = join(root, 'README.md');
const readme = readFileSync(readmePath, 'utf8');
@@ -92,3 +95,10 @@ if (!readme.includes(start) || !readme.includes(end)) {
throw new Error(`README.md has no ${start} ... ${end} block`);
}
writeFileSync(readmePath, readme.slice(0, readme.indexOf(start) + start.length) + '\n' + lines.join('\n') + '\n' + readme.slice(readme.indexOf(end)));
+
+function otherParts(count: number) {
+ if (count === 0) {
+ return '';
+ }
+ return `${count === 1 ? 'The other one works' : `The other ${count} work`}, with open gaps listed below. `;
+}