werkmeister-core 0.89.2 → 0.90.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 CHANGED
@@ -1,5 +1,21 @@
1
1
  # sandbox-core
2
2
 
3
+ ## 0.90.1
4
+
5
+ ### Patch Changes
6
+
7
+ - c08040c: A starved queue head no longer deadlocks with the feature it waits on (SW-699). A services start from a feature whose gate is running (its lease is busy) now starts past a queue head that holds the line, when it fits: it is how that gate ends and frees the room the head waits for. Before, a head waiting on a busy gate's lease and that gate's own request for one more service each waited on the other until someone stopped a container by hand.
8
+
9
+ ## 0.90.0
10
+
11
+ ## 0.89.3
12
+
13
+ ### Patch Changes
14
+
15
+ - 857fbb4: `werkmeister pr gate` and `pr open` no longer test every service when the diff touches `pnpm-lock.yaml`. The gate compares the worktree's lockfile with the one at the diff's base and touches only the services at the `importers:` entries that differ, mapped through `path_mappings` like a file under that importer. The `tests` row says so (`lockfile: pnpm-lock.yaml changes importers <path> → <svc>`). A change to the root importer `.`, to an importer no mapping covers, to an existing `packages:`/`snapshots:` entry, or to a top-level setting (`overrides`, `settings`, …) still tests every service, and so does a lockfile with no copy on the base.
16
+
17
+ `with-fixture-workspace` takes `--change-base <file>` and `--change-branch <file>` (with `--change`), which give the changed file real text on main and on the branch, e.g. two lockfile copies.
18
+
3
19
  ## 0.89.2
4
20
 
5
21
  ### Patch Changes
@@ -44,6 +44,9 @@ export interface FixtureOptions {
44
44
  slotsFull?: boolean;
45
45
  /** The first repo's `.werkmeister/services.yaml` on the branch, committed over a base fragment on main (`fragment`, else the default registry's), so the gate's fragment row compares the two (SW-664). */
46
46
  fragmentChange?: string;
47
+ /** The texts `change` holds on main and on the branch, instead of `base` and `changed`, e.g. two pnpm-lock.yaml copies (SW-696). */
48
+ changeBase?: string;
49
+ changeBranch?: string;
47
50
  /** Top-level keys added to the fixture's config.yaml, e.g. `{ budget: { host_load: 0.01 } }` (SW-670); fixturePreset refuses any key but CONFIG_KEYS. */
48
51
  config?: Record<string, unknown>;
49
52
  }
@@ -157,7 +157,7 @@ ${githubProject(repos.map((r) => r.name))}${opts.config ? YAML.stringify(opts.co
157
157
  const changed = [change, frag === undefined ? undefined : FRAGMENT_FILE].filter(Boolean);
158
158
  if (changed.length) {
159
159
  if (change)
160
- write(path.join(repo, change), "base\n");
160
+ write(path.join(repo, change), opts.changeBase ?? "base\n");
161
161
  if (frag !== undefined)
162
162
  write(path.join(repo, FRAGMENT_FILE), opts.fragment ?? BASE_FRAGMENT);
163
163
  git(repo, "add", ".");
@@ -176,7 +176,7 @@ ${githubProject(repos.map((r) => r.name))}${opts.config ? YAML.stringify(opts.co
176
176
  git(source, "switch", "-q", "-c", "fixture-source");
177
177
  if (changed.length) {
178
178
  if (change)
179
- write(path.join(repo, change), "changed\n");
179
+ write(path.join(repo, change), opts.changeBranch ?? "changed\n");
180
180
  if (frag !== undefined)
181
181
  write(path.join(repo, FRAGMENT_FILE), frag);
182
182
  git(repo, "commit", "-q", "-am", `change ${changed.join(", ")}`);
@@ -255,7 +255,7 @@ const SCRIPT = `#!/bin/sh
255
255
  # Generated by \`werkmeister workspace init\` (SW-292); rerun it to regenerate.
256
256
  # Runs this workspace's own built werkmeister CLI against a seeded fixture workspace, removed on exit:
257
257
  # temp HOME and registry, a local bare origin, logging fakes for gh and docker, dead Docker and daemon.
258
- # usage: with-fixture-workspace [--no-wait] [--gate] [--bare] [--daemon] [--exec-runs] [--merged] [--behind] [--slots-full] [--issue <ref>] [--pr-field <key>=<value>]... [--workspace <file>] [--config <file>] [--services <file>] [--fragment <file>] [--change <path>] [--fragment-change <file>] [--print <file>]... <werkmeister args> [--then <werkmeister args>]...
258
+ # usage: with-fixture-workspace [--no-wait] [--gate] [--bare] [--daemon] [--exec-runs] [--merged] [--behind] [--slots-full] [--issue <ref>] [--pr-field <key>=<value>]... [--workspace <file>] [--config <file>] [--services <file>] [--fragment <file>] [--change <path>] [--change-base <file>] [--change-branch <file>] [--fragment-change <file>] [--print <file>]... <werkmeister args> [--then <werkmeister args>]...
259
259
  # It only ever runs that CLI, never another command, so one allow rule can cover it (SW-172, SW-231);
260
260
  # --exec-runs, given first, also runs the registry's rows on the host, so the workspace asks before it (SW-473).
261
261
  ws=$(cd "$(dirname "$0")/../.." && pwd -P) || exit 1
@@ -141,6 +141,17 @@ export declare function fragmentTouched(dir: string, files: string[], branch: Re
141
141
  all: string | null;
142
142
  services: string[];
143
143
  };
144
+ /**
145
+ * What a pnpm-lock.yaml change reaches (SW-696): the importers whose entries differ from the
146
+ * base's, or `all` naming a change that reaches every importer — a top-level setting, or a
147
+ * `packages:`/`snapshots:` key on both sides whose value changed (pnpm gives a new version or
148
+ * peer set a new key, so only an existing entry can change an unchanged importer's tree).
149
+ * `null` when either side is not a lockfile.
150
+ */
151
+ export declare function lockfileTouched(base: string, branch: string): {
152
+ all: string | null;
153
+ importers: string[];
154
+ } | null;
144
155
  /**
145
156
  * The pre-PR gate for one repo. A container it had to start for the repo's
146
157
  * tests is stopped again, pass or fail; what was running before stays (SW-34).
@@ -432,6 +432,38 @@ export function fragmentTouched(dir, files, branch, before) {
432
432
  .sort();
433
433
  return { all: reasons.length ? reasons.join(", ") : null, services };
434
434
  }
435
+ const LOCKFILE = "pnpm-lock.yaml";
436
+ /**
437
+ * What a pnpm-lock.yaml change reaches (SW-696): the importers whose entries differ from the
438
+ * base's, or `all` naming a change that reaches every importer — a top-level setting, or a
439
+ * `packages:`/`snapshots:` key on both sides whose value changed (pnpm gives a new version or
440
+ * peer set a new key, so only an existing entry can change an unchanged importer's tree).
441
+ * `null` when either side is not a lockfile.
442
+ */
443
+ export function lockfileTouched(base, branch) {
444
+ let m;
445
+ let b;
446
+ try {
447
+ m = YAML.parse(base);
448
+ b = YAML.parse(branch);
449
+ }
450
+ catch {
451
+ return null;
452
+ }
453
+ if (!m || !b || typeof m !== "object" || typeof b !== "object")
454
+ return null;
455
+ const changed = (x = {}, y = {}) => [...new Set([...Object.keys(x), ...Object.keys(y)])].filter((k) => !isDeepStrictEqual(x[k], y[k]));
456
+ const reasons = [
457
+ ...changed(m, b).filter((k) => !["importers", "packages", "snapshots"].includes(k)),
458
+ ...["packages", "snapshots"].flatMap((s) => changed(m[s], b[s])
459
+ .filter((k) => m[s]?.[k] !== undefined && b[s]?.[k] !== undefined)
460
+ .map((k) => `${s}: ${k}`)),
461
+ ];
462
+ const all = reasons.length
463
+ ? `${reasons.slice(0, 3).join(", ")}${reasons.length > 3 ? ", …" : ""}`
464
+ : null;
465
+ return { all, importers: changed(m["importers"], b["importers"]).sort() };
466
+ }
435
467
  function readEnv(ws, key) {
436
468
  try {
437
469
  for (const line of fs.readFileSync(path.join(ws, ".env"), "utf8").split(/\r?\n/)) {
@@ -806,15 +838,49 @@ testsOnly = false) {
806
838
  : null;
807
839
  // No base fragment (new, or unreadable): the file stays unmapped and every service runs.
808
840
  const fragment = own && before ? fragmentTouched(file.dir, diffed, own, before) : null;
809
- const files = fragment ? diffed.filter((f) => f !== FRAGMENT_REL) : diffed;
810
- const touched = fragment?.all
841
+ // The lockfile maps to the importers its diff changes, not to every service (SW-696).
842
+ // Against the worktree's copy: the gate's containers bind-mount the worktree, not HEAD.
843
+ const lockChange = async () => {
844
+ const mb = await deps.run("git", ["-C", dir, "merge-base", `origin/${base}`, "HEAD"]);
845
+ const show = mb.code
846
+ ? mb
847
+ : await deps.run("git", ["-C", dir, "show", `${mb.stdout.trim()}:${LOCKFILE}`]);
848
+ if (show.code)
849
+ return null;
850
+ try {
851
+ return lockfileTouched(show.stdout, fs.readFileSync(path.join(dir, LOCKFILE), "utf8"));
852
+ }
853
+ catch {
854
+ return null;
855
+ }
856
+ };
857
+ // No base lockfile, or either side unreadable: the file stays unmapped and every service runs.
858
+ const lock = diffed.includes(LOCKFILE) && mappingFor(LOCKFILE, repo) === undefined
859
+ ? await lockChange()
860
+ : null;
861
+ const files = diffed.filter((f) => !(fragment && f === FRAGMENT_REL) && !(lock && f === LOCKFILE));
862
+ // An importer maps like a file under it, so the root importer `.` touches every service.
863
+ const importerFile = (i) => path.posix.join(i, "package.json");
864
+ const lockImporters = lock && !lock.all ? lock.importers : [];
865
+ const lockServices = mapTouched(lockImporters.map(importerFile), repo);
866
+ // Named like an unmapped file (SW-563), so the importer gets mapped rather than every service started again.
867
+ const lockUnmapped = lockImporters.filter((i) => mappingFor(importerFile(i), repo) === undefined);
868
+ const touched = fragment?.all || lock?.all
811
869
  ? [...(repo["services"] ?? [])].sort()
812
- : [...new Set([...mapTouched(files, repo), ...(fragment?.services ?? [])])].sort();
870
+ : [
871
+ ...new Set([...mapTouched(files, repo), ...(fragment?.services ?? []), ...lockServices]),
872
+ ].sort();
813
873
  const skips = (file.fm["skip_tests"] ?? {});
814
874
  if (fragment)
815
875
  add("tests", true, fragment.all
816
876
  ? `every service: ${FRAGMENT_REL} changes ${fragment.all}`
817
877
  : `fragment: ${FRAGMENT_REL} changes ${fragment.services.join(", ") || "no service entry"}`);
878
+ if (lock)
879
+ add("tests", true, lock.all
880
+ ? `every service: ${LOCKFILE} changes ${lock.all}`
881
+ : lockUnmapped.length
882
+ ? `every service: ${LOCKFILE} changes importer ${lockUnmapped.join(", ")}, which no path_mappings or no_service_paths entry covers`
883
+ : `lockfile: ${LOCKFILE} changes importers ${lock.importers.join(", ") || "none"} → ${lockServices.join(", ") || "no service"}`);
818
884
  const unmapped = unmappedFiles(files, repo);
819
885
  const unmappedList = `${unmapped.slice(0, 5).join(", ")}${unmapped.length > 5 ? ", …" : ""}`;
820
886
  // Nothing touched yet unmapped files: the repo has no services to map to
package/dist/scheduler.js CHANGED
@@ -49,8 +49,12 @@ export function admit(budget, running, queue, req) {
49
49
  const position = order.indexOf(self) + 1;
50
50
  const isHead = position === 1;
51
51
  // Backfill: what fits starts past a head that doesn't, unless the head is a gate (it frees its whole
52
- // feature soonest) or has waited STARVE_MS (SW-675).
53
- const headHolds = !isHead && (order[0].gate || order[0].waitedMs >= STARVE_MS);
52
+ // feature soonest) or has waited STARVE_MS (SW-675). Never against a service start of a busy
53
+ // feature: it is how its gate ends and frees the lease the head may be waiting on (SW-699).
54
+ // shortcut: busy also covers a gate exec in the last idle_stop_minutes, so a recent gate's later
55
+ // --service start passes too; tighten to a live-gate signal if heads starve again.
56
+ const endsGate = !!req.services && running.some((l) => l.feature === req.feature && l.busy);
57
+ const headHolds = !isHead && !endsGate && (order[0].gate || order[0].waitedMs >= STARVE_MS);
54
58
  if (fits({ memory: 0, cpus: 0 }) && (req.byPerson || !headHolds))
55
59
  return { kind: "admit" };
56
60
  // An idle or human-check lease (a session parked on a question) has nobody in it, so the queue head
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "werkmeister-core",
3
- "version": "0.89.2",
3
+ "version": "0.90.1",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "description": "werkmeister's shared library. Its public API is werkmeister-core/sdk; every other entry point is internal.",
@@ -125,6 +125,7 @@
125
125
  "typecheck": "tsc --noEmit",
126
126
  "docs:links": "typedoc",
127
127
  "docs:sdk": "typedoc --options typedoc.sdk.json",
128
- "test": "sh ./run-tests.sh"
128
+ "test": "sh ./run-tests.sh",
129
+ "test:changed": "node test-changed.mjs"
129
130
  }
130
131
  }