Skip to content

feat(import-sessions): add chunked Sure NDJSON import commands - #25

Merged
jjmata merged 1 commit into
we-promise:mainfrom
vlnd0:feat/import-sessions
Jun 18, 2026
Merged

feat(import-sessions): add chunked Sure NDJSON import commands#25
jjmata merged 1 commit into
we-promise:mainfrom
vlnd0:feat/import-sessions

Conversation

@vlnd0

@vlnd0 vlnd0 commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

What

Adds CLI coverage for the import_sessions API surface — the only api/v1
resource with no command wrapper. This is the chunked Sure NDJSON import flow
(distinct from imports, which handles CSV with column mapping).

Command Endpoint
import-sessions create POST /api/v1/import_sessions
import-sessions show <id> GET /api/v1/import_sessions/:id
import-sessions add-chunk <id> POST /api/v1/import_sessions/:id/chunks
import-sessions publish <id> POST /api/v1/import_sessions/:id/publish

Why

import_sessions (create / show / create_chunk / publish) is implemented
server-side but had no CLI entry point, so the chunked NDJSON import path was
not scriptable. This completes the agent-first contract over the full API.

Design

  • Follows the existing dry-run-by-default + --apply contract and reuses
    dispatchWrite / printGet / PostMultipart — no new infra.
  • add-chunk accepts a Sure NDJSON --file (multipart, reusing
    mimeForImportFile) or --raw-content (JSON body); validates sequence >= 1,
    exactly one content source, and the .ndjson/.json extension client-side.
  • Params are top-level to match the controller (no wrapping key). Honors the
    client_session_id / client_chunk_id idempotency keys.

Tests

  • Payload-builder + command-registration tests, in the categories_create_test.go
    style. go test ./..., go vet ./..., and tools/validate-samples.sh green
    locally. README updated with examples.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added import-sessions CLI command for chunked NDJSON imports with subcommands to create sessions, add chunks, view details, and publish.
  • Documentation

    • Updated README with examples for the new chunked import workflow.
  • Tests

    • Added comprehensive unit tests for import session functionality.

Wire the import_sessions API surface that had no CLI coverage:

  create     POST   /api/v1/import_sessions
  show       GET    /api/v1/import_sessions/:id
  add-chunk  POST   /api/v1/import_sessions/:id/chunks
  publish    POST   /api/v1/import_sessions/:id/publish

Mirrors the existing dry-run-by-default + --apply contract and reuses
dispatchWrite/printGet/PostMultipart. add-chunk accepts a Sure NDJSON
file (multipart) or --raw-content, validating sequence and content
source client-side. Top-level params match the controller (no wrapping
key). Adds payload-builder + registration tests and README examples.
@coderabbitai

coderabbitai Bot commented Jun 15, 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 31d5449f-02ac-495d-9565-398f2c17b581

📥 Commits

Reviewing files that changed from the base of the PR and between d20109e and c4ef46d.

📒 Files selected for processing (4)
  • README.md
  • cmd/sure-cli/root/import_sessions_cmd.go
  • cmd/sure-cli/root/import_sessions_test.go
  • cmd/sure-cli/root/root.go

📝 Walkthrough

Walkthrough

Adds the import-sessions CLI command group to sure-cli with four subcommands: create (POST a new import session), show (GET a session), add-chunk (POST sequenced NDJSON chunks as multipart or JSON body), and publish (POST to publish a session). Payload validation helpers enforce required fields and mutual exclusivity. Unit tests and README docs are included.

Changes

Chunked NDJSON Import Sessions Command

Layer / File(s) Summary
Root registration and top-level command structure
cmd/sure-cli/root/root.go, cmd/sure-cli/root/import_sessions_cmd.go
New() registers newImportSessionsCmd(); the new file defines the import-sessions parent Cobra command and wires show, create, add-chunk, and publish subcommands.
Session create payload validation and subcommand
cmd/sure-cli/root/import_sessions_cmd.go
importSessionCreateOpts and buildImportSessionCreatePayload validate non-empty type and non-negative expected-chunks, conditionally include optional fields; the create subcommand wires flags and dispatches POST in dry-run or apply mode.
Chunk upload validation, payload building, and subcommands
cmd/sure-cli/root/import_sessions_cmd.go
Chunk opts/plan structures and buildChunkCreate enforce sequence ≥ 1, mutual exclusivity of --file/--raw-content, file extension validation, and multipart vs JSON body selection; add-chunk dispatches via PostMultipart or client.Post; chunkDryRunBody omits file contents in dry-run; publish subcommand POSTs to /api/v1/import_sessions/:id/publish.
Unit tests and README docs
cmd/sure-cli/root/import_sessions_test.go, README.md
Tests cover payload validation, chunk mutual exclusivity, multipart construction, missing file and bad extension rejection, and subcommand/flag registration; README adds chunked import workflow examples.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

codex

Suggested reviewers

  • dgilperez

Poem

🐰 Hop, hop, hooray for chunked delight,
NDJSON splits now flow just right!
A session born, then chunks arrive in turn,
--apply to publish, watch the import churn.
The rabbit stamps each sequence with care —
No missing files, no bad extensions there! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% 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 pull request title accurately summarizes the main change: adding chunked Sure NDJSON import commands to the CLI. It is specific, concise, and directly reflects the primary objective.
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.

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

✨ 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 and usage tips.

@superagent-security

Copy link
Copy Markdown

Superagent didn't find any vulnerabilities or security issues in this PR.

@jjmata
jjmata merged commit 990cb65 into we-promise:main Jun 18, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants