Skip to content

DX-2803: expose read-only QStash & Workflow tools for readonly API keys - #19

Merged
ytkimirti merged 4 commits into
mainfrom
DX-2803
Jul 6, 2026
Merged

DX-2803: expose read-only QStash & Workflow tools for readonly API keys#19
ytkimirti merged 4 commits into
mainfrom
DX-2803

Conversation

@CahidArda

Copy link
Copy Markdown
Contributor

Summary

Read-only Upstash API keys previously exposed only Redis tools — all QStash and
Workflow tools were hidden and hard-errored. The Upstash API returns a
read_only_token per region for read-only keys (the full-access token is empty),
which works on read endpoints and is rejected by QStash on any write. This wires
that token through so read-only keys can list QStash logs, DLQ, schedules, and
Workflow logs/DLQ.

Changes

  • types.ts: add read_only_token to QStashUser.
  • utils.ts: remove the readonly hard-throw; select read_only_token vs token
    by mode in getQStashCredentials, with a guard for a missing token.
  • qstash.ts / workflow.ts: mark the read tools readonly: true
    (qstash_logs_list/get, qstash_dlq_list/get, qstash_schedules_list,
    workflow_logs_list/get, workflow_dlq_list/get). Write tools
    (publish, schedules_manage, workflow_dlq_manage) stay hidden.
  • readonly.test.ts: replace "not available" assertions with live read-tool
    checks and a write-rejection check.
  • README.md: note QStash/Workflow reads are available with readonly keys; Box is not.

Testing

  • Verified live: readonly key fetches read_only_token, reads succeed (200),
    publish rejected (403).
  • bun test src/readonly.test.ts → 13 pass / 0 fail. prettier + eslint clean.

Notes

  • Box tools remain unavailable with a readonly key (not yet implementable).

@linear-code

linear-code Bot commented Jul 3, 2026

Copy link
Copy Markdown

DX-2803

CahidArda added 3 commits July 3, 2026 14:51
E2E tests hit real Upstash APIs and log() wrote full request/response
bodies to stderr, which CI captured into public logs, leaking QStash and
Redis tokens. Disable logging under NODE_ENV=test, and redact
secret-bearing fields (token, rest_token, password, etc.) from all log
output as a backstop even when logging is enabled.
…race

- qstash.test.ts: clear the shared QStash user cache and reset config.readonly
  in beforeAll so it can't reuse read-only users cached by readonly.test.ts
  (whose token field is empty), which broke 'lists schedules (eu)'.
- box.test.ts: poll the snapshot list until it leaves the 'creating' state
  before deleting, avoiding a 409 'Snapshot is still being created'.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends readonly Upstash API key support to allow QStash + Workflow read operations by wiring through the per-region read_only_token returned by the Upstash API, while keeping write tools hidden/blocked.

Changes:

  • Add read_only_token to QStash user typing and update QStash credential selection to choose read_only_token vs token based on readonly mode (with an explicit missing-token guard).
  • Mark QStash/Workflow read tools as readonly: true so they remain available when the server filters tools for readonly keys; update readonly/QStash tests accordingly (including cache reset between suites).
  • Add test-runner log suppression + secret redaction utilities (with unit tests), plus improve Box snapshot E2E stability by polling until snapshots are ready before deletion.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/tools/qstash/workflow.ts Marks Workflow log/DLQ read tools as readonly: true so they’re available under readonly keys.
src/tools/qstash/utils.ts Uses read_only_token in readonly mode; removes the previous hard-throw that blocked QStash entirely in readonly mode.
src/tools/qstash/types.ts Adds read_only_token to QStashUser.
src/tools/qstash/qstash.ts Marks QStash logs/DLQ/schedules list/get tools as readonly: true.
src/tools/qstash/qstash.test.ts Forces full-access mode and clears shared QStash token cache to avoid cross-test contamination.
src/tools/box/box.test.ts Adds snapshot readiness polling before deletion to reduce 409 flakiness; adjusts timeouts/formatting.
src/readonly.test.ts Updates expectations: QStash/Workflow read tools are available in readonly mode; adds a publish rejection check.
src/log.ts Disables logging under tests and adds defense-in-depth redaction for sensitive keys.
src/log.test.ts Adds unit tests for log-argument redaction behavior.
README.md Documents readonly key behavior for QStash/Workflow reads and adds local smoke-test instructions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/log.ts
Comment on lines +44 to +56
function redactValue(value: unknown): unknown {
if (Array.isArray(value)) {
return value.map((item) => redactValue(item));
}
if (value && typeof value === "object") {
const out: Record<string, unknown> = {};
for (const [key, val] of Object.entries(value)) {
out[key] = SENSITIVE_KEYS.has(key.toLowerCase()) ? REDACTED : redactValue(val);
}
return out;
}
return value;
}
Comment thread src/readonly.test.ts
body: "{}",
method: "POST",
})
).rejects.toThrow();
@ytkimirti
ytkimirti merged commit e3ab3c2 into main Jul 6, 2026
3 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.

3 participants