Files
reverse-engineering-anything/vitest.config.ts
T
morluto 4126698407 feat(mcp): project compact input schemas into the portable advertised dialect (#10632)
* test(mcp): check advertised schemas against a portable dialect in every profile

* fix(mcp): re-emit advertised patterns in a portable regex grammar

* fix(mcp): present discover_tools input through the selected profile

The hot-cold catalog registered discover_tools directly with the SDK, so
the default compact input profile still advertised its canonical schema,
including page-size defaults clients apply on their own (#5322). Route
every listed input schema, transport discovery included, through one
server-owned presentation, and pass the selected presentation to the
deferred server, which serves recorded tool schemas but not discovery.

* fix(mcp): keep the Evidence union on described borrowed inputs

borrowEvidenceInput installed its advertised projection on one schema
instance. A call site's .describe() rebuilds the schema from its
definition, so match_native_functions advertised left and right as
unconstrained values in every input profile. Install the projection in
the borrowed parser's constructor so derived schemas keep it, for both
borrowed inputs and borrowed arrays.

* fix(mcp): validate advertised dialect by selected profile

* fix(mcp): preserve schema widening through references

* feat(mcp): project compact input schemas into the portable advertised dialect

One projection (advertisedDialectProjection.ts) owns the compact input
advertisement: one type per node, items on every array, string literals
as enums, oneOf widened to anyOf, allOf merged, tuples as element unions,
exclusive bounds made inclusive, and every keyword outside the dialect
dropped. Each rewrite is exact or widening; server validation is
unchanged. The root description and sentences for dropped cross-field
constraints move to the tool description, which Codex and Zed keep.

The compact baseline falls to nullable values only (29), which the
dialect cannot express without narrowing an input. The gateway shape
repairs (typeArrayItemUnions, hasGatewayIncompatibleShape), the second
dependentRequired-to-prose copy and the strict-gateway test denylist are
removed; the dialect checker gates the inline presentation instead.

* fix(mcp): refuse zero-padded repeat bounds and record host-specific path patterns

* fix(mcp): keep projected schemas permissive

* fix(mcp): keep references valid when presentation widens their targets

* fix(mcp): keep a single union branch's closure scoped to its properties

* fix(mcp): keep an allOf member's tuple tail with its own positions

* fix(mcp): relax references into negations and conditionals presentation may remove

* test(mcp): select the borrowed Evidence contract from its family

* fix(mcp): keep astral literals and dynamic references widening in every mode

* fix(mcp): omit astral literals and relax untracked references when presentation widens

* fix(mcp): read reference pointers by schema position, not segment spelling

* fix(mcp): protect references into collapsing boolean unions and keep referencing branches out of the collapse

* fix(mcp): keep reduced schemas open when their root admits names by pattern

* test(mcp): keep the reduced-schema pattern case outside the size-limited block

* fix(mcp): omit patterns whose classes name astral characters

* fix(mcp): decide union collapse and pointer protection from canonical branches

* docs(mcp): document non-u astral matching and pin BMP agreement across V8 modes

* fix(mcp): keep prototype-named properties as own properties in the dialect projection

* test(mcp): expect the advertised base64 schema to omit the unbounded pad-bit probe

* fix(mcp): protect references into unevaluated keywords lost evaluation removes

* fix(mcp): emit stack-safe classes with non-ASCII members and protect draft-07 reference siblings

* fix(mcp): protect references into literal siblings of relaxed draft-07 references

* feat(mcp): omit output schemas from tools/list by default (#10646)

* feat(mcp): omit output schemas from tools/list by default

No surveyed model API reads an output schema, MCP client validators
repeat REA's own result validation, and complete output schemas were
about 92% of the default tools/list. REA_MCP_OUTPUT_SCHEMA_PROFILE now
resolves to off through one owner (resolveMcpOutputSchemaProfile);
compact and full remain selectable. structuredContent is still
delivered, and the deferred server serves both off and full from the
recorded catalog with the matching recorded identity.

Tests and artifact verifiers that validate results against complete
advertised output contracts select full explicitly.

* fix(mcp): select schemas in verification workflows

* fix(mcp): select complete output schemas in the Electron verifier

* fix(mcp): select complete output schemas in standalone verifier probes

* fix(mcp): select complete output schemas in every verifier transport

* test(mcp): select full output schemas in packet and signal schema checks

* fix(mcp): validate the doctor probe reply against the canonical output contract (#10655)

* fix(mcp): validate the doctor probe reply against the canonical output contract

* test(mcp): replay doctor probe validation under every output profile

* test(mcp): accept typed-branch nullable unions in the advertised dialect (#10649)

* test(mcp): select full output schemas in HTTP session workflows

* fix(mcp): keep the Evidence union on described borrowed inputs (#10597)

* fix(mcp): keep the Evidence union on described borrowed inputs

borrowEvidenceInput installed its advertised projection on one schema
instance. A call site's .describe() rebuilds the schema from its
definition, so match_native_functions advertised left and right as
unconstrained values in every input profile. Install the projection in
the borrowed parser's constructor so derived schemas keep it, for both
borrowed inputs and borrowed arrays.

* test(mcp): select the borrowed Evidence contract from its family

* docs(mcp): admit baseline growth only for restored contract declarations

* fix(mcp): state reduced multi-type properties as typed branches, not type lists

The reduced fallback derived a property's types and emitted them as a type
list, which Gemini, Moonshot and Ark reject. A property whose canonical
schema is anyOf string and number therefore traded a typed union for a
rejected construct when the inline projection fell back. Emit one type, or
anyOf typed branches, so [T, null] becomes the dialect's nullable union.
2026-11-15 18:26:13 +08:00

239 lines
8.2 KiB
TypeScript

import { realpathSync } from "node:fs";
import { availableParallelism, tmpdir } from "node:os";
import { join } from "node:path";
import { defineConfig } from "vitest/config";
import { parseCLI } from "vitest/node";
import {
BUILT_TEST_PROJECTS,
SOURCE_TEST_PROJECTS,
} from "./scripts/lib/test-projects.mjs";
import { CiTestSequencer } from "./tests/ciTestSequencer.js";
import {
COVERAGE_DEADLINE_SCALE,
HOSTED_RUNNER_DEADLINE_SCALE,
LONG_RUNNING_DEADLINE_MS,
remainingTestDeadline,
TEST_DEADLINE_MS as BASE_TEST_DEADLINE_MS,
} from "./tests/support/testDeadlines.js";
// Playwright's registry does not derive a cache directory for Termux's
// `android` platform. Match the production CLI fallback before workers import
// browser modules.
if (
process.platform === "android" &&
process.env.PLAYWRIGHT_BROWSERS_PATH === undefined
) {
const cacheRoot =
process.env.XDG_CACHE_HOME ?? join(process.env.HOME ?? ".", ".cache");
process.env.PLAYWRIGHT_BROWSERS_PATH = join(cacheRoot, "ms-playwright");
}
const CANONICAL_TEMPORARY_DIRECTORY = realpathSync(tmpdir());
// Use Vitest's option parser so explicit false and spaced shard values retain
// their meaning. Unknown worker/embedding arguments are not Vitest options.
const { options: testOptions } = parseCLI(
["vitest", ...process.argv.slice(2)],
{ allowUnknownOptions: true },
);
const COVERAGE_ENABLED = testOptions.coverage?.enabled === true;
const COVERAGE_SHARD = testOptions.shard !== undefined;
// Bound concurrency by the runner rather than command locks. A hosted CI job
// owns its whole four-core runner, so it may use every core; other hosts stay
// at two workers because developers and agents share them with other checks.
const DEDICATED_CI_RUNNER = process.env.GITHUB_ACTIONS === "true";
const MAX_TEST_WORKERS = Math.min(
DEDICATED_CI_RUNNER ? 4 : 2,
availableParallelism(),
);
// A test deadline only turns a hang into a named failure; it is not a
// performance assertion. Projects own it so tests do not hard-code host speed.
// Built projects launch compiled CLI, MCP, and provider processes while other
// lanes share the runner, and coverage instrumentation slows every lane. Hosted
// CI runs a worker per core, so CPU-bound cases there share every core with
// other workers and their subprocesses.
const DEADLINE_SCALE =
(COVERAGE_ENABLED ? COVERAGE_DEADLINE_SCALE : 1) *
(DEDICATED_CI_RUNNER ? HOSTED_RUNNER_DEADLINE_SCALE : 1);
const TEST_DEADLINE_MS = {
source: BASE_TEST_DEADLINE_MS.source * DEADLINE_SCALE,
built: BASE_TEST_DEADLINE_MS.built * DEADLINE_SCALE,
} as const;
// Vitest's one-second `expect.poll` default is a host-speed guess. A poll the
// project owns waits as long as its test may run, less a reporting reserve, so
// a condition that never holds still fails with the poll's own diagnostics.
const pollPolicy = (deadlineMs: number) => {
const timeout = remainingTestDeadline(deadlineMs, 0);
return timeout === undefined ? {} : { timeout };
};
const TEST_PROJECTS = [...SOURCE_TEST_PROJECTS, ...BUILT_TEST_PROJECTS];
const PROJECT_POLICIES = {
domain: {
pool: "threads" as const,
maxWorkers: MAX_TEST_WORKERS,
// Domain and contract modules are pure and own no process-global state, so
// per-file module isolation adds startup cost without protecting a seam.
},
services: {
pool: "threads" as const,
maxWorkers: MAX_TEST_WORKERS,
// Service tests use recording ports and own no process-global state. Share
// their module graph so file startup does not dominate the lane.
},
adapters: { pool: "forks" as const, maxWorkers: MAX_TEST_WORKERS },
composition: {
pool: "threads" as const,
maxWorkers: MAX_TEST_WORKERS,
// Composition tests use provider-neutral sessions and test-scoped cleanup;
// sharing their immutable module graph avoids per-file startup work.
},
boundary: { pool: "forks" as const, maxWorkers: MAX_TEST_WORKERS },
"cli-boundary": {
pool: "forks" as const,
maxWorkers: MAX_TEST_WORKERS,
// CLI tests create fresh command instances or subprocesses and own their
// cleanup. Reuse the immutable graph; module mocks belong in process-global.
// The shared source/contract graph also needs transient schema/help space.
// Ordinary CI exhausted 384 MiB after earlier files warmed that graph.
// Use the measured 512 MiB budget with the same bounded concurrency.
execArgv: ["--max-old-space-size=512"],
},
"process-boundary": {
pool: "forks" as const,
maxWorkers: MAX_TEST_WORKERS,
// Process-tree observations share host sampling resources; keep this small
// lane serial while the independent projects run together.
fileParallelism: false,
sequence: { groupOrder: 1 },
},
"mcp-boundary": {
pool: "threads" as const,
maxWorkers: MAX_TEST_WORKERS,
// Each file creates and closes an explicit in-memory MCP session. Reuse the
// immutable server graph so module startup does not outweigh transport work.
},
acceptance: { pool: "forks" as const, maxWorkers: MAX_TEST_WORKERS },
"process-global": { pool: "forks" as const, maxWorkers: MAX_TEST_WORKERS },
conformance: {
pool: "threads" as const,
maxWorkers: MAX_TEST_WORKERS,
// Contract cases use recording providers and own no process-global state.
},
evaluation: {
pool: "threads" as const,
maxWorkers: MAX_TEST_WORKERS,
// Evaluator tests inspect deterministic inputs without mutating shared state.
},
};
const ZERO_COVERAGE_THRESHOLDS = {
statements: 0,
branches: 0,
functions: 0,
lines: 0,
"src/domain/**": {
statements: 0,
branches: 0,
functions: 0,
lines: 0,
},
"src/contracts/**": {
statements: 0,
branches: 0,
functions: 0,
lines: 0,
},
};
const projects = TEST_PROJECTS.map((project) => {
const policy =
PROJECT_POLICIES[project.name as keyof typeof PROJECT_POLICIES];
if (!policy)
throw new Error(`Missing test runner policy for ${project.name}`);
return {
extends: true as const,
test: {
name: project.name,
include: [...project.include],
...(project.exclude ? { exclude: [...project.exclude] } : {}),
isolate: project.isolate !== false,
testTimeout: TEST_DEADLINE_MS[project.group],
hookTimeout: TEST_DEADLINE_MS[project.group],
expect: { poll: pollPolicy(TEST_DEADLINE_MS[project.group]) },
...policy,
},
};
});
export default defineConfig({
test: {
env: {
TMPDIR: CANONICAL_TEMPORARY_DIRECTORY,
// In-process servers advertise complete output schemas so SDK clients
// validate every structured result. Tests of the default (`off`) set
// the profile, or pass an environment without it, explicitly.
REA_MCP_OUTPUT_SCHEMA_PROFILE: "full",
},
maxWorkers: MAX_TEST_WORKERS,
projects,
...(process.env.REA_CI_TEST_HISTORY
? { sequence: { sequencer: CiTestSequencer } }
: {}),
retry: 0,
reporters: ["default"],
runner: "./tests/processOwnershipRunner.ts",
testTimeout: TEST_DEADLINE_MS.source,
hookTimeout: TEST_DEADLINE_MS.source,
expect: { poll: pollPolicy(TEST_DEADLINE_MS.source) },
// Deadline probes compare what Vitest applies with the configured policy.
provide: { testDeadlineScale: DEADLINE_SCALE },
tags: [
{
name: "long-running",
description:
"A bounded workload that needs more than its project's deadline",
timeout: LONG_RUNNING_DEADLINE_MS * DEADLINE_SCALE,
},
],
coverage: {
enabled: false,
provider: "v8",
reportsDirectory: join(
tmpdir(),
`rea-vitest-coverage-${String(process.pid)}`,
),
include: ["src/**"],
thresholds: COVERAGE_SHARD
? ZERO_COVERAGE_THRESHOLDS
: {
statements: 65,
branches: 60,
functions: 60,
lines: 68,
"src/domain/**": {
statements: 80,
branches: 75,
functions: 75,
lines: 80,
},
"src/contracts/**": {
statements: 85,
branches: 80,
functions: 80,
lines: 85,
},
},
reporter: ["text", "text-summary"],
},
},
});
declare module "vitest" {
export interface ProvidedContext {
readonly testDeadlineScale: number;
}
}