Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/test/snapshots/.mocharc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
const getFluidTestMochaConfig = require("@fluid-internal/mocha-test-setup/mocharc-common");

const config = getFluidTestMochaConfig(__dirname);
config.ignore = config.spec + "/generate/**/*";
// These tests need to be run with multiple different test file filters for different "test" cases.
// It's simplest to just let the individual scripts specify what they need and disable the default.
delete config.spec;
// TODO: figure out why this package needs the --exit flag, tests might not be cleaning up correctly after themselves
// AB#7856
config.exit = true;
Expand Down
8 changes: 4 additions & 4 deletions packages/test/snapshots/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
"test": "npm run test:mocha",
"test:coverage": "c8 npm test",
"test:mocha": "npm run test:mocha:esm && echo skipping cjs to avoid overhead - npm run test:mocha:cjs",
"test:mocha:cjs": "cross-env FLUID_TEST_MODULE_SYSTEM=CJS mocha",
"test:mocha:esm": "mocha",
"test:mocha:cjs": "cross-env FLUID_TEST_MODULE_SYSTEM=CJS mocha --ignore \"dist/test/generate/**/*\" \"dist/test/**/*.spec.*js\"",
"test:mocha:esm": "mocha --ignore \"lib/test/generate/**/*\" \"lib/test/**/*.spec.*js\"",
"test:mocha:verbose": "cross-env FLUID_TEST_VERBOSE=1 npm run test:mocha",
"test:new": "mocha --experimental-worker \"lib/test/generate/new.spec.*js\"",
"test:update": "mocha --experimental-worker \"lib/test/generate/update.spec.*js\"",
"test:new": "mocha \"lib/test/generate/new.spec.*js\"",
"test:update": "mocha \"lib/test/generate/update.spec.*js\"",
"tsc": "fluid-tsc commonjs --project ./tsconfig.cjs.json && copyfiles -f ../../../common/build/build-common/src/cjs/package.json ./dist"
},
"c8": {
Expand Down
35 changes: 23 additions & 12 deletions packages/test/snapshots/src/replayMultipleFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export enum Mode {
}

export interface IWorkerArgs {
name: string;
folder: string;
mode: Mode;
snapFreq?: number;
Expand Down Expand Up @@ -137,7 +138,12 @@ export async function processOneNode(args: IWorkerArgs) {
// replayArgs.overlappingContainers = 1;

try {
const start = performance.now();
const errors = await new ReplayTool(replayArgs).Go();
const end = performance.now();
console.log(
`${args.name} processed with ${errors.length} errors in ${((end - start) / 1000).toFixed(2)} seconds`,
);
if (errors.length !== 0) {
throw new Error(`Errors\n ${errors.join("\n")}`);
}
Expand Down Expand Up @@ -185,12 +191,13 @@ export async function processContent(mode: Mode, concurrently = true) {
testSummaries = true;
}

const data: IWorkerArgs = {
const data = {
name: node.name,
folder,
mode,
snapFreq,
testSummaries,
};
} as const satisfies IWorkerArgs;
Copy link

Copilot AI Oct 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using as const satisfies IWorkerArgs creates an immutable object that cannot be spread or modified later. This conflicts with the code at lines 245-249 where data is spread using ...data. Consider using satisfies IWorkerArgs without as const to maintain type safety while allowing the object to be spread.

Suggested change
} as const satisfies IWorkerArgs;
} satisfies IWorkerArgs;

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, an immutable object can't be spread? Sure seems like it can.


switch (mode) {
case Mode.Validate:
Expand Down Expand Up @@ -218,7 +225,7 @@ export async function processContent(mode: Mode, concurrently = true) {
* from multiple old versions, process snapshot from each of these versions.
*/
async function processNodeForValidate(
data: IWorkerArgs,
data: Readonly<IWorkerArgs>,
concurrently: boolean,
limiter: ConcurrencyLimiter,
) {
Expand All @@ -235,8 +242,12 @@ async function processNodeForValidate(
continue;
}

data.initializeFromSnapshotsDir = `${srcSnapshotsDir}/${node.name}`;
await processNode(data, concurrently, limiter);
const subData = {
...data,
name: `${data.name}-${node.name}`,
initializeFromSnapshotsDir: `${srcSnapshotsDir}/${node.name}`,
};
await processNode(subData, concurrently, limiter);
}
}

Expand All @@ -248,7 +259,7 @@ async function processNodeForValidate(
* - Update the package version of the current snapshots.
*/
async function processNodeForUpdatingSnapshots(
data: IWorkerArgs,
data: Readonly<IWorkerArgs>,
concurrently: boolean,
limiter: ConcurrencyLimiter,
) {
Expand Down Expand Up @@ -297,7 +308,7 @@ async function processNodeForUpdatingSnapshots(
* generate snapshot files and write them to the current snapshots dir.
*/
async function processNodeForNewSnapshots(
data: IWorkerArgs,
data: Readonly<IWorkerArgs>,
concurrently: boolean,
limiter: ConcurrencyLimiter,
) {
Expand All @@ -311,10 +322,10 @@ async function processNodeForNewSnapshots(
fs.mkdirSync(currentSnapshotsDir, { recursive: true });

// For new snapshots, testSummaries should be set because summaries should be generated as per the original file.
data.testSummaries = true;
const dataSummaries = { ...data, testSummaries: true };

// Process the current folder which will write the generated snapshots to current snapshots dir.
await processNode(data, concurrently, limiter);
await processNode(dataSummaries, concurrently, limiter);

const versionFileName = `${currentSnapshotsDir}/snapshotVersion.json`;
// Write the versions file to the current snapshots dir.
Expand All @@ -323,7 +334,7 @@ async function processNodeForNewSnapshots(
});

// Write the metadata file.
writeMetadataFile(data.folder);
writeMetadataFile(dataSummaries.folder);
}

/**
Expand All @@ -335,7 +346,7 @@ async function processNodeForNewSnapshots(
* 3. Validates that the snapshot matches with the corresponding snapshot in current version.
* 4. Loads a document with snapshot in current version. Repeats steps 2 and 3.
*/
async function processNodeForBackCompat(data: IWorkerArgs) {
async function processNodeForBackCompat(data: Readonly<IWorkerArgs>) {
const messagesFile = `${data.folder}/messages.json`;
if (!fs.existsSync(messagesFile)) {
throw new Error(`messages.json doesn't exist in ${data.folder}`);
Expand Down Expand Up @@ -381,7 +392,7 @@ async function processNodeForBackCompat(data: IWorkerArgs) {
* the threads. If concurrently if false, directly processes the snapshots.
*/
async function processNode(
workerData: IWorkerArgs,
workerData: Readonly<IWorkerArgs>,
concurrently: boolean,
limiter: ConcurrencyLimiter,
) {
Expand Down
Loading