commit 75ed2641481dae9b665474ea2189fa82aaa1823e
parent 9b8fe12af4cca540819f709517c3edbec5847082
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Sun, 1 Nov 2026 23:44:19 -0500
umtool projects: a lookup that misses on the memoised walk walks again (lib/projects.ts lookUp, for projectRef and resolveProjectPath), so a project made on disk a moment ago is found the first time it is asked for -- bench-prep.spec.ts failed only in a full run because the spec before it had just walked the reports, its project was made in beforeAll inside that second, and the Cut tab 404'd. The spec now makes its project after a request that walks without it, so the order it runs in no longer matters (it failed so alone, before)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
2 files changed, 47 insertions(+), 10 deletions(-)
diff --git a/umtool/e2e/bench-prep.spec.ts b/umtool/e2e/bench-prep.spec.ts
@@ -10,7 +10,8 @@ import * as urls from "./urls";
// clip's first open -- a long recording's excerpt, the waveform -- and the
// bench then opens on the prepared files.
//
-// Its own project, made here and removed after (the suite runs one spec file
+// Its own project, made here -- by the test, a moment after the server walked
+// the reports without it -- and removed after (the suite runs one spec file
// at a time, so no other spec's project count sees it): r01 sits on a
// "recording", a cached window whose NAME says 0–700 s (longer than the
// bench's EXCERPT_OVER_S, so the bench is given an excerpt of it), and r02 on
@@ -24,7 +25,14 @@ const DIR = path.join(FIXTURE, "reports", "prep-fixture");
const TONE = path.join(FIXTURE, "reports", "report-fixture", "out", "clips-raw", "vid1_0.00-9.00.mp4");
const EXCERPT = path.join(DIR, "out", "bench-excerpts", "vidp", "0.00-60.00.excerpt.mp4");
-test.beforeAll(() => {
+/**
+ * The project, on disk. Made INSIDE the test, after the server has walked the
+ * reports without it: whatever an earlier spec asked a moment ago (the walk is
+ * memoised for a second, lib/projects.ts), a project made on disk is found
+ * the moment it is asked for -- in a full run the spec before this one used to
+ * leave a walk that did not have it, and the Cut tab 404'd.
+ */
+function makeProject() {
rmSync(DIR, { recursive: true, force: true });
mkdirSync(path.join(DIR, "out", "clips-raw"), { recursive: true });
const clip = (id: string, video: string) => ({ type: "clip", id, video, start: 3, end: 6, cite: 3, section: 0, lock: true, quote: "and because" });
@@ -34,6 +42,10 @@ test.beforeAll(() => {
);
copyFileSync(TONE, path.join(DIR, "out", "clips-raw", "vidp_0.00-700.00.mp4"));
copyFileSync(TONE, path.join(DIR, "out", "clips-raw", "vid1_0.00-9.00.mp4"));
+}
+
+test.beforeAll(() => {
+ rmSync(DIR, { recursive: true, force: true });
});
test.afterAll(() => {
@@ -41,6 +53,10 @@ test.afterAll(() => {
});
test("Prepare clips for the walk makes the excerpt and the waveforms, and the bench opens on them", async ({ page, request }) => {
+ // The server walks the reports now, and finds no such project...
+ expect((await request.get(`/api/report/prep?project=${encodeURIComponent(PROJECT)}`)).status()).toBe(404);
+ // ...which is made a moment later, and opened at once.
+ makeProject();
await page.goto(urls.section(PROJECT, "timeline"));
const panel = page.locator("[data-bench-prep]");
await expect(panel.locator("[data-bench-prep-status]")).toHaveText("0 of 2 ready to open · 2 to prepare");
diff --git a/umtool/lib/projects.ts b/umtool/lib/projects.ts
@@ -113,6 +113,22 @@ export async function projectRefs(): Promise<ProjectRef[]> {
}
/**
+ * A lookup over the walk that walks again when it misses on a MEMOISED walk: a
+ * project made on disk a moment ago (the CLI's scaffold, an agent, a spec) is
+ * found the first time it is asked for, not up to a second later -- the memo
+ * answered "no such project" for it, and its page 404'd (bench-prep.spec.ts,
+ * in a full run, behind a spec whose last request had just walked). A miss on
+ * a fresh walk is final, so a wrong address costs one walk, never a loop.
+ */
+async function lookUp<T>(find: (refs: ProjectRef[]) => T | null): Promise<T | null> {
+ const memo = !!CACHES.walk && Date.now() - CACHES.walk.at < 1000;
+ const got = find(await projectRefs());
+ if (got !== null || !memo) return got;
+ CACHES.walk = null;
+ return find(await projectRefs());
+}
+
+/**
* What `pruneIndex` would drop, read only (Settings · system's plan, P5): the
* index's records for projects the walk no longer finds, against a fresh walk.
*/
@@ -143,7 +159,7 @@ export async function pruneIndex(): Promise<number> {
}
export async function projectRef(id: string): Promise<ProjectRef | null> {
- return (await projectRefs()).find((p) => p.id === id) ?? null;
+ return lookUp((refs) => refs.find((p) => p.id === id) ?? null);
}
type KindSummary = {
@@ -375,20 +391,25 @@ export type Resolved =
* path, and `a/b` being a project must not stop `a/b/c` from being one too.
*/
export async function resolveProjectPath(segments: string[]): Promise<Resolved> {
- const refs = await projectRefs();
const id = segments.join("/");
- let best: ProjectRef | null = null;
- for (const p of refs) {
- if (p.routing !== "ok") continue;
- if (id === p.id || id.startsWith(`${p.id}/`)) {
- if (!best || p.id.length > best.id.length) best = p;
+ const longest = (refs: ProjectRef[]) => {
+ let best: ProjectRef | null = null;
+ for (const p of refs) {
+ if (p.routing !== "ok") continue;
+ if (id === p.id || id.startsWith(`${p.id}/`)) {
+ if (!best || p.id.length > best.id.length) best = p;
+ }
}
- }
+ return best;
+ };
+ const best = await lookUp(longest);
if (best) {
const rest = id === best.id ? [] : id.slice(best.id.length + 1).split("/");
return { project: best, rest, folder: null };
}
+ // (The walk the miss above made: memoised now, so the folders and the alias read the same one.)
+ const refs = await projectRefs();
const folders = await listFolders();
const folder = folders.get(id);