Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 3 additions & 43 deletions .opencode/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,46 +35,6 @@
*/

// Export the main plugin

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Built entry export contract has no regression guard

The root entry now correctly exports only the default plugin, but the automated checks never import .opencode/dist/index.js and assert that its export namespace is exactly a function-valued default. tests/scripts/build-opencode.test.js verifies that the build succeeds and artifacts exist, while the hook suite imports dist/plugins/ecc-hooks.js directly. A temporary named string export still let the existing build test pass while the compiled-entry export-shape check failed. Add a post-build assertion for Object.keys(module) === ["default"] and typeof module.default === "function" so a future named export cannot silently restore the legacy-loader failure.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Artifacts

Executable built OpenCode entry export-shape checker

  • The authored Node harness dynamically imports a built entry and enforces the legacy loader's default-only function-export contract, providing the missing executable assertion.

Base build fails the OpenCode loader export-shape check

  • The disposable parent revision was built and its entry exposed ECCHooksPlugin, VERSION, default, and metadata; the executable check failed, confirming the pre-fix loader-incompatible shape.

PR head build has default-only entry and focused suites pass

  • The disposable PR-head revision was built, its entry exported only default:function, and both existing focused test suites passed, confirming the current fix works.

Simulated named export passes existing test but fails entry-shape check

  • A disposable named string export made the existing build test pass while the built-entry checker failed, proving the missing automated regression coverage.

Disposable regression source restored and worktrees removed

  • The disposable PR-head source was restored and rebuilt with only the default export before both temporary worktrees were removed, leaving no test mutation behind.

View artifacts

T-Rex Ran code and verified through T-Rex

export { ECCHooksPlugin, default } from "./plugins/index.js"

// Export individual components for selective use
export * from "./plugins/index.js"

// Version export
export const VERSION = "1.6.0"

// Plugin metadata
export const metadata = {
name: "ecc-universal",
version: VERSION,
description: "ECC plugin for OpenCode",
author: "affaan-m",
features: {
agents: 13,
commands: 31,
skills: 37,
configAssets: true,
hookEvents: [
"file.edited",
"tool.execute.before",
"tool.execute.after",
"session.created",
"session.idle",
"session.deleted",
"file.watcher.updated",
"permission.ask",
"todo.updated",
"shell.env",
"experimental.session.compacting",
],
customTools: [
"run-tests",
"check-coverage",
"security-audit",
"format-code",
"lint-check",
"git-summary",
"changed-files",
],
},
}
// opencode's legacy plugin loader iterates every module export and throws if
// any is not a plugin function, so only the plugin function may be exported.
export { default } from "./plugins/index.js"
69 changes: 69 additions & 0 deletions tests/scripts/build-opencode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,75 @@ function main() {
assert.strictEqual(result.status, 0, result.stderr)
assert.ok(fs.existsSync(distEntry), ".opencode/dist/index.js should exist after build")
}],
["built OpenCode entry exports only the plugin function", () => {
const check = `
const assert = require("assert")
const { pathToFileURL } = require("url")

async function main() {
let mod
try {
mod = await import(pathToFileURL(process.argv[1]).href)
} catch (error) {
console.error(error)
process.exit(1)
}
assert.deepStrictEqual(Object.keys(mod).sort(), ["default"])
assert.strictEqual(typeof mod.default, "function")

let shellCalls = 0
const plugin = await mod.default({
client: { app: { log: () => {} } },
$: async () => {
shellCalls += 1
throw new Error("$ must not be called during plugin init")
},
directory: process.cwd(),
worktree: process.cwd(),
})
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
assert.strictEqual(shellCalls, 0, "$ must not be called during plugin init")
assert.ok(plugin && typeof plugin === "object", "default export must return a plugin record")
const expectedHooks = [
"file.edited",
"tool.execute.after",
"tool.execute.before",
"session.created",
"session.idle",
"session.deleted",
"file.watcher.updated",
"todo.updated",
"shell.env",
"experimental.session.compacting",
"permission.ask",
]
for (const hook of expectedHooks) {
assert.strictEqual(typeof plugin[hook], "function", "missing hook: " + hook)
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
assert.deepStrictEqual(
Object.keys(plugin.tool).sort(),
["changed-files", "dependency-analyzer"],
"plugin.tool must expose exactly the custom tools"
)
for (const toolName of ["changed-files", "dependency-analyzer"]) {
const toolDefinition = plugin.tool[toolName]
assert.ok(toolDefinition && typeof toolDefinition === "object", "missing tool: " + toolName)
assert.strictEqual(typeof toolDefinition.description, "string", toolName + " must declare a description")
assert.ok(toolDefinition.args && typeof toolDefinition.args === "object", toolName + " must declare args")
assert.strictEqual(typeof toolDefinition.execute, "function", toolName + " must declare an execute function")
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}

main().catch((error) => {
console.error(error)
process.exit(1)
})
`
const result = spawnSync(process.execPath, ["-e", check, distEntry], {
cwd: repoRoot,
encoding: "utf8",
})
assert.strictEqual(result.status, 0, result.stderr)
}],
["npm pack includes the compiled OpenCode dist payload", () => {
const result = spawnSync("npm", ["pack", "--dry-run", "--json"], {
cwd: repoRoot,
Expand Down