mirror of
https://github.com/affaan-m/ECC.git
synced 2026-11-17 13:32:18 +00:00
fix(opencode): address round-2 review findings on the hooks surface
- R2-1: the V2 execute.after adapter passed { result: ... } as the tool
output; skill-run-tracker derives outcomes from error fields on the
response itself, so failed skills recorded as successes. The adapter
now forwards the raw event.result ?? event.output. Covered by a T05
assertion that an is_error skill event records outcome failure and a
clean event still records success.
- R2-2: cmd.exe expands %VAR% and honors embedded quotes even inside
double quotes, so escaping " was unsafe. spawnCommand now refuses
arguments carrying ", %, CR or LF (nothing spawns; the rejection
surfaces through the formatter's catch) and emits the canonical /s
form with one outer quote pair around the whole command. T01 asserts
the outer pair, strips it before inspecting the inner quoting, and
covers two refusal payloads.
- R2-3: repo review rules ban console.log; the client-less log fallback
and the startup line now use console.info (identical stdout behavior).
- R2-4: declined installs recorded before the barrel split retained the
old module/factory stub in plugins/index.ts, and a later selective
install (e.g. commands-core) has no operation rewriting it, so the
strict deactivation gate failed the install after all writes landed.
The strict branch now migrates such retained files in place only when
ownership is proven twice (managed-recorded contentSha256 matches disk
AND disk equals an exact historical disabled-stub payload), written
through writeFileNoFollow with that digest as expectedContent;
anything else keeps failing closed. The preflight branch accepts an
already-inactive recorded config under the same digest-verified
condition, since selective installs legitimately plan no .opencode
writes. New lifecycle test covers both the migration (install ok,
doctor clean, ownership retained) and the refusal path (mis-recorded
digest never grants a rewrite).
This commit is contained in:
1 parent
6286b7c2f1
commit
76f8ea4bd3
5 files changed
+234
-10
No files matched your search
@@ -830,17 +830,42 @@ async function main() {
|
||||
assert.strictEqual(call.options.shell, false, "spawn must never use shell:true")
|
||||
if (process.platform === "win32") {
|
||||
// Routed through cmd.exe ONLY as the documented .cmd-shim
|
||||
// escape: /d /s /c with every argument double-quoted, so the
|
||||
// & ; | characters in the path are data, not separators.
|
||||
// escape: /d /s /c with the complete command string wrapped in
|
||||
// one outer quote pair (which cmd strips) and every argument
|
||||
// double-quoted inside it, so the & ; | characters in the path
|
||||
// are data, not separators.
|
||||
assert.match(call.file, /cmd\.exe$/i)
|
||||
assert.deepStrictEqual(call.args.slice(0, 3), ["/d", "/s", "/c"])
|
||||
const inner = call.args[3]
|
||||
const commandString = call.args[3]
|
||||
assert.ok(
|
||||
commandString.startsWith('"') && commandString.endsWith('"'),
|
||||
`the full command must carry the /s outer quote pair: ${commandString}`,
|
||||
)
|
||||
// cmd strips exactly the outer pair; what it then executes is
|
||||
// the remainder.
|
||||
const inner = commandString.slice(1, -1)
|
||||
assert.ok(inner.includes(`"${evil}"`), `evil path must be quoted inside: ${inner}`)
|
||||
assert.strictEqual(
|
||||
unquotedMetachars(inner),
|
||||
"",
|
||||
`unquoted shell metacharacters survived: ${inner}`,
|
||||
)
|
||||
|
||||
// R2-2: characters cmd expands or that terminate quoting even
|
||||
// INSIDE double quotes (quote, percent, line breaks) must be
|
||||
// refused outright — never escaped, never spawned.
|
||||
resetSpawns()
|
||||
await hooks["file.edited"]({ path: 'evil" %PATH% expand.ts' })
|
||||
assert.strictEqual(spawnCalls.length, 0, "quote/percent-bearing args must never reach spawn")
|
||||
assert.ok(
|
||||
client.logs.some(
|
||||
(entry) => entry.level === "debug" && entry.message.includes("unsafe argument"),
|
||||
),
|
||||
"the shim refusal must be visible in the debug log",
|
||||
)
|
||||
resetSpawns()
|
||||
await hooks["file.edited"]({ path: "evil\r\nx && calc.ts" })
|
||||
assert.strictEqual(spawnCalls.length, 0, "line-break-bearing args must never reach spawn")
|
||||
} else {
|
||||
assert.strictEqual(call.file, "npx")
|
||||
assert.deepStrictEqual(call.args, ["prettier", "--write", evil])
|
||||
@@ -965,6 +990,45 @@ async function main() {
|
||||
await ctx.state.handlers["tool.execute.before"]({ tool: "write", callID: "c1", input: { filePath: "a.ts" } })
|
||||
await ctx.state.handlers["tool.execute.after"]({ tool: "write", callID: "c1", input: { filePath: "a.ts" }, output: {} })
|
||||
|
||||
// R2-1: the execute.after adapter must hand the skill tracker the RAW
|
||||
// tool output. The tracker reads error fields (is_error/isError/
|
||||
// status/error) directly off tool_response, so a `{ result: … }`
|
||||
// wrapper made failed skills record as successes.
|
||||
{
|
||||
const previousHome = process.env.HOME
|
||||
const previousUserProfile = process.env.USERPROFILE
|
||||
const skillHome = fs.mkdtempSync(path.join(os.tmpdir(), "ecc-v2-skill-home-"))
|
||||
process.env.HOME = skillHome
|
||||
process.env.USERPROFILE = skillHome
|
||||
try {
|
||||
await ctx.state.handlers["tool.execute.after"]({
|
||||
tool: "skill",
|
||||
callID: "c2",
|
||||
input: { name: "code-review" },
|
||||
output: { output: "skill crashed", is_error: true },
|
||||
})
|
||||
const runs = readRecordedRuns(skillHome)
|
||||
assert.strictEqual(runs.length, 1, "the skill run must be recorded through V2")
|
||||
assert.strictEqual(
|
||||
runs[0].outcome,
|
||||
"failure",
|
||||
"an error-bearing skill response must record as failure, not success",
|
||||
)
|
||||
await ctx.state.handlers["tool.execute.after"]({
|
||||
tool: "skill",
|
||||
callID: "c3",
|
||||
input: { name: "code-review" },
|
||||
output: { output: "all good" },
|
||||
})
|
||||
const both = readRecordedRuns(skillHome)
|
||||
assert.strictEqual(both.length, 2)
|
||||
assert.strictEqual(both[1].outcome, "success", "clean responses still record as success")
|
||||
} finally {
|
||||
restoreEnv({ HOME: previousHome, USERPROFILE: previousUserProfile })
|
||||
fs.rmSync(skillHome, { recursive: true, force: true })
|
||||
}
|
||||
}
|
||||
|
||||
// Session compaction appends ECC context through the V2 event object.
|
||||
const compactionEvent = { system: [] }
|
||||
await ctx.state.handlers["session.compaction"](compactionEvent)
|
||||
|
||||
Reference in new issue
Block a user