mirror of
https://github.com/bitbaum/openclaw.git
synced 2026-12-04 04:07:14 +01:00
* fix(browser): unblock compiled native-host bootstrap Load canonical config and pairing only after native-host validation. Keep pure Browser URL and port helpers out of transport and mixed runtime barrels, register the existing private CDP SDK export, and remove obsolete bridge exports. Run the extracted compiled-host integration case in the existing artifact CI job with exact report validation. Preserve the custom installation context, native framing, private Node trampoline, and 10-second deadline. * fix(build): map private Browser SDK declarations Complete browser-cdp registration in the shared plugin package-boundary paths and XAI's matching override. Keep the SDK JavaScript-only in the published package while using package-built declarations inside the repo. The unchanged package-boundary contract reproduced the missing mapping before this fix. No native-host runtime, fixture, assertion, or deadline changes are included.
520 lines
21 KiB
TypeScript
520 lines
21 KiB
TypeScript
import { existsSync } from "node:fs";
|
|
import path from "node:path";
|
|
import { detectChangedLanes } from "../changed-lanes.mts";
|
|
import {
|
|
buildVitestRunPlans,
|
|
findUnmatchedExplicitTestTargets,
|
|
hasImportGraphImpactOnTargets,
|
|
isTestFileTarget,
|
|
isTestSupportFileTarget,
|
|
resolveChangedTestTargetPlan,
|
|
} from "../test-projects.test-support.mts";
|
|
import { listAvailableExtensionIds } from "./changed-extensions.mts";
|
|
import {
|
|
createNodeTestShards,
|
|
isPolicyTestOwnedPath,
|
|
resolvePolicyTestTargets,
|
|
} from "./ci-node-test-plan.mts";
|
|
import {
|
|
listExtensionTestFilesForRoots,
|
|
resolveExtensionTestConfig,
|
|
shouldSplitExtensionTestProcesses,
|
|
splitExtensionTestJobTargets,
|
|
} from "./extension-test-plan.mts";
|
|
import { buildPluginSdkEntrySources, publicPluginSdkEntrypoints } from "./plugin-sdk-entries.mts";
|
|
import {
|
|
resolveVitestPretestBuildMode,
|
|
type VitestPretestBuildMode,
|
|
} from "./vitest-build-prerequisites.mts";
|
|
|
|
type ChangedNodeTestShard = {
|
|
checkName: string;
|
|
configs: string[];
|
|
includePatterns?: string[];
|
|
planConcurrency?: number;
|
|
pretestBuildMode?: VitestPretestBuildMode;
|
|
requiresDist: boolean;
|
|
runner: string;
|
|
shardName: string;
|
|
targets?: string[];
|
|
};
|
|
type CwdOptions = { cwd?: string };
|
|
|
|
const DEFAULT_NODE_TEST_RUNNER = "blacksmith-8vcpu-ubuntu-2404";
|
|
const MAX_CHANGED_NODE_TEST_TARGETS = 96;
|
|
// Each target runs in its own child process (isolation contract), so bound the
|
|
// serial tail per job; the shard runner overlaps two children at a time.
|
|
const CHANGED_NODE_TEST_TARGETS_PER_JOB = 12;
|
|
// Memory Core targets perform real SQLite/indexing work. Two concurrent Vitest
|
|
// processes starve each other on 4-vCPU runners and push otherwise healthy
|
|
// integration tests past the global timeout.
|
|
const SERIAL_CHANGED_TARGET_RE = /^extensions\/memory-core\//u;
|
|
const BOUNDARY_NODE_TEST_CONFIG = "test/vitest/vitest.boundary.config.ts";
|
|
const MCP_DOCKER_SEED_LANES = [
|
|
"mcp-channels",
|
|
"cron-mcp-cleanup",
|
|
"mcp-code-mode-gateway",
|
|
] as const;
|
|
const DOCKER_SEED_LANE_ORDER = [...MCP_DOCKER_SEED_LANES, "update-channel-switch"] as const;
|
|
type DockerSeedLane = (typeof DOCKER_SEED_LANE_ORDER)[number];
|
|
const DOCKER_SEED_LANES_BY_PATH: Readonly<Record<string, readonly DockerSeedLane[]>> = {
|
|
".github/workflows/ci.yml": MCP_DOCKER_SEED_LANES,
|
|
"scripts/e2e/cron-mcp-cleanup-seed.ts": ["cron-mcp-cleanup"],
|
|
"scripts/e2e/docker-openai-seed.ts": MCP_DOCKER_SEED_LANES,
|
|
"scripts/e2e/lib/mcp-code-mode-probe-server.ts": ["mcp-code-mode-gateway"],
|
|
"scripts/e2e/lib/update-channel-switch/assertions.mjs": ["update-channel-switch"],
|
|
"scripts/e2e/mcp-channels-seed.ts": ["mcp-channels"],
|
|
"scripts/e2e/mcp-code-mode-gateway-seed.ts": ["mcp-code-mode-gateway"],
|
|
"scripts/e2e/update-channel-switch-docker.sh": ["update-channel-switch"],
|
|
"scripts/lib/ci-changed-node-test-plan.mts": MCP_DOCKER_SEED_LANES,
|
|
};
|
|
const publicPluginSdkEntrySources = Object.values(
|
|
buildPluginSdkEntrySources(publicPluginSdkEntrypoints),
|
|
);
|
|
|
|
const fullNodeTestShards = createNodeTestShards({
|
|
includeReleaseOnlyPluginShards: false,
|
|
});
|
|
const configsRequiringFullSuiteMetadata = new Set(
|
|
fullNodeTestShards
|
|
.filter((shard) => shard.env || shard.shardName.startsWith("core-tooling"))
|
|
.flatMap((shard) => shard.configs),
|
|
);
|
|
const splitNodeTestConfigs = new Set(
|
|
fullNodeTestShards.filter((shard) => shard.includePatterns).flatMap((shard) => shard.configs),
|
|
);
|
|
|
|
export function resolveChangedDockerSeedLanes(changedPaths: string[]) {
|
|
const selected = new Set<DockerSeedLane>();
|
|
for (const changedPath of changedPaths) {
|
|
const normalizedPath = changedPath.replaceAll("\\", "/");
|
|
for (const lane of DOCKER_SEED_LANES_BY_PATH[normalizedPath] ?? []) {
|
|
selected.add(lane);
|
|
}
|
|
}
|
|
return DOCKER_SEED_LANE_ORDER.filter((lane) => selected.has(lane));
|
|
}
|
|
|
|
function isTestOnlyPath(changedPath: string) {
|
|
return (
|
|
isTestFileTarget(changedPath) ||
|
|
isTestSupportFileTarget(changedPath) ||
|
|
changedPath.startsWith("test/")
|
|
);
|
|
}
|
|
|
|
// Inputs `build:ci-artifacts` consumes: runtime/plugin/package sources plus
|
|
// the build pipeline itself (mirrors the build-all cache key in ci.yml).
|
|
// Built-artifact test inputs below also require this lane even though they do
|
|
// not change the bytes under test.
|
|
const BUILD_INPUT_RE =
|
|
/^(?:src|extensions|packages)\/|^(?:openclaw\.mjs|package\.json|pnpm-lock\.yaml|pnpm-workspace\.yaml)$|^tsconfig[^/]*\.json$|^scripts\/(?:build-[^/]+|runtime-postbuild\.mts|write-plugin-sdk-entry-dts\.ts)$|^scripts\/lib\/(?:copy-assets\.ts|plugin-sdk-entries\.mts)$/u;
|
|
const BUILT_ARTIFACT_TEST_INPUTS = new Set([
|
|
"extensions/browser/chrome-extension/relay-key.test-support.ts",
|
|
"extensions/browser/src/browser/extension-install.native-host.e2e.test.ts",
|
|
"extensions/browser/src/browser/extension-install.test-support.ts",
|
|
]);
|
|
|
|
/**
|
|
* True when a changed path can influence built dist/packaging bytes: a
|
|
* non-test build-input source, build pipeline, or built-artifact test input.
|
|
* Diffs entirely outside that set (ordinary tests, repo scripts, workflows) let the
|
|
* manifest skip the build-artifacts lane.
|
|
*/
|
|
export function hasBuildArtifactAffectingChange(changedPaths: string[]) {
|
|
return changedPaths.some(
|
|
(changedPath) =>
|
|
BUILT_ARTIFACT_TEST_INPUTS.has(changedPath) ||
|
|
(BUILD_INPUT_RE.test(changedPath) && !isTestOnlyPath(changedPath)),
|
|
);
|
|
}
|
|
|
|
// QA-owned surfaces that keep the smoke lane on pull requests: the qa-lab
|
|
// harness and scenario data, the two channels the smoke profile drives
|
|
// (matrix, telegram), the packaged-CLI docker packaging scripts, and the QA
|
|
// lane's own orchestration (this planner, the CI workflow, composite
|
|
// actions) — changes to the gate must not be able to skip the gated lane.
|
|
const QA_SMOKE_SURFACE_RE =
|
|
/^(?:extensions\/(?:matrix|qa-lab|telegram)|qa)\/|^scripts\/(?:build-all\.mts|package-openclaw-for-docker\.mts)$|^scripts\/lib\/ci-changed-node-test-plan\.mts$|^\.github\/(?:workflows\/ci\.yml$|actions\/)/u;
|
|
|
|
/**
|
|
* True when a pull request diff touches a QA-owned smoke surface. Broad
|
|
* runtime changes (src/ui/packages/dependency manifests) deliberately no
|
|
* longer select the smoke lane on pull requests: every canonical `main` push
|
|
* and release validation still runs the full profile set, so runtime
|
|
* regressions surface one push later instead of taxing every PR with the
|
|
* six-part smoke matrix (~5 hosted-runner minutes each).
|
|
*/
|
|
export function hasQaSmokeAffectingChange(changedPaths: string[]) {
|
|
return changedPaths.some((changedPath) => QA_SMOKE_SURFACE_RE.test(changedPath));
|
|
}
|
|
|
|
// Surfaces the prompt-snapshot check exercises outside its generator's
|
|
// relative import graph: the snapshot fixtures and generator scripts, the
|
|
// codex extension (its test API loads through a dynamic bundled-plugin module
|
|
// id the graph walk cannot see), and the gate's own orchestration — changes
|
|
// to the gate must not be able to skip the gated lane.
|
|
const PROMPT_SNAPSHOT_SURFACE_RE =
|
|
/^(?:test\/(?:helpers\/agents|fixtures\/agents\/prompt-snapshots)|extensions\/codex|packages)\/|^scripts\/(?:generate-prompt-snapshots\.ts|prompt-snapshot-files\.[cm]?[jt]s)$|^scripts\/lib\/ci-changed-node-test-plan\.mts$|^\.github\/(?:workflows\/ci\.yml$|actions\/)|^(?:package\.json|pnpm-lock\.yaml|pnpm-workspace\.yaml)$/u;
|
|
// The generator renders real prompt-layer stacks, so its runtime blast radius
|
|
// is the snapshot helper's import graph (auto-reply prompts, channel typing,
|
|
// plugin-sdk agent harness, codex catalog fixtures).
|
|
const PROMPT_SNAPSHOT_ENTRY = "test/helpers/agents/happy-path-prompt-snapshots.ts";
|
|
|
|
// The fallback planner and chunk-policy owner are part of the gate surface; changes to the
|
|
// gate must not be able to skip the gated lane (#124412).
|
|
const CORE_EXTENSION_IMPACT_SURFACE_RE =
|
|
/^scripts\/lib\/(?:changed-extensions|ci-changed-node-test-plan|extension-test-plan)\.mts$/u;
|
|
|
|
/**
|
|
* True when a changed path can influence generated prompt snapshots: it
|
|
* touches the snapshot surface directly, or the generator's import graph
|
|
* reaches it. Diffs outside both cannot change generator output, so the
|
|
* manifest may skip the check lane.
|
|
*/
|
|
export function hasPromptSnapshotAffectingChange(changedPaths: string[], options: CwdOptions = {}) {
|
|
const cwd = options.cwd ?? process.cwd();
|
|
if (changedPaths.some((changedPath) => PROMPT_SNAPSHOT_SURFACE_RE.test(changedPath))) {
|
|
return true;
|
|
}
|
|
const sourcePaths = changedPaths.filter(
|
|
(changedPath) => changedPath.startsWith("src/") && !isTestFileTarget(changedPath),
|
|
);
|
|
if (sourcePaths.length === 0) {
|
|
return false;
|
|
}
|
|
// Deleted sources cannot be graphed; fail safe to running the check.
|
|
if (sourcePaths.some((changedPath) => !existsSync(path.join(cwd, changedPath)))) {
|
|
return true;
|
|
}
|
|
return hasImportGraphImpactOnTargets(sourcePaths, [PROMPT_SNAPSHOT_ENTRY], cwd);
|
|
}
|
|
|
|
// The lifecycle proof crosses dynamic Gateway method registration, doctor
|
|
// migrations, shared session coordination, the public session SDK, and the
|
|
// built CLI. Keep those owners on the direct surface; use the import graph only
|
|
// inside the embedded-runner neighborhood, whose session reachability is not
|
|
// apparent from filenames.
|
|
const SQLITE_SESSION_LIFECYCLE_PREFIX_RE =
|
|
/^(?:src\/(?:agents\/(?:sessions\/|[^/]*(?:session|transcript|compaction)[^/]*)|commands\/doctor-session-|config\/sessions\/|gateway\/(?:agent-turn\/agent-session-persist|server-chat\.(?:load-gateway-session-row|persist-session-lifecycle)|server-methods\/sessions|server\.sessions|session-|sessions-)|plugin-sdk\/session-|sessions\/|state\/openclaw-agent-(?:db|schema))|\.github\/actions\/setup-node-env\/)/u;
|
|
const SQLITE_SESSION_LIFECYCLE_EXACT_RE =
|
|
/^(?:src\/config\/sessions\.ts|test\/helpers\/(?:openclaw-test-instance|sqlite-sessions-transcripts-flip-proof(?:-assertions)?)\.ts|test\/scripts\/(?:sqlite-sessions-transcripts-flip-proof(?:\.built-cli)?\.e2e\.test|vitest-e2e-global-setup\.test)\.ts|test\/vitest\/vitest\.e2e\.(?:config|global-setup)\.ts|scripts\/lib\/ci-changed-node-test-plan\.mts|\.github\/workflows\/ci\.yml|openclaw\.mjs|package\.json|pnpm-lock\.yaml|pnpm-workspace\.yaml)$/u;
|
|
const SQLITE_SESSION_LIFECYCLE_ENTRY =
|
|
"test/scripts/sqlite-sessions-transcripts-flip-proof.e2e.test.ts";
|
|
const SQLITE_SESSION_LIFECYCLE_IMPORT_CANDIDATE_RE = /^src\/agents\/embedded-agent-runner\/run\//u;
|
|
|
|
/**
|
|
* True when a changed path touches a SQLite session lifecycle owner or reaches
|
|
* the proof from the embedded-runner neighborhood.
|
|
*/
|
|
export function hasSqliteSessionLifecycleAffectingChange(
|
|
changedPaths: string[],
|
|
options: CwdOptions = {},
|
|
) {
|
|
const cwd = options.cwd ?? process.cwd();
|
|
if (
|
|
changedPaths.some(
|
|
(changedPath) =>
|
|
(!isTestFileTarget(changedPath) && SQLITE_SESSION_LIFECYCLE_PREFIX_RE.test(changedPath)) ||
|
|
SQLITE_SESSION_LIFECYCLE_EXACT_RE.test(changedPath),
|
|
)
|
|
) {
|
|
return true;
|
|
}
|
|
const sourcePaths = changedPaths.filter(
|
|
(changedPath) =>
|
|
SQLITE_SESSION_LIFECYCLE_IMPORT_CANDIDATE_RE.test(changedPath) &&
|
|
!isTestFileTarget(changedPath),
|
|
);
|
|
// Deleted sources cannot be graphed; fail safe to running the lifecycle proof.
|
|
if (sourcePaths.some((changedPath) => !existsSync(path.join(cwd, changedPath)))) {
|
|
return true;
|
|
}
|
|
if (sourcePaths.length === 0) {
|
|
return false;
|
|
}
|
|
return hasImportGraphImpactOnTargets(sourcePaths, [SQLITE_SESSION_LIFECYCLE_ENTRY], cwd);
|
|
}
|
|
|
|
function createBoundaryShard() {
|
|
// Boundary tests scan the source tree (including test files) and build
|
|
// their own fixtures; they do not consume the built dist artifact. When the
|
|
// build-artifacts lane is skipped, this shard keeps that coverage.
|
|
return {
|
|
checkName: "checks-node-changed-boundary",
|
|
configs: [BOUNDARY_NODE_TEST_CONFIG],
|
|
requiresDist: false,
|
|
runner: DEFAULT_NODE_TEST_RUNNER,
|
|
shardName: "changed-boundary",
|
|
};
|
|
}
|
|
|
|
function resolvePreciseChangedTargets(
|
|
changedPaths: string[],
|
|
cwd: string,
|
|
additionalTargets: string[] = [],
|
|
) {
|
|
const resolveTargetPlan = (paths: string[]) =>
|
|
resolveChangedTestTargetPlan(paths, {
|
|
broad: true,
|
|
combineSiblingWithImportGraph: true,
|
|
cwd,
|
|
forceFullImportGraph: true,
|
|
includeExtensionImpact: false,
|
|
});
|
|
const plan =
|
|
changedPaths.length > 0
|
|
? resolveTargetPlan(changedPaths)
|
|
: { mode: "targets" as const, targets: [] };
|
|
// Aggregate resolution must not let one precise path hide another path that
|
|
// contributes no tests. Partial plans silently drop coverage.
|
|
if (
|
|
changedPaths.some((changedPath) => {
|
|
const changedPathPlan = resolveTargetPlan([changedPath]);
|
|
return changedPathPlan.mode !== "targets" || changedPathPlan.targets.length === 0;
|
|
}) ||
|
|
plan.mode !== "targets"
|
|
) {
|
|
return null;
|
|
}
|
|
const targets = [...new Set([...plan.targets, ...additionalTargets])];
|
|
if (
|
|
targets.length > MAX_CHANGED_NODE_TEST_TARGETS ||
|
|
targets.some(
|
|
(target) =>
|
|
/^test\/vitest\/vitest\.full-.*\.config\.ts$/u.test(target) ||
|
|
splitNodeTestConfigs.has(target),
|
|
) ||
|
|
targets.some(
|
|
(target) =>
|
|
!isTestFileTarget(target) || findUnmatchedExplicitTestTargets([target], cwd).length > 0,
|
|
)
|
|
) {
|
|
return null;
|
|
}
|
|
|
|
const targetPlans = targets.map((target) => ({
|
|
plans: buildVitestRunPlans([target], cwd),
|
|
target,
|
|
}));
|
|
if (
|
|
targetPlans.some(
|
|
({ plans }) => plans.length === 0 || plans.some((targetPlan) => !targetPlan.includePatterns),
|
|
)
|
|
) {
|
|
return null;
|
|
}
|
|
// Preserve special shard setup (for example Go and TUI PTY coverage) by using
|
|
// the compact plan until targeted jobs can carry per-config prerequisites.
|
|
if (
|
|
targetPlans.some(({ plans }) =>
|
|
plans.some(({ config }) => configsRequiringFullSuiteMetadata.has(config)),
|
|
)
|
|
) {
|
|
return null;
|
|
}
|
|
return targetPlans.map(({ target }) => target);
|
|
}
|
|
|
|
function createChangedTargetShards(
|
|
targets: string[],
|
|
names: { checkName: string; shardName: string },
|
|
) {
|
|
const targetChunks: string[][] = [];
|
|
for (let offset = 0; offset < targets.length; offset += CHANGED_NODE_TEST_TARGETS_PER_JOB) {
|
|
targetChunks.push(targets.slice(offset, offset + CHANGED_NODE_TEST_TARGETS_PER_JOB));
|
|
}
|
|
return targetChunks.map((chunk, index) => {
|
|
const suffix = targetChunks.length === 1 ? "" : `-${index + 1}`;
|
|
const shard: ChangedNodeTestShard = {
|
|
checkName: `${names.checkName}${suffix}`,
|
|
configs: [],
|
|
requiresDist: false,
|
|
runner: DEFAULT_NODE_TEST_RUNNER,
|
|
shardName: `${names.shardName}${suffix}`,
|
|
targets: chunk,
|
|
};
|
|
const pretestBuildMode = resolveVitestPretestBuildMode([{ includePatterns: chunk }]);
|
|
if (pretestBuildMode) {
|
|
shard.pretestBuildMode = pretestBuildMode;
|
|
}
|
|
if (chunk.some((target) => SERIAL_CHANGED_TARGET_RE.test(target))) {
|
|
shard.planConcurrency = 1;
|
|
}
|
|
return shard;
|
|
});
|
|
}
|
|
|
|
function resolveChangedExtensionRoots(changedPaths: string[]) {
|
|
return [
|
|
...new Set(
|
|
changedPaths.flatMap((changedPath) => {
|
|
const [, extensionId] = changedPath.split("/");
|
|
return extensionId ? [`extensions/${extensionId}`] : [];
|
|
}),
|
|
),
|
|
];
|
|
}
|
|
|
|
function createChangedExtensionConfigShards(extensionRoots: string[]) {
|
|
const rootsByConfig = new Map<string, string[]>();
|
|
for (const root of extensionRoots) {
|
|
const config = resolveExtensionTestConfig(root);
|
|
rootsByConfig.set(config, [...(rootsByConfig.get(config) ?? []), root]);
|
|
}
|
|
const plans: Array<{ config: string; includePatterns?: string[]; roots: string[] }> = [
|
|
...rootsByConfig,
|
|
].flatMap(([config, roots]) => {
|
|
const testFiles = shouldSplitExtensionTestProcesses(config)
|
|
? listExtensionTestFilesForRoots(roots)
|
|
: [];
|
|
const chunks = testFiles.length > 0 ? splitExtensionTestJobTargets(config, testFiles) : [roots];
|
|
return chunks.length > 1
|
|
? chunks.map((includePatterns) => ({ config, includePatterns, roots }))
|
|
: [{ config, roots }];
|
|
});
|
|
return plans.map(({ config, includePatterns, roots }, index) => {
|
|
const suffix = plans.length === 1 ? "" : `-${index + 1}`;
|
|
const shard: ChangedNodeTestShard = {
|
|
checkName: `checks-node-changed-extensions-config${suffix}`,
|
|
configs: [config],
|
|
requiresDist: false,
|
|
runner: DEFAULT_NODE_TEST_RUNNER,
|
|
shardName: `changed-extensions-config${suffix}`,
|
|
};
|
|
const pretestBuildMode = resolveVitestPretestBuildMode([
|
|
{ configs: [config], includePatterns },
|
|
]);
|
|
if (pretestBuildMode) {
|
|
shard.pretestBuildMode = pretestBuildMode;
|
|
}
|
|
if (includePatterns) {
|
|
shard.includePatterns = includePatterns;
|
|
}
|
|
if (roots.some((root) => SERIAL_CHANGED_TARGET_RE.test(`${root}/`))) {
|
|
shard.planConcurrency = 1;
|
|
}
|
|
return shard;
|
|
});
|
|
}
|
|
|
|
function createChangedExtensionConfigShardsForPaths(changedPaths: string[], cwd: string) {
|
|
const relevantPaths = changedPaths.filter(
|
|
(changedPath) =>
|
|
changedPath.startsWith("extensions/") &&
|
|
(existsSync(path.join(cwd, changedPath)) || !isTestFileTarget(changedPath)),
|
|
);
|
|
return createChangedExtensionConfigShards(resolveChangedExtensionRoots(relevantPaths));
|
|
}
|
|
|
|
/**
|
|
* True when core or fallback-gate changes can affect extension consumers beyond
|
|
* the changed extension paths.
|
|
*/
|
|
export function hasCoreExtensionImpact(changedPaths: string[], options: CwdOptions = {}) {
|
|
if (changedPaths.some((changedPath) => CORE_EXTENSION_IMPACT_SURFACE_RE.test(changedPath))) {
|
|
return true;
|
|
}
|
|
const cwd = options.cwd ?? process.cwd();
|
|
const regularLivePaths = changedPaths.filter(
|
|
(changedPath) =>
|
|
existsSync(path.join(cwd, changedPath)) &&
|
|
!changedPath.startsWith("extensions/") &&
|
|
!isPolicyTestOwnedPath(changedPath),
|
|
);
|
|
return (
|
|
detectChangedLanes(changedPaths).extensionImpactFromCore ||
|
|
(regularLivePaths.some((changedPath) => changedPath.startsWith("src/")) &&
|
|
hasImportGraphImpactOnTargets(regularLivePaths, publicPluginSdkEntrySources, cwd))
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Covers changed extensions plus the full core-impact blast radius when precise
|
|
* planning falls back. See #124412.
|
|
*/
|
|
export function createChangedExtensionFallbackShards(
|
|
changedPaths: string[],
|
|
options: CwdOptions = {},
|
|
): ChangedNodeTestShard[] {
|
|
const cwd = options.cwd ?? process.cwd();
|
|
if (hasCoreExtensionImpact(changedPaths, { cwd })) {
|
|
return createChangedExtensionConfigShards(
|
|
listAvailableExtensionIds().map((extensionId) => `extensions/${extensionId}`),
|
|
);
|
|
}
|
|
return createChangedExtensionConfigShardsForPaths(changedPaths, cwd);
|
|
}
|
|
|
|
/**
|
|
* Builds bounded PR jobs from precise changed-test targets.
|
|
* Null means the caller must fail safe to the compact full-suite plan.
|
|
*/
|
|
export function createChangedNodeTestShards(
|
|
changedPaths: string[],
|
|
options: CwdOptions = {},
|
|
): ChangedNodeTestShard[] | null {
|
|
const cwd = options.cwd ?? process.cwd();
|
|
if (!Array.isArray(changedPaths) || changedPaths.length === 0) {
|
|
return null;
|
|
}
|
|
|
|
const livePaths: string[] = [];
|
|
const deletedPaths: string[] = [];
|
|
for (const changedPath of changedPaths) {
|
|
(existsSync(path.join(cwd, changedPath)) ? livePaths : deletedPaths).push(changedPath);
|
|
}
|
|
// Deleted test files cannot regress runtime behavior, so they never block
|
|
// targeting. Deleted source files cannot be import-graphed from the merged
|
|
// tree and no live-path heuristic proves their consumers are covered, so
|
|
// any source deletion keeps the full-suite plan.
|
|
if (deletedPaths.some((deletedPath) => !isTestFileTarget(deletedPath))) {
|
|
return null;
|
|
}
|
|
|
|
const policyTargetsByPath = new Map(
|
|
livePaths
|
|
.filter((changedPath) => !changedPath.startsWith("extensions/"))
|
|
.map((changedPath) => [changedPath, resolvePolicyTestTargets([changedPath])]),
|
|
);
|
|
const regularLivePaths = livePaths.filter(
|
|
(changedPath) => !changedPath.startsWith("extensions/") && !isPolicyTestOwnedPath(changedPath),
|
|
);
|
|
|
|
// Workspace package consumers often use package specifiers, which the
|
|
// relative import graph cannot connect back to the changed package source.
|
|
if (changedPaths.some((changedPath) => changedPath.startsWith("packages/"))) {
|
|
return null;
|
|
}
|
|
|
|
// Package-specifier consumers are invisible to the relative import graph.
|
|
// Fail safe when a core change reaches a public SDK entrypoint indirectly.
|
|
if (hasCoreExtensionImpact(changedPaths, { cwd })) {
|
|
return null;
|
|
}
|
|
|
|
const targets = resolvePreciseChangedTargets(regularLivePaths, cwd, [
|
|
...[...policyTargetsByPath.values()].flat(),
|
|
// Plugin changes normally select only extension suites. This host-owned
|
|
// proof also exercises the real Copilot entrypoint and manifest discovery.
|
|
...(livePaths.some((changedPath) => changedPath.startsWith("extensions/copilot/"))
|
|
? ["src/agents/prepared-model-runtime.copilot.integration.test.ts"]
|
|
: []),
|
|
]);
|
|
if (targets === null) {
|
|
return null;
|
|
}
|
|
|
|
// Boundary-config targets run as regular nondist targets: the boundary
|
|
// suite scans the checked-out tree and never consumes the built dist.
|
|
const shards = [
|
|
...createChangedExtensionConfigShardsForPaths(livePaths, cwd),
|
|
...createChangedTargetShards(targets, {
|
|
checkName: "checks-node-changed",
|
|
shardName: "changed",
|
|
}),
|
|
...(hasBuildArtifactAffectingChange(changedPaths) ? [] : [createBoundaryShard()]),
|
|
];
|
|
return shards.length > 0 ? shards : null;
|
|
}
|