Skip to content

refactor(opencode): add pty control HttpApi coverage - #1384

Merged
Astro-Han merged 1 commit into
devfrom
codex/i936-pty-control-httpapi
Jun 18, 2026
Merged

refactor(opencode): add pty control HttpApi coverage#1384
Astro-Han merged 1 commit into
devfrom
codex/i936-pty-control-httpapi

Conversation

@Astro-Han

@Astro-Han Astro-Han commented Jun 18, 2026

Copy link
Copy Markdown
Owner

Summary

Adds local Effect HttpApi coverage for the remaining PTY JSON/control routes and the small control-plane auth/log routes:

  • PTY list, create, get, update, remove, and connect-token endpoints.
  • Control-plane auth set/remove and log endpoints.
  • Route inventory assertions that mark these endpoints as localHttpApi: true.

Why

This continues the #936 HttpApi coverage migration while keeping the production server on Hono. The PR intentionally leaves /doc, PTY WebSocket connect, permission e2e ask, automation, session, SSE, workspace WebSocket, and static UI routes outside this slice.

Related Issue

Related to #936

Human Review Status

Pending

Review Focus

Please focus on whether the new local HttpApi handlers preserve the existing Hono wire behavior for JSON parsing, 400/404 bodies, PTY missing targets, auth credential writes/removes, and log level dispatch.

Risk Notes

No production server switch. The local HttpApi coverage mirrors existing Hono behavior and keeps the WebSocket/OpenAPI-source/test-only routes Hono-only. No visible UI or copy changed, so the UI screenshot checklist item is not applicable.

How To Verify

bun install --frozen-lockfile: ok
Baseline before changes: bun test test/server/route-inventory-harness.test.ts test/server/pty-routes.test.ts test/server/auth.test.ts: 39 pass
Focused tests: bun test test/server/route-inventory-harness.test.ts test/server/pty-routes.test.ts test/server/control-routes.test.ts test/server/auth.test.ts: 51 pass
Typecheck: GOMAXPROCS=2 bun run typecheck: ok
Diff check: git diff --check origin/dev..HEAD: ok

Screenshots or Recordings

Not applicable; no visible UI changes.

Checklist

How to use this checklist:

  • Tick a box by replacing [ ] with [x]. Do not edit, add, or remove items.
  • The bot-applied label items can only be honestly ticked AFTER the PR is opened and the labeler / priority-triage bots have run — return to the PR description and tick them then.
  • Most items are required. The few that are conditional are explicitly marked (conditional); for those, leave unticked if they truly do not apply and explain why in Risk Notes. All other items must be ticked before requesting human review.
  • Type label — this PR carries exactly one of bug, enhancement, task, documentation. Type labels are author-added; the labeler bot does NOT assign them. Add the label in the GitHub UI, then tick this.
  • Routing labels — this PR carries at least one of app, ui, platform, harness, ci. The labeler bot assigns these on PR open based on changed paths. Confirm the bot's choice (or override if wrong), then tick this.
  • Priority label — this PR carries exactly one of P0, P1, P2, P3. The priority-triage bot suggests one on PR open. Confirm or override, then tick this.
  • Human Review Status above is set to Pending, Approved by @<reviewer>, or Not required: <reason> (default is Pending; "not required" is restricted to bot-authored low-risk PRs).
  • I linked the related issue, or stated in Summary why there is no issue.
  • I described the review focus and any meaningful risks.
  • I replaced the example block in How To Verify with the real verification steps and the key result for each.
  • I did not introduce unrelated refactors, dependencies, generated files, or file changes beyond the stated scope.
  • (conditional) I manually checked visible UI or copy changes when needed, with screenshots or recordings. Leave unticked only if no visible UI or copy changed.
  • (conditional) I considered macOS and Windows impact for platform, packaging, updater, signing, paths, shell, or permissions changes. Leave unticked only if no platform/packaging surface was touched.
  • (conditional) I called out docs, release notes, dependencies, permissions, credentials, deletion behavior, generated content, or local file changes when relevant. Leave unticked only if none of those surfaces was touched.
  • I reviewed the final diff for unrelated changes and suspicious dependency changes.
  • I am targeting dev, and my PR title and commit messages use Conventional Commits in English.

@Astro-Han Astro-Han added P2 Medium priority upstream Tracked upstream or vendor behavior harness Model harness, prompts, tool descriptions, and session mechanics task Narrow execution, audit, spike, migration, tracking, or upstream follow-up work tech-debt Supplemental cleanup, maintainability, architecture, test, or quality debt context labels Jun 18, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested priority: P2 (includes non-doc, non-test paths outside the low-risk bucket).

P1/P0 are reserved for maintainer confirmation. Please relabel manually if this is a release blocker, security issue, data-loss risk, or updater/runtime failure.

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@Astro-Han, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 34 minutes and 26 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: ccca7dfa-8d12-4a15-85e1-c54e0441b633

📥 Commits

Reviewing files that changed from the base of the PR and between 1b34ccd and 6fc530d.

📒 Files selected for processing (7)
  • packages/opencode/src/server/routes/instance/httpapi/groups/control.ts
  • packages/opencode/src/server/routes/instance/httpapi/groups/pty.ts
  • packages/opencode/src/server/routes/instance/httpapi/handlers/control.ts
  • packages/opencode/src/server/routes/instance/httpapi/handlers/pty.ts
  • packages/opencode/test/server/control-routes.test.ts
  • packages/opencode/test/server/pty-routes.test.ts
  • packages/opencode/test/server/route-inventory-harness.test.ts
📝 Walkthrough

Walkthrough

Two new Effect HttpApi route modules are added: ControlApi (auth credential set/remove and log write) and PtyApi (PTY session lifecycle and connect-token issuance). Each module includes schema definitions, raw HttpApiBuilder handlers wired to existing Auth.Service and Pty.Service, integration tests, and route-inventory harness updates.

Changes

Control and PTY HttpApi Route Migration

Layer / File(s) Summary
Control API schemas, endpoints, and handlers
packages/opencode/src/server/routes/instance/httpapi/groups/control.ts, packages/opencode/src/server/routes/instance/httpapi/handlers/control.ts
Defines AuthParam and LogPayload schemas; builds ControlApi with PUT/DELETE /auth/:providerID and POST /log plus OpenAPI metadata; implements controlHandlers with JSON body parsing, controlFailure normalization, writeLog level dispatch, and raw handlers calling Auth.Service.
PTY API schemas, endpoints, and handlers
packages/opencode/src/server/routes/instance/httpapi/groups/pty.ts, packages/opencode/src/server/routes/instance/httpapi/handlers/pty.ts
Defines PtyParam, PtyInfo, PtyCreateInput, PtyUpdateInput, and ConnectToken schemas; builds PtyApi with six endpoints including connectToken; implements ptyHandlers with notFound/ptyFailure error normalization, session existence checks, and PtyTicket issuance.
Integration tests and route-inventory harness
packages/opencode/test/server/control-routes.test.ts, packages/opencode/test/server/pty-routes.test.ts, packages/opencode/test/server/route-inventory-harness.test.ts
Adds control-route tests (OpenAPI spec, auth round-trip, log dispatch with warn override, malformed JSON 400), PTY-route tests (OpenAPI spec, full lifecycle, 404 for missing sessions, malformed JSON 400), and route-inventory assertions for hono/localHttpApi classification.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  rect rgba(100, 149, 237, 0.5)
    note over Client,Auth.Service: Control API
    Client->>controlHandlers: PUT /auth/:providerID {credentials}
    controlHandlers->>parseJsonBody: validate body
    parseJsonBody-->>controlHandlers: typed credentials or 400
    controlHandlers->>Auth.Service: authSet(providerID, credentials)
    controlHandlers-->>Client: 200 true

    Client->>controlHandlers: POST /log {level, message, extra}
    controlHandlers->>parseJsonBody: validate LogPayload
    controlHandlers->>Log.create: writeLog(level, message, extra)
    controlHandlers-->>Client: 200 true
  end
  rect rgba(60, 179, 113, 0.5)
    note over Client,Pty.Service: PTY API
    Client->>ptyHandlers: POST /pty {command, args}
    ptyHandlers->>Pty.Service: create(input)
    ptyHandlers-->>Client: 200 PtyInfo

    Client->>ptyHandlers: POST /pty/:ptyID/connect-token
    ptyHandlers->>Pty.Service: get(ptyID) — existence check
    ptyHandlers->>Pty.Service: issueTicket(ptyID)
    ptyHandlers-->>Client: 200 {ticket, expires_in}

    Client->>ptyHandlers: DELETE /pty/:ptyID
    ptyHandlers->>Pty.Service: get(ptyID) — existence check
    ptyHandlers->>Pty.Service: remove(ptyID)
    ptyHandlers-->>Client: 200 true
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Astro-Han/pawwork#949: Introduced the route-inventory harness (route-inventory-harness.test.ts) whose localHttpApi/hono classification expectations are directly extended by this PR for the new PTY and control-plane routes.

Poem

🐇 Hoppin' through the terminal with glee,
New PTY routes wired up, fresh as can be!
Auth set and remove, logs neatly dispatched,
Connect tokens issued, sessions cleanly patched.
The harness confirms every route's in its place—
This rabbit approves of this elegant space! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'refactor(opencode): add pty control HttpApi coverage' is concise, specific, and accurately describes the main change—adding HttpApi coverage for PTY and control routes as part of the #936 migration.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The pull request description is comprehensive and follows the template structure, including Summary, Why, Related Issue, Human Review Status, Review Focus, Risk Notes, How To Verify with actual test results, Screenshots/Recordings statement, and a complete checklist.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/i936-pty-control-httpapi

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🧹 Nitpick comments (3)
packages/opencode/src/server/routes/instance/httpapi/groups/pty.ts (1)

12-43: ⚡ Quick win

Use Schema.Class for multi-field PTY schema models.

Lines 12-43 define multi-field models (PtyInfo, PtyCreateInput, PtyUpdateInput, ConnectToken) with Schema.Struct; these should be Schema.Class per repo conventions.

As per coding guidelines: Use Schema.Class for multi-field data in Effect schemas.

🤖 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 `@packages/opencode/src/server/routes/instance/httpapi/groups/pty.ts` around
lines 12 - 43, The four schema definitions PtyInfo, PtyCreateInput,
PtyUpdateInput, and ConnectToken are currently using Schema.Struct but should be
converted to Schema.Class per repository conventions for multi-field data models
in Effect schemas. Replace Schema.Struct with Schema.Class for all four of these
schema definitions while keeping the field definitions and structure unchanged.

Source: Coding guidelines

packages/opencode/src/server/routes/instance/httpapi/groups/control.ts (1)

11-16: ⚡ Quick win

Use Schema.Class for the multi-field log payload schema.

Lines 11-16 define a multi-field Effect schema with Schema.Struct. Converting this to Schema.Class keeps this file aligned with the repo’s Effect schema conventions.

♻️ Proposed refactor
-const LogPayload = Schema.Struct({
-  service: Schema.String,
-  level: Schema.Literals(["debug", "info", "error", "warn"]),
-  message: Schema.String,
-  extra: Schema.optional(Schema.Record(Schema.String, Schema.Any)),
-})
+class LogPayload extends Schema.Class<LogPayload>("ControlLogPayload")({
+  service: Schema.String,
+  level: Schema.Literals(["debug", "info", "error", "warn"]),
+  message: Schema.String,
+  extra: Schema.optional(Schema.Record(Schema.String, Schema.Any)),
+}) {}

As per coding guidelines: Use Schema.Class for multi-field data in Effect schemas.

🤖 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 `@packages/opencode/src/server/routes/instance/httpapi/groups/control.ts`
around lines 11 - 16, The LogPayload schema definition is currently using
Schema.Struct for a multi-field data structure. Convert this schema to use
Schema.Class instead, as per the repository's Effect schema conventions for
multi-field data. Keep the same fields (service, level, message, extra) with
their existing types and optional properties when refactoring from Schema.Struct
to Schema.Class.

Source: Coding guidelines

packages/opencode/src/server/routes/instance/httpapi/handlers/control.ts (1)

20-42: ⚡ Quick win

Extract JSON parsing helpers into a shared module.

Lines 20-42 are duplicated in packages/opencode/src/server/routes/instance/httpapi/handlers/pty.ts. Pulling these into one shared helper will prevent behavior drift in 400 handling and content-type matching.

🤖 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 `@packages/opencode/src/server/routes/instance/httpapi/handlers/control.ts`
around lines 20 - 42, The functions isJsonContentType, badRequestJson, and
parseJsonBody are duplicated across control.ts and pty.ts, which can lead to
behavior drift during maintenance. Extract these three functions into a new
shared utility module in a common location within the httpapi handlers
directory, then import and use these functions from the shared module in both
control.ts and pty.ts, removing the duplicate definitions from each file.
🤖 Prompt for all review comments with 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.

Inline comments:
In `@packages/opencode/src/server/routes/instance/httpapi/groups/pty.ts`:
- Around line 40-43: The ConnectToken schema structure defines expires_in as a
plain Schema.Number, but the actual implementation in ticket.ts issues
expires_in as a positive integer. Update the expires_in field definition in the
ConnectToken schema to apply a positive integer constraint instead of accepting
any number, ensuring the schema accurately reflects the contract of what is
actually being issued and prevents downstream consumers from receiving invalid
values.

---

Nitpick comments:
In `@packages/opencode/src/server/routes/instance/httpapi/groups/control.ts`:
- Around line 11-16: The LogPayload schema definition is currently using
Schema.Struct for a multi-field data structure. Convert this schema to use
Schema.Class instead, as per the repository's Effect schema conventions for
multi-field data. Keep the same fields (service, level, message, extra) with
their existing types and optional properties when refactoring from Schema.Struct
to Schema.Class.

In `@packages/opencode/src/server/routes/instance/httpapi/groups/pty.ts`:
- Around line 12-43: The four schema definitions PtyInfo, PtyCreateInput,
PtyUpdateInput, and ConnectToken are currently using Schema.Struct but should be
converted to Schema.Class per repository conventions for multi-field data models
in Effect schemas. Replace Schema.Struct with Schema.Class for all four of these
schema definitions while keeping the field definitions and structure unchanged.

In `@packages/opencode/src/server/routes/instance/httpapi/handlers/control.ts`:
- Around line 20-42: The functions isJsonContentType, badRequestJson, and
parseJsonBody are duplicated across control.ts and pty.ts, which can lead to
behavior drift during maintenance. Extract these three functions into a new
shared utility module in a common location within the httpapi handlers
directory, then import and use these functions from the shared module in both
control.ts and pty.ts, removing the duplicate definitions from each file.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 75646aec-41c7-4630-b385-a2f0220cf7a1

📥 Commits

Reviewing files that changed from the base of the PR and between 67eb846 and 1b34ccd.

📒 Files selected for processing (7)
  • packages/opencode/src/server/routes/instance/httpapi/groups/control.ts
  • packages/opencode/src/server/routes/instance/httpapi/groups/pty.ts
  • packages/opencode/src/server/routes/instance/httpapi/handlers/control.ts
  • packages/opencode/src/server/routes/instance/httpapi/handlers/pty.ts
  • packages/opencode/test/server/control-routes.test.ts
  • packages/opencode/test/server/pty-routes.test.ts
  • packages/opencode/test/server/route-inventory-harness.test.ts

Comment thread packages/opencode/src/server/routes/instance/httpapi/groups/pty.ts
@Astro-Han
Astro-Han force-pushed the codex/i936-pty-control-httpapi branch from 1b34ccd to ff17a18 Compare June 18, 2026 21:41
@Astro-Han
Astro-Han force-pushed the codex/i936-pty-control-httpapi branch from ff17a18 to 6fc530d Compare June 18, 2026 21:57
@Astro-Han
Astro-Han merged commit 140d614 into dev Jun 18, 2026
37 checks passed
@Astro-Han
Astro-Han deleted the codex/i936-pty-control-httpapi branch June 18, 2026 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

harness Model harness, prompts, tool descriptions, and session mechanics P2 Medium priority task Narrow execution, audit, spike, migration, tracking, or upstream follow-up work tech-debt Supplemental cleanup, maintainability, architecture, test, or quality debt context upstream Tracked upstream or vendor behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant