mirror of
https://github.com/affaan-m/ECC.git
synced 2026-11-17 05:22:17 +00:00
fix(opencode): guard hooks against undefined output to prevent compaction crash
The shell.env and experimental.session.compacting hooks dereferenced output.env and output.prompt unconditionally. When OpenCode invokes a hook without an output object, this threw TypeError: undefined is not an object and aborted compaction entirely. - shell.env: early-return when output is undefined - experimental.session.compacting: guard the output.prompt/output.context branches so a missing output no-ops instead of throwing Add regression tests for both hooks covering the undefined-output case. Fixes #3934
This commit is contained in:
1 parent
d2ef268059
commit
9ce5cd92e7
2 files changed
+39
-2
No files matched your search
@@ -639,6 +639,10 @@ export const ECCHooksPlugin: ECCHooksPluginFn = async ({
|
||||
* Action: Sets PROJECT_ROOT, PACKAGE_MANAGER, DETECTED_LANGUAGES, ECC_VERSION
|
||||
*/
|
||||
"shell.env": async (_input: { cwd: string }, output: { env: Record<string, string> }) => {
|
||||
// OpenCode may invoke this hook with no output object. Dereferencing
|
||||
// output.env unconditionally below throws and aborts the shell environment
|
||||
// hook, so bail out early instead (#3934).
|
||||
if (!output) return
|
||||
const env: Record<string, string> = {
|
||||
ECC_VERSION: getECCVersion(eccRoot),
|
||||
ECC_PLUGIN: "true",
|
||||
@@ -744,9 +748,11 @@ export const ECCHooksPlugin: ECCHooksPluginFn = async ({
|
||||
]
|
||||
|
||||
// OpenCode requires output assignment and skips context when a prompt is set.
|
||||
if (output.prompt !== undefined) {
|
||||
// Guard against a missing output object so a hook invocation that omits it
|
||||
// no-ops instead of throwing and aborting compaction (#3934).
|
||||
if (output && output.prompt !== undefined) {
|
||||
output.prompt = [output.prompt, ...eccContext].join("\n\n")
|
||||
} else {
|
||||
} else if (output) {
|
||||
output.context = [...output.context, ...eccContext]
|
||||
}
|
||||
},
|
||||
|
||||
@@ -347,6 +347,22 @@ async function main() {
|
||||
}
|
||||
},
|
||||
],
|
||||
[
|
||||
"shell.env no-ops instead of throwing when the host omits the output object",
|
||||
async () => withTempProject([], async (projectDir) => {
|
||||
const client = createClient()
|
||||
const $ = createFailingShell()
|
||||
const hooks = await ECCHooksPlugin({ client, $, directory: projectDir })
|
||||
|
||||
// OpenCode may invoke the hook with no output object; the previous
|
||||
// implementation dereferenced output.env unconditionally and aborted
|
||||
// the shell environment hook with TypeError: undefined is not an
|
||||
// object (#3934).
|
||||
await hooks["shell.env"]({ cwd: projectDir }, undefined)
|
||||
|
||||
assert.deepStrictEqual($.calls, [], "Expected no shell probes")
|
||||
}),
|
||||
],
|
||||
[
|
||||
"compacting appends ECC context without replacing the host compaction prompt",
|
||||
async () => withTempProject([], async (projectDir) => {
|
||||
@@ -388,6 +404,21 @@ async function main() {
|
||||
assert.deepStrictEqual($.calls, [])
|
||||
}),
|
||||
],
|
||||
[
|
||||
"compacting no-ops instead of throwing when the host omits the output object",
|
||||
async () => withTempProject([], async (projectDir) => {
|
||||
const client = createClient()
|
||||
const $ = createFailingShell()
|
||||
const hooks = await ECCHooksPlugin({ client, $, directory: projectDir })
|
||||
|
||||
// OpenCode may invoke the hook with no output object; the previous
|
||||
// implementation dereferenced output.prompt unconditionally and aborted
|
||||
// compaction with TypeError: undefined is not an object (#3934).
|
||||
await hooks["experimental.session.compacting"]({ sessionID: "session-1" }, undefined)
|
||||
|
||||
assert.deepStrictEqual($.calls, [], "Expected no shell probes")
|
||||
}),
|
||||
],
|
||||
[
|
||||
"permission.ask handles read-only tools correctly",
|
||||
async () => withTempProject(
|
||||
|
||||
Reference in new issue
Block a user