Files
Jyotisha/frontend/tests/membership-fair-use-contract.test.ts
T
Jesse_ChenandClaude Opus 5.5 eb773f1299 refactor(rectification): split POST /api/rectification/agent into branch handlers
Move-only (TASK-rectification-code-split-20260926 T2/T4). No behavior, API,
copy, DB, Skill, billing or scoring change.

- route.ts: 1077 -> 152 lines; POST 927 -> 114. It builds the Supabase
  clients (so the setup-failure mapping stays here) and assembles:
  agent-route-request.ts (auth / product / schema / flag / Case-Session
  binding), agent-route-typed-message.ts (declared-window reply, typed-answer
  preflight, unfocused classification), agent-route-structured-choice.ts,
  agent-route-agent-turn.ts (opening / read-only / typed agent stream and its
  exit gate), agent-route-billing.ts, agent-route-support.ts (schema, one-shot
  NDJSON reply, context types).
- The four mutable preflight lets (expectedWrite, collectIntent,
  writeClassified, classifierDiagnostic) that crossed branches are one
  turnState object; values and flow unchanged.
- Tests: whole-source contracts read tests/rectification-agent-route-surface.ts;
  the typed fast-path slice is rebuilt from the new files; billing,
  declared-window and structured-choice slices now call the handlers
  (billing in a child process because feature-pricing imports server-only),
  each with 原值/新值/原因. Route growth caps added.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017eEAG8HD3mm8gsKXgk8uU8
2026-09-26 19:40:07 +08:00

29 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import test from "node:test";
import { rectificationAgentRouteSurface } from "./rectification-agent-route-surface.ts";
const pricingSimulation = readFileSync(
fileURLToPath(new URL("../src/lib/pricing-simulation.ts", import.meta.url)),
"utf8",
);
const productManagement = readFileSync(
fileURLToPath(new URL("../src/components/admin/product-management.tsx", import.meta.url)),
"utf8",
);
// 原值: 读 app/api/rectification/agent/route.ts 单文件。新值: rectificationAgentRouteSurface(route.ts + 拆出的 agent-route-*.ts,见 rectification-agent-route-surface.ts)。原因: TASK-rectification-code-split-20260926 只搬不改,整文件断言跟着代码走;切片断言另行改写。
const rectificationRoute = rectificationAgentRouteSurface;
test("documents billingLimit as a circuit breaker rather than a chat quota", () => {
assert.match(pricingSimulation, /billingLimit is an anomaly-account circuit breaker/);
assert.match(productManagement, /billingLimit 仅用于异常账号熔断/);
assert.match(productManagement, /minuteLimit 与 dayLimit/);
assert.match(productManagement, /生时校正与完整报告单独计费/);
});
test("fair-use billing-period messaging avoids promising a quota", () => {
assert.match(rectificationRoute, /code === "fair_use_billing_period"[\s\S]*安全熔断,请稍后再试或联系支持/);
assert.doesNotMatch(rectificationRoute, /fair_use_billing_period[\s\S]{0,240}配额用完/);
});