opencode-model-router 2.8.0 → 2.9.1
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 +372 -0
- package/README.md +22 -2
- package/package.json +5 -1
- package/src/commands/output.ts +23 -1
- package/src/compat/background.ts +2439 -0
- package/src/compat/child-session.ts +6 -0
- package/src/compat/turn-state.ts +215 -0
- package/src/compat/v2-client.ts +136 -17
- package/src/compat/v2-hooks.ts +2656 -114
- package/src/compat/v2-observations.ts +328 -0
- package/src/executor/capacity.ts +362 -0
- package/src/executor/child-guards.ts +40 -0
- package/src/executor/command.ts +265 -0
- package/src/executor/compile/edges.ts +809 -0
- package/src/executor/compile/estimate.ts +158 -0
- package/src/executor/compile/footprint.ts +829 -0
- package/src/executor/compile/index.ts +1080 -0
- package/src/executor/compile/parse.ts +1492 -0
- package/src/executor/compile/residue.ts +706 -0
- package/src/executor/compile/validate.ts +280 -0
- package/src/executor/create.ts +672 -0
- package/src/executor/expand.ts +551 -0
- package/src/executor/git.ts +1214 -0
- package/src/executor/host-preamble.ts +17 -0
- package/src/executor/instructions.ts +35 -0
- package/src/executor/integrate/bisect.ts +73 -0
- package/src/executor/integrate/checks.ts +1086 -0
- package/src/executor/integrate/land.ts +177 -0
- package/src/executor/integrate/phase-suite.ts +407 -0
- package/src/executor/integrate/queue.ts +3083 -0
- package/src/executor/integrate/run-resolver.ts +19 -0
- package/src/executor/launch.ts +652 -0
- package/src/executor/ledger.ts +2208 -0
- package/src/executor/observations.ts +212 -0
- package/src/executor/paths.ts +159 -0
- package/src/executor/platform.ts +39 -0
- package/src/executor/process-identity.ts +19 -0
- package/src/executor/qa-loop.ts +470 -0
- package/src/executor/recovery.ts +403 -0
- package/src/executor/runtime.ts +6233 -0
- package/src/executor/schedule.ts +246 -0
- package/src/executor/slots/env.ts +145 -0
- package/src/executor/slots/pool.ts +1564 -0
- package/src/executor/slots/provision.ts +853 -0
- package/src/executor/tool.ts +534 -0
- package/src/executor/types.ts +2064 -0
- package/src/executor/unattended.ts +488 -0
- package/src/guard/store.ts +3 -1
- package/src/index.ts +1498 -288
- package/src/router/config.ts +776 -25
- package/src/router/git-tools.ts +106 -15
- package/src/router/leases.ts +1469 -0
- package/src/router/logger.ts +44 -32
- package/src/router/protocol.ts +40 -10
- package/src/router/role-agents.ts +224 -17
- package/src/router/roles-config.ts +10 -1
- package/src/router/roles.ts +1 -1
- package/src/router/run-tools.ts +56 -4
- package/src/router/tool-paths.ts +308 -0
- package/src/router/work-roots.ts +86 -0
- package/src/routing/advisor/findings.ts +25 -5
- package/src/routing/classify/index.ts +7 -1
- package/src/routing/classify/rules.ts +11 -0
- package/src/routing/commands/stats.ts +2 -2
- package/src/routing/outcomes/durations.ts +225 -0
- package/src/routing/outcomes/index.ts +59 -2
- package/src/routing/outcomes/persist.ts +409 -0
- package/src/routing/outcomes/stats.ts +170 -11
- package/src/routing/outcomes/timings.ts +836 -0
- package/src/routing/outcomes/types.ts +98 -0
- package/src/routing/roles/approvals.ts +86 -5
- package/src/routing/roles/binding.ts +99 -9
- package/src/routing/roles/orphans.ts +68 -0
- package/src/routing/roles/policy.ts +21 -3
- package/src/routing/roles/work-root.ts +3 -1
- package/src/routing/wire/dispatch.ts +86 -12
- package/src/routing/wire/hint.ts +56 -8
- package/src/v2.ts +94 -49
- package/src/verify/branch.ts +8 -2
- package/src/verify/canonical-path.ts +35 -0
- package/src/verify/deterministic.ts +38 -9
- package/src/verify/dispatch.ts +64 -28
- package/src/verify/exec.ts +52 -9
- package/src/verify/pending.ts +1691 -10
- package/src/verify/perimeter.ts +12 -6
- package/src/verify/plan-task.ts +729 -0
- package/src/verify/reference.ts +216 -3
- package/src/verify/tree.ts +30 -13
- package/src/verify/types.ts +9 -2
- package/src/verify/wiring.ts +290 -31
- package/tiers.json +5 -5
package/src/verify/reference.ts
CHANGED
|
@@ -733,7 +733,7 @@ import type { ArgvSeam, ExecOptions, ExecResult } from "./types";
|
|
|
733
733
|
import type { TreeSnapshot } from "./dispatch";
|
|
734
734
|
import { gitTopOf, perimeterKey } from "./git-top";
|
|
735
735
|
// Type-only: pin.ts imports perimeter.ts, which imports this module; samePin is loaded lazily in step 7.
|
|
736
|
-
import type { LinkPin } from "./pin";
|
|
736
|
+
import type { LinkPin, PinWhy } from "./pin";
|
|
737
737
|
import type { PluginLogger } from "../router/logger";
|
|
738
738
|
|
|
739
739
|
// --- Seams --------------------------------------------------------------------
|
|
@@ -835,6 +835,152 @@ export interface DispatchReference {
|
|
|
835
835
|
readonly pins?: readonly LinkPin[];
|
|
836
836
|
}
|
|
837
837
|
|
|
838
|
+
/** JSON-safe form of a DispatchReference (pending.jsonl, phase 2.1 section 11). */
|
|
839
|
+
export interface SerializedReference {
|
|
840
|
+
readonly root: string;
|
|
841
|
+
readonly head: string;
|
|
842
|
+
readonly commit: string;
|
|
843
|
+
readonly untracked: Readonly<Record<string, string>>;
|
|
844
|
+
readonly tracked: Readonly<Record<string, string>>;
|
|
845
|
+
readonly captureReasons: readonly InexactReason[];
|
|
846
|
+
readonly capturedAt: number;
|
|
847
|
+
/** Absolute node_modules links the materialized dir held (link path -> target); re-created on materialize. */
|
|
848
|
+
readonly links?: Readonly<Record<string, string>>;
|
|
849
|
+
/** DispatchReference.pins, when present (QA-SYNC1-9: a restart keeps the dispatch-time pins of linked repositories). */
|
|
850
|
+
readonly pins?: readonly LinkPin[];
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
export function serializeReference(
|
|
854
|
+
ref: DispatchReference,
|
|
855
|
+
links?: Readonly<Record<string, string>>,
|
|
856
|
+
): SerializedReference {
|
|
857
|
+
return {
|
|
858
|
+
root: ref.root,
|
|
859
|
+
head: ref.head,
|
|
860
|
+
commit: ref.commit,
|
|
861
|
+
untracked: Object.fromEntries(ref.untracked),
|
|
862
|
+
tracked: Object.fromEntries(ref.tracked),
|
|
863
|
+
captureReasons: ref.captureReasons.map((r) => ({ cause: r.cause, path: r.path })),
|
|
864
|
+
capturedAt: ref.capturedAt,
|
|
865
|
+
...(links !== undefined && Object.keys(links).length > 0 ? { links: { ...links } } : {}),
|
|
866
|
+
...(ref.pins !== undefined ? { pins: ref.pins.map(copyPin) } : {}),
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
/** A plain copy of `pin` (only the LinkPin fields, nested pins included). */
|
|
871
|
+
function copyPin(pin: LinkPin): LinkPin {
|
|
872
|
+
return pin.kind === "pinned"
|
|
873
|
+
? { kind: "pinned", root: pin.root, head: pin.head, fingerprint: pin.fingerprint, ignored: pin.ignored, nested: pin.nested.map(copyPin) }
|
|
874
|
+
: { kind: "unpinnable", root: pin.root, why: pin.why };
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
function digestMap(v: unknown): Map<string, string> | undefined {
|
|
878
|
+
if (typeof v !== "object" || v === null || Array.isArray(v)) return undefined;
|
|
879
|
+
const out = new Map<string, string>();
|
|
880
|
+
for (const [k, d] of Object.entries(v)) {
|
|
881
|
+
if (typeof d !== "string") return undefined;
|
|
882
|
+
out.set(k, d);
|
|
883
|
+
}
|
|
884
|
+
return out;
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
/** The links recorded by serializeReference; empty when absent or malformed. */
|
|
888
|
+
export function serializedReferenceLinks(json: unknown): Readonly<Record<string, string>> {
|
|
889
|
+
const raw = typeof json === "string" ? safeParse(json) : json;
|
|
890
|
+
if (typeof raw !== "object" || raw === null) return {};
|
|
891
|
+
const links = digestMap((raw as Record<string, unknown>).links);
|
|
892
|
+
return links === undefined ? {} : Object.fromEntries(links);
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
function safeParse(text: string): unknown {
|
|
896
|
+
try {
|
|
897
|
+
return JSON.parse(text);
|
|
898
|
+
} catch {
|
|
899
|
+
return undefined;
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
const INEXACT_CAUSES: ReadonlySet<string> = new Set<InexactCause>([
|
|
904
|
+
"untracked-deleted",
|
|
905
|
+
"untracked-modified",
|
|
906
|
+
"untracked-not-file",
|
|
907
|
+
"untracked-unreadable",
|
|
908
|
+
"untracked-symlink",
|
|
909
|
+
"untracked-unsafe-path",
|
|
910
|
+
"dependency-drift",
|
|
911
|
+
"workspace-link-drift",
|
|
912
|
+
"external-link",
|
|
913
|
+
"root-link",
|
|
914
|
+
"index-flags",
|
|
915
|
+
"checkout-conversion",
|
|
916
|
+
]);
|
|
917
|
+
|
|
918
|
+
const PIN_WHYS: ReadonlySet<string> = new Set<PinWhy>(["not-observed", "not-admitted", "not-git", "over-bounds", "deep-link"]);
|
|
919
|
+
|
|
920
|
+
/**
|
|
921
|
+
* One serialized LinkPin, or undefined when malformed. `nestedAllowed` mirrors pin.ts pinTarget: only a top-level pin
|
|
922
|
+
* carries nested pins (one level), so a nested pin with nested pins of its own is malformed.
|
|
923
|
+
*/
|
|
924
|
+
function deserializePin(v: unknown, nestedAllowed: boolean): LinkPin | undefined {
|
|
925
|
+
if (typeof v !== "object" || v === null || Array.isArray(v)) return undefined;
|
|
926
|
+
const p = v as Record<string, unknown>;
|
|
927
|
+
if (typeof p.root !== "string") return undefined;
|
|
928
|
+
if (p.kind === "unpinnable") {
|
|
929
|
+
if (typeof p.why !== "string" || !PIN_WHYS.has(p.why)) return undefined;
|
|
930
|
+
return { kind: "unpinnable", root: p.root, why: p.why as PinWhy };
|
|
931
|
+
}
|
|
932
|
+
if (p.kind !== "pinned") return undefined;
|
|
933
|
+
if (typeof p.head !== "string" || typeof p.fingerprint !== "string" || typeof p.ignored !== "string") return undefined;
|
|
934
|
+
if (!Array.isArray(p.nested) || (!nestedAllowed && p.nested.length > 0)) return undefined;
|
|
935
|
+
const nested: LinkPin[] = [];
|
|
936
|
+
for (const n of p.nested) {
|
|
937
|
+
const pin = deserializePin(n, false);
|
|
938
|
+
if (pin === undefined) return undefined;
|
|
939
|
+
nested.push(pin);
|
|
940
|
+
}
|
|
941
|
+
return { kind: "pinned", root: p.root, head: p.head, fingerprint: p.fingerprint, ignored: p.ignored, nested };
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
/** Inverse of serializeReference. Accepts a JSON string or the parsed object; undefined when malformed. */
|
|
945
|
+
export function deserializeReference(json: unknown): DispatchReference | undefined {
|
|
946
|
+
const raw: unknown = typeof json === "string" ? safeParse(json) : json;
|
|
947
|
+
if (typeof raw !== "object" || raw === null) return undefined;
|
|
948
|
+
const o = raw as Record<string, unknown>;
|
|
949
|
+
if (typeof o.root !== "string" || typeof o.head !== "string" || typeof o.commit !== "string") return undefined;
|
|
950
|
+
if (typeof o.capturedAt !== "number" || !Number.isFinite(o.capturedAt)) return undefined;
|
|
951
|
+
const untracked = digestMap(o.untracked);
|
|
952
|
+
const tracked = digestMap(o.tracked);
|
|
953
|
+
if (untracked === undefined || tracked === undefined) return undefined;
|
|
954
|
+
const reasons: InexactReason[] = [];
|
|
955
|
+
if (!Array.isArray(o.captureReasons)) return undefined;
|
|
956
|
+
for (const r of o.captureReasons) {
|
|
957
|
+
if (typeof r !== "object" || r === null) return undefined;
|
|
958
|
+
const rr = r as Record<string, unknown>;
|
|
959
|
+
if (typeof rr.cause !== "string" || !INEXACT_CAUSES.has(rr.cause) || typeof rr.path !== "string") return undefined;
|
|
960
|
+
reasons.push({ cause: rr.cause as InexactCause, path: rr.path });
|
|
961
|
+
}
|
|
962
|
+
let pins: LinkPin[] | undefined;
|
|
963
|
+
if (o.pins !== undefined) {
|
|
964
|
+
if (!Array.isArray(o.pins)) return undefined;
|
|
965
|
+
pins = [];
|
|
966
|
+
for (const v of o.pins) {
|
|
967
|
+
const pin = deserializePin(v, true);
|
|
968
|
+
if (pin === undefined) return undefined;
|
|
969
|
+
pins.push(pin);
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
return {
|
|
973
|
+
root: o.root,
|
|
974
|
+
head: o.head,
|
|
975
|
+
commit: o.commit,
|
|
976
|
+
untracked,
|
|
977
|
+
tracked,
|
|
978
|
+
captureReasons: reasons,
|
|
979
|
+
capturedAt: o.capturedAt,
|
|
980
|
+
...(pins !== undefined ? { pins } : {}),
|
|
981
|
+
};
|
|
982
|
+
}
|
|
983
|
+
|
|
838
984
|
export type InexactCause =
|
|
839
985
|
| "untracked-deleted"
|
|
840
986
|
| "untracked-modified"
|
|
@@ -2093,6 +2239,73 @@ function parseWorktreeList(stdout: string): WorktreeEntry[] {
|
|
|
2093
2239
|
return entries;
|
|
2094
2240
|
}
|
|
2095
2241
|
|
|
2242
|
+
/**
|
|
2243
|
+
* Reference dirs reloaded from pending.jsonl by a later process (phase 2.1 section 11.3): the dir
|
|
2244
|
+
* name still carries the dead owner's pid, so GC must skip them while the pending entry lives.
|
|
2245
|
+
* Keyed by basename (REF_DIR_PATTERN); the value is the last known absolute dir, if given.
|
|
2246
|
+
*/
|
|
2247
|
+
const KEPT = processWideSet("omr.reference.kept");
|
|
2248
|
+
/** Absolute dirs of KEPT names whose path is known: refreshed by the keep heartbeat. */
|
|
2249
|
+
const KEPT_DIRS = new Map<string, string>();
|
|
2250
|
+
let keptBeat: ReturnType<typeof setInterval> | undefined;
|
|
2251
|
+
|
|
2252
|
+
function keptName(key: string): string | undefined {
|
|
2253
|
+
const name = key.replace(/[\\/]+$/, "").split(/[\\/]/).pop() ?? "";
|
|
2254
|
+
return REF_DIR_PATTERN.test(name) ? name : undefined;
|
|
2255
|
+
}
|
|
2256
|
+
|
|
2257
|
+
/** True when `key` (a dir path or basename) was passed to keepReferences and not released. */
|
|
2258
|
+
export function isReferenceKept(key: string): boolean {
|
|
2259
|
+
const name = keptName(key);
|
|
2260
|
+
return name !== undefined && KEPT.has(name);
|
|
2261
|
+
}
|
|
2262
|
+
|
|
2263
|
+
export interface KeepReferencesOptions {
|
|
2264
|
+
/** Default nodeReferenceFs. */
|
|
2265
|
+
fs?: Pick<ReferenceFs, "utimes">;
|
|
2266
|
+
/** Default HEARTBEAT_INTERVAL_MS. */
|
|
2267
|
+
heartbeatMs?: number;
|
|
2268
|
+
logger?: Pick<PluginLogger, "warn">;
|
|
2269
|
+
}
|
|
2270
|
+
|
|
2271
|
+
/**
|
|
2272
|
+
* Marks reloaded reference dirs active: gcStaleReferences skips them, and dirs given as absolute paths
|
|
2273
|
+
* are heartbeated under this process's pid (their name still carries the dead owner's). Keys are absolute
|
|
2274
|
+
* dir paths or bare `omr-ref-<pid>-<16 hex>` names; anything else is ignored. The returned function
|
|
2275
|
+
* releases exactly these keys.
|
|
2276
|
+
*/
|
|
2277
|
+
export function keepReferences(keys: Iterable<string>, opts: KeepReferencesOptions = {}): () => void {
|
|
2278
|
+
const added: string[] = [];
|
|
2279
|
+
for (const key of keys) {
|
|
2280
|
+
const name = keptName(key);
|
|
2281
|
+
if (name === undefined) continue;
|
|
2282
|
+
KEPT.add(name);
|
|
2283
|
+
if (/[\\/]/.test(key)) KEPT_DIRS.set(name, key);
|
|
2284
|
+
added.push(name);
|
|
2285
|
+
}
|
|
2286
|
+
if (keptBeat === undefined && KEPT_DIRS.size > 0) {
|
|
2287
|
+
const fs = opts.fs ?? nodeReferenceFs;
|
|
2288
|
+
keptBeat = setInterval(() => {
|
|
2289
|
+
const now = new Date();
|
|
2290
|
+
for (const dir of KEPT_DIRS.values()) {
|
|
2291
|
+
fs.utimes(dir, now, now).catch((error: unknown) =>
|
|
2292
|
+
opts.logger?.warn("reference keep heartbeat failed", { dir, error: describeError(error) }));
|
|
2293
|
+
}
|
|
2294
|
+
}, opts.heartbeatMs ?? HEARTBEAT_INTERVAL_MS);
|
|
2295
|
+
keptBeat.unref();
|
|
2296
|
+
}
|
|
2297
|
+
return () => {
|
|
2298
|
+
for (const name of added) {
|
|
2299
|
+
KEPT.delete(name);
|
|
2300
|
+
KEPT_DIRS.delete(name);
|
|
2301
|
+
}
|
|
2302
|
+
if (KEPT_DIRS.size === 0 && keptBeat !== undefined) {
|
|
2303
|
+
clearInterval(keptBeat);
|
|
2304
|
+
keptBeat = undefined;
|
|
2305
|
+
}
|
|
2306
|
+
};
|
|
2307
|
+
}
|
|
2308
|
+
|
|
2096
2309
|
/** Section 11. Never throws; touches only stale omr-ref-* dirs directly under a tmp root. */
|
|
2097
2310
|
export async function gcStaleReferences(root: string, deps: ReferenceDeps): Promise<GcReport> {
|
|
2098
2311
|
const report = { removed: [] as string[], kept: [] as string[], failed: [] as string[] };
|
|
@@ -2158,7 +2371,7 @@ async function gcInner(
|
|
|
2158
2371
|
const key = comparable(dir, platform);
|
|
2159
2372
|
const keys = [key];
|
|
2160
2373
|
const ownLock = entry.locked && isOwnLockReason(dir, entry.lockReason, platform);
|
|
2161
|
-
if ((entry.locked && !ownLock) || ACTIVE.has(key)) {
|
|
2374
|
+
if ((entry.locked && !ownLock) || ACTIVE.has(key) || isReferenceKept(dir)) {
|
|
2162
2375
|
report.kept.push(dir);
|
|
2163
2376
|
continue;
|
|
2164
2377
|
}
|
|
@@ -2235,7 +2448,7 @@ async function gcInner(
|
|
|
2235
2448
|
continue;
|
|
2236
2449
|
}
|
|
2237
2450
|
const keys = [comparable(dir, platform), comparable(realDir, platform)];
|
|
2238
|
-
if (keys.some((k) => registered.has(k) || ACTIVE.has(k))) continue;
|
|
2451
|
+
if (isReferenceKept(name) || keys.some((k) => registered.has(k) || ACTIVE.has(k))) continue;
|
|
2239
2452
|
if (!stale(parsed.pid, stats, keys)) {
|
|
2240
2453
|
report.kept.push(dir);
|
|
2241
2454
|
continue;
|
package/src/verify/tree.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { createHash } from "node:crypto";
|
|
|
4
4
|
import { lstat, readdir, readFile, readlink, realpath, stat } from "node:fs/promises";
|
|
5
5
|
import { constants as osConstants, setPriority } from "node:os";
|
|
6
6
|
import { extname, join, resolve } from "node:path";
|
|
7
|
+
import { scrubText } from "../guard/scrub";
|
|
7
8
|
import * as tools from "../router/git-tools";
|
|
8
9
|
import { ABSENT_DIGEST, FILE_DIGEST_PREFIX, LINK_DIGEST_PREFIX, type TreeSnapshot, type ChangedFile } from "./dispatch";
|
|
9
10
|
|
|
@@ -173,6 +174,8 @@ export interface SnapshotOptions {
|
|
|
173
174
|
hardened?: boolean;
|
|
174
175
|
/** The git process seam (tests). Default execGit. */
|
|
175
176
|
git?: SnapshotGit;
|
|
177
|
+
/** Optional failure diagnostic: scrubbed, single-line, at most 200 chars. Callback errors are ignored. */
|
|
178
|
+
onError?: (reason: string) => void;
|
|
176
179
|
/**
|
|
177
180
|
* Cross-repo P2.6 (SD11): also compute `TreeSnapshot.ignored`, a bounded digest of the repository's ignored files (nothing
|
|
178
181
|
* under a `node_modules` segment), with the snapshot's own git runner (hardened when `hardened`). QA-2 #9b: "over-bounds" when
|
|
@@ -509,24 +512,29 @@ export async function snapshotTree(cwd: string, signal: AbortSignal, options: Sn
|
|
|
509
512
|
const lowPriority = options.lowPriority === true;
|
|
510
513
|
let prefix: readonly string[] = ["--no-pager"];
|
|
511
514
|
let hardening: Pick<SnapshotGitOptions, "env" | "executable"> = {};
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
+
type Stage = "root" | "head" | "status" | "diff-worktree" | "diff-index" | "index" | "untracked-list" | "hash" | "index-tags" | "ignored-list";
|
|
516
|
+
let stage: Stage = "root";
|
|
517
|
+
const git = (label: Stage, args: string[]) => {
|
|
518
|
+
stage = label;
|
|
519
|
+
return run([...prefix, ...args], {
|
|
520
|
+
cwd: gitCwd, signal, timeoutMs: SNAPSHOT_GIT_TIMEOUT_MS, maxBuffer: SNAPSHOT_GIT_MAX_BUFFER, lowPriority, ...hardening,
|
|
521
|
+
});
|
|
522
|
+
};
|
|
515
523
|
try {
|
|
516
524
|
if (options.hardened === true) {
|
|
517
525
|
const hardened = await hardenedGit(cwd);
|
|
518
526
|
prefix = hardened.prefix;
|
|
519
527
|
hardening = { env: hardened.env, executable: hardened.executable };
|
|
520
528
|
}
|
|
521
|
-
const root = (await git(["rev-parse", "--show-toplevel"])).trim();
|
|
529
|
+
const root = (await git("root", ["rev-parse", "--show-toplevel"])).trim();
|
|
522
530
|
// ls-files otherwise scopes untracked contents to a subdirectory cwd,
|
|
523
531
|
// missing same-path edits in sibling packages that tests may import.
|
|
524
532
|
gitCwd = root;
|
|
525
533
|
// One process, so HEAD and its branch describe the same checkout.
|
|
526
|
-
const [headLine, refLine] = (await git(["rev-parse", "HEAD", "--symbolic-full-name", "HEAD"])).split(/\r?\n/);
|
|
534
|
+
const [headLine, refLine] = (await git("head", ["rev-parse", "HEAD", "--symbolic-full-name", "HEAD"])).split(/\r?\n/);
|
|
527
535
|
const head = (headLine ?? "").trim();
|
|
528
536
|
const branch = parseBranchLine(refLine);
|
|
529
|
-
const status = await git(["status", "--porcelain=v1", "-z", "--untracked-files=all"]);
|
|
537
|
+
const status = await git("status", ["status", "--porcelain=v1", "-z", "--untracked-files=all"]);
|
|
530
538
|
const files: ChangedFile[] = [];
|
|
531
539
|
const records = status.split("\0");
|
|
532
540
|
for (let i = 0; i < records.length; i++) {
|
|
@@ -541,13 +549,14 @@ export async function snapshotTree(cwd: string, signal: AbortSignal, options: Sn
|
|
|
541
549
|
files.push(file);
|
|
542
550
|
}
|
|
543
551
|
const hash = createHash("sha256").update(status);
|
|
544
|
-
hash.update(await git(["diff", "HEAD", "--binary", "--no-ext-diff", "--no-textconv"]));
|
|
545
|
-
hash.update(await git(["diff", "--cached", "--binary", "--no-ext-diff", "--no-textconv"]));
|
|
552
|
+
hash.update(await git("diff-worktree", ["diff", "HEAD", "--binary", "--no-ext-diff", "--no-textconv"]));
|
|
553
|
+
hash.update(await git("diff-index", ["diff", "--cached", "--binary", "--no-ext-diff", "--no-textconv"]));
|
|
546
554
|
// A submodule's dirty marker does not describe its content. Refuse rather
|
|
547
555
|
// than cache a fingerprint that would excuse unmeasured changes there.
|
|
548
|
-
if (/^160000 /m.test(await git(["ls-files", "--stage"]))) return undefined;
|
|
549
|
-
const untracked = (await git(["ls-files", "--others", "--exclude-standard", "--full-name", "-z"]))
|
|
556
|
+
if (/^160000 /m.test(await git("index", ["ls-files", "--stage"]))) return undefined;
|
|
557
|
+
const untracked = (await git("untracked-list", ["ls-files", "--others", "--exclude-standard", "--full-name", "-z"]))
|
|
550
558
|
.split("\0").filter(Boolean).sort();
|
|
559
|
+
stage = "hash";
|
|
551
560
|
for (const path of untracked) {
|
|
552
561
|
const absolute = resolve(root, path);
|
|
553
562
|
const stat = await lstat(absolute);
|
|
@@ -568,7 +577,7 @@ export async function snapshotTree(cwd: string, signal: AbortSignal, options: Sn
|
|
|
568
577
|
// Cross-repo QA-2 #9b: a skip-worktree (`S`) or assume-unchanged (lowercase) entry hides its edits from `status` and
|
|
569
578
|
// `diff`, so the fingerprint cannot vouch for it: the digest is unusable ("over-bounds"), as reference.ts treats it for W.
|
|
570
579
|
// A failed listing leaves `ignored` absent and the snapshot intact, as a failed ignored listing does.
|
|
571
|
-
const hidden = await git([...INDEX_TAGS_ARGS]).then(
|
|
580
|
+
const hidden = await git("index-tags", [...INDEX_TAGS_ARGS]).then(
|
|
572
581
|
tags => tags.split("\0").some(record => record !== "" && (record[0] === "S" || record[0] !== record[0]?.toUpperCase())),
|
|
573
582
|
() => undefined,
|
|
574
583
|
);
|
|
@@ -578,7 +587,7 @@ export async function snapshotTree(cwd: string, signal: AbortSignal, options: Sn
|
|
|
578
587
|
? "over-bounds"
|
|
579
588
|
: await ignoredFilesDigest(
|
|
580
589
|
root,
|
|
581
|
-
() => git([...IGNORED_LIST_ARGS]),
|
|
590
|
+
() => git("ignored-list", [...IGNORED_LIST_ARGS]),
|
|
582
591
|
signal,
|
|
583
592
|
options.maxIgnoredFiles ?? MAX_IGNORED_FILES,
|
|
584
593
|
options.maxIgnoredBytes ?? MAX_IGNORED_BYTES,
|
|
@@ -588,8 +597,16 @@ export async function snapshotTree(cwd: string, signal: AbortSignal, options: Sn
|
|
|
588
597
|
cwd: await realpath(cwd), root: await realpath(root), head, branch, fingerprint: hash.digest("hex"), dirty: files.length > 0, files, digests,
|
|
589
598
|
...(ignored !== undefined ? { ignored } : {}),
|
|
590
599
|
};
|
|
591
|
-
} catch {
|
|
600
|
+
} catch (error) {
|
|
592
601
|
// Not a Git checkout, unreadable file, timeout or concurrent deletion: no baseline.
|
|
602
|
+
try {
|
|
603
|
+
if (options.onError !== undefined) {
|
|
604
|
+
const code = errorCode(error);
|
|
605
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
606
|
+
const reason = `${stage}: ${typeof code === "string" || typeof code === "number" ? `${code}: ` : ""}${message}`;
|
|
607
|
+
options.onError(scrubText(reason).replace(/\s+/g, " ").trim().slice(0, 200) || "snapshot failed");
|
|
608
|
+
}
|
|
609
|
+
} catch { /* Diagnostics never turn an unavailable snapshot into a throw. */ }
|
|
593
610
|
return undefined;
|
|
594
611
|
}
|
|
595
612
|
}
|
package/src/verify/types.ts
CHANGED
|
@@ -64,21 +64,26 @@ export interface ExecResult {
|
|
|
64
64
|
|
|
65
65
|
/** Options shared by every verification process seam (shell string or argv). */
|
|
66
66
|
export interface ExecOptions {
|
|
67
|
+
/** Optional v2 diagnostics; process adapters split preparation from the actual spawn/child lifetime. */
|
|
68
|
+
service?: import("../executor/observations").ServiceExecution;
|
|
67
69
|
cwd?: string;
|
|
68
70
|
timeoutMs?: number;
|
|
69
71
|
/** Aborting kills the whole process tree; an already-aborted signal never spawns. */
|
|
70
72
|
signal?: AbortSignal;
|
|
71
73
|
/** Run the process (and its descendants) at below-normal OS priority. */
|
|
72
74
|
lowPriority?: boolean;
|
|
73
|
-
/** Merged over process.env;
|
|
75
|
+
/** Merged over process.env by default; see envMode for a complete, sanitized environment. */
|
|
74
76
|
env?: Record<string, string>;
|
|
77
|
+
/** `replace` uses only env (empty when omitted), without process.env or automatic slot-environment injection. */
|
|
78
|
+
envMode?: "merge" | "replace";
|
|
75
79
|
}
|
|
76
80
|
|
|
81
|
+
/** Execution-only seam; an adapter doing preparation must forward `service` to the instrumented process layer. */
|
|
77
82
|
export interface ExecSeam {
|
|
78
83
|
(command: string, opts?: ExecOptions): Promise<ExecResult>;
|
|
79
84
|
}
|
|
80
85
|
|
|
81
|
-
/** Spawn `file` with `args` and no shell: arguments reach the child byte-for-byte. */
|
|
86
|
+
/** Spawn `file` with `args` and no shell: arguments reach the child byte-for-byte. Adapters preserve `service`. */
|
|
82
87
|
export interface ArgvSeam {
|
|
83
88
|
(file: string, args: readonly string[], opts?: ExecOptions): Promise<ExecResult>;
|
|
84
89
|
}
|
|
@@ -93,6 +98,8 @@ export interface MutexRegistry {
|
|
|
93
98
|
}
|
|
94
99
|
|
|
95
100
|
export interface DeterministicDeps {
|
|
101
|
+
/** Read-only v2 intrinsic-execution diagnostics; absent on v1/off. */
|
|
102
|
+
service?: import("../executor/observations").ServiceObservation;
|
|
96
103
|
/**
|
|
97
104
|
* S5 (deterministic.ts header, T2 P2-P7): plans, runs and rechecks one testsPass request. Called
|
|
98
105
|
* outside `mutex`. Absent -> testsPass is unverifiable, never a run (G5).
|