Skip to content

Commit 76ec18e

Browse files
committed
fix: hermetic host stub for teardown probe; peer-review follow-ups
1 parent 18fbbea commit 76ec18e

5 files changed

Lines changed: 46 additions & 16 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ node_modules/
22
dist/
33
.DS_Store
44
*.log
5+
# project-root only: local plugin registration, never committed
56
/opencode.jsonc

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ How each mechanism is enforced on OpenCode `v2` (verified on `v2.0.26`):
7373
npm install opencode-dev-framework
7474
```
7575

76-
Then add the plugin to your project's `opencode.json`:
76+
Then add the plugin to your project's `opencode.jsonc`:
7777

7878
```json
7979
{
@@ -104,7 +104,7 @@ profile from the shell; `df version` prints the plugin version.
104104
## Local development and testing
105105

106106
To test the plugin from source without publishing to npm, point OpenCode at the
107-
local repository path in your project's `opencode.json` **and** in a `tui.json`.
107+
local repository path in your project's `opencode.jsonc` **and** in a `tui.json`.
108108
The TUI module (`/df-status`, `/df-help` modals) is **not** auto-discovered for
109109
local filesystem paths — it only loads when the package is listed in the TUI
110110
config. OpenCode reads `tui.json` from the global config dir

‎docs/plans/07-publishing.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ npm run dev:clean
128128

129129
Caveats:
130130

131-
- `opencode plugin <module>` writes a `.opencode/opencode.json` file that
132-
overrides the project-level `opencode.json`. Delete it or keep its plugin
133-
list consistent with the project-level config.
131+
- `opencode plugin <module>` writes a `.opencode/opencode.json[c]` file whose
132+
plugin array **merges** with (never replaces) the project-level config.
133+
Delete it or keep its plugin list consistent with the project-level config.
134134
- Clear OpenCode's plugin cache after switching from a published version to a
135135
local path:
136136

‎docs/plans/08-notes.md‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -559,8 +559,8 @@ Keep both. The custom tool lets the agent call verification explicitly; the slas
559559

560560
## Future work — Effect-API rewrite (post-process, not scheduled)
561561

562-
**`@opencode/plugin/v2/effect` evaluation (deferred):** the V2 Effect entrypoint
563-
(`Plugin.define` via `@opencode/plugin/v2/effect` + `effect` package, scoped
562+
**`@opencode/plugin/effect` evaluation (deferred):** the V2 Effect entrypoint
563+
(`Plugin.define` via `@opencode/plugin/effect` + `effect` package, scoped
564564
plugin effect with finalizers/fibers/registrations auto-released on reload)
565565
could replace the hand-rolled `AbortController` + manual `Registration.dispose()`
566566
event loop in `src/index.ts`. Current approach works and is regression-covered
@@ -577,8 +577,9 @@ without that spike + peer review.
577577
strain observed (see strain probe below), (b) gate steps still run
578578
sequentially (`Promise.all` would cover parallelism if ever needed), (c)
579579
`@opencode/plugin@2.0.26` pins `effect@4.0.0-rc.112` — Effect 4 is still a
580-
release candidate. Two corrections to the paragraph above: the entrypoint
581-
path is `@opencode/plugin/effect` (not `@opencode/plugin/v2/effect`), and
580+
release candidate. Two corrections since first writing (paragraph above now fixed): the entrypoint
581+
path was originally recorded here as `@opencode/plugin/v2/effect` — it is
582+
`@opencode/plugin/effect` — and
582583
"port only the loop" is narrower than it sounds — the Effect `Stream`
583584
`subscribe` is only reachable through the Effect `Context`, so a
584585
promise-entrypoint spike would manage its own `Runtime` + `Scope` (fiber

‎tests/teardown.test.ts‎

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,28 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
55
import { clearConfigCache } from "../src/config";
66
import plugin from "../src/index";
77

8+
// Hermetic stub: no child process ever spawns from this file. `setup()`
9+
// hardwires the real spawner (src/index.ts `run: runCommand`), so without
10+
// this every idle-triggered gate would shell out to real `git`/`false` —
11+
// the only test file in the suite that did. `false` mimics /bin/false
12+
// (exit 1, gate-failing); `git` mimics "not a repo" so gitChangedFiles
13+
// fails fast to [] exactly as it does in these temp dirs.
14+
vi.mock("../src/host", async (importOriginal) => {
15+
const original = await importOriginal<typeof import("../src/host")>();
16+
const runCommand: typeof original.runCommand = async (command) => {
17+
if (command[0] === "false") {
18+
return { stdout: "", stderr: "", exitCode: 1, timedOut: false };
19+
}
20+
if (command[0] === "git") {
21+
return { stdout: "", stderr: "not a git repo", exitCode: 128, timedOut: false };
22+
}
23+
return { stdout: "", stderr: "", exitCode: 0, timedOut: false };
24+
};
25+
return { ...original, runCommand };
26+
});
27+
28+
type Cleanup = () => Promise<void> | void;
29+
830
describe("issue #1: teardown must not brick tool calls", () => {
931
let directory: string;
1032

@@ -54,11 +76,15 @@ describe("issue #1: teardown must not brick tool calls", () => {
5476
async function waitForPromptCalls(
5577
prompt: unknown,
5678
expected: number,
57-
timeoutMs = 10000,
79+
// Below the default vitest 5s test timeout on purpose: on failure the
80+
// terminal expect below must be what reports, not a framework timeout.
81+
timeoutMs = 3000,
5882
): Promise<void> {
5983
const mock = prompt as { mock: { calls: unknown[][] } };
6084
const deadline = Date.now() + timeoutMs;
61-
while (mock.mock.calls.length !== expected && Date.now() < deadline) {
85+
// `<` (not `!==`): an overshoot is already a failure — fail fast
86+
// instead of spinning the full timeout before the expect fires.
87+
while (mock.mock.calls.length < expected && Date.now() < deadline) {
6288
await sleep(25);
6389
}
6490
expect(mock.mock.calls.length).toBe(expected);
@@ -263,16 +289,15 @@ describe("issue #1: teardown must not brick tool calls", () => {
263289

264290
it("rapid setup/teardown cycles with in-flight streams leave no live stale loop (strain probe)", async () => {
265291
// Gate config that blocks on idle, so event-loop liveness is observable
266-
// via ctx.session.prompt: `false` exits 1 instantly (hermetic, no real
267-
// checks run) and skip_unchanged is off so the gate runs with no
268-
// changed files.
292+
// via ctx.session.prompt: stubbed `false` exits 1 (no child process
293+
// ever spawns — see the host mock at the top of this file) and
294+
// skip_unchanged is off so the gate runs with no changed files.
269295
writeFileSync(
270296
join(directory, ".opencode-dev-framework.yml"),
271297
'profile: standard\ncommands:\n typecheck: "false"\ngate:\n run_typecheck: true\n run_tests: false\n skip_unchanged: false\n block_on_failure: true\n',
272298
);
273299
clearConfigCache();
274300
const mod = plugin as unknown as { setup: (c: unknown) => Promise<unknown> };
275-
type Cleanup = () => Promise<void> | void;
276301

277302
// Reload churn: five rapid setup/teardown pairs with hanging streams.
278303
const dead: Array<{
@@ -314,13 +339,16 @@ describe("issue #1: teardown must not brick tool calls", () => {
314339
expect(live.ctx.session.prompt).toHaveBeenCalledWith(
315340
expect.objectContaining({ sessionID: "stress-live" }),
316341
);
342+
// Quiescence: a double-firing loop would land its second prompt just
343+
// after the first — settle, then confirm the count is still exactly 1.
344+
await sleep(200);
345+
expect(live.ctx.session.prompt).toHaveBeenCalledTimes(1);
317346

318347
await cleanupLive();
319348
});
320349

321350
it("a throwing event subscriber neither breaks setup nor bricks the session", async () => {
322351
const mod = plugin as unknown as { setup: (c: unknown) => Promise<unknown> };
323-
type Cleanup = () => Promise<void> | void;
324352

325353
// 1) subscribe() throws synchronously: the loop catches it, setup still
326354
// resolves, and the guardrail still works.

0 commit comments

Comments
 (0)