feat: continue reviewed tasks and add reproducible engineering delivery validation
This commit is contained in:
@@ -36,16 +36,17 @@ export function invalidateProjectChecks(store, projectId, reason = '工程文件
|
||||
store.invalidateChecks(projectId, reason);
|
||||
}
|
||||
|
||||
function npmInvocation(name) {
|
||||
const cli = path.join(path.dirname(process.execPath), 'node_modules', 'npm', 'bin', 'npm-cli.js');
|
||||
if (!fs.existsSync(cli)) throw new Error('执行宿主没有可用的npm CLI,请使用随附Node运行工作台。');
|
||||
function npmInvocation(name, runtimeDirectory) {
|
||||
const cli = [runtimeDirectory, path.dirname(process.execPath)].filter(Boolean).map(directory => path.join(directory, 'node_modules', 'npm', 'bin', 'npm-cli.js')).find(file => fs.existsSync(file));
|
||||
if (!cli) throw new Error('执行宿主没有可用的npm CLI,请使用随附Node运行工作台。');
|
||||
return { executable: process.execPath, args: [cli, 'run', name] };
|
||||
}
|
||||
|
||||
export class CheckRunner {
|
||||
constructor(store, { redact = value => String(value), timeoutMs = 180000, projectBusy = () => false } = {}) {
|
||||
constructor(store, { redact = value => String(value), timeoutMs = 180000, projectBusy = () => false, runtimeDirectory = null } = {}) {
|
||||
this.store = store; this.redact = redact; this.timeoutMs = timeoutMs; this.projectBusy = projectBusy;
|
||||
this.active = new Map(); this.projects = new Map();
|
||||
this.runtimeDirectory = runtimeDirectory;
|
||||
}
|
||||
isActive(sessionId) { return [...this.active.values()].some(value => value.sessionId === sessionId); }
|
||||
projectActive(projectId) { return this.projects.has(projectId); }
|
||||
@@ -116,7 +117,7 @@ export class CheckRunner {
|
||||
const artifact = this.store.artifactStore.write(session, run, text, { kind: 'check-log', mediaType: 'text/plain' });
|
||||
this.store.core.artifact.set(artifact.id, artifact);
|
||||
const { stdout, stderr, ...record } = result;
|
||||
job.results.push({ id: randomUUID(), name: check.name, kind: check.kind, command: check.command, ...record, logArtifactId: artifact.id });
|
||||
job.results.push({ id: randomUUID(), name: check.name, kind: check.kind, command: check.command, ...record, logArtifactId: artifact.id, logExcerpt: text.slice(-8000) });
|
||||
this.store.save(session, { type: 'check.result', detail: { jobId: job.id, checkId: check.id, status: record.status, artifactId: artifact.id } });
|
||||
if (['cancelled', 'unknown'].includes(record.status)) break;
|
||||
const after = await inspectProject(this.store.project(session.projectId));
|
||||
@@ -147,7 +148,7 @@ export class CheckRunner {
|
||||
executeCheck(check, project, signal) {
|
||||
const started = Date.now();
|
||||
let invocation;
|
||||
try { invocation = npmInvocation(check.name); } catch (error) { return Promise.resolve({ status: 'failed', exitCode: null, durationMs: 0, tests: null, stdout: '', stderr: error.message, reason: error.message }); }
|
||||
try { invocation = npmInvocation(check.name, this.runtimeDirectory); } catch (error) { return Promise.resolve({ status: 'failed', exitCode: null, durationMs: 0, tests: null, stdout: '', stderr: error.message, reason: error.message }); }
|
||||
return new Promise(resolve => {
|
||||
const env = { ...process.env, NO_COLOR: '1', CI: '1' };
|
||||
delete env.FORCE_COLOR;
|
||||
|
||||
Reference in New Issue
Block a user