Skip to content

Warn on schemeless tool URL templates - #159

Merged
dantheuber merged 14 commits into
mainfrom
freight/feature-tool-url-scheme-warning
Sep 6, 2026
Merged

Warn on schemeless tool URL templates#159
dantheuber merged 14 commits into
mainfrom
freight/feature-tool-url-scheme-warning

Conversation

@dantheuber

@dantheuber dantheuber commented Sep 2, 2026

Copy link
Copy Markdown
Owner

This branch assembles the listed issues for review.

Issues in this consist

Closes #157

What & why

Tool URL templates without an http:///https:// scheme silently opened zero tabs, with no indication to the user why. This adds an inline warning in the tool editor and makes the tray's "opened tabs" toast honest about partial failures.

Changes

  • Added hasWebScheme to src/shared/tools.ts as the single source of truth for the scheme check (case-insensitive, trimmed).
  • ToolEditor shows an inline warning under the URL field when the template lacks a web scheme, with an "add https://" link that prefixes the scheme and preserves cursor position.
  • Tray.openTabs now reports "Opened N of M tabs; only http and https links can open" when fewer tabs opened than were offered, instead of a misleading plain success count.
  • README updated to document the http/https requirement for tool URLs.

Review notes

  • The main-process allowlist in open-external.ts remains the actual enforcement point; the editor warning is informational only and does not block saving.
  • Tests added alongside each change (ToolEditor, Tray, tools).
  • Branch merged current with main; typecheck and full test suite (87 files, 1065 tests) pass after the merge.
  • Version bumped to 2.3.0 (minor) — new backward-compatible functionality, no breaking changes.

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

📊 Coverage Report

Metric Coverage
Statements 94.18%
Branches 93.7%
Functions 95.04%
Lines 94.28%

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

🧪 E2E Test Results

36 passed, 0 failed, 0 skipped

Test Suite Result
App Launch
Clipboard
Context Menu
Image Clipboard
Quick Clips
Quick look
Quick look — clipboard writes
Quick look — rendered html
Settings window
Theme
Settings — Tools tab
Quick look — pattern scanning
Quick look — clip templates

cb-jeeves and others added 3 commits September 2, 2026 08:02
… tabs honestly

Closes the silent "Opened 0 tabs" path from #157. A template that does not
start with http:// or https:// now gets an inline warning under the URL field
in ToolEditor, in the same msg/msgWarn style the Hotkeys rows use, with an
"add https://" link that prefixes the scheme, trims leading whitespace and
leaves the caret after the prefix. In Tray.openTabs, when the main process
opened fewer tabs than were offered, the toast reads "Opened N of M tabs;
only http and https links can open" instead of a plain success count.

Decisions:
- The scheme check lives in src/shared/tools.ts as hasWebScheme (case-
  insensitive, trimmed) so the editor and any future caller agree; the
  main-process allowlist in open-external.ts is untouched and remains the
  enforcement point, per the issue.
- Saving is still allowed with a schemeless template; the warning informs
  rather than blocks, matching the Hotkeys reserved-combination pattern.
- The tray message is aggregate per click (N of M across all URLs offered),
  since openExternalUrls only returns a count.

Files: src/shared/tools.ts, ToolEditor.tsx, Tray.tsx, plus tests for each.
@cb-jeeves
cb-jeeves marked this pull request as ready for review September 2, 2026 08:08
@cb-jeeves cb-jeeves added the Jeeves-Review Jeeves: request a skeptical review of this issue label Sep 2, 2026

@cb-jeeves cb-jeeves left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Adds a shared hasWebScheme check, an inline warning plus one-click fix in the tool editor, and an honest "Opened N of M tabs" toast. The shape is right and the tests cover the happy paths. One defect in the one-click fix is worth handling before merge. The correctness lens failed this round and contributed nothing.

The correctness pass did not complete this round.

Comment thread src/renderer/src/components/settings/tools/ToolEditor.tsx Outdated
The one-click fix prepended https:// to whatever the template held, so
ftp://host became https://ftp://host and mailto:a@b became
https://mailto:a@b, both of which silence the warning while pointing at
the wrong host. Strip a leading scheme first. A colon followed by a digit
is left alone so a schemeless host:port keeps its port.
@cb-jeeves

Copy link
Copy Markdown
Collaborator

Responded to review round 1, pushed 0370cf1:

  • Addressed the "add https://" fix keeping an existing scheme: addScheme now strips a leading scheme before prefixing, so ftp://, mailto:, file:// and the https:/ typo all become real https URLs. A colon followed by a digit is left alone so a schemeless host:port keeps its port. Added editor tests for each case. Typecheck and the full test suite pass.

@cb-jeeves cb-jeeves left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since last round, 0370cf1 makes the one-click fix strip an existing scheme before prefixing https://, with a digit lookahead so a schemeless host:port keeps its port. That resolves the ftp:// and mailto: defect from round 1, and the reply's reasoning for the lookahead holds. The PR is ready apart from one minor placement suggestion below. The correctness lens failed this round and contributed nothing.

The correctness pass did not complete this round.

Comment thread src/renderer/src/components/settings/tools/ToolEditor.tsx Outdated
The scheme-stripping regex has to agree with hasWebScheme, so it now lives
next to it in src/shared/tools.ts as withWebScheme, with a plain unit
table there. The editor keeps one test proving the fix button is wired up.
@cb-jeeves

Copy link
Copy Markdown
Collaborator

Responded to review round 2, pushed 83cb8c9:

  • Addressed the placement of the scheme-stripping regex: it now lives in src/shared/tools.ts as withWebScheme, beside hasWebScheme, and addScheme in ToolEditor.tsx calls it. The scheme replacement cases are a plain unit table in tools.test.ts, each also checking hasWebScheme accepts the output. The editor keeps one wiring test and one caret test. Typecheck, lint and the full test suite pass.

@cb-jeeves cb-jeeves left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since round 2, 83cb8c9 moves the scheme stripper into src/shared/tools.ts as withWebScheme beside hasWebScheme with its own unit table, exactly as asked; the correctness lens did not run this round, but the helper checks out on every case the tests cover.

The correctness pass did not complete this round.

@cb-jeeves cb-jeeves left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since round 3 the only change is the merge from main: package-lock.json and the 2.3.0 version bump. The scheme warning, one-click fix and tray toast are unchanged. The correctness lens ran for the first time this PR and found one real gap in code approved last round, so this is not yet ready to merge. Fix that and it is.

The README line added in this PR ("a tool URL must start with http:// or https://") states the same over-broad rule; once the editor exempts a leading {url} token, reword it to say the resolved link must be http or https.

Comment thread src/renderer/src/components/settings/tools/ToolEditor.tsx Outdated
A template that leads with the url token resolves to the captured value,
which the built-in url pattern captures with its http or https scheme and
buildToolUrls substitutes unencoded. The literal-prefix check flagged it
anyway and the one-click fix rewrote it to https://{url}, which resolves to
https://https://... and opens the wrong host. The editor now skips the
warning and the fix button when the template starts with {url}. A pipe
token like {url|domain} keeps the warning since a domain has no scheme.

Reword the README rule to describe the resolved link rather than the
template's literal prefix.
@cb-jeeves

Copy link
Copy Markdown
Collaborator

Responded to review round 4, pushed 08acb36:

  • Addressed the {url} false positive in ToolEditor.tsx: a template that leads with the url token is exempt from the scheme warning, so the fix button never rewrites it to https://{url}. The group name is matched exactly, as toolTokens does, and a pipe token like {url|domain} still warns. Added an editor test for {url}, { url }/extra, {url|domain} and x/{url}.
  • Addressed the README rule: it now says the resolved link must be http or https, so a template starts with http://, https:// or the {url} token. Typecheck, lint and the full test suite pass.

@cb-jeeves cb-jeeves left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since round 4, 08acb36 exempts a template that leads with the url token from the scheme warning and the fix button, with an editor test for {url}, { url }/extra, {url|domain} and x/{url}, and the README line now says the resolved link must be http or https. That closes the round 4 defect. One small gap remains: the exemption spells the token as a regex instead of asking toolTokens, so a url-only pipe token like {url|} still gets the warning and a fix that breaks it. It is minor and the PR is otherwise ready.

Comment thread src/renderer/src/components/settings/tools/ToolEditor.tsx Outdated
The editor exempted a leading url token with its own regex, so {url|} and
{|url}, which toolTokens reads as a url-only token, still warned and the fix
button rewrote them to https://{url|}. needsWebScheme lives beside
hasWebScheme and asks toolTokens for the first token, so the two cannot
drift. The cases move into the shared test table; the editor test keeps one
proving the warning and button stay hidden for {url}.
@cb-jeeves

Copy link
Copy Markdown
Collaborator

Responded to review round 5, pushed 0744fda:

  • Addressed the url-token exemption living in the editor as a regex: needsWebScheme in src/shared/tools.ts now decides the warning, next to hasWebScheme, and reads the leading token through toolTokens. {url|}, {|url}, { url } and {url|url} are exempt because every alternative is url; {url|domain}, x/{url} and {URL} still warn. The hasWebScheme doc comment now points at needsWebScheme instead of claiming the editor warns on everything it rejects. The cases moved into a table in tools.test.ts and the editor test keeps one {url} case. Typecheck, lint and the full test suite pass.

@dantheuber
dantheuber merged commit 5d7b130 into main Sep 6, 2026
3 checks passed
@dantheuber
dantheuber deleted the freight/feature-tool-url-scheme-warning branch September 6, 2026 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Jeeves-Review Jeeves: request a skeptical review of this issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warn when a tool URL template has no http or https scheme

3 participants