opencode-model-router 2.9.1 → 2.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +482 -0
- package/README.md +4 -2
- package/package.json +12 -5
- package/src/compat/background.ts +56 -19
- package/src/compat/child-history.ts +134 -0
- package/src/compat/child-report.ts +185 -0
- package/src/compat/child-session.ts +10 -0
- package/src/compat/session-lookup.ts +21 -0
- package/src/compat/v2-client.ts +124 -6
- package/src/compat/v2-hooks.ts +525 -203
- package/src/compat/v2-observations.ts +1 -0
- package/src/compat/v2-vocabulary.ts +14 -0
- package/src/executor/create.ts +47 -28
- package/src/executor/git.ts +226 -30
- package/src/executor/integrate/checks.ts +29 -11
- package/src/executor/integrate/land.ts +32 -2
- package/src/executor/integrate/queue.ts +95 -13
- package/src/executor/ledger.ts +16 -12
- package/src/executor/lfs-restore.ts +492 -0
- package/src/executor/paths.ts +7 -2
- package/src/executor/recovery.ts +2 -1
- package/src/executor/runtime.ts +1062 -243
- package/src/executor/slots/pool.ts +120 -19
- package/src/executor/slots/provision.ts +111 -23
- package/src/executor/slots/root.ts +81 -0
- package/src/executor/types.ts +28 -2
- package/src/executor/unattended.ts +6 -1
- package/src/executor/verify-trees.ts +507 -0
- package/src/guard/enforce.ts +2 -1
- package/src/guard/fingerprint.ts +9 -0
- package/src/guard/guards.ts +7 -1
- package/src/index.ts +191 -31
- package/src/router/answer-dedup.ts +198 -0
- package/src/router/common-dir.ts +241 -0
- package/src/router/config.ts +228 -40
- package/src/router/diff-handles.ts +322 -0
- package/src/router/diff-summary.ts +318 -0
- package/src/router/git-metadata-guard.ts +317 -0
- package/src/router/git-tools.ts +1136 -49
- package/src/router/read-only.ts +37 -13
- package/src/router/role-agents.ts +100 -36
- package/src/router/run-summary.ts +253 -0
- package/src/router/run-tools.ts +177 -25
- package/src/router/sessions.ts +23 -1
- package/src/router/tool-paths.ts +62 -4
- package/src/routing/classify/rules.ts +93 -14
- package/src/routing/roles/read-set.ts +10 -1
- package/src/routing/roles/work-root.ts +20 -3
- package/src/routing/wire/hint.ts +9 -2
- package/src/v2.ts +3 -1
- package/src/verify/exec.ts +454 -2
- package/src/verify/head.ts +6 -1
- package/src/verify/pending.ts +14 -1
- package/src/verify/plan-task.ts +86 -26
- package/src/verify/reference.ts +60 -7
- package/src/verify/runner.ts +14 -6
- package/src/verify/tree.ts +34 -10
- package/src/verify/types.ts +44 -0
- package/src/verify/wiring.ts +134 -22
package/src/verify/pending.ts
CHANGED
|
@@ -421,7 +421,12 @@ export const PENDING_LIST_LIMIT = 5;
|
|
|
421
421
|
export const FOOTER_MAX_REASONS = 3;
|
|
422
422
|
export const LATE_NOTICE_MAX_IDS = 10;
|
|
423
423
|
|
|
424
|
-
|
|
424
|
+
/**
|
|
425
|
+
* Terminal and cause-neutral (R6): the registry cannot tell a handle that was never issued here, one issued to another
|
|
426
|
+
* session, and one lost to a restart or an eviction. Re-asking cannot change the answer, and the text says so.
|
|
427
|
+
*/
|
|
428
|
+
export const UNKNOWN_HANDLE_TEXT =
|
|
429
|
+
"unknown handle: this session has no record of it (never issued here, issued to another session, or no longer tracked after a restart, eviction or a failed background run); retrying will not change the answer";
|
|
425
430
|
export const EXPIRED_HANDLE_TEXT = "expired handle: older than pendingTtlMs or evicted; it can no longer be verified";
|
|
426
431
|
export const VERIFYING_ELSEWHERE_TEXT =
|
|
427
432
|
"still being verified by another router_verify call; call again for its verdict";
|
|
@@ -803,6 +808,11 @@ export interface PendingRegistry {
|
|
|
803
808
|
reserveHandle(sessionID: string): string | undefined;
|
|
804
809
|
/** Gives a reserved handle back (the ack failed, or the dispatch is not held after all). */
|
|
805
810
|
releaseHandle(handle: string): void;
|
|
811
|
+
/**
|
|
812
|
+
* The session a handle is reserved for (drawn by `reserveHandle`, not yet registered or released), else undefined. Callers
|
|
813
|
+
* must compare it with the calling session: another session's reservation is never revealed (R6).
|
|
814
|
+
*/
|
|
815
|
+
reservedBy(handle: string): string | undefined;
|
|
806
816
|
/** The entry registered under `dispatchID` (callID), if still stored. */
|
|
807
817
|
findByDispatch(dispatchID: string): PendingEntry | undefined;
|
|
808
818
|
/** The session's "held" entries, newest first (they are never listed by listPending). */
|
|
@@ -2983,6 +2993,9 @@ export function createPendingRegistry(options: PendingRegistryOptions): PendingR
|
|
|
2983
2993
|
releaseHandle(handle) {
|
|
2984
2994
|
unreserve(handle);
|
|
2985
2995
|
},
|
|
2996
|
+
reservedBy(handle) {
|
|
2997
|
+
return reserved.get(handle);
|
|
2998
|
+
},
|
|
2986
2999
|
hasSlot,
|
|
2987
3000
|
findByDispatch(dispatchID) {
|
|
2988
3001
|
const rec = byDispatch.get(dispatchID);
|
package/src/verify/plan-task.ts
CHANGED
|
@@ -189,7 +189,10 @@ export function planTaskGit(): PlanTaskGit {
|
|
|
189
189
|
|
|
190
190
|
/** QA-5.1-4: the reason of every verification cut by `dispose`. */
|
|
191
191
|
export const PLAN_TASK_SHUTDOWN_REASON = "the plugin is shutting down";
|
|
192
|
-
/**
|
|
192
|
+
/**
|
|
193
|
+
* QA-5.1-4: how long `dispose` waits for the abort of one grader session. Recovery-R1-m2 (#190): it also bounds each grader
|
|
194
|
+
* abort of a cut, timed-out or failed gate pass, and the drain of that gate before its lease exemptions go.
|
|
195
|
+
*/
|
|
193
196
|
export const PLAN_TASK_ABORT_MS = 5_000;
|
|
194
197
|
|
|
195
198
|
/** QA-5.1-4: a wait cut by the verifier's `dispose`. */
|
|
@@ -397,10 +400,13 @@ export function createPlanTaskVerifier(deps: PlanTaskVerifierDeps): PlanTaskVeri
|
|
|
397
400
|
if (finalText !== undefined && finalText.trim() !== "") finalTexts.set(key, finalText);
|
|
398
401
|
const record = records.get(key);
|
|
399
402
|
// No begin record (a restart): verify takes the fail-closed fallback.
|
|
400
|
-
if (record === undefined
|
|
403
|
+
if (record === undefined) return;
|
|
401
404
|
// The cached observation is process-wide (it outlives an attachment): only its WAIT is bound to the attachment, never
|
|
402
405
|
// the observation itself, so an attachment cut cannot cache a failed observation that the next attachment would grade.
|
|
403
|
-
record.observed
|
|
406
|
+
record.observed ??= prepare(record, attempt);
|
|
407
|
+
// Phase-6.1 N1 (#190): every observe waits for the shared observation, also one an earlier attachment started, so the
|
|
408
|
+
// router's commit and cleanForChecks never run while its tree snapshot still reads the slot (bounded by the observation's
|
|
409
|
+
// own gate budget and by this attachment's signal).
|
|
404
410
|
// QA-5.1-4: dispose never waits for an observation (its deadline is aborted; verify then cuts).
|
|
405
411
|
try { await untilStopped(record.observed, ctx?.signal); } catch { /* cut by dispose or attachment change */ }
|
|
406
412
|
}
|
|
@@ -466,10 +472,33 @@ export function createPlanTaskVerifier(deps: PlanTaskVerifierDeps): PlanTaskVeri
|
|
|
466
472
|
return { ok: true, record, prepared: { ...observed.prepared, changedFiles: [], changeBaseline: "available" }, trusted: false };
|
|
467
473
|
}
|
|
468
474
|
|
|
475
|
+
/**
|
|
476
|
+
* Recovery-R1-m2 (#190): waits for a cut, timed-out or failed gate to settle (its deadline is already aborted), at most
|
|
477
|
+
* PLAN_TASK_ABORT_MS; a gate still running then is left behind with one warning. Absent gate (never started): no wait.
|
|
478
|
+
* Whether the gate settled (true for an absent gate).
|
|
479
|
+
*/
|
|
480
|
+
async function drainGate(gate: Promise<GateResult> | undefined, label: string): Promise<boolean> {
|
|
481
|
+
if (gate === undefined) return true;
|
|
482
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
483
|
+
const bound = new Promise<"bound">((resolve) => {
|
|
484
|
+
timer = setTimeout(() => resolve("bound"), PLAN_TASK_ABORT_MS);
|
|
485
|
+
timer.unref?.();
|
|
486
|
+
});
|
|
487
|
+
try {
|
|
488
|
+
const settled = gate.then(() => "settled" as const, () => "settled" as const);
|
|
489
|
+
if ((await Promise.race([settled, bound])) === "settled") return true;
|
|
490
|
+
const name = scrubText(label).replace(/\s+/g, " ").trim().slice(0, 200);
|
|
491
|
+
warn(`plan-task verification gate for ${name} did not settle within ${PLAN_TASK_ABORT_MS} ms of its cut or timeout; its lease exemptions are released`);
|
|
492
|
+
return false;
|
|
493
|
+
} finally {
|
|
494
|
+
clearTimeout(timer);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
|
|
469
498
|
async function runPass(
|
|
470
499
|
passDoD: DoD, budgetMs: number, record: AttemptRecord, task: TaskNode, slot: SlotLease, attempt: Attempt,
|
|
471
500
|
artefact: Artefact, prepared: PreparedVerification, parent: string, signal?: AbortSignal,
|
|
472
|
-
): Promise<{ res: GateResult; cut: boolean }> {
|
|
501
|
+
): Promise<{ res: GateResult; cut: boolean; settled: boolean }> {
|
|
473
502
|
// Bind this pass's wait to its attachment as well as plugin shutdown; the gate remains directly awaited.
|
|
474
503
|
const untilShutdown = <T>(work: Promise<T>): Promise<T> => untilStopped(work, signal);
|
|
475
504
|
const cfg = deps.getConfig();
|
|
@@ -486,6 +515,8 @@ export function createPlanTaskVerifier(deps: PlanTaskVerifierDeps): PlanTaskVeri
|
|
|
486
515
|
const child = attempt.childSessionID ?? "";
|
|
487
516
|
const tree = prepared.snapshot?.root ?? slot.path;
|
|
488
517
|
const releases = [tree, slot.path].map((root) => deps.exemptions.exempt(root, [child, leaseHolderID(record.planId, task.id)]));
|
|
518
|
+
// Recovery-R1-m2 (#190): the gate itself, so a cut or timed-out pass drains it before its exemptions go.
|
|
519
|
+
let gate: Promise<GateResult> | undefined;
|
|
489
520
|
try {
|
|
490
521
|
// QA-5.1-14: the grader is parented to the plan's CURRENT orchestrator, as the runtime read it for this verify (an
|
|
491
522
|
// adopt moves the plan; verify refused an unknown one before any gate ran).
|
|
@@ -503,27 +534,29 @@ export function createPlanTaskVerifier(deps: PlanTaskVerifierDeps): PlanTaskVeri
|
|
|
503
534
|
...(placement.refused !== undefined ? { refusedCheck: placement.refused } : {}),
|
|
504
535
|
};
|
|
505
536
|
if (disposing || signal?.aborted) throw new PlanTaskShutdownError();
|
|
506
|
-
|
|
507
|
-
|
|
537
|
+
gate = accept(delegation, artefact, gateDeps);
|
|
538
|
+
const res = await untilShutdown(withTimeout(gate, deadline.remaining(), "verification gate"));
|
|
539
|
+
return { res, cut: false, settled: true };
|
|
508
540
|
} catch (error) {
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
const
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
}
|
|
541
|
+
const cut = error instanceof PlanTaskShutdownError || disposing || signal?.aborted === true;
|
|
542
|
+
const timedOut = !cut && error instanceof RouterTimeoutError;
|
|
543
|
+
// Recovery-R1-m2 (#190): the deadline goes first; it cancels the gate's checks and every grader dispatch linked to it
|
|
544
|
+
// (buildGateDeps, `cancelGradersWithDeadline`), also one whose session is created only after this point.
|
|
545
|
+
deadline.abort(cut ? PLAN_TASK_SHUTDOWN_REASON : timedOut ? "verification gate timed out" : "verification gate failed");
|
|
546
|
+
// QA-5.1-4: dispose owns the grader aborts of its own cut. Every other cut, timeout or failure aborts the graders this
|
|
547
|
+
// pass knows (best effort, each bounded) while the gate drains: a rerun or the next attachment starts only after it.
|
|
548
|
+
const aborts = cut && disposing ? [] : [...graders].map((sessionID) =>
|
|
549
|
+
withTimeout(deps.abortSession(sessionID), PLAN_TASK_ABORT_MS, "grader abort").catch(() => undefined));
|
|
550
|
+
const [settled] = await Promise.all([drainGate(gate, `${task.id}#${attempt.n}`), Promise.all(aborts)]);
|
|
551
|
+
// The pass judged nothing and is never re-run.
|
|
552
|
+
if (cut) return { res: unverifiableGateResult(PLAN_TASK_SHUTDOWN_REASON, passDoD.source, strict), cut: false, settled };
|
|
521
553
|
return {
|
|
522
554
|
res: unverifiableGateResult(
|
|
523
555
|
timedOut ? `verification gate timed out after ${budgetMs}ms` : `verification unavailable: ${scrubText(String(error))}`,
|
|
524
556
|
passDoD.source, strict, completedFailures,
|
|
525
557
|
),
|
|
526
558
|
cut: timedOut,
|
|
559
|
+
settled,
|
|
527
560
|
};
|
|
528
561
|
} finally {
|
|
529
562
|
live.delete(entry);
|
|
@@ -533,11 +566,21 @@ export function createPlanTaskVerifier(deps: PlanTaskVerifierDeps): PlanTaskVeri
|
|
|
533
566
|
}
|
|
534
567
|
}
|
|
535
568
|
|
|
536
|
-
async function verifyWithAttachment(signal: AbortSignal | undefined, task: TaskNode, slot: SlotLease,
|
|
537
|
-
onDecided: (decided: PlanTaskVerdict) => void): Promise<PlanTaskVerdict> {
|
|
569
|
+
async function verifyWithAttachment(signal: AbortSignal | undefined, journal: PlanTaskContext["processJournal"], task: TaskNode, slot: SlotLease,
|
|
570
|
+
attempt: Attempt, parent: string, onDecided: (decided: PlanTaskVerdict) => void): Promise<PlanTaskVerdict> {
|
|
538
571
|
const untilShutdown = <T>(work: Promise<T>): Promise<T> => untilStopped(work, signal);
|
|
539
572
|
const key = keyOf(slot.planId, task.id, attempt.n);
|
|
540
573
|
let record = records.get(key);
|
|
574
|
+
// Phase-6.1 N2 (#190): a record kept across a cut observed another slot when the task was re-provisioned since: it
|
|
575
|
+
// describes no tree of this slot, so it goes (its ids too) and this verification takes the restart fallback.
|
|
576
|
+
if (record !== undefined && planTreeKey(record.slotPath) !== planTreeKey(slot.path)) {
|
|
577
|
+
clearIds(record.id, null);
|
|
578
|
+
records.delete(key);
|
|
579
|
+
record = undefined;
|
|
580
|
+
}
|
|
581
|
+
// Phase-6.1 N2 (#190): the begin record this pipeline graded (null: the restart fallback's), and whether it decided.
|
|
582
|
+
const begun = record?.observed !== undefined ? record : null;
|
|
583
|
+
let decidedHere = false;
|
|
541
584
|
let prepared: PreparedVerification;
|
|
542
585
|
try {
|
|
543
586
|
if (record?.observed !== undefined) {
|
|
@@ -599,11 +642,15 @@ export function createPlanTaskVerifier(deps: PlanTaskVerifierDeps): PlanTaskVeri
|
|
|
599
642
|
const gatePrepared: PreparedVerification = {
|
|
600
643
|
...prepared,
|
|
601
644
|
graderDispatchLabel: `${task.id}#${attempt.n}`,
|
|
645
|
+
// Recovery-R1-m2 (#190): a grader dispatch ends with its pass's deadline (cut, timeout), never outlives the gate.
|
|
646
|
+
cancelGradersWithDeadline: true,
|
|
602
647
|
...(boundService === undefined ? {} : { service: boundService }),
|
|
603
648
|
changedFiles,
|
|
604
649
|
// The union is complete: the observed files and every path the candidate commits over the reset commit.
|
|
605
650
|
changeBaseline: prepared.branchSwitch !== undefined ? "unavailable" : "available",
|
|
606
651
|
snapshot: fresh,
|
|
652
|
+
// #189 R2-pre-2: the gate's check seams record every root they spawn in the attempt's process journal.
|
|
653
|
+
...(journal === undefined ? {} : { processJournal: journal }),
|
|
607
654
|
};
|
|
608
655
|
const child = attempt.childSessionID ?? "";
|
|
609
656
|
const producerTier = planTaskProducerTier(task, cfg);
|
|
@@ -633,9 +680,11 @@ export function createPlanTaskVerifier(deps: PlanTaskVerifierDeps): PlanTaskVeri
|
|
|
633
680
|
const current = record;
|
|
634
681
|
const withReruns = async (passDoD: DoD, budgetMs: number): Promise<GateResult> => {
|
|
635
682
|
for (;;) {
|
|
636
|
-
const { res, cut } = await runPass(passDoD, budgetMs, current, task, slot, attempt, artefact, gatePrepared, parent, signal);
|
|
683
|
+
const { res, cut, settled } = await runPass(passDoD, budgetMs, current, task, slot, attempt, artefact, gatePrepared, parent, signal);
|
|
637
684
|
if (signal?.aborted) return res;
|
|
638
|
-
|
|
685
|
+
// Recovery-R1-m2 (#190): a gate that did not settle within its drain bound may still run checks or a grader in the
|
|
686
|
+
// slot: never re-run over it (the transient result stands).
|
|
687
|
+
if (disposing || !settled || !isTransientPlanTaskResult(res, cut) || reruns >= PLAN_TASK_TRANSIENT_RERUNS) return res;
|
|
639
688
|
const reason = scrubText([...new Set([...res.verdict.reasons, ...(res.verdict.caveats ?? [])])].join("; "))
|
|
640
689
|
.replace(/\s+/g, " ").trim().slice(0, 200);
|
|
641
690
|
const label = scrubText(`${task.id}#${attempt.n}`).replace(/\s+/g, " ").trim().slice(0, 200);
|
|
@@ -670,6 +719,7 @@ export function createPlanTaskVerifier(deps: PlanTaskVerifierDeps): PlanTaskVeri
|
|
|
670
719
|
res = applyDispatchCaveats(res, gatePrepared);
|
|
671
720
|
// QA-5.1-21: from here the verdict is decided: `verify` returns it even when dispose cuts its wait afterwards.
|
|
672
721
|
const decided = slotVerdictOf(res);
|
|
722
|
+
decidedHere = true;
|
|
673
723
|
onDecided(decided);
|
|
674
724
|
if (child !== "" && res.verdict.skipped !== true) {
|
|
675
725
|
try { deps.onVerdict?.(child, res.verdict); } catch (error) { warn("plan-task verdict not ingested", error); }
|
|
@@ -678,9 +728,15 @@ export function createPlanTaskVerifier(deps: PlanTaskVerifierDeps): PlanTaskVeri
|
|
|
678
728
|
} catch (error) {
|
|
679
729
|
return unverifiable(`verification unavailable: ${scrubText(error instanceof Error ? error.message : String(error))}`, record?.dod);
|
|
680
730
|
} finally {
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
731
|
+
// Phase-6.1 N2 (#190): an attachment cut that decided nothing keeps the begin record, the child's final text and the
|
|
732
|
+
// store ids, so the next same-process attachment grades the observed attempt (the runtime never calls begin again)
|
|
733
|
+
// instead of the restart fallback. A decided verdict, any other result, a fallback record and dispose clear them.
|
|
734
|
+
const keep = begun !== null && signal?.aborted === true && !disposing && !decidedHere && records.get(key) === begun;
|
|
735
|
+
if (!keep) {
|
|
736
|
+
records.delete(key);
|
|
737
|
+
finalTexts.delete(key);
|
|
738
|
+
if (record !== undefined) clearIds(record.id, attempt.childSessionID);
|
|
739
|
+
}
|
|
684
740
|
}
|
|
685
741
|
}
|
|
686
742
|
|
|
@@ -693,7 +749,7 @@ export function createPlanTaskVerifier(deps: PlanTaskVerifierDeps): PlanTaskVeri
|
|
|
693
749
|
try {
|
|
694
750
|
// Attachment cuts are handled inside the pipeline, including bounded grader abort/cleanup, before a new
|
|
695
751
|
// attachment can verify this identity. Global dispose retains its prompt outer cut semantics.
|
|
696
|
-
const verifyNow = verifyWithAttachment.bind(undefined, ctx?.signal);
|
|
752
|
+
const verifyNow = verifyWithAttachment.bind(undefined, ctx?.signal, ctx?.processJournal);
|
|
697
753
|
const result = await untilStopped(verifyNow(task, slot, attempt, orchestrator(ctx), (v) => { decided = v; }));
|
|
698
754
|
return ctx?.signal?.aborted && decided === null ? cut() : result;
|
|
699
755
|
} catch (error) {
|
|
@@ -711,6 +767,10 @@ export function createPlanTaskVerifier(deps: PlanTaskVerifierDeps): PlanTaskVeri
|
|
|
711
767
|
if (disposing) return;
|
|
712
768
|
disposing = true;
|
|
713
769
|
shutdown.abort();
|
|
770
|
+
// Phase-6.1 N2 (#190): records kept across an attachment cut never outlive the plugin.
|
|
771
|
+
for (const record of records.values()) clearIds(record.id, null);
|
|
772
|
+
records.clear();
|
|
773
|
+
finalTexts.clear();
|
|
714
774
|
const sessions = new Set<string>();
|
|
715
775
|
for (const entry of live) {
|
|
716
776
|
entry.deadline.abort(PLAN_TASK_SHUTDOWN_REASON);
|
package/src/verify/reference.ts
CHANGED
|
@@ -142,7 +142,15 @@
|
|
|
142
142
|
// AbortSignal.any([signal, AbortSignal.timeout(remaining)]).
|
|
143
143
|
// Every git call in this module runs as `git --no-optional-locks ...`
|
|
144
144
|
// (QA-1.5-2), so a read-only call never refreshes, and so never rewrites,
|
|
145
|
-
// the user's index.
|
|
145
|
+
// the user's index. Right after that flag comes git-tools workRootReadArgs()
|
|
146
|
+
// (no fsmonitor, null-device hooksPath, no ssh key command, no transport);
|
|
147
|
+
// a later `-c core.hooksPath=` (D9's worktree add) still wins. Capture and
|
|
148
|
+
// materialize also blank the filter/merge drivers only the repository's own
|
|
149
|
+
// configuration names, include targets of any condition too, with
|
|
150
|
+
// filter.<name>.required=true so a blanked filter makes git refuse instead of
|
|
151
|
+
// writing unfiltered content (git-tools collectRepositoryDriverArgs); every
|
|
152
|
+
// call runs with GIT_NO_LAZY_FETCH=1. A configuration that cannot be read
|
|
153
|
+
// means no reference.
|
|
146
154
|
// 1. `git rev-parse --show-toplevel` (cwd: the dispatch cwd) -> root. A
|
|
147
155
|
// non-zero exit (outside a repository, or a bare repository) returns
|
|
148
156
|
// undefined.
|
|
@@ -735,6 +743,7 @@ import { gitTopOf, perimeterKey } from "./git-top";
|
|
|
735
743
|
// Type-only: pin.ts imports perimeter.ts, which imports this module; samePin is loaded lazily in step 7.
|
|
736
744
|
import type { LinkPin, PinWhy } from "./pin";
|
|
737
745
|
import type { PluginLogger } from "../router/logger";
|
|
746
|
+
import { collectRepositoryDriverArgs, gitExecutable, workRootGuards, workRootReadArgs } from "../router/git-tools";
|
|
738
747
|
|
|
739
748
|
// --- Seams --------------------------------------------------------------------
|
|
740
749
|
|
|
@@ -1308,6 +1317,8 @@ interface GitRun {
|
|
|
1308
1317
|
readonly signal?: AbortSignal;
|
|
1309
1318
|
/** Merged over process.env by the seam. */
|
|
1310
1319
|
readonly env?: Record<string, string>;
|
|
1320
|
+
/** `-c` pairs placed after the work-root read prefix and before `args`: the repository-only driver blanking. */
|
|
1321
|
+
readonly config?: readonly string[];
|
|
1311
1322
|
}
|
|
1312
1323
|
|
|
1313
1324
|
/** Overrides for the pathspec environment switches git would otherwise inherit (QA-1.5-18). */
|
|
@@ -1349,6 +1360,9 @@ function stdoutTruncated(result: ExecResult): boolean {
|
|
|
1349
1360
|
* A truncated stdout (QA-1.5-21) comes back as a failed call (code -1): the
|
|
1350
1361
|
* seam's trailing stdout note in stderr (stdoutTruncated), or a non-empty
|
|
1351
1362
|
* `-z` output that does not end in NUL. Every caller parses stdout only after `code === 0`.
|
|
1363
|
+
* #141 (#77 G4): git by absolute path from outside the work-root guards of `run.cwd`, never a
|
|
1364
|
+
* bare `git` that Windows may resolve from the (model-writable) cwd; a refused or missing
|
|
1365
|
+
* executable is a failed call (code -1), with nothing spawned.
|
|
1352
1366
|
*/
|
|
1353
1367
|
async function runGit(argv: ArgvSeam, args: readonly string[], run: GitRun): Promise<ExecResult | undefined> {
|
|
1354
1368
|
if (run.timeoutMs <= 0 || run.signal?.aborted) return undefined;
|
|
@@ -1356,9 +1370,11 @@ async function runGit(argv: ArgvSeam, args: readonly string[], run: GitRun): Pro
|
|
|
1356
1370
|
if (run.signal) opts.signal = run.signal;
|
|
1357
1371
|
// QA-1.5-18: pathspec env switches (literal/glob/noglob/icase) change what every pathspec
|
|
1358
1372
|
// means; git reads them as booleans, so "0" neutralises them whatever the plugin inherited.
|
|
1359
|
-
|
|
1373
|
+
// GIT_NO_LAZY_FETCH (git >= 2.44): a partial clone's missing object fails the call instead of fetching it.
|
|
1374
|
+
opts.env = { ...PATHSPEC_ENV_RESET, GIT_NO_LAZY_FETCH: "1", ...run.env };
|
|
1360
1375
|
try {
|
|
1361
|
-
|
|
1376
|
+
// workRootReadArgs() before the caller's args, so a later `-c core.hooksPath=<noHooks>` (D9) wins over its null device.
|
|
1377
|
+
const result = await argv(gitExecutable(workRootGuards(run.cwd)), ["--no-optional-locks", ...workRootReadArgs(), ...(run.config ?? []), ...args], opts);
|
|
1362
1378
|
if (result.timedOut || run.signal?.aborted) return undefined;
|
|
1363
1379
|
// QA-1.5-21: the p12 seam keeps exit code 0 when it cuts stdout at maxBuffer.
|
|
1364
1380
|
const cut =
|
|
@@ -1374,6 +1390,29 @@ async function runGit(argv: ArgvSeam, args: readonly string[], run: GitRun): Pro
|
|
|
1374
1390
|
}
|
|
1375
1391
|
}
|
|
1376
1392
|
|
|
1393
|
+
/**
|
|
1394
|
+
* The `-c` pairs that blank the filter/merge drivers (and set the protocols to `never`) only `root`'s own configuration names,
|
|
1395
|
+
* include targets of any condition too (git-tools collectRepositoryDriverArgs), read through the seam, in the environment of
|
|
1396
|
+
* the reference's own git calls, which reads the user's system/global configuration as plain git does: a global LFS filter
|
|
1397
|
+
* and its `git lfs install --local` copy are kept. `required=true`: the reference writes (stash create, the checkout), so a
|
|
1398
|
+
* blanked filter makes git refuse instead of storing or checking out unfiltered content. Undefined when the configuration
|
|
1399
|
+
* cannot be read, the budget is spent, a key cannot be blanked, or the environment carries the legacy GIT_CONFIG (which would
|
|
1400
|
+
* replace the repository's configuration in the listing alone): the caller has no reference (fail closed).
|
|
1401
|
+
*/
|
|
1402
|
+
async function repositoryDrivers(argv: ArgvSeam, root: string, budget: Budget): Promise<readonly string[] | undefined> {
|
|
1403
|
+
if (budget.spent() || Object.keys(process.env).some((key) => key.toUpperCase() === "GIT_CONFIG")) return undefined;
|
|
1404
|
+
const query = async (args: readonly string[]) => {
|
|
1405
|
+
const result = budget.spent() ? undefined : await runGit(argv, args, { cwd: root, timeoutMs: budget.remaining(), signal: budget.signal });
|
|
1406
|
+
if (!result || budget.spent()) throw new Error("the driver configuration could not be read in time");
|
|
1407
|
+
return result;
|
|
1408
|
+
};
|
|
1409
|
+
try {
|
|
1410
|
+
return await collectRepositoryDriverArgs(query, root, { required: true });
|
|
1411
|
+
} catch {
|
|
1412
|
+
return undefined;
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1377
1416
|
function isAliveDefault(pid: number): boolean {
|
|
1378
1417
|
try {
|
|
1379
1418
|
process.kill(pid, 0);
|
|
@@ -1585,15 +1624,20 @@ async function captureInner(cwd: string, signal: AbortSignal, deps: CaptureDeps)
|
|
|
1585
1624
|
const platform = process.platform;
|
|
1586
1625
|
const p = pathFor(platform);
|
|
1587
1626
|
const budget = makeBudget(signal, deps.timeoutMs ?? DEFAULT_CAPTURE_TIMEOUT_MS);
|
|
1627
|
+
let config: readonly string[] = [];
|
|
1588
1628
|
const git = async (args: readonly string[], at: string) => {
|
|
1589
1629
|
if (budget.spent()) return undefined;
|
|
1590
|
-
const result = await runGit(deps.argv, args, { cwd: at, timeoutMs: budget.remaining(), signal: budget.signal });
|
|
1630
|
+
const result = await runGit(deps.argv, args, { cwd: at, timeoutMs: budget.remaining(), signal: budget.signal, config });
|
|
1591
1631
|
return result && result.code === 0 && !budget.spent() ? result : undefined;
|
|
1592
1632
|
};
|
|
1593
1633
|
|
|
1594
1634
|
const top = await git(["rev-parse", "--show-toplevel"], cwd);
|
|
1595
1635
|
if (!top) return undefined;
|
|
1596
1636
|
const root = p.resolve(stripNewline(top.stdout));
|
|
1637
|
+
// `stash create` hashes the working tree through the clean filters: blank the repository-only ones first.
|
|
1638
|
+
const drivers = await repositoryDrivers(deps.argv, root, budget);
|
|
1639
|
+
if (drivers === undefined) return undefined;
|
|
1640
|
+
config = drivers;
|
|
1597
1641
|
const stage = await git(["ls-files", "--stage"], root);
|
|
1598
1642
|
if (!stage || /^160000 /m.test(stage.stdout)) return undefined;
|
|
1599
1643
|
// Section 2f (QA-1.5-6): neither stash create nor the drift diff sees an edit to an
|
|
@@ -1619,6 +1663,7 @@ async function captureInner(cwd: string, signal: AbortSignal, deps: CaptureDeps)
|
|
|
1619
1663
|
cwd: root,
|
|
1620
1664
|
timeoutMs: budget.remaining(),
|
|
1621
1665
|
env: { GIT_INDEX_FILE: copy },
|
|
1666
|
+
config,
|
|
1622
1667
|
});
|
|
1623
1668
|
return stash && stash.code === 0 && !budget.spent() ? stash.stdout.trim() : undefined;
|
|
1624
1669
|
});
|
|
@@ -1807,8 +1852,9 @@ export async function materialize(
|
|
|
1807
1852
|
await cleanup();
|
|
1808
1853
|
return fail(reason, detail);
|
|
1809
1854
|
};
|
|
1855
|
+
let config: readonly string[] = [];
|
|
1810
1856
|
const git = async (args: readonly string[]) =>
|
|
1811
|
-
budget.spent() ? undefined : runGit(deps.argv, args, { cwd: root, timeoutMs: budget.remaining(), signal: budget.signal });
|
|
1857
|
+
budget.spent() ? undefined : runGit(deps.argv, args, { cwd: root, timeoutMs: budget.remaining(), signal: budget.signal, config });
|
|
1812
1858
|
|
|
1813
1859
|
try {
|
|
1814
1860
|
// 0. Same-repository guard.
|
|
@@ -1819,6 +1865,12 @@ export async function materialize(
|
|
|
1819
1865
|
return fail("error", "currentTree is not inside the reference repository");
|
|
1820
1866
|
}
|
|
1821
1867
|
}
|
|
1868
|
+
// 0b. The checkout (smudge) and the drift diff (clean) run filters: blank the repository-only ones for every call, in the
|
|
1869
|
+
// live repository and in the reference worktree (which shares its configuration).
|
|
1870
|
+
const drivers = await repositoryDrivers(deps.argv, root, budget);
|
|
1871
|
+
if (budget.spent()) return fail("aborted", "aborted before the worktree was created");
|
|
1872
|
+
if (drivers === undefined) return fail("error", "the repository's filter/merge driver configuration cannot be read");
|
|
1873
|
+
config = drivers;
|
|
1822
1874
|
// 1. The unreferenced stash commit may have been pruned (section 8).
|
|
1823
1875
|
const exists = await git(["cat-file", "-e", `${ref.commit}^{commit}`]);
|
|
1824
1876
|
if (budget.spent()) return fail("aborted", "aborted before the worktree was created");
|
|
@@ -1869,7 +1921,7 @@ export async function materialize(
|
|
|
1869
1921
|
"-c", `core.hooksPath=${noHooks}`,
|
|
1870
1922
|
"-c", "advice.detachedHead=false",
|
|
1871
1923
|
"worktree", "add", "--detach", ...lock, candidate, ref.commit,
|
|
1872
|
-
], { cwd: root, timeoutMs: budget.remaining(), signal: budget.signal, env: { LC_ALL: "C" } });
|
|
1924
|
+
], { cwd: root, timeoutMs: budget.remaining(), signal: budget.signal, env: { LC_ALL: "C" }, config });
|
|
1873
1925
|
let added = await add(["--lock", "--reason", referenceLockReason(deps.pid ?? process.pid)]);
|
|
1874
1926
|
if (added && added.code !== 0 && !budget.spent() && ADD_LOCK_UNSUPPORTED.test(added.stderr)) {
|
|
1875
1927
|
// git < 2.33: the option parser failed before anything was written; the dir must still be empty.
|
|
@@ -2014,7 +2066,7 @@ export async function materialize(
|
|
|
2014
2066
|
...(only.length > 0 ? ["--literal-pathspecs"] : []),
|
|
2015
2067
|
"-c", "core.splitIndex=false", "diff", "--name-only", "-z", "--no-renames", "--no-ext-diff", ref.commit, "--", ...only,
|
|
2016
2068
|
], {
|
|
2017
|
-
cwd: root, timeoutMs: budget.remaining(), signal: budget.signal, env: { GIT_INDEX_FILE: copy },
|
|
2069
|
+
cwd: root, timeoutMs: budget.remaining(), signal: budget.signal, env: { GIT_INDEX_FILE: copy }, config,
|
|
2018
2070
|
}));
|
|
2019
2071
|
const diff = await driftDiff();
|
|
2020
2072
|
const nowUntracked = await git(["ls-files", "--others", "--exclude-standard", "-z"]);
|
|
@@ -2124,6 +2176,7 @@ export async function materialize(
|
|
|
2124
2176
|
cwd,
|
|
2125
2177
|
timeoutMs: budget.remaining(),
|
|
2126
2178
|
signal,
|
|
2179
|
+
config,
|
|
2127
2180
|
});
|
|
2128
2181
|
return listed && listed.code === 0 ? parseEolList(listed.stdout) : undefined;
|
|
2129
2182
|
};
|
package/src/verify/runner.ts
CHANGED
|
@@ -1210,6 +1210,19 @@ export const MAX_ARGV_CHARS = 30000;
|
|
|
1210
1210
|
/** Report files: `${tmpdir}/omr-verify-<uuid>.json|.xml`. readResult touches nothing else. */
|
|
1211
1211
|
export const REPORT_NAME_RE = /^omr-verify-[0-9a-f-]{36}\.(json|xml)$/;
|
|
1212
1212
|
|
|
1213
|
+
/**
|
|
1214
|
+
* readResult's report-path guard: `path` names a file directly in `tmpdir` (both absolute; compared case-folded on win32)
|
|
1215
|
+
* whose name matches `name`. Nothing else is read or unlinked. `router_run`'s `summary: "failures"` (#108) uses it with
|
|
1216
|
+
* its own report names.
|
|
1217
|
+
*/
|
|
1218
|
+
export function reportPathAllowed(path: string, tmpdir: string, platform: NodeJS.Platform = process.platform,
|
|
1219
|
+
name: RegExp = REPORT_NAME_RE): boolean {
|
|
1220
|
+
const win = platform === "win32";
|
|
1221
|
+
const P = win ? nodePath.win32 : nodePath.posix;
|
|
1222
|
+
const key = (p: string) => (win ? p.toLowerCase() : p);
|
|
1223
|
+
return P.isAbsolute(tmpdir) && P.isAbsolute(path) && key(P.dirname(P.resolve(path))) === key(P.resolve(tmpdir)) && name.test(P.basename(path));
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1213
1226
|
// ---------------------------------------------------------------------------------------------
|
|
1214
1227
|
// Types
|
|
1215
1228
|
// ---------------------------------------------------------------------------------------------
|
|
@@ -5491,12 +5504,7 @@ export async function readResult(
|
|
|
5491
5504
|
host?: Partial<RunnerHost>,
|
|
5492
5505
|
): Promise<RunResult> {
|
|
5493
5506
|
const ctx = makeCtx(host);
|
|
5494
|
-
const
|
|
5495
|
-
const allowed =
|
|
5496
|
-
P.isAbsolute(ctx.host.tmpdir) &&
|
|
5497
|
-
P.isAbsolute(spec.reportPath) &&
|
|
5498
|
-
ctx.key(P.dirname(P.resolve(spec.reportPath))) === ctx.key(P.resolve(ctx.host.tmpdir)) &&
|
|
5499
|
-
REPORT_NAME_RE.test(P.basename(spec.reportPath));
|
|
5507
|
+
const allowed = reportPathAllowed(spec.reportPath, ctx.host.tmpdir, ctx.host.platform);
|
|
5500
5508
|
try {
|
|
5501
5509
|
if (!allowed) return crossLinkCompleteness(ctx, spec, textResult(ctx, spec, execResult, `report path rejected: ${spec.reportPath}`));
|
|
5502
5510
|
let text: string | undefined;
|
package/src/verify/tree.ts
CHANGED
|
@@ -23,7 +23,10 @@ export interface SnapshotGitOptions {
|
|
|
23
23
|
readonly lowPriority: boolean;
|
|
24
24
|
/** Cross-repo QA-1 F4 (SnapshotOptions.hardened): the environment git runs with. Absent: the process's own (unchanged). */
|
|
25
25
|
readonly env?: NodeJS.ProcessEnv;
|
|
26
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Cross-repo QA-1 F4: the git executable, by absolute path. Absent (#141, #77 G4): the router's git outside the work-root
|
|
28
|
+
* guards of `cwd` (`gitExecutable(workRootGuards(cwd))`), never a bare `git` that Windows may resolve from `cwd`.
|
|
29
|
+
*/
|
|
27
30
|
readonly executable?: string;
|
|
28
31
|
}
|
|
29
32
|
|
|
@@ -98,12 +101,14 @@ export const execGit: SnapshotGit = (args, opts) => new Promise<string>((ok, fai
|
|
|
98
101
|
return;
|
|
99
102
|
}
|
|
100
103
|
const nice = opts.lowPriority && !isWin;
|
|
101
|
-
const git = opts.executable ?? "git";
|
|
102
104
|
let child: ChildProcess;
|
|
103
105
|
try {
|
|
106
|
+
// #141: a refused or missing executable throws here and rejects like a spawn error, with nothing spawned.
|
|
107
|
+
const git = opts.executable ?? tools.gitExecutable(tools.workRootGuards(opts.cwd));
|
|
108
|
+
// GIT_NO_LAZY_FETCH (git >= 2.44): a partial clone's missing object fails the read instead of fetching it.
|
|
104
109
|
child = spawn(nice ? "nice" : git, nice ? ["-n", "10", "--", git, ...args] : [...args], {
|
|
105
110
|
cwd: opts.cwd, windowsHide: true, detached: !isWin, stdio: ["ignore", "pipe", "ignore"],
|
|
106
|
-
...(opts.env
|
|
111
|
+
env: { ...(opts.env ?? process.env), GIT_NO_LAZY_FETCH: "1" },
|
|
107
112
|
});
|
|
108
113
|
} catch (e) {
|
|
109
114
|
fail(e);
|
|
@@ -169,7 +174,9 @@ export interface SnapshotOptions {
|
|
|
169
174
|
* Cross-repo QA-1 F4 (I11): run every git process of the snapshot hardened, as the router's other git calls in a repository
|
|
170
175
|
* it does not own (git-tools.ts): `hardeningArgs()` (no fsmonitor, no hooks, no pager, no external diff, no optional locks),
|
|
171
176
|
* the user's `safe.directory` values and inherited line-ending settings (`core.autocrlf` …), `gitEnvironment()` (no inherited GIT_*, no system or global config) and git by absolute
|
|
172
|
-
* path outside the snapshotted tree. The perimeter's extra roots use it. Default false: the snapshot of W
|
|
177
|
+
* path outside the snapshotted tree. The perimeter's extra roots use it. Default false: the snapshot of W runs with
|
|
178
|
+
* `workRootReadArgs()` (no fsmonitor, no hooks, no transport) and keeps git's index refresh. Both modes blank the filter and
|
|
179
|
+
* merge drivers only the repository's own configuration names (`repositoryDriverArgs`).
|
|
173
180
|
*/
|
|
174
181
|
hardened?: boolean;
|
|
175
182
|
/** The git process seam (tests). Default execGit. */
|
|
@@ -510,9 +517,13 @@ export async function snapshotTree(cwd: string, signal: AbortSignal, options: Sn
|
|
|
510
517
|
let gitCwd = cwd;
|
|
511
518
|
const run = options.git ?? execGit;
|
|
512
519
|
const lowPriority = options.lowPriority === true;
|
|
513
|
-
|
|
520
|
+
// The default snapshot (W) keeps git's index refresh (no `hardeningArgs()`: diff.autoRefreshIndex=false would change the
|
|
521
|
+
// fingerprint) but never runs a repository-configured fsmonitor, hook, ssh key command or transport (`workRootReadArgs()`).
|
|
522
|
+
let prefix: readonly string[] = ["--no-pager", ...tools.workRootReadArgs()];
|
|
514
523
|
let hardening: Pick<SnapshotGitOptions, "env" | "executable"> = {};
|
|
515
|
-
|
|
524
|
+
// #194: `harden` (the hardened snapshot's executable and inherited configuration) and `finalize` (the paths of the
|
|
525
|
+
// result) label failures outside a git call, which would otherwise carry the previous stage's label.
|
|
526
|
+
type Stage = "harden" | "root" | "drivers" | "head" | "status" | "diff-worktree" | "diff-index" | "index" | "untracked-list" | "hash" | "index-tags" | "ignored-list" | "finalize";
|
|
516
527
|
let stage: Stage = "root";
|
|
517
528
|
const git = (label: Stage, args: string[]) => {
|
|
518
529
|
stage = label;
|
|
@@ -522,6 +533,7 @@ export async function snapshotTree(cwd: string, signal: AbortSignal, options: Sn
|
|
|
522
533
|
};
|
|
523
534
|
try {
|
|
524
535
|
if (options.hardened === true) {
|
|
536
|
+
stage = "harden";
|
|
525
537
|
const hardened = await hardenedGit(cwd);
|
|
526
538
|
prefix = hardened.prefix;
|
|
527
539
|
hardening = { env: hardened.env, executable: hardened.executable };
|
|
@@ -530,11 +542,25 @@ export async function snapshotTree(cwd: string, signal: AbortSignal, options: Sn
|
|
|
530
542
|
// ls-files otherwise scopes untracked contents to a subdirectory cwd,
|
|
531
543
|
// missing same-path edits in sibling packages that tests may import.
|
|
532
544
|
gitCwd = root;
|
|
545
|
+
// Status and diff run clean filters: a filter (or merge driver) only the repository's own configuration names is blanked,
|
|
546
|
+
// in both modes (required=false: a read never stores content); a system/global one and its identical repository copy
|
|
547
|
+
// (`git lfs install --local`) are kept. The listing runs in the environment of the snapshot's own processes. A
|
|
548
|
+
// configuration that cannot be read leaves no snapshot.
|
|
549
|
+
stage = "drivers";
|
|
550
|
+
prefix = [...prefix, ...await tools.repositoryDriverArgs(root, {
|
|
551
|
+
...(hardening.executable !== undefined ? { executable: hardening.executable } : {}),
|
|
552
|
+
...(hardening.env !== undefined ? { env: hardening.env } : {}), signal, timeoutMs: SNAPSHOT_GIT_TIMEOUT_MS,
|
|
553
|
+
})];
|
|
533
554
|
// One process, so HEAD and its branch describe the same checkout.
|
|
534
555
|
const [headLine, refLine] = (await git("head", ["rev-parse", "HEAD", "--symbolic-full-name", "HEAD"])).split(/\r?\n/);
|
|
535
556
|
const head = (headLine ?? "").trim();
|
|
536
557
|
const branch = parseBranchLine(refLine);
|
|
537
|
-
|
|
558
|
+
// A submodule's dirty marker does not describe its content. Refuse rather than cache a fingerprint that would excuse
|
|
559
|
+
// unmeasured changes there, and before `status`/`diff`, which would run git inside a populated submodule with its own
|
|
560
|
+
// configuration. The listing is not hashed.
|
|
561
|
+
if (/^160000 /m.test(await git("index", ["ls-files", "--stage"]))) return undefined;
|
|
562
|
+
// --no-optional-locks: the default snapshot's status never rewrites the user's index (output unchanged).
|
|
563
|
+
const status = await git("status", ["--no-optional-locks", "status", "--porcelain=v1", "-z", "--untracked-files=all"]);
|
|
538
564
|
const files: ChangedFile[] = [];
|
|
539
565
|
const records = status.split("\0");
|
|
540
566
|
for (let i = 0; i < records.length; i++) {
|
|
@@ -551,9 +577,6 @@ export async function snapshotTree(cwd: string, signal: AbortSignal, options: Sn
|
|
|
551
577
|
const hash = createHash("sha256").update(status);
|
|
552
578
|
hash.update(await git("diff-worktree", ["diff", "HEAD", "--binary", "--no-ext-diff", "--no-textconv"]));
|
|
553
579
|
hash.update(await git("diff-index", ["diff", "--cached", "--binary", "--no-ext-diff", "--no-textconv"]));
|
|
554
|
-
// A submodule's dirty marker does not describe its content. Refuse rather
|
|
555
|
-
// than cache a fingerprint that would excuse unmeasured changes there.
|
|
556
|
-
if (/^160000 /m.test(await git("index", ["ls-files", "--stage"]))) return undefined;
|
|
557
580
|
const untracked = (await git("untracked-list", ["ls-files", "--others", "--exclude-standard", "--full-name", "-z"]))
|
|
558
581
|
.split("\0").filter(Boolean).sort();
|
|
559
582
|
stage = "hash";
|
|
@@ -593,6 +616,7 @@ export async function snapshotTree(cwd: string, signal: AbortSignal, options: Sn
|
|
|
593
616
|
options.maxIgnoredBytes ?? MAX_IGNORED_BYTES,
|
|
594
617
|
);
|
|
595
618
|
}
|
|
619
|
+
stage = "finalize";
|
|
596
620
|
return {
|
|
597
621
|
cwd: await realpath(cwd), root: await realpath(root), head, branch, fingerprint: hash.digest("hex"), dirty: files.length > 0, files, digests,
|
|
598
622
|
...(ignored !== undefined ? { ignored } : {}),
|
package/src/verify/types.ts
CHANGED
|
@@ -62,6 +62,22 @@ export interface ExecResult {
|
|
|
62
62
|
timedOut?: boolean;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
/**
|
|
66
|
+
* #189 R2-pre-2: the root of one spawned process tree, as the process layer (exec.ts) reports it to `onSpawn`/`onSettle`.
|
|
67
|
+
*/
|
|
68
|
+
export interface SpawnedProcess {
|
|
69
|
+
readonly pid: number;
|
|
70
|
+
/** Date.now() taken just before the spawn: the root's creation time is at or after it. */
|
|
71
|
+
readonly startedAtMs: number;
|
|
72
|
+
/** POSIX: the process group the root leads (it is spawned detached), so pgid === pid; null on Windows. */
|
|
73
|
+
readonly pgid: number | null;
|
|
74
|
+
/**
|
|
75
|
+
* The run's deadline in ms after `startedAtMs` (exec.ts `deadlineOf`); null without one (a signal-only run). A process
|
|
76
|
+
* the root started is created before `startedAtMs + deadlineMs + KILL_GRACE_MS`: by then the run killed its tree.
|
|
77
|
+
*/
|
|
78
|
+
readonly deadlineMs: number | null;
|
|
79
|
+
}
|
|
80
|
+
|
|
65
81
|
/** Options shared by every verification process seam (shell string or argv). */
|
|
66
82
|
export interface ExecOptions {
|
|
67
83
|
/** Optional v2 diagnostics; process adapters split preparation from the actual spawn/child lifetime. */
|
|
@@ -76,6 +92,34 @@ export interface ExecOptions {
|
|
|
76
92
|
env?: Record<string, string>;
|
|
77
93
|
/** `replace` uses only env (empty when omitted), without process.env or automatic slot-environment injection. */
|
|
78
94
|
envMode?: "merge" | "replace";
|
|
95
|
+
/**
|
|
96
|
+
* #189 R2-pre-2 (v2 plan tasks only): called once, synchronously, right after a spawn that produced a pid. A throw is
|
|
97
|
+
* ignored: the hook never affects spawning, cancellation or settlement. Absent (v1, dispatches): nothing is reported.
|
|
98
|
+
*/
|
|
99
|
+
onSpawn?: (root: SpawnedProcess) => void;
|
|
100
|
+
/**
|
|
101
|
+
* #189 R2-pre-2: called once when the root (the direct child) exits, with the time it was seen exiting; nothing it
|
|
102
|
+
* started can be created after that. A throw is ignored.
|
|
103
|
+
*/
|
|
104
|
+
onExit?: (root: SpawnedProcess, exitedAtMs: number) => void;
|
|
105
|
+
/** #189 R2-pre-2: called once when the run whose spawn `onSpawn` reported settles; a throw is ignored. */
|
|
106
|
+
onSettle?: (root: SpawnedProcess) => void;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* #189 R2-pre-2: where a plan-task verification records the process trees it spawns (one journal per attempt, written by
|
|
111
|
+
* the executor), so a restart can end the trees a dead server left running before it verifies again. Never throws.
|
|
112
|
+
*/
|
|
113
|
+
export interface ProcessJournal {
|
|
114
|
+
/**
|
|
115
|
+
* A root was spawned. `command` is text the root's command line contains: the shell command of a shell run, the
|
|
116
|
+
* executable of an argv run.
|
|
117
|
+
*/
|
|
118
|
+
spawned(root: SpawnedProcess, command: string): void;
|
|
119
|
+
/** `root` exited at `exitedAtMs` (its run may still be pending: a descendant can hold the pipes). */
|
|
120
|
+
exited(root: SpawnedProcess, exitedAtMs: number): void;
|
|
121
|
+
/** The run of `root` settled. */
|
|
122
|
+
settled(root: SpawnedProcess): void;
|
|
79
123
|
}
|
|
80
124
|
|
|
81
125
|
/** Execution-only seam; an adapter doing preparation must forward `service` to the instrumented process layer. */
|