fix: sync Grok empty-group preservation
This commit is contained in:
1 parent
2d10a50366
commit
3de6f8823a
2 files changed
+10
-5
No files matched your search
@@ -241,14 +241,19 @@ function removeManaged(
|
|||||||
result.push(group);
|
result.push(group);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
let groupChanged = false;
|
||||||
const handlers = group.hooks.filter((handler) => {
|
const handlers = group.hooks.filter((handler) => {
|
||||||
const managedId = managedAgentId(handler, scriptName);
|
const managedId = managedAgentId(handler, scriptName);
|
||||||
const remove = managedId !== undefined
|
const remove = managedId !== undefined
|
||||||
&& (agentId === undefined || sameAgentId(managedId, agentId));
|
&& (agentId === undefined || sameAgentId(managedId, agentId));
|
||||||
if (remove) changed = true;
|
if (remove) {
|
||||||
|
changed = true;
|
||||||
|
groupChanged = true;
|
||||||
|
}
|
||||||
return !remove;
|
return !remove;
|
||||||
});
|
});
|
||||||
if (handlers.length > 0) result.push(handlers.length === group.hooks.length ? group : { ...group, hooks: handlers });
|
if (!groupChanged) result.push(group);
|
||||||
|
else if (handlers.length > 0) result.push({ ...group, hooks: handlers });
|
||||||
}
|
}
|
||||||
return { groups: result, changed };
|
return { groups: result, changed };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -351,17 +351,17 @@ test('Grok install replaces stale Elydora handlers for every agent', async () =>
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Grok uninstall preserves an untouched empty native event', async () => {
|
test('Grok uninstall preserves an untouched empty native group', async () => {
|
||||||
const fixture = await createFixture({ config: { owner: 'user' } });
|
const fixture = await createFixture({ config: { owner: 'user' } });
|
||||||
try {
|
try {
|
||||||
assert.equal(fixture.installResult.code, 0, fixture.installResult.stderr);
|
assert.equal(fixture.installResult.code, 0, fixture.installResult.stderr);
|
||||||
const config = JSON.parse(await readFile(fixture.configPath, 'utf-8'));
|
const config = JSON.parse(await readFile(fixture.configPath, 'utf-8'));
|
||||||
config.hooks.PreToolUse = [];
|
config.hooks.PreToolUse.unshift({ hooks: [], label: 'keep empty group' });
|
||||||
await writeFile(fixture.configPath, JSON.stringify(config, null, 2));
|
await writeFile(fixture.configPath, JSON.stringify(config, null, 2));
|
||||||
const result = await runPlugin(fixture, 'uninstall', 'agent-1');
|
const result = await runPlugin(fixture, 'uninstall', 'agent-1');
|
||||||
assert.equal(result.code, 0, result.stderr);
|
assert.equal(result.code, 0, result.stderr);
|
||||||
const remaining = JSON.parse(await readFile(fixture.configPath, 'utf-8'));
|
const remaining = JSON.parse(await readFile(fixture.configPath, 'utf-8'));
|
||||||
assert.deepEqual(remaining.hooks.PreToolUse, []);
|
assert.deepEqual(remaining.hooks.PreToolUse, [{ hooks: [], label: 'keep empty group' }]);
|
||||||
assert.equal(remaining.hooks.PostToolUse, undefined);
|
assert.equal(remaining.hooks.PostToolUse, undefined);
|
||||||
} finally {
|
} finally {
|
||||||
await fixture.close();
|
await fixture.close();
|
||||||
|
|||||||
Reference in new issue
Block a user