Skip to content

Exit non-zero on publish request/status errors - #468

Merged
neuromechanist merged 4 commits into
devfrom
feature/issue-94-publish-exit-code
May 14, 2026
Merged

neuromechanist merged 4 commits into
devfrom
feature/issue-94-publish-exit-code

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Closes #94

Summary

nemar dataset publish request, publish status, and publish resend all
called spinner.fail() in their catch blocks and then returned with exit code
0, masking failures from any caller that checked $?. Every other command in
src/commands/dataset.ts exits 1 on error; these three were the outliers.

Added process.exit(1) at the end of each catch block so failures propagate
correctly. Test coverage:

  • Extended the existing publish status/request/resend for non-existent dataset returns error tests in test/publish-workflow.test.ts to also
    assert exitCode === 1 (these only run when TEST_USER_API_KEY is set).
  • Added two unconditional tests that use a bogus api key in the config so
    isAuthenticated() passes but the API call fails. Verifies the catch
    branch exits 1.

Test plan

  • bun test test/publish-workflow.test.ts (20 pass, 0 fail)
  • bun run tsc --noEmit (passes)
  • bun run build (passes)

@github-actions

github-actions Bot commented May 14, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR468

Version: 0.8.14-PR468.42de81c
Commit: 42de81c


🤖 Updated on each push.

@neuromechanist

Copy link
Copy Markdown
Contributor Author

PR Review: Exit non-zero on publish request/status errors

Reviewed by: automated review (claude-sonnet-4-6)


Critical

None.


Important

Missing bogus-key test for resend (test/publish-workflow.test.ts)

The fix adds process.exit(1) to all three catch blocks (request, status, resend). The two new unconditional tests (those that run in any environment, without TEST_USER_API_KEY) only cover status and request. There is no unconditional test verifying that resend exits non-zero when the API call fails with an invalid key.

The three existing non-existent dataset returns error tests do cover resend exit code, but they are gated on if (!TEST_CONFIG.userApiKey) return;, so they skip in CI environments without the key set. As a result, the resend fix has weaker unconditional coverage than the other two.

Suggested addition to test/publish-workflow.test.ts (inside the same describe block):

test("publish resend with invalid api key exits non-zero (issue #94)", async () => {
  const ctx = createTestContext();
  setTestConfig(ctx, {
    apiKey: "nemar_invalid_key_for_exit_code_test_xxxxxxxxxxxx",
    apiUrl: TEST_CONFIG.apiUrl,
    username: "test-user",
  });

  const { exitCode } = await runCli(["dataset", "publish", "resend", "nm000104"], ctx);
  expect(exitCode).toBe(1);
});

Suggestions

Bogus-key request test hits a live dataset with a POST (test/publish-workflow.test.ts:249)

publish request uses POST /datasets/nm000104/publish/request. With a bogus key the server returns 401 before any mutation, so it is safe in practice. However, using nm000104 (a live dataset) is slightly surprising given the project's convention of using nm099999 for anything that touches the API. Consider swapping to nm099999 for consistency with the rest of the test file.

Scope creep rationale should be in commit message or PR description

The original issue (#94) called out only publish request and publish status. The agent correctly identified resend as having the same bug and fixed it in the same commit, which is the right call. The PR description does mention it. No action required, just noting the scope expansion is well-justified.


Nice-to-haves

None.


False positives

None.


Verdict

The core fix is correct and minimal. All three catch blocks now have process.exit(1) at the correct position (after the error branches, before the closing brace). isAuthenticated() only checks for the presence of an apiKey field in config, so the bogus-key tests do reach the production API path and exercise the catch branch. Tests are deterministic (no env-dependent assertions in the new unconditional tests). TypeScript passes clean.

One important gap: the resend exit-code path has no unconditional test. All other findings are minor. The PR is merge-ready once that test is added.

Adds the missing unconditional test for publish resend (mirrors the
existing status/request bogus-key tests). Also changes nm000104 to
nm099999 in the two existing bogus-key tests (test convention).
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Addressed review findings:

  • Added unconditional bogus-key exit-code test for resend, mirroring the existing status and request tests (all 3 pass without TEST_USER_API_KEY)
  • Changed nm000104 to nm099999 in the two existing bogus-key tests per test convention

Commit: 42de81c

@neuromechanist
neuromechanist merged commit 8c26e4f into dev May 14, 2026
7 of 9 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-94-publish-exit-code branch May 14, 2026 05:16

This branch was previously deployed

1 inactive deployment
npm — 33cdf8e9 Deployed May 14, 2026 by neuromechanist via publish #835
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.

1 participant