Skip to content

Enforce Fail-Fast Validation for Network Configurations in Subgraph Templating - #72

Open
magqqgq wants to merge 1 commit into
Polymarket:mainfrom
magqqgq:magqqgq-patch-1
Open

Enforce Fail-Fast Validation for Network Configurations in Subgraph Templating#72
magqqgq wants to merge 1 commit into
Polymarket:mainfrom
magqqgq:magqqgq-patch-1

Conversation

@magqqgq

@magqqgq magqqgq commented Sep 9, 2026

Copy link
Copy Markdown

Description

This pull request resolves Medium severity reliability and configuration findings identified in polymarket-subgraph during the workspace audit. Previously, missing or unrecognised network targets defaulted to empty evaluation contexts (networks[undefined]), prompting Handlebars to silently compile syntactically valid manifests with blank contract addresses and missing startBlock fields. Additionally, templatify.ts only accepted positional arguments, breaking scripts relying on NETWORK_NAME. This PR adds dual input support (argv and env) and fail-fast assertions against networks.yaml definitions.

Key Changes & Remediations

Configuration Resolution & Fail-Fast Guards (templatify.ts)

  • Dual Target Resolution: Updated network resolution to check process.argv[2] || process.env.NETWORK_NAME, ensuring alignment with prepare:* package scripts that pass network targets via environment variables.
  • Missing Target Assertion: Enforced an explicit error when no network name is supplied, eliminating confusing error messages that referenced obsolete flags.
  • Target Existence Assertion: Added an explicit check ensuring networks[networkName] exists before compiling templates. If an invalid network is supplied, the script throws an actionable error enumerating valid entries defined in networks.yaml rather than generating empty manifests that fail silently at deployment.

How to Review

  1. Target Loading: Verify in templatify.ts that networkName correctly evaluates positional arguments and process.env.NETWORK_NAME.
  2. Fail-Fast Guard: Test invoking templatify.ts with no arguments and with an unknown target (e.g., ts-node ./templatify.ts invalid-net) to ensure execution halts with clear error diagnostics.
  3. Template Compilation: Confirm valid network generation (e.g., matic) populates addresses and configurations as expected.

Note

Low Risk
Build-time subgraph templating only; no runtime auth, payments, or production indexing logic changes.

Overview
templatify.ts now resolves the target network from the first CLI argument or NETWORK_NAME, fixing prepare:mainnet / prepare:matic / prepare:mumbai scripts that only set the env var.

Validation runs before template compilation: missing network names get a corrected error (no obsolete SUBGRAPH hint), and unknown keys fail fast with a list of valid entries from networks.yaml instead of emitting subgraph manifests with blank addresses and empty startBlock values.

Reviewed by Cursor Bugbot for commit 850e07e. Bugbot is set up for automated code reviews on this repo. Configure here.

…emplating

### Description
This pull request resolves Medium severity reliability and configuration findings identified in `polymarket-subgraph` during the workspace audit. Previously, missing or unrecognised network targets defaulted to empty evaluation contexts (`networks[undefined]`), prompting Handlebars to silently compile syntactically valid manifests with blank contract addresses and missing `startBlock` fields. Additionally, `templatify.ts` only accepted positional arguments, breaking scripts relying on `NETWORK_NAME`. This PR adds dual input support (`argv` and `env`) and fail-fast assertions against `networks.yaml` definitions.

### Key Changes & Remediations

#### Configuration Resolution & Fail-Fast Guards (`templatify.ts`)
* **Dual Target Resolution:** Updated network resolution to check `process.argv[2] || process.env.NETWORK_NAME`, ensuring alignment with `prepare:*` package scripts that pass network targets via environment variables.
* **Missing Target Assertion:** Enforced an explicit error when no network name is supplied, eliminating confusing error messages that referenced obsolete flags.
* **Target Existence Assertion:** Added an explicit check ensuring `networks[networkName]` exists before compiling templates. If an invalid network is supplied, the script throws an actionable error enumerating valid entries defined in `networks.yaml` rather than generating empty manifests that fail silently at deployment.

### How to Review
1. **Target Loading:** Verify in `templatify.ts` that `networkName` correctly evaluates positional arguments and `process.env.NETWORK_NAME`.
2. **Fail-Fast Guard:** Test invoking `templatify.ts` with no arguments and with an unknown target (e.g., `ts-node ./templatify.ts invalid-net`) to ensure execution halts with clear error diagnostics.
3. **Template Compilation:** Confirm valid network generation (e.g., `matic`) populates addresses and configurations as expected.
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.

1 participant