Files
orca/config/scripts/test-only-source-path.mjs
T
Brennan Benson 508419f11e test: check structured-chat code for Electron imports even before the runtime loads it (#24988)
* test: keep structured chat free of Electron imports

* test: widen runtime Electron ratchet to structured chat

* test: check whole structured-chat directories for Electron imports

Cover src/main/{native-chat,claude,codex}, src/shared and every structured-*
or agent-session-* file under src/main/runtime, so new files are checked by
default. A lane that exists today now fails loudly if it goes missing; only
the not-yet-landed acp/ and provider-process/ may be absent.

Move the test-only file rule into one classifier shared with the
localization audit, so -test-<thing> helpers and test doubles no longer
enter the production gate.

* test: run the Electron-import CLI path in tests and retire may-be-absent lanes

Export main() so the real-tree tests exercise the entry list CI uses,
check every required lane for the missing-directory error, and fail once
acp/ or provider-process/ exists while still allowed to be absent.
2026-10-05 14:48:33 -07:00

24 lines
1.2 KiB
JavaScript

/**
* Whether a repo source path is test-only by this repo's naming conventions: specs, test helpers
* and doubles that sit beside their spec (`*-test-harness.ts`, `*-fixtures.ts`, `*-fake.ts`), and
* test directories (`__tests__/`, `orca-runtime-tests/`). Shared by the Electron-import check and
* the localization audit, so a helper is test-only to both or to neither.
*/
// Why `(?<!self)`: `*-self-test-*` modules are a shipped runtime probe, not tests.
const TEST_ONLY_BASENAME =
/\.(?:test|spec)\.|(?<!self)[.-]test-|[.-](?:fixtures?|mocks?|fakes?|stubs?|doubles?)\.[cm]?[jt]sx?$/
const TEST_ONLY_DIRECTORY = /^(?:__)?(?:tests?|fixtures?|mocks)(?:__)?$|(?:^|[.-])tests?(?:[.-]|$)/
/** @param {string} relativePath Repo-relative path with `/` separators. */
export function isTestOnlySourcePath(relativePath) {
const directories = relativePath.split('/')
const basename = directories.pop() ?? ''
return TEST_ONLY_BASENAME.test(basename) || directories.some(isTestOnlyDirectoryName)
}
/** Lets a directory walk prune a whole test tree instead of testing every file in it. */
export function isTestOnlyDirectoryName(name) {
return TEST_ONLY_DIRECTORY.test(name)
}