mirror of
https://github.com/affaan-m/ECC.git
synced 2026-08-22 23:42:24 +02:00
fix(opencode): don't crash the whole session when plugins/lib is missing (#2538)
* fix(opencode): don't crash the whole session when plugins/lib is missing (#2530) * fix: address review feedback (trailing newlines, symptom wording) * fix(opencode): also lazy-load the store in ecc-hooks.ts plugin entrypoint * test(opencode): add regression coverage for missing/present plugins/lib in ecc-hooks * fix(opencode): guard diagnostic log() against unhandled rejection; tighten test assertion * fix(opencode): only publish store after init succeeds; scrub loader errors from warning; catch sync log throws * fix(opencode): scrub raw loader error from changed-files tool; add tool-level regression tests * fix(ci): make OpenCode checks cross-platform --------- Co-authored-by: haelyra <49814733+haelyra@users.noreply.github.com>
This commit is contained in:
co-authored by
haelyra
parent
afa34d1aca
commit
591ab5cbd3
@@ -84,6 +84,92 @@ async function main() {
|
||||
|
||||
const { ECCHooksPlugin } = await loadPlugin()
|
||||
const tests = [
|
||||
[
|
||||
"plugin initializes and hooks stay usable when plugins/lib is missing",
|
||||
async () => withTempProject([], async (projectDir) => {
|
||||
const repoRoot = path.join(__dirname, "..")
|
||||
const libDir = path.join(repoRoot, ".opencode", "dist", "plugins", "lib")
|
||||
const backupDir = path.join(
|
||||
repoRoot,
|
||||
".opencode",
|
||||
"dist",
|
||||
"plugins",
|
||||
"lib.missing-store-test-backup"
|
||||
)
|
||||
fs.renameSync(libDir, backupDir)
|
||||
try {
|
||||
const client = createClient()
|
||||
const $ = createFailingShell()
|
||||
|
||||
// Plugin initialization must resolve even though changed-files-store.js
|
||||
// cannot be found -- it must not throw and crash session startup (#2530).
|
||||
const hooks = await ECCHooksPlugin({ client, $, directory: projectDir })
|
||||
|
||||
const disabledWarnings = client.logs.filter(
|
||||
(entry) =>
|
||||
entry.level === "warn" &&
|
||||
entry.message.includes("[ECC] changed-files tracking disabled") &&
|
||||
entry.message.includes("ecc repair --target opencode")
|
||||
)
|
||||
assert.strictEqual(
|
||||
disabledWarnings.length,
|
||||
1,
|
||||
"Expected exactly one warning when plugins/lib/changed-files-store.js cannot be loaded"
|
||||
)
|
||||
|
||||
// Every hook that touches the store must remain callable and must not throw.
|
||||
await hooks["file.edited"]({ path: "src/example.ts" })
|
||||
await hooks["tool.execute.after"]({ tool: "edit", args: { path: "src/other.ts" } }, {})
|
||||
await hooks["session.deleted"]()
|
||||
} finally {
|
||||
fs.renameSync(backupDir, libDir)
|
||||
}
|
||||
}),
|
||||
],
|
||||
[
|
||||
"changed-files tracking records and clears through the plugin hooks",
|
||||
async () => withTempProject([], async (projectDir) => {
|
||||
const client = createClient()
|
||||
const $ = createFailingShell()
|
||||
|
||||
const hooks = await ECCHooksPlugin({ client, $, directory: projectDir })
|
||||
|
||||
assert.ok(
|
||||
!client.logs.some(
|
||||
(entry) => entry.level === "warn" && entry.message.includes("changed-files tracking disabled")
|
||||
),
|
||||
"Did not expect a disabled warning when plugins/lib is present"
|
||||
)
|
||||
|
||||
const storeUrl = pathToFileURL(
|
||||
path.join(__dirname, "..", ".opencode", "dist", "plugins", "lib", "changed-files-store.js")
|
||||
).href
|
||||
const store = await import(storeUrl)
|
||||
|
||||
await hooks["file.edited"]({ path: "src/example.ts" })
|
||||
assert.ok(
|
||||
store
|
||||
.getChangedPaths()
|
||||
.some(
|
||||
(entry) =>
|
||||
entry.path === path.normalize("src/example.ts") &&
|
||||
entry.changeType === "modified"
|
||||
),
|
||||
"Expected file.edited to record a change via the plugin hook"
|
||||
)
|
||||
|
||||
await hooks["tool.execute.after"]({ tool: "edit", args: { path: "src/other.ts" } }, {})
|
||||
assert.ok(
|
||||
store
|
||||
.getChangedPaths()
|
||||
.some((entry) => entry.path === path.normalize("src/other.ts")),
|
||||
"Expected tool.execute.after to record a change for the edit tool"
|
||||
)
|
||||
|
||||
await hooks["session.deleted"]()
|
||||
assert.ok(!store.hasChanges(), "Expected session.deleted to clear tracked changes")
|
||||
}),
|
||||
],
|
||||
[
|
||||
"shell.env detects project markers without shelling out to test -f",
|
||||
async () => withTempProject(
|
||||
|
||||
Reference in New Issue
Block a user