Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
simplify: collapse duplicated venv-exists checks into a shared helper
[._.]/ Adam Eivy7b00d19f85a1
diff --git a/scripts/setup-image-video.sh b/scripts/setup-image-video.shindex d78ce7ad6e..f5976e7ec0 100755--- a/scripts/setup-image-video.sh+++ b/scripts/setup-image-video.sh@@ -43,6 +43,10 @@ venv_python() {fi}+# True if a venv at $1 already has an interpreter under either layout —+# shared with venv_python so the two probes can't drift apart.+venv_exists() { [[ -x "$1/bin/python3" || -x "$1/Scripts/python.exe" ]]; }+# Check out a pin (a commit SHA, tag, or branch name) in an already-fetched# clone. A bare `git checkout <branch>` lands on the *local* branch created at# clone time, which `git fetch origin` never advances — so re-running with a@@ -468,7 +472,7 @@ if [[ "$INSTALL_MINIMAX_H3_CUDA" == "1" ]]; then# A Windows venv puts the interpreter under Scripts/, a POSIX one under bin/.# Probe for either rather than branching on `uname`, so an MSYS/Cygwin bash on# Windows (which is what the in-app installer runs) resolves correctly.- if [[ ! -x "$MINIMAX_H3_CUDA_VENV/bin/python3" && ! -x "$MINIMAX_H3_CUDA_VENV/Scripts/python.exe" ]]; then+ if ! venv_exists "$MINIMAX_H3_CUDA_VENV"; thenecho "📦 Creating MiniMax H3 CUDA venv...""$PYTHON_BIN" -m venv "$MINIMAX_H3_CUDA_VENV"fi@@ -642,7 +646,7 @@ if [[ "$INSTALL_AUDIOLDM2" == "1" ]]; thenAUDIOLDM2_VENV="${HOME}/.portos/venv-audioldm2"mkdir -p "${HOME}/.portos"- if [[ ! -x "$AUDIOLDM2_VENV/bin/python3" && ! -x "$AUDIOLDM2_VENV/Scripts/python.exe" ]]; then+ if ! venv_exists "$AUDIOLDM2_VENV"; thenecho "📦 Creating AudioLDM2 venv at ${AUDIOLDM2_VENV}...""$PYTHON_BIN" -m venv "$AUDIOLDM2_VENV"fi@@ -688,7 +692,7 @@ if [[ "$INSTALL_ACESTEP" == "1" ]]; thenACESTEP_VENV="${HOME}/.portos/venv-acestep"mkdir -p "${HOME}/.portos"- if [[ ! -x "$ACESTEP_VENV/bin/python3" && ! -x "$ACESTEP_VENV/Scripts/python.exe" ]]; then+ if ! venv_exists "$ACESTEP_VENV"; thenecho "📦 Creating ACE-Step venv at ${ACESTEP_VENV}...""$PYTHON_BIN" -m venv "$ACESTEP_VENV"fi@@ -728,7 +732,7 @@ if [[ "$INSTALL_MINIMAX_MUSIC3" == "1" ]]; thenecho "♻️ Existing MiniMax Music 3 venv was built from a conda base (torch can't load there) — rebuilding from ${PYTHON_BIN}."rm -rf "$MINIMAX_MUSIC3_VENV"fi- if [[ ! -x "$MINIMAX_MUSIC3_VENV/bin/python3" && ! -x "$MINIMAX_MUSIC3_VENV/Scripts/python.exe" ]]; then+ if ! venv_exists "$MINIMAX_MUSIC3_VENV"; then"$PYTHON_BIN" -m venv "$MINIMAX_MUSIC3_VENV"fiMINIMAX_MUSIC3_PY="$(venv_python "$MINIMAX_MUSIC3_VENV")"@@ -783,7 +787,7 @@ if [[ "$INSTALL_MUSCRIPTOR" == "1" ]]; thenMUSCRIPTOR_VENV="${HOME}/.portos/venv-muscriptor"mkdir -p "${HOME}/.portos"- if [[ ! -x "$MUSCRIPTOR_VENV/bin/python3" && ! -x "$MUSCRIPTOR_VENV/Scripts/python.exe" ]]; then+ if ! venv_exists "$MUSCRIPTOR_VENV"; thenecho "📦 Creating MuScriptor venv at ${MUSCRIPTOR_VENV}...""$PYTHON_BIN" -m venv "$MUSCRIPTOR_VENV"fi@@ -814,7 +818,7 @@ if [[ "$INSTALL_FLUX2" == "1" ]]; then# fragile, so we use a sibling venv. server/lib/pythonSetup.js looks for# this venv's interpreter when the active model has runner=='flux2'.FLUX2_VENV="${HOME}/.portos/venv-flux2"- if [[ ! -x "$FLUX2_VENV/bin/python3" && ! -x "$FLUX2_VENV/Scripts/python.exe" ]]; then+ if ! venv_exists "$FLUX2_VENV"; thenecho "📦 Creating FLUX.2 venv at ${FLUX2_VENV}..."mkdir -p "${HOME}/.portos""$PYTHON_BIN" -m venv "$FLUX2_VENV"diff --git a/scripts/setup-image-video.test.js b/scripts/setup-image-video.test.jsindex 422c7ae00f..8bb16dd291 100644--- a/scripts/setup-image-video.test.js+++ b/scripts/setup-image-video.test.js@@ -9,6 +9,7 @@ const REPO_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');const SETUP_SCRIPT = join(REPO_ROOT, 'scripts', 'setup-image-video.sh');const source = readFileSync(SETUP_SCRIPT, 'utf8');const helper = source.match(/^venv_python\(\) \{\n(?:.*\n)*?^\}\n/m)?.[0];+const existsHelper = source.match(/^venv_exists\(\) \{.*\}\n/m)?.[0];const tempVenvs = [];afterEach(() => {@@ -31,11 +32,24 @@ function resolveVenvPython(venv) {}).trim();}+function venvExists(venv) {+ const result = execFileSync(+ 'bash',+ ['-c', `${existsHelper}\nvenv_exists "$1" && echo yes || echo no`, 'bash', venv],+ { encoding: 'utf8' }+ ).trim();+ return result === 'yes';+}+describe('setup-image-video venv layout handling (issue #4200)', () => {it('defines the shared venv interpreter resolver', () => {expect(helper).toBeTruthy();});+ it('defines the shared venv-exists predicate', () => {+ expect(existsHelper).toBeTruthy();+ });+// Windows CI runs Node directly; these bash-execution checks are POSIX-only,// while the portable structural guard below still covers every platform.it.skipIf(process.platform === 'win32')('passes Bash syntax validation', () => {@@ -52,6 +66,14 @@ describe('setup-image-video venv layout handling (issue #4200)', () => {expect(resolveVenvPython(venv)).toBe(interpreter);});+ it.skipIf(process.platform === 'win32')('venv_exists is true for either layout, false for neither', () => {+ expect(venvExists(createVenv('posix').venv)).toBe(true);+ expect(venvExists(createVenv('windows').venv)).toBe(true);+ const empty = mkdtempSync(join(tmpdir(), 'portos-venv-python-'));+ tempVenvs.push(empty);+ expect(venvExists(empty)).toBe(false);+ });+it.each([['MiniMax H3 CUDA', 'MINIMAX_H3_CUDA_VENV', 'MINIMAX_H3_CUDA_PY'],['AudioLDM2', 'AUDIOLDM2_VENV', 'AUDIOLDM2_PY'],@@ -60,7 +82,22 @@ describe('setup-image-video venv layout handling (issue #4200)', () => {['MuScriptor', 'MUSCRIPTOR_VENV', 'MUSCRIPTOR_PY'],['FLUX.2', 'FLUX2_VENV', 'FLUX2_PY'],])('%s reuses an existing Windows venv and resolves it with the helper', (_name, venv, python) => {- expect(source).toContain(`if [[ ! -x "$${venv}/bin/python3" && ! -x "$${venv}/Scripts/python.exe" ]]; then`);+ expect(source).toContain(`if ! venv_exists "$${venv}"; then`);expect(source).toContain(`${python}="$(venv_python "$${venv}")"`);});++ it('has no call site that hardcodes a venv interpreter path outside the shared helpers', () => {+ // A literal "$SOMETHING_VENV/bin/python3" assignment outside the helper+ // definitions means a call site bypassed venv_python() and reintroduced+ // the POSIX-only bug this file guards against — EXCEPT for venvs that are+ // gated behind is_macos and can never be created by Windows Python, which+ // legitimately hardcode the POSIX path: mflux (uv-managed, Apple Silicon+ // only) and MusicGen (MLX runtime, is_macos-gated).+ const macosOnlyVenvExemptions = ['MFLUX_VENV', 'MUSICGEN_VENV'];+ const body = macosOnlyVenvExemptions+ .reduce((text, name) => text.replaceAll(`\${${name}}`, '').replaceAll(`$${name}`, ''), source)+ .replace(helper, '')+ .replace(existsHelper, '');+ expect(body).not.toMatch(/\$\{?\w+_VENV\}?\/bin\/python3/);+ });});