Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions plugin/hooks/hooks.codex.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
{
"type": "command",
"command": "node ${CLAUDE_PLUGIN_ROOT}/scripts/stop.mjs"
},
{
"type": "command",
"command": "node ${CLAUDE_PLUGIN_ROOT}/scripts/session-end.mjs"
}
]
}
Expand Down
13 changes: 13 additions & 0 deletions test/codex-plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ describe("Codex plugin manifest (developers.openai.com/codex/plugins)", () => {
expect(existsSync(join(pluginRoot, rel)), `missing hook script: ${rel}`).toBe(true);
}
});

it("Stop hook summarizes and ends the session", () => {
type HookHandler = { type: string; command: string };
type HookEntry = { hooks: HookHandler[] };
const hooks = readJson<{ hooks: Record<string, HookEntry[]> }>(
join(pluginRoot, "hooks/hooks.codex.json"),
);
const stopCommands = hooks.hooks.Stop.flatMap((entry) =>
entry.hooks.map((handler) => handler.command),
);
expect(stopCommands).toContain("node ${CLAUDE_PLUGIN_ROOT}/scripts/stop.mjs");
expect(stopCommands).toContain("node ${CLAUDE_PLUGIN_ROOT}/scripts/session-end.mjs");
Comment on lines +101 to +105

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Assert command order, not just presence.

Line 101 flattens commands and Lines 104-105 only check containment. This misses regressions where session-end.mjs runs before stop.mjs. Please assert sequence explicitly.

Suggested test tightening
-    expect(stopCommands).toContain("node ${CLAUDE_PLUGIN_ROOT}/scripts/stop.mjs");
-    expect(stopCommands).toContain("node ${CLAUDE_PLUGIN_ROOT}/scripts/session-end.mjs");
+    const stopIdx = stopCommands.indexOf("node ${CLAUDE_PLUGIN_ROOT}/scripts/stop.mjs");
+    const endIdx = stopCommands.indexOf("node ${CLAUDE_PLUGIN_ROOT}/scripts/session-end.mjs");
+    expect(stopIdx).toBeGreaterThanOrEqual(0);
+    expect(endIdx).toBeGreaterThanOrEqual(0);
+    expect(stopIdx).toBeLessThan(endIdx);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const stopCommands = hooks.hooks.Stop.flatMap((entry) =>
entry.hooks.map((handler) => handler.command),
);
expect(stopCommands).toContain("node ${CLAUDE_PLUGIN_ROOT}/scripts/stop.mjs");
expect(stopCommands).toContain("node ${CLAUDE_PLUGIN_ROOT}/scripts/session-end.mjs");
const stopCommands = hooks.hooks.Stop.flatMap((entry) =>
entry.hooks.map((handler) => handler.command),
);
const stopIdx = stopCommands.indexOf("node ${CLAUDE_PLUGIN_ROOT}/scripts/stop.mjs");
const endIdx = stopCommands.indexOf("node ${CLAUDE_PLUGIN_ROOT}/scripts/session-end.mjs");
expect(stopIdx).toBeGreaterThanOrEqual(0);
expect(endIdx).toBeGreaterThanOrEqual(0);
expect(stopIdx).toBeLessThan(endIdx);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/codex-plugin.test.ts` around lines 101 - 105, The test currently only
checks that both stop scripts exist in stopCommands (from hooks.hooks.Stop) but
not their order; update the assertions to verify sequence explicitly by locating
the two command strings (from stopCommands) and asserting that "node
${CLAUDE_PLUGIN_ROOT}/scripts/stop.mjs" appears before "node
${CLAUDE_PLUGIN_ROOT}/scripts/session-end.mjs" (e.g., compare their indices or
assert the slice/sequence matches the expected order) so regressions that invert
these handlers fail the test.

});
});

describe("Codex marketplace.json (.codex-plugin/marketplace.json at repo root)", () => {
Expand Down