opencode-model-router 2.6.1 → 2.8.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 +239 -0
- package/README.md +3 -1
- package/package.json +2 -2
- package/src/commands/approvals.ts +354 -0
- package/src/commands/output.ts +12 -1
- package/src/compat/v2-hooks.ts +255 -53
- package/src/index.ts +328 -37
- package/src/router/config.ts +48 -2
- package/src/router/dispatch-header.ts +95 -2
- package/src/router/git-tools.ts +165 -9
- package/src/router/protocol.ts +5 -1
- package/src/router/role-agents.ts +110 -3
- package/src/router/roles-config.ts +83 -0
- package/src/router/roles.ts +1 -1
- package/src/router/sessions.ts +11 -0
- package/src/routing/classify/route-line.ts +96 -5
- package/src/routing/classify/types.ts +26 -0
- package/src/routing/outcomes/signals.ts +17 -0
- package/src/routing/roles/admission.ts +1028 -0
- package/src/routing/roles/approvals.ts +876 -0
- package/src/routing/roles/binding.ts +17 -4
- package/src/routing/roles/check-placement.ts +112 -0
- package/src/routing/roles/git-root.ts +500 -0
- package/src/routing/roles/policy.ts +9 -0
- package/src/routing/roles/read-set.ts +325 -0
- package/src/routing/roles/work-root.ts +9 -1
- package/src/routing/wire/dispatch.ts +611 -18
- package/src/routing/wire/working-set.ts +58 -0
- package/src/util/linear-trim.ts +32 -0
- package/src/verify/batch.ts +7 -2
- package/src/verify/branch.ts +135 -0
- package/src/verify/deterministic.ts +232 -10
- package/src/verify/dispatch.ts +284 -9
- package/src/verify/dod.ts +46 -0
- package/src/verify/edges.ts +817 -0
- package/src/verify/gate.ts +349 -16
- package/src/verify/git-top.ts +43 -0
- package/src/verify/head.ts +107 -0
- package/src/verify/pending.ts +155 -8
- package/src/verify/perimeter.ts +1180 -0
- package/src/verify/pin.ts +109 -0
- package/src/verify/reference.ts +174 -30
- package/src/verify/risk.ts +16 -3
- package/src/verify/runner.ts +706 -32
- package/src/verify/tree.ts +347 -8
- package/src/verify/types.ts +57 -0
- package/src/verify/wiring.ts +1324 -35
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/verify/pin.ts
|
|
3
|
+
*
|
|
4
|
+
* Cross-repo P2d.2 (docs/design/cross-repo.md, OD3 = fail closed): the pin of a linked repository. At dispatch each admitted
|
|
5
|
+
* link target of W is snapshotted together with a bounded digest of its ignored files (`node_modules` excluded). At
|
|
6
|
+
* materialize the link counts as exact when both are unchanged; it is `external-link` when the target changed, the digest is
|
|
7
|
+
* over its bounds, the target is not admitted, or the target is not a git repository. A target's own external links are
|
|
8
|
+
* followed one level; a link one level deeper makes the target's pin unusable.
|
|
9
|
+
*
|
|
10
|
+
* Pure apart from the injected deps: nothing here runs git.
|
|
11
|
+
*/
|
|
12
|
+
import type { TreeSnapshot } from "./dispatch";
|
|
13
|
+
import { perimeterKey } from "./git-top";
|
|
14
|
+
import { linkedTargets } from "./perimeter";
|
|
15
|
+
|
|
16
|
+
export type PinWhy = "not-observed" | "not-admitted" | "not-git" | "over-bounds" | "deep-link";
|
|
17
|
+
|
|
18
|
+
export type LinkPin =
|
|
19
|
+
| {
|
|
20
|
+
readonly kind: "pinned";
|
|
21
|
+
readonly root: string;
|
|
22
|
+
readonly head: string;
|
|
23
|
+
readonly fingerprint: string;
|
|
24
|
+
readonly ignored: string;
|
|
25
|
+
readonly nested: readonly LinkPin[];
|
|
26
|
+
}
|
|
27
|
+
| { readonly kind: "unpinnable"; readonly root: string; readonly why: PinWhy };
|
|
28
|
+
|
|
29
|
+
/** What `pinTarget` needs; all injected so no git is run here. */
|
|
30
|
+
export interface PinDeps {
|
|
31
|
+
snapshot(dir: string): Promise<TreeSnapshot | undefined>;
|
|
32
|
+
admitted(dir: string): boolean;
|
|
33
|
+
externalLinks(dir: string): string[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The default link discovery: the external package links of `dir` (perimeter.ts linkedTargets). */
|
|
37
|
+
export const defaultExternalLinks: (dir: string) => string[] = linkedTargets;
|
|
38
|
+
|
|
39
|
+
function unpinnable(root: string, why: PinWhy): LinkPin {
|
|
40
|
+
return { kind: "unpinnable", root, why };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The pin of one root from its dispatch-time snapshot (no links followed). */
|
|
44
|
+
export function pinOf(root: string, snapshot: TreeSnapshot | undefined, admitted: boolean): LinkPin {
|
|
45
|
+
if (!admitted) return unpinnable(root, "not-admitted");
|
|
46
|
+
if (snapshot === undefined) return unpinnable(root, "not-observed");
|
|
47
|
+
if (snapshot.root === undefined) return unpinnable(root, "not-git");
|
|
48
|
+
if (snapshot.ignored === "over-bounds") return unpinnable(root, "over-bounds");
|
|
49
|
+
if (snapshot.ignored === undefined) return unpinnable(root, "not-observed");
|
|
50
|
+
return { kind: "pinned", root, head: snapshot.head, fingerprint: snapshot.fingerprint, ignored: snapshot.ignored, nested: [] };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** UNC and device paths (`\\host\share`, `//host/share`, `\\?\`, `\\.\`): never touched, decided by text alone. */
|
|
54
|
+
function isUncOrDevice(dir: string): boolean {
|
|
55
|
+
return /^[\\/]{2}/.test(dir);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** True only for a non-UNC directory that is admitted; checked before any snapshot or link discovery on it. */
|
|
59
|
+
function mayTouch(dir: string, deps: PinDeps): boolean {
|
|
60
|
+
return !isUncOrDevice(dir) && deps.admitted(dir);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** True only when both pins are pinned and identical, nested pins included (order-independent by root key). */
|
|
64
|
+
export function samePin(a: LinkPin, b: LinkPin): boolean {
|
|
65
|
+
if (a.kind !== "pinned" || b.kind !== "pinned") return false;
|
|
66
|
+
if (perimeterKey(a.root) !== perimeterKey(b.root)) return false;
|
|
67
|
+
if (a.head !== b.head || a.fingerprint !== b.fingerprint || a.ignored !== b.ignored) return false;
|
|
68
|
+
if (a.nested.length !== b.nested.length) return false;
|
|
69
|
+
const byKey = new Map<string, LinkPin>();
|
|
70
|
+
for (const pin of b.nested) {
|
|
71
|
+
const key = perimeterKey(pin.root);
|
|
72
|
+
if (byKey.has(key)) return false;
|
|
73
|
+
byKey.set(key, pin);
|
|
74
|
+
}
|
|
75
|
+
const seen = new Set<string>();
|
|
76
|
+
for (const pin of a.nested) {
|
|
77
|
+
const key = perimeterKey(pin.root);
|
|
78
|
+
const other = byKey.get(key);
|
|
79
|
+
if (other === undefined || seen.has(key) || !samePin(pin, other)) return false;
|
|
80
|
+
seen.add(key);
|
|
81
|
+
}
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Pins `root` and, one level deep, the targets of its own external links. A target that itself has external links makes the
|
|
87
|
+
* whole root unpinnable (`deep-link`, OD3); an unpinnable nested pin makes the root unpinnable with its reason. A UNC or
|
|
88
|
+
* device path, or a directory that is not admitted, is `not-admitted` before any snapshot or link discovery on it (I11/I12).
|
|
89
|
+
* Never throws.
|
|
90
|
+
*/
|
|
91
|
+
export async function pinTarget(root: string, deps: PinDeps): Promise<LinkPin> {
|
|
92
|
+
try {
|
|
93
|
+
// I11/I12: refuse UNC/device paths by text and non-admitted directories before any fs or git call on them.
|
|
94
|
+
if (!mayTouch(root, deps)) return unpinnable(root, "not-admitted");
|
|
95
|
+
const own = pinOf(root, await deps.snapshot(root), true);
|
|
96
|
+
if (own.kind !== "pinned") return own;
|
|
97
|
+
const nested: LinkPin[] = [];
|
|
98
|
+
for (const target of deps.externalLinks(root)) {
|
|
99
|
+
if (!mayTouch(target, deps)) return unpinnable(root, "not-admitted");
|
|
100
|
+
if (deps.externalLinks(target).length > 0) return unpinnable(root, "deep-link");
|
|
101
|
+
const pin = pinOf(target, await deps.snapshot(target), true);
|
|
102
|
+
if (pin.kind !== "pinned") return unpinnable(root, pin.why);
|
|
103
|
+
nested.push(pin);
|
|
104
|
+
}
|
|
105
|
+
return { ...own, nested };
|
|
106
|
+
} catch {
|
|
107
|
+
return unpinnable(root, "not-observed");
|
|
108
|
+
}
|
|
109
|
+
}
|
package/src/verify/reference.ts
CHANGED
|
@@ -101,7 +101,16 @@
|
|
|
101
101
|
// "a0\r\n" while exact stayed true. LF files under text=auto are common
|
|
102
102
|
// on win32 (e.g. Prettier's default endOfLine: lf). Each differing path
|
|
103
103
|
// adds "checkout-conversion" for it, up to MAX_CONVERSION_REASONS, then
|
|
104
|
-
// one "" reason.
|
|
104
|
+
// one "" reason. A file another writer edits between the drift diff
|
|
105
|
+
// and the live listing is in neither set, so when the listing finds a
|
|
106
|
+
// live-vs-reference `w/` difference the diff is taken again, limited
|
|
107
|
+
// to those paths, and the paths it reports join the changed set
|
|
108
|
+
// before flagging (#88). They get checks (c) and (d) and are then
|
|
109
|
+
// judged like any file edited after dispatch (the QA-1.5-16 rule
|
|
110
|
+
// above: flagged only when the reference's `w/` differs from its
|
|
111
|
+
// `i/`; under `* text=auto` with native CRLF still flagged,
|
|
112
|
+
// QA-1.5-19). A failed or unaffordable re-diff (budget spent, more
|
|
113
|
+
// than MAX_REDIFF_PATHS paths) keeps every flag.
|
|
105
114
|
// (f) No index entry is assume-unchanged or skip-worktree at capture
|
|
106
115
|
// (QA-1.5-6b). Git skips such entries, so neither stash create nor the
|
|
107
116
|
// drift diff sees a local edit to them (live "v2-local" became "v1" at
|
|
@@ -312,11 +321,22 @@
|
|
|
312
321
|
// "checkout-conversion" for it. A path in the drift set but not in
|
|
313
322
|
// ref.tracked (edited after capture, QA-1.5-16) has unknown dispatch
|
|
314
323
|
// bytes, so it adds "checkout-conversion" when the reference's own `w/`
|
|
315
|
-
// class differs from its `i/` class (the checkout converted it).
|
|
316
|
-
// the
|
|
317
|
-
//
|
|
318
|
-
//
|
|
319
|
-
//
|
|
324
|
+
// class differs from its `i/` class (the checkout converted it). When
|
|
325
|
+
// the lists show a path with a live-vs-reference `w/` difference that is
|
|
326
|
+
// in neither set (#88: edited by another writer after the step-7 diff),
|
|
327
|
+
// the step-7 diff (private index, `--literal-pathspecs`, limited to
|
|
328
|
+
// those paths, at most MAX_REDIFF_PATHS) is taken again. The paths it
|
|
329
|
+
// reports join the drift set, get the (c)/(d) checks of step 7, and are
|
|
330
|
+
// then judged by the QA-1.5-16 rule above (a re-diffed path whose
|
|
331
|
+
// checkout converted it, w/ != i/, stays flagged, QA-1.5-19). A failed
|
|
332
|
+
// re-diff (logged), a spent budget or too many paths keeps every flag.
|
|
333
|
+
// This is the last step, so the two listings get the remaining budget
|
|
334
|
+
// with the caller's signal only: a budget that runs out here, or a
|
|
335
|
+
// failing call, adds "" instead of failing materialize; a caller abort
|
|
336
|
+
// returns ok:false "aborted". The re-diff is the exception: like step 7
|
|
337
|
+
// it runs under the budget's signal (its private-index copy), so a
|
|
338
|
+
// spent budget there skips it and keeps the flags, while a caller abort
|
|
339
|
+
// returns "aborted" and an UnsafeReferencePathError "unsafe-path".
|
|
320
340
|
// 8. Return { ok: true, reference: { dir, exact, inexactReasons,
|
|
321
341
|
// unreproduced, links, toRefPath, dispose } }. toRefPath(p) maps an
|
|
322
342
|
// absolute live path under root, or under realpath(root), to the same
|
|
@@ -386,7 +406,7 @@
|
|
|
386
406
|
// so a junction created after the sweep costs nothing (QA-1.5-3 repro:
|
|
387
407
|
// `git worktree remove` in this slot deleted the late junction's target
|
|
388
408
|
// contents; fs.rm left them intact). The sweep stays, because fs.rm's
|
|
389
|
-
// non-following is proven only on Node v24.21.0 and engines is >=
|
|
409
|
+
// non-following is proven only on Node v24.21.0 and engines is >=22. If
|
|
390
410
|
// dir still exists afterwards (EBUSY from a process whose cwd is inside),
|
|
391
411
|
// warn and leave it for GC; git is not run.
|
|
392
412
|
// 4. Only once dir is gone, and while the admin entry is still registered:
|
|
@@ -661,6 +681,12 @@
|
|
|
661
681
|
// reference inexact. Avoiding it needs each path's `w/` class at capture,
|
|
662
682
|
// i.e. a full `ls-files --eol` inside the capture budget; not done, since
|
|
663
683
|
// the error only yields "unverifiable", never a wrong excuse.
|
|
684
|
+
// - The QA-1.5-16 rule cannot see a legacy-checkout conversion (QA-1.5-18
|
|
685
|
+
// class: old core.autocrlf, `crlf` attribute) in a file edited after
|
|
686
|
+
// dispatch, because the reference's `i/` equals its `w/` there. That was
|
|
687
|
+
// already true for edits before the step-7 diff; the step-7b re-diff
|
|
688
|
+
// (#88) extends it to edits in the window between the diff and the live
|
|
689
|
+
// listing.
|
|
664
690
|
// - Output cap (QA-1.5-24, owner 2.1): the seam caps each stream (p12
|
|
665
691
|
// runArgv default 10 M chars) and a cut listing is a failed call. Capture's
|
|
666
692
|
// `ls-files --stage` hits the cap first, at ~95-150k tracked paths (path
|
|
@@ -705,6 +731,9 @@ import { tmpdir as osTmpdir } from "node:os";
|
|
|
705
731
|
import { posix as pathPosix, win32 as pathWin32 } from "node:path";
|
|
706
732
|
import type { ArgvSeam, ExecOptions, ExecResult } from "./types";
|
|
707
733
|
import type { TreeSnapshot } from "./dispatch";
|
|
734
|
+
import { gitTopOf, perimeterKey } from "./git-top";
|
|
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";
|
|
708
737
|
import type { PluginLogger } from "../router/logger";
|
|
709
738
|
|
|
710
739
|
// --- Seams --------------------------------------------------------------------
|
|
@@ -778,6 +807,11 @@ export interface ReferenceDeps extends CaptureDeps {
|
|
|
778
807
|
randomSuffix?: () => string;
|
|
779
808
|
/** Default HEARTBEAT_INTERVAL_MS: how often a materialized dir's mtime is refreshed while in use. */
|
|
780
809
|
heartbeatMs?: number;
|
|
810
|
+
/**
|
|
811
|
+
* Cross-repo P2.6: the current pin of a link target's repository top, computed by the caller (pin.ts pinTarget). With
|
|
812
|
+
* DispatchReference.pins, a package link into a pinned repository unchanged since dispatch is exact instead of external-link.
|
|
813
|
+
*/
|
|
814
|
+
pinNow?: (root: string) => Promise<LinkPin>;
|
|
781
815
|
}
|
|
782
816
|
|
|
783
817
|
// --- Data types ---------------------------------------------------------------
|
|
@@ -797,6 +831,8 @@ export interface DispatchReference {
|
|
|
797
831
|
readonly captureReasons: readonly InexactReason[];
|
|
798
832
|
/** now() when the capture resolved. */
|
|
799
833
|
readonly capturedAt: number;
|
|
834
|
+
/** Cross-repo P2.6: the dispatch-time pins of linked repositories (pin.ts); see ReferenceDeps.pinNow. */
|
|
835
|
+
readonly pins?: readonly LinkPin[];
|
|
800
836
|
}
|
|
801
837
|
|
|
802
838
|
export type InexactCause =
|
|
@@ -808,6 +844,8 @@ export type InexactCause =
|
|
|
808
844
|
| "untracked-unsafe-path"
|
|
809
845
|
| "dependency-drift"
|
|
810
846
|
| "workspace-link-drift"
|
|
847
|
+
| "external-link"
|
|
848
|
+
| "root-link"
|
|
811
849
|
| "index-flags"
|
|
812
850
|
| "checkout-conversion";
|
|
813
851
|
|
|
@@ -877,6 +915,20 @@ const ADD_LOCK_UNSUPPORTED = /unknown option\W+(?:reason|lock)\b/;
|
|
|
877
915
|
export const STALE_REFERENCE_AGE_MS = 60 * 60 * 1000;
|
|
878
916
|
/** A live reference dir's mtime is refreshed this often, far below STALE_REFERENCE_AGE_MS (QA-1.5-4). */
|
|
879
917
|
export const HEARTBEAT_INTERVAL_MS = 5 * 60 * 1000;
|
|
918
|
+
/**
|
|
919
|
+
* Package-store layouts (pnpm `.pnpm/x@1/node_modules/x`, a global virtual store, a custom virtualStoreDir) all place the
|
|
920
|
+
* package directly under a node_modules dir (or its @scope): a package link whose real path is such a directory is store-like
|
|
921
|
+
* (P0.4, step 7 below; cross-repo P1.8 link discovery, perimeter.ts).
|
|
922
|
+
*/
|
|
923
|
+
export function isStoreLikeLink(real: string, platform: string): boolean {
|
|
924
|
+
const p = platform === "win32" ? pathWin32 : pathPosix;
|
|
925
|
+
const fold = (s: string): string => (platform === "win32" ? s.toLowerCase() : s);
|
|
926
|
+
const parent = p.dirname(real);
|
|
927
|
+
const parentName = fold(p.basename(parent));
|
|
928
|
+
if (parentName === "node_modules") return true;
|
|
929
|
+
return parentName.startsWith("@") && fold(p.basename(p.dirname(parent))) === "node_modules";
|
|
930
|
+
}
|
|
931
|
+
|
|
880
932
|
/** Equals the baselineTimeoutMs default (§1.4); callers pass the configured value. */
|
|
881
933
|
export const DEFAULT_CAPTURE_TIMEOUT_MS = 15_000;
|
|
882
934
|
export const DEFAULT_MATERIALIZE_TIMEOUT_MS = 30_000;
|
|
@@ -889,6 +941,8 @@ export const MAX_UNTRACKED_BYTES = 64 * 1024 * 1024;
|
|
|
889
941
|
export const MAX_SWEEP_ENTRIES = 500_000;
|
|
890
942
|
/** Per-path "checkout-conversion" reasons from the eol comparison (section 2e); beyond it, one "" reason. */
|
|
891
943
|
export const MAX_CONVERSION_REASONS = 100;
|
|
944
|
+
/** Most paths the step-7b re-diff (#88) is limited to; more than this keeps every conversion flag. */
|
|
945
|
+
const MAX_REDIFF_PATHS = 64;
|
|
892
946
|
/** Marker value for an untracked symbolic link (not a sha256, so it never matches a file hash). */
|
|
893
947
|
export const UNTRACKED_SYMLINK = "symlink";
|
|
894
948
|
/** Basenames whose drift between commit and the live tree makes a linked node_modules stale (section 2c). */
|
|
@@ -1750,6 +1804,8 @@ export async function materialize(
|
|
|
1750
1804
|
}
|
|
1751
1805
|
|
|
1752
1806
|
// 5. Discovery of ignored entries; nothing ignored is ever copied.
|
|
1807
|
+
// A directory-only pattern (`node_modules/`) never matches a symlink, so a symlinked node_modules
|
|
1808
|
+
// it does not ignore is an untracked entry (inexact via its untracked reason), never a link candidate.
|
|
1753
1809
|
const ignored = await git(["ls-files", "--others", "--ignored", "--exclude-standard", "--directory", "-z"]);
|
|
1754
1810
|
if (budget.spent()) return await abandon("aborted", "aborted during ignored-file discovery");
|
|
1755
1811
|
if (!ignored || ignored.code !== 0) return await abandon("error", ignored?.stderr.trim() ?? "ignored-file discovery failed");
|
|
@@ -1762,7 +1818,9 @@ export async function materialize(
|
|
|
1762
1818
|
}
|
|
1763
1819
|
|
|
1764
1820
|
// 6. Link node_modules (section 5), parents before children (git's order).
|
|
1765
|
-
|
|
1821
|
+
// Each target keeps the root-relative path of the candidate node_modules it came from,
|
|
1822
|
+
// so drift reasons never leak a path outside root (a node_modules that is itself a link).
|
|
1823
|
+
const linkTargets: { readonly target: string; readonly label: string }[] = [];
|
|
1766
1824
|
for (const entry of candidates) {
|
|
1767
1825
|
if (budget.spent()) return await abandon("aborted", "aborted while linking node_modules");
|
|
1768
1826
|
const rel = entry.replace(/\/$/, "");
|
|
@@ -1794,7 +1852,7 @@ export async function materialize(
|
|
|
1794
1852
|
}
|
|
1795
1853
|
links.push(linkPath);
|
|
1796
1854
|
await fs.symlink(target, linkPath, platform === "win32" ? "junction" : "dir");
|
|
1797
|
-
linkTargets.push(target);
|
|
1855
|
+
linkTargets.push({ target, label: rel });
|
|
1798
1856
|
}
|
|
1799
1857
|
|
|
1800
1858
|
// 7. Drift checks (section 2 c and d). Porcelain `git diff` rewrites the index
|
|
@@ -1802,10 +1860,17 @@ export async function materialize(
|
|
|
1802
1860
|
const scratchEnv: PrivateIndexEnv = {
|
|
1803
1861
|
argv: deps.argv, fs, root, tmpdir: tmp, platform, pid: deps.pid ?? process.pid, logger: deps.logger,
|
|
1804
1862
|
};
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1863
|
+
// `only`: the step-7b re-diff (#88) is limited to the paths it must classify, as literal
|
|
1864
|
+
// pathspecs whatever GIT_LITERAL_PATHSPECS says.
|
|
1865
|
+
const driftDiff = (only: readonly string[] = []) =>
|
|
1866
|
+
withPrivateIndex(scratchEnv, budget, (copy) =>
|
|
1867
|
+
runGit(deps.argv, [
|
|
1868
|
+
...(only.length > 0 ? ["--literal-pathspecs"] : []),
|
|
1869
|
+
"-c", "core.splitIndex=false", "diff", "--name-only", "-z", "--no-renames", "--no-ext-diff", ref.commit, "--", ...only,
|
|
1870
|
+
], {
|
|
1871
|
+
cwd: root, timeoutMs: budget.remaining(), signal: budget.signal, env: { GIT_INDEX_FILE: copy },
|
|
1872
|
+
}));
|
|
1873
|
+
const diff = await driftDiff();
|
|
1809
1874
|
const nowUntracked = await git(["ls-files", "--others", "--exclude-standard", "-z"]);
|
|
1810
1875
|
if (budget.spent()) return await abandon("aborted", "aborted during drift checks");
|
|
1811
1876
|
if (!diff || diff.code !== 0 || !nowUntracked || nowUntracked.code !== 0) {
|
|
@@ -1813,13 +1878,46 @@ export async function materialize(
|
|
|
1813
1878
|
}
|
|
1814
1879
|
for (const rel of splitZ(diff.stdout)) changed.add(rel);
|
|
1815
1880
|
for (const rel of splitZ(nowUntracked.stdout)) if (!ref.untracked.has(rel)) changed.add(rel);
|
|
1816
|
-
const changedSorted = [...changed].sort(byCodeUnit);
|
|
1817
|
-
for (const rel of changedSorted) {
|
|
1818
|
-
if (DEPENDENCY_FILES.has(rel.split("/").at(-1) ?? "")) reasons.push({ cause: "dependency-drift", path: rel });
|
|
1819
|
-
}
|
|
1820
1881
|
const realRoot = p.resolve(await fs.realpath(root));
|
|
1882
|
+
const fold = (s: string) => (platform === "win32" ? s.toLowerCase() : s);
|
|
1821
1883
|
const workspaceDirs = new Set<string>();
|
|
1822
|
-
|
|
1884
|
+
// P0.4: package links whose real path is outside the repository (and not a store-like
|
|
1885
|
+
// path under a node_modules segment) load code the reference cannot pin.
|
|
1886
|
+
const externalLinks = new Set<string>();
|
|
1887
|
+
// A package link to the root itself, or to an ancestor of it, would load the live tree.
|
|
1888
|
+
const rootLinks = new Set<string>();
|
|
1889
|
+
// Package-store layouts (pnpm `.pnpm/x@1/node_modules/x`, a global virtual store, a custom
|
|
1890
|
+
// virtualStoreDir) all place the package directly under a node_modules dir (or its @scope).
|
|
1891
|
+
const storeLike = (real: string): boolean => isStoreLikeLink(real, platform);
|
|
1892
|
+
// Cross-repo P2.6 (OD3, fail closed): an outside link whose git top was pinned at dispatch (ref.pins) and has the same
|
|
1893
|
+
// pin now (deps.pinNow) is exact. No pin, an unpinnable or changed pin, no pinNow, or a throw keeps external-link.
|
|
1894
|
+
const pins = ref.pins ?? [];
|
|
1895
|
+
const pinNow = deps.pinNow;
|
|
1896
|
+
const usePins = pins.length > 0 && pinNow !== undefined;
|
|
1897
|
+
const pinVerdicts = new Map<string, Promise<boolean>>();
|
|
1898
|
+
const pinnedUnchanged = async (real: string): Promise<boolean> => {
|
|
1899
|
+
try {
|
|
1900
|
+
if (pinNow === undefined) return false;
|
|
1901
|
+
const top = gitTopOf(real);
|
|
1902
|
+
if (top === undefined) return false;
|
|
1903
|
+
const key = perimeterKey(top);
|
|
1904
|
+
const dispatchPin = pins.find((pin) => perimeterKey(pin.root) === key);
|
|
1905
|
+
if (dispatchPin === undefined || dispatchPin.kind !== "pinned") return false;
|
|
1906
|
+
let verdict = pinVerdicts.get(key);
|
|
1907
|
+
if (verdict === undefined) {
|
|
1908
|
+
verdict = (async () => {
|
|
1909
|
+
// Lazy: a static import would close the cycle reference -> pin -> perimeter -> reference.
|
|
1910
|
+
const { samePin } = await import("./pin");
|
|
1911
|
+
return samePin(dispatchPin, await pinNow(dispatchPin.root));
|
|
1912
|
+
})().catch(() => false);
|
|
1913
|
+
pinVerdicts.set(key, verdict);
|
|
1914
|
+
}
|
|
1915
|
+
return await verdict;
|
|
1916
|
+
} catch {
|
|
1917
|
+
return false;
|
|
1918
|
+
}
|
|
1919
|
+
};
|
|
1920
|
+
for (const { target, label } of linkTargets) {
|
|
1823
1921
|
for (const entry of await packageEntries(fs, target, platform)) {
|
|
1824
1922
|
const stats = await lstatOrMissing(fs, entry);
|
|
1825
1923
|
if (!stats || !stats.isSymbolicLink()) continue;
|
|
@@ -1831,18 +1929,37 @@ export async function materialize(
|
|
|
1831
1929
|
continue;
|
|
1832
1930
|
}
|
|
1833
1931
|
const base = [realRoot, root].find((candidateRoot) => isStrictlyInside(real, candidateRoot, platform));
|
|
1834
|
-
if (!base)
|
|
1932
|
+
if (!base) {
|
|
1933
|
+
// Dot-entries (`.cache`, `.bin`) are tool state, not packages.
|
|
1934
|
+
if (!p.basename(entry).startsWith(".")) {
|
|
1935
|
+
const entryLabel = [label, ...p.relative(target, entry).split(p.sep)].join("/");
|
|
1936
|
+
if (insideOrEqual(realRoot, real, platform) || insideOrEqual(root, real, platform)) rootLinks.add(entryLabel);
|
|
1937
|
+
else if (!storeLike(real) && !(usePins && (await pinnedUnchanged(real)))) externalLinks.add(entryLabel);
|
|
1938
|
+
}
|
|
1939
|
+
continue;
|
|
1940
|
+
}
|
|
1835
1941
|
const rel = p.relative(base, real).split(p.sep).join("/");
|
|
1836
1942
|
if (!rel.split("/").includes("node_modules")) workspaceDirs.add(rel);
|
|
1837
1943
|
}
|
|
1838
1944
|
}
|
|
1839
|
-
const
|
|
1840
|
-
for (const rel of [...
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1945
|
+
for (const rel of [...rootLinks].sort(byCodeUnit)) reasons.push({ cause: "root-link", path: rel });
|
|
1946
|
+
for (const rel of [...externalLinks].sort(byCodeUnit)) reasons.push({ cause: "external-link", path: rel });
|
|
1947
|
+
// Section 2 (c) and (d) over a set of drifted paths; run on the step-7 set and, in step 7b, on
|
|
1948
|
+
// the paths its re-diff adds (#88), so a late edit is judged like any other drift.
|
|
1949
|
+
const driftReasons = (paths: readonly string[]) => {
|
|
1950
|
+
const sorted = [...paths].sort(byCodeUnit);
|
|
1951
|
+
for (const rel of sorted) {
|
|
1952
|
+
if (DEPENDENCY_FILES.has(rel.split("/").at(-1) ?? "")) reasons.push({ cause: "dependency-drift", path: rel });
|
|
1844
1953
|
}
|
|
1845
|
-
|
|
1954
|
+
for (const rel of [...workspaceDirs].sort(byCodeUnit)) {
|
|
1955
|
+
const prefix = fold(rel) + "/";
|
|
1956
|
+
if (reasons.some((r) => r.cause === "workspace-link-drift" && r.path === rel)) continue;
|
|
1957
|
+
if (sorted.some((c) => fold(c) === fold(rel) || fold(c).startsWith(prefix))) {
|
|
1958
|
+
reasons.push({ cause: "workspace-link-drift", path: rel });
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
};
|
|
1962
|
+
driftReasons([...changed]);
|
|
1846
1963
|
|
|
1847
1964
|
// 7b. Clean-file checkout conversion (section 2e, QA-1.5-13): the working-tree eol class
|
|
1848
1965
|
// of every tracked path that is neither hashed above (ref.tracked) nor changed since
|
|
@@ -1872,14 +1989,41 @@ export async function materialize(
|
|
|
1872
1989
|
if (!liveEol || !refEol) {
|
|
1873
1990
|
conversion(""); // not compared: budget spent or git failed
|
|
1874
1991
|
} else {
|
|
1992
|
+
// #88: a writer that edits a file between the step-7 diff and the live listing leaves it
|
|
1993
|
+
// in neither set; its live `w/` then differs from the reference's with no checkout
|
|
1994
|
+
// conversion behind it. Take the diff again, limited to those paths (at most
|
|
1995
|
+
// MAX_REDIFF_PATHS; beyond that the flags stay), before flagging them. A failed or
|
|
1996
|
+
// unaffordable re-diff changes nothing, so every flag stays (fail safe). Paths it adds go
|
|
1997
|
+
// through the (c)/(d) drift checks and then the QA-1.5-16 rule below.
|
|
1998
|
+
const unexplained = (rel: string, w: string) => {
|
|
1999
|
+
if (ref.tracked.has(rel) || changed.has(rel)) return false;
|
|
2000
|
+
const live = liveEol.get(rel);
|
|
2001
|
+
return live !== undefined && live.w !== w;
|
|
2002
|
+
};
|
|
2003
|
+
const suspects = [...refEol].filter(([rel, { w }]) => unexplained(rel, w)).map(([rel]) => rel).sort(byCodeUnit);
|
|
2004
|
+
if (suspects.length > 0 && suspects.length <= MAX_REDIFF_PATHS && !budget.spent()) {
|
|
2005
|
+
let again: ExecResult | undefined;
|
|
2006
|
+
try {
|
|
2007
|
+
again = await driftDiff(suspects);
|
|
2008
|
+
} catch (error) {
|
|
2009
|
+
if (signal.aborted || error instanceof UnsafeReferencePathError) throw error;
|
|
2010
|
+
deps.logger?.warn("reference eol re-diff failed: flags kept", { error: describeError(error) });
|
|
2011
|
+
}
|
|
2012
|
+
if (signal.aborted) return await abandon("aborted", "aborted during the eol comparison");
|
|
2013
|
+
if (again && again.code === 0) {
|
|
2014
|
+
const added = splitZ(again.stdout).filter((rel) => !changed.has(rel));
|
|
2015
|
+
for (const rel of added) changed.add(rel);
|
|
2016
|
+
driftReasons(added);
|
|
2017
|
+
} else if (again) {
|
|
2018
|
+
deps.logger?.warn("reference eol re-diff failed: flags kept", { code: again.code, stderr: again.stderr.trim() });
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
1875
2021
|
// QA-1.5-16: a path edited since capture (in changed, not in ref.tracked) has unknown
|
|
1876
2022
|
// dispatch bytes; it is flagged when the reference's checkout converted it (w/ != i/).
|
|
1877
2023
|
const differing = [...refEol]
|
|
1878
2024
|
.filter(([rel, { i, w }]) => {
|
|
1879
|
-
if (ref.tracked.has(rel)) return
|
|
1880
|
-
|
|
1881
|
-
const live = liveEol.get(rel);
|
|
1882
|
-
return live !== undefined && live.w !== w;
|
|
2025
|
+
if (changed.has(rel) && !ref.tracked.has(rel)) return i !== "" && w !== "" && i !== w;
|
|
2026
|
+
return unexplained(rel, w);
|
|
1883
2027
|
})
|
|
1884
2028
|
.map(([rel]) => rel)
|
|
1885
2029
|
.sort(byCodeUnit);
|
|
@@ -2114,4 +2258,4 @@ async function gcInner(
|
|
|
2114
2258
|
}
|
|
2115
2259
|
}
|
|
2116
2260
|
}
|
|
2117
|
-
}
|
|
2261
|
+
}
|
package/src/verify/risk.ts
CHANGED
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
* | 7 | a test file (incl. snapshots) was modified (added, changed, renamed) | medium |
|
|
34
34
|
* | 8 | a non-test file was deleted or any file was renamed | medium |
|
|
35
35
|
* | 9 | config / lock / CI / test-setup file changed (see isConfigPath) | medium |
|
|
36
|
-
* | 10 | scoping impossible (Unverifiable, S6)
|
|
36
|
+
* | 10 | scoping impossible (Unverifiable, S6), or the full suite runs | medium |
|
|
37
|
+
* | | (FullScopePlan: REASONS.fullScope instead) | |
|
|
37
38
|
* | 11 | producer tier "fast" | medium |
|
|
38
39
|
* | 12 | no reference captured | +1 step (max high) |
|
|
39
40
|
*
|
|
@@ -50,12 +51,22 @@ import type { ChangedPath, StaticScoping } from "./runner";
|
|
|
50
51
|
export type RiskLevel = "low" | "medium" | "high";
|
|
51
52
|
export type ProducerTier = "fast" | "medium" | "heavy" | (string & {});
|
|
52
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Cross-repo P2e (QA-1 #6): the scoping "plan" of a DoD whose every testsPass check runs the full suite (`scope=full`, or the
|
|
56
|
+
* dispatch's full scope): nothing is planned, so it is neither scoped nor S6. Row 10 then rates it medium with the neutral
|
|
57
|
+
* REASONS.fullScope instead of REASONS.unverifiable.
|
|
58
|
+
*/
|
|
59
|
+
export interface FullScopePlan {
|
|
60
|
+
readonly fullScope: true;
|
|
61
|
+
}
|
|
62
|
+
export const FULL_SCOPE_PLAN: FullScopePlan = { fullScope: true };
|
|
63
|
+
|
|
53
64
|
export interface RiskInput {
|
|
54
65
|
readonly changedFiles: readonly ChangedPath[];
|
|
55
66
|
/** Whether a reference (baseline) exists for this delegation. Only presence matters. */
|
|
56
67
|
readonly reference: boolean;
|
|
57
68
|
readonly producerTier: ProducerTier;
|
|
58
|
-
readonly scopingPlan: StaticScoping;
|
|
69
|
+
readonly scopingPlan: StaticScoping | FullScopePlan;
|
|
59
70
|
/** Git root; absolute changed paths are made relative to it before classification. */
|
|
60
71
|
readonly root?: string;
|
|
61
72
|
}
|
|
@@ -79,6 +90,7 @@ export const REASONS = {
|
|
|
79
90
|
deletedOrRenamed: "files were deleted or renamed",
|
|
80
91
|
configChanged: "config, lock or CI files changed",
|
|
81
92
|
unverifiable: "scoping impossible (S6): the change cannot be verified by scoped tests",
|
|
93
|
+
fullScope: "the full suite runs (scope=full)",
|
|
82
94
|
noAffected: "no affected tests found by static scoping",
|
|
83
95
|
fastTier: "produced by the fast tier",
|
|
84
96
|
noReference: "no reference captured: risk raised one step",
|
|
@@ -257,7 +269,8 @@ export function assessRisk(input: RiskInput): RiskAssessment {
|
|
|
257
269
|
hit("medium", REASONS.configChanged);
|
|
258
270
|
}
|
|
259
271
|
|
|
260
|
-
if ("
|
|
272
|
+
if ("fullScope" in scopingPlan && scopingPlan.fullScope === true) hit("medium", REASONS.fullScope);
|
|
273
|
+
else if ("unverifiable" in scopingPlan && scopingPlan.unverifiable === true) hit("medium", REASONS.unverifiable);
|
|
261
274
|
else if ("noAffected" in scopingPlan && scopingPlan.noAffected === true) reasons.push(REASONS.noAffected);
|
|
262
275
|
|
|
263
276
|
if (producerTier === "fast") hit("medium", REASONS.fastTier);
|