mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-18 06:04:33 +01:00
train S5: merge #3960 at a0d44c31ca v1.95.4.0
This commit is contained in:
commit
71ebc5c2fa
12 files changed
+216
-59
No files matched your search
+18
-1
@@ -142,7 +142,24 @@ export interface VerdictProblem { detail: string; code: ResultCodeName; fix?: st
|
||||
export function verdictProblem(skill: string, gstackRoot: string, env: Env, bunPath: string, bunVersion: string, cwd?: string): VerdictProblem | null {
|
||||
const src = sourceRoot(gstackRoot);
|
||||
const project = installProject(src, cwd);
|
||||
const file = findInstallVerdict(src, project, env);
|
||||
return admittedVerdict(skill, src, findInstallVerdict(src, project, env), project, bunPath, bunVersion).problem;
|
||||
}
|
||||
|
||||
/**
|
||||
* The verdict file that admits `skill`: `file` itself, else the workflow's own record
|
||||
* <verdict>.for/<skill>.json that every install also writes, so a later install for another
|
||||
* workflow never drops this one (GST-1233), except after a failed ./setup, which changed the
|
||||
* checkout every record certified. When neither admits, `file` with its problem.
|
||||
*/
|
||||
export function admittedVerdict(skill: string, src: string, file: string, project: string | null, bunPath: string, bunVersion: string): { file: string; problem: VerdictProblem | null } {
|
||||
const problem = verdictFileProblem(file, skill, src, project, bunPath, bunVersion);
|
||||
const own = file.replace(/\.json$/, `.for/${skill}.json`);
|
||||
if (problem && /^[A-Za-z0-9._-]+$/.test(skill) && !readInstallVerdict(file)?.trailer?.startsWith('gstack: fail setup') && fs.existsSync(own) && !verdictFileProblem(own, skill, src, project, bunPath, bunVersion)) return { file: own, problem: null };
|
||||
return { file, problem };
|
||||
}
|
||||
|
||||
/** Why the verdict in `file` does not admit `skill`; null when it does. */
|
||||
function verdictFileProblem(file: string, skill: string, src: string, project: string | null, bunPath: string, bunVersion: string): VerdictProblem | null {
|
||||
const v = readInstallVerdict(file);
|
||||
const problem = (detail: string): VerdictProblem => ({ detail, code: 'INSTALL_UNVERIFIED' });
|
||||
if (!v && fs.existsSync(file)) return problem(`the install verdict at ${file} is unreadable or has an unsupported schema_version; rerun the installer`);
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { findInstallVerdict, installProject, readInstallVerdict, sourceRoot, verdictProblem } from '../install-verdict';
|
||||
import { admittedVerdict, findInstallVerdict, installProject, readInstallVerdict, sourceRoot } from '../install-verdict';
|
||||
import { resultCodeSuffix } from '../result-codes';
|
||||
import { collectPins, evaluatePins, exactPlan, parseVersion, satisfies } from '../runtime-pins';
|
||||
import { resolveStateRoot } from '../state-root';
|
||||
@@ -152,15 +152,15 @@ export interface LaunchRuntime {
|
||||
* The Bun the lanes and guards run under, its dir first on PATH; the env is
|
||||
* unchanged when nothing qualifies. Under the admission condition the install
|
||||
* verdict for (checkout, project) is validated as workflow admission does
|
||||
* (verdictProblem: ok, HEAD, pins, project, coverage, for /ship) and its
|
||||
* (admittedVerdict: ok, HEAD, pins, project, coverage, for /ship; else /ship's own record) and its
|
||||
* recorded Bun is the one launched; the gstack checkout itself binds the
|
||||
* 'none' verdict (installProject).
|
||||
*/
|
||||
export function launchRuntime(repoRoot: string, env: NodeJS.ProcessEnv): LaunchRuntime {
|
||||
const checkout = sourceRoot(GSTACK_ROOT);
|
||||
const project = installProject(checkout, repoRoot);
|
||||
const file = findInstallVerdict(checkout, project, env);
|
||||
const recorded = readInstallVerdict(file);
|
||||
const admitted = admittedVerdict('ship', checkout, findInstallVerdict(checkout, project, env), project, '', '');
|
||||
const recorded = readInstallVerdict(admitted.file);
|
||||
let pinsRoot: string | null = null;
|
||||
try { pinsRoot = fs.realpathSync(repoRoot); } catch { /* unresolvable: no pins */ }
|
||||
const { pinExact, accept } = projectBunPins(pinsRoot, env);
|
||||
@@ -174,14 +174,16 @@ export function launchRuntime(repoRoot: string, env: NodeJS.ProcessEnv): LaunchR
|
||||
if (env.GSTACK_CAPY !== '1' && !recorded) {
|
||||
verdictLine = 'install verdict: not checked (no GSTACK_CAPY=1 and no verdict for this checkout and project)';
|
||||
} else {
|
||||
const problem = verdictProblem('ship', GSTACK_ROOT, env, '', '', repoRoot);
|
||||
const { problem } = admitted;
|
||||
if (problem) return refuse('INSTALL_UNVERIFIED', problem.detail, problem.fix ?? installer);
|
||||
verdict = 'ok';
|
||||
if (recorded!.bun_path) {
|
||||
const now = fs.existsSync(recorded!.bun_path) ? bunVersionOf(recorded!.bun_path, env) : '';
|
||||
const why = !now ? 'is gone' : now !== recorded!.bun_version ? `now reports ${now}` : !accept(now) ? 'no longer satisfies the project pins' : '';
|
||||
if (why) return refuse('BUN_RESOLUTION_DRIFT', `recorded bun ${recorded!.bun_version} at ${recorded!.bun_path} ${why}`, 're-run the Capy skill installer with --check (scripts/install.sh --check --for ship) and follow its fix');
|
||||
const launch = recorded!.launch_path && fs.existsSync(recorded!.launch_path) ? recorded!.launch_path : path.dirname(recorded!.bun_path);
|
||||
let launchBun = '';
|
||||
try { launchBun = fs.realpathSync(path.join(recorded!.launch_path, 'bun')); } catch { /* no Bun in the launch dir */ }
|
||||
const launch = recorded!.launch_path && fs.existsSync(recorded!.launch_path) && (!launchBun || launchBun === recorded!.bun_path) ? recorded!.launch_path : path.dirname(recorded!.bun_path);
|
||||
return result(launch, now, `bun ${now} at ${recorded!.bun_path} (recorded by the install verdict)`, 'ok', '');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user