Fixes #12
This commit is contained in:
Will Chen
2025-06-05 22:26:17 -07:00
committed by GitHub
parent 97ed34cf08
commit d3fbb48472
18 changed files with 6386 additions and 65 deletions

View File

@@ -0,0 +1,52 @@
import { expect } from "@playwright/test";
import { test, Timeout } from "./helpers/test_helper";
const tests = [
{
testName: "with history",
newAppName: "copied-app-with-history",
buttonName: "Copy app with history",
expectedVersion: "Version 2",
},
{
testName: "without history",
newAppName: "copied-app-without-history",
buttonName: "Copy app without history",
expectedVersion: "Version 1",
},
];
for (const { testName, newAppName, buttonName, expectedVersion } of tests) {
test(`copy app ${testName}`, async ({ po }) => {
await po.setUp({ autoApprove: true });
await po.sendPrompt("hi");
await po.snapshotAppFiles({ name: "app" });
await po.getTitleBarAppNameButton().click();
// Open the dropdown menu
await po.clickAppDetailsMoreOptions();
await po.clickAppDetailsCopyAppButton();
await po.page.getByLabel("New app name").fill(newAppName);
// Click the "Copy app" button
await po.page.getByRole("button", { name: buttonName }).click();
// Expect to be on the new app's detail page
await expect(
po.page.getByRole("heading", { name: newAppName }),
).toBeVisible({
// Potentially takes a while for the copy to complete
timeout: Timeout.MEDIUM,
});
const currentAppName = await po.getCurrentAppName();
expect(currentAppName).toBe(newAppName);
await po.clickOpenInChatButton();
await expect(po.page.getByText(expectedVersion)).toBeVisible();
await po.snapshotAppFiles({ name: "app" });
});
}

View File

@@ -0,0 +1,129 @@
import fs from "fs";
import path from "path";
import crypto from "crypto";
export interface FileSnapshotData {
relativePath: string;
content: string;
}
const binaryExtensions = new Set([
".png",
".jpg",
".jpeg",
".gif",
".webp",
".tiff",
".psd",
".raw",
".bmp",
".heif",
".ico",
".pdf",
".eot",
".otf",
".ttf",
".woff",
".woff2",
".zip",
".tar",
".gz",
".7z",
".rar",
".mov",
".mp4",
".m4v",
".mkv",
".webm",
".flv",
".avi",
".wmv",
".mp3",
".wav",
".ogg",
".flac",
".exe",
".dll",
".so",
".a",
".lib",
".o",
".db",
".sqlite3",
".wasm",
]);
function isBinaryFile(filePath: string): boolean {
return binaryExtensions.has(path.extname(filePath).toLowerCase());
}
export function generateAppFilesSnapshotData(
currentPath: string,
basePath: string,
): FileSnapshotData[] {
const ignorePatterns = [
".git",
"node_modules",
// Avoid snapshotting lock files because they are getting generated
// automatically and cause noise, and not super important anyways.
"package-lock.json",
"pnpm-lock.yaml",
];
const entries = fs.readdirSync(currentPath, { withFileTypes: true });
let files: FileSnapshotData[] = [];
// Sort entries for deterministic order
entries.sort((a, b) => a.name.localeCompare(b.name));
for (const entry of entries) {
const entryPath = path.join(currentPath, entry.name);
if (ignorePatterns.includes(entry.name)) {
continue;
}
if (entry.isDirectory()) {
files = files.concat(generateAppFilesSnapshotData(entryPath, basePath));
} else if (entry.isFile()) {
const relativePath = path
.relative(basePath, entryPath)
// Normalize path separators to always use /
// to prevent diffs on Windows.
.replace(/\\/g, "/");
try {
if (isBinaryFile(entryPath)) {
const fileBuffer = fs.readFileSync(entryPath);
const hash = crypto
.createHash("sha256")
.update(fileBuffer)
.digest("hex");
files.push({
relativePath,
content: `[binary hash="${hash}"]`,
});
continue;
}
let content = fs
.readFileSync(entryPath, "utf-8")
// Normalize line endings to always use \n
.replace(/\r\n/g, "\n");
if (entry.name === "package.json") {
const packageJson = JSON.parse(content);
packageJson.packageManager = "<scrubbed>";
content = JSON.stringify(packageJson, null, 2);
}
files.push({ relativePath, content });
} catch (error) {
// Could be a binary file or permission issue, log and add a placeholder
const e = error as Error;
console.warn(`Could not read file ${entryPath}: ${e.message}`);
files.push({
relativePath,
content: `[Error reading file: ${e.message}]`,
});
}
}
}
return files;
}

View File

@@ -5,6 +5,7 @@ import fs from "fs";
import path from "path";
import os from "os";
import { execSync } from "child_process";
import { generateAppFilesSnapshotData } from "./generateAppFilesSnapshotData";
const showDebugLogs = process.env.DEBUG_LOGS === "true";
@@ -80,14 +81,7 @@ export class PageObject {
}
await expect(() => {
const filesData = generateAppFilesSnapshotData(appPath, appPath, [
".git",
"node_modules",
// Avoid snapshotting lock files because they are getting generated
// automatically and cause noise, and not super important anyways.
"package-lock.json",
"pnpm-lock.yaml",
]);
const filesData = generateAppFilesSnapshotData(appPath, appPath);
// Sort by relative path to ensure deterministic output
filesData.sort((a, b) => a.relativePath.localeCompare(b.relativePath));
@@ -97,7 +91,7 @@ export class PageObject {
.join("\n\n");
if (name) {
expect(snapshotContent).toMatchSnapshot(name);
expect(snapshotContent).toMatchSnapshot(name + ".txt");
} else {
expect(snapshotContent).toMatchSnapshot();
}
@@ -378,6 +372,10 @@ export class PageObject {
await this.page.getByTestId(`app-list-item-${appName}`).click();
}
async clickOpenInChatButton() {
await this.page.getByRole("button", { name: "Open in Chat" }).click();
}
async clickAppDetailsRenameAppButton() {
await this.page.getByTestId("app-details-rename-app-button").click();
}
@@ -386,6 +384,10 @@ export class PageObject {
await this.page.getByTestId("app-details-more-options-button").click();
}
async clickAppDetailsCopyAppButton() {
await this.page.getByRole("button", { name: "Copy app" }).click();
}
async clickConnectSupabaseButton() {
await this.page.getByTestId("connect-supabase-button").click();
}
@@ -406,10 +408,13 @@ export class PageObject {
const settings = path.join(this.userDataDir, "user-settings.json");
const settingsContent = fs.readFileSync(settings, "utf-8");
// Sanitize the "telemetryUserId" since it's a UUID
const sanitizedSettingsContent = settingsContent.replace(
/"telemetryUserId": "[^"]*"/g,
'"telemetryUserId": "[UUID]"',
);
const sanitizedSettingsContent = settingsContent
.replace(/"telemetryUserId": "[^"]*"/g, '"telemetryUserId": "[UUID]"')
// Don't snapshot this otherwise it'll diff with every release.
.replace(
/"lastShownReleaseNotesVersion": "[^"]*"/g,
'"lastShownReleaseNotesVersion": "[scrubbed]"',
);
expect(sanitizedSettingsContent).toMatchSnapshot();
}
@@ -652,48 +657,3 @@ function prettifyDump(
})
.join("\n\n");
}
interface FileSnapshotData {
relativePath: string;
content: string;
}
function generateAppFilesSnapshotData(
currentPath: string,
basePath: string,
ignorePatterns: string[],
): FileSnapshotData[] {
const entries = fs.readdirSync(currentPath, { withFileTypes: true });
let files: FileSnapshotData[] = [];
// Sort entries for deterministic order
entries.sort((a, b) => a.name.localeCompare(b.name));
for (const entry of entries) {
const entryPath = path.join(currentPath, entry.name);
if (ignorePatterns.includes(entry.name)) {
continue;
}
if (entry.isDirectory()) {
files = files.concat(
generateAppFilesSnapshotData(entryPath, basePath, ignorePatterns),
);
} else if (entry.isFile()) {
const relativePath = path.relative(basePath, entryPath);
try {
const content = fs.readFileSync(entryPath, "utf-8");
files.push({ relativePath, content });
} catch (error) {
// Could be a binary file or permission issue, log and add a placeholder
const e = error as Error;
console.warn(`Could not read file ${entryPath}: ${e.message}`);
files.push({
relativePath,
content: `[Error reading file: ${e.message}]`,
});
}
}
}
return files;
}

View File

@@ -9,7 +9,7 @@
"telemetryUserId": "[UUID]",
"hasRunBefore": true,
"experiments": {},
"lastShownReleaseNotesVersion": "0.8.0",
"lastShownReleaseNotesVersion": "[scrubbed]",
"maxChatTurnsInContext": 5,
"enableProLazyEditsMode": true,
"enableProSmartFilesContextMode": true,

File diff suppressed because it is too large Load Diff

View File

@@ -8,7 +8,7 @@
"telemetryUserId": "[UUID]",
"hasRunBefore": true,
"experiments": {},
"lastShownReleaseNotesVersion": "0.8.0",
"lastShownReleaseNotesVersion": "[scrubbed]",
"enableProLazyEditsMode": true,
"enableProSmartFilesContextMode": true,
"isTestMode": true

View File

@@ -8,7 +8,7 @@
"telemetryUserId": "[UUID]",
"hasRunBefore": true,
"experiments": {},
"lastShownReleaseNotesVersion": "0.8.0",
"lastShownReleaseNotesVersion": "[scrubbed]",
"enableProLazyEditsMode": true,
"enableProSmartFilesContextMode": true,
"isTestMode": true

View File

@@ -8,7 +8,7 @@
"telemetryUserId": "[UUID]",
"hasRunBefore": true,
"experiments": {},
"lastShownReleaseNotesVersion": "0.8.0",
"lastShownReleaseNotesVersion": "[scrubbed]",
"enableProLazyEditsMode": true,
"enableProSmartFilesContextMode": true,
"isTestMode": true