-
Notifications
You must be signed in to change notification settings - Fork 1
test(codex): add real plugin lifecycle smoke #255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
corylanou
merged 1 commit into
main
from
detent/gopher-ai-gopherguides_gopher-ai_252-3f33d6fd1642
Jul 19, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| import argparse | ||
| import json | ||
| import threading | ||
| import time | ||
| from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| class LifecycleHandler(SimpleHTTPRequestHandler): | ||
| request_count = 0 | ||
| request_lock = threading.Lock() | ||
| state_dir = Path() | ||
|
|
||
| def do_POST(self): | ||
| if self.path != "/v1/responses": | ||
| self.send_error(404) | ||
| return | ||
|
|
||
| content_length = int(self.headers.get("Content-Length", "0")) | ||
| self.rfile.read(content_length) | ||
|
|
||
| with self.request_lock: | ||
| type(self).request_count += 1 | ||
| request_number = type(self).request_count | ||
|
|
||
| self.state_dir.joinpath(f"{request_number}.requested").write_text( | ||
| self.path, encoding="utf-8" | ||
| ) | ||
| release_path = self.state_dir / f"{request_number}.release" | ||
| deadline = time.monotonic() + 90 | ||
| while not release_path.exists() and time.monotonic() < deadline: | ||
| time.sleep(0.05) | ||
|
|
||
| if not release_path.exists(): | ||
| self.send_error(504, "response release timed out") | ||
| return | ||
|
|
||
| response_id = f"response_{request_number}" | ||
| events = [ | ||
| { | ||
| "type": "response.created", | ||
| "response": {"id": response_id}, | ||
| }, | ||
| { | ||
| "type": "response.output_item.done", | ||
| "item": { | ||
| "type": "message", | ||
| "role": "assistant", | ||
| "id": response_id, | ||
| "content": [ | ||
| {"type": "output_text", "text": "lifecycle-ok"} | ||
| ], | ||
| }, | ||
| }, | ||
| { | ||
| "type": "response.completed", | ||
| "response": { | ||
| "id": response_id, | ||
| "usage": { | ||
| "input_tokens": 0, | ||
| "input_tokens_details": None, | ||
| "output_tokens": 0, | ||
| "output_tokens_details": None, | ||
| "total_tokens": 0, | ||
| }, | ||
| }, | ||
| }, | ||
| ] | ||
| body = "".join( | ||
| f"event: {event['type']}\ndata: {json.dumps(event, separators=(',', ':'))}\n\n" | ||
| for event in events | ||
| ).encode("utf-8") | ||
|
|
||
| self.send_response(200) | ||
| self.send_header("Content-Type", "text/event-stream") | ||
| self.send_header("Content-Length", str(len(body))) | ||
| self.send_header("Connection", "close") | ||
| self.end_headers() | ||
| self.wfile.write(body) | ||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("--directory", required=True, type=Path) | ||
| parser.add_argument("--port-file", required=True, type=Path) | ||
| parser.add_argument("--state-dir", required=True, type=Path) | ||
| args = parser.parse_args() | ||
|
|
||
| args.state_dir.mkdir(parents=True, exist_ok=True) | ||
| LifecycleHandler.state_dir = args.state_dir | ||
|
|
||
| def handler(*handler_args, **handler_kwargs): | ||
| return LifecycleHandler( | ||
| *handler_args, directory=str(args.directory), **handler_kwargs | ||
| ) | ||
|
|
||
| server = ThreadingHTTPServer(("127.0.0.1", 0), handler) | ||
| port_path = args.port_file.with_suffix(".tmp") | ||
| port_path.write_text(str(server.server_port), encoding="utf-8") | ||
| port_path.replace(args.port_file) | ||
| server.serve_forever() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a prior
--userrun was interrupted and left the current-version cache root incomplete, this restore path backs up that broken directory, letscodex plugin addrecreate a good one, and then deletes the fresh target and copies the broken backup back over it. In that recovery scenario the installer exits successfully but the plugin remains missing files or executable hooks, so a normal rerun cannot heal the cache; only restore roots that were actually removed/superseded, or avoid overwriting an existing freshly installed target.Useful? React with 👍 / 👎.