Repository navigation
fix(verifiers): keep the recorded-crash root until its owners finish #8706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
abhisheksharma001
wants to merge
3
commits into
morluto:main
Choose a base branch
from
abhisheksharma001:fix/recorded-crash-verifier-cleanup-ownership
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+385
−36
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
5e66a36
fix(verifiers): keep the recorded-crash root until its owners finish
abhisheksharma001 5819e45
fix(verifiers): own a recorded-crash session before it connects
abhisheksharma001 13bc110
fix(verifiers): keep the trace client's connection failure beside a r…
abhisheksharma001 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
196 changes: 196 additions & 0 deletions
196
tests/boundary/process/recordedCrashVerifierCleanup.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,196 @@ | ||
| import { existsSync } from "node:fs"; | ||
| import { mkdir, readFile } from "node:fs/promises"; | ||
| import { join } from "node:path"; | ||
| import { fileURLToPath } from "node:url"; | ||
| import { expect } from "vitest"; | ||
| import { z } from "zod"; | ||
|
|
||
| import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; | ||
| import { | ||
| processTest, | ||
| type TestProcesses, | ||
| } from "../../support/process/processFixture.js"; | ||
|
|
||
| const preload = fileURLToPath( | ||
| new URL("../../fixtures/recordedCrashVerifierPreload.mjs", import.meta.url), | ||
| ); | ||
| const script = fileURLToPath( | ||
| new URL("../../../scripts/verify-recorded-crash.mjs", import.meta.url), | ||
| ); | ||
|
|
||
| const reportSchema = z.object({ | ||
| status: z.enum(["passed", "failed"]), | ||
| retained_root: z.string().nullable(), | ||
| verifier: z.object({ | ||
| process_lineage: z.object({ status: z.string() }), | ||
| }), | ||
| }); | ||
|
|
||
| /** Run the real verifier with authored owners; only its ownership handling is observed. */ | ||
| const runScenario = async (processes: TestProcesses, scenario: string) => { | ||
| const root = await createTestTempDirectory("rea-core-verifier-cleanup-"); | ||
| const temporary = join(root, "temporary"); | ||
| await mkdir(temporary); | ||
| const log = join(root, "events.log"); | ||
| const authored = join(root, "authored-absent-tool"); | ||
| const result = await processes.run( | ||
| process.execPath, | ||
| ["--import", preload, script], | ||
| { | ||
| env: { | ||
| ...process.env, | ||
| TMPDIR: temporary, | ||
| TMP: temporary, | ||
| TEMP: temporary, | ||
| REA_PWNTOOLS_PYTHON: authored, | ||
| REA_PWNDBG_GDB: authored, | ||
| REA_PWNDBG_GDBINIT: authored, | ||
| REA_PWNDBG_VENV_PATH: authored, | ||
| REA_VERIFY_STRACE_COMMAND: authored, | ||
| REA_CORE_TEST_EVENTS: log, | ||
| REA_CORE_TEST_SCENARIO: scenario, | ||
| }, | ||
| timeoutMs: 20_000, | ||
| }, | ||
| ); | ||
| const recorded = await readFile(log, "utf8").then( | ||
| (text) => text.split("\n").filter((line) => line !== ""), | ||
| () => [], | ||
| ); | ||
| const fixtureRoot = recorded | ||
| .find((line) => line.startsWith("root-create ")) | ||
| ?.slice("root-create ".length); | ||
| expect(result.exitCode, result.stderr).toBe(1); | ||
| return { | ||
| ...result, | ||
| report: reportSchema.parse(JSON.parse(result.stdout)), | ||
| events: recorded.map((line) => line.split(" ")[0]), | ||
| fixtureRoot, | ||
| rootRetained: fixtureRoot !== undefined && existsSync(fixtureRoot), | ||
| }; | ||
| }; | ||
|
|
||
| const ownersClosed = ["client-close", "transport-close", "sentinel-close"]; | ||
|
|
||
| processTest( | ||
| "releases the root after a prerequisite failure acquired no owner", | ||
| async ({ processes }) => { | ||
| const outcome = await runScenario(processes, "prerequisite-unavailable"); | ||
| expect(outcome.stderr).toContain("prerequisite unavailable: gcc"); | ||
| expect(outcome.stderr).toContain("authored gcc absence"); | ||
| expect(outcome.events).toEqual([ | ||
| "root-create", | ||
| "lineage-observe", | ||
| "root-close", | ||
| ]); | ||
| expect(outcome.report).toMatchObject({ | ||
| status: "failed", | ||
| retained_root: null, | ||
| }); | ||
| expect(outcome.rootRetained).toBe(false); | ||
| }, | ||
| ); | ||
|
|
||
| processTest( | ||
| "releases the root only after its owners closed and lineage was verified", | ||
| async ({ processes }) => { | ||
| const outcome = await runScenario(processes, "owners-released"); | ||
| expect(outcome.stderr).toContain("authored CLI failure"); | ||
| expect(outcome.stderr).not.toContain("retained fixture root"); | ||
| expect(outcome.events).toEqual([ | ||
| "root-create", | ||
| ...ownersClosed, | ||
| "lineage-observe", | ||
| "root-close", | ||
| ]); | ||
| expect(outcome.report).toMatchObject({ | ||
| status: "failed", | ||
| retained_root: null, | ||
| verifier: { process_lineage: { status: "verified" } }, | ||
| }); | ||
| expect(outcome.rootRetained).toBe(false); | ||
| }, | ||
| ); | ||
|
|
||
| processTest.for(["client", "transport", "sentinel"])( | ||
| "retains the root and the other owners' closes when the %s close is refused", | ||
| async (owner, { processes }) => { | ||
| const outcome = await runScenario(processes, `${owner}-close-refused`); | ||
| expect(outcome.stderr).toContain("authored CLI failure"); | ||
| expect(outcome.stderr).toContain(`authored ${owner} close failure`); | ||
| expect(outcome.stderr).toContain("retained fixture root"); | ||
| // Lineage is still observed for the report, after every owner and | ||
| // without releasing the root. | ||
| expect(outcome.events).toEqual([ | ||
| "root-create", | ||
| ...ownersClosed, | ||
| "lineage-observe", | ||
| ]); | ||
| expect(outcome.report).toMatchObject({ | ||
| status: "failed", | ||
| retained_root: outcome.fixtureRoot, | ||
| }); | ||
| expect(outcome.rootRetained).toBe(true); | ||
| }, | ||
| ); | ||
|
|
||
| processTest( | ||
| "retains the root when owned process lineage cannot be verified", | ||
| async ({ processes }) => { | ||
| const outcome = await runScenario(processes, "lineage-unverified"); | ||
| expect(outcome.stderr).toContain("authored lineage unavailability"); | ||
| expect(outcome.stderr).toContain("retained fixture root"); | ||
| expect(outcome.events).toEqual([ | ||
| "root-create", | ||
| ...ownersClosed, | ||
| "lineage-observe", | ||
| ]); | ||
| expect(outcome.report).toMatchObject({ | ||
| status: "failed", | ||
| retained_root: outcome.fixtureRoot, | ||
| verifier: { process_lineage: { status: "unavailable" } }, | ||
| }); | ||
| expect(outcome.rootRetained).toBe(true); | ||
| }, | ||
| ); | ||
|
|
||
| processTest( | ||
| "closes a session whose connection failed before releasing the root", | ||
| async ({ processes }) => { | ||
| const outcome = await runScenario(processes, "connect-refused"); | ||
| expect(outcome.stderr).toContain("authored connection failure"); | ||
| expect(outcome.stderr).not.toContain("retained fixture root"); | ||
| // The session is owned before it connects, so its owners still close. | ||
| expect(outcome.events).toEqual([ | ||
| "root-create", | ||
| ...ownersClosed, | ||
| "lineage-observe", | ||
| "root-close", | ||
| ]); | ||
| expect(outcome.report).toMatchObject({ | ||
| status: "failed", | ||
| retained_root: null, | ||
| }); | ||
| expect(outcome.rootRetained).toBe(false); | ||
| }, | ||
| ); | ||
|
|
||
| processTest( | ||
| "retains the root when a failed connection's transport close is refused", | ||
| async ({ processes }) => { | ||
| const outcome = await runScenario(processes, "connect-and-close-refused"); | ||
| expect(outcome.stderr).toContain("authored connection failure"); | ||
| expect(outcome.stderr).toContain("authored transport close failure"); | ||
| expect(outcome.stderr).toContain("retained fixture root"); | ||
| expect(outcome.events).toEqual([ | ||
| "root-create", | ||
| ...ownersClosed, | ||
| "lineage-observe", | ||
| ]); | ||
| expect(outcome.report).toMatchObject({ | ||
| status: "failed", | ||
| retained_root: outcome.fixtureRoot, | ||
| }); | ||
| expect(outcome.rootRetained).toBe(true); | ||
| }, | ||
| ); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.