-
Notifications
You must be signed in to change notification settings - Fork 0
test: diagnose restart startup cascades #175
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6483dea
test: add restart startup diagnostics
mohanagy 288ff74
test: trace audit compaction timeout
mohanagy fa97c5d
test: trace lazy upstream discovery
mohanagy 0f21d68
test: trace timed close replacement startup
mohanagy 7c63120
test: preserve upstream diagnostic causes
mohanagy 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import { mkdtemp, rm, writeFile } from "node:fs/promises"; | ||
| import { tmpdir } from "node:os"; | ||
| import { join } from "node:path"; | ||
| import { afterEach, describe, expect, it } from "vitest"; | ||
| import { countFixtureStarts, diagnosticFailure, summarizeUpstreamHealth } from "./upstream-diagnostics.js"; | ||
|
|
||
| const directories: string[] = []; | ||
|
|
||
| afterEach(async () => { | ||
| await Promise.all(directories.splice(0).map(async (directory) => rm(directory, { recursive: true, force: true }))); | ||
| }); | ||
|
|
||
| describe("upstream test diagnostics", () => { | ||
| it("counts fixture starts and emits only the safe health fields", async () => { | ||
| const directory = await mkdtemp(join(tmpdir(), "miftah-upstream-diagnostics-")); | ||
| directories.push(directory); | ||
| const starts = join(directory, "starts"); | ||
| await writeFile(starts, "one\n\ntwo\n"); | ||
|
|
||
| await expect(countFixtureStarts(starts)).resolves.toBe(2); | ||
| expect( | ||
| summarizeUpstreamHealth([ | ||
| { | ||
| profile: "work", | ||
| upstreamName: "remote", | ||
| state: "failed", | ||
| processState: "failed", | ||
| restartCount: 1, | ||
| lastStopReason: "shutdown-timeout", | ||
| restartLimitReached: false, | ||
| capabilities: { | ||
| tools: { state: "failed", lastTransition: "2026-01-01T00:00:00.000Z", error: "sensitive tool failure" }, | ||
| resources: { state: "unknown", lastTransition: "2026-01-01T00:00:00.000Z" }, | ||
| prompts: { state: "available", lastTransition: "2026-01-01T00:00:00.000Z" } | ||
| }, | ||
| status: "failed", | ||
| lastTransition: "2026-01-01T00:00:00.000Z", | ||
| error: "sensitive manager error" | ||
| } | ||
| ]) | ||
| ).toEqual([ | ||
| { | ||
| profile: "work", | ||
| upstreamName: "remote", | ||
| state: "failed", | ||
| processState: "failed", | ||
| restartCount: 1, | ||
| lastStopReason: "shutdown-timeout", | ||
| restartLimitReached: false, | ||
| capabilities: { tools: "failed", resources: "unknown", prompts: "available" } | ||
| } | ||
| ]); | ||
| }); | ||
|
|
||
| it("keeps a captured failure as the cause without putting it in the safe diagnostic message", () => { | ||
| const cause = new Error("sensitive upstream failure"); | ||
| const error = diagnosticFailure("Upstream marker diagnostic", { startDelta: 0 }, cause); | ||
|
|
||
| expect(error.message).toBe('Upstream marker diagnostic: {"startDelta":0}'); | ||
| expect(error.message).not.toContain("sensitive upstream failure"); | ||
| expect(error.cause).toBe(cause); | ||
| }); | ||
| }); |
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,48 @@ | ||
| import { readFile } from "node:fs/promises"; | ||
|
|
||
| interface DiagnosticCapabilityHealth { | ||
| readonly state: string; | ||
| readonly lastTransition: string; | ||
| readonly error?: string; | ||
| } | ||
|
|
||
| interface DiagnosticUpstreamHealth { | ||
| readonly profile: string; | ||
| readonly upstreamName: string; | ||
| readonly status?: string; | ||
| readonly state: string; | ||
| readonly processState: string; | ||
| readonly lastTransition?: string; | ||
| readonly restartCount: number; | ||
| readonly lastStopReason?: string; | ||
| readonly restartLimitReached?: boolean; | ||
| readonly error?: string; | ||
| readonly capabilities: Record<string, DiagnosticCapabilityHealth>; | ||
| } | ||
|
|
||
| /** Counts fixture process entries without reporting any fixture output. */ | ||
| export async function countFixtureStarts(path: string): Promise<number> { | ||
| const contents = await readFile(path, "utf8"); | ||
| return contents.split("\n").filter(Boolean).length; | ||
| } | ||
|
|
||
| /** Restricts failure diagnostics to lifecycle metadata that cannot contain upstream output or secrets. */ | ||
| export function summarizeUpstreamHealth(health: readonly DiagnosticUpstreamHealth[]): Array<Record<string, unknown>> { | ||
| return health.map((entry) => ({ | ||
| profile: entry.profile, | ||
| upstreamName: entry.upstreamName, | ||
| state: entry.state, | ||
| processState: entry.processState, | ||
| restartCount: entry.restartCount, | ||
| lastStopReason: entry.lastStopReason, | ||
| restartLimitReached: entry.restartLimitReached, | ||
| capabilities: Object.fromEntries( | ||
| Object.entries(entry.capabilities).map(([capability, capabilityHealth]) => [capability, capabilityHealth.state]) | ||
| ) | ||
| })); | ||
| } | ||
|
|
||
| /** Keeps the original test failure in Error.cause while emitting a safe, allowlisted diagnostic message. */ | ||
| export function diagnosticFailure(message: string, details: Record<string, unknown>, cause: unknown): Error { | ||
| return new Error(`${message}: ${JSON.stringify(details)}`, { cause }); | ||
| } |
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.