Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ jobs:
fi
echo "Settings schema is up-to-date"

- name: 'Check serve fast-path bundle closure'
if: "${{ needs.classify_pr.outputs.skip_ci != 'true' }}"
run: 'npm run check:serve-fast-path-bundle'
Comment thread
doudouOUC marked this conversation as resolved.
Resolved

- name: 'Run tests and generate reports'
id: 'unit_tests'
if: "${{ needs.classify_pr.outputs.skip_ci != 'true' }}"
Expand Down Expand Up @@ -428,7 +432,6 @@ jobs:
os: '${{ matrix.os }}'
github_token: '${{ secrets.GITHUB_TOKEN }}'


# Integration tests run only in the merge queue, not on every PR push.
# They are the suite that previously ran *only* in the nightly Release
# pipeline (`release.yml`), so regressions stayed hidden until release
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"telemetry": "node scripts/telemetry.js",
"check:lockfile": "node scripts/check-lockfile.js",
"check:desktop-isolation": "node scripts/check-desktop-isolation.js",
"check:serve-fast-path-bundle": "npm run build -- --cli-only && cross-env DEV=true npm run bundle && node scripts/check-serve-fast-path-bundle.js",
"desktop-openwork-sync": "bun run scripts/desktop-openwork-sync.ts",
"clean": "node scripts/clean.js",
"pre-commit": "node scripts/pre-commit.js"
Expand Down
103 changes: 17 additions & 86 deletions packages/cli/src/serve/fast-path.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import { afterEach, describe, expect, it, vi } from 'vitest';
import yargs, { type Argv } from 'yargs';
import { execFileSync } from 'node:child_process';
import {
existsSync,
mkdirSync,
Expand Down Expand Up @@ -70,26 +69,13 @@ const originalCloudShell = process.env['CLOUD_SHELL'];
const originalGoogleCloudProject = process.env['GOOGLE_CLOUD_PROJECT'];
const originalCwd = process.cwd();
const cliPackageRoot = process.cwd();
const repoRoot = resolve(cliPackageRoot, '../..');

interface StaticSourceGraph {
localFiles: Set<string>;
externalValueImports: Set<string>;
unresolvedLocalImports: string[];
}

interface EsbuildMetafileOutput {
inputs?: Record<string, unknown>;
imports?: Array<{
path: string;
kind?: string;
}>;
}

interface EsbuildMetafile {
outputs: Record<string, EsbuildMetafileOutput>;
}

function normalizePathForTest(filePath: string): string {
return filePath.replace(/\\/g, '/');
}
Expand Down Expand Up @@ -196,69 +182,6 @@ function collectStaticSourceGraph(entryFile: string): StaticSourceGraph {
return { localFiles, externalValueImports, unresolvedLocalImports };
}

function collectBundledRunServeStaticRuntimeOffenders(): string[] {
const metafilePath = resolve(repoRoot, 'dist/esbuild.json');
rmSync(metafilePath, { force: true });
execFileSync(process.execPath, [resolve(repoRoot, 'esbuild.config.js')], {
cwd: repoRoot,
env: { ...process.env, DEV: 'true' },
stdio: 'pipe',
timeout: 30_000,
});

expect(existsSync(metafilePath)).toBe(true);
const metafile = JSON.parse(
readFileSync(metafilePath, 'utf8'),
) as EsbuildMetafile;
const outputs = new Map(
Object.entries(metafile.outputs).map(([outputPath, output]) => [
normalizePathForTest(outputPath),
output,
]),
);
const runServeOutput = [...outputs.entries()].find(([, output]) =>
Object.keys(output.inputs ?? {}).some(
(input) =>
normalizePathForTest(input) ===
'packages/cli/src/serve/run-qwen-serve.ts',
),
);
expect(runServeOutput).toBeDefined();
const queue = [runServeOutput![0]];
const staticClosure = new Set(queue);

for (let i = 0; i < queue.length; i++) {
const output = outputs.get(queue[i]);
for (const bundledImport of output?.imports ?? []) {
if (bundledImport.kind !== 'import-statement') continue;
const importedOutput = normalizePathForTest(bundledImport.path);
if (!outputs.has(importedOutput) || staticClosure.has(importedOutput)) {
continue;
}
staticClosure.add(importedOutput);
queue.push(importedOutput);
}
}

const forbiddenInputs = new Set([
'packages/cli/src/serve/acp-session-bridge.ts',
'packages/acp-bridge/src/bridge.ts',
'packages/acp-bridge/src/bridgeClient.ts',
'packages/acp-bridge/src/spawnChannel.ts',
]);
const offenders: string[] = [];
for (const outputPath of staticClosure) {
const output = outputs.get(outputPath);
for (const input of Object.keys(output?.inputs ?? {})) {
const normalizedInput = normalizePathForTest(input);
if (forbiddenInputs.has(normalizedInput)) {
offenders.push(`${outputPath} -> ${normalizedInput}`);
}
}
}
return offenders;
}

function useTempQwenHome(): string {
tempQwenHome = realpathSync(
mkdtempSync(join(os.tmpdir(), 'qws-fast-path-home-')),
Expand Down Expand Up @@ -490,6 +413,23 @@ describe('CLI entry import boundary', () => {
expect(runServeSource).toContain("import('@qwen-code/acp-bridge/bridge')");
});

it('keeps request helpers from value-importing the ACP compatibility shim', () => {
const requestHelpersSource = readFileSync(
'src/serve/server/request-helpers.ts',
'utf8',
);

expect(requestHelpersSource).not.toMatch(
/from ['"]\.\.\/acp-session-bridge\.js['"]/,
);
expect(requestHelpersSource).toContain(
"import type { AcpSessionBridge } from '@qwen-code/acp-bridge/bridgeTypes';",
);
expect(requestHelpersSource).toContain(
"import { MAX_WORKSPACE_PATH_LENGTH } from '@qwen-code/acp-bridge/workspacePaths';",
);
});

it('keeps the runQwenServe static source graph free of ACP runtime modules', () => {
const graph = collectStaticSourceGraph(
resolve(cliPackageRoot, 'src/serve/run-qwen-serve.ts'),
Expand Down Expand Up @@ -519,15 +459,6 @@ describe('CLI entry import boundary', () => {
`Unexpected ACP runtime imports:\n${forbiddenImports.join('\n')}`,
).toEqual([]);
});

it('keeps bundled runQwenServe static imports free of ACP runtime modules', () => {
const offenders = collectBundledRunServeStaticRuntimeOffenders();

expect(
offenders,
`Unexpected ACP runtime inputs in static bundle closure:\n${offenders.join('\n')}`,
).toEqual([]);
}, 30_000);
});

describe('serve fast path argument parsing', () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export default defineConfig({
__dirname,
'../acp-bridge/src/bridgeFileSystem.ts',
),
'@qwen-code/acp-bridge/eventBus': path.resolve(
__dirname,
'../acp-bridge/src/eventBus.ts',
),
'@qwen-code/acp-bridge/workspacePaths': path.resolve(
__dirname,
'../acp-bridge/src/workspacePaths.ts',
Expand Down
Loading
Loading