Skip to content

Commit 7bb3bfc

Browse files
author
wenshao
committed
probe r3 head s11-status-plain
0 parents  commit 7bb3bfc

11 files changed

Lines changed: 2718 additions & 0 deletions

‎.github/workflows/probe.yml‎

Lines changed: 1262 additions & 0 deletions
Large diffs are not rendered by default.

‎PROBE.json‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"arm": "head",
3+
"rev": "e27c390a84",
4+
"scenario": "s11-status-plain",
5+
"spec": [
6+
"m",
7+
"pass",
8+
"ok",
9+
"report",
10+
false,
11+
true,
12+
15
13+
]
14+
}

‎package.json‎

Lines changed: 256 additions & 0 deletions
Large diffs are not rendered by default.

‎scripts/lib/entry-point.js‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @license
3+
* Copyright 2026 Qwen Team
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
import { realpathSync } from 'node:fs';
8+
import { resolve } from 'node:path';
9+
import { fileURLToPath } from 'node:url';
10+
11+
/**
12+
* Whether the module is the executed entry point rather than an import.
13+
*
14+
* `import.meta.url` is a percent-encoded file URL, so comparing it to a plain
15+
* `file://` + path breaks on spaces or non-ASCII characters. Both sides are
16+
* resolved through `realpath`, because Node resolves the entry module's
17+
* symlinks while `argv[1]` keeps the path the shell was given.
18+
*/
19+
export function isEntryPoint(metaUrl, argv1) {
20+
if (!argv1) return false;
21+
try {
22+
return (
23+
realpathSync(resolve(argv1)) === realpathSync(fileURLToPath(metaUrl))
24+
);
25+
} catch {
26+
return false;
27+
}
28+
}

‎scripts/lib/qwen-home-bootstrap.js‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Qwen Team
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
import { existsSync, readFileSync } from 'node:fs';
8+
import path from 'node:path';
9+
import os from 'node:os';
10+
import dotenv from 'dotenv';
11+
12+
/**
13+
* Expands tilde and resolves relative paths to absolute. Mirrors
14+
* `Storage.resolvePath` in packages/core (kept in sync — these scripts run
15+
* before the core bundle is built and cannot import from it).
16+
*/
17+
export function resolvePath(dir) {
18+
let resolved = dir;
19+
if (
20+
resolved === '~' ||
21+
resolved.startsWith('~/') ||
22+
resolved.startsWith('~\\')
23+
) {
24+
const segments =
25+
resolved === '~'
26+
? []
27+
: resolved
28+
.slice(2)
29+
.split(/[/\\]+/)
30+
.filter(Boolean);
31+
resolved = path.join(os.homedir(), ...segments);
32+
}
33+
if (!path.isAbsolute(resolved)) {
34+
resolved = path.resolve(resolved);
35+
}
36+
return resolved;
37+
}
38+
39+
/**
40+
* Pre-resolves QWEN_HOME / QWEN_RUNTIME_DIR from home-scoped `.env` files so
41+
* that helper scripts (sandbox launcher, telemetry) agree with the main CLI's
42+
* `preResolveHomeEnvOverrides`. Without this, the CLI may route to a custom
43+
* config dir via `~/.env` while these scripts still read `~/.qwen/...`,
44+
* splitting global state across two locations.
45+
*
46+
* Project `.env` files are deliberately excluded — only home-scoped files are
47+
* consulted so a project repo can never redirect global state through this
48+
* back door (consistent with `PROJECT_ENV_HARDCODED_EXCLUSIONS` in the CLI).
49+
*
50+
* Idempotent: safe to call from multiple scripts in the same process.
51+
*/
52+
export function bootstrapHomeEnv() {
53+
if (process.env.QWEN_HOME && process.env.QWEN_RUNTIME_DIR) {
54+
return;
55+
}
56+
const initialQwenHome = process.env.QWEN_HOME;
57+
const initialQwenDir = initialQwenHome
58+
? resolvePath(initialQwenHome)
59+
: path.join(os.homedir(), '.qwen');
60+
const candidates = [path.join(initialQwenDir, '.env')];
61+
if (!initialQwenHome) {
62+
candidates.push(path.join(os.homedir(), '.env'));
63+
}
64+
for (const candidate of candidates) {
65+
readEnvInto(candidate);
66+
}
67+
68+
// If QWEN_HOME was just discovered, also read <new QWEN_HOME>/.env so
69+
// QWEN_RUNTIME_DIR can be sourced from there (mirrors the VS Code
70+
// companion's bootstrapHomeEnvOverrides).
71+
const discoveredQwenHome = process.env.QWEN_HOME;
72+
if (discoveredQwenHome && discoveredQwenHome !== initialQwenHome) {
73+
const discoveredDir = resolvePath(discoveredQwenHome);
74+
if (discoveredDir !== initialQwenDir) {
75+
readEnvInto(path.join(discoveredDir, '.env'));
76+
}
77+
}
78+
}
79+
80+
function readEnvInto(file) {
81+
if (!existsSync(file)) {
82+
return;
83+
}
84+
try {
85+
const parsed = dotenv.parse(readFileSync(file, 'utf-8'));
86+
for (const key of ['QWEN_HOME', 'QWEN_RUNTIME_DIR']) {
87+
if (parsed[key] && !Object.hasOwn(process.env, key)) {
88+
process.env[key] = parsed[key];
89+
}
90+
}
91+
} catch {
92+
// Match dotenv's quiet-mode behavior used elsewhere.
93+
}
94+
}

‎scripts/lib/release-helpers.js‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Qwen Team
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
import { readFileSync } from 'node:fs';
8+
9+
/**
10+
* Parse command-line arguments in `--key=value` format.
11+
* Flags without a value (e.g. `--dry-run`) are set to `true`.
12+
*/
13+
export function getArgs() {
14+
const args = {};
15+
process.argv.slice(2).forEach((arg) => {
16+
if (arg.startsWith('--')) {
17+
const stripped = arg.substring(2);
18+
const eqIndex = stripped.indexOf('=');
19+
if (eqIndex === -1) {
20+
args[stripped] = true;
21+
} else {
22+
args[stripped.substring(0, eqIndex)] = stripped.substring(eqIndex + 1);
23+
}
24+
}
25+
});
26+
return args;
27+
}
28+
29+
/**
30+
* Read and parse a JSON file.
31+
*/
32+
export function readJson(filePath) {
33+
return JSON.parse(readFileSync(filePath, 'utf-8'));
34+
}
35+
36+
/**
37+
* Validate that a version string matches the expected format.
38+
* Throws if the version is invalid.
39+
*/
40+
export function validateVersion(version, format, name) {
41+
const versionRegex = {
42+
'X.Y.Z': /^\d+\.\d+\.\d+$/,
43+
'X.Y.Z-preview.N': /^\d+\.\d+\.\d+-preview\.\d+$/,
44+
};
45+
46+
if (!versionRegex[format] || !versionRegex[format].test(version)) {
47+
throw new Error(
48+
`Invalid ${name}: ${version}. Must be in ${format} format.`,
49+
);
50+
}
51+
}
52+
53+
/**
54+
* Check whether an error from `gh release view` indicates the release
55+
* simply doesn't exist (as opposed to an unexpected failure).
56+
*
57+
* Copied verbatim into `scripts/assert-release-version.mjs`, which the
58+
* release workflow checks out on its own and so cannot import this file.
59+
* Change both together; `scripts/tests/release-workflow.test.js` pins it.
60+
*/
61+
export function isExpectedMissingGitHubRelease(error) {
62+
const stderr = error.stderr?.toString() ?? '';
63+
const stdout = error.stdout?.toString() ?? '';
64+
const message = `${error.message}\n${stderr}\n${stdout}`;
65+
return message.includes('release not found') || message.includes('Not Found');
66+
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/**
2+
* @license
3+
* Copyright 2026 Qwen Team
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
import assert from 'node:assert/strict';
8+
import fs from 'node:fs';
9+
import path from 'node:path';
10+
11+
const UNUSED_ENTRY_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000;
12+
13+
/**
14+
* Returns the bytes at `url` once `digest` of them equals `expected`. With a
15+
* `cacheDir`, a copy there is used only if it matches, and a fresh download is
16+
* written back. The cache only saves time: no cache failure reaches the caller.
17+
*/
18+
export async function fetchVerifiedArchive(
19+
url,
20+
filename,
21+
{ digest, expected },
22+
{
23+
cacheDir,
24+
fetchImpl = fetch,
25+
sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
26+
} = {},
27+
) {
28+
const cached = cacheDir && path.join(cacheDir, filename);
29+
if (cached) {
30+
try {
31+
const bytes = fs.readFileSync(cached);
32+
if (digest(bytes) === expected) {
33+
console.log(`runtime archive reused from cache: ${cached}`);
34+
markUsed(cached);
35+
return bytes;
36+
}
37+
// Replaced by the download below.
38+
console.log(`runtime archive in cache failed verification: ${cached}`);
39+
} catch {
40+
// Not cached yet, or unreadable: download it below.
41+
}
42+
}
43+
let bytes;
44+
for (let attempt = 1; !bytes; attempt++) {
45+
try {
46+
const response = await fetchImpl(url, {
47+
signal: AbortSignal.timeout(300_000),
48+
});
49+
assert.equal(
50+
response.status,
51+
200,
52+
`runtime download: ${url} returned ${response.status}`,
53+
);
54+
const body = Buffer.from(await response.arrayBuffer());
55+
// Verified per attempt: a truncated or stale body is retried like a
56+
// failed request.
57+
const actual = digest(body);
58+
assert(
59+
actual === expected,
60+
`runtime archive digest mismatch: ${url} is ${actual}, pinned ${expected}`,
61+
);
62+
bytes = body;
63+
} catch (error) {
64+
if (attempt === 3) throw error;
65+
// undici reports only "fetch failed"; the cause says why.
66+
const cause =
67+
error instanceof Error && error.cause instanceof Error
68+
? ` (cause: ${error.cause.message})`
69+
: '';
70+
console.log(
71+
`runtime download attempt ${attempt} failed: ${error}${cause}`,
72+
);
73+
await sleep(attempt * 5_000);
74+
}
75+
}
76+
if (cached) {
77+
// Rename into place so a concurrent job never reads a partial file.
78+
const partial = `${cached}.${process.pid}.tmp`;
79+
try {
80+
fs.mkdirSync(cacheDir, { recursive: true });
81+
fs.writeFileSync(partial, bytes);
82+
fs.renameSync(partial, cached);
83+
console.log(`runtime archive cached: ${cached}`);
84+
} catch (error) {
85+
try {
86+
fs.rmSync(partial, { force: true });
87+
} catch {
88+
// A directory that refused the write can refuse the cleanup too.
89+
}
90+
console.log(`runtime archive not cached: ${error}`);
91+
}
92+
}
93+
return bytes;
94+
}
95+
96+
function markUsed(file) {
97+
try {
98+
const now = new Date();
99+
fs.utimesSync(file, now, now);
100+
} catch {
101+
// The sweep below also spares the archives a run names as used.
102+
}
103+
}
104+
105+
/**
106+
* Removes what no run has used for a week: archives that only other revisions
107+
* pin, and partial files a killed run left behind. Call it once a run has
108+
* fetched every archive it needs, naming them in `used`; until then, an
109+
* archive the run fetches later may look just as unused. Each fetch marks its
110+
* archive as used, so revisions still running keep theirs, and an in-flight
111+
* partial file is always newer than a week.
112+
*/
113+
export function sweepRuntimeCache(cacheDir, used) {
114+
let entries;
115+
try {
116+
entries = fs.readdirSync(cacheDir);
117+
} catch {
118+
return;
119+
}
120+
const now = Date.now();
121+
for (const entry of entries) {
122+
if (used.includes(entry)) continue;
123+
try {
124+
const file = path.join(cacheDir, entry);
125+
// Another job may have removed it since the listing.
126+
const stats = fs.statSync(file, { throwIfNoEntry: false });
127+
if (stats?.isFile() && now - stats.mtimeMs > UNUSED_ENTRY_MAX_AGE_MS) {
128+
fs.rmSync(file, { force: true });
129+
}
130+
} catch {
131+
// Sweeping only saves space; an entry it cannot remove does not stop
132+
// it from removing the rest.
133+
}
134+
}
135+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @license
3+
* Copyright 2026 Qwen Team
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// The runtimes the standalone regression runs under, and the published
8+
// digests of their archives: the Node SHASUMS256.txt entry and the npm
9+
// `dist.integrity` of @oven/bun-*. Pinning them lets CI verify an archive,
10+
// downloaded or cached, without first fetching checksum metadata from the
11+
// network. A version bump replaces every digest of that runtime.
12+
export const NODE_VERSION = '24.19.0';
13+
export const BUN_VERSION = '1.4.4';
14+
15+
export const RUNTIME_ARCHIVE_DIGESTS = {
16+
'linux-x64': {
17+
node: 'f625d97cd707df4ff96254916fbc5ff014f09c09effe5a1e0ca8f6d41a8789d4',
18+
bun: 'sha512-CHbbkmHVM28T1GFq+6GL4Ao4ujwwYwj1CxFFwEFzLanPfNsId9AhbIP0Q4reWuWBkGimUkoQygrK7Rgjtj3vog==',
19+
},
20+
'linux-arm64': {
21+
node: 'd28c8a5bf0a808f0ed434a1dce8c54ae98f0371c0bd86ac58abc613f73e6643f',
22+
bun: 'sha512-ZTVtpf9zmHSBVPX1sBwe5agGb/rN34yPGg/Hby8e2Ax2uCUA2URZKlZH7qLntK7qaFJCMXh9v0GWNYN2zINz1w==',
23+
},
24+
'darwin-x64': {
25+
node: 'd1b5e999db158c62fe8f7267a4476b035d8bd93b1a605bac24a3f0dd166e3316',
26+
bun: 'sha512-oKGcxLsvh4oHjAo28nPm8c/xN0o/OmGyj1IHYc94vprkWsW2hNg2keEZt5f40cI5Hvu4jDlSRTR0UNpv1UIAxw==',
27+
},
28+
'darwin-arm64': {
29+
node: '8294b7aa9b03997481c06babf1e8b270c859358f27da57a11509afe537ac381d',
30+
bun: 'sha512-zW/hxwc8sJAILGwB5eTC4i48ouGXf0V4lrxmEOk3JIE6JkYVW1TZh1E2pIempqsezgW1sckTIIDudFON8bJ2Mw==',
31+
},
32+
};

0 commit comments

Comments
 (0)