Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

ci: the contract job plans six of its eight minutes; a test file is not a shared style (#10322)

Cindy Zhang06e392baf62c
diff --git a/.github/scripts/a11y-pr-contracts.mjs b/.github/scripts/a11y-pr-contracts.mjs
index aac9d378ab..b213d32737 100644
--- a/.github/scripts/a11y-pr-contracts.mjs
+++ b/.github/scripts/a11y-pr-contracts.mjs
@@ -52,8 +52,9 @@
* first), in the time left. It reads no title and runs no component audit; a
* changed `audit` spec still waits for its audit pull request. To stay inside the job's 15-minute budget
* it takes at most CHANGED_SPEC_LIMIT changed files, starts each file only
- * when the run still fits DEFAULT_CHECK_BUDGET_MS at that file's recorded time
- * (.github/a11y-contract-durations.json), and stops at that budget. Each file
+ * when the run still fits PLAN_BUDGET_MS at that file's recorded time
+ * (.github/a11y-contract-durations.json), and stops at
+ * DEFAULT_CHECK_BUDGET_MS. Each file
* it leaves out is reported as not run, never as passed or failed. Locally,
* `pnpm test:a11y-contract:pr origin/main --dry-run` prints what a PR from
* this branch would run.
@@ -316,6 +317,14 @@ export const CHANGED_SPEC_LIMIT = 4;
/** The default check's wall-clock bound, inside the job's 15 minutes. */
export const DEFAULT_CHECK_BUDGET_MS = 8 * 60 * 1000;
+/**
+ * The time the default check plans: three quarters of its stop. A
+ * pull-request runner can run a file slower than its recorded time even with
+ * the margin, and a file that the stop cuts fails the run, so the plan keeps
+ * the last quarter free.
+ */
+export const PLAN_BUDGET_MS = 6 * 60 * 1000;
+
/**
* The times come from the release legs. A pull-request runner can be slower,
* and a file that the budget stops fails the run. Thus the plan adds a margin
@@ -703,7 +712,7 @@ export function planDefaultCheck({
dependents = [],
seconds,
workers,
- budgetMs = DEFAULT_CHECK_BUDGET_MS,
+ budgetMs = PLAN_BUDGET_MS,
dependentShareMs = DEPENDENT_SHARE_MS,
}) {
const {run: changedInLimit, notRun} = withinBudget(changed);
@@ -725,7 +734,7 @@ export function planDefaultCheck({
if (STARTUP_MS + projectedMs(withFile, msOf, workers) > budgetMs) {
notRun.push({
file: entry.file,
- reason: `${entry.reason}; its expected ${Math.round(secondsOf(entry.file))} s does not fit the default check's ${budgetMs / 60000}-minute budget; add ci:run-a11y to run it`,
+ reason: `${entry.reason}; its expected ${Math.round(secondsOf(entry.file))} s does not fit the default check's ${budgetMs / 60000}-minute plan; add ci:run-a11y to run it`,
});
} else if (!fits(withFile)) {
notRun.push({
diff --git a/.github/scripts/a11y-pr-contracts.test.mjs b/.github/scripts/a11y-pr-contracts.test.mjs
index 7d2004b556..c2bfde17d8 100644
--- a/.github/scripts/a11y-pr-contracts.test.mjs
+++ b/.github/scripts/a11y-pr-contracts.test.mjs
@@ -27,6 +27,7 @@ import {
changedOnly,
changedSinceMergeBase,
DEFAULT_CHECK_BUDGET_MS,
+ PLAN_BUDGET_MS,
DEPENDENT_SHARE_MS,
dependentSpecs,
importerGraph,
@@ -302,14 +303,57 @@ describe('the default check of the touched components', () => {
expect(owns(['core/Switch'], [], [tokened])).toEqual([]);
});
- it('runs every owned file that fits the budget at its recorded time', () => {
+ it('runs every owned file that fits the plan at its recorded time', () => {
expect(plan(['core/Switch'])).toEqual({
run: [{file: SWITCH, reason: 'component core/Switch'}],
notRun: [],
});
- expect(files(plan(['core/Selector']).run).sort()).toEqual(
- [COMBOBOX_FIELD, LISTBOX].sort(),
+ // Listbox's 325 s, with the margin and startup, passes the 6-minute plan.
+ const selector = plan(['core/Selector']);
+ expect(files(selector.run)).toEqual([COMBOBOX_FIELD]);
+ expect(files(selector.notRun)).toEqual([LISTBOX]);
+ });
+
+ it('plans three quarters of the stop, so a slower runner still finishes every file it starts', () => {
+ expect(PLAN_BUDGET_MS).toBe(DEFAULT_CHECK_BUDGET_MS * 0.75);
+ // One pull request's changed and owned specs, at the times recorded when
+ // the plan filled the whole 8 minutes and the stop cut Listbox (7 minutes
+ // on that runner). A file with no recorded time has the median then, 17.3 s.
+ const recorded = {
+ 'packages/core/src/Selector/__tests__/SelectorKeyboardInset.a11y.chromium.spec.ts': 17.3,
+ 'packages/core/src/__tests__/FocusRingOwner.a11y.chromium.spec.ts': 17.3,
+ 'packages/core/src/DropdownMenu/__tests__/DropdownMenuTooltip.a11y.chromium.spec.ts': 17.3,
+ 'packages/core/src/Field/__tests__/FieldDisabledForcedColorsFocus.a11y.chromium.spec.ts': 17.3,
+ 'packages/core/src/Layer/__tests__/BackdropPress.a11y.chromium.spec.ts': 17.3,
+ 'packages/core/src/Layer/__tests__/LayerBrowserHide.a11y.chromium.spec.ts': 5.3,
+ 'packages/core/src/Selector/__tests__/ComboboxField.a11y.chromium.spec.ts': 38.2,
+ 'packages/core/src/Selector/__tests__/Listbox.a11y.chromium.spec.ts': 325.2,
+ 'packages/core/src/Selector/__tests__/Selector.a11y.chromium.spec.ts': 1.7,
+ 'packages/core/src/Selector/__tests__/Selector.combobox.a11y.chromium.spec.ts': 12.3,
+ 'packages/core/src/Selector/__tests__/SelectorListboxName.a11y.chromium.spec.ts': 17.3,
+ 'packages/core/src/Selector/__tests__/SelectorReducedMotion.a11y.chromium.spec.ts': 17.3,
+ };
+ const changedAndOwned = Object.keys(recorded);
+ const {run, notRun} = planDefaultCheck({
+ changed: [{file: changedAndOwned[0], reason: 'spec changed'}],
+ owned: changedAndOwned.slice(1).map(file => ({
+ file,
+ reason: 'changed packages/core/src/Selector/Selector.test.tsx',
+ })),
+ seconds: recorded,
+ workers: 4,
+ });
+ const msOf = file => recorded[file] * 1000 * RECORDED_TIME_MARGIN;
+ expect(STARTUP_MS + projectedMs(files(run), msOf, 4)).toBeLessThanOrEqual(
+ PLAN_BUDGET_MS,
+ );
+ expect(files(notRun)).toContain(
+ 'packages/core/src/Selector/__tests__/Listbox.a11y.chromium.spec.ts',
);
+ expect(
+ notRun.find(({file}) => file.endsWith('Listbox.a11y.chromium.spec.ts'))
+ .reason,
+ ).toContain('6-minute plan');
});
it('reports a file that does not fit as not run, with the label that runs it', () => {
@@ -320,9 +364,11 @@ describe('the default check of the touched components', () => {
expect(files(notRun)).toEqual([LISTBOX]);
expect(notRun[0].reason).toContain('component core/Selector');
expect(notRun[0].reason).toContain('ci:run-a11y');
- expect(notRun[0].reason).toContain('8-minute budget');
- // On four workers they run side by side.
- expect(plan(['core/Selector', 'core/Switch']).notRun).toEqual([]);
+ expect(notRun[0].reason).toContain('6-minute plan');
+ // On four workers the others run side by side; Listbox alone passes the plan.
+ expect(files(plan(['core/Selector', 'core/Switch']).notRun)).toEqual([
+ LISTBOX,
+ ]);
});
it('never starts a file that the recorded time says the stop would cut', () => {
@@ -343,19 +389,31 @@ describe('the default check of the touched components', () => {
);
});
- it('runs changed specs first and counts them against the budget, without running a file twice', () => {
- expect(plan(['core/Selector'], [LISTBOX])).toEqual({
+ it('runs changed specs first and counts them against the plan, without running a file twice', () => {
+ const later =
+ 'packages/core/src/Switch/__tests__/SwitchLater.a11y.chromium.spec.ts';
+ const check = workers =>
+ planDefaultCheck({
+ changed: [{file: SWITCH, reason: 'spec changed'}],
+ owned: [
+ {file: SWITCH, reason: 'component core/Switch'},
+ {file: later, reason: 'component core/Switch'},
+ ],
+ seconds: {...seconds, [later]: 120},
+ workers,
+ });
+ expect(check(4)).toEqual({
run: [
- {file: LISTBOX, reason: 'spec changed'},
- {file: COMBOBOX_FIELD, reason: 'component core/Selector'},
+ {file: SWITCH, reason: 'spec changed'},
+ {file: later, reason: 'component core/Switch'},
],
notRun: [],
});
- // On one worker, ComboboxField after the changed Listbox passes the
- // budget: 30 + (325.2 + 38.2) * 1.25 s.
- const {run, notRun} = plan(['core/Selector'], [LISTBOX], 1);
- expect(run).toEqual([{file: LISTBOX, reason: 'spec changed'}]);
- expect(files(notRun)).toEqual([COMBOBOX_FIELD]);
+ // On one worker, the later file after the changed Switch passes the
+ // plan: 30 + (168.4 + 120) * 1.25 s is more than 6 minutes.
+ const {run, notRun} = check(1);
+ expect(run).toEqual([{file: SWITCH, reason: 'spec changed'}]);
+ expect(files(notRun)).toEqual([later]);
});
it('reports a changed spec that does not fit as not run, never starts it', () => {
diff --git a/.github/scripts/touched-components.mjs b/.github/scripts/touched-components.mjs
index 3c28696f79..b4d6be8758 100644
--- a/.github/scripts/touched-components.mjs
+++ b/.github/scripts/touched-components.mjs
@@ -50,9 +50,15 @@ const FOUNDATION_PATTERNS = [
/** A Storybook story file. */
export const STORY_FILE = /\.stories\.(?:[cm]?[jt]sx?|mdx)$/;
+// Tests, stories, docs and notes in a foundation folder style nothing.
+const NOT_A_STYLE =
+ /(?:^|\/)__tests__\/|\.(?:test|spec|stories|doc)\.[^/]+$|\.md$/;
+
export function foundationChanges(files) {
- return files.filter(file =>
- FOUNDATION_PATTERNS.some(pattern => pattern.test(file)),
+ return files.filter(
+ file =>
+ !NOT_A_STYLE.test(file) &&
+ FOUNDATION_PATTERNS.some(pattern => pattern.test(file)),
);
}
diff --git a/.github/scripts/touched-components.test.mjs b/.github/scripts/touched-components.test.mjs
index 1591c40c37..bd7e00cf04 100644
--- a/.github/scripts/touched-components.test.mjs
+++ b/.github/scripts/touched-components.test.mjs
@@ -223,6 +223,27 @@ describe('wide changes', () => {
expect(decideWideChange(owners(1), behaviour).wideChange).toBe(false);
});
+ it('never counts a test, story, doc or note in a foundation folder as a shared style', () => {
+ const notStyles = [
+ 'packages/core/src/theme/derivedVarRegistry.test.ts',
+ 'packages/core/src/theme/__tests__/themingTargets.test.ts',
+ 'packages/themes/neutral/src/__tests__/neutralTheme.test.ts',
+ 'packages/themes/neutral/src/neutralTheme.stories.tsx',
+ 'packages/core/src/theme/theme.doc.mjs',
+ 'packages/themes/neutral/README.md',
+ 'packages/core/src/Layer/__tests__/layer.stylex.test.ts',
+ ];
+ expect(foundationChanges(notStyles)).toEqual([]);
+ expect(decideWideChange(owners(2), notStyles).wideChange).toBe(false);
+ // A real foundation beside them still makes the change wide.
+ expect(
+ decideWideChange(owners(2), [
+ ...notStyles,
+ 'packages/core/src/theme/tokens.stylex.ts',
+ ]).wideChange,
+ ).toBe(true);
+ });
+
it('writes a skipped visual verdict for a wide change, carrying the run identity', () => {
const verdict = wideVisualVerdict(
{componentCount: 7},
diff --git a/docs/specs/AST-030/spec.md b/docs/specs/AST-030/spec.md
index ad3487ea1f..86f1a1e715 100644
--- a/docs/specs/AST-030/spec.md
+++ b/docs/specs/AST-030/spec.md
@@ -253,9 +253,10 @@ they are separately named.
MUST NOT become the pull request's critical path: it starts after the
Storybook build and MUST finish before the slowest unit-test job, so the
time until the required `test` join reports does not grow. It stops after
- eight minutes: it starts a file only when that file's recorded duration fits
- the time left. A contract file that cannot finish within the budget is
- reported as not run, not split. Each file it does not run, for that budget
+ eight minutes and plans six of them: it starts a file only when that file's
+ recorded duration fits what is left of those six, so a runner up to a third
+ slower than the plan still finishes every file it starts. A contract file
+ that cannot finish within the budget is reported as not run, not split. Each file it does not run, for that budget
or the four-file limit, is reported as not run in the check's summary and
annotations, with the label that runs it. A spec that starts and does not
finish fails. A failing contract fails the required `test` join (FR7) and