Skip to content

Commit bc1b382

Browse files
committed
fix(ci): lint changed root tests in their canonical project
1 parent 833a38b commit bc1b382

9 files changed

Lines changed: 338 additions & 34 deletions

File tree

‎docs/ci.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,7 @@ Local changed-lane logic lives in `scripts/changed-lanes.mjs` and is executed by
11451145

11461146
- core production changes run core prod and core test typecheck plus core lint/guards;
11471147
- core test-only changes run only core test typecheck plus core lint;
1148+
- root TypeScript tests and support files run root test typecheck plus targeted type-aware lint within `test/tsconfig/tsconfig.test.root.json`; the discoverable `test/tsconfig.json` inherits that source-only program. It includes `.ts`, `.tsx`, `.d.mts`, and `.d.cts`, not ordinary `.mts`/`.cts`; fixtures and built-artifact Docker clients stay outside targeted root lint;
11481149
- extension production changes run extension prod and extension test typecheck plus extension lint;
11491150
- extension test-only changes run extension test typecheck plus extension lint;
11501151
- bundled channel manifests, package metadata, config schemas, UI hints, and generator owners also run the bundled channel config metadata drift check;

‎scripts/changed-lanes.mts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ export function hasDeadcodeScannedSource(changedPaths: string[]): boolean {
2323

2424
const SCRIPTS_TYPECHECK_PATH_RE =
2525
/^(?:scripts\/.*\.(?:[cm]?ts|[cm]?tsx)|tsconfig\.scripts\.json)$/u;
26-
const TEST_ROOT_TYPECHECK_PATH_RE =
27-
/^(?:test\/(?!fixtures\/).*\.(?:[cm]?ts|[cm]?tsx)|test\/tsconfig\/tsconfig\.test\.root\.json)$/u;
2826
/** @internal Shared repository-script contract. */
2927
export const LIVE_DOCKER_AUTH_SHELL_TARGETS = [
3028
"scripts/lib/live-docker-auth.sh",
@@ -161,7 +159,11 @@ export function detectChangedLanes(
161159
if (SCRIPTS_TYPECHECK_PATH_RE.test(changedPath)) {
162160
lanes.scripts = true;
163161
}
164-
if (TEST_ROOT_TYPECHECK_PATH_RE.test(changedPath)) {
162+
if (
163+
facts.isRootTestSource ||
164+
changedPath === "test/tsconfig.json" ||
165+
changedPath === "test/tsconfig/tsconfig.test.root.json"
166+
) {
165167
lanes.testRoot = true;
166168
}
167169

‎scripts/check-changed.mts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
rmSync,
1010
writeFileSync,
1111
} from "node:fs";
12+
import { createRequire } from "node:module";
1213
import { tmpdir } from "node:os";
1314
import path from "node:path";
1415
import { performance } from "node:perf_hooks";
@@ -113,6 +114,7 @@ const SHRINK_RATCHET_OWNER_PATH = "scripts/lib/shrink-ratchet.mts";
113114
const CORE_OXLINT_TS_CONFIG = "config/tsconfig/oxlint.core.json";
114115
const EXTENSIONS_OXLINT_TS_CONFIG = "extensions/tsconfig.json";
115116
const SCRIPTS_OXLINT_TS_CONFIG = "config/tsconfig/oxlint.scripts.json";
117+
const ROOT_TEST_TS_CONFIG = "test/tsconfig/tsconfig.test.root.json";
116118
const TARGETED_LINT_PATH_LIMIT = 8;
117119
const LINTABLE_CORE_PATH_RE = /^(?:src|ui|packages)\/.+\.[cm]?[jt]sx?$/u;
118120
const LINTABLE_EXTENSION_PATH_RE = /^extensions\/[^/]+\/.+\.[cm]?[jt]sx?$/u;
@@ -495,6 +497,42 @@ export function createChangedCheckPlan(
495497
const addTypecheck = (name: string, args: string[]) =>
496498
typechecks.add(add(name, args, createSparseTsgoSkipEnv(baseEnv)));
497499
const finishPlan = (summary: string) => {
500+
// Full lint shards exclude test/. Keep changed root sources covered even
501+
// when another path selects the all-lane early return, without widening lint.
502+
let rootTestTargets = result.paths.filter(
503+
(file) => getChangedPathFacts(file).isRootTestSource && existsSync(file),
504+
);
505+
if (rootTestTargets.length > 0) {
506+
// --tsconfig affects import resolution, not native semantic discovery or
507+
// target selection. Expand the canonical roots before passing explicit files.
508+
const ts = createRequire(import.meta.url)("typescript") as typeof import("typescript");
509+
const config = ts.getParsedCommandLineOfConfigFile(
510+
path.resolve(ROOT_TEST_TS_CONFIG),
511+
{},
512+
{
513+
...ts.sys,
514+
onUnRecoverableConfigFileDiagnostic(diagnostic) {
515+
throw new Error(ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
516+
},
517+
},
518+
);
519+
if (!config || config.errors.length > 0) {
520+
throw new Error(
521+
`Invalid ${ROOT_TEST_TS_CONFIG}: ${config?.errors.map((error) => ts.flattenDiagnosticMessageText(error.messageText, "\n")).join("\n")}`,
522+
);
523+
}
524+
const roots = new Set(config.fileNames.map((file) => path.resolve(file)));
525+
rootTestTargets = rootTestTargets.filter((file) => roots.has(path.resolve(file)));
526+
}
527+
for (let offset = 0; offset < rootTestTargets.length; offset += TARGETED_LINT_PATH_LIMIT) {
528+
const batch = rootTestTargets.slice(offset, offset + TARGETED_LINT_PATH_LIMIT);
529+
addCommand(
530+
batch.length === 1 ? "lint test root changed file" : "lint test root changed files",
531+
"node",
532+
["scripts/run-oxlint.mjs", "--tsconfig", ROOT_TEST_TS_CONFIG, ...batch],
533+
baseEnv,
534+
);
535+
}
498536
const end = commands.findLastIndex((command) => typechecks.has(command)) + 1;
499537
const prefix = commands.slice(0, end);
500538
// These audits produce diagnostics, not compiler inputs. Defer them without
@@ -1012,6 +1050,7 @@ function createTargetedOxlintCommand({
10121050
!LINTABLE_CORE_PATH_RE.test(changedPath) &&
10131051
!LINTABLE_EXTENSION_PATH_RE.test(changedPath) &&
10141052
!LINTABLE_SCRIPT_PATH_RE.test(changedPath) &&
1053+
!getChangedPathFacts(changedPath).isRootTestSource &&
10151054
!neutralPathRe.test(changedPath) &&
10161055
!MARKDOWN_LINT_OPTIMIZATION_NEUTRAL_PATH_RE.test(changedPath),
10171056
)

‎scripts/lib/changed-path-facts.mjs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const TEST_ONLY_PATH_RE =
3131
/(^test\/|\/test\/|\/tests\/|(?:^|\/)[^/]+\.(?:test|spec|suite|test-utils|test-(?:helpers|support|harness)|e2e-harness)\.[cm]?[jt]sx?$)/u;
3232
const NATIVE_ONLY_PATH_RE =
3333
/^(?:apps\/android\/|apps\/ios\/|apps\/macos\/|apps\/macos-mlx-tts\/|apps\/shared\/|apps\/swabble\/|Swabble\/|appcast\.xml$)/u;
34+
const ROOT_TEST_SOURCE_PATH_RE = /^test\/(?!fixtures\/).*\.[cm]?tsx?$/u;
3435

3536
/**
3637
* Normalizes a changed file path into repo-relative POSIX form.
@@ -47,7 +48,7 @@ export function normalizeChangedPath(inputPath) {
4748
/**
4849
* Returns shared path facts without imposing a caller's lane-selection policy.
4950
* @param {unknown} inputPath
50-
* @returns {{ path: string; surface: ChangedPathSurface; isChangedLaneTest: boolean; isTestOnly: boolean; isNativeOnly: boolean }}
51+
* @returns {{ path: string; surface: ChangedPathSurface; isChangedLaneTest: boolean; isRootTestSource: boolean; isTestOnly: boolean; isNativeOnly: boolean }}
5152
*/
5253
export function getChangedPathFacts(inputPath) {
5354
const path = typeof inputPath === "string" ? inputPath.trim() : "";
@@ -57,6 +58,7 @@ export function getChangedPathFacts(inputPath) {
5758
path,
5859
surface,
5960
isChangedLaneTest: CHANGED_LANE_TEST_PATH_RE.test(path),
61+
isRootTestSource: ROOT_TEST_SOURCE_PATH_RE.test(path),
6062
isTestOnly: TEST_ONLY_PATH_RE.test(path),
6163
isNativeOnly: NATIVE_ONLY_PATH_RE.test(path),
6264
};

‎scripts/run-oxlint.mts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const OXLINT_VALUE_FLAGS = new Set([
4747
const OXLINT_BOUNDARY_FREE_TS_CONFIGS = new Set([
4848
"config/tsconfig/oxlint.core.json",
4949
"config/tsconfig/oxlint.scripts.json",
50+
"test/tsconfig/tsconfig.test.root.json",
5051
]);
5152
const OPENCLAW_FOCUSED_CONFIG_FLAG = "--openclaw-focused-config";
5253

@@ -65,7 +66,7 @@ export function shouldPrepareExtensionPackageBoundaryArtifacts(args: string[]) {
6566
}
6667
return arg.startsWith("--tsconfig=") ? [arg.slice("--tsconfig=".length)] : [];
6768
});
68-
// Core and script lint resolve workspace sources through the root tsconfig;
69+
// Core, script, and root-test lint resolve sources through the root tsconfig;
6970
// generated plugin package declarations are only an extension-lint input.
7071
return (
7172
tsconfigs.length === 0 ||

0 commit comments

Comments
 (0)