Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/api/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ import { buildAutomationState } from "../services/automation-state";
import { loadGatePrecisionReport } from "../services/gate-precision";
import { computeOpsStats, isOpsEnabled, resolveOpsManifestOverride } from "../review/ops-wire";
import { deleteLiveOverride, listOverrideAudit, loadOverride, loadShadowOverride, sanitizeOverridePayload, authoritativeGateOverride, toLiveGateThresholdFields, type StorageEnv } from "../review/auto-apply";
import { handleInternalCalibration, handleInternalDecision, type OpsAgentConfig } from "../review/ops";
import { handleInternalCalibration, handleInternalDecision, handleInternalStatus, type OpsAgentConfig } from "../review/ops";
import { computeParityReadiness, isParityAuditEnabled } from "../review/parity-wire";
import { computePredictedGateAgreement } from "../review/predicted-gate-agreement";
import { computeContributorGateEval, contributorFairnessFlags, computeBlendedContributorGateEval, contributorGlobalFairnessFlags } from "../review/contributor-gate-eval";
Expand Down Expand Up @@ -4690,6 +4690,12 @@ export function createApp() {
// Fails safe to an empty-but-shaped report when there is no review signal yet. Aggregate counts only.
app.get("/v1/internal/calibration", (c) => handleInternalCalibration(c.req.raw, c.env, internalOpsAgentConfig(c.env)));

// Operator per-agent health/verdict breakdown, manual-rate, stuck targets, config-invariant violations, and
// recent decisions (#8904 — the handler existed and was unit-tested but its route was never registered, unlike
// its two siblings above). Bearer-gated by the `/v1/internal/*` middleware (INTERNAL_JOB_TOKEN);
// handleInternalStatus re-checks that same token. Aggregate review state only — no PR content.
app.get("/v1/internal/status", (c) => handleInternalStatus(c.req.raw, c.env, internalOpsAgentConfig(c.env)));

// Operator calibration trend (#8113): weekly per-rule fired/decided/precision plus backtest-run verdict
// counts, re-bucketed live from audit_events (no cron rollup — see rule-calibration-trend.ts's header). Sibling
// of /v1/internal/calibration above, same INTERNAL_JOB_TOKEN gate via the /v1/internal/* middleware.
Expand Down
29 changes: 29 additions & 0 deletions test/unit/routes-internal-decision-calibration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,32 @@ describe("GET /v1/internal/calibration — operator calibration endpoint", () =>
expect(((await res.json()) as { project: string }).project).toBe("loopover");
});
});

// #8904: handleInternalStatus was fully implemented + unit-tested but its route was never registered in
// routes.ts, unlike its two siblings above. These assert the newly-wired route end-to-end.
describe("GET /v1/internal/status — operator agent-health endpoint (#8904)", () => {
it("401s without the internal token (the /v1/internal/* middleware gate)", async () => {
const app = createApp();
const env = createTestEnv();
expect((await app.request("/v1/internal/status", {}, env)).status).toBe(401);
expect((await app.request("/v1/internal/status", { headers: { authorization: "Bearer nope" } }, env)).status).toBe(401);
});

it("200s with the agent-health report (fail-safe empty), scoped to the app slug", async () => {
const app = createApp();
const env = createTestEnv(); // GITHUB_APP_SLUG defaults to "loopover-orb"
const res = await app.request("/v1/internal/status", { headers: bearer(env) }, env);
expect(res.status).toBe(200);
const body = (await res.json()) as {
project: string;
counts: { byStatus: unknown; byVerdict: unknown };
health: { manualRate: number };
};
expect(body.project).toBe("loopover-orb");
expect(body.counts).toBeTruthy();
expect(body.counts.byStatus).toBeTruthy();
expect(typeof body.health.manualRate).toBe("number");
// Privacy: aggregate review state only — never actor logins / trust internals.
expect(JSON.stringify(body)).not.toMatch(/login|actor|reward|payout|trust|wallet|hotkey/i);
});
});