Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(deploy): stage the untracked half of a directory git already checked out

nirholasc7ab8d2d5ebd
diff --git a/scripts/prepare-deploy-worktree.mjs b/scripts/prepare-deploy-worktree.mjs
index c63711a9c..106388940 100644
--- a/scripts/prepare-deploy-worktree.mjs
+++ b/scripts/prepare-deploy-worktree.mjs
@@ -146,6 +146,29 @@ export const ARTIFACTS = [
},
];
+/**
+ * How to hardlink one artifact into the staged tree.
+ *
+ * An artifact is not always all-or-nothing in git. `animation-sources` holds
+ * tracked .fbx sources next to gitignored .glb fixtures, so `git worktree add`
+ * creates the directory with only the tracked half in it. Treating a
+ * destination that merely EXISTS as already staged then drops every file this
+ * entry was added for, and the suite fails on 25 missing fixtures that read as
+ * a broken commit rather than an unstaged tree. So an existing destination is
+ * merged into instead of skipped: `--update=none` hardlinks what checkout could
+ * not produce and leaves every file the worktree already owns exactly as it is,
+ * which matters because a hardlinked tracked file would make an edit in the
+ * deploy tree rewrite the source tree too.
+ *
+ * @param {string} src absolute path in the source tree
+ * @param {string} dest absolute path in the staged tree
+ * @param {boolean} destExists does dest already exist (git checked part of it out)
+ * @returns {string[]} argv for `cp`
+ */
+export function cpArgsFor(src, dest, destExists) {
+ return destExists ? ['-al', '--update=none', `${src}/.`, `${dest}/`] : ['-al', src, dest];
+}
+
/** Env files copied (never hardlinked: a deploy tree must not share their inode). */
const ENV_FILES = ['.env', '.env.local'];
@@ -261,9 +284,9 @@ function run() {
for (const p of plan) {
if (p.action === 'skip') continue;
const dest = path.join(TARGET, p.rel);
- if (existsSync(dest)) continue;
- execFileSync('cp', ['-al', p.src, dest], { cwd: ROOT, timeout: 900_000 });
- console.log(`[prep:worktree] hardlinked ${p.rel}`);
+ const merging = existsSync(dest);
+ execFileSync('cp', cpArgsFor(p.src, dest, merging), { cwd: ROOT, timeout: 900_000 });
+ console.log(`[prep:worktree] hardlinked ${merging ? `the untracked half of ${p.rel}` : p.rel}`);
}
for (const e of envPlan) {
diff --git a/tests/prepare-deploy-worktree.test.js b/tests/prepare-deploy-worktree.test.js
index 85e4f0008..214bc4972 100644
--- a/tests/prepare-deploy-worktree.test.js
+++ b/tests/prepare-deploy-worktree.test.js
@@ -12,7 +12,7 @@ import { execFileSync } from 'node:child_process';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
-import { ARTIFACTS, planArtifacts } from '../scripts/prepare-deploy-worktree.mjs';
+import { ARTIFACTS, planArtifacts, cpArgsFor } from '../scripts/prepare-deploy-worktree.mjs';
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const SCRIPT = path.join(ROOT, 'scripts/prepare-deploy-worktree.mjs');
@@ -75,6 +75,35 @@ describe('planArtifacts', () => {
});
});
+describe('cpArgsFor', () => {
+ it('hardlinks the whole artifact when the worktree has no such directory', () => {
+ expect(cpArgsFor('/src/node_modules', '/wt/node_modules', false)).toEqual([
+ '-al',
+ '/src/node_modules',
+ '/wt/node_modules',
+ ]);
+ });
+
+ it('fills in a directory git already created rather than skipping it', () => {
+ // animation-sources is half tracked (.fbx) and half gitignored (.glb), so
+ // checkout creates it with only the tracked half. Skipping it on the
+ // grounds that it exists is what left the glb-diff and model-diff suites
+ // failing on 25 missing fixtures in a freshly staged tree.
+ expect(cpArgsFor('/src/animation-sources', '/wt/animation-sources', true)).toEqual([
+ '-al',
+ '--update=none',
+ '/src/animation-sources/.',
+ '/wt/animation-sources/',
+ ]);
+ });
+
+ it('never overwrites a file the worktree already owns', () => {
+ // A tracked file hardlinked from the source tree would make an edit in the
+ // deploy tree rewrite the shared tree through the shared inode.
+ expect(cpArgsFor('/src/x', '/wt/x', true)).toContain('--update=none');
+ });
+});
+
describe('guards (plan mode, writes nothing)', () => {
it('refuses a target on another filesystem, where cp -al cannot hardlink', () => {
const r = plan(['--path', '/tmp/deploy-wt-vitest-probe']);