werkmeister-core 0.94.2 → 0.94.4

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,26 @@
1
1
  # sandbox-core
2
2
 
3
+ ## 0.94.4
4
+
5
+ ### Patch Changes
6
+
7
+ - e5bfa35: The fixture's config.yaml sits at its temp HOME's `~/.werkmeister/config.yaml`, and `machine migrate` runs when `*_CONFIG_FILE` names that default path, so `with-fixture-workspace machine migrate` works (SW-581).
8
+ - 2a8f495: `with-temp-home` takes `--cwd <dir>` (after `--no-wait`) and runs its command there, whatever the shell's cwd; in the werkmeister container the same worktree maps to `/app`. The test commands in `werkmeister-context.md` and their allow rules now pass `--cwd <ws>/<repo>`, so they work from the workspace root too, still with no `cd` (SW-652). Rerun `werkmeister workspace init` to regenerate the file; `werkmeister machine migrate` refreshes the rules and the wrapper.
9
+ - 2775cec: The core, CLI and MCP test entries refuse to start when HOME holds the real `~/.werkmeister` and is not `with-temp-home`'s temp HOME, which every version of the wrapper marks by setting TMPDIR to it (SW-662).
10
+ - 47cd1d8: Tests only: `up_exit.test.ts` drops an inherited `WERKMEISTER_ROOT`, and the `waitForSetupLoad` tests restore `WERKMEISTER_NO_WAIT` (SW-671).
11
+ - eb7da8b: `werkmeister internal wait-load` decides exit 75 from the wait's structured result (`spent`, `note`), not by parsing its note (SW-716).
12
+ - 46c84f0: `with-temp-home` pins the daemon at `http://127.0.0.1:65535`, which is refused like a stopped daemon unless a test listener was handed that port (port 1 was rejected by fetch as a bad port), with a 500 ms retry (SW-743).
13
+ - 1f15a0f: Tests only: `daemon-client.test.mjs` no longer fails under a no-match `--test-name-pattern`, and a `test:no-match` check runs in CI (SW-816).
14
+ - a0625a5: `with-fixture-workspace --stale-compose` (with `--fragment-change`) inits the workspace before the branch's fragment lands, so `pr gate` starts the service from `compose.gate.yml`; in-process fixtures get `staleCompose` and `applyFragmentChange()` (SW-817).
15
+ - e65468d: Tests only: a guard test fails when a file in `shared-process.list` is missing or touches shared process state (SW-826).
16
+
17
+ ## 0.94.3
18
+
19
+ ### Patch Changes
20
+
21
+ - 31dd7fd: Shared infra made from an old checkout path is detected. A container made from another checkout's compose file is named, with `werkmeister infra up` as the fix, by `feature up`, `infra proxy-reload`, `feature status` and `infra status`. `infra up` now recreates those containers too, including one whose only drift is the files it was made from. Caddy counts as unhealthy when its `/__werkmeister` picker page is missing from its mount, which used to 404 on every routed host.
22
+ - 879f709: `feature stop --via-daemon` (the SessionEnd auto-stop) calls the daemon even when the CLI can't find its own daemon build for the build header. The lookup failure used to throw before the request, and the error was dropped, so the stop did nothing and exited 0. It now sends no header, and any daemon error other than "not running" is printed.
23
+
3
24
  ## 0.94.2
4
25
 
5
26
  ### Patch Changes
@@ -59,7 +59,7 @@ export declare function isPlainChain(cmd: string): boolean;
59
59
  * so every part runs under the temp HOME (`with-temp-home a && b` wraps only `a`) and a `{ …; }`
60
60
  * group is not a syntax error (SW-660).
61
61
  */
62
- export declare function wrappedTestCommand(tempHome: string, test: string, lint?: string): string;
62
+ export declare function wrappedTestCommand(tempHome: string, test: string, lint?: string, repo?: string): string;
63
63
  /**
64
64
  * How to exercise a change to one service when it has no URL to hit.
65
65
  *
@@ -126,13 +126,15 @@ export function isPlainChain(cmd) {
126
126
  * so every part runs under the temp HOME (`with-temp-home a && b` wraps only `a`) and a `{ …; }`
127
127
  * group is not a syntax error (SW-660).
128
128
  */
129
- export function wrappedTestCommand(tempHome, test, lint) {
129
+ export function wrappedTestCommand(tempHome, test, lint, repo) {
130
130
  const full = lint ? `${lint} && ${test}` : test;
131
131
  if (!tempHome)
132
132
  return full;
133
+ // SW-652: from *repo*'s worktree (<ws>/<repo>; tempHome is <ws>/.werkmeister/bin/…), whatever the shell's cwd.
134
+ const wrapper = repo ? `${tempHome} --cwd ${path.resolve(tempHome, "../../..", repo)}` : tempHome;
133
135
  if (isPlainChain(full) && !full.includes("&&"))
134
- return `${tempHome} ${full}`;
135
- return `${tempHome} sh -c '${full.split("'").join(`'\\''`)}'`;
136
+ return `${wrapper} ${full}`;
137
+ return `${wrapper} sh -c '${full.split("'").join(`'\\''`)}'`;
136
138
  }
137
139
  /**
138
140
  * How to exercise a change to one service when it has no URL to hit.
package/dist/caddy.js CHANGED
@@ -7,7 +7,7 @@
7
7
  import * as fs from "node:fs";
8
8
  import { Colors } from "./colors.js";
9
9
  import { stopOrRestart } from "./compose.js";
10
- import { composeInvocation, INFRA_PROJECT } from "./compose_infra.js";
10
+ import { composeInvocation, INFRA_PROJECT, warnStaleInfra } from "./compose_infra.js";
11
11
  import { sharedProxySkipReason, stateInfraRoot } from "./config.js";
12
12
  import { copyFileToContainer, execCapture, projectContainers } from "./docker.js";
13
13
  import { ProcError, run } from "./proc.js";
@@ -297,6 +297,8 @@ export async function reloadCaddy() {
297
297
  info(`Caddy reload skipped (${skip})`);
298
298
  return true;
299
299
  }
300
+ // A reload only copies the Caddyfile: it can't fix a container still mounting a moved checkout (SW-610).
301
+ await warnStaleInfra();
300
302
  const hostCaddyfile = `${stateInfraRoot()}/proxy/Caddyfile`;
301
303
  info("Copying Caddyfile into Caddy container...");
302
304
  if (!(await cpCaddyfileToContainer(hostCaddyfile))) {
@@ -11,6 +11,7 @@
11
11
  * all call this, and `infra.ts` already imports `k8s.ts`, so putting it in
12
12
  * `infra.ts` would make a cycle.
13
13
  */
14
+ import type Dockerode from "dockerode";
14
15
  /** The Compose project name for shared infra (shared-infra.yml's `name:`). */
15
16
  export declare const INFRA_PROJECT = "w9r-infra";
16
17
  /**
@@ -31,3 +32,34 @@ export declare function composeInvocation(): {
31
32
  env: NodeJS.ProcessEnv;
32
33
  cwd: string;
33
34
  };
35
+ /** An infra container left over from another checkout (SW-610). */
36
+ export interface StaleInfraContainer {
37
+ name: string;
38
+ service: string;
39
+ reason: string;
40
+ }
41
+ /**
42
+ * Why *c* no longer matches the shipped compose file at *composeFile*, or null.
43
+ * Compose stamps the files it ran with; after a checkout moves, a container made
44
+ * from the old path keeps its relative bind mounts (the Caddy picker UI) pointed
45
+ * there, and `feature up` / `proxy-reload` never recreate it. The label, not the
46
+ * bind sources: a missing source comes back as an empty dir on restart, and from
47
+ * a container the host's paths don't exist at all.
48
+ */
49
+ export declare function staleInfraReason(c: Pick<Dockerode.ContainerInfo, "Labels">, composeFile: string): string | null;
50
+ /**
51
+ * The shared-infra containers {@link staleInfraReason} flags. Never throws: empty when
52
+ * docker is unreachable or there is no machine config to say where the compose file is.
53
+ */
54
+ export declare function staleInfraContainers(): Promise<StaleInfraContainer[]>;
55
+ /** One warning per stale infra container, naming the command that recreates it. */
56
+ export declare function warnStaleInfra(): Promise<void>;
57
+ /**
58
+ * Split *stale* into the services `up` can recreate (those in *started*, this run's list)
59
+ * and leftovers whose service this checkout's file no longer has: naming one to
60
+ * `compose up` fails every run, or turns on a profile that is off.
61
+ */
62
+ export declare function recreatePlan(stale: StaleInfraContainer[], started: string[]): {
63
+ recreate: string[];
64
+ leftover: StaleInfraContainer[];
65
+ };
@@ -14,8 +14,11 @@
14
14
  import * as fs from "node:fs";
15
15
  import * as path from "node:path";
16
16
  import { baselineOverridePath } from "./baseline.js";
17
- import { infraRoot, loadConfig, stateInfraRoot } from "./config.js";
17
+ import { infraRoot, isFixture, loadConfig, stateInfraRoot } from "./config.js";
18
+ import { docker } from "./docker.js";
19
+ import { insideContainer } from "./global_config.js";
18
20
  import { generateK8sForwards, overrideFilePath } from "./k8s_forwards.js";
21
+ import { warn } from "./reporter.js";
19
22
  /** The Compose project name for shared infra (shared-infra.yml's `name:`). */
20
23
  export const INFRA_PROJECT = "w9r-infra";
21
24
  /**
@@ -73,3 +76,62 @@ export function composeInvocation() {
73
76
  cwd: path.dirname(stateInfraRoot()),
74
77
  };
75
78
  }
79
+ /**
80
+ * Why *c* no longer matches the shipped compose file at *composeFile*, or null.
81
+ * Compose stamps the files it ran with; after a checkout moves, a container made
82
+ * from the old path keeps its relative bind mounts (the Caddy picker UI) pointed
83
+ * there, and `feature up` / `proxy-reload` never recreate it. The label, not the
84
+ * bind sources: a missing source comes back as an empty dir on restart, and from
85
+ * a container the host's paths don't exist at all.
86
+ */
87
+ export function staleInfraReason(c, composeFile) {
88
+ const from = c.Labels?.["com.docker.compose.project.config_files"]?.split(",")[0];
89
+ return from && path.resolve(from) !== path.resolve(composeFile) ? `created from ${from}` : null;
90
+ }
91
+ /**
92
+ * The shared-infra containers {@link staleInfraReason} flags. Never throws: empty when
93
+ * docker is unreachable or there is no machine config to say where the compose file is.
94
+ */
95
+ export async function staleInfraContainers() {
96
+ // A workspace container's checkout is /app, so every host-made label differs, and a
97
+ // recreate from there would mount /app paths the host lacks (SW-554). Fixtures never start infra.
98
+ if (insideContainer() && !isFixture())
99
+ return [];
100
+ let list;
101
+ let composeFile;
102
+ try {
103
+ list = await docker().listContainers({
104
+ all: true,
105
+ filters: { label: [`com.docker.compose.project=${INFRA_PROJECT}`] },
106
+ });
107
+ composeFile = composeInvocation().argv[3];
108
+ }
109
+ catch {
110
+ return [];
111
+ }
112
+ return list.flatMap((c) => {
113
+ const reason = staleInfraReason(c, composeFile);
114
+ const name = c.Names?.[0]?.replace(/^\//, "") ?? c.Id.slice(0, 12);
115
+ return reason
116
+ ? [{ name, service: c.Labels?.["com.docker.compose.service"] ?? "", reason }]
117
+ : [];
118
+ });
119
+ }
120
+ /** One warning per stale infra container, naming the command that recreates it. */
121
+ export async function warnStaleInfra() {
122
+ for (const s of await staleInfraContainers()) {
123
+ warn(`${s.name} was ${s.reason}, not this checkout: run \`werkmeister infra up\` to recreate it`);
124
+ }
125
+ }
126
+ /**
127
+ * Split *stale* into the services `up` can recreate (those in *started*, this run's list)
128
+ * and leftovers whose service this checkout's file no longer has: naming one to
129
+ * `compose up` fails every run, or turns on a profile that is off.
130
+ */
131
+ export function recreatePlan(stale, started) {
132
+ const known = stale.filter((s) => started.includes(s.service));
133
+ return {
134
+ recreate: [...new Set(known.map((s) => s.service))],
135
+ leftover: stale.filter((s) => !started.includes(s.service)),
136
+ };
137
+ }
@@ -173,6 +173,15 @@ let staleWarned = false;
173
173
  export function expectDaemonBuild(get) {
174
174
  expectedBuild = get;
175
175
  }
176
+ // The header is a hint: a lookup that throws (no checkout to find, SW-718) sends none rather than dropping the call.
177
+ function buildToSend() {
178
+ try {
179
+ return expectedBuild?.() ?? null;
180
+ }
181
+ catch {
182
+ return null;
183
+ }
184
+ }
176
185
  function checkBuild(onDisk, res) {
177
186
  const loaded = res.headers.get(BUILD_HEADER);
178
187
  if (staleWarned || !onDisk || !loaded || loaded === onDisk)
@@ -241,7 +250,7 @@ export async function daemonStatus() {
241
250
  */
242
251
  export async function callTool(name, args = {}, opts = {}) {
243
252
  const timeout = AbortSignal.timeout(opts.timeoutMs ?? 120_000);
244
- const build = expectedBuild?.() ?? null;
253
+ const build = buildToSend();
245
254
  const res = await send(`${daemonUrl()}/api/tool`, {
246
255
  method: "POST",
247
256
  headers: {
@@ -44,6 +44,8 @@ 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
+ /** With `fragmentChange`: hold the branch's fragment back until `applyFragmentChange`, so a `workspace init` run first renders compose.yml from the base fragment and `pr gate` sees the branch settings as changed (SW-817). */
48
+ staleCompose?: boolean;
47
49
  /** 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
50
  changeBase?: string;
49
51
  changeBranch?: string;
@@ -85,6 +87,8 @@ export interface Fixture {
85
87
  repo: string;
86
88
  ghLog: string;
87
89
  dockerLog: string;
90
+ /** With `staleCompose`: commit the branch's held-back fragment (SW-817). */
91
+ applyFragmentChange?: () => void;
88
92
  /** What a process needs to run against the fixture, HOME (`<root>/home`, empty) included. */
89
93
  env: Record<string, string>;
90
94
  }
@@ -122,7 +122,9 @@ export function seedFixture(root, opts = {}) {
122
122
  const repos = opts.repos ?? [{ name: "app" }];
123
123
  write(path.join(root, "services.yaml"), opts.services ?? SERVICES);
124
124
  write(path.join(root, "ports.yaml"), PORTS);
125
- const configFile = path.join(root, "config.yaml");
125
+ // At the temp HOME's default path, so `machine migrate` treats it as the home it is (SW-581).
126
+ const home = path.join(root, "home");
127
+ const configFile = path.join(dotDir(home), "config.yaml");
126
128
  write(configFile, `version: 1
127
129
  paths:
128
130
  repos_root: ${root}/repos
@@ -156,6 +158,7 @@ ${githubProject(repos.map((r) => r.name))}${opts.config ? YAML.stringify(opts.co
156
158
  // status goes in verbatim, so a brief can try the forms people write, comments included (SW-549).
157
159
  const { status = "approved", ...prFields } = opts.prFields ?? {};
158
160
  const extra = Object.keys(prFields).length ? YAML.stringify(prFields) : "";
161
+ let applyFragmentChange;
159
162
  for (const { name, change } of repos) {
160
163
  // Ends in owner/repo.git so originSlug matches the PR file's repo: (SW-381).
161
164
  const remote = path.join(root, "remotes", "o", `${name}.git`);
@@ -193,13 +196,18 @@ ${githubProject(repos.map((r) => r.name))}${opts.config ? YAML.stringify(opts.co
193
196
  git(source, "push", "-q", "origin", "HEAD:main");
194
197
  }
195
198
  git(source, "switch", "-q", "-c", "fixture-source");
196
- if (changed.length) {
197
- if (change)
198
- write(path.join(repo, change), opts.changeBranch ?? "changed\n");
199
- if (frag !== undefined)
199
+ const held = opts.staleCompose && frag !== undefined;
200
+ if (change)
201
+ write(path.join(repo, change), opts.changeBranch ?? "changed\n");
202
+ if (frag !== undefined && !held)
203
+ write(path.join(repo, FRAGMENT_FILE), frag);
204
+ if (change || (frag !== undefined && !held))
205
+ git(repo, "commit", "-q", "-am", `change ${changed.filter((f) => !held || f !== FRAGMENT_FILE).join(", ")}`);
206
+ if (held)
207
+ applyFragmentChange = () => {
200
208
  write(path.join(repo, FRAGMENT_FILE), frag);
201
- git(repo, "commit", "-q", "-am", `change ${changed.join(", ")}`);
202
- }
209
+ git(repo, "commit", "-q", "-am", `change ${FRAGMENT_FILE}`);
210
+ };
203
211
  if (opts.prFile && changed.length)
204
212
  write(path.join(notes, `pr-${name}.md`), `---\nrepo: o/${name}\nbranch: ${FIXTURE_BRANCH}\nbase: main\nstatus: ${status}\n${extra}---\n# feat: fixture change\n\n${PASS}`);
205
213
  }
@@ -259,8 +267,7 @@ ${githubProject(repos.map((r) => r.name))}${opts.config ? YAML.stringify(opts.co
259
267
  fs.mkdirSync(ws, { recursive: true });
260
268
  return [c.feature, ws, c.startedAt, c.memory, c.nanoCpus].join("\t");
261
269
  });
262
- const home = path.join(root, "home");
263
- fs.mkdirSync(home);
270
+ fs.mkdirSync(home, { recursive: true });
264
271
  const fakes = writeFakes(path.join(root, "bin"), {
265
272
  prUrl: `https://github.com/${FIXTURE_REPO_SLUG}/pull/1`,
266
273
  running: opts.running ?? [],
@@ -272,6 +279,7 @@ ${githubProject(repos.map((r) => r.name))}${opts.config ? YAML.stringify(opts.co
272
279
  });
273
280
  return {
274
281
  root,
282
+ applyFragmentChange,
275
283
  configFile,
276
284
  workspace,
277
285
  repo: path.join(workspace, repos[0].name),
@@ -320,7 +328,7 @@ const SCRIPT = `#!/bin/sh
320
328
  # Generated by \`werkmeister workspace init\` (SW-292); rerun it to regenerate.
321
329
  # Runs this workspace's own built werkmeister CLI against a seeded fixture workspace, removed on exit:
322
330
  # temp HOME and registry, a local bare origin, logging fakes for gh and docker, dead Docker and daemon.
323
- # usage: with-fixture-workspace [--no-wait] [--gate] [--bare] [--daemon] [--exec-runs] [--merged] [--behind] [--slots-full] [--running <file>] [--queue <feature>[,<feature>]... | --queue <feature>:<waitedMin>[:<service>,...]]... [--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>]...
331
+ # usage: with-fixture-workspace [--no-wait] [--gate] [--bare] [--daemon] [--exec-runs] [--merged] [--behind] [--slots-full] [--running <file>] [--queue <feature>[,<feature>]... | --queue <feature>:<waitedMin>[:<service>,...]]... [--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>] [--stale-compose] [--print <file>]... <werkmeister args> [--then <werkmeister args>]...
324
332
  # It only ever runs that CLI, never another command, so one allow rule can cover it (SW-172, SW-231);
325
333
  # --exec-runs, given first, also runs the registry's rows on the host, so the workspace asks before it (SW-473).
326
334
  ws=$(cd "$(dirname "$0")/../.." && pwd -P) || exit 1
@@ -267,7 +267,7 @@ function testCommandLine(feature, svc, servicesConfig, archetypes, lint, tempHom
267
267
  : `- \`${svc}\`: no test command registered (add \`test:\` to its registry entry)`;
268
268
  }
269
269
  /** SW-720: in sw-700 host `node`, a compound line and `docker exec … node <script>` were each denied before this form ran. */
270
- const PROBE_FORM = (tempHome) => `A one-off probe is a \`node --test\` file, run as \`${tempHome} --no-wait node --test <file>\` (in the service's container, after its \`docker exec -w <dir> <container>\`, when the host has no node_modules); never host \`node <script>\`, a compound shell line or \`docker exec … node <script>\`. That form asks each time and is never pre-approved, since it runs any file (SW-510).`;
270
+ const PROBE_FORM = (tempHome) => `A one-off probe is a \`node --test\` file, run as \`${tempHome} --no-wait node --test <file>\` (in the service's container, after its \`docker exec -w <dir> <container>\`, when the host has no node_modules); never host \`node <script>\`, a compound shell line or \`docker exec … node <script>\`. That form, with no \`--cwd\` (pass the file's path instead), asks each time and is never pre-approved, since it runs any file (SW-510); with \`--cwd\` it matches no rule and auto mode denies it (SW-652).`;
271
271
  // SW-765: sw-753's spec planned to delete turbo cache entries, not knowing the cache is one volume every workspace shares.
272
272
  function sharedCachesLine(caches) {
273
273
  const entries = Object.entries(caches);
@@ -342,7 +342,7 @@ export function buildSandboxContextMd(feature, slot, portStart, portEnd, localSe
342
342
  const testCell = (r) => {
343
343
  if (!r.test)
344
344
  return "—";
345
- return `\`${wrappedTestCommand(tempHome, r.test, lintOf(r.repo))}\``;
345
+ return `\`${wrappedTestCommand(tempHome, r.test, lintOf(r.repo), r.repo)}\``;
346
346
  };
347
347
  // SW-705: the gate tests every service a change reaches, so the table lists the candidates' whole repos.
348
348
  // Each service's own `repo:`, not repos.<repo>.services: only registry sync fills that list.
@@ -532,7 +532,7 @@ How to exercise a change to each service in this workspace.${extraRows
532
532
  : ""}${onDemand.length
533
533
  ? ` A plain \`werkmeister feature up\` skips the on-demand ones, ${onDemand.map((s) => `\`${s}\``).join(", ")}: start one with \`werkmeister feature up --service <name>\`.`
534
534
  : ""}${tempHome
535
- ? ` Each test command runs through \`.werkmeister/bin/with-temp-home\`, which gives it a fresh temporary HOME and deletes it on exit: never hand-roll \`HOME=…\`. Start every exercise command with the script itself, never with env assignments or a \`cd\`, so one permission rule matches it: \`${tempHome} <test command>\`. A command that needs an env var takes it after the script (\`${tempHome} env WERKMEISTER_ROOT=… <cmd>\`); no rule pre-approves that form, so it asks. Put \`--no-wait\` first (\`${tempHome} --no-wait <cmd>\`) to skip its host-load and free-memory wait; the allow rules below cover that form too. That wait lasts up to 90 s; if load or memory is still over its limit then, the script exits 75 without running the command (retry later). It prints only on stderr, so a foreground call shows nothing until it ends and its only child is \`werkmeister internal wait-load\`: that is the wait, not a hang. The allow rule that covers them is \`Bash(${tempHome} <test command>:*)\` for each test command below: run those for a test without a prompt. A test command of more than one command (an \`&&\` chain, a \`{ …; }\` group, \`||\`, \`;\` or a pipe) is shown as \`${tempHome} sh -c '…'\`, so every part runs under the temp HOME, and its rule allows that exact line: run it as shown, with no extra arguments. ${PROBE_FORM(tempHome)} The script alone is never allowed either, since it runs any command. The temp HOME only keeps a run from writing to the real one by accident; it is not an isolation boundary. A pre-approved test command or built CLI still runs whatever the worktree holds, a test written in this run included, and that code can reach absolute paths, the caller's env, the network, docker and gh (SW-522).`
535
+ ? ` Each test command runs through \`.werkmeister/bin/with-temp-home\`, which gives it a fresh temporary HOME and deletes it on exit: never hand-roll \`HOME=…\`. Start every exercise command with the script itself, never with env assignments or a \`cd\`, so one permission rule matches it: \`${tempHome} --cwd <worktree> <test command>\`. Its \`--cwd <worktree>\` runs the command from that service's worktree, whatever the shell's cwd, so it works from the workspace root too (SW-652). A command that needs an env var takes it after the script (\`${tempHome} env WERKMEISTER_ROOT=… <cmd>\`); no rule pre-approves that form, so it asks. Put \`--no-wait\` first (\`${tempHome} --no-wait <cmd>\`) to skip its host-load and free-memory wait; the allow rules below cover that form too. That wait lasts up to 90 s; if load or memory is still over its limit then, the script exits 75 without running the command (retry later). It prints only on stderr, so a foreground call shows nothing until it ends and its only child is \`werkmeister internal wait-load\`: that is the wait, not a hang. The allow rule that covers them is \`Bash(${tempHome} --cwd <worktree> <test command>:*)\` for each test command below: run those for a test without a prompt. A test command of more than one command (an \`&&\` chain, a \`{ …; }\` group, \`||\`, \`;\` or a pipe) is shown as \`${tempHome} --cwd <worktree> sh -c '…'\`, so every part runs under the temp HOME, and its rule allows that exact line: run it as shown, with no extra arguments. ${PROBE_FORM(tempHome)} The script alone is never allowed either, since it runs any command. The temp HOME only keeps a run from writing to the real one by accident; it is not an isolation boundary. A pre-approved test command or built CLI still runs whatever the worktree holds, a test written in this run included, and that code can reach absolute paths, the caller's env, the network, docker and gh (SW-522).`
536
536
  : ""}${linted
537
537
  ? " A test command starting with `<lint> &&` first runs the repo's lint, the same command the PR gate's lint row runs, so a format error fails here, before the tests, and not first at `werkmeister pr open`."
538
538
  : ""} ${HOST_SCRIPT_RULE}
@@ -443,10 +443,15 @@ hostServices = [], reposConfig = {}) {
443
443
  }
444
444
  if (!tempHome)
445
445
  continue;
446
- const lint = reposConfig[String(servicesConfig[svc]?.["repo"] ?? "")]?.lint;
447
- const wrapped = wrappedTestCommand(tempHome, cmd, lint);
448
- // Exact for an `sh -c` line: a prefix would let `; <anything>` ride after the quote.
449
- rules.push(wrapped.startsWith(`${tempHome} sh -c '`) ? `Bash(${wrapped})` : `Bash(${wrapped}:*)`);
446
+ const repo = servicesConfig[svc]?.["repo"];
447
+ const lint = reposConfig[String(repo ?? "")]?.lint;
448
+ const wrapped = wrappedTestCommand(tempHome, cmd, lint, repo ? String(repo) : undefined);
449
+ // Exact for an `sh -c` line: a prefix would let `; <anything>` ride after the quote. Past any --cwd (SW-652).
450
+ const shC = wrapped
451
+ .slice(tempHome.length)
452
+ .replace(/^ --cwd \S+/, "")
453
+ .startsWith(" sh -c '");
454
+ rules.push(shC ? `Bash(${wrapped})` : `Bash(${wrapped}:*)`);
450
455
  }
451
456
  if (tempHome)
452
457
  for (const cli of builtClis)
package/dist/infra.js CHANGED
@@ -21,10 +21,11 @@ import * as net from "node:net";
21
21
  import * as os from "node:os";
22
22
  import * as path from "node:path";
23
23
  import { baselineSpecs, generateBaselineOverride } from "./baseline.js";
24
+ import { CADDY_CONTAINER } from "./caddy.js";
24
25
  import { stopOrRestart, takeDownProject } from "./compose.js";
25
- import { composeInvocation, INFRA_PROJECT, infraProfiles, LEGACY_INFRA_PROJECT, } from "./compose_infra.js";
26
+ import { composeInvocation, INFRA_PROJECT, infraProfiles, LEGACY_INFRA_PROJECT, recreatePlan, staleInfraContainers, } from "./compose_infra.js";
26
27
  import { isFixture, sandboxHome } from "./config.js";
27
- import { projectContainers } from "./docker.js";
28
+ import { execCapture, projectContainers } from "./docker.js";
28
29
  import { generateCaddyfile } from "./generate.js";
29
30
  import { configureGitHooksPath } from "./git_hooks.js";
30
31
  import { checkPortForwardHealth, ensurePortForwardsHealthy, refreshKubeconfig } from "./k8s.js";
@@ -145,13 +146,13 @@ export async function startSharedInfra(signal) {
145
146
  return false;
146
147
  }
147
148
  takeDownProject(LEGACY_INFRA_PROJECT, "the pre-rename shared infra");
148
- const services = [
149
+ const started = [
149
150
  "k8s-forwards",
150
151
  "caddy",
151
152
  ...infraProfiles(),
152
153
  ...baselineSpecs().map((s) => `baseline-${s.service}`),
153
- ].join(", ");
154
- info(`Starting shared infrastructure (${services})...`);
154
+ ];
155
+ info(`Starting shared infrastructure (${started.join(", ")})...`);
155
156
  try {
156
157
  const result = await runAsync([...argv, "up", "-d", "--build"], {
157
158
  capture: true,
@@ -163,6 +164,20 @@ export async function startSharedInfra(signal) {
163
164
  error(`docker compose failed:\n${result.stderr.trim()}`);
164
165
  return false;
165
166
  }
167
+ // `up` recreates a container whose resolved binds changed, not one whose only drift is
168
+ // the compose files it was made from (w9r-k8s-forwards after a checkout move, SW-610).
169
+ const { recreate, leftover } = recreatePlan(await staleInfraContainers(), started);
170
+ for (const s of leftover) {
171
+ warn(`${s.name} was ${s.reason}, and this checkout has no such service: remove it with \`docker rm -f ${s.name}\``);
172
+ }
173
+ if (recreate.length) {
174
+ info(`Recreating ${recreate.join(", ")} from this checkout...`);
175
+ const again = await runAsync([...argv, "up", "-d", "--no-deps", "--force-recreate", ...recreate], { capture: true, signal, env, cwd });
176
+ if (again.status !== 0) {
177
+ error(`docker compose failed:\n${again.stderr.trim()}`);
178
+ return false;
179
+ }
180
+ }
166
181
  success("Shared infrastructure started");
167
182
  return true;
168
183
  }
@@ -178,6 +193,8 @@ export async function startSharedInfra(signal) {
178
193
  throw e;
179
194
  }
180
195
  }
196
+ /** The page Caddy serves for `/__werkmeister` (generate.ts's `root * /werkmeister/proxy/ui`). */
197
+ const PICKER_PAGE = "/werkmeister/proxy/ui/index.html";
181
198
  function checkPort(host, port, timeoutSec) {
182
199
  return new Promise((resolve) => {
183
200
  const sock = net.createConnection({ host, port });
@@ -209,6 +226,11 @@ async function checkInfraHealth() {
209
226
  for (const c of (await projectContainers(INFRA_PROJECT, undefined, { all: false })) ?? []) {
210
227
  services[c.service || c.name] = c.health === "healthy" || (c.state === "running" && !c.health);
211
228
  }
229
+ // Running is not serving: an empty picker mount 404s /__werkmeister on every host (SW-610).
230
+ if (services["caddy"]) {
231
+ const picker = await execCapture(CADDY_CONTAINER, ["test", "-s", PICKER_PAGE]).catch(() => null);
232
+ services["caddy"] = picker?.exitCode === 0;
233
+ }
212
234
  // Fallback: check key ports if the daemon listed nothing
213
235
  if (!Object.keys(services).length) {
214
236
  const portChecks = [
package/dist/migrate.js CHANGED
@@ -14,7 +14,7 @@ import * as os from "node:os";
14
14
  import * as path from "node:path";
15
15
  import { parse as parseYaml } from "yaml";
16
16
  import { COMPOSE_FILE, LEGACY_COMPOSE_FILE } from "./compose_file.js";
17
- import { configPath, envVar, expandUser, sandboxHome, servicesLocalYamlPath, servicesYamlPath, workspacesRoot, } from "./config.js";
17
+ import { configPath, envVar, expandUser, isFixture, sandboxHome, servicesLocalYamlPath, servicesYamlPath, workspacesRoot, } from "./config.js";
18
18
  import { docker } from "./docker.js";
19
19
  import { DOT_DIR, dotDir } from "./dot_dir.js";
20
20
  import { writeFixtureWrapper } from "./fixture_workspace.js";
@@ -113,7 +113,8 @@ export async function migrate(opts = {}) {
113
113
  const legacy = path.join(home, LEGACY_DOT_DIR);
114
114
  const target = path.join(home, DOT_DIR);
115
115
  const would = (did, will) => (checkOnly ? will : did);
116
- if (envVar("CONFIG_FILE")) {
116
+ // One that names the default path (the fixture's, SW-581) moves nothing elsewhere, so migrate runs.
117
+ if (envVar("CONFIG_FILE") && path.resolve(configPath()) !== path.join(target, "config.yaml")) {
117
118
  return [
118
119
  {
119
120
  label: "tool home",
@@ -227,9 +228,13 @@ export async function migrate(opts = {}) {
227
228
  steps.push(...syncRegistry());
228
229
  }
229
230
  // Its log path is the home; in --check before the move, `current` is judged against the old one.
230
- const prWatch = prWatchScheduleState(opts.prWatch);
231
231
  const prLabel = "pr-watch schedule";
232
- if (!prWatch.installed) {
232
+ // crontab isn't scoped by HOME: a fixture run must not rewrite the caller's real one (SW-581).
233
+ const prWatch = isFixture() ? undefined : prWatchScheduleState(opts.prWatch);
234
+ if (!prWatch) {
235
+ steps.push({ label: prLabel, ok: true, detail: "skipped in the fixture" });
236
+ }
237
+ else if (!prWatch.installed) {
233
238
  steps.push({ label: prLabel, ok: true, detail: "not installed" });
234
239
  }
235
240
  else if (prWatch.current && !(checkOnly && moving)) {
@@ -760,7 +760,7 @@ testsOnly = false) {
760
760
  const why = res.code ? retryIf(res) : null;
761
761
  if (why) {
762
762
  // Only before this one retry: the gate itself never waits on load (SW-542).
763
- const waited = await waitForHostLoadNow(deps, undefined, "the gate's retry");
763
+ const { note: waited } = await waitForHostLoadNow(deps, undefined, "the gate's retry");
764
764
  res = await exec();
765
765
  lines[0] = `${cmd} → exit ${res.code}, retried once after ${why}${waited ? `; ${waited}` : ""}`;
766
766
  }
@@ -71,16 +71,22 @@ export declare const readHostLoad: () => {
71
71
  load: number[];
72
72
  cores: number;
73
73
  };
74
+ /** What with-temp-home's wait did: *spent* means a limit was still over when it gave up (SW-716). */
75
+ export interface HostLoadWait {
76
+ spent: boolean;
77
+ note: string;
78
+ }
74
79
  /**
75
80
  * The wait of `werkmeister internal wait-load`, which the generated with-temp-home runs first (SW-224):
76
81
  * up to 90 s for the 1-minute load to fall under the limit and free memory to rise over its own (SW-620),
77
- * saying so up front and printing progress each minute (SW-262); the note for the wrapper's stderr, or "".
78
- * A spent wait's note starts "ran with". The gate stopped waiting in SW-542.
82
+ * saying so up front and printing progress each minute (SW-262). Returns the note for the wrapper's stderr ("" when
83
+ * it did not wait) and whether the wait is *spent* with a limit still over (SW-716).
84
+ * The gate stopped waiting in SW-542.
79
85
  * Load not on macOS: its loadavg counts idle daemons in R state (450-550 on a quiet host) and never the
80
86
  * Linux VM that runs the tests, so it is no signal to wait on (SW-556). Its memory is: Claude Code
81
87
  * stops an idle background shell when the Mac runs low (SW-620).
82
88
  */
83
- export declare function waitForHostLoadNow(deps?: HostLoadDeps, platform?: NodeJS.Platform, before?: string): Promise<string>;
89
+ export declare function waitForHostLoadNow(deps?: HostLoadDeps, platform?: NodeJS.Platform, before?: string): Promise<HostLoadWait>;
84
90
  /**
85
91
  * Before compose starts a setup one-shot among *services* (undefined: what a whole `up` starts),
86
92
  * wait on host load and free memory as with-temp-home does, and fail once the wait is spent (SW-630,
@@ -177,16 +177,18 @@ const minutes = (ms) => Number((ms / 60_000).toFixed(1));
177
177
  /**
178
178
  * The wait of `werkmeister internal wait-load`, which the generated with-temp-home runs first (SW-224):
179
179
  * up to 90 s for the 1-minute load to fall under the limit and free memory to rise over its own (SW-620),
180
- * saying so up front and printing progress each minute (SW-262); the note for the wrapper's stderr, or "".
181
- * A spent wait's note starts "ran with". The gate stopped waiting in SW-542.
180
+ * saying so up front and printing progress each minute (SW-262). Returns the note for the wrapper's stderr ("" when
181
+ * it did not wait) and whether the wait is *spent* with a limit still over (SW-716).
182
+ * The gate stopped waiting in SW-542.
182
183
  * Load not on macOS: its loadavg counts idle daemons in R state (450-550 on a quiet host) and never the
183
184
  * Linux VM that runs the tests, so it is no signal to wait on (SW-556). Its memory is: Claude Code
184
185
  * stops an idle background shell when the Mac runs low (SW-620).
185
186
  */
186
187
  export async function waitForHostLoadNow(deps = realHostLoad, platform = process.platform, before = "with-temp-home; --no-wait skips") {
187
188
  // WERKMEISTER_NO_WAIT skips it inside the command too, not only in with-temp-home's shell (SW-425).
189
+ const none = { spent: false, note: "" };
188
190
  if (envVar("NO_WAIT"))
189
- return "";
191
+ return none;
190
192
  const read = () => {
191
193
  const { load, cores } = deps.hostLoad();
192
194
  const limit = platform === "darwin" ? 0 : hostLoadLimit(cores);
@@ -199,7 +201,7 @@ export async function waitForHostLoadNow(deps = realHostLoad, platform = process
199
201
  };
200
202
  let now = read();
201
203
  if (!now.loadOver && !now.memory)
202
- return "";
204
+ return none;
203
205
  const waitedFor = [now.loadOver && "host load", now.memory && "free memory"]
204
206
  .filter(Boolean)
205
207
  .join(" and ");
@@ -219,11 +221,14 @@ export async function waitForHostLoadNow(deps = realHostLoad, platform = process
219
221
  await deps.sleep(LOAD_POLL_MS);
220
222
  now = read();
221
223
  if (!now.loadOver && !now.memory)
222
- return `waited ${waited / 1000} s for ${waitedFor}`;
224
+ return { spent: false, note: `waited ${waited / 1000} s for ${waitedFor}` };
223
225
  if (waited % LOAD_PROGRESS_MS === 0 && waited < WRAPPER_LOAD_WAIT_MS)
224
226
  info(`still waiting: ${state()}, ${waited / 1000} s so far, up to ${minutes(WRAPPER_LOAD_WAIT_MS - waited)} min left`);
225
227
  }
226
- return `ran with ${state()}; the ${minutes(WRAPPER_LOAD_WAIT_MS)} min host-load wait is spent`;
228
+ return {
229
+ spent: true,
230
+ note: `ran with ${state()}; the ${minutes(WRAPPER_LOAD_WAIT_MS)} min host-load wait is spent`,
231
+ };
227
232
  }
228
233
  /**
229
234
  * Before compose starts a setup one-shot among *services* (undefined: what a whole `up` starts),
@@ -240,8 +245,8 @@ export async function waitForSetupLoad(workspace, services, deps = realHostLoad,
240
245
  if (!setups.length)
241
246
  return;
242
247
  const what = setups.join(", ");
243
- const note = await waitForHostLoadNow(deps, platform, `starting ${what}; WERKMEISTER_NO_WAIT=1 skips`);
244
- if (!note.startsWith("ran with"))
248
+ const { spent, note } = await waitForHostLoadNow(deps, platform, `starting ${what}; WERKMEISTER_NO_WAIT=1 skips`);
249
+ if (!spent)
245
250
  return;
246
251
  const { load, cores } = deps.hostLoad();
247
252
  const limit = hostLoadLimit(cores);
@@ -4,7 +4,7 @@
4
4
  * hand-roll `HOME=$(mktemp -d) …` and none can forget it.
5
5
  */
6
6
  /** Also run inline in a container by the pr gate (SW-329). */
7
- export declare const TEMP_HOME_SCRIPT = "#!/bin/sh\n# Generated by `werkmeister workspace init` (SW-124); rerun it to regenerate.\n# Runs <cmd...> with HOME set to a fresh temporary directory, removed on exit,\n# so no test or CLI exercise reads or writes the real ~/.werkmeister.\n# --no-wait first does what WERKMEISTER_NO_WAIT=1 does, without an env assignment (SW-367),\n# and exports it, so a with-temp-home nested under it skips its wait too (SW-425).\n[ \"${1:-}\" != --no-wait ] || { export WERKMEISTER_NO_WAIT=1; shift; }\nno_wait=${WERKMEISTER_NO_WAIT:-}\n[ \"$#\" -gt 0 ] || { echo \"usage: with-temp-home [--no-wait] <cmd> [args...]\" >&2; exit 2; }\n# Wait like the pr gate while host load is over budget.host_load (SW-224), before HOME\n# changes so the real config's budget applies; no werkmeister on PATH, no wait.\n# In the background with a trap, so killing the wrapper ends the wait too (SW-456).\n[ -n \"$no_wait\" ] || ! command -v werkmeister >/dev/null 2>&1 || {\n # Trap before the fork: $! is empty until the job exists, so no signal can land between them.\n trap 'kill $! 2>/dev/null; exit 130' HUP INT TERM\n werkmeister internal wait-load >&2 &\n wait $!\n# 75: the wait is spent and load is still over, so running would pile on (SW-540); any other failure runs.\n} || { s=$?; [ \"$s\" -ne 75 ] || exit 75; }\ntmp=$(mktemp -d) || exit 1\n# os.tmpdir() scratch from the wrapped command goes with the temp HOME (SW-799).\nexport TMPDIR=\"$tmp\"\ntrap 'rm -rf \"$tmp\"' EXIT\ntrap 'exit 130' HUP INT TERM\n# Corepack keeps pnpm under HOME; without this a fresh HOME re-downloads it every run.\nexport COREPACK_HOME=\"${COREPACK_HOME:-$HOME/.cache/node/corepack}\"\n# OrbStack and Docker Desktop keep the compose plugin and context here (SW-285).\nexport DOCKER_CONFIG=\"${DOCKER_CONFIG:-$HOME/.docker}\"\n# A temp HOME isolates files, not the daemon: unreachable unless the caller sets it (SW-264).\nexport WERKMEISTER_HOST=\"${WERKMEISTER_HOST:-http://127.0.0.1:1}\"\n# An agent's shell inherits its Claude Code session's variables; CI has none (SW-332). CLAUDE_BIN stays.\nunset CLAUDECODE\nfor v in $(env | sed -n '/^CLAUDE_CODE_[A-Za-z0-9_]*=/s/=.*//p'); do unset \"$v\"; done\nHOME=$tmp \"$@\"\nstatus=$?\n# A failure under load reads as load (SW-209).\n[ \"$status\" -eq 0 ] || echo \"with-temp-home: exit $status; host load $(uptime | sed 's/.*load averages*: //; s/,//g') on $(getconf _NPROCESSORS_ONLN) cores\" >&2\nexit \"$status\"\n";
7
+ export declare const TEMP_HOME_SCRIPT = "#!/bin/sh\n# Generated by `werkmeister workspace init` (SW-124); rerun it to regenerate.\n# Runs <cmd...> with HOME set to a fresh temporary directory, removed on exit,\n# so no test or CLI exercise reads or writes the real ~/.werkmeister.\n# --no-wait first does what WERKMEISTER_NO_WAIT=1 does, without an env assignment (SW-367),\n# and exports it, so a with-temp-home nested under it skips its wait too (SW-425).\n[ \"${1:-}\" != --no-wait ] || { export WERKMEISTER_NO_WAIT=1; shift; }\nno_wait=${WERKMEISTER_NO_WAIT:-}\n# --cwd <dir> next runs the command there, whatever the shell's cwd, with no `cd` to break the allow rule (SW-652).\n# In the werkmeister container the worktree is also at /app, the only place its node_modules volume is mounted (SW-548).\nif [ \"${1:-}\" = --cwd ] && [ \"$#\" -ge 2 ]; then\n if [ /app -ef \"$2\" ]; then cd /app; else cd \"$2\"; fi || exit 1\n shift 2\nfi\n[ \"$#\" -gt 0 ] || { echo \"usage: with-temp-home [--no-wait] [--cwd <dir>] <cmd> [args...]\" >&2; exit 2; }\n# Wait like the pr gate while host load is over budget.host_load (SW-224), before HOME\n# changes so the real config's budget applies; no werkmeister on PATH, no wait.\n# In the background with a trap, so killing the wrapper ends the wait too (SW-456).\n[ -n \"$no_wait\" ] || ! command -v werkmeister >/dev/null 2>&1 || {\n # Trap before the fork: $! is empty until the job exists, so no signal can land between them.\n trap 'kill $! 2>/dev/null; exit 130' HUP INT TERM\n werkmeister internal wait-load >&2 &\n wait $!\n# 75: the wait is spent and load is still over, so running would pile on (SW-540); any other failure runs.\n} || { s=$?; [ \"$s\" -ne 75 ] || exit 75; }\ntmp=$(mktemp -d) || exit 1\n# os.tmpdir() scratch from the wrapped command goes with the temp HOME (SW-799); HOME = TMPDIR is also how a test entry knows the HOME is this temp one (SW-662).\nexport TMPDIR=\"$tmp\"\ntrap 'rm -rf \"$tmp\"' EXIT\ntrap 'exit 130' HUP INT TERM\n# Corepack keeps pnpm under HOME; without this a fresh HOME re-downloads it every run.\nexport COREPACK_HOME=\"${COREPACK_HOME:-$HOME/.cache/node/corepack}\"\n# OrbStack and Docker Desktop keep the compose plugin and context here (SW-285).\nexport DOCKER_CONFIG=\"${DOCKER_CONFIG:-$HOME/.docker}\"\n# A temp HOME isolates files, not the daemon: unreachable unless the caller sets it (SW-264). Refused, as a\n# stopped daemon is: fetch rejects :1 as a \"bad port\" before connecting (SW-743). A short retry, not the 15 s restart gap.\n# shortcut: 65535 is in macOS's ephemeral range, so a port-0 listener (another test's fake daemon) can hold it; bind-and-close a port (SW-708) if that flakes.\nexport WERKMEISTER_HOST=\"${WERKMEISTER_HOST:-http://127.0.0.1:65535}\"\nexport WERKMEISTER_DAEMON_RETRY_MS=\"${WERKMEISTER_DAEMON_RETRY_MS:-500}\"\n# An agent's shell inherits its Claude Code session's variables; CI has none (SW-332). CLAUDE_BIN stays.\nunset CLAUDECODE\nfor v in $(env | sed -n '/^CLAUDE_CODE_[A-Za-z0-9_]*=/s/=.*//p'); do unset \"$v\"; done\nHOME=$tmp \"$@\"\nstatus=$?\n# A failure under load reads as load (SW-209).\n[ \"$status\" -eq 0 ] || echo \"with-temp-home: exit $status; host load $(uptime | sed 's/.*load averages*: //; s/,//g') on $(getconf _NPROCESSORS_ONLN) cores\" >&2\nexit \"$status\"\n";
8
8
  export declare function tempHomeWrapper(workspaceRoot: string): string;
9
9
  /** Write the wrapper, executable, over any earlier copy; returns its path. */
10
10
  export declare function writeTempHomeWrapper(workspaceRoot: string): string;
package/dist/temp_home.js CHANGED
@@ -15,7 +15,13 @@ export const TEMP_HOME_SCRIPT = `#!/bin/sh
15
15
  # and exports it, so a with-temp-home nested under it skips its wait too (SW-425).
16
16
  [ "\${1:-}" != --no-wait ] || { export WERKMEISTER_NO_WAIT=1; shift; }
17
17
  no_wait=\${WERKMEISTER_NO_WAIT:-}
18
- [ "$#" -gt 0 ] || { echo "usage: with-temp-home [--no-wait] <cmd> [args...]" >&2; exit 2; }
18
+ # --cwd <dir> next runs the command there, whatever the shell's cwd, with no \`cd\` to break the allow rule (SW-652).
19
+ # In the werkmeister container the worktree is also at /app, the only place its node_modules volume is mounted (SW-548).
20
+ if [ "\${1:-}" = --cwd ] && [ "$#" -ge 2 ]; then
21
+ if [ /app -ef "$2" ]; then cd /app; else cd "$2"; fi || exit 1
22
+ shift 2
23
+ fi
24
+ [ "$#" -gt 0 ] || { echo "usage: with-temp-home [--no-wait] [--cwd <dir>] <cmd> [args...]" >&2; exit 2; }
19
25
  # Wait like the pr gate while host load is over budget.host_load (SW-224), before HOME
20
26
  # changes so the real config's budget applies; no werkmeister on PATH, no wait.
21
27
  # In the background with a trap, so killing the wrapper ends the wait too (SW-456).
@@ -27,7 +33,7 @@ no_wait=\${WERKMEISTER_NO_WAIT:-}
27
33
  # 75: the wait is spent and load is still over, so running would pile on (SW-540); any other failure runs.
28
34
  } || { s=$?; [ "$s" -ne 75 ] || exit 75; }
29
35
  tmp=$(mktemp -d) || exit 1
30
- # os.tmpdir() scratch from the wrapped command goes with the temp HOME (SW-799).
36
+ # os.tmpdir() scratch from the wrapped command goes with the temp HOME (SW-799); HOME = TMPDIR is also how a test entry knows the HOME is this temp one (SW-662).
31
37
  export TMPDIR="$tmp"
32
38
  trap 'rm -rf "$tmp"' EXIT
33
39
  trap 'exit 130' HUP INT TERM
@@ -35,8 +41,11 @@ trap 'exit 130' HUP INT TERM
35
41
  export COREPACK_HOME="\${COREPACK_HOME:-$HOME/.cache/node/corepack}"
36
42
  # OrbStack and Docker Desktop keep the compose plugin and context here (SW-285).
37
43
  export DOCKER_CONFIG="\${DOCKER_CONFIG:-$HOME/.docker}"
38
- # A temp HOME isolates files, not the daemon: unreachable unless the caller sets it (SW-264).
39
- export WERKMEISTER_HOST="\${WERKMEISTER_HOST:-http://127.0.0.1:1}"
44
+ # A temp HOME isolates files, not the daemon: unreachable unless the caller sets it (SW-264). Refused, as a
45
+ # stopped daemon is: fetch rejects :1 as a "bad port" before connecting (SW-743). A short retry, not the 15 s restart gap.
46
+ # shortcut: 65535 is in macOS's ephemeral range, so a port-0 listener (another test's fake daemon) can hold it; bind-and-close a port (SW-708) if that flakes.
47
+ export WERKMEISTER_HOST="\${WERKMEISTER_HOST:-http://127.0.0.1:65535}"
48
+ export WERKMEISTER_DAEMON_RETRY_MS="\${WERKMEISTER_DAEMON_RETRY_MS:-500}"
40
49
  # An agent's shell inherits its Claude Code session's variables; CI has none (SW-332). CLAUDE_BIN stays.
41
50
  unset CLAUDECODE
42
51
  for v in $(env | sed -n '/^CLAUDE_CODE_[A-Za-z0-9_]*=/s/=.*//p'); do unset "$v"; done
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "werkmeister-core",
3
- "version": "0.94.2",
3
+ "version": "0.94.4",
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.",
@@ -136,6 +136,7 @@
136
136
  "docs:links": "typedoc",
137
137
  "docs:sdk": "node ../../scripts/format-examples.mjs --check && typedoc --options typedoc.sdk.json",
138
138
  "test": "sh ./run-tests.sh",
139
- "test:changed": "node test-changed.mjs"
139
+ "test:changed": "node test-changed.mjs",
140
+ "test:no-match": "sh ../../scripts/require-temp-home.sh && unset GIT_DIR GIT_WORK_TREE GIT_COMMON_DIR && WERKMEISTER_GH_BIN=$PWD/test/no-gh.sh node --test --test-concurrency=3 --test-name-pattern=__nomatch__ test/*.test.mjs"
140
141
  }
141
142
  }