fix: reconcile captured main and owned findings for PR #1603
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { afterEach, expect, it, onTestFinished, vi } from "vitest";
|
||||
|
||||
import { ApktoolProvider } from "../../src/apktool/ApktoolProvider.js";
|
||||
import { execFileOutput } from "../../src/process/ExecFileOutput.js";
|
||||
|
||||
vi.mock("../../src/process/ExecFileOutput.js", async (importOriginal) => ({
|
||||
...(await importOriginal<
|
||||
typeof import("../../src/process/ExecFileOutput.js")
|
||||
>()),
|
||||
execFileOutput: vi.fn(async () => ({ stdout: "2.7.0-stub\n", stderr: "" })),
|
||||
}));
|
||||
afterEach(() => {
|
||||
vi.unstubAllEnvs();
|
||||
vi.mocked(execFileOutput).mockClear();
|
||||
});
|
||||
|
||||
it.skipIf(process.platform === "win32")(
|
||||
"keeps an explicit environment's PATH choice and samples ambient inheritance per operation",
|
||||
async () => {
|
||||
vi.stubEnv("REA_APKTOOL_COMMAND", "/ambient/initial-apktool");
|
||||
vi.stubEnv("REA_APKTOOL_TEST_INHERITED_VALUE", "initial");
|
||||
const provider = new ApktoolProvider({ environment: {} });
|
||||
onTestFinished(() => provider.close());
|
||||
vi.stubEnv("REA_APKTOOL_COMMAND", "/ambient/changed-apktool");
|
||||
vi.stubEnv("REA_APKTOOL_TEST_INHERITED_VALUE", "changed");
|
||||
await provider.inspectAvailability();
|
||||
expect(vi.mocked(execFileOutput).mock.lastCall?.[0]).toBe("apktool");
|
||||
expect(vi.mocked(execFileOutput).mock.lastCall?.[2]?.env).toMatchObject({
|
||||
REA_APKTOOL_COMMAND: undefined,
|
||||
REA_APKTOOL_TEST_INHERITED_VALUE: "changed",
|
||||
});
|
||||
vi.stubEnv("REA_APKTOOL_TEST_INHERITED_VALUE", undefined);
|
||||
await provider.inspectAvailability();
|
||||
expect(
|
||||
vi.mocked(execFileOutput).mock.lastCall?.[2]?.env
|
||||
?.REA_APKTOOL_TEST_INHERITED_VALUE,
|
||||
).toBeUndefined();
|
||||
},
|
||||
);
|
||||
|
||||
it.skipIf(process.platform === "win32")(
|
||||
"inherits the current default launcher when no environment was selected",
|
||||
async () => {
|
||||
vi.stubEnv("REA_APKTOOL_COMMAND", "/ambient/initial-apktool");
|
||||
const provider = new ApktoolProvider();
|
||||
onTestFinished(() => provider.close());
|
||||
vi.stubEnv("REA_APKTOOL_COMMAND", "/ambient/later-apktool");
|
||||
await provider.inspectAvailability();
|
||||
expect(vi.mocked(execFileOutput).mock.lastCall?.[0]).toBe(
|
||||
"/ambient/later-apktool",
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Cli } from "incur";
|
||||
import { resolve } from "node:path";
|
||||
import { expect, it, vi } from "vitest";
|
||||
|
||||
import type { BrowserScenarioCapturePort } from "../../src/application/BrowserScenarioCapturePort.js";
|
||||
@@ -32,7 +33,7 @@ vi.mock("../../src/composition/browserScenario.js", () => ({
|
||||
}));
|
||||
|
||||
const scenario = browserScenarioSchema.parse({
|
||||
browser: { mode: "launch", executable_path: "/fixture/chromium" },
|
||||
browser: { mode: "launch", executable_path: resolve("/fixture/chromium") },
|
||||
start_url: { url: "https://app.example.test/" },
|
||||
actions: [{ step_id: "wait", action: "wait_for_timeout", duration_ms: 1 }],
|
||||
storage: {},
|
||||
@@ -111,6 +112,22 @@ class RetrySession implements BrowserScenarioSessionPort {
|
||||
}
|
||||
}
|
||||
|
||||
it("waits for a slow but successful browser close before removing its profile", async () => {
|
||||
const stages: string[] = [];
|
||||
const cleanup = new PlaywrightScenarioBrowserCleanupOwner({
|
||||
closeBrowser: async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1_250));
|
||||
stages.push("browser-closed");
|
||||
},
|
||||
removeProfile: async () => {
|
||||
stages.push("profile-removed");
|
||||
},
|
||||
});
|
||||
|
||||
await cleanup.close();
|
||||
expect(stages).toEqual(["browser-closed", "profile-removed"]);
|
||||
});
|
||||
|
||||
const serveScenario = async () => {
|
||||
const cli = Cli.create("browser-cleanup-test", { sync: false });
|
||||
registerBrowserScenarioCommands(cli, silentLogger, {});
|
||||
|
||||
@@ -30,6 +30,9 @@ it
|
||||
await chmod(launcher, 0o700);
|
||||
await symlink(launcher, alternate);
|
||||
}
|
||||
// A rejection must come from the fixture we are about to launch. An
|
||||
// existing Xvfb would otherwise mask a broken executable-identity check.
|
||||
await assertCleanLinuxHopperRuntime(alternateMode ? [launcher] : []);
|
||||
const command = alternateMode ? alternate : process.execPath;
|
||||
const arguments_ = alternateMode ? ["30"] : ["-e", childCode];
|
||||
const parentCode = `
|
||||
|
||||
@@ -18,7 +18,10 @@ import {
|
||||
PWNTOOLS_MEMORY_FAILURE_EXIT,
|
||||
PWNTOOLS_PROVIDER_IDENTITY,
|
||||
} from "../../src/native/pwntools/PwntoolsRelease.js";
|
||||
import { cleanupOwnedProcessGroup } from "../../src/process/ProcessOwnership.js";
|
||||
import {
|
||||
cleanupOwnedProcessGroup,
|
||||
type OwnedProcessGroup,
|
||||
} from "../../src/process/ProcessOwnership.js";
|
||||
import { prepareProcessOwnershipInspection } from "../../src/process/ProcessOwnershipObservation.js";
|
||||
import { spawnOwnedProviderProcess } from "../../src/process/ProviderProcess.js";
|
||||
import { PrivateRuntimeRoot } from "../../src/process/PrivateRuntimeRoot.js";
|
||||
@@ -232,12 +235,13 @@ it.runIf(supportedHost).each([
|
||||
const { path, root, environment, basic } = await fixture();
|
||||
let launches = 0;
|
||||
let cleanupAllowed = false;
|
||||
let retainedOwnership: OwnedProcessGroup | undefined;
|
||||
const read = vi.spyOn(artifacts, "readStableArtifact");
|
||||
const provider = new PwntoolsRecordedCrashProvider(
|
||||
environment,
|
||||
async (spawn) => {
|
||||
if (stage === "debugger" && ++launches === 1) return basic(spawn);
|
||||
return changingWorker(
|
||||
const launched = await changingWorker(
|
||||
spawn,
|
||||
join(spawn.cwd ?? "", "resource.failure"),
|
||||
{
|
||||
@@ -247,6 +251,8 @@ it.runIf(supportedHost).each([
|
||||
},
|
||||
() => cleanupAllowed,
|
||||
);
|
||||
retainedOwnership = launched.ownership;
|
||||
return launched;
|
||||
},
|
||||
async () => root,
|
||||
);
|
||||
@@ -261,14 +267,14 @@ it.runIf(supportedHost).each([
|
||||
if (result.ok) throw new Error("Expected unresolved process ownership");
|
||||
const projected = projectAnalysisError(result.error);
|
||||
expect(projected.code).toBe("cleanup_incomplete");
|
||||
expect(projected).toMatchObject({
|
||||
details: {
|
||||
resources: expect.arrayContaining([
|
||||
expect.stringMatching(/^pid:\d+$/u),
|
||||
expect.stringMatching(/^process-group:\d+$/u),
|
||||
]),
|
||||
},
|
||||
});
|
||||
if (retainedOwnership === undefined)
|
||||
throw new Error("Expected retained process ownership");
|
||||
expect(projected.details?.resources).toEqual([
|
||||
retainedOwnership.runId,
|
||||
root.path,
|
||||
`pid:${retainedOwnership.leaderPid}`,
|
||||
`process-group:${retainedOwnership.processGroupId}`,
|
||||
]);
|
||||
if (stage === "debugger")
|
||||
expect(projected).toMatchObject({
|
||||
details: {
|
||||
|
||||
@@ -25,6 +25,7 @@ beforeEach(async () => {
|
||||
HOME: home,
|
||||
USERPROFILE: home,
|
||||
APPDATA: join(home, "AppData", "Roaming"),
|
||||
LOCALAPPDATA: join(home, "AppData", "Local"),
|
||||
CLAUDE_CONFIG_DIR: home,
|
||||
CODEX_HOME: join(home, ".codex"),
|
||||
COPILOT_HOME: join(home, ".copilot"),
|
||||
|
||||
Reference in New Issue
Block a user