Skip to content

armgit / hypit

Public Imported from GitHub
0

Clone any viral video with AI agents. Not just a script, the whole workflow: swap the face, the words, the B-roll, ship 100 variants in one command, and get your 100M views.

fix: resolve project directory aliases at Node entry points

kashorin963d7b6c9053
diff --git a/packages/cli/README.md b/packages/cli/README.md
index e9d44f0a..d3dc00a3 100644
--- a/packages/cli/README.md
+++ b/packages/cli/README.md
@@ -148,6 +148,9 @@ from a lookup that still needs the Build's Runtime or correct project selection.
Worker process log instead, for Runtime startup or process-level failures.
Project context resolution is owned by [`@hypit/project-context-node`](../project-context-node/README.md).
+History Source filters resolve existing filesystem links before comparing project-relative Result
+paths. A deleted Source or directory remains queryable: only its existing ancestor is resolved and
+the missing path suffix is retained. This is local argument handling, with no saved alias inventory.
CLI, Studio and creation tools call that same package; the CLI is not another environment owner.
`doctor`, `programs up|status|down`, and `runtime up` accept repeated `--endpoint <instance>` values.
diff --git a/packages/cli/src/commands/results.ts b/packages/cli/src/commands/results.ts
index d2c242dc..3c98892a 100644
--- a/packages/cli/src/commands/results.ts
+++ b/packages/cli/src/commands/results.ts
@@ -1,4 +1,5 @@
-import { resolve } from "node:path";
+import { realpath } from "node:fs/promises";
+import { basename, dirname, resolve } from "node:path";
import type { BuildResultRepository } from "@hypit/build-result";
@@ -20,6 +21,21 @@ export function isProjectResultCommand(args: CliCommand): args is ProjectResultC
|| args.command === "get" || (args.command === "result" && args.action === "edit");
}
+/** History can name a deleted Source. Resolve existing directory links, keeping the absent suffix. */
+async function historySourcePath(path: string): Promise<string> {
+ let existing = resolve(path);
+ const suffix: string[] = [];
+ while (true) {
+ try { return resolve(await realpath(existing), ...suffix); }
+ catch (error) {
+ const parent = dirname(existing);
+ if ((error as NodeJS.ErrnoException).code !== "ENOENT" || parent === existing) throw error;
+ suffix.unshift(basename(existing));
+ existing = parent;
+ }
+ }
+}
+
/** Execute commands that need only project-owned Result history, never a Runtime. */
export async function runProjectResultCommand(input: {
readonly args: ProjectResultCommand;
@@ -62,7 +78,7 @@ export async function runProjectResultCommand(input: {
}
if (args.command === "history") {
- const source = args.source === undefined ? undefined : resolve(args.source);
+ const source = args.source === undefined ? undefined : await historySourcePath(args.source);
const page = await browseBuildOutputHistory(repository, {
projectRoot,
output: args.outputName,
@@ -177,7 +193,7 @@ export async function runProjectResultCommand(input: {
kind: exported.kind,
path: exported.path,
};
- const path = projectPath(exported.path, projectRoot);
+ const path = projectPath(await realpath(exported.path), projectRoot);
write(machine, `Exported ${exported.output} → ${path}`, "success",
args.presentation.verbose ? [
["Build", exported.build],
diff --git a/packages/cli/test/build-programs.test.ts b/packages/cli/test/build-programs.test.ts
index a352430c..581929a9 100644
--- a/packages/cli/test/build-programs.test.ts
+++ b/packages/cli/test/build-programs.test.ts
@@ -1,5 +1,5 @@
import assert from "node:assert/strict";
-import { mkdtemp, readFile, writeFile } from "node:fs/promises";
+import { mkdtemp, readFile, realpath, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { dirname, join, resolve } from "node:path";
import test from "node:test";
@@ -224,7 +224,7 @@ test("Build confirms durable submission before following stable work progress",
output = "";
let progress = "";
- const projectRoot = dirname(source);
+ const projectRoot = await realpath(dirname(source));
const runtimeProfile = resolve("/p/a selected runtime.json");
await runCli([
"build", source, "--workspace", projectRoot, "--runtime", runtimeProfile,
diff --git a/packages/cli/test/build-results.test.ts b/packages/cli/test/build-results.test.ts
index eb7491d3..0b6f042a 100644
--- a/packages/cli/test/build-results.test.ts
+++ b/packages/cli/test/build-results.test.ts
@@ -1,5 +1,5 @@
import assert from "node:assert/strict";
-import { mkdtemp, readFile, readdir, realpath, rm, stat, writeFile } from "node:fs/promises";
+import { mkdir, mkdtemp, readFile, readdir, realpath, rm, stat, symlink, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { pathToFileURL } from "node:url";
@@ -644,7 +644,7 @@ test("logs reads finished evidence without a Runtime and clearly limits the tail
})() });
await writeFile(join(root, ".hypit/runtime"), "missing-profile.json\n");
assert.ok((await humanCommand(["inspect", id], root)).includes(
- commandHint(["logs", id], { projectRoot: root }),
+ commandHint(["logs", id], { projectRoot: await realpath(root) }),
));
assert.deepEqual(await jsonCommand(["logs", id, "--lines", "1"], root), {
format: "hypit.cli-logs@1", build: id, source: "result", records: [records[1]], omittedRecords: 1,
@@ -670,6 +670,25 @@ test("history continuation keeps the same project and Source query", async () =>
} finally { await rm(root, { recursive: true, force: true }); }
});
+test("history through a directory alias still finds a Source after its directory is removed", async () => {
+ const parent = await mkdtemp(join(tmpdir(), "hypit-history-alias-"));
+ try {
+ const root = join(parent, "project");
+ const alias = join(parent, "shortcut");
+ await mkdir(join(root, "chapter"), { recursive: true });
+ await writeFile(join(root, "chapter", "main.svml"), "source");
+ await symlink(root, alias, "junction");
+ const id = "bld_20260902T110000000Z_0000000001";
+ await fixture(root, id, "chapter/main.svml");
+ await rm(join(root, "chapter"), { recursive: true });
+ const history = await jsonCommand(["history", "stage.value", "--source", join(alias, "chapter", "main.svml")], alias) as {
+ source: string; entries: { build: string }[];
+ };
+ assert.equal(history.source, "chapter/main.svml");
+ assert.deepEqual(history.entries.map((entry) => entry.build), [id]);
+ } finally { await rm(parent, { recursive: true, force: true }); }
+});
+
test("logs reports unavailable evidence as unsuccessful, while an existing empty log is valid", async () => {
const root = await mkdtemp(join(tmpdir(), "hypit-cli-missing-log-"));
try {
diff --git a/packages/cli/test/control-commands.test.ts b/packages/cli/test/control-commands.test.ts
index 48af0161..182bd7d4 100644
--- a/packages/cli/test/control-commands.test.ts
+++ b/packages/cli/test/control-commands.test.ts
@@ -1,5 +1,7 @@
import assert from "node:assert/strict";
-import { resolve } from "node:path";
+import { mkdtemp, realpath, rm } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import { join, resolve } from "node:path";
import test from "node:test";
import type { CliDistribution } from "../src/distribution.js";
@@ -62,7 +64,7 @@ test("doctor retains later errors even with a small display limit", async () =>
] }) } as unknown as CliDistribution;
let output = "";
let exitCode = 0;
- await runCli(["doctor", "--workspace", "/tmp", "--limit", "1", "--json"], {
+ await runCli(["doctor", "--workspace", tmpdir(), "--limit", "1", "--json"], {
write(text) { output += text; }, setExitCode(code) { exitCode = code; },
}, selected);
assert.equal(exitCode, 1);
@@ -76,7 +78,7 @@ test("finished status reports failure details and a nonzero exit without a Runti
}) } as unknown as CliDistribution;
let output = "";
let exitCode = 0;
- await runCli(["status", "failed", "--workspace", "/tmp"], {
+ await runCli(["status", "failed", "--workspace", tmpdir()], {
write(text) { output += text; }, setExitCode(code) { exitCode = code; },
}, selected);
assert.equal(exitCode, 1);
@@ -293,7 +295,7 @@ test("status preserves Runtime decision and attention when its Result Store is u
let exitCode = 0;
await runCli([
- "status", view.id, "--workspace", "/tmp", "--runtime", "/tmp/runtime with space.json", "--json",
+ "status", view.id, "--workspace", tmpdir(), "--runtime", "/tmp/runtime with space.json", "--json",
], { write: (text) => { output += text; }, setExitCode: (code) => { exitCode = code; } }, distribution);
const result = JSON.parse(output) as {
@@ -307,7 +309,7 @@ test("status preserves Runtime decision and attention when its Result Store is u
assert.equal(result.build.result.state, "unavailable");
assert.equal(result.build.attention.message, "S3 unavailable");
assert.equal(result.build.attention.action, commandHint(["result", "finish", view.id], {
- projectRoot: resolve("/tmp"), runtimeProfile: resolve("/tmp/runtime with space.json"),
+ projectRoot: await realpath(tmpdir()), runtimeProfile: resolve("/tmp/runtime with space.json"),
}));
assert.deepEqual((result.build as { operations?: unknown }).operations, [{
endpoint: "images.internal", state: "failed", failure: { code: "REMOTE", message: "provider detail" },
@@ -316,7 +318,7 @@ test("status preserves Runtime decision and attention when its Result Store is u
view.issue = { scope: "cleanup", message: "temporary resource cleanup unavailable" };
output = "";
await runCli([
- "status", view.id, "--workspace", "/tmp", "--runtime", "/tmp/runtime with space.json", "--json",
+ "status", view.id, "--workspace", tmpdir(), "--runtime", "/tmp/runtime with space.json", "--json",
], { write: (text) => { output += text; } }, distribution);
const cleanup = JSON.parse(output).build.attention;
assert.equal(cleanup.message, "temporary resource cleanup unavailable");
@@ -426,7 +428,7 @@ test("command options fail closed instead of being silently ignored", async () =
);
await assert.rejects(
async () => await runCli([
- "doctor", "/tmp/runtime.json", "--workspace", "/tmp",
+ "doctor", "/tmp/runtime.json", "--workspace", tmpdir(),
], io, distribution),
/profile delegated: .*runtime\.json/u,
);
@@ -438,8 +440,9 @@ test("command options fail closed instead of being silently ignored", async () =
);
});
-test("doctor diagnoses project Results without requiring a Runtime Profile", async () => {
- const projectRoot = resolve("/tmp/hypit-project");
+test("doctor diagnoses project Results without requiring a Runtime Profile", async (t) => {
+ const projectRoot = await realpath(await mkdtemp(join(tmpdir(), "hypit-doctor-project-")));
+ t.after(async () => await rm(projectRoot, { recursive: true, force: true }));
const calls: string[] = [];
const distribution = {
async diagnoseProjectResults(projectRoot: string) {
@@ -692,7 +695,7 @@ test("cancelling an already failed execution preserves and reports its stop reas
});
test("a stopped Worker ends observation with scoped evidence commands, not a Result-read failure", async () => {
- const projectRoot = resolve("/tmp");
+ const projectRoot = await realpath(tmpdir());
const runtimeProfile = resolve("/tmp/selected runtime.json");
let closed = false;
let resultOpened = false;
diff --git a/packages/cli/test/programs-command.test.ts b/packages/cli/test/programs-command.test.ts
index 8e2fbe00..b0035375 100644
--- a/packages/cli/test/programs-command.test.ts
+++ b/packages/cli/test/programs-command.test.ts
@@ -1,4 +1,6 @@
import assert from "node:assert/strict";
+import { realpath } from "node:fs/promises";
+import { tmpdir } from "node:os";
import { resolve } from "node:path";
import test from "node:test";
@@ -344,7 +346,7 @@ test("runtime status keeps scheduling phases out of the default view", async ()
});
test("Worker stop suggests Program control in the same project and Profile", async () => {
- const projectRoot = resolve("/tmp");
+ const projectRoot = await realpath(tmpdir());
const runtimeProfile = resolve("/tmp/a selected profile.json");
let output = "";
await runCli(["runtime", "down", "--workspace", projectRoot, "--runtime", runtimeProfile], {
diff --git a/packages/cli/test/runtime-selection.test.ts b/packages/cli/test/runtime-selection.test.ts
index 0b657c7c..4b545d54 100644
--- a/packages/cli/test/runtime-selection.test.ts
+++ b/packages/cli/test/runtime-selection.test.ts
@@ -1,5 +1,5 @@
import assert from "node:assert/strict";
-import { mkdtemp, mkdir, readFile, realpath, rm, writeFile } from "node:fs/promises";
+import { mkdtemp, mkdir, readFile, realpath, rm, symlink, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import test from "node:test";
@@ -52,10 +52,10 @@ test("paths reports project selection, invocation override and no selection with
return JSON.parse(output);
};
const absent = await readPaths();
- assert.equal(absent.project, resolve(root));
+ assert.equal(absent.project, await realpath(root));
assert.equal(absent.profileSource, "none");
assert.equal(absent.profile, undefined);
- assert.equal(absent.selectionFile, join(root, ".hypit", "runtime"));
+ assert.equal(absent.selectionFile, join(await realpath(root), ".hypit", "runtime"));
const selected = await selectRuntimeProfile(root, profile);
const project = await readPaths();
assert.equal(project.profileSource, "project");
@@ -85,7 +85,7 @@ test("project resolution precedes exact project Runtime selection", async () =>
assert.equal(await findRuntimeProfile(nested), undefined);
const project = await resolveProjectRoot({ cwd: nested });
- assert.equal(project, resolve(root));
+ assert.equal(project, await realpath(root));
const found = await findRuntimeProfile(project);
assert.equal(found?.profile, selected.profile);
assert.equal(await realpath(found!.projectRoot), selected.projectRoot);
@@ -105,13 +105,31 @@ test("a parent Runtime selection never becomes a child project's selection", asy
await selectRuntimeProfile(parent, profile);
const project = await resolveProjectRoot({ cwd: child });
- assert.equal(project, resolve(child));
+ assert.equal(project, await realpath(child));
assert.equal(await findRuntimeProfile(project), undefined);
} finally {
await rm(parent, { recursive: true, force: true });
}
});
+test("project discovery chooses the caller's parent before resolving directory aliases", async () => {
+ const root = await mkdtemp(join(tmpdir(), "hypit-project-alias-"));
+ try {
+ const caller = join(root, "caller");
+ const targetParent = join(root, "target");
+ const target = join(targetParent, "nested");
+ await mkdir(caller);
+ await mkdir(target, { recursive: true });
+ await writeFile(join(caller, "package.json"), "{}");
+ await writeFile(join(targetParent, "package.json"), "{}");
+ const alias = join(caller, "linked");
+ await symlink(target, alias, "junction");
+ assert.equal(await resolveProjectRoot({ cwd: alias }), await realpath(caller));
+ assert.equal(await resolveProjectRoot({ workspaceRoot: alias }), await realpath(target));
+ await assert.rejects(resolveProjectRoot({ workspaceRoot: join(root, "missing") }), { code: "ENOENT" });
+ } finally { await rm(root, { recursive: true, force: true }); }
+});
+
test("runtime use lets later CLI commands reuse the selected Profile", async () => {
const root = await mkdtemp(join(tmpdir(), "hypit-runtime-cli-"));
const previous = process.cwd();
diff --git a/packages/project-context-node/README.md b/packages/project-context-node/README.md
index 09c49277..2a7abf5f 100644
--- a/packages/project-context-node/README.md
+++ b/packages/project-context-node/README.md
@@ -6,6 +6,8 @@ It does not load Providers, install programs, inspect credentials or select serv
1. `resolveProjectRoot({ workspaceRoot?, cwd? })` uses the explicit Workspace, otherwise the nearest
`package.json` above cwd, otherwise cwd itself. Source and Run filenames do not choose the project.
+ After selecting the existing directory, it returns its real filesystem path so project and Source
+ paths use the same representation. Symlinks do not redirect the preceding parent-project search.
2. `findRuntimeProfile(projectRoot)` reads only that project's `.hypit/runtime` file and resolves its
path relative to the project. An entrypoint's explicit `--runtime` overrides this read for that invocation.
3. The selected Runtime implementation interprets the Profile, including `dataRoot`, Credentials,
diff --git a/packages/project-context-node/src/project-context.ts b/packages/project-context-node/src/project-context.ts
index 51b553e7..9d436760 100644
--- a/packages/project-context-node/src/project-context.ts
+++ b/packages/project-context-node/src/project-context.ts
@@ -1,4 +1,4 @@
-import { stat } from "node:fs/promises";
+import { realpath, stat } from "node:fs/promises";
import { dirname, resolve } from "node:path";
async function nearestProjectPackageRoot(start: string): Promise<string | undefined> {
@@ -28,8 +28,10 @@ export async function resolveProjectRoot(options: {
readonly cwd?: string;
} = {}): Promise<string> {
const start = resolve(options.workspaceRoot ?? options.cwd ?? process.cwd());
- if (options.workspaceRoot !== undefined) return start;
- return await nearestProjectPackageRoot(start) ?? start;
+ const selected = options.workspaceRoot !== undefined ? start : await nearestProjectPackageRoot(start) ?? start;
+ // Select through the caller's directory first; following a link before discovery
+ // could choose a different parent project. Source readers also return real paths.
+ return await realpath(selected);
}
/** Project package discovery cannot escape an already resolved project. */
diff --git a/packages/runtime-local/test/local.test.ts b/packages/runtime-local/test/local.test.ts
index 0fa538bc..356e152a 100644
--- a/packages/runtime-local/test/local.test.ts
+++ b/packages/runtime-local/test/local.test.ts
@@ -6,8 +6,10 @@ import {
mkdtemp,
readFile,
readdir,
+ realpath,
rm,
stat,
+ symlink,
writeFile,
} from "node:fs/promises";
import { tmpdir } from "node:os";
@@ -23,6 +25,8 @@ import { defineEndpointPackage } from "@hypit/endpoint-kit";
import type { AsyncEndpoint, EndpointPackage } from "@hypit/endpoint-kit";
import type { ComponentPackage } from "@hypit/component-kit";
import { createLocalRuntime } from "@hypit/runtime-local";
+import { resolveProjectRoot } from "@hypit/project-context-node";
+import { NodeFilesystemWorkspace } from "../../workspace-fs-node/src/index.js";
import { defineBuild } from "@hypit/core";
import {
collectLoadedNodePackageComponents,
@@ -108,6 +112,30 @@ function durableBuildRequest(
} as const;
}
+test("a project directory alias admits its Source and stores a project-relative Result path", async () => {
+ const parent = await realpath(await mkdtemp(join(tmpdir(), "hypit-local-project-alias-")));
+ try {
+ const directory = join(parent, "project");
+ const alias = join(parent, "shortcut");
+ await mkdir(directory);
+ await writeFile(join(directory, "main.svml"), "source");
+ await writeFile(join(parent, "outside.svs"), "outside");
+ await symlink(directory, alias, "junction");
+ await symlink(parent, join(directory, "escape"), "junction");
+ const root = await resolveProjectRoot({ workspaceRoot: alias });
+ const session = await new NodeFilesystemWorkspace({ root }).open(join(alias, "main.svml"));
+ await assert.rejects(async () => await session.resolveSource(session.entry, { from: "./escape/outside.svs", alias: "outside" }),
+ { code: "SOURCE_OUTSIDE_ROOT" });
+ const runtime = await createLocalRuntime(projectRuntimeFixture(directory));
+ try {
+ const request = durableBuildRequest(root, "bld_20260916T150000000Z_0000000001", createGreetingBuild());
+ await runtime.build({ ...request, catalog: { ...request.catalog, source: { path: session.entry.id } } });
+ const result = await new FileBuildResultRepository(join(directory, "results")).read(request.id);
+ assert.equal(result?.source.path, "main.svml");
+ } finally { await runtime.close(); }
+ } finally { await rm(parent, { recursive: true, force: true }); }
+});
+
async function finishClaimedBuild(
runtime: Awaited<ReturnType<typeof createLocalRuntime>>,
): Promise<BuildCompletion> {
diff --git a/packages/workspace-fs-node/test/workspace.test.ts b/packages/workspace-fs-node/test/workspace.test.ts
index ebe5cbbf..02200dae 100644
--- a/packages/workspace-fs-node/test/workspace.test.ts
+++ b/packages/workspace-fs-node/test/workspace.test.ts
@@ -1,5 +1,5 @@
import assert from "node:assert/strict";
-import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
+import { mkdir, mkdtemp, rm, symlink, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import test from "node:test";
@@ -21,6 +21,11 @@ test("an in-root Source whose basename starts with .. is admitted", async () =>
async () => await session.resolveSource(session.entry, { from: "../outside.svs", alias: "escaped" }),
(error: unknown) => error instanceof WorkspaceError && error.code === "SOURCE_OUTSIDE_ROOT",
);
+ await symlink(parent, join(root, "..linked"), "junction");
+ await assert.rejects(
+ async () => await session.resolveSource(session.entry, { from: "./..linked/outside.svs", alias: "linked" }),
+ (error: unknown) => error instanceof WorkspaceError && error.code === "SOURCE_OUTSIDE_ROOT",
+ );
} finally {
await rm(parent, { recursive: true, force: true });
}