Skip to content

Turn any idea, plan, or codebase into a beautiful interactive diagram. An agent skill for Claude Code, Codex, and more.

fix(opener): pass Windows targets through PowerShell environment

asts-topa2ca4d063ece
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index a138b321..bd4b5b09 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -195,10 +195,11 @@ jobs:
- name: Verify Windows-sensitive regression fixtures
run: >-
node --test
- --test-name-pattern="Git checkout preserves|clean staging preserves index modes|workflow migration cleanup failure|preview runs from an installed skill|canonical watch target|Windows 8.3 short path"
+ --test-name-pattern="Git checkout preserves|clean staging preserves index modes|workflow migration cleanup failure|preview runs from an installed skill|canonical watch target|Windows 8.3 short path|open artifact:"
archify/test/checkout-line-endings.test.mjs
archify/test/clean-skill-staging.test.mjs
archify/test/workflow-migration.test.mjs
+ archify/test/open-artifact.test.mjs
archify/test/cli.test.mjs
archify/test/preview.test.mjs
diff --git a/archify.zip b/archify.zip
index 585b79a8..c0b6dbf2 100644
Binary files a/archify.zip and b/archify.zip differ
diff --git a/archify/bin/open-artifact.mjs b/archify/bin/open-artifact.mjs
index 878f6b4c..b8559cfc 100644
--- a/archify/bin/open-artifact.mjs
+++ b/archify/bin/open-artifact.mjs
@@ -15,14 +15,13 @@ const OPENERS = {
win32: {
command: 'powershell.exe',
method: 'powershell',
- // Keep the command constant and pass the target through PowerShell's
- // argument array. Paths are never interpolated into executable source.
- args: (target) => [
+ // Keep the command constant and pass the target through a child-only
+ // environment variable. Paths are never interpolated into executable source.
+ args: () => [
'-NoProfile',
'-NonInteractive',
'-Command',
- 'Start-Process -FilePath $args[0]',
- target,
+ 'Start-Process -FilePath $env:ARCHIFY_OPEN_TARGET',
],
},
};
@@ -42,13 +41,20 @@ function launchTarget(target, options = {}) {
const spawn = options.spawn || spawnSync;
let result;
try {
- result = spawn(opener.command, opener.args(target), {
+ const spawnOptions = {
encoding: 'utf8',
shell: false,
stdio: 'ignore',
timeout: options.timeoutMs || 5000,
windowsHide: true,
- });
+ };
+ if (platform === 'win32') {
+ spawnOptions.env = {
+ ...process.env,
+ ARCHIFY_OPEN_TARGET: target,
+ };
+ }
+ result = spawn(opener.command, opener.args(target), spawnOptions);
} catch {
result = { error: new Error('opener threw') };
}
diff --git a/archify/test/open-artifact.test.mjs b/archify/test/open-artifact.test.mjs
index 22be2813..41adf774 100644
--- a/archify/test/open-artifact.test.mjs
+++ b/archify/test/open-artifact.test.mjs
@@ -27,8 +27,7 @@ test('open artifact: uses argument arrays without shell interpolation on every s
'-NoProfile',
'-NonInteractive',
'-Command',
- 'Start-Process -FilePath $args[0]',
- target,
+ 'Start-Process -FilePath $env:ARCHIFY_OPEN_TARGET',
],
method: 'powershell',
},
@@ -54,9 +53,28 @@ test('open artifact: uses argument arrays without shell interpolation on every s
assert.deepEqual(invocation.args, expected.args);
assert.equal(invocation.options.shell, false);
assert.equal(invocation.options.timeout, 5000);
+ if (expected.platform === 'win32') {
+ assert.equal(invocation.options.env.ARCHIFY_OPEN_TARGET, target);
+ } else {
+ assert.equal(invocation.options.env, undefined);
+ }
}
});
+test('open artifact: Windows PowerShell launches a real target', { skip: process.platform !== 'win32' }, () => {
+ // Use a bundled console executable so this exercises PowerShell without a browser.
+ const systemRoot = process.env.SystemRoot ?? process.env.WINDIR ?? 'C:\\Windows';
+ const target = path.join(systemRoot, 'System32', 'where.exe');
+ const result = openArtifact(target);
+
+ assert.deepEqual(result, {
+ requested: true,
+ status: 'opened',
+ target: path.resolve(target),
+ method: 'powershell',
+ });
+});
+
test('open artifact: distinguishes missing support from opener execution failure', () => {
const missing = openArtifact(target, {
platform: 'linux',
@@ -105,6 +123,28 @@ test('open artifact: live preview opens only an exact loopback HTTP root', () =>
assert.deepEqual(invocation.args, [url]);
assert.equal(invocation.options.shell, false);
+ let windowsInvocation;
+ const windowsResult = openLoopbackUrl(url, {
+ platform: 'win32',
+ spawn(command, args, options) {
+ windowsInvocation = { command, args, options };
+ return { status: 0 };
+ },
+ });
+ assert.deepEqual(windowsResult, {
+ requested: true,
+ status: 'opened',
+ target: url,
+ method: 'powershell',
+ });
+ assert.deepEqual(windowsInvocation.args, [
+ '-NoProfile',
+ '-NonInteractive',
+ '-Command',
+ 'Start-Process -FilePath $env:ARCHIFY_OPEN_TARGET',
+ ]);
+ assert.equal(windowsInvocation.options.env.ARCHIFY_OPEN_TARGET, url);
+
for (const rejected of [
'https://127.0.0.1:43127/',
'http://localhost:43127/',