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.
Files changed (59) hide show
  1. package/CHANGELOG.md +482 -0
  2. package/README.md +4 -2
  3. package/package.json +12 -5
  4. package/src/compat/background.ts +56 -19
  5. package/src/compat/child-history.ts +134 -0
  6. package/src/compat/child-report.ts +185 -0
  7. package/src/compat/child-session.ts +10 -0
  8. package/src/compat/session-lookup.ts +21 -0
  9. package/src/compat/v2-client.ts +124 -6
  10. package/src/compat/v2-hooks.ts +525 -203
  11. package/src/compat/v2-observations.ts +1 -0
  12. package/src/compat/v2-vocabulary.ts +14 -0
  13. package/src/executor/create.ts +47 -28
  14. package/src/executor/git.ts +226 -30
  15. package/src/executor/integrate/checks.ts +29 -11
  16. package/src/executor/integrate/land.ts +32 -2
  17. package/src/executor/integrate/queue.ts +95 -13
  18. package/src/executor/ledger.ts +16 -12
  19. package/src/executor/lfs-restore.ts +492 -0
  20. package/src/executor/paths.ts +7 -2
  21. package/src/executor/recovery.ts +2 -1
  22. package/src/executor/runtime.ts +1062 -243
  23. package/src/executor/slots/pool.ts +120 -19
  24. package/src/executor/slots/provision.ts +111 -23
  25. package/src/executor/slots/root.ts +81 -0
  26. package/src/executor/types.ts +28 -2
  27. package/src/executor/unattended.ts +6 -1
  28. package/src/executor/verify-trees.ts +507 -0
  29. package/src/guard/enforce.ts +2 -1
  30. package/src/guard/fingerprint.ts +9 -0
  31. package/src/guard/guards.ts +7 -1
  32. package/src/index.ts +191 -31
  33. package/src/router/answer-dedup.ts +198 -0
  34. package/src/router/common-dir.ts +241 -0
  35. package/src/router/config.ts +228 -40
  36. package/src/router/diff-handles.ts +322 -0
  37. package/src/router/diff-summary.ts +318 -0
  38. package/src/router/git-metadata-guard.ts +317 -0
  39. package/src/router/git-tools.ts +1136 -49
  40. package/src/router/read-only.ts +37 -13
  41. package/src/router/role-agents.ts +100 -36
  42. package/src/router/run-summary.ts +253 -0
  43. package/src/router/run-tools.ts +177 -25
  44. package/src/router/sessions.ts +23 -1
  45. package/src/router/tool-paths.ts +62 -4
  46. package/src/routing/classify/rules.ts +93 -14
  47. package/src/routing/roles/read-set.ts +10 -1
  48. package/src/routing/roles/work-root.ts +20 -3
  49. package/src/routing/wire/hint.ts +9 -2
  50. package/src/v2.ts +3 -1
  51. package/src/verify/exec.ts +454 -2
  52. package/src/verify/head.ts +6 -1
  53. package/src/verify/pending.ts +14 -1
  54. package/src/verify/plan-task.ts +86 -26
  55. package/src/verify/reference.ts +60 -7
  56. package/src/verify/runner.ts +14 -6
  57. package/src/verify/tree.ts +34 -10
  58. package/src/verify/types.ts +44 -0
  59. package/src/verify/wiring.ts +134 -22
@@ -540,10 +540,27 @@ export function createIntegrationChecks(d: IntegrationChecksDeps): IntegrationCh
540
540
  ...(c.cwd === undefined ? {} : { cwd: c.cwd }), ...(c.env === undefined ? {} : { env: c.env }) };
541
541
  }
542
542
 
543
- /** The configured pytest interpreter (`python`: a bare name or an absolute path; "auto" is the bare `python`). */
544
- function configuredPython(): string {
543
+ /**
544
+ * The configured pytest interpreter for `cwd` and its command label, the one place both are chosen: a selection, a
545
+ * command moved to another slot and each spawn ask it, so the label always names the interpreter that runs. `python`
546
+ * is a bare name or an absolute path; "auto" is the bare `python`. POSIX (#192): outside a slot with a virtual
547
+ * environment (which always has `python`), "auto" is `python3` when it resolves (Debian and Ubuntu ship only
548
+ * `python3`), else `python`.
549
+ */
550
+ function pytestInterpreter(cwd: string): { program: string; label: string } {
551
+ const pick = (program: string) => ({ program, label: `${program} -m pytest` });
545
552
  const python = d.ledger().config.python;
546
- return python === "auto" ? "python" : python;
553
+ if (python !== "auto") return pick(python);
554
+ const platform = process.platform;
555
+ if (platform === "win32" || slotEnvFor(cwd, platform)?.set.VIRTUAL_ENV !== undefined) return pick("python");
556
+ const guards = workRootGuards(cwd);
557
+ try {
558
+ resolveCommandExecutable("python3", { platform, env: runEnvironment(process.env, platform, undefined, { guards }) }, guards);
559
+ return pick("python3");
560
+ } catch {
561
+ // No usable python3 on PATH: the bare `python` (resolution then reports it when it is missing too).
562
+ return pick("python");
563
+ }
547
564
  }
548
565
 
549
566
  /**
@@ -563,7 +580,8 @@ export function createIntegrationChecks(d: IntegrationChecksDeps): IntegrationCh
563
580
  * never a bare name resolved from the cwd. `configured`: argv[0] is the configured interpreter (N-A-1), else the
564
581
  * planner's (a scoped or rerun spec planned in this cwd).
565
582
  */
566
- function resolvePython(c: ResolvedCommand, cwd: string, configured: boolean): ResolvedCommand {
583
+ function resolvePython(c: ResolvedCommand, cwd: string, configured: boolean,
584
+ chosen: { program: string; label: string } | undefined = configured ? pytestInterpreter(cwd) : undefined): ResolvedCommand {
567
585
  const platform = process.platform;
568
586
  const guards = workRootGuards(cwd);
569
587
  let shell: string | undefined;
@@ -575,11 +593,11 @@ export function createIntegrationChecks(d: IntegrationChecksDeps): IntegrationCh
575
593
  const slotEnv = slotEnvFor(cwd, platform);
576
594
  try {
577
595
  const host = { platform, env: base };
578
- const program = configured ? configuredPython() : c.file;
596
+ const program = chosen?.program ?? c.file;
579
597
  const file = slotToolExecutable(program, slotEnv, host, () => guards) ?? resolveCommandExecutable(program, host, guards);
580
598
  const env = applySlotEnv(base, slotEnv, platform);
581
- const resolved: ResolvedCommand = { ...c, file, resolution: { cwd, env: Object.fromEntries(Object.entries(env)
582
- .filter((entry): entry is [string, string] => entry[1] !== undefined)) } };
599
+ const resolved: ResolvedCommand = { ...c, ...(chosen === undefined ? {} : { label: chosen.label }), file,
600
+ resolution: { cwd, env: Object.fromEntries(Object.entries(env).filter((entry): entry is [string, string] => entry[1] !== undefined)) } };
583
601
  if (configured) fromConfig.add(resolved);
584
602
  return resolved;
585
603
  } catch (e) {
@@ -602,10 +620,10 @@ export function createIntegrationChecks(d: IntegrationChecksDeps): IntegrationCh
602
620
  const tests: TestComponent[] = [];
603
621
  if (sel.node) tests.push({ framework: "node", full: await resolveRef({ script: "test", args: [] }, cwd) });
604
622
  if (sel.pytest) {
605
- const python = configuredPython();
606
- const label = `${python} -m pytest`;
607
- if (d.allowCommand === undefined || d.allowCommand(label)) {
608
- tests.push({ framework: "pytest", full: resolvePython({ label, file: python, args: ["-m", "pytest"], source: "pytest", ref: null }, cwd, true) });
623
+ const chosen = pytestInterpreter(cwd);
624
+ if (d.allowCommand === undefined || d.allowCommand(chosen.label)) {
625
+ tests.push({ framework: "pytest", full: resolvePython(
626
+ { label: chosen.label, file: chosen.program, args: ["-m", "pytest"], source: "pytest", ref: null }, cwd, true, chosen) });
609
627
  }
610
628
  }
611
629
  const extras: ResolvedCommand[] = [];
@@ -3,6 +3,8 @@
3
3
  // (`repo.toplevel`): every probe runs with `-C <toplevel>`, never against another worktree of the same repository.
4
4
  // Never forces and never creates a non-fast-forward.
5
5
 
6
+ import { lstat } from "node:fs/promises";
7
+ import { join } from "node:path";
6
8
  import { hardeningArgs } from "../../router/git-tools";
7
9
  import { phaseTagName as gitPhaseTagName } from "../git";
8
10
  import type { GitOps } from "../git";
@@ -22,6 +24,8 @@ export interface LanderDeps {
22
24
  /** Hardened runner for the read-only owner-checkout probes (toplevel, HEAD, status); each call uses `-C <toplevel>`. */
23
25
  run: GitRunner;
24
26
  realpath: (p: string) => Promise<string>; platform: NodeJS.Platform;
27
+ /** Whether a path exists (a populated submodule's `.git`). Default: `lstat` succeeds. */
28
+ exists?: (p: string) => Promise<boolean>;
25
29
  }
26
30
 
27
31
  export interface LanderApi {
@@ -61,12 +65,33 @@ function parseStatusPaths(stdout: string): string[] {
61
65
  }
62
66
 
63
67
  export function createLander(d: LanderDeps): LanderApi {
68
+ const exists = d.exists ?? (async (p: string) => lstat(p).then(() => true, () => false));
69
+
64
70
  async function probe(toplevel: string, args: readonly string[]): Promise<{ code: number | null; stdout: string }> {
65
- // hardeningArgs() neutralises configured hooks/fsmonitor/pagers: `status` must not run a repo-configured program.
71
+ // hardeningArgs() neutralises configured hooks/fsmonitor/pagers: `status` must not run a repo-configured program. The
72
+ // production runner (executor/git.ts withRepositoryDrivers) also blanks the repository-only filter/merge drivers.
66
73
  const r = await d.run.run(["-C", toplevel, "--no-optional-locks", ...hardeningArgs(), ...args], { cwd: toplevel, timeoutMs: READ_TIMEOUT_MS });
67
74
  return { code: r.code, stdout: r.stdout };
68
75
  }
69
76
 
77
+ /**
78
+ * The populated submodules of the owner checkout (gitlinks whose directory holds a `.git`). `status --ignore-submodules=none`
79
+ * runs `git status` inside each with that submodule's own configuration, whose filter/merge drivers the superproject's
80
+ * listing never sees, so the cleanliness check refuses to run there (an unpopulated gitlink runs nothing).
81
+ */
82
+ async function populatedSubmodules(toplevel: string): Promise<string[]> {
83
+ const listed = await probe(toplevel, ["ls-files", "--stage", "-z"]);
84
+ if (listed.code !== 0) throw new Error(`git ls-files failed in the owner checkout (exit ${listed.code ?? "unknown"})`);
85
+ const populated: string[] = [];
86
+ for (const record of listed.stdout.split("\0")) {
87
+ const tab = record.indexOf("\t");
88
+ if (!record.startsWith("160000 ") || tab === -1) continue;
89
+ const path = record.slice(tab + 1);
90
+ if (await exists(join(toplevel, path, ".git"))) populated.push(path);
91
+ }
92
+ return populated;
93
+ }
94
+
70
95
  async function inspect(req: LandRequest): Promise<LandInspection> {
71
96
  const { toplevel, baseBranch, candidate } = req;
72
97
 
@@ -97,7 +122,12 @@ export function createLander(d: LanderDeps): LanderApi {
97
122
  return { ok: false, refusal: { reason: "not-checked-out", head: headRef === "" ? null : headRef }, baseTip };
98
123
  }
99
124
 
100
- // 3. The owner checkout is clean.
125
+ // 3. The owner checkout is clean. A populated submodule fails closed first (see populatedSubmodules).
126
+ const submodules = await populatedSubmodules(toplevel);
127
+ if (submodules.length > 0) {
128
+ throw new Error(`the owner checkout has populated submodules (${submodules.slice(0, 5).join(", ")}): the executor does not run git `
129
+ + "inside them with their own configuration; land manually");
130
+ }
101
131
  const status = await probe(toplevel, ["status", "--porcelain=v1", "-z", "--untracked-files=all", "--ignore-submodules=none"]);
102
132
  if (status.code !== 0) throw new Error(`git status failed in the owner checkout (exit ${status.code ?? "unknown"})`);
103
133
  const dirty = parseStatusPaths(status.stdout);
@@ -67,6 +67,8 @@ export const PREEMPT_LIMIT = 3, LOCK_HEARTBEAT_MS = 30_000, LOCK_STALE_MS = 600_
67
67
  export const LOCK_WAIT_REPORT_MS = 300_000;
68
68
  /** QA-62C-7: a failed repo-lock heartbeat is retried after at most this long; this many failures in a row are warned once. */
69
69
  export const LOCK_HEARTBEAT_RETRY_MS = 1_000, LOCK_HEARTBEAT_WARN_FAILURES = 3;
70
+ /** 3.2-m3 (#187): background retries of a release's failed compare-and-delete (heartbeat retry delay, doubling). */
71
+ export const LOCK_RELEASE_RETRIES = 5;
70
72
  /** QA-3.2-30: retries of a tag entry of a completed plan (after its 3 tries), with doubling delays from TAG_RETRY_BASE_MS. */
71
73
  export const TAG_RETRY_LIMIT = 3, TAG_RETRY_BASE_MS = 60_000;
72
74
 
@@ -669,6 +671,35 @@ export function createRepoLockFactory(o: {
669
671
  void p.finally(() => { if (beating === p) beating = null; });
670
672
  };
671
673
  let timer = o.clock.setTimer(heartbeatMs, beat);
674
+ const report = (text: string): void => {
675
+ try {
676
+ o.logger?.warn(text);
677
+ } catch {
678
+ // A reporting failure never blocks a release.
679
+ }
680
+ };
681
+ /**
682
+ * 3.2-m3 (#187): retry `n` of a release's failed compare-and-delete, after heartbeatRetryMs·2^(n-1). It removes only
683
+ * the file this lock wrote (`ours` compares the token): once the file is gone, or holds a newer lock (this process's
684
+ * next acquire or another holder writes a new token), nothing of ours is left and the retries stop.
685
+ */
686
+ const retryRemoval = (n: number): void => {
687
+ o.clock.setTimer(heartbeatRetryMs * 2 ** (n - 1), () => {
688
+ void (async () => {
689
+ try {
690
+ const raw = await readRaw(file);
691
+ if (raw !== null && ours(raw)) await removeIfSame(file, raw);
692
+ } catch (e) {
693
+ if (n < LOCK_RELEASE_RETRIES) {
694
+ retryRemoval(n + 1);
695
+ return;
696
+ }
697
+ report(`integration queue: gave up removing the repo lock ${file} after ${n} retries (${message(e)}); other `
698
+ + "processes on this host wait for it until this process exits or the file is removed");
699
+ }
700
+ })();
701
+ });
702
+ };
672
703
  const lock: RepoLockWithTakeover = {
673
704
  lost: lost.signal,
674
705
  takeover,
@@ -688,10 +719,15 @@ export function createRepoLockFactory(o: {
688
719
  o.clock.clearTimer(timer);
689
720
  try {
690
721
  if (beating !== null) await beating;
722
+ // Already gone (null) or replaced by a takeover (not ours): nothing of ours to remove.
691
723
  const raw = await readRaw(file);
692
724
  if (raw !== null && ours(raw)) await removeIfSame(file, raw);
693
- } catch {
694
- // Already gone or replaced by a takeover: nothing of ours to remove.
725
+ } catch (e) {
726
+ // 3.2-m3 (#187): a failed read or compare-and-delete leaves our lock file, which another process on this host
727
+ // would wait for until this one exits. Reported, and retried in the background a bounded number of times.
728
+ report(`integration queue: could not remove the repo lock ${file} on release (${message(e)}); retrying up to `
729
+ + `${LOCK_RELEASE_RETRIES} times`);
730
+ retryRemoval(1);
695
731
  } finally {
696
732
  freeMutex();
697
733
  }
@@ -1273,9 +1309,11 @@ class Queue implements IntegrationQueue {
1273
1309
  /**
1274
1310
  * QA-3.2-10 / QA-3.2-25: the rebase upstream of a task that was reverted. A retry built on the old task branch whose
1275
1311
  * original change lies below the merge base (fast-forwarded as is, then reverted) would replay only its fixes. Unless the
1276
- * tip already contains the latest revert (a retry rebuilt on the head keeps the merge base), the upstream is the one
1277
- * journaled in the task's first rebase step (its original base, ancestor of the tip), else the `from` of the OLDEST revert
1278
- * whose `to` is below the merge base. Any number of reverts keeps the original change.
1312
+ * tip already contains the latest revert (a retry rebuilt on the head keeps the merge base), the upstream is the NEWEST
1313
+ * one journaled in the task's rebase steps that is an ancestor of the tip (3.2-m2, #188: a retry branch rebuilt on a head
1314
+ * and then reused must not replay from an older base, which would replay other tasks' reverted changes), even when it is
1315
+ * the merge base (a retry that landed as a rebased copy: its own commits are not on the branch), else the `from` of the
1316
+ * OLDEST revert whose `to` is below the merge base. Any number of reverts keeps the original change.
1279
1317
  */
1280
1318
  private async reintegrationUpstream(id: TaskId, tip: string, mergeBase: string): Promise<string> {
1281
1319
  const reverts = await this.revertedRanges(id);
@@ -1283,8 +1321,13 @@ class Queue implements IntegrationQueue {
1283
1321
  if (latest === undefined) return mergeBase;
1284
1322
  const top = this.ledger.repo.toplevel;
1285
1323
  if (latest.revertHead !== null && await this.d.igit.isAncestor(top, latest.revertHead, tip)) return mergeBase;
1286
- const first = await this.firstUpstream(id);
1287
- if (first !== null && first !== mergeBase && await this.d.igit.isAncestor(top, first, tip)) return first;
1324
+ const journaled = await this.journaledUpstreams(id);
1325
+ let newest: string | null = null;
1326
+ for (let i = journaled.length - 1; i >= 0 && newest === null; i--) {
1327
+ const u = journaled[i];
1328
+ if (u !== undefined && await this.d.igit.isAncestor(top, u, tip)) newest = u;
1329
+ }
1330
+ if (newest !== null) return newest;
1288
1331
  for (const rv of reverts) {
1289
1332
  if (rv.to !== rv.from && await this.d.igit.isAncestor(top, rv.to, mergeBase)) return rv.from;
1290
1333
  }
@@ -1311,18 +1354,22 @@ class Queue implements IntegrationQueue {
1311
1354
  return out;
1312
1355
  }
1313
1356
 
1314
- /** The `upstream` journaled for `id` in the first rebase step that planned it (its original base), or null. */
1315
- private async firstUpstream(id: TaskId): Promise<string | null> {
1357
+ /** Every distinct `upstream` journaled for `id` in the rebase steps that planned it, oldest first (first = original base). */
1358
+ private async journaledUpstreams(id: TaskId): Promise<string[]> {
1359
+ const out: string[] = [];
1316
1360
  for (const ev of await this.loadSteps()) {
1317
1361
  if (ev.step !== "rebase" || ev.edge !== "start" || (ev.entry.kind !== "task" && ev.entry.kind !== "batch")) continue;
1318
1362
  const tasks = parseDetail(ev.detail)?.tasks;
1319
1363
  if (!Array.isArray(tasks)) continue;
1320
1364
  for (const t of tasks as unknown[]) {
1321
1365
  const x = t as { taskId?: unknown; upstream?: unknown } | null;
1322
- if (x !== null && typeof x === "object" && x.taskId === id && typeof x.upstream === "string") return x.upstream;
1366
+ if (x === null || typeof x !== "object" || x.taskId !== id || typeof x.upstream !== "string") continue;
1367
+ const i = out.indexOf(x.upstream);
1368
+ if (i >= 0) out.splice(i, 1);
1369
+ out.push(x.upstream);
1323
1370
  }
1324
1371
  }
1325
- return null;
1372
+ return out;
1326
1373
  }
1327
1374
 
1328
1375
  private async runTaskEntry(ids: TaskId[], requeue: boolean): Promise<void> {
@@ -2284,14 +2331,49 @@ class Queue implements IntegrationQueue {
2284
2331
  "revert-build", { v: 1, culprit: { ...rv.culprit }, suiteCommit: rv.suiteCommit, head, files: [...rv.files] }, NONE, rv.ids);
2285
2332
  this.serial = live;
2286
2333
  const slot = await this.integrationSlot();
2334
+ const p = rv.phaseId;
2335
+ let commands = rv.commands;
2336
+ if (rv.ids.length === 0 && commands.length === 0) {
2337
+ // 3.2-m4 (#188): a culprit with no ids (a full-command bisect), rebuilt from history or rerun after the suite commands
2338
+ // failed to resolve, has only the suite commands to re-check the regression with. They are resolved once more; still
2339
+ // none: fail closed, never a revert without its regression run.
2340
+ let why: string;
2341
+ let phaseCause = false;
2342
+ try {
2343
+ const res = await this.d.suite.resolve(this.ledger, p, rv.suiteCommit);
2344
+ if (res.kind === "runs") commands = res.commands;
2345
+ phaseCause = res.kind !== "runs" || res.commands.length === 0;
2346
+ why = res.kind === "refused" ? res.reason : res.kind === "runs" ? "the suite resolves to no command" : `the suite resolves to "${res.kind}"`;
2347
+ } catch (e) {
2348
+ why = message(e);
2349
+ }
2350
+ if (commands.length === 0) {
2351
+ const text = `The revert of ${rv.culprit.taskId} was not built: the culprit has no failing test ids, so only the phase suite commands can check the revert, and they do not resolve at ${rv.suiteCommit} (${clipText(why, 500)}).`;
2352
+ if (!phaseCause) {
2353
+ // The resolver failed: the entry stays open (M36); unpause rolls it back and rebuilds the revert, resolving again.
2354
+ if (live.open !== null) await this.end(live, "refused", { v: 1, reason: "resolve", message: clipText(why, 1000) }, false);
2355
+ return this.infraPause(live, text);
2356
+ }
2357
+ // The phase's suite setting (refused/none/off): as `suiteRefused`, only the phase pauses. The entry closes, so the
2358
+ // unpause reruns the suite (M25: no revert pending), which resolves the commands again.
2359
+ const now = this.d.clock.iso();
2360
+ const before = this.ledger.inbox.length;
2361
+ if (live.open === null) await this.start(live, "revert-build", { v: 1, culprit: { ...rv.culprit }, suiteCommit: rv.suiteCommit, head: this.ledger.integration.head, files: [...rv.files] });
2362
+ const next = await this.end(live, "refused", { v: 1, reason: "resolve", message: clipText(why, 1000) }, true, [],
2363
+ lg => [{ type: "phase-paused", phaseId: p, paused: true, reason: "suite-unresolvable" },
2364
+ this.inboxEvent(lg, "failure", "critical", rv.culprit.taskId,
2365
+ `${text} Phase ${p} is paused; fix its suite, then unpause phase ${p} to run the suite again.`, now)]);
2366
+ this.notifyInbox(this.newInbox(next, before));
2367
+ return;
2368
+ }
2369
+ }
2287
2370
  // M26: built at the current head (a rerun entry may have been journaled before requeued tasks integrated).
2288
2371
  const buildHead = this.ledger.integration.head;
2289
2372
  const v = await this.d.suite.revert({ planId: this.d.planId, phaseId: rv.phaseId, culprit: { ...rv.culprit }, suiteCommit: rv.suiteCommit,
2290
- head: buildHead, regression: { ids: [...rv.ids], files: [...rv.files], commands: [...rv.commands] }, slot },
2373
+ head: buildHead, regression: { ids: [...rv.ids], files: [...rv.files], commands: [...commands] }, slot },
2291
2374
  this.journal(live, this.ctl.signal));
2292
2375
  const now = this.d.clock.iso();
2293
2376
  const before = this.ledger.inbox.length;
2294
- const p = rv.phaseId;
2295
2377
  if (v.kind === "interrupted") throw new LaneStop(`revert interrupted by ${v.by}`);
2296
2378
  if (v.kind === "error") {
2297
2379
  if (live.open !== null) await this.end(live, "refused", { v: 1, reason: v.reason, message: clipText(v.message, 1000) }, false);
@@ -301,10 +301,6 @@ function edgeEndpointExists(l: LedgerV1, id: string): boolean {
301
301
  return taskOf(l, id) !== null;
302
302
  }
303
303
 
304
- function sameStrings(a: readonly string[], b: readonly string[]): boolean {
305
- return a.length === b.length && a.every((x, i) => x === b[i]);
306
- }
307
-
308
304
  function isSuperset(next: readonly string[], prev: readonly string[]): boolean {
309
305
  return prev.every((p) => next.includes(p));
310
306
  }
@@ -2132,6 +2128,16 @@ function fsErrorCode(e: unknown): string | undefined {
2132
2128
  return undefined;
2133
2129
  }
2134
2130
 
2131
+ /**
2132
+ * The error codes the node FileSystem's `fsyncDir` ignores. Windows cannot open a directory for fsync (EPERM, EACCES,
2133
+ * EISDIR); NTFS journals the directory entry itself. POSIX (#192): some file systems cannot fsync a directory (EINVAL,
2134
+ * ENOTSUP, macOS EOPNOTSUPP); the rename itself has landed. Never ENOENT.
2135
+ */
2136
+ export function fsyncDirIgnorable(code: string | undefined, platform: NodeJS.Platform): boolean {
2137
+ if (platform === "win32") return code === "EPERM" || code === "EACCES" || code === "EISDIR";
2138
+ return code === "EINVAL" || code === "ENOTSUP" || code === "EOPNOTSUPP";
2139
+ }
2140
+
2135
2141
  /** Production `FileSystem` over node:fs. Nothing runs at module load; every call is made on demand. */
2136
2142
  export function createNodeFileSystem(): FileSystem {
2137
2143
  return {
@@ -2167,14 +2173,16 @@ export function createNodeFileSystem(): FileSystem {
2167
2173
  await nodeFsp.rmdir(p);
2168
2174
  }
2169
2175
  },
2170
- async mkdir(p) {
2171
- await nodeFsp.mkdir(p, { recursive: true });
2176
+ async mkdir(p, o) {
2177
+ await nodeFsp.mkdir(p, o?.mode === undefined ? { recursive: true } : { recursive: true, mode: o.mode });
2172
2178
  },
2173
2179
  readdir: (p) => nodeFsp.readdir(p),
2174
2180
  async lstat(p): Promise<FsStat | null> {
2175
2181
  try {
2176
2182
  const s = await nodeFsp.lstat(p);
2177
2183
  const kind: FsStat["kind"] = s.isSymbolicLink() ? "symlink" : s.isDirectory() ? "dir" : s.isFile() ? "file" : "other";
2184
+ // POSIX (#192): owner and mode, for the private slots root and lock directory checks.
2185
+ if (process.platform !== "win32") return { kind, size: s.size, mtimeMs: s.mtimeMs, uid: s.uid, mode: s.mode };
2178
2186
  return { kind, size: s.size, mtimeMs: s.mtimeMs };
2179
2187
  } catch (e) {
2180
2188
  if (fsErrorCode(e) === "ENOENT") return null;
@@ -2182,13 +2190,9 @@ export function createNodeFileSystem(): FileSystem {
2182
2190
  }
2183
2191
  },
2184
2192
  realpath: (p) => nodeFsp.realpath(p),
2193
+ chmod: (p, mode) => nodeFsp.chmod(p, mode),
2185
2194
  async fsyncDir(p) {
2186
- // Windows cannot open a directory for fsync (EPERM/EACCES/EISDIR); NTFS journals the directory entry itself.
2187
- const ignorable = (e: unknown): boolean => {
2188
- if (process.platform !== "win32") return false;
2189
- const c = fsErrorCode(e);
2190
- return c === "EPERM" || c === "EACCES" || c === "EISDIR";
2191
- };
2195
+ const ignorable = (e: unknown): boolean => fsyncDirIgnorable(fsErrorCode(e), process.platform);
2192
2196
  let fh: nodeFsp.FileHandle;
2193
2197
  try {
2194
2198
  fh = await nodeFsp.open(p, "r");