test: close conversational rectification review gaps
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
||||
} from "../../../lib/conversational-rectification/errors.ts";
|
||||
import {
|
||||
createConversationalRectificationService,
|
||||
conversationalRectificationTelemetryOutcome,
|
||||
evidencePredatesBirthDate,
|
||||
type ConversationalRectificationPacketBuildInput,
|
||||
type ConversationalRectificationService,
|
||||
@@ -691,7 +692,7 @@ async function dispatch(
|
||||
}
|
||||
|
||||
function telemetryPhase(
|
||||
turn: ConversationalRectificationTurn | null,
|
||||
turn: Pick<ConversationalRectificationTurn, "status"> | null,
|
||||
): ConversationalRectificationTelemetryPayload["phase"] {
|
||||
switch (turn?.status) {
|
||||
case "active": return "collecting_evidence";
|
||||
@@ -740,6 +741,7 @@ export function createBirthTimeConversationPostHandler(
|
||||
);
|
||||
dependencies.createRequestId?.(request);
|
||||
let actionKind: ConversationalRectificationTelemetryPayload["actionKind"] = "unknown";
|
||||
let service: BirthTimeConversationRouteService | null = null;
|
||||
try {
|
||||
const authenticated = await dependencies.authenticate(request);
|
||||
if (!authenticated) throw new ConversationalRectificationError("authentication_required");
|
||||
@@ -748,29 +750,32 @@ export function createBirthTimeConversationPostHandler(
|
||||
if (!parsed.success) throw new ConversationalRectificationError("invalid_command");
|
||||
actionKind = parsed.data.type;
|
||||
|
||||
const service = await dependencies.createService(authenticated);
|
||||
service = await dependencies.createService(authenticated);
|
||||
const turn = await dispatch(service, authenticated.userId, parsed.data);
|
||||
const outcome = conversationalRectificationTelemetryOutcome(service);
|
||||
telemetry({
|
||||
protocol: "conversational-evidence-v3",
|
||||
phase: telemetryPhase(turn),
|
||||
actionKind,
|
||||
resultCategory: "success",
|
||||
latencyBucket: conversationalRectificationLatencyBucket(now() - startedAt),
|
||||
billingState: actionKind === "start" ? "unknown" : "unchanged",
|
||||
billingState: outcome?.billingState ?? (actionKind === "start" ? "unknown" : "unchanged"),
|
||||
errorCategory: "none",
|
||||
deploymentSha,
|
||||
});
|
||||
return Response.json(turn);
|
||||
} catch (error) {
|
||||
const publicError = toConversationalRectificationPublicError(error);
|
||||
const outcome = service ? conversationalRectificationTelemetryOutcome(service) : null;
|
||||
dependencies.log?.({ code: publicError.code });
|
||||
telemetry({
|
||||
protocol: "conversational-evidence-v3",
|
||||
phase: "entry",
|
||||
phase: telemetryPhase(outcome?.caseStatus ? { status: outcome.caseStatus } : null),
|
||||
actionKind,
|
||||
resultCategory: telemetryResultCategory(publicError.status),
|
||||
latencyBucket: conversationalRectificationLatencyBucket(now() - startedAt),
|
||||
billingState: publicError.code === "billing_failed" ? "unknown" : "not_applicable",
|
||||
billingState: outcome?.billingState
|
||||
?? (publicError.code === "billing_failed" ? "unknown" : "not_applicable"),
|
||||
errorCategory: telemetryErrorCategory(publicError.code),
|
||||
deploymentSha,
|
||||
});
|
||||
|
||||
@@ -7,15 +7,12 @@ type Check = {
|
||||
};
|
||||
|
||||
const jyotishApiBase = process.env.JYOTISH_API_BASE ?? "http://127.0.0.1:5200";
|
||||
const gitCommit =
|
||||
process.env.GITHUB_SHA
|
||||
?? process.env.VERCEL_GIT_COMMIT_SHA
|
||||
?? process.env.NEXT_PUBLIC_GIT_COMMIT
|
||||
?? "unknown";
|
||||
const rectificationV3CreationEnabled =
|
||||
process.env.RECTIFICATION_V3_CREATE_ENABLED?.trim().toLowerCase() !== "false";
|
||||
const rectificationV3MigrationsReady =
|
||||
process.env.RECTIFICATION_V3_MIGRATIONS_READY?.trim().toLowerCase() === "true";
|
||||
function deployedGitCommit(): string {
|
||||
return process.env.GITHUB_SHA
|
||||
?? process.env.VERCEL_GIT_COMMIT_SHA
|
||||
?? process.env.NEXT_PUBLIC_GIT_COMMIT
|
||||
?? "unknown";
|
||||
}
|
||||
|
||||
function envCheck(names: string[]): Check {
|
||||
const missing = names.filter((name) => !process.env[name]);
|
||||
@@ -62,6 +59,12 @@ function aggregate(checks: Record<string, Check>) {
|
||||
}
|
||||
|
||||
export async function GET() {
|
||||
const gitCommit = deployedGitCommit();
|
||||
const rectificationV3CreationEnabled =
|
||||
process.env.RECTIFICATION_V3_CREATE_ENABLED?.trim().toLowerCase() !== "false";
|
||||
const rectificationV3MigrationsReady =
|
||||
process.env.RECTIFICATION_V3_MIGRATIONS_READY?.trim().toLowerCase() === "true";
|
||||
const smokeSha = process.env.RECTIFICATION_V3_SYNTHETIC_SMOKE_SHA?.trim().toLowerCase() ?? "";
|
||||
const checks = {
|
||||
web: { status: "ok" } satisfies Check,
|
||||
supabasePublicConfig: envCheck(["NEXT_PUBLIC_SUPABASE_URL", "NEXT_PUBLIC_SUPABASE_ANON_KEY"]),
|
||||
@@ -70,9 +73,12 @@ export async function GET() {
|
||||
jyotishApi: await jyotishApiCheck(),
|
||||
};
|
||||
const status = aggregate(checks);
|
||||
const rectificationV3Ready = rectificationV3CreationEnabled
|
||||
const deploymentHasFullSha = /^[0-9a-f]{40}$/.test(gitCommit);
|
||||
const smokeMatchesDeployment = deploymentHasFullSha && smokeSha === gitCommit;
|
||||
const rectificationV3Ready = status === "ok"
|
||||
&& rectificationV3CreationEnabled
|
||||
&& rectificationV3MigrationsReady
|
||||
&& gitCommit !== "unknown";
|
||||
&& smokeMatchesDeployment;
|
||||
return NextResponse.json(
|
||||
{
|
||||
status,
|
||||
@@ -85,7 +91,7 @@ export async function GET() {
|
||||
protocol: "conversational-evidence-v3",
|
||||
newCaseCreation: rectificationV3CreationEnabled ? "enabled" : "paused",
|
||||
migrations: rectificationV3MigrationsReady ? "ready" : "unverified",
|
||||
syntheticSmoke: "required",
|
||||
syntheticSmoke: smokeMatchesDeployment ? "matched" : "pending",
|
||||
readyForNewCases: rectificationV3Ready,
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user