Skip to content

Commit 6d4be13

Browse files
author
hzq
committed
Resolve the Windows ACL utility outside the agent discovery PATH
1 parent f8a8f92 commit 6d4be13

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,5 @@ jobs:
5454
- run: npm run format:check
5555
- run: npm run build
5656
- run: node --import ./dist/test/setup-locale.js --test --test-concurrency=1 dist/test/release-plan.test.js dist/test/claude-sdk.test.js dist/test/profile-init.test.js dist/test/profile-update.test.js
57+
- name: Verify profile edits with an agent-only PATH
58+
run: node --import ./dist/test/setup-locale.js --test --test-concurrency=1 --test-name-pattern="oaa doctor --write|一键启用已安装的智能体" dist/test/acp.test.js dist/test/handoff.test.js

‎src/core/win-acl.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,13 @@ export async function restrictToOwner(
137137
): Promise<boolean> {
138138
if (platform !== 'win32') return false;
139139
const user = currentUser();
140-
if (!user) return false;
140+
const system = process.env.SystemRoot;
141+
if (!user || !system || !path.isAbsolute(system)) return false;
142+
// Discovery may deliberately set PATH to only the installed agents. Never resolve an ACL tool there.
143+
const utility = path.join(system, 'System32', 'icacls.exe');
141144
return await new Promise<boolean>((resolve) => {
142145
try {
143-
execFile('icacls', icaclsArgs(file, user), { windowsHide: true, timeout: 5000 }, (error) =>
146+
execFile(utility, icaclsArgs(file, user), { windowsHide: true, timeout: 5000 }, (error) =>
144147
resolve(!error),
145148
);
146149
} catch {

‎test/profile-update.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,23 @@ test('competing CLI processes cannot both publish from one revision', async (t)
9999
assert.equal(await readFile(file, 'utf8'), values[status.indexOf('published')]);
100100
});
101101

102+
test(
103+
'Windows profile writes do not depend on the agent-discovery PATH',
104+
{ skip: process.platform !== 'win32' },
105+
async (t) => {
106+
const { dir, file } = await profile(t);
107+
const env = { ...process.env };
108+
for (const key of Object.keys(env)) if (key.toLowerCase() === 'path') delete env[key];
109+
env.PATH = dir;
110+
const result = await exec(process.execPath, [fixture, 'write', file, changed], {
111+
env,
112+
timeout: 30000,
113+
});
114+
assert.equal(result.stdout.trim(), 'published');
115+
assert.equal(await readFile(file, 'utf8'), changed);
116+
},
117+
);
118+
102119
test(
103120
'a lost rename acknowledgement is accepted only after publication',
104121
{ skip: process.platform === 'win32' },

0 commit comments

Comments
 (0)