mirror of
https://github.com/stablyai/orca.git
synced 2026-09-21 16:02:20 +00:00
* refactor(mobile-web): share the bundle manifest assembly with a second builder Manifest assembly and the on-disk write move to writeMobileWebBundleTree, and the helpers the Phase C app builder needs become exports. No behaviour change to the shipped bootstrap bundle. The CRLF guard grows two exemptions it needs once it is pointed at mobile/src: the image and font extensions .gitattributes already pins -text, and the gitignored webview engine modules the postinstall writes. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * feat(mobile): web entry for the host route tree, and its two transport siblings The entry mounts app/h on react-native-web through expo-router's own ExpoRoot. It lives inside mobile/ so one React resolves, and supplies RpcClientProvider itself: the route tree starts below the native root layout that owns it. route-manifest.ts is a real typed module whose body the builder replaces -- esbuild has no require.context. A virtual specifier would need an ambient declaration and would leave the entry unchecked. Two .web.* siblings, both listed with a reason in web-overrides.json: the transport substitution point (a placeholder client until C0.4 lands BridgeRpcClient) and the device token store, whose native path imports expo-secure-store, which is {} on web. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * feat(build): build:mobile-web:app, the phone's host routes bundled for the web Same builder shape as the Phase A bootstrap into a separate out/mobile-web-app, with the same manifest and the same two-scratch-build determinism check. Dark: build:mobile-web, packaging and the A2 census are untouched, and C1 is what flips build:release. Six shims, each a named Metro or RN Web gap. Images are emitted as same-origin hashed assets rather than data: URLs, because the shell's CSP sets img-src 'self'; the render check under that exact header is what found it. The script is referenced root-absolute for the same reason a <base> tag cannot be used: the document is served at every route depth and base-uri is 'none'. The budget sits below the contract's per-asset ceiling so growth trips a build rather than a refused asset on a phone. esbuild splitting does not lower it: one entry with only static imports emits one chunk (measured). Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * fix(mobile): let React Native Web paint under the shell CSP RN Web 0.21.2 injects its stylesheet at runtime with no nonce support, so style-src 'self' blocks every rule and the page renders unstyled. Measured, not predicted: the render check serves the document under this exact header and reported the violation. 'unsafe-inline' is granted to style-src and nothing else. script-src 'self' holds, which is the directive that decides whether page code can arrive any way other than as a fetched same-origin script. The test now pins that scoping rather than rejecting the token everywhere. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * ci: prove the Route A app bundle on every PR A dedicated job, for the same reason the browser provider has one: it needs mobile/node_modules and a real browser, and the sharded test matrix would pay for both on every shard. It builds the bundle, verifies it, and runs the builder, override-census and render suites. It ships nothing. The mobile_web_app signal is lifted out of should_run the way static_analysis is. A mobile-only diff is desktop-irrelevant and skips every gated job, and that is exactly the diff that changes the page this job builds. Also the C0.6 review follow-up: mobile/package.json and mobile/pnpm-lock.yaml join the installer cache keys in the two workflows that build an installer off a hashFiles key, since beforePack requires out/mobile-web and a mobile-only change must miss those caches rather than reuse a stale build. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * test(build): pin the shipped builder against the app builder's own module name The assertion named a specifier that no longer exists, so it held vacuously. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * test(mobile): assert the RN Web style-src grant in the Swift checks The Swift twin of the Kotlin CSP test still required style-src 'self' and no unsafe-inline anywhere, so it trapped on the approved grant. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * test(build): make the Route A render check name what each route paints The check asserted only "some html, no errors", which expo-router's Unmatched screen satisfies: pointing HOST_ROUTE at /zzz/not-a-real-prefix stayed green. Each route now asserts content only its own component produces, and the unmatched case asserts the screen positively so the negatives discriminate. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * test(build): read the shell CSP past the comments that quote directives Both constants document themselves with // comments containing quoted directive text, which the quoted-string scan picked up as directives. One parser now drops comment lines, and iOS and Android go through it. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * feat(build): honour a .web.* route sibling in the app bundle Routes were imported by absolute path with the extension, so esbuild's resolveExtensions never applied and a .web.tsx under app/ was dead code the census still accepted. The manifest now carries a key and a module: the key stays the native filename so the URL does not move, and the module is the web sibling when one exists. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * test(build): tie each named shim to the esbuild option that implements it The shim list was asserted against a literal copy of itself, which passes however the build is configured. Each entry now carries an appliesTo that reads its own option, checked against the real options object. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * chore(build): line up the CRLF exemptions, the budget comment, and the job scope The builder loads .gif as a file but neither .gitattributes nor the CRLF scan exempted it, so the blanket eol=lf pin would have rewritten one. A test now keeps the two lists in step. The Phase C byte budget's comment sat on the asset count, and a root package.json edit could change build:mobile-web:app without running the job that proves it. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * style(build): satisfy the index-check lint rule in the CSP parser Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * ci: key the installer caches on the mobile page trees too beforePack builds the mobile web bundle into the installer. Today those bytes are Phase A's, which src/** already covers, but once C1 flips the entry to mobile/app a page-only change would hit a cache holding a stale installer. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * test(build): skip the bundling tests where mobile dependencies are absent The sharded `test` job collects config/scripts/**/*.test.mjs and installs no mobile dependencies, so the two new suites failed there on "Could not resolve react-native-web". They now skip themselves with a message naming the job that runs them, and that job sets ORCA_MOBILE_WEB_APP_DEPS_REQUIRED so a missing install fails it instead of skipping everything it exists to prove. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * fix(build): scan mobile/packages in the .web.* census The census claimed the app entry never resolves into packages/, but the dictation hook imports @orca/expo-two-way-audio and the built script carries ExpoTwoWayAudioModule.web.ts. That file is now listed with its reason, and planting a .web.* in each scanned tree proves the scan is not passing because a tree happens to be empty. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * test(build): assert the route exclusions against a tree that has them mobile/app holds no test, spec or +api file, so the exclusion rule was asserted against a tree it could not fire on. A scratch tree plants one of each; dropping the rule now fails this test. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * test(build): 404 unknown file paths in the render check's page server The server answered every path with the document, so pointing publicPath at /wrong-prefix still rendered three green routes: the script is fetched from the one prefix that is served. A path naming a file now has to come out of the bundle, which is what the shell's manifest map does. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * test(build): cover the app bundle verifier's own checks The verifier had no test. One doctors the buildId, which the packaged assert catches; the other rewrites the tree so every digest still agrees and only the two fresh builds can tell, which is what a stale out/ looks like. Deleting either check now fails a test. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * chore(build): tidy the app bundle comments and the job's path prefixes Drops an export nothing read, merges two comments that had drifted apart from the constant they describe, and corrects the claim that the job runs on every PR when it is path-gated. package.json leaves the prefix list because GLOBAL_FORCE_FILES already forces every job on it; mobile/packages/ joins it, since the page resolves a .web.ts out of there. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * style(build): merge the duplicate node:fs/promises import in the census Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * fix(mobile): redirect the hybrid shell route on the web page app/h/[hostId]/web.tsx reaches OrcaMobileWebShellView, whose module calls requireNativeViewManager at import. In a browser that throws before React mounts, and the route manifest imports every route statically, so one native route left the whole page blank at every URL. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * test(build): fail the render check with the error that stopped the mount The check waited on "#root has children" with Playwright's animation-frame polling, so a route module that threw at import read as a bare 30s timeout naming nothing. It now waits on a mount attribute the entry sets after the router commits, polls on a timer, and races the wait against the first uncaught error so the failure carries it. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * test(build): answer the favicon the render browser asks for CI resolves the runner's Google Chrome, which requests /favicon.ico; the bundled headless shell does not. The bundle carries no icon, so the server answers 204 rather than turning a browser habit into a console error the render assertions read as a page fault. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * test(build): settle the render check's uncaught-error race without rejecting The entry throws during goto, before anything awaits the race, so a rejected promise surfaced as an unhandled rejection beside the real failure. The same signal now resolves with the error. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * chore(mobile): list the page transport in the raw request port inventory The placeholder client implements the port, so the boundary test counts it as an unlisted file. It belongs under OWNERS until C0.4's BridgeRpcClient replaces it. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
567 lines
22 KiB
JavaScript
567 lines
22 KiB
JavaScript
import { spawn, spawnSync } from 'node:child_process'
|
|
import { readFileSync } from 'node:fs'
|
|
import { join, resolve } from 'node:path'
|
|
import { describe, expect, it } from 'vitest'
|
|
import { parse } from 'yaml'
|
|
import {
|
|
classifyPrJobs,
|
|
isDocsOnlyPath,
|
|
PR_CHECK_JOBS,
|
|
shouldRunPrChecks,
|
|
STATIC_ANALYSIS_SCAN_ROOTS
|
|
} from './pr-code-change-scope.mjs'
|
|
|
|
const projectDir = resolve(import.meta.dirname, '../..')
|
|
const prWorkflow = parse(readFileSync(join(projectDir, '.github/workflows/pr.yml'), 'utf8'))
|
|
|
|
const expensiveJobs = [
|
|
'static_analysis',
|
|
'typecheck',
|
|
'git_compatibility',
|
|
'codex_index_heal_contract',
|
|
'xterm_patch_sync',
|
|
'shell_contracts',
|
|
'test',
|
|
'orcad_browser',
|
|
'cross-version-wire',
|
|
'managed_hook_node18',
|
|
'package',
|
|
'package_windows'
|
|
]
|
|
|
|
const ALWAYS_ON = ['static_analysis', 'typecheck', 'test']
|
|
|
|
function expectedJobs(overrides, { alwaysOn = true } = {}) {
|
|
return Object.fromEntries(
|
|
PR_CHECK_JOBS.map((job) => [
|
|
job,
|
|
(alwaysOn && ALWAYS_ON.includes(job)) || Boolean(overrides[job])
|
|
])
|
|
)
|
|
}
|
|
|
|
function expectClassification(files, overrides) {
|
|
const result = classifyPrJobs(files)
|
|
const shouldRun = shouldRunPrChecks(files)
|
|
expect(result.should_run).toBe(shouldRun)
|
|
expect(result).toMatchObject({
|
|
should_run: shouldRun,
|
|
...expectedJobs(overrides, { alwaysOn: shouldRun })
|
|
})
|
|
}
|
|
|
|
describe('docs-only path classification', () => {
|
|
it('treats the WeChat README PR files as docs-only', () => {
|
|
expect(
|
|
shouldRunPrChecks([
|
|
'README.md',
|
|
'docs/assets/wechat-qr-group8.jpg',
|
|
'docs/readme/README.zh-CN.md'
|
|
])
|
|
).toBe(false)
|
|
})
|
|
|
|
it('skips root instruction files and GitHub markdown templates', () => {
|
|
expect(isDocsOnlyPath('AGENTS.md')).toBe(true)
|
|
expect(isDocsOnlyPath('CLAUDE.md')).toBe(true)
|
|
expect(isDocsOnlyPath('LICENSE')).toBe(true)
|
|
expect(isDocsOnlyPath('.github/CONTRIBUTING.md')).toBe(true)
|
|
expect(isDocsOnlyPath('.github/pull_request_template.md')).toBe(true)
|
|
expect(isDocsOnlyPath('.github/ISSUE_TEMPLATE/bug_report.yml')).toBe(true)
|
|
expect(isDocsOnlyPath('.github/CODEOWNERS')).toBe(true)
|
|
})
|
|
|
|
it('still runs PR Checks for product markdown and CI', () => {
|
|
expect(isDocsOnlyPath('skills/computer-use/SKILL.md')).toBe(false)
|
|
expect(isDocsOnlyPath('skill-guides/orca-cli.md')).toBe(false)
|
|
expect(isDocsOnlyPath('.github/workflows/pr.yml')).toBe(false)
|
|
expect(isDocsOnlyPath('src/main/index.ts')).toBe(false)
|
|
expect(isDocsOnlyPath('config/scripts/pr-code-change-scope.mjs')).toBe(false)
|
|
expect(shouldRunPrChecks(['README.md', 'src/main/index.ts'])).toBe(true)
|
|
})
|
|
|
|
it('runs PR Checks when the diff is empty rather than skipping by accident', () => {
|
|
expect(shouldRunPrChecks([])).toBe(true)
|
|
})
|
|
|
|
it('does not start desktop PR Checks for mobile-only diffs', () => {
|
|
expect(shouldRunPrChecks(['mobile/src/App.tsx', 'mobile/package.json'])).toBe(false)
|
|
})
|
|
|
|
it('does not start desktop PR Checks for cloud-only diffs', () => {
|
|
expect(
|
|
shouldRunPrChecks([
|
|
'cloud/apps/relay/src/index.ts',
|
|
'cloud/package.json',
|
|
'cloud/.gitleaks.toml',
|
|
'.github/workflows/cloud-verify.yml'
|
|
])
|
|
).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('per-job path classification', () => {
|
|
it('runs every expensive job on an empty diff rather than skipping by accident', () => {
|
|
const result = classifyPrJobs([])
|
|
expect(result.should_run).toBe(true)
|
|
for (const job of PR_CHECK_JOBS) {
|
|
expect(result[job], job).toBe(true)
|
|
}
|
|
})
|
|
|
|
it('skips every expensive job for docs-only diffs', () => {
|
|
expectClassification(['README.md', 'docs/readme/README.zh-CN.md'], {})
|
|
})
|
|
|
|
it('runs packaging and always-on jobs for product source, not git/xterm/shell lanes', () => {
|
|
expectClassification(['src/renderer/src/components/tab-bar/TabBar.tsx'], {
|
|
package: true,
|
|
package_windows: true
|
|
})
|
|
})
|
|
|
|
it('runs Git compatibility only when git capability inputs change', () => {
|
|
expectClassification(['src/shared/git-capability-cache.ts'], {
|
|
git_compatibility: true,
|
|
package: true,
|
|
package_windows: true
|
|
})
|
|
expectClassification(['src/shared/git-binary-compatibility.test.ts'], {
|
|
git_compatibility: true
|
|
})
|
|
})
|
|
|
|
it('runs the Codex index-heal contract only when the heal or its transport changes', () => {
|
|
expectClassification(['src/main/codex/codex-session-index-heal.ts'], {
|
|
codex_index_heal_contract: true,
|
|
package: true,
|
|
package_windows: true
|
|
})
|
|
expectClassification(['src/main/sqlite/sync-database.ts'], {
|
|
codex_index_heal_contract: true,
|
|
package: true,
|
|
package_windows: true
|
|
})
|
|
expectClassification(['src/main/codex/codex-app-server-session.ts'], {
|
|
codex_index_heal_contract: true,
|
|
package: true,
|
|
package_windows: true
|
|
})
|
|
expectClassification(['src/main/codex/codex-index-heal-binary-contract.test.ts'], {
|
|
codex_index_heal_contract: true
|
|
})
|
|
// Keep the real-binary gate live when a transport or launch dependency changes.
|
|
for (const file of [
|
|
'src/main/codex/codex-app-server-capability-signal.ts',
|
|
'src/main/codex/codex-process-exit-deadline.ts',
|
|
'src/main/codex/codex-session-backfill.ts',
|
|
'src/main/codex/codex-session-index-heal-state.ts',
|
|
'src/main/codex-cli/command.ts',
|
|
'src/main/win32-utils.ts',
|
|
'src/shared/node-cli-command-resolution.ts',
|
|
'src/shared/windows-batch-spawn.ts'
|
|
]) {
|
|
expectClassification([file], {
|
|
codex_index_heal_contract: true,
|
|
package: true,
|
|
package_windows: true
|
|
})
|
|
}
|
|
// A neighbouring Codex module must not drag the real-binary job in.
|
|
expectClassification(['src/main/codex/codex-home-paths.ts'], {
|
|
package: true,
|
|
package_windows: true
|
|
})
|
|
})
|
|
|
|
it('runs xterm patch sync only when xterm inputs change', () => {
|
|
expectClassification(['config/patches/xterm-upstream.json'], {
|
|
xterm_patch_sync: true
|
|
})
|
|
expectClassification(['config/patches/@xterm__xterm@6.1.0-beta.287.patch'], {
|
|
xterm_patch_sync: true
|
|
})
|
|
})
|
|
|
|
it('runs native package jobs only for the platform that ships the changed native', () => {
|
|
expectClassification(['native/windows-cli-launcher/OrcaCliLauncher.cs'], {
|
|
package_windows: true
|
|
})
|
|
expectClassification(['native/computer-use-linux/runtime.py'], {
|
|
package: true
|
|
})
|
|
expectClassification(['native/computer-use-macos/Package.swift'], {})
|
|
})
|
|
|
|
it('runs Linux packaging when an artifact contract changes', () => {
|
|
for (const file of [
|
|
'config/docker/cli-launch-contract/Dockerfile',
|
|
'config/docker/cli-launch-contract/run-cli-case.sh',
|
|
'config/docker/headless-pairing/Dockerfile',
|
|
'config/docker/headless-pairing/run-appimage-case.sh',
|
|
'config/docker/headless-serve-shutdown/Dockerfile',
|
|
'config/scripts/run-linux-cli-launch-contract-docker.mjs',
|
|
'config/scripts/run-headless-linux-pairing-docker.mjs',
|
|
'config/scripts/static-appimage-package-contract.cjs'
|
|
]) {
|
|
expectClassification([file], { package: true })
|
|
}
|
|
})
|
|
|
|
it('runs both package jobs when the shared skills runtime verifier changes', () => {
|
|
expectClassification(['config/scripts/verify-skills-cli-runtime.cjs'], {
|
|
package: true,
|
|
package_windows: true
|
|
})
|
|
})
|
|
|
|
it('runs shell contracts when live-shell inputs change', () => {
|
|
expectClassification(['src/main/daemon/shell-ready.ts'], {
|
|
shell_contracts: true,
|
|
package: true,
|
|
package_windows: true
|
|
})
|
|
})
|
|
|
|
it('runs shell contracts when wrapper templates or live-shell fixtures change', () => {
|
|
expectClassification(['src/main/shell-templates.ts'], {
|
|
shell_contracts: true,
|
|
package: true,
|
|
package_windows: true
|
|
})
|
|
expectClassification(['src/main/shell-startup-launch-intent-fixtures.ts'], {
|
|
shell_contracts: true,
|
|
package: true,
|
|
package_windows: true
|
|
})
|
|
})
|
|
|
|
it('runs orcad browser when Chrome launch, session, or tab modules change', () => {
|
|
for (const file of [
|
|
'src/main/orcad/external-chromium-browser-session.ts',
|
|
'src/main/orcad/external-chromium-command-arguments.ts',
|
|
'src/main/orcad/external-chromium-tab-registry.ts',
|
|
'src/main/orcad/external-chromium-tab-projection.ts'
|
|
]) {
|
|
expectClassification([file], {
|
|
orcad_browser: true,
|
|
package: true,
|
|
package_windows: true
|
|
})
|
|
}
|
|
expectClassification(['src/main/orcad/orcad-native-preflight.ts'], {
|
|
package: true,
|
|
package_windows: true
|
|
})
|
|
})
|
|
|
|
it('runs the mobile web app job for the builder, the page source and the shell policy', () => {
|
|
for (const file of [
|
|
'config/scripts/build-mobile-web-app-bundle.mjs',
|
|
'config/scripts/mobile-web-app-route-manifest.mjs',
|
|
'mobile/web-entry/index.tsx',
|
|
'mobile/app/h/[hostId]/index.tsx',
|
|
'mobile/src/transport/client-context.web.tsx',
|
|
'mobile/modules/orca-mobile-web-shell/ios/MobileWebShellCsp.swift',
|
|
// The vendored Expo module the page resolves a .web.ts out of.
|
|
'mobile/packages/expo-two-way-audio/src/ExpoTwoWayAudioModule.web.ts'
|
|
]) {
|
|
expect(classifyPrJobs([file]).mobile_web_app, file).toBe(true)
|
|
}
|
|
})
|
|
|
|
it('runs it on a mobile-only diff, which should_run alone would skip', () => {
|
|
const classified = classifyPrJobs(['mobile/app/h/[hostId]/tasks.tsx'])
|
|
expect(classified.should_run).toBe(false)
|
|
expect(classified.mobile_web_app).toBe(true)
|
|
})
|
|
|
|
it('needs no package.json prefix, because package.json already forces every job', () => {
|
|
// build:mobile-web:app is defined there, so the job has to run on an edit to it. A prefix
|
|
// that broad is not how: GLOBAL_FORCE_FILES already covers the file.
|
|
expect(classifyPrJobs(['package.json']).mobile_web_app).toBe(true)
|
|
})
|
|
|
|
it('leaves it off for changes that cannot reach the page', () => {
|
|
for (const file of ['docs/reference/x.md', 'src/main/orcad/orcad-native-preflight.ts']) {
|
|
expect(classifyPrJobs([file]).mobile_web_app, file).toBe(false)
|
|
}
|
|
})
|
|
|
|
it('runs cross-version wire checks for every working-tree wire module', () => {
|
|
for (const file of [
|
|
'src/shared/protocol-version.ts',
|
|
'src/shared/terminal-stream-protocol.ts',
|
|
'src/shared/agent-session-wire.ts',
|
|
'src/shared/agent-session-mutation-envelope.ts',
|
|
'src/shared/agent-session-journal-item-key.ts',
|
|
'src/shared/agent-session-journal-types.ts',
|
|
'src/main/ai-vault/structured-session-ownership.ts',
|
|
'src/main/native-chat/agent-session-journal/journal-cursor.ts',
|
|
'src/main/native-chat/agent-session-journal/journal-reducer.ts',
|
|
'src/main/native-chat/agent-session-journal/journal-row-schema.ts',
|
|
'src/main/native-chat/agent-session-wire/structured-agent-session-host.ts',
|
|
'src/main/runtime/agent-session-record-store.ts',
|
|
'src/main/runtime/rpc/dispatcher.ts',
|
|
'src/main/runtime/rpc/methods/ai-vault.ts',
|
|
'src/main/runtime/rpc/methods/browser-tab-create-schema.ts',
|
|
'src/main/runtime/rpc/methods/session-tabs.ts',
|
|
'src/main/runtime/rpc/methods/structured-agent-session.ts',
|
|
'src/main/runtime/rpc/methods/structured-agent-session-gate.ts',
|
|
'src/main/runtime/rpc/methods/structured-agent-session-hold.ts',
|
|
'src/main/runtime/rpc/methods/structured-agent-session-schemas.ts',
|
|
'src/main/runtime/rpc/methods/terminal.ts',
|
|
'src/renderer/src/runtime/remote-runtime-terminal-multiplexer.ts'
|
|
]) {
|
|
expectClassification([file], {
|
|
'cross-version-wire': true,
|
|
package: true,
|
|
package_windows: true
|
|
})
|
|
}
|
|
expectClassification(
|
|
['tests/e2e/cross-version-wire/cross-version-terminal-wire.unit.test.ts'],
|
|
{ 'cross-version-wire': true }
|
|
)
|
|
})
|
|
|
|
it('runs workflow-self-change and lockfile diffs as force-all', () => {
|
|
const result = classifyPrJobs(['.github/workflows/pr.yml'])
|
|
expect(result.should_run).toBe(true)
|
|
for (const job of PR_CHECK_JOBS) {
|
|
expect(result[job], job).toBe(true)
|
|
}
|
|
expect(classifyPrJobs(['pnpm-lock.yaml']).git_compatibility).toBe(true)
|
|
})
|
|
|
|
it('primes native caches only when their immutable inputs change', () => {
|
|
expect(classifyPrJobs([]).native_cache_changed).toBe(true)
|
|
expect(classifyPrJobs(['README.md']).native_cache_changed).toBe(false)
|
|
expect(classifyPrJobs(['src/main/index.ts']).native_cache_changed).toBe(false)
|
|
for (const file of [
|
|
'package.json',
|
|
'pnpm-lock.yaml',
|
|
'.github/actions/install-node-dependencies/action.yml',
|
|
'config/scripts/ensure-native-runtime.mjs',
|
|
'config/scripts/rebuild-native-deps.mjs',
|
|
'config/patches/node-pty@1.1.0.patch'
|
|
]) {
|
|
expect(classifyPrJobs([file]).native_cache_changed, file).toBe(true)
|
|
}
|
|
})
|
|
|
|
// Why: static analysis lints changed mobile files with a type-aware pass, and
|
|
// mobile is a separate pnpm project. Without its node_modules every mobile type
|
|
// resolves to an `error` type and the changed-code gate fails on phantom
|
|
// findings, which is exactly how a react-test-renderer union broke a PR.
|
|
it('installs mobile dependencies exactly when mobile files change', () => {
|
|
expect(classifyPrJobs([]).mobile_dependencies).toBe(true)
|
|
expect(classifyPrJobs(['README.md']).mobile_dependencies).toBe(false)
|
|
expect(classifyPrJobs(['src/main/index.ts']).mobile_dependencies).toBe(false)
|
|
expect(
|
|
classifyPrJobs(['src/main/index.ts', 'mobile/src/session/a.test.ts']).mobile_dependencies
|
|
).toBe(true)
|
|
// Why true: a mobile-only diff still skips the desktop suite, but the repo-wide audits lint
|
|
// mobile/, so static analysis runs and its changed-code pass needs the mobile types.
|
|
expect(classifyPrJobs(['mobile/package.json']).mobile_dependencies).toBe(true)
|
|
expect(classifyPrJobs(['mobile/package.json']).should_run).toBe(false)
|
|
expect(classifyPrJobs(['README.md', 'mobile/src/a.ts']).mobile_dependencies).toBe(true)
|
|
})
|
|
|
|
// Why: `mobile/` is desktop-irrelevant for every other job, so a mobile-only diff used to skip
|
|
// the audits that do lint it. That is how #20702 landed two duplicate imports which then failed
|
|
// this gate on every later PR's merge ref until #20895 swept them.
|
|
it('runs static analysis for a mobile-only diff without dragging in the desktop suite', () => {
|
|
const result = classifyPrJobs([
|
|
'mobile/src/test-support/rpc-recording/adapters/push-registration-mount-adapters.ts'
|
|
])
|
|
expect(result.static_analysis).toBe(true)
|
|
expect(result.mobile_dependencies).toBe(true)
|
|
expect(result.should_run).toBe(false)
|
|
for (const job of ['typecheck', 'test', 'package', 'package_windows', 'git_compatibility']) {
|
|
expect(result[job], job).toBe(false)
|
|
}
|
|
})
|
|
|
|
// The ratchet: adding a tree to an audit command has to widen this trigger on its own.
|
|
it('runs static analysis for every tree the audit commands scan', () => {
|
|
expect(STATIC_ANALYSIS_SCAN_ROOTS).toEqual(
|
|
expect.arrayContaining(['src', 'config', 'tests', 'mobile'])
|
|
)
|
|
for (const root of STATIC_ANALYSIS_SCAN_ROOTS) {
|
|
expect(classifyPrJobs([`${root}/changed-file.ts`]).static_analysis, root).toBe(true)
|
|
}
|
|
})
|
|
|
|
it('leaves diffs the audits never read out of static analysis', () => {
|
|
expect(classifyPrJobs(['README.md']).static_analysis).toBe(false)
|
|
expect(classifyPrJobs(['cloud/apps/relay/src/index.ts']).static_analysis).toBe(false)
|
|
})
|
|
|
|
it('keeps unit-test-only diffs out of packaging', () => {
|
|
expectClassification(['src/main/git/git-status.test.ts'], {
|
|
git_compatibility: true
|
|
})
|
|
})
|
|
|
|
it('emits GitHub output pairs from the shipped CLI', () => {
|
|
const result = spawnSync(process.execPath, ['config/scripts/pr-code-change-scope.mjs'], {
|
|
cwd: projectDir,
|
|
encoding: 'utf8',
|
|
input: 'config/patches/xterm-upstream.json\n'
|
|
})
|
|
expect(result.status, result.stderr).toBe(0)
|
|
expect(result.stdout).toContain('should_run=true\n')
|
|
expect(result.stdout).toContain('xterm_patch_sync=true\n')
|
|
expect(result.stdout).toContain('git_compatibility=false\n')
|
|
expect(result.stdout).toContain('package=false\n')
|
|
expect(result.stdout).toContain('test=true\n')
|
|
})
|
|
|
|
// A long-lived PR whose base.sha has gone stale diffs thousands of files, so the writer
|
|
// outruns one pipe buffer. A single fd-0 read then returns early, breaks the writer's pipe,
|
|
// and still exits 0 -- emitting no pairs at all, which silently skips every lane.
|
|
it('classifies a path that arrives after the first pipe buffer', async () => {
|
|
const filler = Array.from(
|
|
{ length: 12_000 },
|
|
(_, index) => `docs/reference/generated-placeholder-${index}.md`
|
|
)
|
|
const input = `${[...filler, 'config/patches/xterm-upstream.json'].join('\n')}\n`
|
|
expect(input.length).toBeGreaterThan(64 * 1024)
|
|
|
|
const child = spawn(process.execPath, ['config/scripts/pr-code-change-scope.mjs'], {
|
|
cwd: projectDir,
|
|
stdio: ['pipe', 'pipe', 'pipe']
|
|
})
|
|
let stdout = ''
|
|
let stderr = ''
|
|
let brokePipe = false
|
|
child.stdout.setEncoding('utf8')
|
|
child.stderr.setEncoding('utf8')
|
|
child.stdout.on('data', (chunk) => (stdout += chunk))
|
|
child.stderr.on('data', (chunk) => (stderr += chunk))
|
|
child.stdin.on('error', (error) => {
|
|
brokePipe ||= error.code === 'EPIPE'
|
|
})
|
|
|
|
const exitCode = await new Promise((resolvePromise) => {
|
|
child.on('close', resolvePromise)
|
|
let offset = 0
|
|
const step = () => {
|
|
if (offset >= input.length) {
|
|
child.stdin.end()
|
|
return
|
|
}
|
|
child.stdin.write(input.slice(offset, offset + 64 * 1024))
|
|
offset += 64 * 1024
|
|
setTimeout(step, 20)
|
|
}
|
|
step()
|
|
})
|
|
|
|
expect(stderr).not.toContain('EAGAIN')
|
|
expect(brokePipe).toBe(false)
|
|
expect(exitCode, stderr).toBe(0)
|
|
expect(stdout).toContain('should_run=true\n')
|
|
expect(stdout).toContain('xterm_patch_sync=true\n')
|
|
})
|
|
})
|
|
|
|
describe('PR Checks skip wiring', () => {
|
|
it('classifies the PR range with a tested script and expands renames', () => {
|
|
const classify = prWorkflow.jobs.code_paths.steps.find(
|
|
(step) => step.name === 'Classify changed paths'
|
|
)
|
|
expect(classify.run).toContain('--diff-filter=ACDMR')
|
|
expect(classify.run).toContain('--no-renames')
|
|
expect(classify.run).toContain('--merge-base "$BASE_SHA" "$HEAD_SHA"')
|
|
expect(classify.run).toContain('node config/scripts/pr-code-change-scope.mjs')
|
|
expect(classify.run).toContain('tee -a "$GITHUB_OUTPUT"')
|
|
for (const jobName of ['should_run', 'native_cache_changed', ...expensiveJobs]) {
|
|
expect(prWorkflow.jobs.code_paths.outputs[jobName], jobName).toBe(
|
|
`\${{ steps.filter.outputs.${jobName} }}`
|
|
)
|
|
}
|
|
})
|
|
|
|
it('gives static analysis the mobile types its type-aware pass resolves', () => {
|
|
expect(prWorkflow.jobs.code_paths.outputs.mobile_dependencies).toBe(
|
|
'${{ steps.filter.outputs.mobile_dependencies }}'
|
|
)
|
|
const steps = prWorkflow.jobs.static_analysis.steps
|
|
const install = steps.findIndex(
|
|
(step) => step.uses === './.github/actions/install-mobile-dependencies'
|
|
)
|
|
const gate = steps.findIndex((step) => step.name === 'Enforce changed-code quality')
|
|
expect(install).toBeGreaterThan(-1)
|
|
expect(install).toBeLessThan(gate)
|
|
expect(steps[install].if).toBe("needs.code_paths.outputs.mobile_dependencies == 'true'")
|
|
// The install itself moved into the action the packaging jobs share; assert it there so
|
|
// this job cannot keep the step while the action stops installing anything.
|
|
const action = parse(
|
|
readFileSync(
|
|
join(projectDir, '.github/actions/install-mobile-dependencies/action.yml'),
|
|
'utf8'
|
|
)
|
|
)
|
|
const [installStep] = action.runs.steps
|
|
expect(installStep['working-directory']).toBe('mobile')
|
|
expect(installStep.run).toContain('--frozen-lockfile')
|
|
})
|
|
|
|
it('keeps the cheap root-directory guard on docs-only PRs', () => {
|
|
expect(prWorkflow.jobs.root_directory_guard.if).toBeUndefined()
|
|
expect(prWorkflow.jobs.root_directory_guard.needs).toBeUndefined()
|
|
})
|
|
|
|
it('gates each expensive job on its classifier and cache prerequisite', () => {
|
|
for (const jobName of expensiveJobs.filter((jobName) => jobName !== 'test')) {
|
|
expect(prWorkflow.jobs[jobName].needs, jobName).toEqual(['code_paths'])
|
|
expect(prWorkflow.jobs[jobName].if, jobName).toBe(
|
|
`needs.code_paths.outputs.${jobName} == 'true'`
|
|
)
|
|
}
|
|
expect(prWorkflow.jobs.test.needs).toEqual(['code_paths', 'test_native_cache'])
|
|
expect(prWorkflow.jobs.test.if).toContain("needs.code_paths.outputs.test == 'true'")
|
|
expect(prWorkflow.jobs.test.if).toContain("needs.test_native_cache.result == 'success'")
|
|
expect(prWorkflow.jobs.test.if).toContain("needs.test_native_cache.result == 'skipped'")
|
|
expect(prWorkflow.jobs.test_native_cache.needs).toEqual(['code_paths'])
|
|
expect(prWorkflow.jobs.test_native_cache.if).toBe(
|
|
"needs.code_paths.outputs.native_cache_changed == 'true'"
|
|
)
|
|
expect(prWorkflow.jobs.test_native_cache.strategy).toBeUndefined()
|
|
const primerInstall = prWorkflow.jobs.test_native_cache.steps.find(
|
|
(step) => step.uses === './.github/actions/install-node-dependencies'
|
|
)
|
|
expect(primerInstall.with['node-version']).toBe('24')
|
|
})
|
|
|
|
it('skips e2e detection on docs-only PRs without dropping the draft gate', () => {
|
|
const filter = prWorkflow.jobs.code_paths.steps.find((step) => step.id === 'e2e_filter')
|
|
expect(filter.if).toBe(
|
|
"github.event.pull_request.draft != true && steps.filter.outputs.should_run == 'true'"
|
|
)
|
|
expect(prWorkflow.jobs['e2e-paths']).toBeUndefined()
|
|
})
|
|
|
|
it('lets verify pass skipped jobs the classifier turned off', () => {
|
|
const verifyStep = prWorkflow.jobs.verify.steps.find(
|
|
(step) => step.name === 'Require successful checks'
|
|
)
|
|
expect(prWorkflow.jobs.verify.needs[0]).toBe('code_paths')
|
|
expect(verifyStep.env.SHOULD_RUN).toBe('${{ needs.code_paths.outputs.should_run }}')
|
|
expect(verifyStep.run).toContain('"$ROOT_DIRECTORY_GUARD" != "success"')
|
|
expect(verifyStep.run).toContain('# Require success when the PR has code-relevant changes')
|
|
expect(verifyStep.run).toContain('expected skipped')
|
|
expect(verifyStep.run).toContain('expected success')
|
|
for (const job of prWorkflow.jobs.verify.needs) {
|
|
if (job === 'code_paths' || job === 'root_directory_guard') {
|
|
continue
|
|
}
|
|
const envVar = `${job.replaceAll('-', '_').toUpperCase()}_SHOULD_RUN`
|
|
expect(verifyStep.env[envVar]).toBe(`\${{ needs.code_paths.outputs.${job} }}`)
|
|
expect(verifyStep.run).toContain(`"$${envVar}"`)
|
|
}
|
|
})
|
|
})
|