Skip to content

server: add workerd check, and suggest the closest service name - #8083

Draft
bartlomieju wants to merge 2 commits into
mainfrom
biwanczuk/workerd-check
Draft

bartlomieju wants to merge 2 commits into
mainfrom
biwanczuk/workerd-check

Conversation

@bartlomieju

Copy link
Copy Markdown
Collaborator

Split out of #8065, rebuilt on top of #8051.

workerd check <config-file> loads a config the way serve does, .capnp or wrangler.json(c), builds every service and compiles every Worker, and resolves every socket's service. It binds no socket and joins no cluster. Every error is reported, not only the first, followed by a summary. The exit status is 1 if there was any error.

$ workerd check errors.capnp
service broken: Uncaught Error: failed at startup
  at main.js:1:7
Worker "main"'s binding "OTHER" refers to a service "mian", but no such service is defined. Did you mean "main"?
Socket "http" refers to a service "mainn", but no such service is defined. Did you mean "main"?
3 config errors found.

$ workerd check ok.capnp
Config OK: 2 services, 2 sockets.

Two commits:

  • Suggest the closest service for an unknown service name. Every lookup through lookup_service and lookup_actor_class (sockets, bindings, globalOutbound, cacheApiOutbound, tails) appends Did you mean "x"?. The suggestion is made when a defined service is within a small, case-insensitive edit distance.
  • Add workerd check.
    • --directory-path and --external-addr are checked against the config, as serve checks them.
    • A socket without an address is a warning rather than an error, because serve can take the address from --socket-addr or --socket-fd.
    • --watch and --inspector-addr are usage errors rather than being silently ignored.
    • The socket lookup that start() did inline is now socket_channel(), which both commands use.

Tests: unit tests for the hint, and a new shell test, src/workerd/server/tests/check. It runs the binary on a valid config, on one with three errors, with an override that matches nothing, on a wrangler.jsonc, and with --watch.

A designator naming a service that is not defined now ends its error
with a hint naming the closest defined service, when one is within a
small edit distance (case-insensitive Levenshtein, at most a third of
the name's length and at least 2):

  Socket "http" refers to a service "mainn", but no such service is
  defined. Did you mean "main"?

This covers every lookup through lookup_service and
lookup_actor_class: sockets, bindings, globalOutbound,
cacheApiOutbound and tails.
`workerd check <config-file>` loads a config the way `serve` does,
.capnp or wrangler.json(c), builds every service and compiles every
Worker, and resolves every socket's service, but binds no socket and
joins no cluster. It reports every error rather than only the first,
then either "N config errors found." with exit status 1, or
"Config OK: N services, N sockets.".

--directory-path and --external-addr are checked against the config
as `serve` checks them. A socket without an address is a warning,
since `serve` takes it from --socket-addr or --socket-fd. --watch and
--inspector-addr are usage errors rather than silently ignored.

The socket designator lookup `start` did inline moves into
socket_channel, which `check` shares. A shell test runs the binary on
a valid config, one with three errors, an unmatched override and a
wrangler.jsonc.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 32.00000% with 102 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.15%. Comparing base (c564d8a) to head (5236c69).

Files with missing lines Patch % Lines
src/workerd/server/server/entry.rs 0.00% 45 Missing ⚠️
src/workerd/server/cli/lib.rs 0.00% 31 Missing ⚠️
src/workerd/server/server/run.rs 39.47% 23 Missing ⚠️
src/workerd/server/server/config.rs 91.66% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8083      +/-   ##
==========================================
- Coverage   68.18%   68.15%   -0.03%     
==========================================
  Files         712      712              
  Lines      185743   185881     +138     
  Branches    29255    29255              
==========================================
+ Hits       126645   126685      +40     
- Misses      42019    42118      +99     
+ Partials    17079    17078       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

2 participants