Skip to content

Commit 66803a0

Browse files
committed
Simplify in-memory test file management by removing UUID references
1 parent 9340833 commit 66803a0

File tree

6 files changed

+19
-29
lines changed

6 files changed

+19
-29
lines changed

src/tools/add-percy-snapshots.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
44
import { percyWebSetupInstructions } from "../tools/sdk-utils/percy-web/handler.js";
55

66
export async function updateTestsWithPercyCommands(args: {
7-
uuid: string;
87
index: number;
98
}): Promise<CallToolResult> {
10-
const { uuid, index } = args;
9+
const { index } = args;
1110
const stored = storedPercyResults.get();
12-
13-
if (!stored || !stored.uuid || stored.uuid !== uuid || !stored[uuid]) {
14-
throw new Error(`No test files found in memory for UUID: ${uuid}`);
11+
if (!stored || !stored.testFiles) {
12+
throw new Error(
13+
`No test files found in memory. Please call listTestFiles first.`,
14+
);
1515
}
1616

17-
const fileStatusMap = stored[uuid];
17+
const fileStatusMap = stored.testFiles;
1818
const filePaths = Object.keys(fileStatusMap);
1919

2020
if (index < 0 || index >= filePaths.length) {
2121
throw new Error(
22-
`Invalid index: ${index}. There are ${filePaths.length} files for UUID: ${uuid}`,
22+
`Invalid index: ${index}. There are ${filePaths.length} files available.`,
2323
);
2424
}
2525

@@ -30,9 +30,8 @@ export async function updateTestsWithPercyCommands(args: {
3030
percyWebSetupInstructions,
3131
);
3232

33-
// Mark this file as updated (true) in the unified structure
3433
const updatedStored = { ...stored };
35-
updatedStored[uuid][filePaths[index]] = true; // true = updated
34+
updatedStored.testFiles[filePaths[index]] = true; // true = updated
3635
storedPercyResults.set(updatedStored);
3736

3837
return {

src/tools/list-test-files.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { listTestFiles } from "./percy-snapshot-utils/detect-test-files.js";
22
import { storedPercyResults } from "../lib/inmemory-store.js";
33
import { updateFileAndStep } from "./percy-snapshot-utils/utils.js";
44
import { percyWebSetupInstructions } from "./sdk-utils/percy-web/handler.js";
5-
import crypto from "crypto";
65
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
76

87
export async function addListTestFiles(): Promise<CallToolResult> {
@@ -56,30 +55,26 @@ export async function addListTestFiles(): Promise<CallToolResult> {
5655
};
5756
}
5857

59-
// For multiple files, use the UUID workflow
60-
const uuid = crypto.randomUUID();
61-
62-
// Store files in the unified structure with initial status false (not updated)
58+
// For multiple files, store directly in testFiles
6359
const fileStatusMap: { [key: string]: boolean } = {};
6460
testFiles.forEach((file) => {
6561
fileStatusMap[file] = false; // false = not updated, true = updated
6662
});
6763

68-
// Update storedPercyResults with single UUID for the project
64+
// Update storedPercyResults with test files
6965
const updatedStored = { ...storedResults };
70-
updatedStored.uuid = uuid; // Store the UUID reference
71-
updatedStored[uuid] = fileStatusMap; // Store files under the UUID key
66+
updatedStored.testFiles = fileStatusMap;
7267
storedPercyResults.set(updatedStored);
7368

7469
return {
7570
content: [
7671
{
7772
type: "text",
78-
text: `The Test files are stored in memory with id ${uuid} and the total number of tests files found is ${testFiles.length}. You can use this UUID to retrieve the tests file paths later.`,
73+
text: `The Test files are stored in memory and the total number of tests files found is ${testFiles.length}.`,
7974
},
8075
{
8176
type: "text",
82-
text: `You can now use the tool addPercySnapshotCommands to update the test file with Percy commands for visual testing with the UUID ${uuid}`,
77+
text: `You can now use the tool addPercySnapshotCommands to update the test file with Percy commands for visual testing.`,
8378
},
8479
],
8580
};

src/tools/percy-snapshot-utils/constants.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ import { SDKSupportedLanguage } from "../sdk-utils/common/types.js";
33
import { DetectionConfig } from "./types.js";
44

55
export const UpdateTestFileWithInstructionsParams = {
6-
uuid: z
7-
.string()
8-
.describe("UUID referencing the in-memory array of test file paths"),
96
index: z.number().describe("Index of the test file to update"),
107
};
118

src/tools/run-percy-scan.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,14 @@ function checkForUpdatedFiles(
7373
const projectMatches = stored?.projectName === projectName;
7474
return (
7575
projectMatches &&
76-
stored?.uuid &&
77-
stored[stored.uuid] &&
78-
Object.values(stored[stored.uuid]).some((status) => status === true)
76+
stored?.testFiles &&
77+
Object.values(stored.testFiles).some((status) => status === true)
7978
);
8079
}
8180

8281
function getUpdatedFiles(stored: any): string[] {
8382
const updatedFiles: string[] = [];
84-
const fileStatusMap = stored[stored.uuid!];
83+
const fileStatusMap = stored.testFiles;
8584

8685
Object.entries(fileStatusMap).forEach(([filePath, status]) => {
8786
if (status === true) {
@@ -105,7 +104,7 @@ function generateUpdatedFilesSteps(
105104

106105
return [
107106
`Run only the updated files with Percy:\n` +
108-
`Example: ${exampleCommand} -- <file1> <file2> ...`,
107+
`Example: ${exampleCommand} <file1> <file2> ...`,
109108
`Updated files to run:\n${filesToRun.join("\n")}`,
110109
];
111110
}

src/tools/sdk-utils/common/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const PERCY_REPLACE_REGEX =
1919
/Invoke listTestFiles\(\) with the provided directories[\s\S]*?- DO NOT STOP until you add commands in all the files or you reach end of the files\./;
2020

2121
export const PERCY_SNAPSHOT_INSTRUCTION = `
22-
Invoke listTestFiles() with the provided directories from user to gather all test files in memory and obtain the generated UUID ---STEP---
22+
Invoke listTestFiles() with the provided directories from user to gather all test files in memory ---STEP---
2323
Process files in STRICT sequential order using tool addPercySnapshotCommands() with below instructions:
2424
- Start with index 0
2525
- Then index 1

src/tools/sdk-utils/handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export async function setUpPercyHandler(
5757
integrationType: input.integrationType,
5858
folderPaths: input.folderPaths || [],
5959
filePaths: input.filePaths || [],
60-
uuid: null,
60+
testFiles: {},
6161
});
6262

6363
const authorization = getBrowserStackAuth(config);

0 commit comments

Comments
 (0)