cursedops 0.10.6 → 0.10.7
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/README.md +1 -1
- package/package.json +1 -1
- package/src/roots.ts +77 -17
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ bun add cursedops
|
|
|
8
8
|
|
|
9
9
|
| subpath | what it is |
|
|
10
10
|
|---|---|
|
|
11
|
-
| `cursedops/roots` | finding a generation's roots, and a checkout's package root, without knowing a path — and the `cd` prefix of a printed command that RUNS when pasted (`repoCd`, 0.5.0) |
|
|
11
|
+
| `cursedops/roots` | finding a generation's roots, and a checkout's package root, without knowing a path — and the `cd` prefix of a printed command that RUNS when pasted (`repoCd`, 0.5.0); a worktree is followed to its primary from its `.git` file, once per directory, never a `git` per call (0.10.7) |
|
|
12
12
|
| `cursedops/paths` | the generation's whole-tree laws (`check-paths`, `check-doc-citations`, plus any `--also`) run over ONE repo, from a checkout or a worktree — and its `forge-paths` bin (0.5.0) |
|
|
13
13
|
| `cursedops/launchd` | installing, replacing and removing a macOS launchd user agent, and the port a LIVE job serves on (`livePort`, 0.5.0) |
|
|
14
14
|
| `cursedops/smoke` | the scaffolding of a deployed smoke — the ledger, the fetch, the DNS hint, the exit code — the one check no app owns (every address of a deployment serving the same built client), and since 0.5.0 its VERDICTS: the origin asked on loopback, the smoke's own environment, a network that lies about DNS, and a version that has settled |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cursedops",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.7",
|
|
4
4
|
"description": "The build-and-ops answers this generation's apps wrote independently and identically: finding a generation's roots — and printing a command that runs when pasted — without knowing a path, the generation's whole-tree laws run over one repo from a checkout or a worktree, macOS launchd agent install/replace/remove and the live port a job serves, the scaffolding and verdicts of a deployed smoke (origin probe, the smoke's own environment, a network that lies about DNS, a settled version), the static-serving helpers eight apps copied — the path-traversal guard among them — the API floor that keeps an unmatched /api/... from ever being answered with the app shell, the commit and dirty flag a checkout-served process reports, the Cloudflare Worker deploy toolkit four apps copied (the deploy sequence, exact-set secrets over a pipe, origin-first rollback, the curl edge fetch, the row-for-row D1 import proof, the billed-CPU tail check around a deploy's walk and smoke, and each app's worker:secrets and worker:smoke main as one function of its data), the relay a Worker fronts a Mac-bound app with (the Durable Object, the frames, the Mac's dialer and key rotation — lifted from station for roms — and the signed-in stage walk's skeleton and the relay app's whole worker:deploy), the Worker import-graph and await-port checks every Worker app's suite runs over its own source, and the public-surface ratchet three published libraries each carried a forked copy of. Mechanism only — no app knows its name from here. Bun, zero runtime dependencies (typescript is an optional peer, for public-surface only), ships source.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
package/src/roots.ts
CHANGED
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
*/
|
|
55
55
|
|
|
56
56
|
import { spawnSync } from "node:child_process";
|
|
57
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
57
|
+
import { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
58
58
|
import { dirname, join, resolve } from "node:path";
|
|
59
59
|
import { fileURLToPath } from "node:url";
|
|
60
60
|
|
|
@@ -86,30 +86,90 @@ function walkUp(from: string, marker: string): string | null {
|
|
|
86
86
|
return null;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
/**
|
|
90
|
+
* The primary checkout's git directory for the repo `from` is in, read from DISK — or `undefined`
|
|
91
|
+
* when the files do not say, and only `git` can.
|
|
92
|
+
*
|
|
93
|
+
* A worktree's `.git` is a FILE, `gitdir: <primary>/.git/worktrees/<slug>`, and that directory's
|
|
94
|
+
* `commondir` names the primary's `.git` relative to it. A primary checkout or a clone has a `.git`
|
|
95
|
+
* DIRECTORY, which is its own common directory. Both are what `git rev-parse --git-common-dir`
|
|
96
|
+
* answers, without a process.
|
|
97
|
+
*/
|
|
98
|
+
function commonGitDirOnDisk(from: string): string | undefined {
|
|
99
|
+
let dir = resolve(from);
|
|
100
|
+
for (let hops = 0; hops < MAX_HOPS; hops++) {
|
|
101
|
+
const dotGit = join(dir, ".git");
|
|
102
|
+
if (existsSync(dotGit)) {
|
|
103
|
+
if (statSync(dotGit).isDirectory()) return realpathSync(dotGit);
|
|
104
|
+
const pointer = /^gitdir:\s*(.+)$/m.exec(readFileSync(dotGit, "utf8"))?.[1]?.trim();
|
|
105
|
+
if (!pointer) return undefined;
|
|
106
|
+
const gitDir = resolve(dir, pointer);
|
|
107
|
+
const commonFile = join(gitDir, "commondir");
|
|
108
|
+
// A submodule's `.git` points at `.git/modules/<name>`, which has no `commondir`: it IS its own.
|
|
109
|
+
const common = existsSync(commonFile) ? resolve(gitDir, readFileSync(commonFile, "utf8").trim()) : gitDir;
|
|
110
|
+
return existsSync(common) ? realpathSync(common) : undefined;
|
|
111
|
+
}
|
|
112
|
+
const up = dirname(dir);
|
|
113
|
+
if (up === dir) return undefined;
|
|
114
|
+
dir = up;
|
|
115
|
+
}
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* One answer per starting directory, for the life of the process. Which primary a worktree was cut
|
|
121
|
+
* from cannot change while a process runs, and every `forgeState(from)` in a worktree lands here.
|
|
122
|
+
*/
|
|
123
|
+
const viaWorktree = new Map<string, string | null>();
|
|
124
|
+
|
|
125
|
+
/** For a test that must watch the lookup happen again. */
|
|
126
|
+
export function __forgetWorktreeRoots(): void {
|
|
127
|
+
viaWorktree.clear();
|
|
128
|
+
}
|
|
129
|
+
|
|
89
130
|
/**
|
|
90
131
|
* The generation above the checkout a git WORKTREE at `from` was cut from, or `null`.
|
|
91
132
|
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
133
|
+
* The primary checkout's git directory names the checkout; the ordinary walk runs from the
|
|
134
|
+
* directory holding it. For a primary checkout, a clone or a plain repo that is its own `.git`,
|
|
135
|
+
* so the answer is exactly what the walk up from `from` already said. `null` on anything
|
|
136
|
+
* unexpected — no git, not a repo, a directory that is not there — because inventing a root is
|
|
137
|
+
* the failure this module is against.
|
|
138
|
+
*
|
|
139
|
+
* 🔴 Read from the files first, and remembered, because `git` here was a HANG. Until 0.10.7 this
|
|
140
|
+
* spawned `git rev-parse --git-common-dir` on EVERY call, and in a worktree every call reaches it:
|
|
141
|
+
* roms' suite made 593 of them per run (`forgeState` ← `assertTestSafeDbPath`, `requireState`, …).
|
|
142
|
+
* Measured 2026-09-24 in a roms worktree: under `bun test --parallel=6`, about one run in three
|
|
143
|
+
* left a test worker spinning at 99% CPU inside `Bun.spawnSync` beside a `<defunct>` git child —
|
|
144
|
+
* Bun had missed the exit, and the 5 s `timeout` never fired. One gate stood 23 minutes. The
|
|
145
|
+
* primary checkout never saw it, because its walk up finds `forge.env` and never asks git. The
|
|
146
|
+
* same run from files: zero spawns. `git` remains only for a layout the files do not settle.
|
|
98
147
|
*/
|
|
99
148
|
export function findForgeRootViaWorktree(from: string): string | null {
|
|
149
|
+
const key = resolve(from);
|
|
150
|
+
const remembered = viaWorktree.get(key);
|
|
151
|
+
if (remembered !== undefined) return remembered;
|
|
152
|
+
let answer: string | null = null;
|
|
100
153
|
try {
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
encoding: "utf8",
|
|
104
|
-
timeout: 5_000,
|
|
105
|
-
});
|
|
106
|
-
if (git.status !== 0) return null;
|
|
107
|
-
const common = (git.stdout ?? "").trim();
|
|
108
|
-
if (!common.startsWith("/")) return null;
|
|
109
|
-
return walkUp(dirname(common), MARKER);
|
|
154
|
+
const common = commonGitDirOnDisk(key) ?? commonGitDirFromGit(key);
|
|
155
|
+
answer = common ? walkUp(dirname(common), MARKER) : null;
|
|
110
156
|
} catch {
|
|
111
|
-
|
|
157
|
+
answer = null;
|
|
112
158
|
}
|
|
159
|
+
viaWorktree.set(key, answer);
|
|
160
|
+
return answer;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** `git rev-parse --git-common-dir` — the fallback for a layout {@link commonGitDirOnDisk} cannot read. */
|
|
164
|
+
function commonGitDirFromGit(from: string): string | null {
|
|
165
|
+
const git = spawnSync("git", ["rev-parse", "--path-format=absolute", "--git-common-dir"], {
|
|
166
|
+
cwd: from,
|
|
167
|
+
encoding: "utf8",
|
|
168
|
+
timeout: 5_000,
|
|
169
|
+
});
|
|
170
|
+
if (git.status !== 0) return null;
|
|
171
|
+
const common = (git.stdout ?? "").trim();
|
|
172
|
+
return common.startsWith("/") ? common : null;
|
|
113
173
|
}
|
|
114
174
|
|
|
115
175
|
/**
|