• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / edge-runtime / 18860230569

28 Oct 2025 12:36AM UTC coverage: 51.909% (-0.06%) from 51.966%
18860230569

push

github

web-flow
fix: replace gh runner with `blacksmith` and some improvements for fixing flaky tests (#624)

* chore: replace gh runner with `blacksmith`

* stamp: meow

* fix: it seems some library in jsr.io refers to `SharedArrayBuffer`

* chore(base): add dev dependency

* stamp: render diffs

* stamp: eprintln

* stamp: prohibit RealFs

* stamp: clippy

17 of 61 new or added lines in 2 files covered. (27.87%)

75 existing lines in 8 files now uncovered.

18533 of 35703 relevant lines covered (51.91%)

5447.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/cli/src/main.rs
1
use std::fs::File;
2
use std::io::Write;
3
use std::net::IpAddr;
4
use std::net::SocketAddr;
5
use std::path::PathBuf;
6
use std::process::ExitCode;
7
use std::str::FromStr;
8
use std::sync::Arc;
9
use std::time::Duration;
10

11
use anyhow::bail;
12
use anyhow::Context;
13
use anyhow::Error;
14
use base::server;
15
use base::server::Builder;
16
use base::server::ServerFlags;
17
use base::server::Tls;
18
use base::utils::units::percentage_value;
19
use base::worker::pool::SupervisorPolicy;
20
use base::worker::pool::WorkerPoolPolicy;
21
use base::CacheSetting;
22
use base::InspectorOption;
23
use base::WorkerKind;
24
use deno::deno_telemetry;
25
use deno::deno_telemetry::OtelConfig;
26
use deno::ConfigMode;
27
use deno::DenoOptionsBuilder;
28
use deno_facade::extract_from_file;
29
use deno_facade::generate_binary_eszip;
30
use deno_facade::EmitterFactory;
31
use deno_facade::Metadata;
32
use env::resolve_deno_runtime_env;
33
use flags::get_cli;
34
use flags::EszipV2ChecksumKind;
35
use flags::OtelConsoleConfig;
36
use flags::OtelKind;
37
use log::warn;
38
use tokio::time::timeout;
39

40
mod env;
41
mod flags;
42

43
#[cfg(not(feature = "tracing"))]
44
mod logger;
45

46
fn main() -> Result<ExitCode, anyhow::Error> {
×
47
  resolve_deno_runtime_env();
×
48

×
49
  let runtime = tokio::runtime::Builder::new_current_thread()
×
50
    .enable_all()
×
51
    .thread_name("sb-main")
×
52
    .build()
×
53
    .unwrap();
×
54

×
55
  // TODO: Tokio runtime shouldn't be needed here (Address later)
×
56
  let local = tokio::task::LocalSet::new();
×
57
  let res: Result<ExitCode, Error> = local.block_on(&runtime, async {
×
58
    let matches = get_cli().get_matches();
×
59
    let verbose = matches.get_flag("verbose");
×
60

×
61
    if !matches.get_flag("quiet") {
×
62
      #[cfg(feature = "tracing")]
63
      {
64
        use tracing_subscriber::fmt::format::FmtSpan;
65
        use tracing_subscriber::EnvFilter;
66

67
        tracing_subscriber::fmt()
68
          .with_env_filter(EnvFilter::from_default_env())
69
          .with_thread_names(true)
70
          .with_span_events(if verbose {
71
            FmtSpan::FULL
72
          } else {
73
            FmtSpan::NONE
74
          })
75
          .init()
76
      }
77

78
      #[cfg(not(feature = "tracing"))]
79
      {
×
80
        let include_source = matches.get_flag("log-source");
×
81
        logger::init(verbose, include_source);
×
82
      }
×
83
    }
×
84

85
    #[allow(clippy::single_match)]
86
    #[allow(clippy::arc_with_non_send_sync)]
87
    let exit_code = match matches.subcommand() {
×
88
      Some(("start", sub_matches)) => {
×
89
        deno_telemetry::init(
×
90
          deno::versions::otel_runtime_config(),
×
91
          OtelConfig::default(),
×
92
        )?;
×
93

94
        let ip = sub_matches.get_one::<String>("ip").cloned().unwrap();
×
95
        let ip = IpAddr::from_str(&ip)
×
96
          .context("failed to parse the IP address to bind the server")?;
×
97

98
        let port = sub_matches.get_one::<u16>("port").copied().unwrap();
×
99

×
100
        let addr = SocketAddr::new(ip, port);
×
101

102
        let maybe_tls =
×
103
          if let Some(port) = sub_matches.get_one::<u16>("tls").copied() {
×
104
            let Some((key_slice, cert_slice)) = sub_matches
×
105
              .get_one::<PathBuf>("key")
×
106
              .and_then(|it| std::fs::read(it).ok())
×
107
              .zip(
×
108
                sub_matches
×
109
                  .get_one::<PathBuf>("cert")
×
110
                  .and_then(|it| std::fs::read(it).ok()),
×
111
              )
×
112
            else {
113
              bail!("unable to load the key file or cert file");
×
114
            };
115

116
            Some(Tls::new(port, &key_slice, &cert_slice)?)
×
117
          } else {
118
            None
×
119
          };
120

121
        let main_service_path = sub_matches
×
122
          .get_one::<String>("main-service")
×
123
          .cloned()
×
124
          .unwrap();
×
125

×
126
        let no_module_cache = sub_matches
×
127
          .get_one::<bool>("disable-module-cache")
×
128
          .cloned()
×
129
          .unwrap();
×
130

×
131
        let allow_main_inspector = sub_matches
×
132
          .get_one::<bool>("inspect-main")
×
133
          .cloned()
×
134
          .unwrap();
×
135

×
136
        let enable_otel = sub_matches
×
137
          .get_many::<OtelKind>("enable-otel")
×
138
          .unwrap_or_default()
×
139
          .cloned()
×
140
          .collect::<Vec<_>>();
×
141

×
142
        let otel_console = sub_matches
×
143
          .get_one::<OtelConsoleConfig>("otel-console")
×
144
          .cloned()
×
145
          .map(Into::into);
×
146

×
147
        let event_service_manager_path =
×
148
          sub_matches.get_one::<String>("event-worker").cloned();
×
149
        let maybe_main_entrypoint =
×
150
          sub_matches.get_one::<String>("main-entrypoint").cloned();
×
151
        let maybe_events_entrypoint =
×
152
          sub_matches.get_one::<String>("events-entrypoint").cloned();
×
153

×
154
        let maybe_supervisor_policy = sub_matches
×
155
          .get_one::<String>("policy")
×
156
          .map(|it| it.parse::<SupervisorPolicy>().unwrap());
×
157

×
158
        let graceful_exit_deadline_sec = sub_matches
×
159
          .get_one::<u64>("graceful-exit-timeout")
×
160
          .cloned()
×
161
          .unwrap_or(0);
×
162

×
163
        let graceful_exit_keepalive_deadline_ms = sub_matches
×
164
          .get_one::<u64>("experimental-graceful-exit-keepalive-deadline-ratio")
×
165
          .cloned()
×
166
          .and_then(|it| {
×
167
            if it == 0 {
×
168
              return None;
×
169
            }
×
170

×
171
            percentage_value(graceful_exit_deadline_sec * 1000, it)
×
172
          });
×
173

×
174
        let event_worker_exit_deadline_sec = sub_matches
×
175
          .get_one::<u64>("event-worker-exit-timeout")
×
176
          .cloned()
×
177
          .unwrap_or(0);
×
178

×
179
        let maybe_max_parallelism =
×
180
          sub_matches.get_one::<usize>("max-parallelism").cloned();
×
181
        let maybe_request_wait_timeout =
×
182
          sub_matches.get_one::<u64>("request-wait-timeout").cloned();
×
183
        let maybe_request_idle_timeout =
×
184
          sub_matches.get_one::<u64>("request-idle-timeout").cloned();
×
185
        let maybe_request_read_timeout =
×
186
          sub_matches.get_one::<u64>("request-read-timeout").cloned();
×
187

×
188
        let maybe_beforeunload_wall_clock_pct = sub_matches
×
189
          .get_one::<u8>("dispatch-beforeunload-wall-clock-ratio")
×
190
          .cloned();
×
191
        let maybe_beforeunload_cpu_pct = sub_matches
×
192
          .get_one::<u8>("dispatch-beforeunload-cpu-ratio")
×
193
          .cloned();
×
194
        let maybe_beforeunload_memory_pct = sub_matches
×
195
          .get_one::<u8>("dispatch-beforeunload-memory-ratio")
×
196
          .cloned();
×
197

198
        let static_patterns =
×
199
          if let Some(val_ref) = sub_matches.get_many::<String>("static") {
×
200
            val_ref.map(|s| s.as_str()).collect::<Vec<&str>>()
×
201
          } else {
202
            vec![]
×
203
          };
204

205
        let static_patterns: Vec<String> =
×
206
          static_patterns.into_iter().map(|s| s.to_string()).collect();
×
207

×
208
        let inspector = sub_matches.get_one::<clap::Id>("inspector").zip(
×
209
          sub_matches
×
210
            .get_one("inspect")
×
211
            .or(sub_matches.get_one("inspect-brk"))
×
212
            .or(sub_matches.get_one::<SocketAddr>("inspect-wait")),
×
213
        );
×
214

215
        let maybe_inspector_option = if let Some((key, addr)) = inspector {
×
216
          Some(get_inspector_option(key.as_str(), addr).unwrap())
×
217
        } else {
218
          None
×
219
        };
220

221
        let tcp_nodelay =
×
222
          sub_matches.get_one::<bool>("tcp-nodelay").copied().unwrap();
×
223
        let request_buffer_size = sub_matches
×
224
          .get_one::<u64>("request-buffer-size")
×
225
          .copied()
×
226
          .unwrap();
×
227

228
        let flags = ServerFlags {
×
229
          otel: if !enable_otel.is_empty() {
×
230
            if enable_otel.len() > 1 {
×
231
              Some(server::OtelKind::Both)
×
232
            } else {
233
              match enable_otel.first() {
×
234
                Some(OtelKind::Main) => Some(server::OtelKind::Main),
×
235
                Some(OtelKind::Event) => Some(server::OtelKind::Event),
×
236
                None => None,
×
237
              }
238
            }
239
          } else {
240
            None
×
241
          },
242
          otel_console,
×
243

×
244
          no_module_cache,
×
245
          allow_main_inspector,
×
246
          tcp_nodelay,
×
247

×
248
          graceful_exit_deadline_sec,
×
249
          graceful_exit_keepalive_deadline_ms,
×
250
          event_worker_exit_deadline_sec,
×
251
          request_wait_timeout_ms: maybe_request_wait_timeout,
×
252
          request_idle_timeout_ms: maybe_request_idle_timeout,
×
253
          request_read_timeout_ms: maybe_request_read_timeout,
×
254
          request_buffer_size: Some(request_buffer_size),
×
255

×
256
          beforeunload_wall_clock_pct: maybe_beforeunload_wall_clock_pct,
×
257
          beforeunload_cpu_pct: maybe_beforeunload_cpu_pct,
×
258
          beforeunload_memory_pct: maybe_beforeunload_memory_pct,
×
259
        };
×
260

×
261
        let mut builder = Builder::new(addr, &main_service_path);
×
262

×
263
        builder.user_worker_policy(WorkerPoolPolicy::new(
×
264
          maybe_supervisor_policy,
×
265
          if let Some(true) = maybe_supervisor_policy
×
266
            .as_ref()
×
267
            .map(SupervisorPolicy::is_oneshot)
×
268
          {
269
            if let Some(parallelism) = maybe_max_parallelism {
×
270
              if parallelism == 0 || parallelism > 1 {
×
271
                warn!(
×
272
                  "{}",
×
273
                  concat!(
274
                    "if `oneshot` policy is enabled, the maximum ",
275
                    "parallelism is fixed to `1` as forcibly ^^"
276
                  )
277
                );
278
              }
×
279
            }
×
280

281
            Some(1)
×
282
          } else {
283
            maybe_max_parallelism
×
284
          },
285
          flags,
×
286
        ));
287

288
        if let Some(tls) = maybe_tls {
×
289
          builder.tls(tls);
×
290
        }
×
291
        if let Some(worker_path) = event_service_manager_path {
×
292
          builder.event_worker_path(&worker_path);
×
293
        }
×
294
        if let Some(inspector_option) = maybe_inspector_option {
×
295
          builder.inspector(inspector_option);
×
296
        }
×
297

298
        builder.extend_static_patterns(static_patterns);
×
299
        builder.entrypoints_mut().main = maybe_main_entrypoint;
×
300
        builder.entrypoints_mut().events = maybe_events_entrypoint;
×
301

×
302
        *builder.flags_mut() = flags;
×
303

304
        let maybe_received_signum_or_exit_code =
×
305
          builder.build().await?.listen().await?;
×
306

307
        maybe_received_signum_or_exit_code
×
308
          .map(|it| it.map_left(|it| ExitCode::from(it as u8)).into_inner())
×
309
          .unwrap_or_default()
×
310
      }
311

312
      Some(("bundle", sub_matches)) => {
×
313
        let output_path =
×
314
          sub_matches.get_one::<String>("output").cloned().unwrap();
×
315
        let import_map_path =
×
316
          sub_matches.get_one::<String>("import-map").cloned();
×
317
        let decorator = sub_matches.get_one::<String>("decorator").cloned();
×
318
        let static_patterns =
×
319
          if let Some(val_ref) = sub_matches.get_many::<String>("static") {
×
320
            val_ref.map(|s| s.as_str()).collect::<Vec<&str>>()
×
321
          } else {
322
            vec![]
×
323
          };
324
        let timeout_dur = sub_matches
×
325
          .get_one::<u64>("timeout")
×
326
          .cloned()
×
327
          .map(Duration::from_secs);
×
328

×
329
        if import_map_path.is_some() {
×
330
          warn!(concat!(
×
331
            "Specifying import_map through flags is no longer supported. ",
×
332
            "Please use deno.json instead."
×
333
          ))
×
334
        }
×
335
        if decorator.is_some() {
×
336
          warn!(concat!(
×
337
            "Specifying decorator through flags is no longer supported. ",
×
338
            "Please use deno.json instead."
×
339
          ))
×
340
        }
×
341

342
        let entrypoint_script_path = sub_matches
×
343
          .get_one::<String>("entrypoint")
×
344
          .cloned()
×
345
          .unwrap();
×
346

×
347
        let entrypoint_script_path =
×
348
          PathBuf::from(entrypoint_script_path.as_str());
×
349
        if !entrypoint_script_path.is_file() {
×
350
          bail!(
×
351
            "entrypoint path does not exist ({})",
×
352
            entrypoint_script_path.display()
×
353
          );
×
354
        }
×
355

×
356
        let entrypoint_script_path =
×
357
          entrypoint_script_path.canonicalize().unwrap();
×
358

×
359
        let mut emitter_factory = EmitterFactory::new();
×
360

×
361
        if sub_matches
×
362
          .get_one::<bool>("disable-module-cache")
×
363
          .cloned()
×
364
          .unwrap()
×
365
        {
×
366
          emitter_factory.set_cache_strategy(Some(CacheSetting::ReloadAll));
×
367
        }
×
368

369
        let maybe_checksum_kind = sub_matches
×
370
          .get_one::<EszipV2ChecksumKind>("checksum")
×
371
          .copied()
×
372
          .and_then(EszipV2ChecksumKind::into);
×
373

×
374
        emitter_factory.set_permissions_options(Some(
×
375
          base::get_default_permissions(WorkerKind::MainWorker),
×
376
        ));
×
377

×
378
        let mut builder =
×
379
          DenoOptionsBuilder::new().entrypoint(entrypoint_script_path.clone());
×
380

381
        if let Some(path) = import_map_path {
×
382
          let path = PathBuf::from(path);
×
383
          if !path.exists() || !path.is_file() {
×
384
            bail!("import map path is incorrect");
×
385
          }
×
386
          builder.set_config(Some(ConfigMode::Path(path)));
×
387
        }
×
388
        emitter_factory.set_deno_options(builder.build()?);
×
389

390
        let mut metadata = Metadata::default();
×
391
        let eszip_fut = generate_binary_eszip(
×
392
          &mut metadata,
×
393
          Arc::new(emitter_factory),
×
394
          None,
×
395
          maybe_checksum_kind,
×
396
          Some(static_patterns),
×
397
        );
×
398

399
        let eszip = if let Some(dur) = timeout_dur {
×
400
          match timeout(dur, eszip_fut).await {
×
401
            Ok(eszip) => eszip,
×
402
            Err(_) => {
403
              bail!("Failed to complete the bundle within the given time.")
×
404
            }
405
          }
406
        } else {
407
          eszip_fut.await
×
408
        }?;
×
409

410
        let bin = eszip.into_bytes();
×
411

×
412
        if output_path == "-" {
×
413
          let stdout = std::io::stdout();
×
414
          let mut handle = stdout.lock();
×
415

×
416
          handle.write_all(&bin)?
×
417
        } else {
418
          let mut file = File::create(output_path.as_str())?;
×
419
          file.write_all(&bin)?
×
420
        }
421

422
        ExitCode::SUCCESS
×
423
      }
424

425
      Some(("unbundle", sub_matches)) => {
×
426
        let output_path =
×
427
          sub_matches.get_one::<String>("output").cloned().unwrap();
×
428
        let eszip_path =
×
429
          sub_matches.get_one::<String>("eszip").cloned().unwrap();
×
430

×
431
        let output_path = PathBuf::from(output_path.as_str());
×
432
        let eszip_path = PathBuf::from(eszip_path.as_str());
×
433

×
434
        if extract_from_file(eszip_path, output_path.clone()).await {
×
435
          println!(
×
436
            "Eszip extracted successfully inside path {}",
×
437
            output_path.to_str().unwrap()
×
438
          );
×
439
          ExitCode::SUCCESS
×
440
        } else {
441
          ExitCode::FAILURE
×
442
        }
443
      }
444

445
      _ => {
446
        // unrecognized command
UNCOV
447
        ExitCode::FAILURE
×
448
      }
449
    };
450

451
    Ok(exit_code)
×
452
  });
×
453

×
454
  res
×
UNCOV
455
}
×
456

457
fn get_inspector_option(
×
458
  key: &str,
×
459
  addr: &SocketAddr,
×
460
) -> Result<InspectorOption, anyhow::Error> {
×
461
  match key {
×
462
    "inspect" => Ok(InspectorOption::Inspect(*addr)),
×
463
    "inspect-brk" => Ok(InspectorOption::WithBreak(*addr)),
×
464
    "inspect-wait" => Ok(InspectorOption::WithWait(*addr)),
×
UNCOV
465
    key => bail!("invalid inspector key: {}", key),
×
466
  }
UNCOV
467
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc