Files
paseo/packages/app/e2e/support/helpers/project-ownership.ts
T
Mohamed BoudraandGitHub 5a30affd7f Skip unrelated required checks without losing their names (#2542)
* fix(ci): skip unrelated required checks cleanly

Matrix jobs had to start no-op runners to preserve interpolated required-check names. Static named jobs let GitHub report genuine skipped conclusions while keeping those names stable.

* fix(ci): gate changes to install patching script

* fix(ci): route cross-package test contracts narrowly

* fix(ci): keep routed contracts merge-blocking

* fix(server): exclude nested test utilities from builds

* fix(ci): cover app-owned native and browser domains

* refactor(ci): align tests with runtime domains

Own browser specs, desktop specs, and Electron-only app code by stable directories so PR routing does not depend on filename conventions. Keep desktop integration coverage inside the required desktop check.

* fix(ci): keep routing and desktop suites isolated

The routing regression must run before dependency installation, and desktop Vitest must not collect Playwright-owned specs.

* fix(ci): isolate desktop e2e runtime

* perf(test): isolate Playwright workers

* perf(test): parallelize Playwright within specs

* fix(test): keep Playwright file scheduling

* fix(test): share dynamic Metro fixture

* fix(test): preserve own-host restart fixtures

* fix(ci): preserve routed contracts after rebase

* Stabilize Playwright wheel-scroll assertions
2026-08-02 00:56:05 +08:00

65 lines
2.4 KiB
TypeScript

interface OwnedResourceResult {
project?: { projectId: string } | null;
workspace?: { projectId: string } | null;
}
interface ProjectClient {
addProject?: (...args: unknown[]) => Promise<OwnedResourceResult>;
close(): Promise<void>;
createPaseoWorktree?: (...args: unknown[]) => Promise<OwnedResourceResult>;
createWorkspace?: (...args: unknown[]) => Promise<OwnedResourceResult>;
removeProject(projectId: string): Promise<unknown>;
}
/**
* Makes a test client own every project it creates. Closing the client removes
* those projects first, which also terminates their workspaces and terminals.
*/
export function withProjectOwnership<Client extends object>(client: Client): Client {
const target = client as Client & ProjectClient;
const projectIds = new Set<string>();
let closed = false;
async function trackProject(result: OwnedResourceResult) {
const projectId = result.project?.projectId ?? result.workspace?.projectId;
if (projectId) projectIds.add(projectId);
return result;
}
return new Proxy(client, {
get(_target, property) {
if (property === "addProject" && target.addProject) {
const addProject = target.addProject.bind(target);
return async (...args: unknown[]) => trackProject(await addProject(...args));
}
if (property === "createWorkspace" && target.createWorkspace) {
const createWorkspace = target.createWorkspace.bind(target);
return async (...args: unknown[]) => trackProject(await createWorkspace(...args));
}
if (property === "createPaseoWorktree" && target.createPaseoWorktree) {
const createPaseoWorktree = target.createPaseoWorktree.bind(target);
return async (...args: unknown[]) => trackProject(await createPaseoWorktree(...args));
}
if (property === "removeProject") {
return async (projectId: string) => {
const result = await target.removeProject(projectId);
projectIds.delete(projectId);
return result;
};
}
if (property === "close") {
return async () => {
if (closed) return;
closed = true;
for (const projectId of projectIds) {
await target.removeProject(projectId).catch(() => undefined);
}
await target.close();
};
}
const value = Reflect.get(target, property, target);
return typeof value === "function" ? value.bind(target) : value;
},
});
}