---
title: Guard league script entry points so importing a script never runs it
type: task
status: planned
description: >-
  Most league cli/ and scripts/ files run or do work on import, many writing production by default;
  put each entry behind is_main and hold it with a static test.
base_uri: user:task/league/guard-league-script-entry-points.md
created_at: '2026-10-14T22:56:43.676Z'
entity_id: f682d934-95a2-4381-ac3b-314c95cdf651
owner_identity_uri: █████████████████████████
priority: Medium
public_read: true
tags:
  - user:tag/league-xo-football.md
updated_at: '2026-10-14T22:56:43.676Z'
visibility_analyzed_at: '2026-11-05T23:49:34.929Z'
---

## Problem

Importing a league `cli/` or `scripts/` file can run it. On 2026-10-14 the user-base entry-point rule (no top-level `await`, control flow or call statements outside `if (isMain(import.meta.url))`) flagged 386 of 398 non-test files here. About 95 already guard with league's own `is_main` and only fail on a top-level `enable_debug_namespaces(...)` or `debug.enable(...)`. The rest call their entry or do work at module scope, and many write to the production league database by default.

The user-base sweep is the model: [[████████████████████-███-██████-█████-█████████]]. Its static rule lives in `cli/lib/entry-point-guard.test.mjs`.

## Plan

- [ ] Re-measure with the user-base rule, but accept league's `is_main(import.meta.url)` (from `libs-server/is-main.mjs`) as the guard. Record the count, split by shape: entry call, top-level await, module-scope work, debug-enable only.
- [ ] Decide whether a module-scope debug enable stays allowed. Recommendation: move it under the guard, since an import should not change the importer's logging.
- [ ] Wrap each entry in `if (is_main(import.meta.url)) { ... }`, moving bare top-level await scripts into a `main()` first. Keep exports intact and check that exported names are unchanged.
- [ ] Port the static guard test into league's own suite. Prove it red on an unguarded control, then green.
- [ ] Import every converted file with writes, subprocesses and fetch blocked and sockets sent to a closed port, plus a foreign argv. Never execute them.
- [ ] Run league's suites green and commit per directory in the league repo.

## Notes

- League's `is_main` is its own copy. Base's `isMain` is the one user-base `cli/` uses. Unifying them is a separate call.
