feat(user-scripts): store secret settings in SecretStorage#1373
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds end-to-end support for a ChangesUser-Script Secret Settings
Sequence Diagram(s)sequenceDiagram
rect rgba(135, 180, 250, 0.5)
Note over UserScriptSettingsModal: Modal Open
UserScriptSettingsModal->>migrateUserScriptSecretSettings: app, command, settingsDef
migrateUserScriptSecretSettings->>SecretStorage: store legacy plaintext secret
migrateUserScriptSecretSettings-->>UserScriptSettingsModal: changed=true
UserScriptSettingsModal->>UserScriptSettingsModal: onCommandChange() + display()
end
rect rgba(80, 200, 140, 0.5)
Note over UserScriptSettingsModal: Save Secret
UserScriptSettingsModal->>storeUserScriptSecret: app, command, settingName, value
storeUserScriptSecret->>SecretStorage: secretStorage.store(secretId, value)
storeUserScriptSecret-->>UserScriptSettingsModal: secretRef
UserScriptSettingsModal->>UserScriptSettingsModal: command.settings[name] = createUserScriptSecretRef(secretRef)
end
rect rgba(250, 160, 100, 0.5)
Note over MacroChoiceEngine: Script Execution
MacroChoiceEngine->>migrateUserScriptSecretSettings: app, command, settingsDef
migrateUserScriptSecretSettings-->>MacroChoiceEngine: changed → saveSettings()
MacroChoiceEngine->>resolveUserScriptSettings: app, command, settingsDef
resolveUserScriptSettings->>SecretStorage: read secret by secretRef
resolveUserScriptSettings-->>MacroChoiceEngine: { secretName: plaintextValue }
MacroChoiceEngine->>UserScript: invoke with resolved settings
end
Estimated code review effort🎯 5 (Critical) | ⏱️ ~120 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Deploying quickadd with
|
| Latest commit: |
9e1e687
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://b7d3f760.quickadd.pages.dev |
| Branch Preview URL: | https://chhoumann-user-script-secret.quickadd.pages.dev |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f14a0f6a79
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
🧹 Nitpick comments (2)
tests/obsidian-stub.ts (1)
519-544: ⚡ Quick winUse tab indentation in the new
Modalstub block.This block is indented with spaces, but this repository’s TS style requires tabs.
As per coding guidelines,
**/*.{ts,tsx,js,jsx,svelte,css,scss,json,md}must use tab indentation and LF line endings as configured in.editorconfig.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/obsidian-stub.ts` around lines 519 - 544, Replace all space indentation with tab indentation throughout the Modal class block (including the constructor, open method, and close method). Ensure all lines within the class definition, from the property declarations through the close method implementation, use tabs instead of spaces to comply with the repository's .editorconfig settings that require tab indentation for TypeScript files.Source: Coding guidelines
src/services/choiceService.ts (1)
236-254: 💤 Low valueConsider consolidating the duplicated secret-clearing branches.
The
isMacroandisMultibranches execute identical code. Combining them into a single condition improves maintainability.♻️ Suggested consolidation
- if (isMacro) { - const cleared = await clearUserScriptSecretsFromCommand(app, { - type: "NestedChoice", - choice, - }); - if (!cleared) { - new Notice("Could not clear user script secrets. Choice was not deleted."); - return false; - } - } else if (isMulti) { - const cleared = await clearUserScriptSecretsFromCommand(app, { - type: "NestedChoice", - choice, - }); - if (!cleared) { - new Notice("Could not clear user script secrets. Choice was not deleted."); - return false; - } - } + if (isMacro || isMulti) { + const cleared = await clearUserScriptSecretsFromCommand(app, { + type: "NestedChoice", + choice, + }); + if (!cleared) { + new Notice("Could not clear user script secrets. Choice was not deleted."); + return false; + } + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/services/choiceService.ts` around lines 236 - 254, The isMacro and isMulti branches contain identical code that calls clearUserScriptSecretsFromCommand with the same parameters and handles errors identically. Consolidate these two branches into a single conditional statement by combining the conditions with OR logic (isMacro || isMulti), and remove the duplicate code block so the secret-clearing logic and error handling only appears once.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/services/choiceService.ts`:
- Around line 236-254: The isMacro and isMulti branches contain identical code
that calls clearUserScriptSecretsFromCommand with the same parameters and
handles errors identically. Consolidate these two branches into a single
conditional statement by combining the conditions with OR logic (isMacro ||
isMulti), and remove the duplicate code block so the secret-clearing logic and
error handling only appears once.
In `@tests/obsidian-stub.ts`:
- Around line 519-544: Replace all space indentation with tab indentation
throughout the Modal class block (including the constructor, open method, and
close method). Ensure all lines within the class definition, from the property
declarations through the close method implementation, use tabs instead of spaces
to comply with the repository's .editorconfig settings that require tab
indentation for TypeScript files.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 340f00e1-9650-4fe9-92d0-82d6a239fad8
📒 Files selected for processing (21)
docs/docs/Advanced/scriptsWithSettings.mddocs/docs/UserScripts.mdsrc/engine/MacroChoiceEngine.entry.test.tssrc/engine/MacroChoiceEngine.tssrc/engine/SingleMacroEngine.member-access.test.tssrc/engine/SingleMacroEngine.tssrc/gui/MacroGUIs/CommandSequenceEditor.tssrc/gui/MacroGUIs/UserScriptSettingsModal.test.tssrc/gui/MacroGUIs/UserScriptSettingsModal.tssrc/gui/choiceList/ChoiceView.sveltesrc/services/choiceService.test.tssrc/services/choiceService.tssrc/services/packageExportService.test.tssrc/services/packageExportService.tssrc/services/packageImportService.test.tssrc/services/packageImportService.tssrc/utils/userScriptSecrets.test.tssrc/utils/userScriptSecrets.tssrc/utils/userScriptSettings.tstests/obsidian-stub.tstests/vitest-setup.ts
|
Addressed the remaining CodeRabbit review-body nitpicks in 9e1e687: consolidated the duplicated Macro/Multi secret-clearing branch in |
Summary
type: "secret"user-script settings backed by Obsidianapp.secretStorage, with legacytype: "text" | "input", secret: truetreated the same way.data.json.Design notes
quickadd-user-script-<command>-<setting>) and persisted in settings as{ __quickaddSecret: true, secretRef }markers.Issue tracker check
Validation
pnpm exec tsc --noEmit --skipLibCheck --pretty falsepnpm run lintpnpm run check(0 errors, existing 4 warnings)pnpm run test(218 files passed, 2533 tests passed, 31 skipped)pnpm run buildReal Obsidian E2E evidence
Used this worktree's isolated vault via
pnpm run obsidian:e2e -- ....UserScriptSettingsModalpassword input.Save API Key,Clear API Key.qa-e2e-secret-value-173whiledata.jsoncontained only the marker and did not contain plaintext.quickadd:run choice='Secret Roundtrip'; user script read the resolved secret and wrote it tosecret-output.txt, whiledata.jsonstill had no plaintext.API Key, SecretStorage returnednull, runtime output was empty, anddata.jsoncontained neither old nor updated plaintext.data.json, reloaded QuickAdd, ran the macro, and confirmed lazy migration wrote SecretStorage, persisted the marker, removed plaintext fromdata.json, and passed the secret to the script.Release / migration impact
Summary by CodeRabbit
Release Notes
New Features
secretoption type for user scripts with password-style input and “API Key” example.Improvements
Documentation
secretguidance and backward compatibility.Tests