Repository navigation
test: the Node legs cost each swizzle-proof slice by the targets it holds that the change can affect #11716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
test: the Node legs cost each swizzle-proof slice by the targets it holds that the change can affect #11716
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
|
||
| /** | ||
| * @file bound-worker.mjs | ||
| * @input workerData `{relevant, count}`: the change's component source files | ||
| * and the number of slices | ||
| * @output Two messages: `{listed: true}` once the targets are listed, then | ||
| * `{held}`: for each slice, how many of its targets ({@link sliceOf}) the | ||
| * change can affect ({@link affectedBound}) | ||
| * @position Run in a worker by scripts/vitest-shard-sequencer.mjs, so the | ||
| * Node legs' split can stop waiting at its time budget | ||
| */ | ||
|
|
||
| import fs from 'node:fs'; | ||
| import os from 'node:os'; | ||
| import path from 'node:path'; | ||
| import {parentPort, workerData} from 'node:worker_threads'; | ||
|
|
||
| import {affectedBound, createProject, listTargets, sliceOf} from './proof.mjs'; | ||
|
|
||
| const project = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-swizzle-bound-')); | ||
| try { | ||
| createProject(project); | ||
| const targets = await listTargets(project); | ||
| parentPort?.postMessage({listed: true}); | ||
| const affected = affectedBound(targets, workerData.relevant); | ||
| parentPort?.postMessage({ | ||
| held: Array.from( | ||
| {length: workerData.count}, | ||
| (_, index) => | ||
| sliceOf(targets, index, workerData.count).filter(t => | ||
| affected.has(t.key), | ||
| ).length, | ||
| ), | ||
| }); | ||
| } finally { | ||
| fs.rmSync(project, {recursive: true, force: true}); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| // Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
|
||
| /** | ||
| * @file bound.test.mjs | ||
| * @input Real swizzle copies of a few targets, and changes to a component, a | ||
| * shared helper, a layer helper, the theme tokens and a Lab component | ||
| * @output Proves the Node legs' affected bound (proof.mjs affectedBound) | ||
| * holds every target the slices prove (exactAffected), so the split never | ||
| * costs a slice below its work; and logs how long the split's bound takes | ||
| * @position Node test of proof.mjs's bound, beside the swizzle-proof slices | ||
| */ | ||
|
|
||
| import fs from 'node:fs'; | ||
| import os from 'node:os'; | ||
| import path from 'node:path'; | ||
| import {afterAll, beforeAll, describe, expect, it} from 'vitest'; | ||
|
|
||
| import {boundWithin} from '../../../../scripts/vitest-shard-sequencer.mjs'; | ||
| import { | ||
| affectedBound, | ||
| createProject, | ||
| eject, | ||
| exactAffected, | ||
| listTargets, | ||
| } from './proof.mjs'; | ||
|
|
||
| /** | ||
| * Targets of every kind of folder: a component folder (Core), a flat | ||
| * package (Charts, Rich Text), a shared folder (Lab's Chart), a folder of | ||
| * modules (Layer), and a leaf (Lab's DialogHeroHeader). | ||
| */ | ||
| const KEYS = [ | ||
| 'core__Button', | ||
| 'core__Badge', | ||
| 'core__Dialog', | ||
| 'core__Layer', | ||
| 'charts__ChartAxis', | ||
| 'lab__ChartArea', | ||
| 'lab__DialogHeroHeader', | ||
| 'richtext__RichTextEditorAutoLinkPlugin', | ||
| 'vega__VegaChart', | ||
| ]; | ||
|
|
||
| const CHANGES = [ | ||
| ['a component', ['packages/core/src/Button/Button.tsx']], | ||
| ['a press helper', ['packages/core/src/utils/pressClaim.ts']], | ||
| ['a layer helper', ['packages/core/src/Layer/inputHold.ts']], | ||
| ['the theme tokens', ['packages/core/src/theme/tokens.stylex.ts']], | ||
| [ | ||
| 'a Lab component', | ||
| ['packages/lab/src/DialogHeroHeader/DialogHeroHeader.tsx'], | ||
| ], | ||
| ]; | ||
|
|
||
| describe('the Node legs’ affected bound', () => { | ||
| /** @type {Array<{name: string, pkg: string, key: string}>} */ | ||
| let targets = []; | ||
| /** @type {Map<string, any>} */ | ||
| const ejected = new Map(); | ||
| /** One set of caches for every change, as the same copies are read each time. */ | ||
| const caches = {}; | ||
| const project = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-bound-')); | ||
|
|
||
| beforeAll(async () => { | ||
| createProject(project); | ||
| targets = (await listTargets(project)).filter(t => KEYS.includes(t.key)); | ||
| await eject(targets, project, ejected, () => {}); | ||
| }, 300_000); | ||
|
|
||
| afterAll(() => { | ||
| fs.rmSync(project, {recursive: true, force: true}); | ||
| }); | ||
|
|
||
| it('copies every chosen target', () => { | ||
| expect(targets.map(t => t.key).sort()).toEqual([...KEYS].sort()); | ||
| expect(ejected.size).toBe(KEYS.length); | ||
| }); | ||
|
|
||
| it.each(CHANGES)( | ||
| 'holds every target the slices prove for a change to %s', | ||
| (_change, relevant) => { | ||
| const exact = exactAffected(targets, ejected, relevant, caches).map( | ||
| t => t.key, | ||
| ); | ||
| const bound = affectedBound(targets, relevant); | ||
| expect(exact.filter(key => !bound.has(key))).toEqual([]); | ||
| }, | ||
| ); | ||
|
|
||
| it('is not every target: a component change reaches some, and a Lab leaf almost none', () => { | ||
| expect( | ||
| exactAffected(targets, ejected, CHANGES[0][1], caches).length, | ||
| ).toBeGreaterThan(0); | ||
| expect(affectedBound(targets, CHANGES[4][1]).size).toBeLessThan(3); | ||
| }); | ||
|
|
||
| it('counts each slice’s affected targets in a worker, within its budget or not at all', async () => { | ||
| const started = Date.now(); | ||
| const held = await boundWithin(CHANGES[0][1], 8); | ||
| const elapsed = Date.now() - started; | ||
| // The machine's own time, for the record of what the split spends. | ||
| console.log( | ||
| `SWIZZLE_BOUND ${JSON.stringify({ms: elapsed, held, cpus: os.availableParallelism()})}`, | ||
| ); | ||
| if (held !== null) { | ||
| expect(held).toHaveLength(8); | ||
| expect(held.every(n => Number.isInteger(n) && n >= 0)).toBe(true); | ||
| } | ||
| }, 60_000); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One malformed line throws here and fails the leg's drift step with a stack trace.
swizzleSamplesinscripts/lib/swizzle-cost.mjsalready skips a line it cannot parse and keeps only samples whoseaffectedandtotalMsare finite; without that check a line that parses but carries nototalMsalso reachesslowSlices, where theNaNcomparisons drop it silently. Reuse that reader's validation for the JSONL file.