-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(status): trust attested live startup health #5977
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
Closed
RHODIZSECURITY
wants to merge
4
commits into
lidge-jun:dev
from
RHODIZSECURITY:fix/status-live-startup-health-20260926
+237
−15
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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,133 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { fetchLiveStartupHealth, selectStatusStartupHealth, statusServiceSummary } from "../../src/cli/status"; | ||
| import type { StartupHealth } from "../../src/codex/autostart-health"; | ||
|
|
||
| const LIVE = { | ||
| pid: 4242, | ||
| port: 10101, | ||
| hostname: "127.0.0.1", | ||
| source: "runtime" as const, | ||
| }; | ||
|
|
||
| const SECRET = "A".repeat(43); | ||
| const NONCE = "B".repeat(43); | ||
|
|
||
| function startupPayload() { | ||
| return { | ||
| status: "protected", | ||
| routingKind: "opencodex-local", | ||
| routingInjected: true, | ||
| localRoutingDependency: true, | ||
| autostartEnabled: true, | ||
| rebootSafe: true, | ||
| protection: "service", | ||
| serviceInstalled: true, | ||
| serviceViable: true, | ||
| serviceEnabled: true, | ||
| serviceRunning: true, | ||
| serviceStale: false, | ||
| serviceConflict: false, | ||
| shimInstalled: true, | ||
| shimHealthy: true, | ||
| shimCoverage: "cli-only", | ||
| serviceSupported: true, | ||
| platform: "linux", | ||
| diagnosticStale: false, | ||
| recommendedCommand: null, | ||
| commands: { | ||
| installService: "ocx service install", | ||
| repairService: "ocx service repair", | ||
| installShim: "ocx codex-shim install", | ||
| restoreNative: "ocx restore", | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| function deps(body: unknown) { | ||
| return { | ||
| readRuntime: () => ({ | ||
| pid: LIVE.pid, | ||
| port: LIVE.port, | ||
| hostname: LIVE.hostname, | ||
| attestationSecret: SECRET, | ||
| }), | ||
| createNonce: () => NONCE, | ||
| now: () => 1_000, | ||
| fetchImpl: async () => new Response(JSON.stringify(body), { | ||
| status: 200, | ||
| headers: { "content-type": "application/json" }, | ||
| }), | ||
| }; | ||
| } | ||
|
|
||
| describe("ocx status live startup health", () => { | ||
| test("uses an attested live startup verdict when the shell-local service probe would disagree", async () => { | ||
| const observed = await fetchLiveStartupHealth(LIVE, deps(startupPayload())); | ||
| expect(observed?.status).toBe("protected"); | ||
| expect(observed?.rebootSafe).toBe(true); | ||
| expect(observed?.serviceViable).toBe(true); | ||
| expect(observed?.protection).toBe("service"); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }); | ||
|
|
||
| test("rejects malformed live startup payloads", async () => { | ||
| for (const malformed of [ | ||
| { ...startupPayload(), serviceRunning: "yes" }, | ||
| (() => { const row = { ...startupPayload() } as Record<string, unknown>; delete row.platform; return row; })(), | ||
| { ...startupPayload(), recommendedCommand: 7 }, | ||
| { ...startupPayload(), commands: { installService: "ok" } }, | ||
| { ...startupPayload(), routingAdoption: { adoption: "adopted", injectedAtMs: 1, staleClients: "bad", observedClients: 1 } }, | ||
| { ...startupPayload(), routingAdoption: { adoption: "adopted", injectedAtMs: 1, staleClients: [{ pid: "bad", startedAtMs: 1 }], observedClients: 1 } }, | ||
| ]) { | ||
| expect(await fetchLiveStartupHealth(LIVE, deps(malformed))).toBeNull(); | ||
| } | ||
| }); | ||
|
|
||
| test("selection prefers the attested live verdict and does not evaluate the conflicting fallback", () => { | ||
| const live = startupPayload() as StartupHealth; | ||
| let fallbackCalls = 0; | ||
| const selected = selectStatusStartupHealth(live, () => { | ||
| fallbackCalls += 1; | ||
| return { ...live, status: "at-risk", rebootSafe: false, protection: "none" } as StartupHealth; | ||
| }); | ||
| expect(selected.status).toBe("protected"); | ||
| expect(selected.rebootSafe).toBe(true); | ||
| expect(fallbackCalls).toBe(0); | ||
| expect(statusServiceSummary(live, { installed: false, summary: "systemd not found" }, true)) | ||
| .toContain("running under the live managed service"); | ||
| }); | ||
|
|
||
| test("selection falls back to local startup diagnostics when the live read is unavailable", () => { | ||
| const local = { ...startupPayload(), status: "at-risk", rebootSafe: false, protection: "none" } as StartupHealth; | ||
| let fallbackCalls = 0; | ||
| const selected = selectStatusStartupHealth(null, () => { fallbackCalls += 1; return local; }); | ||
| expect(selected).toBe(local); | ||
| expect(fallbackCalls).toBe(1); | ||
| expect(statusServiceSummary(null, { installed: true, summary: "registered" }, false)) | ||
| .toContain("registered but NOT serving"); | ||
| }); | ||
|
|
||
| test("service summary never contradicts a present negative live startup verdict", () => { | ||
| const live = { | ||
| ...startupPayload(), | ||
| status: "at-risk", | ||
| rebootSafe: false, | ||
| protection: "none", | ||
| serviceInstalled: false, | ||
| serviceRunning: false, | ||
| serviceViable: false, | ||
| recommendedCommand: "ocx service repair", | ||
| } as StartupHealth; | ||
| const summary = statusServiceSummary(live, { installed: true, summary: "healthy local service" }, true); | ||
| expect(summary).toContain("live startup reports service absent, not running, not viable"); | ||
| expect(summary).toContain("ocx service repair"); | ||
| expect(summary).not.toContain("healthy local service"); | ||
| }); | ||
|
|
||
| test("fails closed when the runtime attestation cannot bind the live PID", async () => { | ||
| const observed = await fetchLiveStartupHealth(LIVE, { | ||
| ...deps(startupPayload()), | ||
| readRuntime: () => null, | ||
| }); | ||
| expect(observed).toBeNull(); | ||
| }); | ||
| }); | ||
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.