test: add WP7-02 controlled real contract gate
Dada P0-A isolated Windows CI / validate-and-package (push) Failing after 1m36s
Dada P0-A isolated Windows CI / validate-and-package (push) Failing after 1m36s
This commit is contained in:
@@ -1,3 +1,13 @@
|
||||
import { existsSync, readFileSync } from "node:fs";
|
||||
|
||||
import {
|
||||
WP7_02_MODEL_IDS,
|
||||
buildBlockedModelEvidence,
|
||||
inspectAiGatewayReadiness,
|
||||
probeAiGatewayCredentialTargets,
|
||||
writeBlockedModelEvidence,
|
||||
} from "./lib/wp7-02-external-contract.mjs";
|
||||
|
||||
const allowedServices = new Set(["ai", "ai-gateway-service-id", "resend", "amap"]);
|
||||
|
||||
function argument(name) {
|
||||
@@ -8,20 +18,81 @@ function argument(name) {
|
||||
const service = argument("--service");
|
||||
const runId = argument("--run-id");
|
||||
const model = argument("--model");
|
||||
const candidatePath = argument("--candidate-record") ?? process.env.DADA_WP7_01_CANDIDATE_RECORD;
|
||||
const configPath = argument("--config-manifest") ?? process.env.DADA_WP7_02_MODEL_CONFIG_MANIFEST;
|
||||
const evidenceDirectory = argument("--evidence-dir");
|
||||
const confirmed = process.argv.includes("--confirm-controlled-real");
|
||||
const readinessOnly = process.argv.includes("--readiness-only");
|
||||
|
||||
if (!allowedServices.has(service) || !runId || ((service === "ai" || service === "ai-gateway-service-id") && !model)) {
|
||||
console.error("Usage: pnpm validate:external -- --service <ai|ai-gateway-service-id|resend|amap> --run-id <id> [--model <model-id>]");
|
||||
if (!allowedServices.has(service) || !runId || ((service === "ai" || service === "ai-gateway-service-id") && !WP7_02_MODEL_IDS.includes(model))) {
|
||||
console.error("Usage: pnpm validate:external -- --service <ai|ai-gateway-service-id|resend|amap> --run-id <id> [--model <model-id>] [--readiness-only]");
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
console.log(
|
||||
JSON.stringify({
|
||||
blocker: service === "ai" || service === "ai-gateway-service-id" ? "real_gateway_credentials_absent" : undefined,
|
||||
if (service !== "ai" && service !== "ai-gateway-service-id") {
|
||||
console.log(JSON.stringify({
|
||||
blocker: undefined,
|
||||
mode: "mock",
|
||||
model,
|
||||
real_calls: 0,
|
||||
run_id: runId,
|
||||
service,
|
||||
status: service === "ai" || service === "ai-gateway-service-id" ? "not_applicable" : "not_applicable_for_TASK-WP0-01",
|
||||
}),
|
||||
);
|
||||
status: "not_applicable_for_TASK-WP0-01",
|
||||
}));
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
try {
|
||||
const candidateRecord = candidatePath && existsSync(candidatePath) ? JSON.parse(readFileSync(candidatePath, "utf8")) : undefined;
|
||||
const configManifest = configPath && existsSync(configPath) ? JSON.parse(readFileSync(configPath, "utf8")) : undefined;
|
||||
const modelConfig = Array.isArray(configManifest?.models)
|
||||
? configManifest.models.find((entry) => entry?.model_id === model)
|
||||
: undefined;
|
||||
|
||||
if (!candidateRecord) {
|
||||
console.log(JSON.stringify({
|
||||
blockers: ["candidate_record_absent", ...(confirmed ? [] : ["explicit_confirmation_absent"])],
|
||||
mode: "controlled_real_not_executed", model, real_calls: 0, run_id: runId, service, status: "externally_blocked",
|
||||
}));
|
||||
process.exit(3);
|
||||
}
|
||||
|
||||
const readiness = inspectAiGatewayReadiness({
|
||||
candidateRecord,
|
||||
confirmed,
|
||||
credentialTargets: probeAiGatewayCredentialTargets(),
|
||||
modelConfig,
|
||||
modelId: model,
|
||||
});
|
||||
if (!readinessOnly && readiness.blockers.length === 0) readiness.blockers.push("controlled_real_executor_unavailable");
|
||||
readiness.status = readiness.blockers.length > 0 ? "externally_blocked" : "ready_for_controlled_execution";
|
||||
if (readiness.blockers.length > 0 && evidenceDirectory) {
|
||||
const evidence = buildBlockedModelEvidence({
|
||||
blockers: readiness.blockers,
|
||||
candidateRecord,
|
||||
modelConfig: readiness.model_config,
|
||||
modelId: model,
|
||||
runId,
|
||||
});
|
||||
writeBlockedModelEvidence(evidenceDirectory, evidence);
|
||||
}
|
||||
console.log(JSON.stringify({
|
||||
blockers: readiness.blockers,
|
||||
candidate_build_commit: readiness.candidate.build_commit,
|
||||
mode: readinessOnly ? "readiness_only" : "controlled_real_not_executed",
|
||||
model,
|
||||
planned_provider_requests_max: readiness.plan.planned_provider_requests_max,
|
||||
planned_request_breakdown: readiness.plan.planned_request_breakdown,
|
||||
quota_impact: readiness.plan.quota_impact,
|
||||
real_calls: 0,
|
||||
run_id: runId,
|
||||
service,
|
||||
status: readiness.status,
|
||||
}));
|
||||
process.exit(readiness.blockers.length > 0 ? 3 : 0);
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
const code = /^WP7_02_[A-Z0-9_:]+$/.test(message) ? message : "WP7_02_EXTERNAL_VALIDATION_FAILED";
|
||||
console.error(JSON.stringify({ code, model, real_calls: 0, run_id: runId, service, status: "failed" }));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user