mirror of
https://github.com/callstack/agent-device.git
synced 2026-09-14 20:06:34 +08:00
76453add71
* refactor: pnpm workspace + @agent-device/kernel pilot (#1490 W0) Extend the workspace with packages/* and move the kernel behind an enforced public API: packages/kernel with nine consumer-earned subpath exports (errors, device, snapshot, contracts, collections, rect, redaction, daemon-error, bounds — the last absorbed from utils as Rect vocabulary). Every kernel import repo-wide becomes the @agent-device/kernel/<sub> specifier; kernel tests move to src/__tests__/kernel/ and exercise the package surface. The root declares the package in devDependencies (workspace:*), tsdown bundles it (noExternal) so the published artifact and its runtime dependency manifest are unchanged. Gate rewiring in the same change, per the W0 brief: - R1 kernel-sink retires (physically subsumed); new R11 package-boundaries guards no-root-back-imports, relative tunnelling past exports maps, undeclared workspace deps, and non-exported subpaths, with runtime resolution pins via import.meta.resolve. - resolveImportEdges and mutation ownership follow workspace specifiers through exports maps, keeping R4 cycle checks, depgraph, and derived test ownership connected across the seam (kernel-errors still owns 495 tests). listSourceFiles includes packages/*/src. - kernel becomes an unranked zone; mutation registry, stryker mutate globs, and the mutation-affected workflow path filter move to packages/kernel/src/errors.ts. - check:affected gains packages/ ownership (manifests fail open); vitest and coverage include packages/*/src; fallow ignores packages/** (its resolver cannot follow workspace specifiers). - The affected-selector CI job installs dependencies: its closure now crosses workspace specifiers, and the R8 relative exception is unsafe for production src files (Node ESM does not realpath, so dual specifier/relative loads would instantiate modules twice). The R8 zero-dep set is pinned empty with that rationale. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FUv7bvbWNryuXgSBuqTtep * fix: address W0 review — mutation sandbox, exports-map resolution, tsc -b Review findings on #1494, all five: 1. contracts-schema-public.test.ts reads the kernel source at its packages/ path (fs access invisible to the codemod and typecheck). 2. Mutation lane: Stryker sandboxes the tree but pnpm's node_modules symlink resolves @agent-device/* back to the real repo, so mutants in the sandbox never load and vitest.related finds no tests. vitest.mutation.config.ts now aliases each EXPORTED specifier to its source (derived from exports maps, never a wildcard), keeping resolution inside the mutated tree. Validated: kernel-errors module runs end to end (dry run 3,984 tests, mutants killed, exit 0). 3. Layering/depgraph resolve workspace specifiers through the exports-derived map (workspaceSpecifierTargets) instead of reconstructing paths, so '.'-facade packages resolve; the positional fallback remains only for map-less fixtures (P0 pin). 4. Per-package project references implemented: packages/kernel is composite (emitDeclarationOnly -> dist-types, gitignored), the root references it, and typecheck becomes tsc -b — probed to catch type errors on both sides under TypeScript 7 native. 5. R11's relative-route exception now requires membership in an actual R8 zero-dep job closure (zeroDepClosureFiles walks entries), not mere scripts/ placement — closing the dual-instantiation bypass. Also from review discussion: daemon-error moves out of the kernel package to src/client/ — its consumers (cli, client facade) rehydrate wire DaemonErrors client-side; the daemon only produces them. Kernel drops to 8 exported subpaths before any of them ship. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FUv7bvbWNryuXgSBuqTtep * refactor: one exports-map reader for mutation alias and ownership Fallow flagged workspaceExportAliases (cognitive 15, CRAP 90). The manifest-reading logic already exists as workspaceSpecifierTargets in scripts/layering/package-boundaries.ts, so both the Stryker sandbox alias table and the mutation ownership walker now consume it instead of carrying near-clones. Behavior unchanged; mutation suite 45/45 and changed-code fallow green. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FUv7bvbWNryuXgSBuqTtep * fix: composite kernel without a root references edge FreeRange runs plain `tsc -p tsconfig.json`, and a root `references` entry makes non-build-mode TypeScript demand the referenced project's built declarations (TS6305) — a standing "build first" tax on every plain -p consumer (fr, editors). Keep the per-package composite project and build it in typecheck (`tsc -b packages/kernel` before the root and examples/sdk passes), but drop the root references edge: root consumption resolves through exports to source, identical to runtime and to the bundler. Probed: plain -p green with no prebuilt output; kernel-side type errors still caught by its own build. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FUv7bvbWNryuXgSBuqTtep * fix: R11 uses the layering parser; mutation config is a fallow entry Review blockers on #1494: - R11's private single-quote regex could miss a double-quoted or re-export route into packages/*/src. specifierSites now delegates to the layering model's parseImports (both quote styles, side-effect imports, re-exports, dynamic imports), with direct regressions for each formerly-invisible form. - vitest.mutation.config.ts becomes a declared fallow entry instead of a tolerated unused-file finding: the full-repo audit now reports it reachable (unused files 2 -> 1; the remainder predates this PR). FreeRange clean-checkout evidence: with packages/kernel/dist-types and every *.tsbuildinfo deleted, `pnpm check:freerange` reports 0 findings on this head — the TS6305 topology died with the root references edge in the previous commit; check:freerange has no build precondition. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FUv7bvbWNryuXgSBuqTtep --------- Co-authored-by: Claude <noreply@anthropic.com>
133 lines
5.5 KiB
TypeScript
133 lines
5.5 KiB
TypeScript
import type { Reporter } from 'vitest/node';
|
|
import { defineConfig } from 'vitest/config';
|
|
import contentionRetryReporter, {
|
|
FAILURE_FILE_ENV,
|
|
} from './scripts/lib/contention-retry-reporter.ts';
|
|
import { SUBPROCESS_STUB_TESTS } from './scripts/lib/contention-retry.ts';
|
|
import slowTestGateReporter from './scripts/vitest-slow-test-reporter.ts';
|
|
|
|
// Tests that stub a real binary (adb/xcrun/npx) by mutating process.env.PATH and
|
|
// then spawn it, so each case waits real subprocess/retry/poll time. Run at the
|
|
// unit suite's default ~7x file parallelism they contend for CPU and their stub
|
|
// spawns get starved past an internal budget, so production takes a generic
|
|
// failure path and returns a different error than the assertion expects — a
|
|
// contention flake whose failing subset shifts between runs (see
|
|
// docs/agents/testing.md "tests must not wait real time"). Serialized below with
|
|
// per-file isolation so only one such file spawns stubs at a time, the same
|
|
// execution contract the pre-split android index.test.ts aggregation provided.
|
|
// The enumerated file list, with each file's contention reason and its owned
|
|
// waiver, lives in scripts/lib/contention-retry.ts — the same constant the CI
|
|
// single-retry policy (#1419) reads, so the two cannot drift.
|
|
export { SUBPROCESS_STUB_TESTS };
|
|
|
|
/** Every project loads the same setup, including the runner-timeout provenance hook. */
|
|
const SETUP_FILES = [
|
|
'scripts/vitest-runner-timeout-setup.ts',
|
|
'src/__tests__/hermetic-env-setup.ts',
|
|
'src/__tests__/process-memo-setup.ts',
|
|
];
|
|
|
|
/** Reporters for every lane; a `--reporter` flag would replace them, so no lane passes one. */
|
|
export function reporters(env: NodeJS.ProcessEnv = process.env): Array<string | Reporter> {
|
|
const gates: Array<string | Reporter> = ['default', slowTestGateReporter()];
|
|
// The failure sink drains the gates' verdicts, so it reports after them.
|
|
return env[FAILURE_FILE_ENV] ? [...gates, contentionRetryReporter()] : gates;
|
|
}
|
|
|
|
export default defineConfig({
|
|
test: {
|
|
// Wall-clock discipline: unit tests must not wait real time. Measured
|
|
// 2026-07-04: the suite's duration was bounded by files sleeping through
|
|
// production timeout budgets. slowTestThreshold surfaces creep in local
|
|
// output; the slow-test reporter enforces the ratchet (pinned offenders
|
|
// only shrink). Isolation stays ON and pool stays forks: measured
|
|
// --no-isolate = 205s wall vs 48s (module state thrashes across files),
|
|
// threads = no change.
|
|
slowTestThreshold: 500,
|
|
reporters: reporters(),
|
|
projects: [
|
|
{
|
|
test: {
|
|
name: 'unit-core',
|
|
// Explicit script entries keep maintained conformance guards in the
|
|
// unit suite without waking every ad-hoc *.test.ts under scripts/.
|
|
include: [
|
|
'src/**/*.test.ts',
|
|
'packages/*/src/**/*.test.ts',
|
|
'scripts/__tests__/help-conformance-bench.test.ts',
|
|
'scripts/__tests__/help-conformance-error-recovery-coverage.test.ts',
|
|
'scripts/__tests__/help-conformance-sample-outputs.test.ts',
|
|
'scripts/__tests__/help-conformance-topic-coverage.test.ts',
|
|
// Parses CI configuration only, so this action guard needs no device or subprocess lane.
|
|
'test/ci/upload-agent-device-artifacts.test.ts',
|
|
// The frozen replay-compat corpus (#1417): parse-only, no device or
|
|
// subprocess work, so it belongs in the fast lane next to the
|
|
// grammar it guards.
|
|
'test/replay-compat/corpus.test.ts',
|
|
// The Maestro conformance oracle runs via `node --test` in its own CI
|
|
// job (scripts/maestro-conformance), like the layering guard.
|
|
],
|
|
exclude: [...SUBPROCESS_STUB_TESTS],
|
|
setupFiles: SETUP_FILES,
|
|
},
|
|
},
|
|
{
|
|
// The subprocess-stub tests stub adb/xcrun/npx by mutating process.env
|
|
// (PATH, AGENT_DEVICE_TEST_ARGS_FILE) and wait real subprocess/retry/poll
|
|
// time, so the group runs serialized with per-file isolation — the same
|
|
// execution contract the pre-split android index.test.ts aggregation
|
|
// provided without leaking module caches between split files.
|
|
test: {
|
|
name: 'subprocess-stub',
|
|
include: [...SUBPROCESS_STUB_TESTS],
|
|
setupFiles: SETUP_FILES,
|
|
fileParallelism: false,
|
|
isolate: true,
|
|
maxWorkers: 1,
|
|
},
|
|
},
|
|
{
|
|
test: {
|
|
name: 'provider-integration',
|
|
include: ['test/integration/provider-scenarios/**/*.test.ts'],
|
|
setupFiles: SETUP_FILES,
|
|
},
|
|
},
|
|
{
|
|
test: {
|
|
name: 'interaction-contract',
|
|
include: ['test/integration/interaction-contract/**/*.test.ts'],
|
|
setupFiles: SETUP_FILES,
|
|
},
|
|
},
|
|
{
|
|
test: {
|
|
name: 'output-economy',
|
|
include: ['test/output-economy/**/*.test.ts'],
|
|
setupFiles: SETUP_FILES,
|
|
},
|
|
},
|
|
],
|
|
coverage: {
|
|
provider: 'v8',
|
|
reporter: ['text', 'html', 'lcov', 'json-summary'],
|
|
thresholds: {
|
|
statements: 78,
|
|
lines: 80,
|
|
},
|
|
include: ['src/**/*.ts', 'packages/*/src/**/*.ts'],
|
|
exclude: [
|
|
'src/**/*.test.ts',
|
|
'src/**/__tests__/**',
|
|
'src/**/*-types.ts',
|
|
'src/**/types.ts',
|
|
'src/sdk/**',
|
|
'src/bin.ts',
|
|
'src/client/client-types.ts',
|
|
'src/core/interactor-types.ts',
|
|
'src/remote/remote-config.ts',
|
|
],
|
|
},
|
|
},
|
|
});
|