Skip to content
Merged
5 changes: 5 additions & 0 deletions .surface
Original file line number Diff line number Diff line change
Expand Up @@ -15087,13 +15087,16 @@ FLAG basecamp schedule create --cache-dir type=string
FLAG basecamp schedule create --count type=bool
FLAG basecamp schedule create --desc type=string
FLAG basecamp schedule create --description type=string
FLAG basecamp schedule create --draft type=bool
FLAG basecamp schedule create --end type=string
FLAG basecamp schedule create --ends-at type=string
FLAG basecamp schedule create --format type=string
FLAG basecamp schedule create --help type=bool
FLAG basecamp schedule create --highlight type=bool
FLAG basecamp schedule create --hints type=bool
FLAG basecamp schedule create --ids-only type=bool
FLAG basecamp schedule create --in type=string
FLAG basecamp schedule create --join-url type=string
FLAG basecamp schedule create --jq type=string
FLAG basecamp schedule create --json type=bool
FLAG basecamp schedule create --markdown type=bool
Expand Down Expand Up @@ -15255,9 +15258,11 @@ FLAG basecamp schedule update --end type=string
FLAG basecamp schedule update --ends-at type=string
FLAG basecamp schedule update --format type=string
FLAG basecamp schedule update --help type=bool
FLAG basecamp schedule update --highlight type=bool
FLAG basecamp schedule update --hints type=bool
FLAG basecamp schedule update --ids-only type=bool
FLAG basecamp schedule update --in type=string
FLAG basecamp schedule update --join-url type=string
FLAG basecamp schedule update --jq type=string
FLAG basecamp schedule update --json type=bool
FLAG basecamp schedule update --markdown type=bool
Expand Down
2 changes: 1 addition & 1 deletion API-COVERAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ cannot faithfully cover at least one endpoint for a reason outside the CLI. A
| **Schedule** |
| calendars | 2 | `calendars` | ✅ | BC5 | - | show, update (color only). No index endpoint, so there is no `calendars list` — address one by id or pasted URL. The eleven colors are validated client-side for an immediate answer that names the alternatives; since v0.13.0 the SDK also carries the server's field-keyed 422 message |
| schedules | 2 | `schedule` | ✅ | BC4 | - | Schedule container + settings |
| schedule_entries | 5 | `schedule` | ✅ | BC4 | - | list, show, create, update, occurrences. Create supports `--subscribe`/`--no-subscribe` |
| schedule_entries | 5 | `schedule` | ✅ | BC4 | - | list, show, create, update, occurrences. Create supports `--subscribe`/`--no-subscribe`; `--draft` sends `status: drafted` via SDK `CreateEntry`, otherwise `status: active`. Create and update support `--highlight` (including `--highlight=false`) and `--join-url` (including an empty string to clear); omission preserves existing values on update. The join link is written as `url` and read as `join_url`; response `url` remains the API address. Open the returned draft link in Basecamp to edit and publish. Status updates/publication are excluded: the SDK update/replace requests expose no status field; generic archive/trash/restore commands cover recording lifecycle, not draft publication. |
| events | 1 | `events` | ✅ | BC4 | - | Recording change audit trail |
| **Event Feed** |
| event_feed | 3 | `events poll`, `events ticket`, `inbox` | ✅ | BC5 | - | The account-wide event feed: `GET /events.json` (`events poll`), `GET /inbox.json` (`inbox`, agent principals only), `POST /events/stream_ticket.json` (`events ticket`). Pagination is the body envelope — a durable `position` and a `next` continuation URL — not the Link-header page walk, so `--all` walks `next` rather than page numbers. The live WebSocket lane the ticket opens is out of scope for the CLI: the SDK's cable client carries a WebSocket dependency the CLI does not take. The mint is a CLI command only — it is excluded from the MCP surface, whose dispatcher would return the bearer verbatim into a model transcript and which could not open the socket anyway |
Expand Down
30 changes: 30 additions & 0 deletions e2e/smoke/smoke_schedule_write.bats
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,36 @@ setup_file() {
echo "$output" | jq -r '.data.id' > "$BATS_FILE_TMPDIR/entry_id"
}

@test "schedule create saves a draft only when requested" {
local mode expected entry_id
local flags=()
for mode in draft default false; do
flags=()
expected=active
if [[ "$mode" == draft ]]; then
flags=(--draft)
expected=drafted
elif [[ "$mode" == false ]]; then
flags=(--draft=false)
fi
run_smoke basecamp schedule create "CLI smoke publication $mode $(date +%s)" \
--starts-at '2026-11-19T14:00:00Z' --ends-at '2026-11-19T14:30:00Z' \
--schedule "$QA_SCHEDULE" -p "$QA_PROJECT" --no-subscribe --json "${flags[@]}"
assert_success
assert_json_value '.data.status' "$expected"
assert_json_not_null '.data.app_url'
entry_id=$(echo "$output" | jq -r '.data.id')
if [[ "$mode" == draft ]]; then
[[ "$(echo "$output" | jq -r '.notice // ""')" == *'edit and publish'* ]]
fi

run_smoke basecamp schedule show "$entry_id" --no-comments --json
assert_success
assert_json_value '.data.id' "$entry_id"
assert_json_value '.data.status' "$expected"
done
}

@test "schedule update updates a schedule entry" {
local id_file="$BATS_FILE_TMPDIR/entry_id"
[[ -f "$id_file" ]] || mark_unverifiable "No schedule entry created in prior test"
Expand Down
77 changes: 61 additions & 16 deletions internal/commands/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,17 +416,20 @@ func newScheduleCreateCmd(project, scheduleID *string) *cobra.Command {
var endsAt string
var description string
var allDay bool
var highlight bool
var joinURL string
var notify bool
var participants string
var subscribe string
var noSubscribe bool
var attachFiles []string
var visibleToClients bool
var draft bool

cmd := &cobra.Command{
Use: "create <summary>",
Short: "Create a schedule entry",
Long: "Create a new entry in the project schedule.",
Long: "Create a published entry in the project schedule. Use --draft to save an unpublished draft, then open its link in Basecamp to edit and publish it.",
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
entrySummary := summary
Expand Down Expand Up @@ -473,11 +476,12 @@ func newScheduleCreateCmd(project, scheduleID *string) *cobra.Command {
}

app := appctx.FromContext(cmd.Context())
scope := newFollowUpScope(app)
if err := ensureAccount(cmd, app); err != nil {
return err
}

return runScheduleCreate(cmd, app, *project, *scheduleID, entrySummary, startsAt, endsAt, description, allDay, notify, visibleToClients, participants, subscribe, noSubscribe, attachFiles)
return runScheduleCreate(cmd, app, scope, *project, *scheduleID, entrySummary, startsAt, endsAt, description, allDay, notify, visibleToClients, draft, highlight, joinURL, participants, subscribe, noSubscribe, attachFiles)
},
}

Expand All @@ -490,6 +494,8 @@ func newScheduleCreateCmd(project, scheduleID *string) *cobra.Command {
cmd.Flags().StringVar(&description, "description", "", "Detailed description; use - to read from stdin")
cmd.Flags().StringVar(&description, "desc", "", "Description (alias)")
cmd.Flags().BoolVar(&allDay, "all-day", false, "Mark as all-day event")
cmd.Flags().BoolVar(&highlight, "highlight", false, "Highlight the entry on the schedule (false removes the highlight)")
cmd.Flags().StringVar(&joinURL, "join-url", "", "Join link for the event (empty clears it; returned as join_url)")
cmd.Flags().BoolVar(&notify, "notify", false, "Notify participants")
cmd.Flags().StringVar(&participants, "participants", "", "Comma-separated person IDs")
cmd.Flags().StringVar(&participants, "people", "", "Person IDs (alias)")
Expand All @@ -499,12 +505,13 @@ func newScheduleCreateCmd(project, scheduleID *string) *cobra.Command {
cmd.Flags().BoolVar(&noSubscribe, "no-subscribe", false, "Don't subscribe anyone else (silent, no notifications)")
cmd.Flags().StringArrayVar(&attachFiles, "attach", nil, "Attach file (repeatable)")
cmd.Flags().BoolVar(&visibleToClients, "visible-to-clients", false, "Make the schedule entry visible to clients on the project (omit for the server default; client-authenticated callers always post client-visible)")
cmd.Flags().BoolVar(&draft, "draft", false, "Save an unpublished draft (open its link in Basecamp to edit and publish)")

addRichTextFormatFlag(cmd)
return cmd
}

func runScheduleCreate(cmd *cobra.Command, app *appctx.App, project, scheduleID, summary, startsAt, endsAt, description string, allDay, notify, visibleToClients bool, participants, subscribe string, noSubscribe bool, attachFiles []string) error {
func runScheduleCreate(cmd *cobra.Command, app *appctx.App, scope followUpScope, project, scheduleID, summary, startsAt, endsAt, description string, allDay, notify, visibleToClients, draft, highlight bool, joinURL, participants, subscribe string, noSubscribe bool, attachFiles []string) error {
// Resolve subscription flags early (fail fast on bad input)
subs, err := applySubscribeFlags(cmd.Context(), app.Names, subscribe, cmd.Flags().Changed("subscribe"), noSubscribe)
if err != nil {
Expand Down Expand Up @@ -567,7 +574,12 @@ func runScheduleCreate(cmd *cobra.Command, app *appctx.App, project, scheduleID,
}

// Build request
status := "active"
if draft {
status = "drafted"
}
req := &basecamp.CreateScheduleEntryRequest{
Status: &status,
Summary: summary,
StartsAt: startsAt,
EndsAt: endsAt,
Expand All @@ -577,6 +589,13 @@ func runScheduleCreate(cmd *cobra.Command, app *appctx.App, project, scheduleID,
Subscriptions: subs,
}

if cmd.Flags().Changed("highlight") {
req.Highlighted = &highlight
}
if cmd.Flags().Changed("join-url") {
req.URL = &joinURL
}

// Set client visibility only when the flag was provided. Omitting it uses the
// server's default: team-only when posting as a team member, but a
// client-authenticated caller always creates client-visible records (an
Expand Down Expand Up @@ -604,24 +623,37 @@ func runScheduleCreate(cmd *cobra.Command, app *appctx.App, project, scheduleID,
}

resultSummary := fmt.Sprintf("Created schedule entry #%d: %s", entry.ID, summary)
scopeArgs := scope.args(app.Config.AccountID)
crumbs := []output.Breadcrumb{{
Action: "show",
Cmd: fmt.Sprintf("basecamp schedule show %d --project %s%s", entry.ID, resolvedProjectID, scopeArgs),
Description: "View entry",
}}
if draft {
resultSummary = fmt.Sprintf("Created draft schedule entry #%d: %s", entry.ID, summary)
} else {
crumbs = append(crumbs, output.Breadcrumb{
Action: "entries",
Cmd: fmt.Sprintf("basecamp schedule entries --project %s --schedule %d%s", resolvedProjectID, scheduleIDInt, scopeArgs),
Description: "View all entries",
})
}

respOpts := []output.ResponseOption{
output.WithSummary(resultSummary),
output.WithBreadcrumbs(
output.Breadcrumb{
Action: "show",
Cmd: fmt.Sprintf("basecamp schedule show %d --project %s", entry.ID, resolvedProjectID),
Description: "View entry",
},
output.Breadcrumb{
Action: "entries",
Cmd: fmt.Sprintf("basecamp schedule entries --project %s", resolvedProjectID),
Description: "View all entries",
},
),
output.WithBreadcrumbs(crumbs...),
}
notice := mentionNotice
if draft {
notice = strings.TrimSpace(fmt.Sprintf("Unpublished. Open %s in Basecamp to edit and publish this draft. %s", entry.AppURL, mentionNotice))
}
if mentionNotice != "" {
respOpts = append(respOpts, output.WithDiagnostic(mentionNotice))
if app.Output.EffectiveFormat() == output.FormatQuiet {
notice = mentionNotice
}
respOpts = append(respOpts, output.WithDiagnostic(notice))
} else if notice != "" {
respOpts = append(respOpts, output.WithNotice(notice))
}
return app.OK(entry, respOpts...)
}
Expand All @@ -632,6 +664,8 @@ func newScheduleUpdateCmd(project *string) *cobra.Command {
var endsAt string
var description string
var allDay bool
var highlight bool
var joinURL string
var notify bool
var participants string
var attachFiles []string
Expand Down Expand Up @@ -719,6 +753,15 @@ You can pass either an entry ID or a Basecamp URL:
req := &basecamp.UpdateScheduleEntryRequest{}
hasChanges := false

if cmd.Flags().Changed("highlight") {
req.Highlighted = &highlight
hasChanges = true
}
if cmd.Flags().Changed("join-url") {
req.URL = &joinURL
hasChanges = true
}

if summary != "" {
req.Summary = basecamp.Ptr(summary)
hasChanges = true
Expand Down Expand Up @@ -831,6 +874,8 @@ You can pass either an entry ID or a Basecamp URL:
cmd.Flags().StringVar(&description, "description", "", "Detailed description; use - to read from stdin")
cmd.Flags().StringVar(&description, "desc", "", "Description (alias)")
cmd.Flags().BoolVar(&allDay, "all-day", false, "Mark as all-day event")
cmd.Flags().BoolVar(&highlight, "highlight", false, "Highlight the entry on the schedule (false removes the highlight)")
cmd.Flags().StringVar(&joinURL, "join-url", "", "Join link for the event (empty clears it; returned as join_url)")
cmd.Flags().BoolVar(&notify, "notify", false, "Notify participants")
cmd.Flags().StringVar(&participants, "participants", "", "Comma-separated person IDs")
cmd.Flags().StringVar(&participants, "people", "", "Person IDs (alias)")
Expand Down
133 changes: 133 additions & 0 deletions internal/commands/schedule_draft_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package commands

import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"strings"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/basecamp/basecamp-cli/internal/config"
"github.com/basecamp/basecamp-cli/internal/output"
)

type scheduleDraftTransport struct {
mockScheduleCreateTransport
writes int
}

func (tr *scheduleDraftTransport) RoundTrip(req *http.Request) (*http.Response, error) {
if req.Method == http.MethodGet && strings.Contains(req.URL.Path, "/people") {
return &http.Response{StatusCode: http.StatusOK, Header: http.Header{"Content-Type": {"application/json"}}, Body: io.NopCloser(strings.NewReader(`[]`))}, nil
}
resp, err := tr.mockScheduleCreateTransport.RoundTrip(req)
if err != nil || req.Method != http.MethodPost {
return resp, err
}
tr.writes++
var body map[string]any
if err := json.Unmarshal(tr.capturedBody, &body); err != nil {
return nil, err
}
status, _ := body["status"].(string)
if status == "" {
status = "active"
}
resp.Body.Close()
resp.Body = io.NopCloser(strings.NewReader(fmt.Sprintf(`{"id":999,"status":%q,"summary":"Event","app_url":"https://3.basecamp.com/99999/buckets/123/schedule_entries/999","starts_at":"2026-03-04T09:00:00Z","ends_at":"2026-03-04T09:30:00Z"}`, status)))
return resp, nil
}

func TestScheduleCreatePublicationState(t *testing.T) {
for _, tc := range []struct {
name string
flags []string
status string
}{
{"published by default", nil, "active"},
{"explicit draft", []string{"--draft"}, "drafted"},
{"explicit false publishes", []string{"--draft=false"}, "active"},
} {
t.Run(tc.name, func(t *testing.T) {
tr := &scheduleDraftTransport{}
app, buf := newTestAppWithTransport(t, tr)
app.Flags.Hints = true
app.Config.ActiveProfile = "alternate"
app.Config.Sources = map[string]string{"account_id": string(config.SourceFlag)}
args := append([]string{"create", "Event", "--starts-at", "2026-03-04T09:00:00Z", "--ends-at", "2026-03-04T09:30:00Z"}, tc.flags...)
require.NoError(t, executeRecordingCommand(NewScheduleCmd(), app, args...))
require.Equal(t, 1, tr.writes)
var body map[string]any
require.NoError(t, json.Unmarshal(tr.capturedBody, &body))
assert.Equal(t, tc.status, body["status"])
var out struct {
Data struct {
ID int64 `json:"id"`
Status string `json:"status"`
AppURL string `json:"app_url"`
} `json:"data"`
Summary string `json:"summary"`
Notice string `json:"notice"`
Breadcrumbs []struct {
Cmd string `json:"cmd"`
} `json:"breadcrumbs"`
}
require.NoError(t, json.Unmarshal(buf.Bytes(), &out))
assert.Equal(t, int64(999), out.Data.ID)
assert.Equal(t, tc.status, out.Data.Status)
assert.Equal(t, "https://3.basecamp.com/99999/buckets/123/schedule_entries/999", out.Data.AppURL)
require.NotEmpty(t, out.Breadcrumbs)
assert.Contains(t, out.Breadcrumbs[0].Cmd, "schedule show 999")
assert.Contains(t, out.Breadcrumbs[0].Cmd, "--profile alternate --account 99999")
if tc.status == "drafted" {
assert.Contains(t, out.Summary, "draft")
assert.Contains(t, out.Notice, "edit and publish")
assert.Len(t, out.Breadcrumbs, 1, "ordinary listings omit drafts")
} else {
assert.NotContains(t, out.Summary, "draft")
}
})
}
}

func TestScheduleCreateDraftDoesNotWarnInQuietMode(t *testing.T) {
tr := &scheduleDraftTransport{}
app, _ := newTestAppWithTransport(t, tr)
var stdout, stderr bytes.Buffer
app.Output = output.New(output.Options{Format: output.FormatQuiet, Writer: &stdout, ErrWriter: &stderr})
require.NoError(t, executeRecordingCommand(NewScheduleCmd(), app, "create", "Event", "--starts-at", "2026-03-04T09:00:00Z", "--ends-at", "2026-03-04T09:30:00Z", "--draft"))
assert.Empty(t, stderr.String())
var entry struct {
Status string `json:"status"`
}
require.NoError(t, json.Unmarshal(stdout.Bytes(), &entry))
assert.Equal(t, "drafted", entry.Status)
}

func TestScheduleCreateDraftWithUnresolvedMention(t *testing.T) {
for _, format := range []output.Format{output.FormatJSON, output.FormatQuiet} {
t.Run(fmt.Sprint(format), func(t *testing.T) {
tr := &scheduleDraftTransport{}
app, _ := newTestAppWithTransport(t, tr)
var stdout, stderr bytes.Buffer
app.Output = output.New(output.Options{Format: format, Writer: &stdout, ErrWriter: &stderr})
require.NoError(t, executeRecordingCommand(NewScheduleCmd(), app, "create", "Event", "--starts-at", "2026-03-04T09:00:00Z", "--ends-at", "2026-03-04T09:30:00Z", "--description", "Ask @Nobody", "--draft"))
if format == output.FormatQuiet {
assert.Contains(t, stderr.String(), "@Nobody")
assert.NotContains(t, stderr.String(), "edit and publish")
} else {
var result struct {
Notice string `json:"notice"`
}
require.NoError(t, json.Unmarshal(stdout.Bytes(), &result))
assert.Contains(t, result.Notice, "@Nobody")
assert.Contains(t, result.Notice, "edit and publish")
}
})
}
}
Loading
Loading