Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:construction_worker: Record kernel test execution intervals https://github.com/siyuan-note/siyuan/issues/20491

Daniel10c3ddea7a95
diff --git a/scripts/test-kernel.mjs b/scripts/test-kernel.mjs
index 6c24b2c2c1..2829a68d92 100644
--- a/scripts/test-kernel.mjs
+++ b/scripts/test-kernel.mjs
@@ -108,6 +108,8 @@ const command = (args, cwd = kernel) => {
export const runJSONJob = async ({name, args, cwd, expectedTests, executable = "go"}, output) => {
const started = performance.now();
+ const startedAt = new Date().toISOString();
+ console.log(`${name}: START ${startedAt}`);
const logPath = join(output, name + ".jsonl");
const log = createWriteStream(logPath);
const child = spawn(executable, args, {cwd, windowsHide: true, stdio: ["ignore", "pipe", "pipe"]});
@@ -157,16 +159,35 @@ export const runJSONJob = async ({name, args, cwd, expectedTests, executable = "
await new Promise(resolve => log.end(resolve));
const missing = expectedTests?.filter(test => !completed.has(test)) ?? [];
const unexpected = expectedTests ? [...completed].filter(test => !expectedTests.includes(test)) : [];
- const result = {name, code: code ?? 1, seconds: (performance.now() - started) / 1000, tests: completed.size,
+ const result = {name, code: code ?? 1, startedAt, endedAt: new Date().toISOString(),
+ seconds: (performance.now() - started) / 1000, tests: completed.size,
failed: [...failed], missing, unexpected, logPath};
if (result.code || failed.size || missing.length || unexpected.length) {
result.code = 1;
console.error(`${name} failed\n${tail.join("\n")}\nMissing: ${missing.join(", ")}\nUnexpected: ${unexpected.join(", ")}`);
}
- console.log(`${name}: ${result.code ? "FAIL" : "PASS"}, ${result.tests} tests, ${result.seconds.toFixed(1)}s`);
+ console.log(`${name}: ${result.code ? "FAIL" : "PASS"}, ${result.tests} tests, ${result.seconds.toFixed(1)}s; END ${result.endedAt}`);
return result;
};
+export const runCompilation = async (args, cwd = kernel, executable = "go") => {
+ const started = performance.now();
+ const startedAt = new Date().toISOString();
+ console.log(`compile: START ${startedAt}`);
+ let timing;
+ try {
+ await new Promise((resolve, reject) => {
+ const compiler = spawn(executable, args, {cwd, windowsHide: true, stdio: "inherit"});
+ compiler.on("error", reject);
+ compiler.on("close", code => code === 0 ? resolve() : reject(new Error("Sharded test compilation failed: " + code)));
+ });
+ } finally {
+ timing = {startedAt, endedAt: new Date().toISOString(), seconds: (performance.now() - started) / 1000};
+ console.log(`compile: END ${timing.endedAt}, ${timing.seconds.toFixed(1)}s`);
+ }
+ return timing;
+};
+
export const runJobs = async (jobs, concurrency, run) => {
let next = 0;
const results = new Array(jobs.length);
@@ -201,6 +222,7 @@ const main = async () => {
throw new Error("--shards must be an integer between 1 and 16");
}
const started = performance.now();
+ const startedAt = new Date().toISOString();
const workspace = mkdtempSync(join(tmpdir(), "siyuan-kernel-tests-"));
const output = options.output ?? mkdtempSync(join(tmpdir(), "siyuan-kernel-results-"));
mkdirSync(output, {recursive: true});
@@ -224,14 +246,8 @@ const main = async () => {
const binaries = join(workspace, "binaries");
mkdirSync(binaries);
// 同一次 Go 构建共享依赖,每个包只链接一次,原生编译与测试运行分开控制并发。
- await new Promise((resolve, reject) => {
- const compiler = spawn("go", ["test", ...tags, "-p", String(packageParallelism), "-c", "-o", binaries,
- ...configurations.map(configuration => "./" + configuration.name)], {
- cwd: kernel, windowsHide: true, stdio: "inherit",
- });
- compiler.on("error", reject);
- compiler.on("close", code => code === 0 ? resolve() : reject(new Error("Sharded test compilation failed: " + code)));
- });
+ const compilation = await runCompilation(["test", ...tags, "-p", String(packageParallelism), "-c", "-o", binaries,
+ ...configurations.map(configuration => "./" + configuration.name)]);
const jobs = [];
const backgroundJobs = [];
const inventory = {};
@@ -273,10 +289,12 @@ const main = async () => {
if (otherJob) {
results.unshift(...await otherJob);
}
- const summary = {seconds: (performance.now() - started) / 1000, modelTests: inventory.model.tests, shards: inventory.model.shards,
+ const summary = {startedAt, endedAt: new Date().toISOString(), seconds: (performance.now() - started) / 1000,
+ compilation, modelTests: inventory.model.tests, shards: inventory.model.shards,
apiTests: inventory.api?.tests ?? 0, apiShards: inventory.api?.shards ?? 0, packages: inventory, results};
writeFileSync(join(output, "summary.json"), JSON.stringify(summary, null, 2) + "\n");
- console.log(`Kernel tests: ${summary.seconds.toFixed(1)}s; summary: ${join(output, "summary.json")}`);
+ console.log(`Kernel tests: ${summary.seconds.toFixed(1)}s; START ${summary.startedAt}; END ${summary.endedAt}; ` +
+ `summary: ${join(output, "summary.json")}`);
process.exitCode = results.some(result => result.code) ? 1 : 0;
} finally {
if (otherJob) {
diff --git a/scripts/test-kernel.test.mjs b/scripts/test-kernel.test.mjs
index d4f2ce950e..045e994d28 100644
--- a/scripts/test-kernel.test.mjs
+++ b/scripts/test-kernel.test.mjs
@@ -3,7 +3,7 @@ import * as assert from "node:assert/strict";
import {existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync} from "node:fs";
import {tmpdir} from "node:os";
import {dirname, join, resolve} from "node:path";
-import {listTests, orderJobs, planShards, preparePackageWorkspace, runJSONJob, runJobs, testPackageConfigurations} from "./test-kernel.mjs";
+import {listTests, orderJobs, planShards, preparePackageWorkspace, runCompilation, runJSONJob, runJobs, testPackageConfigurations} from "./test-kernel.mjs";
const durations = {prefixLength: 6, defaultSeconds: 0.2, buckets: {
TestSl: {seconds: 40, tests: 2}, TestMe: {seconds: 20, tests: 2}, TestFa: {seconds: 10, tests: 2},
@@ -81,6 +81,22 @@ test("unsharded compilation starts before measured shards and ties remain determ
["mcp-tools-1", "util-1", "util-2"]);
});
+test("compilation records its interval and logs the end even when the process fails to start or exits unsuccessfully", async t => {
+ const messages = [];
+ t.mock.method(console, "log", message => messages.push(message));
+ const directory = temporary(t);
+ const before = Date.now();
+ const timing = await runCompilation(["-e", ""], directory, process.execPath);
+ assert.ok(Date.parse(timing.startedAt) >= before);
+ assert.ok(Date.parse(timing.endedAt) >= Date.parse(timing.startedAt));
+ assert.ok(Date.parse(timing.endedAt) <= Date.now());
+ assert.ok(timing.seconds >= 0);
+ await assert.rejects(runCompilation(["-e", "process.exitCode = 3;"], directory, process.execPath), /compilation failed: 3/);
+ await assert.rejects(runCompilation([], directory, join(directory, "missing-executable")), /ENOENT/);
+ assert.equal(messages.filter(message => message.startsWith("compile: START ")).length, 3);
+ assert.equal(messages.filter(message => message.startsWith("compile: END ")).length, 3);
+});
+
test("each model process has isolated relative writes while retaining repository fixtures", t => {
const directory = temporary(t);
const repository = join(directory, "repository");
@@ -168,10 +184,18 @@ test("process failures, missing tests and truncated coverage cannot produce a pa
const source = `process.stdout.write(${JSON.stringify(events.map(event => JSON.stringify(event)).join("\n") + "\n")}); process.exitCode = ${status};`;
return runJSONJob({name, args: ["-e", source], executable: process.execPath, cwd: output, expectedTests}, output);
};
- assert.equal((await run("pass", [{Action: "pass", Test: "TestOne"}], 0, ["TestOne"])).code, 0);
+ const before = Date.now();
+ const passed = await run("pass", [{Action: "pass", Test: "TestOne"}], 0, ["TestOne"]);
+ assert.equal(passed.code, 0);
+ assert.ok(Date.parse(passed.startedAt) >= before);
+ assert.ok(Date.parse(passed.endedAt) >= Date.parse(passed.startedAt));
+ assert.ok(Date.parse(passed.endedAt) <= Date.now());
+ assert.ok(passed.seconds >= 0);
const missing = await run("missing", [{Action: "pass", Test: "TestOne"}], 0, ["TestOne", "TestTwo"]);
assert.equal(missing.code, 1);
assert.deepEqual(missing.missing, ["TestTwo"]);
+ assert.ok(Date.parse(missing.startedAt) >= Date.parse(passed.endedAt));
+ assert.ok(Date.parse(missing.endedAt) >= Date.parse(missing.startedAt));
assert.equal((await run("unexpected", [{Action: "pass", Test: "TestOther"}], 0, ["TestOne"])).code, 1);
assert.equal((await run("failure", [{Action: "fail", Test: "TestOne"}], 0, ["TestOne"])).code, 1);
assert.equal((await run("crash", [], 2, ["TestOne"])).code, 1);