Skip to content

feat(lab): CL-04 CLI and management read surfaces - #1378

Merged
Wibias merged 2 commits into
lidge-jun:devfrom
Wibias:feat/cl-04-lab-read-surfaces
Aug 9, 2026
Merged

feat(lab): CL-04 CLI and management read surfaces#1378
Wibias merged 2 commits into
lidge-jun:devfrom
Wibias:feat/cl-04-lab-read-surfaces

Conversation

@Wibias

@Wibias Wibias commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add read-only lab query layer (src/lab/query/) over the CL-02 SQLite projection with cursor pagination, DTO sanitization, and stable catalog/status surfaces.
  • Wire ocx lab CLI subcommands and management API routes for status, verdicts, subjects, observations, events, artifacts, and catalog reads.
  • Add tests/lab-read-surfaces.test.ts covering query, management API, CLI, and privacy boundaries.

Out of scope

  • Lab write/mutation paths (ledger append, purge, live probe execution) beyond existing CL-01/02/03 behavior.
  • GUI surfaces for compatibility lab.
  • Changes to CL-01/02/03 conformance, ledger, or live-probe semantics.

Validation commands/results

  • bun x tsc --noEmit — pass
  • bun test tests/lab-read-surfaces.test.ts — 17 pass, 0 fail
  • bun test tests/lab-conformance-harness.test.ts — 17 pass, 0 fail
  • bun test tests/lab-evidence-ledger.test.ts — 37 pass, 4 fail (Windows SQLite file lock in wipeSqlite during repeated rebuildLabProjection; same failures on base 68c71a4 without CL-04)
  • bun test tests/lab-live-probe.test.ts — 19 pass, 0 fail
  • bun test tests/lab-live-sandbox.test.ts — 17 pass, 0 fail
  • bun run privacy:scan — pass

Security notes

  • Public DTOs pass through sanitizePublicText; corruption/artifact error fields are redacted in read surfaces.
  • Management lab routes are read-only and reuse existing management auth boundaries.
  • CLI lab is registered with codex shim autorestore skip to avoid side effects on read-only invocations.

Summary by CodeRabbit

  • New Features

    • Added read-only Compatibility Lab inspection through the ocx lab CLI.
    • Added management API access for status, catalog, verdicts, subjects, observations, events, and artifacts.
    • Added filtering, pagination, cursors, JSON output, resource lookups, and catalog metadata.
    • Added privacy-safe result formatting and structured errors for unavailable or incompatible projections.
  • Bug Fixes

    • Prevented automatic restore behavior when running the lab command.
  • Documentation

    • Added CLI help and usage details for Compatibility Lab commands.

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: c8cf5c01-d9ce-4057-b979-2a84ab7c1ed3

📥 Commits

Reviewing files that changed from the base of the PR and between 1907b90 and 1450238.

📒 Files selected for processing (10)
  • devlog/_plan/260807_compatibility_lab/001_pr_stack_status.md
  • devlog/_plan/260807_compatibility_lab/004_cl04_read_surfaces.md
  • src/cli/codex-shim-autorestore.ts
  • src/cli/help.ts
  • src/cli/lab.ts
  • src/lab/query/connection.ts
  • src/lab/query/dto-map.ts
  • src/lab/query/queries.ts
  • src/server/management/lab-routes.ts
  • tests/lab-read-surfaces.test.ts

📝 Walkthrough

Walkthrough

The PR adds read-only Compatibility Lab projection queries, catalog discovery, management API routes, and ocx lab CLI commands. It defines DTOs, pagination cursors, projection validation, privacy-safe mapping, structured errors, and tests.

Changes

Compatibility Lab read surfaces

Layer / File(s) Summary
Projection contracts and read infrastructure
src/lab/query/types.ts, src/lab/query/connection.ts, src/lab/query/cursor.ts, src/lab/query/dto-map.ts, src/lab/query/errors.ts, src/lab/query/constants.ts, src/lab/query/index.ts, src/lab/index.ts
Defines DTOs and filters, validates read-only SQLite projections, implements bounded cursor pagination, maps event and subject variants, and sanitizes public text.
Projection queries and catalog
src/lab/query/queries.ts, src/lab/query/catalog.ts
Adds filtered status, verdict, subject, observation, event, artifact, and catalog queries with stable ordering, pagination, lookups, and scenario metadata mapping.
Management API routes
src/server/management/lab-routes.ts, src/server/management-api.ts
Adds GET-only /api/lab routes with validation, pagination envelopes, structured errors, resource lookups, and dispatch integration.
CLI command and validation surfaces
src/cli/lab.ts, src/cli/index.ts, src/cli/help.ts, src/cli/codex-shim-autorestore.ts, tests/lab-read-surfaces.test.ts
Adds read-only ocx lab subcommands, text and JSON output, command help, shim handling, and tests for queries, API responses, CLI behavior, read-only operation, and privacy redaction.
Implementation records and stack status
devlog/_plan/260807_compatibility_lab/001_pr_stack_status.md, devlog/_plan/260807_compatibility_lab/004_cl04_read_surfaces.md
Records CL-03 acceptance and the delivered CL-04 scope, validation, blockers, and exclusions.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Operator
  participant LabCLI as ocx lab
  participant ManagementAPI as management API
  participant LabQuery as lab query layer
  participant SQLite as read-only SQLite projection
  Operator->>LabCLI: request projection inspection
  LabCLI->>LabQuery: execute filtered query
  Operator->>ManagementAPI: GET /api/lab request
  ManagementAPI->>LabQuery: validate and execute route query
  LabQuery->>SQLite: open and read projection
  SQLite-->>LabQuery: return rows and metadata
  LabQuery-->>LabCLI: return DTOs or typed errors
  LabQuery-->>ManagementAPI: return DTOs or typed errors
  LabCLI-->>Operator: print text or JSON
  ManagementAPI-->>Operator: return JSON response
Loading

Possibly related PRs

Suggested reviewers: ingwannu, lidge-jun

🚥 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the CL-04 lab feature and its CLI and management read surfaces, which are the primary changes in the pull request.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the enhancement New feature or request label Aug 9, 2026
@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

✅ READY

  • all PR quality gates passed.

UI screenshot waived by the gui-screenshot-waived label.

Hygiene

Deterministic PR hygiene checks passed.

@Wibias Wibias added the gui-screenshot-waived Maintainer waiver for false-positive GUI screenshot requirements label Aug 9, 2026
@Wibias
Wibias marked this pull request as ready for review August 9, 2026 20:58

@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: 21

🤖 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 `@devlog/_plan/260807_compatibility_lab/001_pr_stack_status.md`:
- Around line 191-207: Synchronize the earlier Authorization section with the
current CL-03 and CL-04 status recorded in the merge and start logs: mark CL-03
accepted/closed and CL-04 authorized/in progress, or explicitly label the older
statuses as historical with a date. Update only the relevant authorization
record.

In `@devlog/_plan/260807_compatibility_lab/004_cl04_read_surfaces.md`:
- Around line 37-45: Update the Validation (local) section to record the outcome
of every listed command, including 17/17 for the read-surface tests. Document
that tests/lab-evidence-ledger.test.ts completed 37/41 with four pre-existing
Windows SQLite EPERM flakes, and clearly distinguish this known exception from
successful validations.

In `@src/cli/codex-shim-autorestore.ts`:
- Line 20: Add a short explanatory comment immediately above the `if (command
=== "lab") return true;` condition, documenting that `ocx lab` is read-only and
must not trigger autorestore side effects. Preserve the existing behavior and
avoid changing neighboring command handling.

In `@src/cli/help.ts`:
- Around line 267-280: Use the “catalog” spelling consistently in the lab help
text and the empty-state message in the lab CLI flow, including the visible
`lab.details` catalog entry and the `src/cli/lab.ts` message currently using
“catalogue”.

In `@src/cli/lab.ts`:
- Around line 141-142: Define a shared assertRange helper in src/cli/lab.ts that
rejects cases where from is greater than to, then call it after parsing the
bounds in the verdicts, observations, and events subcommands. Reuse the helper
consistently while preserving the existing nonnegative bound validation.
- Around line 166-175: Update the single-resource JSON output in the “subject”
case to match the sibling “event” and “artifact” cases by passing only the
subject object to printData, removing the redundant subjectId envelope field
while preserving the existing subject lookup and human-readable title.
- Around line 136-156: Validate raw CLI enum options before constructing query
filters, covering the layer, verdict, and other enum-like options in the lab
read commands handled by the relevant command cases in lab.ts. Reuse the
existing enum definitions and invalid-input error/usage behavior so values such
as an unknown layer are rejected with the API-equivalent invalid_layer response,
rather than being passed to queryLabVerdicts or related query functions.
- Around line 261-264: Update the error handling around runCliAction in
src/cli/lab.ts so LabProjectionUnavailableError and
LabProjectionIncompatibleError remain distinct state errors instead of being
wrapped as CliUsageError. Introduce or reuse LabStateError, add the matching
branch in the runtime-api runCliAction mapping, and assign the established
non-usage exit code after checking existing conventions. Preserve usage output
and the usage exit code only for genuine command or syntax errors.
- Around line 122-135: Update handleLabCommand to remove global flags from argv
before destructuring the subcommand, so flag-only invocations such as --json
default to status. Ensure takeFlag and subsequent subcommand argument handling
operate on the flag-stripped arguments while preserving normal subcommand
behavior.
- Around line 206-216: Validate excludedRaw immediately after parsing in the lab
events command, rejecting any value other than "true" or "false" before calling
queryLabEvents. Preserve undefined only when --excluded was not provided, and
retain the existing boolean conversion for valid values.
- Around line 79-113: Extract the repeated pagination hint construction into a
shared helper and have verdictLines, subjectListLines, observationLines,
eventListLines, and artifactLines use it while preserving their existing
empty-result behavior. Update all five formatter signatures to use the
synchronous query result types directly, removing the no-op Awaited<> wrappers
and matching statusSummary and catalogLines.

In `@src/lab/query/connection.ts`:
- Around line 22-25: Move the `new Database(sqlitePath, { readonly: true })`
call into the existing `try` block in the connection logic, ensuring constructor
failures are caught and rethrown as `LabProjectionUnavailableError` without
exposing the SQLite path. Keep the existing missing-file handling and successful
database return behavior unchanged.
- Around line 74-77: Update countTable to validate table against an explicit
allowlist of the seven supported table identifiers before interpolating it into
the SQL query. Reject any value not on that allowlist, while preserving the
existing count query for valid names.

In `@src/lab/query/dto-map.ts`:
- Around line 205-213: Update mapValidatedEventToDto so the exclusionReason
assigned in the shared base object is passed through the same sanitizer used by
mapEventListRow and mapObservationRow, ensuring every event DTO branch inherits
sanitized text while preserving null handling.

In `@src/lab/query/queries.ts`:
- Around line 339-349: Remove the unused joinSql declaration and its
interpolation from the query in the surrounding query function, and change the
SELECT clause from SELECT DISTINCT to SELECT. Preserve the existing filters,
ordering, pagination, and parameter handling.
- Around line 375-383: Remove the unreachable fallback after
parseEventPayloadToDto in the event-mapping flow, returning the parser result
directly while preserving excluded and exclusionReason arguments. Then remove
the now-unused validateLabEvent and mapValidatedEventToDto imports from the
file.

In `@src/server/management/lab-routes.ts`:
- Around line 250-254: The three resource routes let malformed encoded path
segments escape their guarded handling. In src/server/management/lab-routes.ts
at lines 250-254, define decodePathSegment beside rejectUnsafeId to return null
for URIError, replace decodeURIComponent, and return the 404 not_found response
when decoding returns null; apply the same replacement and null response at
lines 323-327 and 360-364.

In `@tests/lab-read-surfaces.test.ts`:
- Around line 92-106: Strengthen the affected tests in
tests/lab-read-surfaces.test.ts:92-106 by asserting discovered scenarios are
non-empty in seedProjection before seeding; at 160-178, replace the
first.hasMore/nextCursor early return with assertions that both indicate another
page; at 249-253, assert payload_json on each verdictsBody.verdicts entry rather
than the envelope; and at 335-360, assert the update changes count is 1, require
artifacts.items to be non-empty before iterating, and query the corruption
surface so the inserted corruption row is actually validated.
- Around line 92-106: Add a precondition assertion in seedProjection immediately
after discoverScenarios so the helper fails clearly when no scenarios are found
for suiteId. Assert that scenarios is non-empty and include the suite identifier
in the failure message; preserve the existing slicing, persistence, and
projection rebuild flow.
- Around line 215-237: Extend the read-only coverage in the test "read calls do
not mutate ledger sqlite artifacts" by invoking queryLabSubjectById,
queryLabEventById, queryLabArtifactByDigest, and queryLabCatalogEntries
alongside the existing queries, using valid seeded-resource arguments. Keep the
existing byte-equality and mtime assertions unchanged so these single-resource
entry points are covered by the same non-mutation checks.
- Around line 298-321: Add output assertions to the lab command tests by
capturing console.log and verifying human status produces non-empty formatted
lines while --json produces JSON-shaped output. Extend argument coverage around
handleLabCommand to test the empty-argv default status behavior and the
["--json"] boundary case, asserting their expected exit codes and output or
error shape; keep these focused near the existing lab tests and exercise
statusSummary and the relevant *Lines formatters.
🪄 Autofix

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: ASSERTIVE

Plan: Pro Plus

Run ID: 1332924b-48aa-4519-8283-d836b455d6e6

📥 Commits

Reviewing files that changed from the base of the PR and between e8ce2b9 and 1907b90.

📒 Files selected for processing (19)
  • devlog/_plan/260807_compatibility_lab/001_pr_stack_status.md
  • devlog/_plan/260807_compatibility_lab/004_cl04_read_surfaces.md
  • src/cli/codex-shim-autorestore.ts
  • src/cli/help.ts
  • src/cli/index.ts
  • src/cli/lab.ts
  • src/lab/index.ts
  • src/lab/query/catalog.ts
  • src/lab/query/connection.ts
  • src/lab/query/constants.ts
  • src/lab/query/cursor.ts
  • src/lab/query/dto-map.ts
  • src/lab/query/errors.ts
  • src/lab/query/index.ts
  • src/lab/query/queries.ts
  • src/lab/query/types.ts
  • src/server/management-api.ts
  • src/server/management/lab-routes.ts
  • tests/lab-read-surfaces.test.ts

Comment thread devlog/_plan/260807_compatibility_lab/001_pr_stack_status.md
Comment thread devlog/_plan/260807_compatibility_lab/004_cl04_read_surfaces.md Outdated
Comment thread src/cli/codex-shim-autorestore.ts
Comment thread src/cli/help.ts
Comment on lines +267 to +280
lab: {
usage: "ocx lab <status|verdicts|subjects|subject|observations|events|event|artifacts|artifact|catalog> [options] [--json]",
summary: "Read-only Compatibility Lab projection inspection (local SQLite; no daemon).",
details: [
"status Projection availability, schema versions, and row counts.",
"verdicts Paginated derived compatibility verdicts with filters.",
"subjects List subjects; subject <id> returns one typed subject.",
"observations Paginated observation rows from the projection.",
"events Event history; event <id> returns one safe typed event.",
"artifacts Artifact metadata only (no content download).",
"catalog Packaged protocol/live scenario catalogue metadata.",
"Reads never rebuild the projection, trigger probes, or require the proxy.",
],
},

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Use one spelling of "catalog" in the user-facing text.

Line 268 names the subcommand catalog. Line 277 describes it as "catalogue". src/cli/lab.ts line 119 also prints "No catalogue scenarios" as the empty-state message.

The subcommand name is catalog, so the prose should match it. Mixed spelling in help text makes the feature harder to search for in the help output and in documentation.

✏️ Proposed fix
-      "catalog               Packaged protocol/live scenario catalogue metadata.",
+      "catalog               Packaged protocol/live scenario catalog metadata.",

Apply the same change in src/cli/lab.ts line 119:

-  return lines.length > 0 ? lines : ["No catalogue scenarios"];
+  return lines.length > 0 ? lines : ["No catalog scenarios"];
🤖 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 `@src/cli/help.ts` around lines 267 - 280, Use the “catalog” spelling
consistently in the lab help text and the empty-state message in the lab CLI
flow, including the visible `lab.details` catalog entry and the `src/cli/lab.ts`
message currently using “catalogue”.

Comment thread src/cli/lab.ts Outdated
Comment thread src/lab/query/queries.ts Outdated
Comment thread src/server/management/lab-routes.ts
Comment thread tests/lab-read-surfaces.test.ts
Comment thread tests/lab-read-surfaces.test.ts
Comment thread tests/lab-read-surfaces.test.ts
@Wibias
Wibias merged commit d517161 into lidge-jun:dev Aug 9, 2026
29 checks passed
@Wibias
Wibias deleted the feat/cl-04-lab-read-surfaces branch August 9, 2026 23:15
@Wibias
Wibias restored the feat/cl-04-lab-read-surfaces branch August 9, 2026 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request gui-screenshot-waived Maintainer waiver for false-positive GUI screenshot requirements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant