From 1c893af1690d7bbdfd540b6d6a359935155db156 Mon Sep 17 00:00:00 2001 From: Jacob Heider Date: Thu, 14 Mar 2024 16:29:52 -0400 Subject: [PATCH 1/2] fix `Assertion failed: pkgx: env is being duped` when multiple unicodes in env closes #988 --- src/prefab/construct-env.test.ts | 11 +++++++++++ src/prefab/construct-env.ts | 5 +++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/prefab/construct-env.test.ts b/src/prefab/construct-env.test.ts index 67afe828..3df73933 100644 --- a/src/prefab/construct-env.test.ts +++ b/src/prefab/construct-env.test.ts @@ -48,4 +48,15 @@ async fn(runner) { await _internals.runtime_env(pkg, []) } }) + + await runner.step("multiple versions", async () => { + const tmp = Path.mktemp() + + const installations = [ + { pkg: {project: "unicode.org", version: new SemVer("71.0.0")}, path: tmp.join("unicode.org/v71.0.0").mkdir('p') }, + { pkg: {project: "unicode.org", version: new SemVer("73.0.0")}, path: tmp.join("unicode.org/v73.0.0").mkdir('p') }, + ] + + await _internals.mkenv({ installations }) + }) }}) diff --git a/src/prefab/construct-env.ts b/src/prefab/construct-env.ts index 45c63650..6bae4d41 100644 --- a/src/prefab/construct-env.ts +++ b/src/prefab/construct-env.ts @@ -36,7 +36,7 @@ export default async function(pkgenv: { installations: Installation[] }) { ///////////////////////// reworked from useShellEnv needs porting back to libpkgx async function mkenv({installations}: {installations: Installation[]}) { - const projects = new Set(installations.map(x => x.pkg.project)) + const projects = new Set(installations.map(x => `${x.pkg.project}@${x.pkg.version}`)) console.assert(projects.size == installations.length, "pkgx: env is being duped") const common_vars: Record> = {} @@ -160,5 +160,6 @@ class OrderedSet { ////////////////////////////////////////////////////////////////////// internals export const _internals = { - runtime_env: (pkg: Package, installations: Installation[]) => usePantry().project(pkg.project).runtime.env(pkg.version, installations) + runtime_env: (pkg: Package, installations: Installation[]) => usePantry().project(pkg.project).runtime.env(pkg.version, installations), + mkenv } From 006b731d1006289c15f25ee98fc9698267fb4018 Mon Sep 17 00:00:00 2001 From: Jacob Heider Date: Thu, 14 Mar 2024 16:43:12 -0400 Subject: [PATCH 2/2] stub pantry use out --- src/prefab/construct-env.test.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/prefab/construct-env.test.ts b/src/prefab/construct-env.test.ts index 3df73933..96019816 100644 --- a/src/prefab/construct-env.test.ts +++ b/src/prefab/construct-env.test.ts @@ -56,7 +56,12 @@ async fn(runner) { { pkg: {project: "unicode.org", version: new SemVer("71.0.0")}, path: tmp.join("unicode.org/v71.0.0").mkdir('p') }, { pkg: {project: "unicode.org", version: new SemVer("73.0.0")}, path: tmp.join("unicode.org/v73.0.0").mkdir('p') }, ] - - await _internals.mkenv({ installations }) + const stub3 = mock.stub(_internals, "runtime_env", async () => ({})) + try { + await _internals.mkenv({ installations }) + } finally { + stub3.restore() + tmp.rm({recursive: true}) + } }) }})