Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ jobs:
- name: Check module tidiness
run: make tidy-check

- name: Test smoke harness offline
working-directory: tests/smoke
env:
HEY_SMOKE_OFFLINE: "1"
run: go test -race -count=1 -timeout 1m -run '^TestHarness'

- name: Run tests with coverage floor
run: make coverage

Expand Down
48 changes: 48 additions & 0 deletions tests/smoke/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,54 @@ The default server is `http://app.hey.localhost:3003`; see the root `AGENTS.md`
login and environment overrides. The full SMTP/browser suite can exceed five
minutes; `make test-smoke` gives the complete run a ten-minute deadline.

## Harness regressions and cleanup

The harness has offline regression tests that need no server, browser, login or SMTP:

```bash
cd tests/smoke
HEY_SMOKE_OFFLINE=1 go test -race -count=1 -timeout 1m -run '^TestHarness'
```

CI runs these separately because this directory is its own Go module. Offline
mode refuses any other selector, so ordinary feature tests cannot masquerade as
live proof. The regressions fake the existing command boundary, not a HEY HTTP
server. They check exact fixture identity, missing fixtures, failed/no-op cleanup,
incomplete readbacks, credential-evidence exclusion and setup-failure teardown.

Draft, owned-thread, contact and event cleanup callbacks check command failures
and read back the resulting state before credentials are removed. Event cleanup
reads all calendars, including switched-off ones, over the fixture's date window.
Thread setup
polls for the exact created topic and retries transient reads. If delivery never
arrives, cleanup makes one final lookup instead of repeating the full wait.
Contact fixtures and their aliases are retained hidden, with notes and uploaded
photos removed; alias pages redirect to the primary contact, not an independent
view of each alias's hidden flag. The owned HOME/config/state/cache/work directory
is removed on normal returns, including browser/OAuth setup and test failures.
A killed or timed-out process can still leave state and fixtures behind; record
the run's exact paths and fixture IDs for recovery.

`HEY_SMOKE_EVIDENCE_DIR` optionally retains `commands.jsonl` for allowlisted data
commands invoked through the shared `hey()` helper, including the test name,
argv, stdout, stderr and status. Leading-flag invocations, unknown commands,
auth/token commands and browser/OAuth progress are not recorded. This is not a
complete transcript of direct subprocess calls. Use an absolute path outside
disposable client state. Keep it private: mail bodies and sharing URLs can be
present. On POSIX, existing directories/files with group or public permissions
are refused rather than written.

Do not run the full suite on a shared identity just to broaden coverage: journal
tests overwrite fixed dates and some other tests still select existing mail/habits
or lack complete cleanup. These changes do not repair every smoke test's cleanup.
Confirm exclusive development ownership and local-only SMTP/capture before sending.

Child CLIs ignore inherited `HEY_*` settings and receive only the harness's
origin, account and keyring settings. Set `HEY_SMOKE_ACCOUNT_ID` to scope the
suite to a particular linked development account; an ordinary `HEY_ACCOUNT_ID`
from your shell does not select it. `HEY_BINARY` may be absolute or relative to
`tests/smoke` (the Go test process's working directory).

## Development prerequisites

A server answering HTTP is not enough for the full suite:
Expand Down
3 changes: 2 additions & 1 deletion tests/smoke/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ func TestConfigSet(t *testing.T) {
runHey := func(args ...string) (string, int) {
t.Helper()
cmd := exec.Command(binaryPath, args...)
env := os.Environ()
cmd.Dir = workDir
env := cliEnv()
// Remove HEY_BASE_URL so config file takes precedence.
filtered := make([]string, 0, len(env))
for _, e := range env {
Expand Down
11 changes: 3 additions & 8 deletions tests/smoke/contacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type smokeContact struct {
EmailAddress string `json:"email_address"`
Aliases []smokeContact `json:"aliases"`
Note string `json:"note"`
AvatarURL string `json:"avatar_url"`
}

func TestContactsListAndShow(t *testing.T) {
Expand All @@ -44,10 +45,7 @@ func TestContactLifecycleAndPrivateNote(t *testing.T) {
t.Fatalf("created contact is incomplete: id=%d email_matches=%v", created.ID, created.EmailAddress == email)
}
id := intStr(created.ID)
t.Cleanup(func() {
_, _, _ = hey(t, "contact", "unbundle", id)
_, _, _ = hey(t, "contact", "hide", id)
})
registerContactCleanup(t, id, created.AvatarURL)

updated := dataAs[smokeContact](t, contactWriteJSON(t, "contact", "update", id, "--name", "Samuel Rivera", "--alias", alias))
if updated.ID == 0 || updated.Name != "Samuel Rivera" {
Expand Down Expand Up @@ -121,10 +119,7 @@ func TestContactPhoto(t *testing.T) {
AvatarURL string `json:"avatar_url"`
}](t, contactWriteJSON(t, "contact", "add", "--name", "Priya Shah", "--email", "priya.shah+"+unique+"@example.com"))
id := intStr(created.ID)
t.Cleanup(func() {
_, _, _ = hey(t, "contact", "photo", "remove", id)
_, _, _ = hey(t, "contact", "hide", id)
})
registerContactCleanup(t, id, created.AvatarURL)

portrait := image.NewRGBA(image.Rect(0, 0, 64, 64))
for x := 0; x < 64; x++ {
Expand Down
1 change: 1 addition & 0 deletions tests/smoke/cookie_verification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func TestCookieRemovalLiveWatch(t *testing.T) {
defer cancel()
cmd := exec.CommandContext(ctx, binaryPath, "watch", "--timeout", "8s")
cmd.Env = cliEnv()
cmd.Dir = workDir
var stdout bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = io.Discard
Expand Down
57 changes: 22 additions & 35 deletions tests/smoke/draft_lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ func composeDraft(t *testing.T, subject string, extra ...string) int64 {
if draft.ID <= 0 {
t.Fatalf("draft id = %d, want positive", draft.ID)
}
t.Cleanup(func() {
_, _, _ = hey(t, "draft", "delete", fmt.Sprintf("%d", draft.ID), "--json")
})
registerDraftCleanup(t, draft.ID)
return draft.ID
}

Expand Down Expand Up @@ -108,7 +106,13 @@ func TestDraftLifecycle(t *testing.T) {
if code != 0 {
skipf(t, "draft send not accepted by server (exit %d): %s", code, stderr)
}
_ = stdout
sent := dataAs[struct {
TopicID int64 `json:"topic_id"`
}](t, parseResponse(t, stdout))
if sent.TopicID <= 0 {
t.Fatalf("sent draft returned no topic ID for subject %q; inspect this fixture for manual cleanup", newSubject)
}
waitForOwnedTopic(t, sent.TopicID, newSubject)
if draftListedIDs(t)[id] {
t.Errorf("draft %d still listed after sending", id)
}
Expand Down Expand Up @@ -136,43 +140,28 @@ func TestDraftSendRefusesWithoutRecipients(t *testing.T) {
}
}

// findSmokeThread composes a message to self and finds its topic in the imbox, falling
// back to any thread there.
// findSmokeThread waits for the exact topic compose created. Another Imbox row
// is never a substitute for a fixture that failed to arrive.
func findSmokeThread(t *testing.T, subject string) string {
t.Helper()
_, _, composeCode := hey(t, "compose", "--to", smokeEmail, "--subject", subject,
stdout, stderr, code := hey(t, "compose", "--to", smokeEmail, "--subject", subject,
"-m", "Original message for the reply draft test", "--json")

resp := heyJSON(t, "box", "imbox")
type posting struct {
AppURL string `json:"app_url"`
Summary string `json:"summary"`
}
type boxResp struct {
Postings []posting `json:"postings"`
}
data := dataAs[boxResp](t, resp)

if composeCode == 0 {
for _, p := range data.Postings {
if p.Summary == subject {
return extractTopicID(p.AppURL)
}
}
if code != 0 {
skipf(t, "could not create reply fixture (exit %d): %s", code, stderr)
}
for _, p := range data.Postings {
if p.AppURL != "" {
return extractTopicID(p.AppURL)
}
sent := dataAs[struct {
TopicID int64 `json:"topic_id"`
}](t, parseResponse(t, stdout))
if sent.TopicID <= 0 {
t.Fatalf("compose returned no topic ID for subject %q; inspect this fixture for manual cleanup", subject)
}
return ""
t.Logf("owned reply setup topic %d", sent.TopicID)
waitForOwnedTopic(t, sent.TopicID, subject)
return fmt.Sprint(sent.TopicID)
}

func TestReplyDraft(t *testing.T) {
topicID := findSmokeThread(t, "Reply draft smoke "+uniqueID())
if topicID == "" {
skipf(t, "no thread available to draft a reply on")
}

stdout, stderr, code := hey(t, "reply", topicID, "-m", "Drafting this reply.", "--draft", "--json")
if code != 0 {
Expand All @@ -182,9 +171,7 @@ func TestReplyDraft(t *testing.T) {
if draft.ID <= 0 {
t.Fatalf("draft id = %d, want positive", draft.ID)
}
t.Cleanup(func() {
_, _, _ = hey(t, "draft", "delete", fmt.Sprintf("%d", draft.ID), "--json")
})
registerDraftCleanup(t, draft.ID)

resp := heyJSON(t, "draft", "show", fmt.Sprintf("%d", draft.ID))
state := dataAs[draftState](t, resp)
Expand Down
63 changes: 15 additions & 48 deletions tests/smoke/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestEventCRUD(t *testing.T) {
t.Fatal("add response carries no event ID")
}
id := fmt.Sprint(event.ID)
t.Cleanup(func() { _, _, _ = hey(t, "event", "delete", id) })
registerEventCleanup(t, id, title, day)

if event.Title != title {
t.Errorf("created title = %q, want %q", event.Title, title)
Expand Down Expand Up @@ -144,10 +144,13 @@ func TestEventOccurrenceEditScopes(t *testing.T) {
}
seriesID := fmt.Sprint(series.ID)
cleanupIDs := []string{seriesID}
t.Logf("owned repeating series %s %q", seriesID, title)
t.Cleanup(func() {
cleanupIDs = append(cleanupIDs, smokeEventSeriesIDsOnDay(t, futureDay, title)...)
for _, id := range uniqueStrings(cleanupIDs) {
_, _, _ = hey(t, "event", "delete", id)
days := []string{firstDay, currentDay, futureDay, first.AddDate(0, 0, 21).Format("2006-01-02"), first.AddDate(0, 0, 28).Format("2006-01-02"), beyondLastDay}
if err := cleanupEventsWith(commandFor(t), cleanupIDs, title, days); err != nil {
t.Error(err)
} else {
t.Logf("series %s and its splits independently confirmed absent", seriesID)
}
})

Expand Down Expand Up @@ -257,12 +260,8 @@ func TestEventOccurrenceFutureSplitAllowsAnEarlierTime(t *testing.T) {
t.Fatal("repeating event response carries no event ID")
}
seriesID := fmt.Sprint(series.ID)
t.Cleanup(func() {
ids := append([]string{seriesID}, smokeEventSeriesIDsOnDay(t, selectedDay, title)...)
for _, id := range uniqueStrings(ids) {
_, _, _ = hey(t, "event", "delete", id)
}
})
registerEventCleanup(t, seriesID, title, firstDay, selectedDay,
first.AddDate(0, 0, 2).Format("2006-01-02"), first.AddDate(0, 0, 3).Format("2006-01-02"))

occurrence := fmt.Sprintf("%d_%s", series.ID, selectedDay)
// The selected 23:00 occurrence itself is removed, and HEY accepts the replacement's
Expand Down Expand Up @@ -315,13 +314,8 @@ func TestEventOccurrenceFutureSplitRefusesARealizedDayMovedEarlier(t *testing.T)
t.Fatal("repeating event response carries no event ID")
}
seriesID := fmt.Sprint(series.ID)
t.Cleanup(func() {
ids := append([]string{seriesID}, smokeEventSeriesIDsOnDay(t, firstDay, title)...)
ids = append(ids, smokeEventSeriesIDsOnDay(t, selectedDay, title)...)
for _, id := range uniqueStrings(ids) {
_, _, _ = hey(t, "event", "delete", id)
}
})
registerEventCleanup(t, seriesID, title, firstDay, selectedDay,
first.AddDate(0, 0, 2).Format("2006-01-02"), first.AddDate(0, 0, 3).Format("2006-01-02"))

occurrence := fmt.Sprintf("%d_%s", series.ID, selectedDay)
if _, stderr, code = hey(t, "event", "edit", seriesID,
Expand Down Expand Up @@ -356,36 +350,6 @@ func TestEventOccurrenceFutureSplitRefusesARealizedDayMovedEarlier(t *testing.T)
}
}

func smokeEventSeriesIDsOnDay(t *testing.T, day, title string) []string {
t.Helper()
stdout, _, code := hey(t, "event", "day", day, "--json")
if code != 0 {
return nil
}
var response Response
if json.Unmarshal([]byte(stdout), &response) != nil {
return nil
}
var events []smokeEvent
if json.Unmarshal(response.Data, &events) != nil {
return nil
}
var ids []string
for _, event := range events {
if event.Title != title {
continue
}
id := event.ParentID
if id == 0 {
id = event.ID
}
if id != 0 {
ids = append(ids, fmt.Sprint(id))
}
}
return ids
}

func uniqueStrings(values []string) []string {
seen := make(map[string]bool, len(values))
unique := make([]string, 0, len(values))
Expand Down Expand Up @@ -444,7 +408,10 @@ func TestEventAllDay(t *testing.T) {
t.Fatalf("failed to parse add response: %v", err)
}
event := dataAs[smokeEvent](t, added)
t.Cleanup(func() { _, _, _ = hey(t, "event", "delete", fmt.Sprint(event.ID), day) })
if event.ID <= 0 {
Comment thread
robzolkos marked this conversation as resolved.
Resolved
t.Fatalf("all-day event %q on %s returned no cleanup ID; inspect this fixture for manual cleanup", title, day)
}
registerEventCleanup(t, fmt.Sprint(event.ID), title, day)

if !event.AllDay {
t.Errorf("--all-day event is not all-day: %#v", event)
Expand Down
Loading
Loading